benchmark.c 514 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147
  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);
  2783. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  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. #ifdef WOLFSSL_KYBER512
  3332. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3333. bench_kyber(KYBER512);
  3334. }
  3335. #endif
  3336. #ifdef WOLFSSL_KYBER768
  3337. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3338. bench_kyber(KYBER768);
  3339. }
  3340. #endif
  3341. #ifdef WOLFSSL_KYBER1024
  3342. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3343. bench_kyber(KYBER1024);
  3344. }
  3345. #endif
  3346. }
  3347. #endif
  3348. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3349. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3350. bench_lms();
  3351. }
  3352. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3353. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3354. if (bench_all) {
  3355. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3356. }
  3357. #ifndef NO_SHA256
  3358. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3359. bench_xmss(WC_HASH_TYPE_SHA256);
  3360. }
  3361. #endif
  3362. #ifdef WOLFSSL_SHA512
  3363. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3364. bench_xmss(WC_HASH_TYPE_SHA512);
  3365. }
  3366. #endif
  3367. #ifdef WOLFSSL_SHAKE128
  3368. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3369. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3370. }
  3371. #endif
  3372. #ifdef WOLFSSL_SHAKE256
  3373. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3374. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3375. }
  3376. #endif
  3377. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3378. #ifdef HAVE_ECC
  3379. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3380. (bench_asym_algs & BENCH_ECC) ||
  3381. (bench_asym_algs & BENCH_ECC_ALL) ||
  3382. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3383. if (bench_asym_algs & BENCH_ECC_ALL) {
  3384. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3385. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3386. err_prefix);
  3387. #else
  3388. int curveId = (int)ECC_SECP192R1;
  3389. /* set make key and encrypt */
  3390. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3391. BENCH_ECC_ENCRYPT;
  3392. if (csv_format != 1) {
  3393. printf("\n%sECC Benchmarks:\n", info_prefix);
  3394. }
  3395. do {
  3396. #ifdef WOLFCRYPT_HAVE_SAKKE
  3397. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3398. if (curveId == ECC_SAKKE_1) {
  3399. curveId++;
  3400. continue;
  3401. }
  3402. #endif
  3403. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3404. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3405. bench_ecc_curve(curveId);
  3406. if (csv_format != 1) {
  3407. printf("\n");
  3408. }
  3409. }
  3410. curveId++;
  3411. } while (curveId != (int)ECC_CURVE_MAX);
  3412. #endif
  3413. }
  3414. else if (bench_asym_algs & BENCH_ECC_P256) {
  3415. bench_ecc_curve((int)ECC_SECP256R1);
  3416. }
  3417. else if (bench_asym_algs & BENCH_ECC_P384) {
  3418. bench_ecc_curve((int)ECC_SECP384R1);
  3419. }
  3420. else if (bench_asym_algs & BENCH_ECC_P521) {
  3421. bench_ecc_curve((int)ECC_SECP521R1);
  3422. }
  3423. else {
  3424. #ifndef NO_ECC256
  3425. bench_ecc_curve((int)ECC_SECP256R1);
  3426. #elif defined(HAVE_ECC384)
  3427. bench_ecc_curve((int)ECC_SECP384R1);
  3428. #elif defined(HAVE_ECC521)
  3429. bench_ecc_curve((int)ECC_SECP521R1);
  3430. #endif
  3431. #ifdef HAVE_ECC_BRAINPOOL
  3432. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3433. #endif
  3434. }
  3435. }
  3436. #endif
  3437. #ifdef WOLFSSL_SM2
  3438. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3439. bench_sm2(0);
  3440. }
  3441. #endif
  3442. #ifdef HAVE_CURVE25519
  3443. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3444. bench_curve25519KeyGen(0);
  3445. #ifdef BENCH_DEVID
  3446. bench_curve25519KeyGen(1);
  3447. #endif
  3448. }
  3449. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3450. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3451. bench_curve25519KeyAgree(0);
  3452. #ifdef BENCH_DEVID
  3453. bench_curve25519KeyAgree(1);
  3454. #endif
  3455. }
  3456. #endif
  3457. #endif
  3458. #ifdef HAVE_ED25519
  3459. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3460. bench_ed25519KeyGen();
  3461. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3462. bench_ed25519KeySign();
  3463. #endif
  3464. #ifdef HAVE_CURVE448
  3465. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3466. bench_curve448KeyGen();
  3467. #ifdef HAVE_CURVE448_SHARED_SECRET
  3468. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3469. bench_curve448KeyAgree();
  3470. #endif
  3471. #endif
  3472. #ifdef HAVE_ED448
  3473. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3474. bench_ed448KeyGen();
  3475. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3476. bench_ed448KeySign();
  3477. #endif
  3478. #ifdef WOLFCRYPT_HAVE_ECCSI
  3479. #ifdef WOLFCRYPT_ECCSI_KMS
  3480. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3481. bench_eccsiKeyGen();
  3482. }
  3483. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3484. bench_eccsiPairGen();
  3485. }
  3486. #endif
  3487. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3488. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3489. bench_eccsiValidate();
  3490. }
  3491. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3492. bench_eccsi();
  3493. }
  3494. #endif
  3495. #endif
  3496. #ifdef WOLFCRYPT_HAVE_SAKKE
  3497. #ifdef WOLFCRYPT_SAKKE_KMS
  3498. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3499. bench_sakkeKeyGen();
  3500. }
  3501. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3502. bench_sakkeRskGen();
  3503. }
  3504. #endif
  3505. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3506. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3507. bench_sakkeValidate();
  3508. }
  3509. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3510. bench_sakke();
  3511. }
  3512. #endif
  3513. #endif
  3514. #ifdef HAVE_FALCON
  3515. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3516. bench_falconKeySign(1);
  3517. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3518. bench_falconKeySign(5);
  3519. #endif
  3520. #ifdef HAVE_DILITHIUM
  3521. #ifndef WOLFSSL_NO_ML_DSA_44
  3522. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3523. bench_dilithiumKeySign(2);
  3524. #endif
  3525. #ifndef WOLFSSL_NO_ML_DSA_65
  3526. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3527. bench_dilithiumKeySign(3);
  3528. #endif
  3529. #ifndef WOLFSSL_NO_ML_DSA_87
  3530. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3531. bench_dilithiumKeySign(5);
  3532. #endif
  3533. #endif
  3534. #ifdef HAVE_SPHINCS
  3535. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3536. bench_sphincsKeySign(1, FAST_VARIANT);
  3537. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3538. bench_sphincsKeySign(3, FAST_VARIANT);
  3539. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3540. bench_sphincsKeySign(5, FAST_VARIANT);
  3541. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3542. bench_sphincsKeySign(1, SMALL_VARIANT);
  3543. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3544. bench_sphincsKeySign(3, SMALL_VARIANT);
  3545. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3546. bench_sphincsKeySign(5, SMALL_VARIANT);
  3547. #endif
  3548. exit:
  3549. /* free benchmark buffers */
  3550. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3551. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3552. #ifdef WOLFSSL_ASYNC_CRYPT
  3553. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3554. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3555. #endif
  3556. #if defined(HAVE_LOCAL_RNG)
  3557. wc_FreeRng(&gRng);
  3558. #endif
  3559. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3560. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3561. wc_ecc_fp_free();
  3562. #endif
  3563. (void)bench_cipher_algs;
  3564. (void)bench_digest_algs;
  3565. (void)bench_mac_algs;
  3566. (void)bench_asym_algs;
  3567. (void)bench_other_algs;
  3568. (void)bench_pq_asym_algs;
  3569. (void)bench_pq_asym_algs2;
  3570. return NULL;
  3571. }
  3572. int benchmark_init(void)
  3573. {
  3574. int ret = 0;
  3575. benchmark_static_init(0);
  3576. #ifdef WOLFSSL_STATIC_MEMORY
  3577. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3578. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3579. if (ret != 0) {
  3580. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3581. }
  3582. #endif /* WOLFSSL_STATIC_MEMORY */
  3583. if ((ret = wolfCrypt_Init()) != 0) {
  3584. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3585. return EXIT_FAILURE;
  3586. }
  3587. #ifdef HAVE_WC_INTROSPECTION
  3588. printf("Math: %s\n", wc_GetMathInfo());
  3589. #endif
  3590. #ifdef WOLFSSL_SECO_CAAM
  3591. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3592. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3593. != 0) {
  3594. printf("%sunable to open HSM\n", err_prefix);
  3595. wolfCrypt_Cleanup();
  3596. return EXIT_FAILURE;
  3597. }
  3598. #endif
  3599. #ifdef WC_RNG_SEED_CB
  3600. wc_SetSeed_Cb(wc_GenerateSeed);
  3601. #endif
  3602. bench_stats_init();
  3603. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3604. wolfSSL_Debugging_ON();
  3605. #endif
  3606. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3607. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3608. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3609. if (csv_format == 1) {
  3610. printf("This format allows you to easily copy "
  3611. "the output to a csv file.");
  3612. }
  3613. #endif
  3614. #ifdef HAVE_WNR
  3615. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3616. if (ret != 0) {
  3617. printf("%sWhitewood netRandom config init failed %d\n",
  3618. err_prefix, ret);
  3619. }
  3620. #endif /* HAVE_WNR */
  3621. return ret;
  3622. }
  3623. int benchmark_free(void)
  3624. {
  3625. int ret;
  3626. #ifdef WC_BENCH_TRACK_STATS
  3627. if (gPrintStats || devId != INVALID_DEVID) {
  3628. bench_stats_print();
  3629. }
  3630. #endif
  3631. bench_stats_free();
  3632. #ifdef WOLF_CRYPTO_CB
  3633. #ifdef HAVE_INTEL_QA_SYNC
  3634. wc_CryptoCb_CleanupIntelQa(&devId);
  3635. #endif
  3636. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3637. wc_CryptoCb_CleanupOcteon(&devId);
  3638. #endif
  3639. #ifdef HAVE_RENESAS_SYNC
  3640. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3641. #endif
  3642. #endif
  3643. #ifdef WOLFSSL_ASYNC_CRYPT
  3644. /* free event queue */
  3645. wolfEventQueue_Free(&eventQueue);
  3646. /* close device */
  3647. wolfAsync_DevClose(&devId);
  3648. #endif
  3649. #ifdef HAVE_WNR
  3650. ret = wc_FreeNetRandom();
  3651. if (ret < 0) {
  3652. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3653. }
  3654. #endif
  3655. #ifdef WOLFSSL_SECO_CAAM
  3656. if (wc_SECO_CloseHSM() != 0) {
  3657. printf("%sError closing down the key store\n", err_prefix);
  3658. }
  3659. #endif
  3660. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3661. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3662. }
  3663. return ret;
  3664. }
  3665. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3666. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3667. {
  3668. benchmark_test(args);
  3669. EXIT_TEST(0);
  3670. }
  3671. static int benchmark_test_threaded(void* args)
  3672. {
  3673. int i;
  3674. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3675. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3676. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3677. if (g_threadData == NULL) {
  3678. printf("%sThread data alloc failed!\n", err_prefix);
  3679. return EXIT_FAILURE;
  3680. }
  3681. for (i = 0; i < g_threadCount; i++) {
  3682. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3683. NULL, run_bench, args));
  3684. }
  3685. for (i = 0; i < g_threadCount; i++) {
  3686. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3687. }
  3688. printf("\n");
  3689. bench_stats_print();
  3690. return 0;
  3691. }
  3692. #endif
  3693. /* so embedded projects can pull in tests on their own */
  3694. #ifdef HAVE_STACK_SIZE
  3695. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3696. #else
  3697. int benchmark_test(void *args)
  3698. #endif
  3699. {
  3700. int ret;
  3701. (void)args;
  3702. #ifdef HAVE_FIPS
  3703. wolfCrypt_SetCb_fips(myFipsCb);
  3704. #endif
  3705. ret = benchmark_init();
  3706. if (ret != 0)
  3707. EXIT_TEST(ret);
  3708. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3709. {
  3710. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3711. **
  3712. ** Chapter Two, Build Options:
  3713. **
  3714. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3715. **
  3716. ** asynchronous cryptography using hardware based adapters such as
  3717. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3718. */
  3719. int i;
  3720. if (g_threadCount == 0) {
  3721. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3722. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3723. #else
  3724. g_threadCount = wc_AsyncGetNumberOfCpus();
  3725. if (g_threadCount > 0) {
  3726. g_threadCount /= 2; /* use physical core count */
  3727. }
  3728. #endif
  3729. }
  3730. if (g_threadCount <= 0) {
  3731. g_threadCount = 1;
  3732. }
  3733. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3734. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3735. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3736. if (g_threadData == NULL) {
  3737. printf("%sThread data alloc failed!\n", err_prefix);
  3738. EXIT_TEST(EXIT_FAILURE);
  3739. }
  3740. /* Create threads */
  3741. for (i = 0; i < g_threadCount; i++) {
  3742. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3743. benchmarks_do, &g_threadData[i]);
  3744. if (ret != 0) {
  3745. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3746. EXIT_TEST(EXIT_FAILURE);
  3747. }
  3748. }
  3749. /* Start threads */
  3750. for (i = 0; i < g_threadCount; i++) {
  3751. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3752. }
  3753. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3754. }
  3755. #else
  3756. benchmarks_do(NULL);
  3757. #endif
  3758. SLEEP_ON_ERROR(1);
  3759. printf("%sBenchmark complete\n", info_prefix);
  3760. ret = benchmark_free();
  3761. EXIT_TEST(ret);
  3762. }
  3763. #ifndef WC_NO_RNG
  3764. void bench_rng(void)
  3765. {
  3766. int ret, i, count;
  3767. double start;
  3768. long pos, len, remain;
  3769. WC_RNG myrng;
  3770. DECLARE_MULTI_VALUE_STATS_VARS()
  3771. #ifndef HAVE_FIPS
  3772. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3773. #else
  3774. ret = wc_InitRng(&myrng);
  3775. #endif
  3776. if (ret < 0) {
  3777. printf("InitRNG failed %d\n", ret);
  3778. return;
  3779. }
  3780. bench_stats_start(&count, &start);
  3781. do {
  3782. for (i = 0; i < numBlocks; i++) {
  3783. /* Split request to handle large RNG request */
  3784. pos = 0;
  3785. remain = (int)bench_size;
  3786. while (remain > 0) {
  3787. len = remain;
  3788. if (len > RNG_MAX_BLOCK_LEN)
  3789. len = RNG_MAX_BLOCK_LEN;
  3790. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3791. (word32)len);
  3792. if (ret < 0)
  3793. goto exit_rng;
  3794. remain -= len;
  3795. pos += len;
  3796. }
  3797. RECORD_MULTI_VALUE_STATS();
  3798. }
  3799. count += i;
  3800. } while (bench_stats_check(start)
  3801. #ifdef MULTI_VALUE_STATISTICS
  3802. || runs < minimum_runs
  3803. #endif
  3804. );
  3805. exit_rng:
  3806. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3807. #ifdef MULTI_VALUE_STATISTICS
  3808. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3809. #endif
  3810. wc_FreeRng(&myrng);
  3811. }
  3812. #endif /* WC_NO_RNG */
  3813. #ifndef NO_AES
  3814. #ifdef HAVE_AES_CBC
  3815. static void bench_aescbc_internal(int useDeviceID,
  3816. const byte* key, word32 keySz,
  3817. const byte* iv, const char* encLabel,
  3818. const char* decLabel)
  3819. {
  3820. const byte* in = bench_cipher;
  3821. byte* out = bench_plain;
  3822. int ret = 0, i, count = 0, times, pending = 0;
  3823. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3824. sizeof(Aes), HEAP_HINT);
  3825. double start;
  3826. DECLARE_MULTI_VALUE_STATS_VARS()
  3827. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3828. sizeof(Aes), HEAP_HINT);
  3829. /* init keys */
  3830. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3831. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3832. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3833. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3834. goto exit;
  3835. }
  3836. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3837. if (ret != 0) {
  3838. printf("AesSetKey failed, ret = %d\n", ret);
  3839. goto exit;
  3840. }
  3841. }
  3842. if (cipher_same_buffer) {
  3843. in = bench_plain;
  3844. }
  3845. bench_stats_start(&count, &start);
  3846. do {
  3847. for (times = 0; times < numBlocks || pending > 0; ) {
  3848. bench_async_poll(&pending);
  3849. /* while free pending slots in queue, submit ops */
  3850. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3851. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3852. &times, numBlocks, &pending)) {
  3853. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3854. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3855. 0, &times, &pending)) {
  3856. goto exit_aes_enc;
  3857. }
  3858. }
  3859. } /* for i */
  3860. RECORD_MULTI_VALUE_STATS();
  3861. } /* for times */
  3862. count += times;
  3863. } while (bench_stats_check(start)
  3864. #ifdef MULTI_VALUE_STATISTICS
  3865. || runs < minimum_runs
  3866. #endif
  3867. );
  3868. exit_aes_enc:
  3869. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3870. bench_size, start, ret);
  3871. #ifdef MULTI_VALUE_STATISTICS
  3872. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3873. #endif
  3874. if (ret < 0) {
  3875. goto exit;
  3876. }
  3877. #ifdef HAVE_AES_DECRYPT
  3878. /* init keys */
  3879. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3880. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3881. if (ret != 0) {
  3882. printf("AesSetKey failed, ret = %d\n", ret);
  3883. goto exit;
  3884. }
  3885. }
  3886. RESET_MULTI_VALUE_STATS_VARS();
  3887. bench_stats_start(&count, &start);
  3888. do {
  3889. for (times = 0; times < numBlocks || pending > 0; ) {
  3890. bench_async_poll(&pending);
  3891. /* while free pending slots in queue, submit ops */
  3892. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3893. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3894. &times, numBlocks, &pending)) {
  3895. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3896. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3897. 0, &times, &pending)) {
  3898. goto exit_aes_dec;
  3899. }
  3900. }
  3901. } /* for i */
  3902. RECORD_MULTI_VALUE_STATS();
  3903. } /* for times */
  3904. count += times;
  3905. } while (bench_stats_check(start)
  3906. #ifdef MULTI_VALUE_STATISTICS
  3907. || runs < minimum_runs
  3908. #endif
  3909. );
  3910. exit_aes_dec:
  3911. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3912. start, ret);
  3913. #ifdef MULTI_VALUE_STATISTICS
  3914. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3915. #endif
  3916. #endif /* HAVE_AES_DECRYPT */
  3917. (void)decLabel;
  3918. exit:
  3919. if (WC_ARRAY_OK(enc)) {
  3920. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3921. wc_AesFree(enc[i]);
  3922. }
  3923. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3924. }
  3925. }
  3926. void bench_aescbc(int useDeviceID)
  3927. {
  3928. #ifdef WOLFSSL_AES_128
  3929. #ifdef HAVE_RENESAS_SYNC
  3930. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3931. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3932. #else
  3933. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3934. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3935. #endif
  3936. #endif
  3937. #ifdef WOLFSSL_AES_192
  3938. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3939. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3940. #endif
  3941. #ifdef WOLFSSL_AES_256
  3942. #ifdef HAVE_RENESAS_SYNC
  3943. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3944. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3945. #else
  3946. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3947. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3948. #endif
  3949. #endif
  3950. }
  3951. #endif /* HAVE_AES_CBC */
  3952. #ifdef HAVE_AESGCM
  3953. static void bench_aesgcm_internal(int useDeviceID,
  3954. const byte* key, word32 keySz,
  3955. const byte* iv, word32 ivSz,
  3956. const char* encLabel, const char* decLabel)
  3957. {
  3958. int ret = 0, i, count = 0, times, pending = 0;
  3959. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3960. sizeof(Aes), HEAP_HINT);
  3961. #ifdef HAVE_AES_DECRYPT
  3962. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3963. sizeof(Aes), HEAP_HINT);
  3964. #endif
  3965. double start;
  3966. DECLARE_MULTI_VALUE_STATS_VARS()
  3967. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3968. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3969. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3970. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3971. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3972. sizeof(Aes), HEAP_HINT);
  3973. #ifdef HAVE_AES_DECRYPT
  3974. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3975. sizeof(Aes), HEAP_HINT);
  3976. #endif
  3977. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3978. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3979. /* init keys */
  3980. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3981. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3982. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3983. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3984. goto exit;
  3985. }
  3986. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  3987. if (ret != 0) {
  3988. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3989. goto exit;
  3990. }
  3991. }
  3992. /* GCM uses same routine in backend for both encrypt and decrypt */
  3993. bench_stats_start(&count, &start);
  3994. do {
  3995. for (times = 0; times < numBlocks || pending > 0; ) {
  3996. bench_async_poll(&pending);
  3997. /* while free pending slots in queue, submit ops */
  3998. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3999. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4000. &times, numBlocks, &pending)) {
  4001. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4002. bench_plain, bench_size,
  4003. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4004. bench_additional, aesAuthAddSz);
  4005. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4006. 0, &times, &pending)) {
  4007. goto exit_aes_gcm;
  4008. }
  4009. }
  4010. } /* for i */
  4011. RECORD_MULTI_VALUE_STATS();
  4012. } /* for times */
  4013. count += times;
  4014. } while (bench_stats_check(start)
  4015. #ifdef MULTI_VALUE_STATISTICS
  4016. || runs < minimum_runs
  4017. #endif
  4018. );
  4019. exit_aes_gcm:
  4020. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4021. start, ret);
  4022. #ifdef MULTI_VALUE_STATISTICS
  4023. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4024. #endif
  4025. #ifdef HAVE_AES_DECRYPT
  4026. RESET_MULTI_VALUE_STATS_VARS();
  4027. /* init keys */
  4028. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4029. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4030. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4031. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4032. goto exit;
  4033. }
  4034. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4035. if (ret != 0) {
  4036. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4037. goto exit;
  4038. }
  4039. }
  4040. bench_stats_start(&count, &start);
  4041. do {
  4042. for (times = 0; times < numBlocks || pending > 0; ) {
  4043. bench_async_poll(&pending);
  4044. /* while free pending slots in queue, submit ops */
  4045. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4046. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4047. &times, numBlocks, &pending)) {
  4048. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4049. bench_cipher, bench_size,
  4050. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4051. bench_additional, aesAuthAddSz);
  4052. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4053. 0, &times, &pending)) {
  4054. goto exit_aes_gcm_dec;
  4055. }
  4056. }
  4057. } /* for i */
  4058. RECORD_MULTI_VALUE_STATS();
  4059. } /* for times */
  4060. count += times;
  4061. } while (bench_stats_check(start)
  4062. #ifdef MULTI_VALUE_STATISTICS
  4063. || runs < minimum_runs
  4064. #endif
  4065. );
  4066. exit_aes_gcm_dec:
  4067. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4068. start, ret);
  4069. #ifdef MULTI_VALUE_STATISTICS
  4070. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4071. #endif
  4072. #endif /* HAVE_AES_DECRYPT */
  4073. (void)decLabel;
  4074. exit:
  4075. if (ret < 0) {
  4076. printf("bench_aesgcm failed: %d\n", ret);
  4077. }
  4078. #ifdef HAVE_AES_DECRYPT
  4079. if (WC_ARRAY_OK(dec)) {
  4080. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4081. wc_AesFree(dec[i]);
  4082. }
  4083. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4084. }
  4085. #endif
  4086. if (WC_ARRAY_OK(enc)) {
  4087. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4088. wc_AesFree(enc[i]);
  4089. }
  4090. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4091. }
  4092. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4093. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4094. }
  4095. #ifdef WOLFSSL_AESGCM_STREAM
  4096. static void bench_aesgcm_stream_internal(int useDeviceID,
  4097. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4098. const char* encLabel, const char* decLabel)
  4099. {
  4100. int ret = 0, i, count = 0, times, pending = 0;
  4101. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4102. sizeof(Aes), HEAP_HINT);
  4103. #ifdef HAVE_AES_DECRYPT
  4104. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4105. sizeof(Aes), HEAP_HINT);
  4106. #endif
  4107. double start;
  4108. DECLARE_MULTI_VALUE_STATS_VARS()
  4109. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4110. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4111. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4112. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4113. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4114. sizeof(Aes), HEAP_HINT);
  4115. #ifdef HAVE_AES_DECRYPT
  4116. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4117. sizeof(Aes), HEAP_HINT);
  4118. #endif
  4119. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4120. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4121. /* init keys */
  4122. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4123. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4124. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4125. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4126. goto exit;
  4127. }
  4128. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4129. if (ret != 0) {
  4130. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4131. goto exit;
  4132. }
  4133. }
  4134. /* GCM uses same routine in backend for both encrypt and decrypt */
  4135. bench_stats_start(&count, &start);
  4136. do {
  4137. for (times = 0; times < numBlocks || pending > 0; ) {
  4138. bench_async_poll(&pending);
  4139. /* while free pending slots in queue, submit ops */
  4140. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4141. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4142. &times, numBlocks, &pending)) {
  4143. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4144. if (ret == 0) {
  4145. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4146. bench_plain, bench_size, bench_additional,
  4147. aesAuthAddSz);
  4148. }
  4149. if (ret == 0) {
  4150. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4151. AES_AUTH_TAG_SZ);
  4152. }
  4153. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4154. 0, &times, &pending)) {
  4155. goto exit_aes_gcm;
  4156. }
  4157. }
  4158. } /* for i */
  4159. RECORD_MULTI_VALUE_STATS();
  4160. } /* for times */
  4161. count += times;
  4162. } while (bench_stats_check(start)
  4163. #ifdef MULTI_VALUE_STATISTICS
  4164. || runs < minimum_runs
  4165. #endif
  4166. );
  4167. exit_aes_gcm:
  4168. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4169. start, ret);
  4170. #ifdef MULTI_VALUE_STATISTICS
  4171. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4172. #endif
  4173. #ifdef HAVE_AES_DECRYPT
  4174. /* init keys */
  4175. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4176. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4177. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4178. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4179. goto exit;
  4180. }
  4181. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4182. if (ret != 0) {
  4183. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4184. goto exit;
  4185. }
  4186. }
  4187. RESET_MULTI_VALUE_STATS_VARS();
  4188. bench_stats_start(&count, &start);
  4189. do {
  4190. for (times = 0; times < numBlocks || pending > 0; ) {
  4191. bench_async_poll(&pending);
  4192. /* while free pending slots in queue, submit ops */
  4193. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4194. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4195. &times, numBlocks, &pending)) {
  4196. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4197. if (ret == 0) {
  4198. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4199. bench_cipher, bench_size, bench_additional,
  4200. aesAuthAddSz);
  4201. }
  4202. if (ret == 0) {
  4203. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4204. AES_AUTH_TAG_SZ);
  4205. }
  4206. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4207. 0, &times, &pending)) {
  4208. goto exit_aes_gcm_dec;
  4209. }
  4210. }
  4211. } /* for i */
  4212. RECORD_MULTI_VALUE_STATS();
  4213. } /* for times */
  4214. count += times;
  4215. } while (bench_stats_check(start)
  4216. #ifdef MULTI_VALUE_STATISTICS
  4217. || runs < minimum_runs
  4218. #endif
  4219. );
  4220. exit_aes_gcm_dec:
  4221. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4222. start, ret);
  4223. #ifdef MULTI_VALUE_STATISTICS
  4224. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4225. #endif
  4226. #endif /* HAVE_AES_DECRYPT */
  4227. (void)decLabel;
  4228. exit:
  4229. if (ret < 0) {
  4230. printf("bench_aesgcm failed: %d\n", ret);
  4231. }
  4232. #ifdef HAVE_AES_DECRYPT
  4233. if (WC_ARRAY_OK(dec)) {
  4234. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4235. wc_AesFree(dec[i]);
  4236. }
  4237. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4238. }
  4239. #endif
  4240. if (WC_ARRAY_OK(enc)) {
  4241. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4242. wc_AesFree(enc[i]);
  4243. }
  4244. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4245. }
  4246. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4247. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4248. }
  4249. #endif
  4250. void bench_aesgcm(int useDeviceID)
  4251. {
  4252. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4253. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4254. && !defined(WOLFSSL_XILINX_CRYPT) \
  4255. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4256. #ifdef HAVE_RENESAS_SYNC
  4257. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4258. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4259. #else
  4260. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4261. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4262. #endif
  4263. #endif
  4264. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4265. && !defined(WOLFSSL_XILINX_CRYPT)
  4266. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4267. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4268. #endif
  4269. #ifdef WOLFSSL_AES_256
  4270. #ifdef HAVE_RENESAS_SYNC
  4271. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4272. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4273. #else
  4274. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4275. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4276. #endif
  4277. #endif
  4278. #ifdef WOLFSSL_AESGCM_STREAM
  4279. #undef AES_GCM_STRING
  4280. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4281. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4282. && !defined(WOLFSSL_XILINX_CRYPT) \
  4283. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4284. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4285. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4286. #endif
  4287. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4288. && !defined(WOLFSSL_XILINX_CRYPT)
  4289. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4290. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4291. #endif
  4292. #ifdef WOLFSSL_AES_256
  4293. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4294. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4295. #endif
  4296. #endif /* WOLFSSL_AESGCM_STREAM */
  4297. #undef AES_GCM_STRING
  4298. }
  4299. /* GMAC */
  4300. void bench_gmac(int useDeviceID)
  4301. {
  4302. int ret, count = 0;
  4303. Gmac gmac;
  4304. double start;
  4305. byte tag[AES_AUTH_TAG_SZ];
  4306. DECLARE_MULTI_VALUE_STATS_VARS()
  4307. /* determine GCM GHASH method */
  4308. #ifdef GCM_SMALL
  4309. const char* gmacStr = "GMAC Small";
  4310. #elif defined(GCM_TABLE)
  4311. const char* gmacStr = "GMAC Table";
  4312. #elif defined(GCM_TABLE_4BIT)
  4313. const char* gmacStr = "GMAC Table 4-bit";
  4314. #elif defined(GCM_WORD32)
  4315. const char* gmacStr = "GMAC Word32";
  4316. #else
  4317. const char* gmacStr = "GMAC Default";
  4318. #endif
  4319. /* init keys */
  4320. XMEMSET(bench_plain, 0, bench_size);
  4321. XMEMSET(tag, 0, sizeof(tag));
  4322. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4323. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4324. useDeviceID ? devId: INVALID_DEVID);
  4325. #ifdef HAVE_RENESAS_SYNC
  4326. wc_GmacSetKey(&gmac, bench_key1, 16);
  4327. #else
  4328. wc_GmacSetKey(&gmac, bench_key, 16);
  4329. #endif
  4330. bench_stats_start(&count, &start);
  4331. do {
  4332. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4333. tag, sizeof(tag));
  4334. count++;
  4335. RECORD_MULTI_VALUE_STATS();
  4336. } while (bench_stats_check(start)
  4337. #ifdef MULTI_VALUE_STATISTICS
  4338. || runs < minimum_runs
  4339. #endif
  4340. );
  4341. wc_AesFree((Aes*)&gmac);
  4342. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4343. #ifdef MULTI_VALUE_STATISTICS
  4344. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4345. #endif
  4346. }
  4347. #endif /* HAVE_AESGCM */
  4348. #ifdef HAVE_AES_ECB
  4349. static void bench_aesecb_internal(int useDeviceID,
  4350. const byte* key, word32 keySz,
  4351. const char* encLabel, const char* decLabel)
  4352. {
  4353. int ret = 0, i, count = 0, times, pending = 0;
  4354. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4355. sizeof(Aes), HEAP_HINT);
  4356. double start;
  4357. DECLARE_MULTI_VALUE_STATS_VARS()
  4358. #ifdef HAVE_FIPS
  4359. const word32 benchSz = AES_BLOCK_SIZE;
  4360. #else
  4361. const word32 benchSz = bench_size;
  4362. #endif
  4363. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4364. sizeof(Aes), HEAP_HINT);
  4365. /* init keys */
  4366. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4367. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4368. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4369. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4370. goto exit;
  4371. }
  4372. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4373. if (ret != 0) {
  4374. printf("AesSetKey failed, ret = %d\n", ret);
  4375. goto exit;
  4376. }
  4377. }
  4378. bench_stats_start(&count, &start);
  4379. do {
  4380. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4381. for (times = 0;
  4382. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4383. ) {
  4384. bench_async_poll(&pending);
  4385. /* while free pending slots in queue, submit ops */
  4386. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4387. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4388. &times, outer_loop_limit, &pending)) {
  4389. #ifdef HAVE_FIPS
  4390. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4391. #else
  4392. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4393. benchSz);
  4394. #endif
  4395. ret = 0;
  4396. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4397. 0, &times, &pending)) {
  4398. goto exit_aes_enc;
  4399. }
  4400. }
  4401. } /* for i */
  4402. RECORD_MULTI_VALUE_STATS();
  4403. } /* for times */
  4404. count += times;
  4405. } while (bench_stats_check(start)
  4406. #ifdef MULTI_VALUE_STATISTICS
  4407. || runs < minimum_runs
  4408. #endif
  4409. );
  4410. exit_aes_enc:
  4411. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4412. start, ret);
  4413. #ifdef MULTI_VALUE_STATISTICS
  4414. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4415. #endif
  4416. #ifdef HAVE_AES_DECRYPT
  4417. /* init keys */
  4418. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4419. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4420. if (ret != 0) {
  4421. printf("AesSetKey failed, ret = %d\n", ret);
  4422. goto exit;
  4423. }
  4424. }
  4425. RESET_MULTI_VALUE_STATS_VARS();
  4426. bench_stats_start(&count, &start);
  4427. do {
  4428. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4429. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4430. bench_async_poll(&pending);
  4431. /* while free pending slots in queue, submit ops */
  4432. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4433. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4434. &times, outer_loop_limit, &pending)) {
  4435. #ifdef HAVE_FIPS
  4436. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4437. #else
  4438. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4439. benchSz);
  4440. #endif
  4441. ret = 0;
  4442. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4443. 0, &times, &pending)) {
  4444. goto exit_aes_dec;
  4445. }
  4446. }
  4447. } /* for i */
  4448. RECORD_MULTI_VALUE_STATS();
  4449. } /* for times */
  4450. count += times;
  4451. } while (bench_stats_check(start)
  4452. #ifdef MULTI_VALUE_STATISTICS
  4453. || runs < minimum_runs
  4454. #endif
  4455. );
  4456. exit_aes_dec:
  4457. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4458. start, ret);
  4459. #ifdef MULTI_VALUE_STATISTICS
  4460. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4461. #endif
  4462. #endif /* HAVE_AES_DECRYPT */
  4463. (void)decLabel;
  4464. exit:
  4465. if (WC_ARRAY_OK(enc)) {
  4466. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4467. wc_AesFree(enc[i]);
  4468. }
  4469. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4470. }
  4471. }
  4472. void bench_aesecb(int useDeviceID)
  4473. {
  4474. #ifdef WOLFSSL_AES_128
  4475. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4476. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4477. #endif
  4478. #ifdef WOLFSSL_AES_192
  4479. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4480. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4481. #endif
  4482. #ifdef WOLFSSL_AES_256
  4483. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4484. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4485. #endif
  4486. }
  4487. #endif /* HAVE_AES_ECB */
  4488. #ifdef WOLFSSL_AES_CFB
  4489. static void bench_aescfb_internal(const byte* key,
  4490. word32 keySz, const byte* iv,
  4491. const char* label)
  4492. {
  4493. Aes enc;
  4494. double start;
  4495. int i, ret, count;
  4496. DECLARE_MULTI_VALUE_STATS_VARS()
  4497. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4498. if (ret != 0) {
  4499. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4500. return;
  4501. }
  4502. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4503. if (ret != 0) {
  4504. printf("AesSetKey failed, ret = %d\n", ret);
  4505. goto out;
  4506. }
  4507. bench_stats_start(&count, &start);
  4508. do {
  4509. for (i = 0; i < numBlocks; i++) {
  4510. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4511. bench_size)) != 0) {
  4512. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4513. goto out;
  4514. }
  4515. RECORD_MULTI_VALUE_STATS();
  4516. }
  4517. count += i;
  4518. } while (bench_stats_check(start)
  4519. #ifdef MULTI_VALUE_STATISTICS
  4520. || runs < minimum_runs
  4521. #endif
  4522. );
  4523. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4524. #ifdef MULTI_VALUE_STATISTICS
  4525. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4526. #endif
  4527. out:
  4528. wc_AesFree(&enc);
  4529. return;
  4530. }
  4531. void bench_aescfb(void)
  4532. {
  4533. #ifdef WOLFSSL_AES_128
  4534. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4535. #endif
  4536. #ifdef WOLFSSL_AES_192
  4537. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4538. #endif
  4539. #ifdef WOLFSSL_AES_256
  4540. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4541. #endif
  4542. }
  4543. #endif /* WOLFSSL_AES_CFB */
  4544. #ifdef WOLFSSL_AES_OFB
  4545. static void bench_aesofb_internal(const byte* key,
  4546. word32 keySz, const byte* iv,
  4547. const char* label)
  4548. {
  4549. Aes enc;
  4550. double start;
  4551. int i, ret, count;
  4552. DECLARE_MULTI_VALUE_STATS_VARS()
  4553. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4554. if (ret != 0) {
  4555. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4556. return;
  4557. }
  4558. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4559. if (ret != 0) {
  4560. printf("AesSetKey failed, ret = %d\n", ret);
  4561. return;
  4562. }
  4563. bench_stats_start(&count, &start);
  4564. do {
  4565. for (i = 0; i < numBlocks; i++) {
  4566. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4567. bench_size)) != 0) {
  4568. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4569. return;
  4570. }
  4571. RECORD_MULTI_VALUE_STATS();
  4572. }
  4573. count += i;
  4574. } while (bench_stats_check(start)
  4575. #ifdef MULTI_VALUE_STATISTICS
  4576. || runs < minimum_runs
  4577. #endif
  4578. );
  4579. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4580. #ifdef MULTI_VALUE_STATISTICS
  4581. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4582. #endif
  4583. wc_AesFree(&enc);
  4584. }
  4585. void bench_aesofb(void)
  4586. {
  4587. #ifdef WOLFSSL_AES_128
  4588. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4589. #endif
  4590. #ifdef WOLFSSL_AES_192
  4591. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4592. #endif
  4593. #ifdef WOLFSSL_AES_256
  4594. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4595. #endif
  4596. }
  4597. #endif /* WOLFSSL_AES_CFB */
  4598. #ifdef WOLFSSL_AES_XTS
  4599. void bench_aesxts(void)
  4600. {
  4601. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4602. double start;
  4603. int i, count, ret;
  4604. DECLARE_MULTI_VALUE_STATS_VARS()
  4605. static const unsigned char k1[] = {
  4606. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4607. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4608. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4609. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4610. };
  4611. static const unsigned char i1[] = {
  4612. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4613. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4614. };
  4615. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4616. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4617. HEAP_HINT, devId);
  4618. if (ret != 0) {
  4619. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4620. goto exit;
  4621. }
  4622. bench_stats_start(&count, &start);
  4623. do {
  4624. for (i = 0; i < numBlocks; i++) {
  4625. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4626. bench_size, i1, sizeof(i1))) != 0) {
  4627. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4628. goto exit;
  4629. }
  4630. RECORD_MULTI_VALUE_STATS();
  4631. }
  4632. count += i;
  4633. } while (bench_stats_check(start)
  4634. #ifdef MULTI_VALUE_STATISTICS
  4635. || runs < minimum_runs
  4636. #endif
  4637. );
  4638. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4639. #ifdef MULTI_VALUE_STATISTICS
  4640. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4641. #endif
  4642. wc_AesXtsFree(aes);
  4643. /* decryption benchmark */
  4644. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4645. HEAP_HINT, devId);
  4646. if (ret != 0) {
  4647. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4648. goto exit;
  4649. }
  4650. RESET_MULTI_VALUE_STATS_VARS();
  4651. bench_stats_start(&count, &start);
  4652. do {
  4653. for (i = 0; i < numBlocks; i++) {
  4654. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4655. bench_size, i1, sizeof(i1))) != 0) {
  4656. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4657. goto exit;
  4658. }
  4659. RECORD_MULTI_VALUE_STATS();
  4660. }
  4661. count += i;
  4662. } while (bench_stats_check(start)
  4663. #ifdef MULTI_VALUE_STATISTICS
  4664. || runs < minimum_runs
  4665. #endif
  4666. );
  4667. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4668. #ifdef MULTI_VALUE_STATISTICS
  4669. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4670. #endif
  4671. exit:
  4672. wc_AesXtsFree(aes);
  4673. WC_FREE_VAR(aes, HEAP_HINT);
  4674. }
  4675. #endif /* WOLFSSL_AES_XTS */
  4676. #ifdef WOLFSSL_AES_COUNTER
  4677. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4678. const byte* iv, const char* label,
  4679. int useDeviceID)
  4680. {
  4681. Aes enc;
  4682. double start;
  4683. int i, count, ret = 0;
  4684. DECLARE_MULTI_VALUE_STATS_VARS()
  4685. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4686. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4687. printf("wc_AesInit failed, ret = %d\n", ret);
  4688. }
  4689. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4690. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4691. return;
  4692. }
  4693. bench_stats_start(&count, &start);
  4694. do {
  4695. for (i = 0; i < numBlocks; i++) {
  4696. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4697. bench_size)) != 0) {
  4698. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4699. return;
  4700. }
  4701. RECORD_MULTI_VALUE_STATS();
  4702. }
  4703. count += i;
  4704. } while (bench_stats_check(start)
  4705. #ifdef MULTI_VALUE_STATISTICS
  4706. || runs < minimum_runs
  4707. #endif
  4708. );
  4709. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4710. #ifdef MULTI_VALUE_STATISTICS
  4711. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4712. #endif
  4713. wc_AesFree(&enc);
  4714. }
  4715. void bench_aesctr(int useDeviceID)
  4716. {
  4717. #ifdef WOLFSSL_AES_128
  4718. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4719. #endif
  4720. #ifdef WOLFSSL_AES_192
  4721. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4722. #endif
  4723. #ifdef WOLFSSL_AES_256
  4724. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4725. #endif
  4726. }
  4727. #endif /* WOLFSSL_AES_COUNTER */
  4728. #ifdef HAVE_AESCCM
  4729. void bench_aesccm(int useDeviceID)
  4730. {
  4731. Aes enc;
  4732. int enc_inited = 0;
  4733. double start;
  4734. int ret, i, count;
  4735. DECLARE_MULTI_VALUE_STATS_VARS()
  4736. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4737. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4738. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4739. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4740. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4741. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4742. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4743. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4744. {
  4745. printf("wc_AesInit failed, ret = %d\n", ret);
  4746. goto exit;
  4747. }
  4748. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4749. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4750. goto exit;
  4751. }
  4752. enc_inited = 1;
  4753. bench_stats_start(&count, &start);
  4754. do {
  4755. for (i = 0; i < numBlocks; i++) {
  4756. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4757. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4758. bench_additional, 0);
  4759. RECORD_MULTI_VALUE_STATS();
  4760. }
  4761. count += i;
  4762. } while (bench_stats_check(start)
  4763. #ifdef MULTI_VALUE_STATISTICS
  4764. || runs < minimum_runs
  4765. #endif
  4766. );
  4767. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4768. bench_size, start, ret);
  4769. #ifdef MULTI_VALUE_STATISTICS
  4770. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4771. #endif
  4772. if (ret != 0) {
  4773. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4774. goto exit;
  4775. }
  4776. #ifdef HAVE_AES_DECRYPT
  4777. RESET_MULTI_VALUE_STATS_VARS();
  4778. bench_stats_start(&count, &start);
  4779. do {
  4780. for (i = 0; i < numBlocks; i++) {
  4781. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4782. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4783. bench_additional, 0);
  4784. RECORD_MULTI_VALUE_STATS();
  4785. }
  4786. count += i;
  4787. } while (bench_stats_check(start)
  4788. #ifdef MULTI_VALUE_STATISTICS
  4789. || runs < minimum_runs
  4790. #endif
  4791. );
  4792. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4793. bench_size, start, ret);
  4794. #ifdef MULTI_VALUE_STATISTICS
  4795. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4796. #endif
  4797. if (ret != 0) {
  4798. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4799. goto exit;
  4800. }
  4801. #endif
  4802. exit:
  4803. if (enc_inited)
  4804. wc_AesFree(&enc);
  4805. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4806. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4807. }
  4808. #endif /* HAVE_AESCCM */
  4809. #ifdef WOLFSSL_AES_SIV
  4810. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4811. encLabel, const char* decLabel)
  4812. {
  4813. int i;
  4814. int ret = 0;
  4815. byte assoc[AES_BLOCK_SIZE];
  4816. byte nonce[AES_BLOCK_SIZE];
  4817. byte siv[AES_BLOCK_SIZE];
  4818. int count = 0;
  4819. double start;
  4820. DECLARE_MULTI_VALUE_STATS_VARS()
  4821. bench_stats_start(&count, &start);
  4822. do {
  4823. for (i = 0; i < numBlocks; i++) {
  4824. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4825. AES_BLOCK_SIZE, bench_plain, bench_size,
  4826. siv, bench_cipher);
  4827. if (ret != 0) {
  4828. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4829. return;
  4830. }
  4831. RECORD_MULTI_VALUE_STATS();
  4832. }
  4833. count += i;
  4834. } while (bench_stats_check(start)
  4835. #ifdef MULTI_VALUE_STATISTICS
  4836. || runs < minimum_runs
  4837. #endif
  4838. );
  4839. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4840. #ifdef MULTI_VALUE_STATISTICS
  4841. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4842. #endif
  4843. RESET_MULTI_VALUE_STATS_VARS();
  4844. bench_stats_start(&count, &start);
  4845. do {
  4846. for (i = 0; i < numBlocks; i++) {
  4847. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4848. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4849. siv, bench_plain);
  4850. if (ret != 0) {
  4851. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4852. return;
  4853. }
  4854. RECORD_MULTI_VALUE_STATS();
  4855. }
  4856. count += i;
  4857. } while (bench_stats_check(start)
  4858. #ifdef MULTI_VALUE_STATISTICS
  4859. || runs < minimum_runs
  4860. #endif
  4861. );
  4862. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4863. #ifdef MULTI_VALUE_STATISTICS
  4864. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4865. #endif
  4866. }
  4867. void bench_aessiv(void)
  4868. {
  4869. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4870. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4871. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4872. }
  4873. #endif /* WOLFSSL_AES_SIV */
  4874. #endif /* !NO_AES */
  4875. #ifdef HAVE_POLY1305
  4876. void bench_poly1305(void)
  4877. {
  4878. Poly1305 enc;
  4879. byte mac[16];
  4880. double start;
  4881. int ret = 0, i, count;
  4882. DECLARE_MULTI_VALUE_STATS_VARS()
  4883. if (digest_stream) {
  4884. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4885. if (ret != 0) {
  4886. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4887. return;
  4888. }
  4889. bench_stats_start(&count, &start);
  4890. do {
  4891. for (i = 0; i < numBlocks; i++) {
  4892. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4893. if (ret != 0) {
  4894. printf("Poly1305Update failed: %d\n", ret);
  4895. break;
  4896. }
  4897. RECORD_MULTI_VALUE_STATS();
  4898. }
  4899. wc_Poly1305Final(&enc, mac);
  4900. count += i;
  4901. } while (bench_stats_check(start)
  4902. #ifdef MULTI_VALUE_STATISTICS
  4903. || runs < minimum_runs
  4904. #endif
  4905. );
  4906. }
  4907. else {
  4908. bench_stats_start(&count, &start);
  4909. do {
  4910. for (i = 0; i < numBlocks; i++) {
  4911. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4912. if (ret != 0) {
  4913. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4914. return;
  4915. }
  4916. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4917. if (ret != 0) {
  4918. printf("Poly1305Update failed: %d\n", ret);
  4919. break;
  4920. }
  4921. wc_Poly1305Final(&enc, mac);
  4922. RECORD_MULTI_VALUE_STATS();
  4923. }
  4924. count += i;
  4925. } while (bench_stats_check(start)
  4926. #ifdef MULTI_VALUE_STATISTICS
  4927. || runs < minimum_runs
  4928. #endif
  4929. );
  4930. }
  4931. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4932. #ifdef MULTI_VALUE_STATISTICS
  4933. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4934. #endif
  4935. }
  4936. #endif /* HAVE_POLY1305 */
  4937. #ifdef HAVE_CAMELLIA
  4938. void bench_camellia(void)
  4939. {
  4940. Camellia cam;
  4941. double start;
  4942. int ret, i, count;
  4943. DECLARE_MULTI_VALUE_STATS_VARS()
  4944. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4945. if (ret != 0) {
  4946. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4947. return;
  4948. }
  4949. bench_stats_start(&count, &start);
  4950. do {
  4951. for (i = 0; i < numBlocks; i++) {
  4952. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4953. bench_size);
  4954. if (ret < 0) {
  4955. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4956. return;
  4957. }
  4958. RECORD_MULTI_VALUE_STATS();
  4959. }
  4960. count += i;
  4961. } while (bench_stats_check(start)
  4962. #ifdef MULTI_VALUE_STATISTICS
  4963. || runs < minimum_runs
  4964. #endif
  4965. );
  4966. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4967. #ifdef MULTI_VALUE_STATISTICS
  4968. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4969. #endif
  4970. }
  4971. #endif
  4972. #ifdef WOLFSSL_SM4_CBC
  4973. void bench_sm4_cbc(void)
  4974. {
  4975. wc_Sm4 sm4;
  4976. double start;
  4977. int ret;
  4978. int i;
  4979. int count;
  4980. DECLARE_MULTI_VALUE_STATS_VARS()
  4981. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4982. if (ret != 0) {
  4983. printf("Sm4SetKey failed, ret = %d\n", ret);
  4984. return;
  4985. }
  4986. ret = wc_Sm4SetIV(&sm4, bench_iv);
  4987. if (ret != 0) {
  4988. printf("Sm4SetIV failed, ret = %d\n", ret);
  4989. return;
  4990. }
  4991. bench_stats_start(&count, &start);
  4992. do {
  4993. for (i = 0; i < numBlocks; i++) {
  4994. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  4995. if (ret < 0) {
  4996. printf("Sm4CbcEncrypt failed: %d\n", ret);
  4997. return;
  4998. }
  4999. RECORD_MULTI_VALUE_STATS();
  5000. }
  5001. count += i;
  5002. } while (bench_stats_check(start)
  5003. #ifdef MULTI_VALUE_STATISTICS
  5004. || runs < minimum_runs
  5005. #endif
  5006. );
  5007. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5008. #ifdef MULTI_VALUE_STATISTICS
  5009. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5010. #endif
  5011. RESET_MULTI_VALUE_STATS_VARS();
  5012. bench_stats_start(&count, &start);
  5013. do {
  5014. for (i = 0; i < numBlocks; i++) {
  5015. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5016. if (ret < 0) {
  5017. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5018. return;
  5019. }
  5020. RECORD_MULTI_VALUE_STATS();
  5021. }
  5022. count += i;
  5023. } while (bench_stats_check(start)
  5024. #ifdef MULTI_VALUE_STATISTICS
  5025. || runs < minimum_runs
  5026. #endif
  5027. );
  5028. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5029. #ifdef MULTI_VALUE_STATISTICS
  5030. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5031. #endif
  5032. }
  5033. #endif
  5034. #ifdef WOLFSSL_SM4_GCM
  5035. void bench_sm4_gcm(void)
  5036. {
  5037. wc_Sm4 sm4;
  5038. double start;
  5039. int ret;
  5040. int i;
  5041. int count;
  5042. DECLARE_MULTI_VALUE_STATS_VARS()
  5043. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5044. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5045. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5046. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5047. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5048. if (ret != 0) {
  5049. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5050. goto exit;
  5051. }
  5052. bench_stats_start(&count, &start);
  5053. do {
  5054. for (i = 0; i < numBlocks; i++) {
  5055. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5056. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5057. bench_additional, aesAuthAddSz);
  5058. if (ret < 0) {
  5059. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5060. goto exit;
  5061. }
  5062. RECORD_MULTI_VALUE_STATS();
  5063. }
  5064. count += i;
  5065. } while (bench_stats_check(start)
  5066. #ifdef MULTI_VALUE_STATISTICS
  5067. || runs < minimum_runs
  5068. #endif
  5069. );
  5070. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5071. #ifdef MULTI_VALUE_STATISTICS
  5072. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5073. #endif
  5074. RESET_MULTI_VALUE_STATS_VARS();
  5075. bench_stats_start(&count, &start);
  5076. do {
  5077. for (i = 0; i < numBlocks; i++) {
  5078. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5079. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5080. bench_additional, aesAuthAddSz);
  5081. if (ret < 0) {
  5082. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5083. goto exit;
  5084. }
  5085. RECORD_MULTI_VALUE_STATS();
  5086. }
  5087. count += i;
  5088. } while (bench_stats_check(start)
  5089. #ifdef MULTI_VALUE_STATISTICS
  5090. || runs < minimum_runs
  5091. #endif
  5092. );
  5093. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5094. #ifdef MULTI_VALUE_STATISTICS
  5095. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5096. #endif
  5097. exit:
  5098. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5099. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5100. }
  5101. #endif
  5102. #ifdef WOLFSSL_SM4_CCM
  5103. void bench_sm4_ccm(void)
  5104. {
  5105. wc_Sm4 enc;
  5106. double start;
  5107. int ret, i, count;
  5108. DECLARE_MULTI_VALUE_STATS_VARS()
  5109. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5110. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5111. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5112. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5113. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5114. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5115. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5116. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5117. goto exit;
  5118. }
  5119. bench_stats_start(&count, &start);
  5120. do {
  5121. for (i = 0; i < numBlocks; i++) {
  5122. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5123. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5124. bench_additional, 0);
  5125. RECORD_MULTI_VALUE_STATS();
  5126. }
  5127. count += i;
  5128. } while (bench_stats_check(start)
  5129. #ifdef MULTI_VALUE_STATISTICS
  5130. || runs < minimum_runs
  5131. #endif
  5132. );
  5133. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5134. #ifdef MULTI_VALUE_STATISTICS
  5135. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5136. #endif
  5137. if (ret != 0) {
  5138. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5139. goto exit;
  5140. }
  5141. RESET_MULTI_VALUE_STATS_VARS();
  5142. bench_stats_start(&count, &start);
  5143. do {
  5144. for (i = 0; i < numBlocks; i++) {
  5145. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5146. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5147. bench_additional, 0);
  5148. RECORD_MULTI_VALUE_STATS();
  5149. }
  5150. count += i;
  5151. } while (bench_stats_check(start)
  5152. #ifdef MULTI_VALUE_STATISTICS
  5153. || runs < minimum_runs
  5154. #endif
  5155. );
  5156. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5157. #ifdef MULTI_VALUE_STATISTICS
  5158. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5159. #endif
  5160. if (ret != 0) {
  5161. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5162. goto exit;
  5163. }
  5164. exit:
  5165. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5166. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5167. }
  5168. #endif /* HAVE_AESCCM */
  5169. #ifndef NO_DES3
  5170. void bench_des(int useDeviceID)
  5171. {
  5172. int ret = 0, i, count = 0, times, pending = 0;
  5173. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5174. sizeof(Des3), HEAP_HINT);
  5175. double start;
  5176. DECLARE_MULTI_VALUE_STATS_VARS()
  5177. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5178. sizeof(Des3), HEAP_HINT);
  5179. /* init keys */
  5180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5181. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5182. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5183. printf("Des3Init failed, ret = %d\n", ret);
  5184. goto exit;
  5185. }
  5186. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5187. if (ret != 0) {
  5188. printf("Des3_SetKey failed, ret = %d\n", ret);
  5189. goto exit;
  5190. }
  5191. }
  5192. bench_stats_start(&count, &start);
  5193. do {
  5194. for (times = 0; times < numBlocks || pending > 0; ) {
  5195. bench_async_poll(&pending);
  5196. /* while free pending slots in queue, submit ops */
  5197. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5198. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5199. &times, numBlocks, &pending)) {
  5200. ret = wc_Des3_CbcEncrypt(enc[i],
  5201. bench_cipher,
  5202. bench_plain, bench_size);
  5203. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5204. 0, &times, &pending)) {
  5205. goto exit_3des;
  5206. }
  5207. }
  5208. } /* for i */
  5209. RECORD_MULTI_VALUE_STATS();
  5210. } /* for times */
  5211. count += times;
  5212. } while (bench_stats_check(start)
  5213. #ifdef MULTI_VALUE_STATISTICS
  5214. || runs < minimum_runs
  5215. #endif
  5216. );
  5217. exit_3des:
  5218. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5219. #ifdef MULTI_VALUE_STATISTICS
  5220. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5221. #endif
  5222. exit:
  5223. if (WC_ARRAY_OK(enc)) {
  5224. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5225. wc_Des3Free(enc[i]);
  5226. }
  5227. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5228. }
  5229. }
  5230. #endif /* !NO_DES3 */
  5231. #ifndef NO_RC4
  5232. void bench_arc4(int useDeviceID)
  5233. {
  5234. int ret = 0, i, count = 0, times, pending = 0;
  5235. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5236. sizeof(Arc4), HEAP_HINT);
  5237. double start;
  5238. DECLARE_MULTI_VALUE_STATS_VARS()
  5239. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5240. sizeof(Arc4), HEAP_HINT);
  5241. /* init keys */
  5242. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5243. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5244. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5245. printf("Arc4Init failed, ret = %d\n", ret);
  5246. goto exit;
  5247. }
  5248. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5249. if (ret != 0) {
  5250. printf("Arc4SetKey failed, ret = %d\n", ret);
  5251. goto exit;
  5252. }
  5253. }
  5254. bench_stats_start(&count, &start);
  5255. do {
  5256. for (times = 0; times < numBlocks || pending > 0; ) {
  5257. bench_async_poll(&pending);
  5258. /* while free pending slots in queue, submit ops */
  5259. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5260. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5261. &times, numBlocks, &pending)) {
  5262. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5263. bench_size);
  5264. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5265. 0, &times, &pending)) {
  5266. goto exit_arc4;
  5267. }
  5268. }
  5269. } /* for i */
  5270. RECORD_MULTI_VALUE_STATS();
  5271. } /* for times */
  5272. count += times;
  5273. } while (bench_stats_check(start)
  5274. #ifdef MULTI_VALUE_STATISTICS
  5275. || runs < minimum_runs
  5276. #endif
  5277. );
  5278. exit_arc4:
  5279. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5280. #ifdef MULTI_VALUE_STATISTICS
  5281. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5282. #endif
  5283. exit:
  5284. if (WC_ARRAY_OK(enc)) {
  5285. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5286. wc_Arc4Free(enc[i]);
  5287. }
  5288. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5289. }
  5290. }
  5291. #endif /* !NO_RC4 */
  5292. #ifdef HAVE_CHACHA
  5293. void bench_chacha(void)
  5294. {
  5295. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5296. double start;
  5297. int ret, i, count;
  5298. DECLARE_MULTI_VALUE_STATS_VARS()
  5299. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5300. XMEMSET(enc, 0, sizeof(ChaCha));
  5301. wc_Chacha_SetKey(enc, bench_key, 16);
  5302. if (encrypt_only) {
  5303. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5304. if (ret < 0) {
  5305. printf("wc_Chacha_SetIV error: %d\n", ret);
  5306. goto exit;
  5307. }
  5308. bench_stats_start(&count, &start);
  5309. do {
  5310. for (i = 0; i < numBlocks; i++) {
  5311. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5312. bench_size);
  5313. if (ret < 0) {
  5314. printf("wc_Chacha_Process error: %d\n", ret);
  5315. goto exit;
  5316. }
  5317. RECORD_MULTI_VALUE_STATS();
  5318. }
  5319. count += i;
  5320. } while (bench_stats_check(start)
  5321. #ifdef MULTI_VALUE_STATISTICS
  5322. || runs < minimum_runs
  5323. #endif
  5324. );
  5325. }
  5326. else {
  5327. bench_stats_start(&count, &start);
  5328. do {
  5329. for (i = 0; i < numBlocks; i++) {
  5330. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5331. if (ret < 0) {
  5332. printf("wc_Chacha_SetIV error: %d\n", ret);
  5333. goto exit;
  5334. }
  5335. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5336. bench_size);
  5337. if (ret < 0) {
  5338. printf("wc_Chacha_Process error: %d\n", ret);
  5339. goto exit;
  5340. }
  5341. RECORD_MULTI_VALUE_STATS();
  5342. }
  5343. count += i;
  5344. } while (bench_stats_check(start)
  5345. #ifdef MULTI_VALUE_STATISTICS
  5346. || runs < minimum_runs
  5347. #endif
  5348. );
  5349. }
  5350. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5351. #ifdef MULTI_VALUE_STATISTICS
  5352. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5353. #endif
  5354. exit:
  5355. WC_FREE_VAR(enc, HEAP_HINT);
  5356. }
  5357. #endif /* HAVE_CHACHA*/
  5358. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5359. void bench_chacha20_poly1305_aead(void)
  5360. {
  5361. double start;
  5362. int ret = 0, i, count;
  5363. DECLARE_MULTI_VALUE_STATS_VARS()
  5364. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5365. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5366. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5367. bench_stats_start(&count, &start);
  5368. do {
  5369. for (i = 0; i < numBlocks; i++) {
  5370. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5371. bench_plain, bench_size, bench_cipher, authTag);
  5372. if (ret < 0) {
  5373. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5374. goto exit;
  5375. }
  5376. RECORD_MULTI_VALUE_STATS();
  5377. }
  5378. count += i;
  5379. } while (bench_stats_check(start)
  5380. #ifdef MULTI_VALUE_STATISTICS
  5381. || runs < minimum_runs
  5382. #endif
  5383. );
  5384. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5385. #ifdef MULTI_VALUE_STATISTICS
  5386. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5387. #endif
  5388. exit:
  5389. WC_FREE_VAR(authTag, HEAP_HINT);
  5390. }
  5391. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5392. #ifndef NO_MD5
  5393. void bench_md5(int useDeviceID)
  5394. {
  5395. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5396. sizeof(wc_Md5), HEAP_HINT);
  5397. double start = 0;
  5398. int ret = 0, i, count = 0, times, pending = 0;
  5399. DECLARE_MULTI_VALUE_STATS_VARS()
  5400. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5401. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5402. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5403. sizeof(wc_Md5), HEAP_HINT);
  5404. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5405. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5406. if (digest_stream) {
  5407. /* init keys */
  5408. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5409. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5410. useDeviceID ? devId : INVALID_DEVID);
  5411. if (ret != 0) {
  5412. printf("InitMd5_ex failed, ret = %d\n", ret);
  5413. goto exit;
  5414. }
  5415. #ifdef WOLFSSL_PIC32MZ_HASH
  5416. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5417. #endif
  5418. }
  5419. bench_stats_start(&count, &start);
  5420. do {
  5421. for (times = 0; times < numBlocks || pending > 0; ) {
  5422. bench_async_poll(&pending);
  5423. /* while free pending slots in queue, submit ops */
  5424. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5425. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5426. 0, &times, numBlocks, &pending)) {
  5427. ret = wc_Md5Update(hash[i], bench_plain,
  5428. bench_size);
  5429. if (!bench_async_handle(&ret,
  5430. BENCH_ASYNC_GET_DEV(hash[i]),
  5431. 0, &times, &pending)) {
  5432. goto exit_md5;
  5433. }
  5434. }
  5435. } /* for i */
  5436. RECORD_MULTI_VALUE_STATS();
  5437. } /* for times */
  5438. count += times;
  5439. times = 0;
  5440. do {
  5441. bench_async_poll(&pending);
  5442. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5443. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5444. 0, &times, numBlocks, &pending)) {
  5445. ret = wc_Md5Final(hash[i], digest[i]);
  5446. if (!bench_async_handle(&ret,
  5447. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5448. &times, &pending)) {
  5449. goto exit_md5;
  5450. }
  5451. }
  5452. } /* for i */
  5453. } while (pending > 0);
  5454. } while (bench_stats_check(start)
  5455. #ifdef MULTI_VALUE_STATISTICS
  5456. || runs < minimum_runs
  5457. #endif
  5458. );
  5459. }
  5460. else {
  5461. bench_stats_start(&count, &start);
  5462. do {
  5463. for (times = 0; times < numBlocks; times++) {
  5464. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5465. if (ret == 0)
  5466. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5467. if (ret == 0)
  5468. ret = wc_Md5Final(hash[0], digest[0]);
  5469. if (ret != 0)
  5470. goto exit_md5;
  5471. RECORD_MULTI_VALUE_STATS();
  5472. } /* for times */
  5473. count += times;
  5474. } while (bench_stats_check(start)
  5475. #ifdef MULTI_VALUE_STATISTICS
  5476. || runs < minimum_runs
  5477. #endif
  5478. );
  5479. }
  5480. exit_md5:
  5481. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5482. #ifdef MULTI_VALUE_STATISTICS
  5483. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5484. #endif
  5485. exit:
  5486. #ifdef WOLFSSL_ASYNC_CRYPT
  5487. if (WC_ARRAY_OK(hash)) {
  5488. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5489. wc_Md5Free(hash[i]);
  5490. }
  5491. }
  5492. #endif
  5493. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5494. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5495. }
  5496. #endif /* !NO_MD5 */
  5497. #ifndef NO_SHA
  5498. void bench_sha(int useDeviceID)
  5499. {
  5500. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5501. sizeof(wc_Sha), HEAP_HINT);
  5502. double start;
  5503. int ret = 0, i, count = 0, times, pending = 0;
  5504. DECLARE_MULTI_VALUE_STATS_VARS()
  5505. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5506. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5507. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5508. sizeof(wc_Sha), HEAP_HINT);
  5509. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5510. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5511. if (digest_stream) {
  5512. /* init keys */
  5513. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5514. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5515. useDeviceID ? devId : INVALID_DEVID);
  5516. if (ret != 0) {
  5517. printf("InitSha failed, ret = %d\n", ret);
  5518. goto exit;
  5519. }
  5520. #ifdef WOLFSSL_PIC32MZ_HASH
  5521. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5522. #endif
  5523. }
  5524. bench_stats_start(&count, &start);
  5525. do {
  5526. for (times = 0; times < numBlocks || pending > 0; ) {
  5527. bench_async_poll(&pending);
  5528. /* while free pending slots in queue, submit ops */
  5529. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5530. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5531. 0, &times, numBlocks, &pending)) {
  5532. ret = wc_ShaUpdate(hash[i], bench_plain,
  5533. bench_size);
  5534. if (!bench_async_handle(&ret,
  5535. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5536. &times, &pending)) {
  5537. goto exit_sha;
  5538. }
  5539. }
  5540. } /* for i */
  5541. RECORD_MULTI_VALUE_STATS();
  5542. } /* for times */
  5543. count += times;
  5544. times = 0;
  5545. do {
  5546. bench_async_poll(&pending);
  5547. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5548. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5549. 0, &times, numBlocks, &pending)) {
  5550. ret = wc_ShaFinal(hash[i], digest[i]);
  5551. if (!bench_async_handle(&ret,
  5552. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5553. &times, &pending)) {
  5554. goto exit_sha;
  5555. }
  5556. }
  5557. } /* for i */
  5558. } while (pending > 0);
  5559. } while (bench_stats_check(start)
  5560. #ifdef MULTI_VALUE_STATISTICS
  5561. || runs < minimum_runs
  5562. #endif
  5563. );
  5564. }
  5565. else {
  5566. bench_stats_start(&count, &start);
  5567. do {
  5568. for (times = 0; times < numBlocks; times++) {
  5569. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5570. useDeviceID ? devId : INVALID_DEVID);
  5571. if (ret == 0)
  5572. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5573. if (ret == 0)
  5574. ret = wc_ShaFinal(hash[0], digest[0]);
  5575. if (ret != 0)
  5576. goto exit_sha;
  5577. RECORD_MULTI_VALUE_STATS();
  5578. } /* for times */
  5579. count += times;
  5580. } while (bench_stats_check(start)
  5581. #ifdef MULTI_VALUE_STATISTICS
  5582. || runs < minimum_runs
  5583. #endif
  5584. );
  5585. }
  5586. exit_sha:
  5587. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5588. #ifdef MULTI_VALUE_STATISTICS
  5589. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5590. #endif
  5591. exit:
  5592. if (WC_ARRAY_OK(hash)) {
  5593. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5594. wc_ShaFree(hash[i]);
  5595. }
  5596. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5597. }
  5598. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5599. }
  5600. #endif /* NO_SHA */
  5601. #ifdef WOLFSSL_SHA224
  5602. void bench_sha224(int useDeviceID)
  5603. {
  5604. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5605. sizeof(wc_Sha224), HEAP_HINT);
  5606. double start;
  5607. int ret = 0, i, count = 0, times, pending = 0;
  5608. DECLARE_MULTI_VALUE_STATS_VARS()
  5609. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5610. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5611. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5612. sizeof(wc_Sha224), HEAP_HINT);
  5613. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5614. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5615. if (digest_stream) {
  5616. /* init keys */
  5617. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5618. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5619. useDeviceID ? devId : INVALID_DEVID);
  5620. if (ret != 0) {
  5621. printf("InitSha224_ex failed, ret = %d\n", ret);
  5622. goto exit;
  5623. }
  5624. }
  5625. bench_stats_start(&count, &start);
  5626. do {
  5627. for (times = 0; times < numBlocks || pending > 0; ) {
  5628. bench_async_poll(&pending);
  5629. /* while free pending slots in queue, submit ops */
  5630. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5631. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5632. 0, &times, numBlocks, &pending)) {
  5633. ret = wc_Sha224Update(hash[i], bench_plain,
  5634. bench_size);
  5635. if (!bench_async_handle(&ret,
  5636. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5637. &times, &pending)) {
  5638. goto exit_sha224;
  5639. }
  5640. }
  5641. } /* for i */
  5642. RECORD_MULTI_VALUE_STATS();
  5643. } /* for times */
  5644. count += times;
  5645. times = 0;
  5646. do {
  5647. bench_async_poll(&pending);
  5648. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5649. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5650. 0, &times, numBlocks, &pending)) {
  5651. ret = wc_Sha224Final(hash[i], digest[i]);
  5652. if (!bench_async_handle(&ret,
  5653. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5654. &times, &pending)) {
  5655. goto exit_sha224;
  5656. }
  5657. }
  5658. } /* for i */
  5659. } while (pending > 0);
  5660. } while (bench_stats_check(start)
  5661. #ifdef MULTI_VALUE_STATISTICS
  5662. || runs < minimum_runs
  5663. #endif
  5664. );
  5665. }
  5666. else {
  5667. bench_stats_start(&count, &start);
  5668. do {
  5669. for (times = 0; times < numBlocks; times++) {
  5670. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5671. useDeviceID ? devId : INVALID_DEVID);
  5672. if (ret == 0)
  5673. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5674. if (ret == 0)
  5675. ret = wc_Sha224Final(hash[0], digest[0]);
  5676. if (ret != 0)
  5677. goto exit_sha224;
  5678. } /* for times */
  5679. count += times;
  5680. } while (bench_stats_check(start)
  5681. #ifdef MULTI_VALUE_STATISTICS
  5682. || runs < minimum_runs
  5683. #endif
  5684. );
  5685. }
  5686. exit_sha224:
  5687. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5688. bench_size, start, ret);
  5689. #ifdef MULTI_VALUE_STATISTICS
  5690. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5691. #endif
  5692. exit:
  5693. if (WC_ARRAY_OK(hash)) {
  5694. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5695. wc_Sha224Free(hash[i]);
  5696. }
  5697. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5698. }
  5699. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5700. }
  5701. #endif
  5702. #ifndef NO_SHA256
  5703. void bench_sha256(int useDeviceID)
  5704. {
  5705. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5706. sizeof(wc_Sha256), HEAP_HINT);
  5707. double start;
  5708. int ret = 0, i, count = 0, times, pending = 0;
  5709. DECLARE_MULTI_VALUE_STATS_VARS()
  5710. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5711. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5712. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5713. sizeof(wc_Sha256), HEAP_HINT);
  5714. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5715. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5716. if (digest_stream) {
  5717. /* init keys */
  5718. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5719. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5720. useDeviceID ? devId: INVALID_DEVID);
  5721. if (ret != 0) {
  5722. printf("InitSha256_ex failed, ret = %d\n", ret);
  5723. goto exit;
  5724. }
  5725. #ifdef WOLFSSL_PIC32MZ_HASH
  5726. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5727. #endif
  5728. }
  5729. bench_stats_start(&count, &start);
  5730. do {
  5731. for (times = 0; times < numBlocks || pending > 0; ) {
  5732. bench_async_poll(&pending);
  5733. /* while free pending slots in queue, submit ops */
  5734. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5735. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5736. 0, &times, numBlocks, &pending)) {
  5737. ret = wc_Sha256Update(hash[i], bench_plain,
  5738. bench_size);
  5739. if (!bench_async_handle(&ret,
  5740. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5741. &times, &pending)) {
  5742. goto exit_sha256;
  5743. }
  5744. }
  5745. } /* for i */
  5746. RECORD_MULTI_VALUE_STATS();
  5747. } /* for times */
  5748. count += times;
  5749. times = 0;
  5750. do {
  5751. bench_async_poll(&pending);
  5752. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5753. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5754. 0, &times, numBlocks, &pending)) {
  5755. ret = wc_Sha256Final(hash[i], digest[i]);
  5756. if (!bench_async_handle(&ret,
  5757. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5758. &times, &pending)) {
  5759. goto exit_sha256;
  5760. }
  5761. }
  5762. } /* for i */
  5763. } while (pending > 0);
  5764. } while (bench_stats_check(start)
  5765. #ifdef MULTI_VALUE_STATISTICS
  5766. || runs < minimum_runs
  5767. #endif
  5768. );
  5769. }
  5770. else {
  5771. bench_stats_start(&count, &start);
  5772. do {
  5773. for (times = 0; times < numBlocks; times++) {
  5774. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5775. useDeviceID ? devId: INVALID_DEVID);
  5776. if (ret == 0)
  5777. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5778. if (ret == 0)
  5779. ret = wc_Sha256Final(hash[0], digest[0]);
  5780. if (ret != 0)
  5781. goto exit_sha256;
  5782. RECORD_MULTI_VALUE_STATS();
  5783. } /* for times */
  5784. count += times;
  5785. } while (bench_stats_check(start)
  5786. #ifdef MULTI_VALUE_STATISTICS
  5787. || runs < minimum_runs
  5788. #endif
  5789. );
  5790. }
  5791. exit_sha256:
  5792. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5793. start, ret);
  5794. #ifdef MULTI_VALUE_STATISTICS
  5795. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5796. #endif
  5797. exit:
  5798. if (WC_ARRAY_OK(hash)) {
  5799. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5800. wc_Sha256Free(hash[i]);
  5801. }
  5802. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5803. }
  5804. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5805. }
  5806. #endif
  5807. #ifdef WOLFSSL_SHA384
  5808. void bench_sha384(int useDeviceID)
  5809. {
  5810. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5811. sizeof(wc_Sha384), HEAP_HINT);
  5812. double start;
  5813. int ret = 0, i, count = 0, times, pending = 0;
  5814. DECLARE_MULTI_VALUE_STATS_VARS()
  5815. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5816. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5817. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5818. sizeof(wc_Sha384), HEAP_HINT);
  5819. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5820. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5821. if (digest_stream) {
  5822. /* init keys */
  5823. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5824. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5825. useDeviceID ? devId : INVALID_DEVID);
  5826. if (ret != 0) {
  5827. printf("InitSha384_ex failed, ret = %d\n", ret);
  5828. goto exit;
  5829. }
  5830. }
  5831. bench_stats_start(&count, &start);
  5832. do {
  5833. for (times = 0; times < numBlocks || pending > 0; ) {
  5834. bench_async_poll(&pending);
  5835. /* while free pending slots in queue, submit ops */
  5836. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5837. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5838. 0, &times, numBlocks, &pending)) {
  5839. ret = wc_Sha384Update(hash[i], bench_plain,
  5840. bench_size);
  5841. if (!bench_async_handle(&ret,
  5842. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5843. &times, &pending)) {
  5844. goto exit_sha384;
  5845. }
  5846. }
  5847. } /* for i */
  5848. RECORD_MULTI_VALUE_STATS();
  5849. } /* for times */
  5850. count += times;
  5851. times = 0;
  5852. do {
  5853. bench_async_poll(&pending);
  5854. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5855. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5856. 0, &times, numBlocks, &pending)) {
  5857. ret = wc_Sha384Final(hash[i], digest[i]);
  5858. if (!bench_async_handle(&ret,
  5859. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5860. &times, &pending)) {
  5861. goto exit_sha384;
  5862. }
  5863. }
  5864. } /* for i */
  5865. } while (pending > 0);
  5866. } while (bench_stats_check(start)
  5867. #ifdef MULTI_VALUE_STATISTICS
  5868. || runs < minimum_runs
  5869. #endif
  5870. );
  5871. }
  5872. else {
  5873. bench_stats_start(&count, &start);
  5874. do {
  5875. for (times = 0; times < numBlocks; times++) {
  5876. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5877. useDeviceID ? devId : INVALID_DEVID);
  5878. if (ret == 0)
  5879. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5880. if (ret == 0)
  5881. ret = wc_Sha384Final(hash[0], digest[0]);
  5882. if (ret != 0)
  5883. goto exit_sha384;
  5884. RECORD_MULTI_VALUE_STATS();
  5885. } /* for times */
  5886. count += times;
  5887. } while (bench_stats_check(start)
  5888. #ifdef MULTI_VALUE_STATISTICS
  5889. || runs < minimum_runs
  5890. #endif
  5891. );
  5892. }
  5893. exit_sha384:
  5894. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5895. start, ret);
  5896. #ifdef MULTI_VALUE_STATISTICS
  5897. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5898. #endif
  5899. exit:
  5900. if (WC_ARRAY_OK(hash)) {
  5901. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5902. wc_Sha384Free(hash[i]);
  5903. }
  5904. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5905. }
  5906. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5907. }
  5908. #endif
  5909. #ifdef WOLFSSL_SHA512
  5910. void bench_sha512(int useDeviceID)
  5911. {
  5912. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5913. sizeof(wc_Sha512), HEAP_HINT);
  5914. double start;
  5915. int ret = 0, i, count = 0, times, pending = 0;
  5916. DECLARE_MULTI_VALUE_STATS_VARS()
  5917. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5918. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5919. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5920. sizeof(wc_Sha512), HEAP_HINT);
  5921. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5922. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5923. if (digest_stream) {
  5924. /* init keys */
  5925. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5926. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5927. useDeviceID ? devId : INVALID_DEVID);
  5928. if (ret != 0) {
  5929. printf("InitSha512_ex failed, ret = %d\n", ret);
  5930. goto exit;
  5931. }
  5932. }
  5933. bench_stats_start(&count, &start);
  5934. do {
  5935. for (times = 0; times < numBlocks || pending > 0; ) {
  5936. bench_async_poll(&pending);
  5937. /* while free pending slots in queue, submit ops */
  5938. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5939. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5940. 0, &times, numBlocks, &pending)) {
  5941. ret = wc_Sha512Update(hash[i], bench_plain,
  5942. bench_size);
  5943. if (!bench_async_handle(&ret,
  5944. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5945. &times, &pending)) {
  5946. goto exit_sha512;
  5947. }
  5948. }
  5949. } /* for i */
  5950. RECORD_MULTI_VALUE_STATS();
  5951. } /* for times */
  5952. count += times;
  5953. times = 0;
  5954. do {
  5955. bench_async_poll(&pending);
  5956. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5957. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5958. 0, &times, numBlocks, &pending)) {
  5959. ret = wc_Sha512Final(hash[i], digest[i]);
  5960. if (!bench_async_handle(&ret,
  5961. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5962. &times, &pending)) {
  5963. goto exit_sha512;
  5964. }
  5965. }
  5966. } /* for i */
  5967. } while (pending > 0);
  5968. } while (bench_stats_check(start)
  5969. #ifdef MULTI_VALUE_STATISTICS
  5970. || runs < minimum_runs
  5971. #endif
  5972. );
  5973. }
  5974. else {
  5975. bench_stats_start(&count, &start);
  5976. do {
  5977. for (times = 0; times < numBlocks; times++) {
  5978. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5979. useDeviceID ? devId : INVALID_DEVID);
  5980. if (ret == 0)
  5981. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  5982. if (ret == 0)
  5983. ret = wc_Sha512Final(hash[0], digest[0]);
  5984. if (ret != 0)
  5985. goto exit_sha512;
  5986. RECORD_MULTI_VALUE_STATS();
  5987. } /* for times */
  5988. count += times;
  5989. } while (bench_stats_check(start)
  5990. #ifdef MULTI_VALUE_STATISTICS
  5991. || runs < minimum_runs
  5992. #endif
  5993. );
  5994. }
  5995. exit_sha512:
  5996. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  5997. start, ret);
  5998. #ifdef MULTI_VALUE_STATISTICS
  5999. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6000. #endif
  6001. exit:
  6002. if (WC_ARRAY_OK(hash)) {
  6003. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6004. wc_Sha512Free(hash[i]);
  6005. }
  6006. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6007. }
  6008. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6009. }
  6010. #if !defined(WOLFSSL_NOSHA512_224) && \
  6011. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6012. void bench_sha512_224(int useDeviceID)
  6013. {
  6014. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6015. sizeof(wc_Sha512_224), HEAP_HINT);
  6016. double start;
  6017. int ret = 0, i, count = 0, times, pending = 0;
  6018. DECLARE_MULTI_VALUE_STATS_VARS()
  6019. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6020. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6021. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6022. sizeof(wc_Sha512_224), HEAP_HINT);
  6023. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6024. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6025. if (digest_stream) {
  6026. /* init keys */
  6027. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6028. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6029. useDeviceID ? devId : INVALID_DEVID);
  6030. if (ret != 0) {
  6031. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6032. goto exit;
  6033. }
  6034. }
  6035. bench_stats_start(&count, &start);
  6036. do {
  6037. for (times = 0; times < numBlocks || pending > 0; ) {
  6038. bench_async_poll(&pending);
  6039. /* while free pending slots in queue, submit ops */
  6040. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6041. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6042. 0, &times, numBlocks, &pending)) {
  6043. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6044. bench_size);
  6045. if (!bench_async_handle(&ret,
  6046. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6047. &times, &pending)) {
  6048. goto exit_sha512_224;
  6049. }
  6050. }
  6051. } /* for i */
  6052. RECORD_MULTI_VALUE_STATS();
  6053. } /* for times */
  6054. count += times;
  6055. times = 0;
  6056. do {
  6057. bench_async_poll(&pending);
  6058. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6059. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6060. 0, &times, numBlocks, &pending)) {
  6061. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6062. if (!bench_async_handle(&ret,
  6063. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6064. &times, &pending)) {
  6065. goto exit_sha512_224;
  6066. }
  6067. }
  6068. } /* for i */
  6069. } while (pending > 0);
  6070. } while (bench_stats_check(start)
  6071. #ifdef MULTI_VALUE_STATISTICS
  6072. || runs < minimum_runs
  6073. #endif
  6074. );
  6075. }
  6076. else {
  6077. bench_stats_start(&count, &start);
  6078. do {
  6079. for (times = 0; times < numBlocks; times++) {
  6080. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6081. useDeviceID ? devId : INVALID_DEVID);
  6082. if (ret == 0)
  6083. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6084. if (ret == 0)
  6085. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6086. if (ret != 0)
  6087. goto exit_sha512_224;
  6088. RECORD_MULTI_VALUE_STATS();
  6089. } /* for times */
  6090. count += times;
  6091. } while (bench_stats_check(start)
  6092. #ifdef MULTI_VALUE_STATISTICS
  6093. || runs < minimum_runs
  6094. #endif
  6095. );
  6096. }
  6097. exit_sha512_224:
  6098. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6099. start, ret);
  6100. #ifdef MULTI_VALUE_STATISTICS
  6101. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6102. #endif
  6103. exit:
  6104. if (WC_ARRAY_OK(hash)) {
  6105. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6106. wc_Sha512_224Free(hash[i]);
  6107. }
  6108. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6109. }
  6110. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6111. }
  6112. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6113. #if !defined(WOLFSSL_NOSHA512_256) && \
  6114. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6115. void bench_sha512_256(int useDeviceID)
  6116. {
  6117. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6118. sizeof(wc_Sha512_256), HEAP_HINT);
  6119. double start;
  6120. int ret = 0, i, count = 0, times, pending = 0;
  6121. DECLARE_MULTI_VALUE_STATS_VARS()
  6122. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6123. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6124. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6125. sizeof(wc_Sha512_256), HEAP_HINT);
  6126. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6127. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6128. if (digest_stream) {
  6129. /* init keys */
  6130. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6131. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6132. useDeviceID ? devId : INVALID_DEVID);
  6133. if (ret != 0) {
  6134. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6135. goto exit;
  6136. }
  6137. }
  6138. bench_stats_start(&count, &start);
  6139. do {
  6140. for (times = 0; times < numBlocks || pending > 0; ) {
  6141. bench_async_poll(&pending);
  6142. /* while free pending slots in queue, submit ops */
  6143. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6144. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6145. 0, &times, numBlocks, &pending)) {
  6146. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6147. bench_size);
  6148. if (!bench_async_handle(&ret,
  6149. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6150. &times, &pending)) {
  6151. goto exit_sha512_256;
  6152. }
  6153. }
  6154. } /* for i */
  6155. RECORD_MULTI_VALUE_STATS();
  6156. } /* for times */
  6157. count += times;
  6158. times = 0;
  6159. do {
  6160. bench_async_poll(&pending);
  6161. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6162. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6163. 0, &times, numBlocks, &pending)) {
  6164. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6165. if (!bench_async_handle(&ret,
  6166. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6167. &times, &pending)) {
  6168. goto exit_sha512_256;
  6169. }
  6170. }
  6171. } /* for i */
  6172. } while (pending > 0);
  6173. } while (bench_stats_check(start)
  6174. #ifdef MULTI_VALUE_STATISTICS
  6175. || runs < minimum_runs
  6176. #endif
  6177. );
  6178. }
  6179. else {
  6180. bench_stats_start(&count, &start);
  6181. do {
  6182. for (times = 0; times < numBlocks; times++) {
  6183. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6184. useDeviceID ? devId : INVALID_DEVID);
  6185. if (ret == 0)
  6186. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6187. if (ret == 0)
  6188. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6189. if (ret != 0)
  6190. goto exit_sha512_256;
  6191. RECORD_MULTI_VALUE_STATS();
  6192. } /* for times */
  6193. count += times;
  6194. } while (bench_stats_check(start)
  6195. #ifdef MULTI_VALUE_STATISTICS
  6196. || runs < minimum_runs
  6197. #endif
  6198. );
  6199. }
  6200. exit_sha512_256:
  6201. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6202. start, ret);
  6203. #ifdef MULTI_VALUE_STATISTICS
  6204. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6205. #endif
  6206. exit:
  6207. if (WC_ARRAY_OK(hash)) {
  6208. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6209. wc_Sha512_256Free(hash[i]);
  6210. }
  6211. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6212. }
  6213. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6214. }
  6215. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6216. #endif /* WOLFSSL_SHA512 */
  6217. #ifdef WOLFSSL_SHA3
  6218. #ifndef WOLFSSL_NOSHA3_224
  6219. void bench_sha3_224(int useDeviceID)
  6220. {
  6221. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6222. sizeof(wc_Sha3), HEAP_HINT);
  6223. double start;
  6224. int ret = 0, i, count = 0, times, pending = 0;
  6225. DECLARE_MULTI_VALUE_STATS_VARS()
  6226. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6227. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6228. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6229. sizeof(wc_Sha3), HEAP_HINT);
  6230. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6231. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6232. if (digest_stream) {
  6233. /* init keys */
  6234. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6235. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6236. useDeviceID ? devId : INVALID_DEVID);
  6237. if (ret != 0) {
  6238. printf("InitSha3_224 failed, ret = %d\n", ret);
  6239. goto exit;
  6240. }
  6241. }
  6242. bench_stats_start(&count, &start);
  6243. do {
  6244. for (times = 0; times < numBlocks || pending > 0; ) {
  6245. bench_async_poll(&pending);
  6246. /* while free pending slots in queue, submit ops */
  6247. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6248. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6249. 0, &times, numBlocks, &pending)) {
  6250. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6251. bench_size);
  6252. if (!bench_async_handle(&ret,
  6253. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6254. &times, &pending)) {
  6255. goto exit_sha3_224;
  6256. }
  6257. }
  6258. } /* for i */
  6259. RECORD_MULTI_VALUE_STATS();
  6260. } /* for times */
  6261. count += times;
  6262. times = 0;
  6263. do {
  6264. bench_async_poll(&pending);
  6265. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6266. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6267. 0, &times, numBlocks, &pending)) {
  6268. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6269. if (!bench_async_handle(&ret,
  6270. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6271. &times, &pending)) {
  6272. goto exit_sha3_224;
  6273. }
  6274. }
  6275. } /* for i */
  6276. } while (pending > 0);
  6277. } while (bench_stats_check(start)
  6278. #ifdef MULTI_VALUE_STATISTICS
  6279. || runs < minimum_runs
  6280. #endif
  6281. );
  6282. }
  6283. else {
  6284. bench_stats_start(&count, &start);
  6285. do {
  6286. for (times = 0; times < numBlocks; times++) {
  6287. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6288. useDeviceID ? devId : INVALID_DEVID);
  6289. if (ret == 0)
  6290. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6291. if (ret == 0)
  6292. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6293. if (ret != 0)
  6294. goto exit_sha3_224;
  6295. RECORD_MULTI_VALUE_STATS();
  6296. } /* for times */
  6297. count += times;
  6298. } while (bench_stats_check(start)
  6299. #ifdef MULTI_VALUE_STATISTICS
  6300. || runs < minimum_runs
  6301. #endif
  6302. );
  6303. }
  6304. exit_sha3_224:
  6305. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6306. start, ret);
  6307. #ifdef MULTI_VALUE_STATISTICS
  6308. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6309. #endif
  6310. exit:
  6311. if (WC_ARRAY_OK(hash)) {
  6312. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6313. wc_Sha3_224_Free(hash[i]);
  6314. }
  6315. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6316. }
  6317. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6318. }
  6319. #endif /* WOLFSSL_NOSHA3_224 */
  6320. #ifndef WOLFSSL_NOSHA3_256
  6321. void bench_sha3_256(int useDeviceID)
  6322. {
  6323. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6324. sizeof(wc_Sha3), HEAP_HINT);
  6325. double start;
  6326. DECLARE_MULTI_VALUE_STATS_VARS()
  6327. int ret = 0, i, count = 0, times, pending = 0;
  6328. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6329. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6330. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6331. sizeof(wc_Sha3), HEAP_HINT);
  6332. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6333. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6334. if (digest_stream) {
  6335. /* init keys */
  6336. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6337. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6338. useDeviceID ? devId : INVALID_DEVID);
  6339. if (ret != 0) {
  6340. printf("InitSha3_256 failed, ret = %d\n", ret);
  6341. goto exit;
  6342. }
  6343. }
  6344. bench_stats_start(&count, &start);
  6345. do {
  6346. for (times = 0; times < numBlocks || pending > 0; ) {
  6347. bench_async_poll(&pending);
  6348. /* while free pending slots in queue, submit ops */
  6349. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6350. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6351. 0, &times, numBlocks, &pending)) {
  6352. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6353. bench_size);
  6354. if (!bench_async_handle(&ret,
  6355. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6356. &times, &pending)) {
  6357. goto exit_sha3_256;
  6358. }
  6359. }
  6360. } /* for i */
  6361. RECORD_MULTI_VALUE_STATS();
  6362. } /* for times */
  6363. count += times;
  6364. times = 0;
  6365. do {
  6366. bench_async_poll(&pending);
  6367. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6368. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6369. 0, &times, numBlocks, &pending)) {
  6370. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6371. if (!bench_async_handle(&ret,
  6372. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6373. &times, &pending)) {
  6374. goto exit_sha3_256;
  6375. }
  6376. }
  6377. } /* for i */
  6378. } while (pending > 0);
  6379. } while (bench_stats_check(start)
  6380. #ifdef MULTI_VALUE_STATISTICS
  6381. || runs < minimum_runs
  6382. #endif
  6383. );
  6384. }
  6385. else {
  6386. bench_stats_start(&count, &start);
  6387. do {
  6388. for (times = 0; times < numBlocks; times++) {
  6389. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6390. useDeviceID ? devId : INVALID_DEVID);
  6391. if (ret == 0)
  6392. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6393. if (ret == 0)
  6394. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6395. if (ret != 0)
  6396. goto exit_sha3_256;
  6397. RECORD_MULTI_VALUE_STATS();
  6398. } /* for times */
  6399. count += times;
  6400. } while (bench_stats_check(start)
  6401. #ifdef MULTI_VALUE_STATISTICS
  6402. || runs < minimum_runs
  6403. #endif
  6404. );
  6405. }
  6406. exit_sha3_256:
  6407. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6408. start, ret);
  6409. #ifdef MULTI_VALUE_STATISTICS
  6410. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6411. #endif
  6412. exit:
  6413. if (WC_ARRAY_OK(hash)) {
  6414. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6415. wc_Sha3_256_Free(hash[i]);
  6416. }
  6417. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6418. }
  6419. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6420. }
  6421. #endif /* WOLFSSL_NOSHA3_256 */
  6422. #ifndef WOLFSSL_NOSHA3_384
  6423. void bench_sha3_384(int useDeviceID)
  6424. {
  6425. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6426. sizeof(wc_Sha3), HEAP_HINT);
  6427. double start;
  6428. int ret = 0, i, count = 0, times, pending = 0;
  6429. DECLARE_MULTI_VALUE_STATS_VARS()
  6430. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6431. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6432. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6433. sizeof(wc_Sha3), HEAP_HINT);
  6434. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6435. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6436. if (digest_stream) {
  6437. /* init keys */
  6438. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6439. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6440. useDeviceID ? devId : INVALID_DEVID);
  6441. if (ret != 0) {
  6442. printf("InitSha3_384 failed, ret = %d\n", ret);
  6443. goto exit;
  6444. }
  6445. }
  6446. bench_stats_start(&count, &start);
  6447. do {
  6448. for (times = 0; times < numBlocks || pending > 0; ) {
  6449. bench_async_poll(&pending);
  6450. /* while free pending slots in queue, submit ops */
  6451. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6452. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6453. 0, &times, numBlocks, &pending)) {
  6454. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6455. bench_size);
  6456. if (!bench_async_handle(&ret,
  6457. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6458. &times, &pending)) {
  6459. goto exit_sha3_384;
  6460. }
  6461. }
  6462. } /* for i */
  6463. RECORD_MULTI_VALUE_STATS();
  6464. } /* for times */
  6465. count += times;
  6466. times = 0;
  6467. do {
  6468. bench_async_poll(&pending);
  6469. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6470. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6471. 0, &times, numBlocks, &pending)) {
  6472. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6473. if (!bench_async_handle(&ret,
  6474. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6475. &times, &pending)) {
  6476. goto exit_sha3_384;
  6477. }
  6478. }
  6479. } /* for i */
  6480. } while (pending > 0);
  6481. } while (bench_stats_check(start)
  6482. #ifdef MULTI_VALUE_STATISTICS
  6483. || runs < minimum_runs
  6484. #endif
  6485. );
  6486. }
  6487. else {
  6488. bench_stats_start(&count, &start);
  6489. do {
  6490. for (times = 0; times < numBlocks; times++) {
  6491. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6492. useDeviceID ? devId : INVALID_DEVID);
  6493. if (ret == 0)
  6494. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6495. if (ret == 0)
  6496. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6497. if (ret != 0)
  6498. goto exit_sha3_384;
  6499. RECORD_MULTI_VALUE_STATS();
  6500. } /* for times */
  6501. count += times;
  6502. } while (bench_stats_check(start)
  6503. #ifdef MULTI_VALUE_STATISTICS
  6504. || runs < minimum_runs
  6505. #endif
  6506. );
  6507. }
  6508. exit_sha3_384:
  6509. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6510. start, ret);
  6511. #ifdef MULTI_VALUE_STATISTICS
  6512. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6513. #endif
  6514. exit:
  6515. if (WC_ARRAY_OK(hash)) {
  6516. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6517. wc_Sha3_384_Free(hash[i]);
  6518. }
  6519. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6520. }
  6521. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6522. }
  6523. #endif /* WOLFSSL_NOSHA3_384 */
  6524. #ifndef WOLFSSL_NOSHA3_512
  6525. void bench_sha3_512(int useDeviceID)
  6526. {
  6527. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6528. sizeof(wc_Sha3), HEAP_HINT);
  6529. double start;
  6530. int ret = 0, i, count = 0, times, pending = 0;
  6531. DECLARE_MULTI_VALUE_STATS_VARS()
  6532. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6533. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6534. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6535. sizeof(wc_Sha3), HEAP_HINT);
  6536. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6537. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6538. if (digest_stream) {
  6539. /* init keys */
  6540. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6541. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6542. useDeviceID ? devId : INVALID_DEVID);
  6543. if (ret != 0) {
  6544. printf("InitSha3_512 failed, ret = %d\n", ret);
  6545. goto exit;
  6546. }
  6547. }
  6548. bench_stats_start(&count, &start);
  6549. do {
  6550. for (times = 0; times < numBlocks || pending > 0; ) {
  6551. bench_async_poll(&pending);
  6552. /* while free pending slots in queue, submit ops */
  6553. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6554. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6555. 0, &times, numBlocks, &pending)) {
  6556. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6557. bench_size);
  6558. if (!bench_async_handle(&ret,
  6559. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6560. &times, &pending)) {
  6561. goto exit_sha3_512;
  6562. }
  6563. }
  6564. } /* for i */
  6565. RECORD_MULTI_VALUE_STATS();
  6566. } /* for times */
  6567. count += times;
  6568. times = 0;
  6569. do {
  6570. bench_async_poll(&pending);
  6571. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6572. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6573. 0, &times, numBlocks, &pending)) {
  6574. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6575. if (!bench_async_handle(&ret,
  6576. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6577. &times, &pending)) {
  6578. goto exit_sha3_512;
  6579. }
  6580. }
  6581. } /* for i */
  6582. } while (pending > 0);
  6583. } while (bench_stats_check(start)
  6584. #ifdef MULTI_VALUE_STATISTICS
  6585. || runs < minimum_runs
  6586. #endif
  6587. );
  6588. }
  6589. else {
  6590. bench_stats_start(&count, &start);
  6591. do {
  6592. for (times = 0; times < numBlocks; times++) {
  6593. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6594. useDeviceID ? devId : INVALID_DEVID);
  6595. if (ret == 0)
  6596. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6597. if (ret == 0)
  6598. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6599. if (ret != 0)
  6600. goto exit_sha3_512;
  6601. RECORD_MULTI_VALUE_STATS();
  6602. } /* for times */
  6603. count += times;
  6604. } while (bench_stats_check(start)
  6605. #ifdef MULTI_VALUE_STATISTICS
  6606. || runs < minimum_runs
  6607. #endif
  6608. );
  6609. }
  6610. exit_sha3_512:
  6611. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6612. start, ret);
  6613. #ifdef MULTI_VALUE_STATISTICS
  6614. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6615. #endif
  6616. exit:
  6617. if (WC_ARRAY_OK(hash)) {
  6618. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6619. wc_Sha3_512_Free(hash[i]);
  6620. }
  6621. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6622. }
  6623. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6624. }
  6625. #endif /* WOLFSSL_NOSHA3_512 */
  6626. #ifdef WOLFSSL_SHAKE128
  6627. void bench_shake128(int useDeviceID)
  6628. {
  6629. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6630. sizeof(wc_Shake), HEAP_HINT);
  6631. double start;
  6632. int ret = 0, i, count = 0, times, pending = 0;
  6633. DECLARE_MULTI_VALUE_STATS_VARS()
  6634. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6635. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6636. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6637. sizeof(wc_Shake), HEAP_HINT);
  6638. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6639. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6640. if (digest_stream) {
  6641. /* init keys */
  6642. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6643. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6644. useDeviceID ? devId : INVALID_DEVID);
  6645. if (ret != 0) {
  6646. printf("InitShake128 failed, ret = %d\n", ret);
  6647. goto exit;
  6648. }
  6649. }
  6650. bench_stats_start(&count, &start);
  6651. do {
  6652. for (times = 0; times < numBlocks || pending > 0; ) {
  6653. bench_async_poll(&pending);
  6654. /* while free pending slots in queue, submit ops */
  6655. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6656. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6657. 0, &times, numBlocks, &pending)) {
  6658. ret = wc_Shake128_Update(hash[i], bench_plain,
  6659. bench_size);
  6660. if (!bench_async_handle(&ret,
  6661. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6662. &times, &pending)) {
  6663. goto exit_shake128;
  6664. }
  6665. }
  6666. } /* for i */
  6667. RECORD_MULTI_VALUE_STATS();
  6668. } /* for times */
  6669. count += times;
  6670. times = 0;
  6671. do {
  6672. bench_async_poll(&pending);
  6673. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6674. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6675. 0, &times, numBlocks, &pending)) {
  6676. ret = wc_Shake128_Final(hash[i], digest[i],
  6677. WC_SHA3_128_BLOCK_SIZE);
  6678. if (!bench_async_handle(&ret,
  6679. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6680. &times, &pending)) {
  6681. goto exit_shake128;
  6682. }
  6683. }
  6684. } /* for i */
  6685. } while (pending > 0);
  6686. } while (bench_stats_check(start)
  6687. #ifdef MULTI_VALUE_STATISTICS
  6688. || runs < minimum_runs
  6689. #endif
  6690. );
  6691. }
  6692. else {
  6693. bench_stats_start(&count, &start);
  6694. do {
  6695. for (times = 0; times < numBlocks; times++) {
  6696. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6697. useDeviceID ? devId : INVALID_DEVID);
  6698. if (ret == 0)
  6699. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6700. if (ret == 0)
  6701. ret = wc_Shake128_Final(hash[0], digest[0],
  6702. WC_SHA3_128_BLOCK_SIZE);
  6703. if (ret != 0)
  6704. goto exit_shake128;
  6705. RECORD_MULTI_VALUE_STATS();
  6706. } /* for times */
  6707. count += times;
  6708. } while (bench_stats_check(start)
  6709. #ifdef MULTI_VALUE_STATISTICS
  6710. || runs < minimum_runs
  6711. #endif
  6712. );
  6713. }
  6714. exit_shake128:
  6715. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6716. start, ret);
  6717. #ifdef MULTI_VALUE_STATISTICS
  6718. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6719. #endif
  6720. exit:
  6721. if (WC_ARRAY_OK(hash)) {
  6722. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6723. wc_Shake128_Free(hash[i]);
  6724. }
  6725. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6726. }
  6727. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6728. }
  6729. #endif /* WOLFSSL_SHAKE128 */
  6730. #ifdef WOLFSSL_SHAKE256
  6731. void bench_shake256(int useDeviceID)
  6732. {
  6733. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6734. sizeof(wc_Shake), HEAP_HINT);
  6735. double start;
  6736. int ret = 0, i, count = 0, times, pending = 0;
  6737. DECLARE_MULTI_VALUE_STATS_VARS()
  6738. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6739. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6740. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6741. sizeof(wc_Shake), HEAP_HINT);
  6742. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6743. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6744. if (digest_stream) {
  6745. /* init keys */
  6746. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6747. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6748. useDeviceID ? devId : INVALID_DEVID);
  6749. if (ret != 0) {
  6750. printf("InitShake256 failed, ret = %d\n", ret);
  6751. goto exit;
  6752. }
  6753. }
  6754. bench_stats_start(&count, &start);
  6755. do {
  6756. for (times = 0; times < numBlocks || pending > 0; ) {
  6757. bench_async_poll(&pending);
  6758. /* while free pending slots in queue, submit ops */
  6759. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6760. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6761. 0, &times, numBlocks, &pending)) {
  6762. ret = wc_Shake256_Update(hash[i], bench_plain,
  6763. bench_size);
  6764. if (!bench_async_handle(&ret,
  6765. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6766. &times, &pending)) {
  6767. goto exit_shake256;
  6768. }
  6769. }
  6770. } /* for i */
  6771. RECORD_MULTI_VALUE_STATS();
  6772. } /* for times */
  6773. count += times;
  6774. times = 0;
  6775. do {
  6776. bench_async_poll(&pending);
  6777. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6778. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6779. 0, &times, numBlocks, &pending)) {
  6780. ret = wc_Shake256_Final(hash[i], digest[i],
  6781. WC_SHA3_256_BLOCK_SIZE);
  6782. if (!bench_async_handle(&ret,
  6783. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6784. &times, &pending)) {
  6785. goto exit_shake256;
  6786. }
  6787. }
  6788. } /* for i */
  6789. } while (pending > 0);
  6790. } while (bench_stats_check(start)
  6791. #ifdef MULTI_VALUE_STATISTICS
  6792. || runs < minimum_runs
  6793. #endif
  6794. );
  6795. }
  6796. else {
  6797. bench_stats_start(&count, &start);
  6798. do {
  6799. for (times = 0; times < numBlocks; times++) {
  6800. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6801. useDeviceID ? devId : INVALID_DEVID);
  6802. if (ret == 0)
  6803. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6804. if (ret == 0)
  6805. ret = wc_Shake256_Final(hash[0], digest[0],
  6806. WC_SHA3_256_BLOCK_SIZE);
  6807. if (ret != 0)
  6808. goto exit_shake256;
  6809. RECORD_MULTI_VALUE_STATS();
  6810. } /* for times */
  6811. count += times;
  6812. } while (bench_stats_check(start)
  6813. #ifdef MULTI_VALUE_STATISTICS
  6814. || runs < minimum_runs
  6815. #endif
  6816. );
  6817. }
  6818. exit_shake256:
  6819. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6820. start, ret);
  6821. #ifdef MULTI_VALUE_STATISTICS
  6822. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6823. #endif
  6824. exit:
  6825. if (WC_ARRAY_OK(hash)) {
  6826. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6827. wc_Shake256_Free(hash[i]);
  6828. }
  6829. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6830. }
  6831. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6832. }
  6833. #endif /* WOLFSSL_SHAKE256 */
  6834. #endif
  6835. #ifdef WOLFSSL_SM3
  6836. void bench_sm3(int useDeviceID)
  6837. {
  6838. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6839. sizeof(wc_Sm3), HEAP_HINT);
  6840. double start;
  6841. int ret = 0, i, count = 0, times, pending = 0;
  6842. DECLARE_MULTI_VALUE_STATS_VARS()
  6843. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6844. HEAP_HINT);
  6845. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6846. sizeof(wc_Sm3), HEAP_HINT);
  6847. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6848. HEAP_HINT);
  6849. if (digest_stream) {
  6850. /* init keys */
  6851. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6852. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6853. useDeviceID ? devId: INVALID_DEVID);
  6854. if (ret != 0) {
  6855. printf("InitSm3 failed, ret = %d\n", ret);
  6856. goto exit;
  6857. }
  6858. }
  6859. bench_stats_start(&count, &start);
  6860. do {
  6861. for (times = 0; times < numBlocks || pending > 0; ) {
  6862. bench_async_poll(&pending);
  6863. /* while free pending slots in queue, submit ops */
  6864. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6865. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6866. 0, &times, numBlocks, &pending)) {
  6867. ret = wc_Sm3Update(hash[i], bench_plain,
  6868. bench_size);
  6869. if (!bench_async_handle(&ret,
  6870. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6871. goto exit_sm3;
  6872. }
  6873. }
  6874. } /* for i */
  6875. RECORD_MULTI_VALUE_STATS();
  6876. } /* for times */
  6877. count += times;
  6878. times = 0;
  6879. do {
  6880. bench_async_poll(&pending);
  6881. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6882. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6883. 0, &times, numBlocks, &pending)) {
  6884. ret = wc_Sm3Final(hash[i], digest[i]);
  6885. if (!bench_async_handle(&ret,
  6886. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6887. goto exit_sm3;
  6888. }
  6889. }
  6890. } /* for i */
  6891. } while (pending > 0);
  6892. } while (bench_stats_check(start)
  6893. #ifdef MULTI_VALUE_STATISTICS
  6894. || runs < minimum_runs
  6895. #endif
  6896. );
  6897. }
  6898. else {
  6899. bench_stats_start(&count, &start);
  6900. do {
  6901. for (times = 0; times < numBlocks; times++) {
  6902. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6903. useDeviceID ? devId: INVALID_DEVID);
  6904. if (ret == 0)
  6905. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6906. if (ret == 0)
  6907. ret = wc_Sm3Final(hash[0], digest[0]);
  6908. if (ret != 0)
  6909. goto exit_sm3;
  6910. RECORD_MULTI_VALUE_STATS();
  6911. } /* for times */
  6912. count += times;
  6913. } while (bench_stats_check(start)
  6914. #ifdef MULTI_VALUE_STATISTICS
  6915. || runs < minimum_runs
  6916. #endif
  6917. );
  6918. }
  6919. exit_sm3:
  6920. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6921. #ifdef MULTI_VALUE_STATISTICS
  6922. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6923. #endif
  6924. exit:
  6925. if (WC_ARRAY_OK(hash)) {
  6926. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6927. wc_Sm3Free(hash[i]);
  6928. }
  6929. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6930. }
  6931. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6932. }
  6933. #endif
  6934. #ifdef WOLFSSL_RIPEMD
  6935. void bench_ripemd(void)
  6936. {
  6937. RipeMd hash;
  6938. byte digest[RIPEMD_DIGEST_SIZE];
  6939. double start;
  6940. int i, count, ret = 0;
  6941. DECLARE_MULTI_VALUE_STATS_VARS()
  6942. if (digest_stream) {
  6943. ret = wc_InitRipeMd(&hash);
  6944. if (ret != 0) {
  6945. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6946. return;
  6947. }
  6948. bench_stats_start(&count, &start);
  6949. do {
  6950. for (i = 0; i < numBlocks; i++) {
  6951. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6952. if (ret != 0) {
  6953. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6954. return;
  6955. }
  6956. RECORD_MULTI_VALUE_STATS();
  6957. }
  6958. ret = wc_RipeMdFinal(&hash, digest);
  6959. if (ret != 0) {
  6960. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6961. return;
  6962. }
  6963. count += i;
  6964. } while (bench_stats_check(start)
  6965. #ifdef MULTI_VALUE_STATISTICS
  6966. || runs < minimum_runs
  6967. #endif
  6968. );
  6969. }
  6970. else {
  6971. bench_stats_start(&count, &start);
  6972. do {
  6973. for (i = 0; i < numBlocks; i++) {
  6974. ret = wc_InitRipeMd(&hash);
  6975. if (ret != 0) {
  6976. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6977. return;
  6978. }
  6979. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6980. if (ret != 0) {
  6981. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6982. return;
  6983. }
  6984. ret = wc_RipeMdFinal(&hash, digest);
  6985. if (ret != 0) {
  6986. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6987. return;
  6988. }
  6989. RECORD_MULTI_VALUE_STATS();
  6990. }
  6991. count += i;
  6992. } while (bench_stats_check(start)
  6993. #ifdef MULTI_VALUE_STATISTICS
  6994. || runs < minimum_runs
  6995. #endif
  6996. );
  6997. }
  6998. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  6999. #ifdef MULTI_VALUE_STATISTICS
  7000. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7001. #endif
  7002. return;
  7003. }
  7004. #endif
  7005. #ifdef HAVE_BLAKE2
  7006. void bench_blake2b(void)
  7007. {
  7008. Blake2b b2b;
  7009. byte digest[64];
  7010. double start;
  7011. int ret = 0, i, count;
  7012. DECLARE_MULTI_VALUE_STATS_VARS()
  7013. if (digest_stream) {
  7014. ret = wc_InitBlake2b(&b2b, 64);
  7015. if (ret != 0) {
  7016. printf("InitBlake2b failed, ret = %d\n", ret);
  7017. return;
  7018. }
  7019. bench_stats_start(&count, &start);
  7020. do {
  7021. for (i = 0; i < numBlocks; i++) {
  7022. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7023. if (ret != 0) {
  7024. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7025. return;
  7026. }
  7027. RECORD_MULTI_VALUE_STATS();
  7028. }
  7029. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7030. if (ret != 0) {
  7031. printf("Blake2bFinal failed, ret = %d\n", ret);
  7032. return;
  7033. }
  7034. count += i;
  7035. } while (bench_stats_check(start)
  7036. #ifdef MULTI_VALUE_STATISTICS
  7037. || runs < minimum_runs
  7038. #endif
  7039. );
  7040. }
  7041. else {
  7042. bench_stats_start(&count, &start);
  7043. do {
  7044. for (i = 0; i < numBlocks; i++) {
  7045. ret = wc_InitBlake2b(&b2b, 64);
  7046. if (ret != 0) {
  7047. printf("InitBlake2b failed, ret = %d\n", ret);
  7048. return;
  7049. }
  7050. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7051. if (ret != 0) {
  7052. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7053. return;
  7054. }
  7055. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7056. if (ret != 0) {
  7057. printf("Blake2bFinal failed, ret = %d\n", ret);
  7058. return;
  7059. }
  7060. RECORD_MULTI_VALUE_STATS();
  7061. }
  7062. count += i;
  7063. } while (bench_stats_check(start)
  7064. #ifdef MULTI_VALUE_STATISTICS
  7065. || runs < minimum_runs
  7066. #endif
  7067. );
  7068. }
  7069. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7070. #ifdef MULTI_VALUE_STATISTICS
  7071. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7072. #endif
  7073. }
  7074. #endif
  7075. #if defined(HAVE_BLAKE2S)
  7076. void bench_blake2s(void)
  7077. {
  7078. Blake2s b2s;
  7079. byte digest[32];
  7080. double start;
  7081. int ret = 0, i, count;
  7082. DECLARE_MULTI_VALUE_STATS_VARS()
  7083. if (digest_stream) {
  7084. ret = wc_InitBlake2s(&b2s, 32);
  7085. if (ret != 0) {
  7086. printf("InitBlake2s failed, ret = %d\n", ret);
  7087. return;
  7088. }
  7089. bench_stats_start(&count, &start);
  7090. do {
  7091. for (i = 0; i < numBlocks; i++) {
  7092. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7093. if (ret != 0) {
  7094. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7095. return;
  7096. }
  7097. RECORD_MULTI_VALUE_STATS();
  7098. }
  7099. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7100. if (ret != 0) {
  7101. printf("Blake2sFinal failed, ret = %d\n", ret);
  7102. return;
  7103. }
  7104. count += i;
  7105. } while (bench_stats_check(start)
  7106. #ifdef MULTI_VALUE_STATISTICS
  7107. || runs < minimum_runs
  7108. #endif
  7109. );
  7110. }
  7111. else {
  7112. bench_stats_start(&count, &start);
  7113. do {
  7114. for (i = 0; i < numBlocks; i++) {
  7115. ret = wc_InitBlake2s(&b2s, 32);
  7116. if (ret != 0) {
  7117. printf("InitBlake2b failed, ret = %d\n", ret);
  7118. return;
  7119. }
  7120. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7121. if (ret != 0) {
  7122. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7123. return;
  7124. }
  7125. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7126. if (ret != 0) {
  7127. printf("Blake2sFinal failed, ret = %d\n", ret);
  7128. return;
  7129. }
  7130. RECORD_MULTI_VALUE_STATS();
  7131. }
  7132. count += i;
  7133. } while (bench_stats_check(start)
  7134. #ifdef MULTI_VALUE_STATISTICS
  7135. || runs < minimum_runs
  7136. #endif
  7137. );
  7138. }
  7139. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7140. #ifdef MULTI_VALUE_STATISTICS
  7141. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7142. #endif
  7143. }
  7144. #endif
  7145. #ifdef WOLFSSL_CMAC
  7146. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7147. {
  7148. Cmac cmac;
  7149. byte digest[AES_BLOCK_SIZE];
  7150. word32 digestSz = sizeof(digest);
  7151. double start;
  7152. int ret, i, count;
  7153. DECLARE_MULTI_VALUE_STATS_VARS()
  7154. #ifdef WOLFSSL_SECO_CAAM
  7155. unsigned int keyID;
  7156. int keyGroup = 1; /* group one was chosen arbitrarily */
  7157. int keyInfo = CAAM_KEY_TRANSIENT;
  7158. int keyType = CAAM_KEYTYPE_AES128;
  7159. byte pubKey[AES_256_KEY_SIZE];
  7160. if (keySz == AES_256_KEY_SIZE) {
  7161. keyType = CAAM_KEYTYPE_AES256;
  7162. }
  7163. if (useDeviceID &&
  7164. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7165. keyInfo, &keyID) != 0) {
  7166. printf("Error generating key in hsm\n");
  7167. return;
  7168. }
  7169. #endif
  7170. (void)useDeviceID;
  7171. bench_stats_start(&count, &start);
  7172. do {
  7173. #ifdef HAVE_FIPS
  7174. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7175. #else
  7176. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7177. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7178. #endif
  7179. if (ret != 0) {
  7180. printf("InitCmac failed, ret = %d\n", ret);
  7181. return;
  7182. }
  7183. #ifdef WOLFSSL_SECO_CAAM
  7184. if (useDeviceID) {
  7185. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7186. }
  7187. #endif
  7188. for (i = 0; i < numBlocks; i++) {
  7189. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7190. if (ret != 0) {
  7191. printf("CmacUpdate failed, ret = %d\n", ret);
  7192. return;
  7193. }
  7194. RECORD_MULTI_VALUE_STATS();
  7195. }
  7196. /* Note: final force zero's the Cmac struct */
  7197. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7198. if (ret != 0) {
  7199. printf("CmacFinal failed, ret = %d\n", ret);
  7200. return;
  7201. }
  7202. count += i;
  7203. } while (bench_stats_check(start)
  7204. #ifdef MULTI_VALUE_STATISTICS
  7205. || runs < minimum_runs
  7206. #endif
  7207. );
  7208. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7209. #ifdef MULTI_VALUE_STATISTICS
  7210. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7211. #endif
  7212. }
  7213. void bench_cmac(int useDeviceID)
  7214. {
  7215. #ifdef WOLFSSL_AES_128
  7216. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7217. #endif
  7218. #ifdef WOLFSSL_AES_256
  7219. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7220. #endif
  7221. }
  7222. #endif /* WOLFSSL_CMAC */
  7223. #ifdef HAVE_SCRYPT
  7224. void bench_scrypt(void)
  7225. {
  7226. byte derived[64];
  7227. double start;
  7228. int ret, i, count;
  7229. DECLARE_MULTI_VALUE_STATS_VARS()
  7230. bench_stats_start(&count, &start);
  7231. do {
  7232. for (i = 0; i < scryptCnt; i++) {
  7233. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7234. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7235. sizeof(derived));
  7236. if (ret != 0) {
  7237. printf("scrypt failed, ret = %d\n", ret);
  7238. goto exit;
  7239. }
  7240. RECORD_MULTI_VALUE_STATS();
  7241. }
  7242. count += i;
  7243. } while (bench_stats_check(start)
  7244. #ifdef MULTI_VALUE_STATISTICS
  7245. || runs < minimum_runs
  7246. #endif
  7247. );
  7248. exit:
  7249. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7250. #ifdef MULTI_VALUE_STATISTICS
  7251. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7252. #endif
  7253. }
  7254. #endif /* HAVE_SCRYPT */
  7255. #ifndef NO_HMAC
  7256. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7257. const byte* key, word32 keySz, const char* label)
  7258. {
  7259. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7260. sizeof(Hmac), HEAP_HINT);
  7261. double start;
  7262. int ret = 0, i, count = 0, times, pending = 0;
  7263. DECLARE_MULTI_VALUE_STATS_VARS()
  7264. #ifdef WOLFSSL_ASYNC_CRYPT
  7265. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7266. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7267. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7268. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7269. #else
  7270. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7271. #endif
  7272. (void)digestSz;
  7273. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7274. sizeof(Hmac), HEAP_HINT);
  7275. /* init keys */
  7276. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7277. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7278. useDeviceID ? devId : INVALID_DEVID);
  7279. if (ret != 0) {
  7280. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7281. goto exit;
  7282. }
  7283. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7284. if (ret != 0) {
  7285. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7286. goto exit;
  7287. }
  7288. }
  7289. bench_stats_start(&count, &start);
  7290. do {
  7291. for (times = 0; times < numBlocks || pending > 0; ) {
  7292. bench_async_poll(&pending);
  7293. /* while free pending slots in queue, submit ops */
  7294. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7295. if (bench_async_check(&ret,
  7296. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7297. &times, numBlocks, &pending)) {
  7298. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7299. if (!bench_async_handle(&ret,
  7300. BENCH_ASYNC_GET_DEV(hmac[i]),
  7301. 0, &times, &pending)) {
  7302. goto exit_hmac;
  7303. }
  7304. }
  7305. } /* for i */
  7306. } /* for times */
  7307. count += times;
  7308. times = 0;
  7309. do {
  7310. bench_async_poll(&pending);
  7311. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7312. if (bench_async_check(&ret,
  7313. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7314. &times, numBlocks, &pending)) {
  7315. ret = wc_HmacFinal(hmac[i], digest[i]);
  7316. if (!bench_async_handle(&ret,
  7317. BENCH_ASYNC_GET_DEV(hmac[i]),
  7318. 0, &times, &pending)) {
  7319. goto exit_hmac;
  7320. }
  7321. }
  7322. RECORD_MULTI_VALUE_STATS();
  7323. } /* for i */
  7324. } while (pending > 0);
  7325. } while (bench_stats_check(start)
  7326. #ifdef MULTI_VALUE_STATISTICS
  7327. || runs < minimum_runs
  7328. #endif
  7329. );
  7330. exit_hmac:
  7331. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7332. #ifdef MULTI_VALUE_STATISTICS
  7333. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7334. #endif
  7335. exit:
  7336. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7337. wc_HmacFree(hmac[i]);
  7338. }
  7339. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7340. #ifdef WOLFSSL_ASYNC_CRYPT
  7341. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7342. #endif
  7343. }
  7344. #ifndef NO_MD5
  7345. void bench_hmac_md5(int useDeviceID)
  7346. {
  7347. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7348. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7349. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7350. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7351. "HMAC-MD5");
  7352. }
  7353. #endif /* NO_MD5 */
  7354. #ifndef NO_SHA
  7355. void bench_hmac_sha(int useDeviceID)
  7356. {
  7357. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7358. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7359. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7360. 0x0b, 0x0b, 0x0b, 0x0b };
  7361. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7362. "HMAC-SHA");
  7363. }
  7364. #endif /* NO_SHA */
  7365. #ifdef WOLFSSL_SHA224
  7366. void bench_hmac_sha224(int useDeviceID)
  7367. {
  7368. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7369. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7370. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7371. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7372. 0x0b, 0x0b, 0x0b, 0x0b };
  7373. bench_hmac(useDeviceID, WC_SHA224,
  7374. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7375. "HMAC-SHA224");
  7376. }
  7377. #endif /* WOLFSSL_SHA224 */
  7378. #ifndef NO_SHA256
  7379. void bench_hmac_sha256(int useDeviceID)
  7380. {
  7381. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7382. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7383. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7384. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7385. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7386. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7387. "HMAC-SHA256");
  7388. }
  7389. #endif /* NO_SHA256 */
  7390. #ifdef WOLFSSL_SHA384
  7391. void bench_hmac_sha384(int useDeviceID)
  7392. {
  7393. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7394. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7395. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7396. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7397. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7398. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7399. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7400. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7401. "HMAC-SHA384");
  7402. }
  7403. #endif /* WOLFSSL_SHA384 */
  7404. #ifdef WOLFSSL_SHA512
  7405. void bench_hmac_sha512(int useDeviceID)
  7406. {
  7407. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7408. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7409. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7410. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7411. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7412. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7413. 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. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7417. "HMAC-SHA512");
  7418. }
  7419. #endif /* WOLFSSL_SHA512 */
  7420. #ifndef NO_PWDBASED
  7421. void bench_pbkdf2(void)
  7422. {
  7423. double start;
  7424. int ret = 0, count = 0;
  7425. const char* passwd32 = "passwordpasswordpasswordpassword";
  7426. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7427. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7428. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7429. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7430. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7431. byte derived[32];
  7432. DECLARE_MULTI_VALUE_STATS_VARS()
  7433. bench_stats_start(&count, &start);
  7434. PRIVATE_KEY_UNLOCK();
  7435. do {
  7436. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7437. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7438. count++;
  7439. RECORD_MULTI_VALUE_STATS();
  7440. } while (bench_stats_check(start)
  7441. #ifdef MULTI_VALUE_STATISTICS
  7442. || runs < minimum_runs
  7443. #endif
  7444. );
  7445. PRIVATE_KEY_LOCK();
  7446. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7447. #ifdef MULTI_VALUE_STATISTICS
  7448. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7449. #endif
  7450. }
  7451. #endif /* !NO_PWDBASED */
  7452. #endif /* NO_HMAC */
  7453. #ifdef WOLFSSL_SIPHASH
  7454. void bench_siphash(void)
  7455. {
  7456. double start;
  7457. int ret = 0, count;
  7458. const char* passwd16 = "passwordpassword";
  7459. byte out[16];
  7460. int i;
  7461. DECLARE_MULTI_VALUE_STATS_VARS()
  7462. bench_stats_start(&count, &start);
  7463. do {
  7464. for (i = 0; i < numBlocks; i++) {
  7465. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7466. out, 8);
  7467. RECORD_MULTI_VALUE_STATS();
  7468. }
  7469. count += i;
  7470. } while (bench_stats_check(start)
  7471. #ifdef MULTI_VALUE_STATISTICS
  7472. || runs < minimum_runs
  7473. #endif
  7474. );
  7475. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7476. #ifdef MULTI_VALUE_STATISTICS
  7477. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7478. #endif
  7479. RESET_MULTI_VALUE_STATS_VARS();
  7480. bench_stats_start(&count, &start);
  7481. do {
  7482. for (i = 0; i < numBlocks; i++) {
  7483. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7484. out, 16);
  7485. RECORD_MULTI_VALUE_STATS();
  7486. }
  7487. count += i;
  7488. } while (bench_stats_check(start)
  7489. #ifdef MULTI_VALUE_STATISTICS
  7490. || runs < minimum_runs
  7491. #endif
  7492. );
  7493. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7494. #ifdef MULTI_VALUE_STATISTICS
  7495. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7496. #endif
  7497. }
  7498. #endif
  7499. #ifdef WC_SRTP_KDF
  7500. void bench_srtpkdf(void)
  7501. {
  7502. double start;
  7503. int count;
  7504. int ret = 0;
  7505. byte keyE[32];
  7506. byte keyA[20];
  7507. byte keyS[14];
  7508. const byte *key = bench_key_buf;
  7509. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7510. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7511. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7512. int kdrIdx = 0;
  7513. int i;
  7514. DECLARE_MULTI_VALUE_STATS_VARS()
  7515. bench_stats_start(&count, &start);
  7516. PRIVATE_KEY_UNLOCK();
  7517. do {
  7518. for (i = 0; i < numBlocks; i++) {
  7519. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7520. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7521. keyS, sizeof(keyS));
  7522. RECORD_MULTI_VALUE_STATS();
  7523. }
  7524. count += i;
  7525. } while (bench_stats_check(start)
  7526. #ifdef MULTI_VALUE_STATISTICS
  7527. || runs < minimum_runs
  7528. #endif
  7529. );
  7530. PRIVATE_KEY_LOCK();
  7531. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7532. #ifdef MULTI_VALUE_STATISTICS
  7533. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7534. #endif
  7535. RESET_MULTI_VALUE_STATS_VARS();
  7536. bench_stats_start(&count, &start);
  7537. PRIVATE_KEY_UNLOCK();
  7538. do {
  7539. for (i = 0; i < numBlocks; i++) {
  7540. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7541. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7542. keyS, sizeof(keyS));
  7543. RECORD_MULTI_VALUE_STATS();
  7544. }
  7545. count += i;
  7546. } while (bench_stats_check(start)
  7547. #ifdef MULTI_VALUE_STATISTICS
  7548. || runs < minimum_runs
  7549. #endif
  7550. );
  7551. PRIVATE_KEY_LOCK();
  7552. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7553. #ifdef MULTI_VALUE_STATISTICS
  7554. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7555. #endif
  7556. RESET_MULTI_VALUE_STATS_VARS();
  7557. bench_stats_start(&count, &start);
  7558. PRIVATE_KEY_UNLOCK();
  7559. do {
  7560. for (i = 0; i < numBlocks; i++) {
  7561. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7562. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7563. keyS, sizeof(keyS));
  7564. RECORD_MULTI_VALUE_STATS();
  7565. }
  7566. count += i;
  7567. } while (bench_stats_check(start)
  7568. #ifdef MULTI_VALUE_STATISTICS
  7569. || runs < minimum_runs
  7570. #endif
  7571. );
  7572. PRIVATE_KEY_LOCK();
  7573. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7574. #ifdef MULTI_VALUE_STATISTICS
  7575. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7576. #endif
  7577. RESET_MULTI_VALUE_STATS_VARS();
  7578. bench_stats_start(&count, &start);
  7579. PRIVATE_KEY_UNLOCK();
  7580. do {
  7581. for (i = 0; i < numBlocks; i++) {
  7582. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7583. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7584. keyS, sizeof(keyS));
  7585. RECORD_MULTI_VALUE_STATS();
  7586. }
  7587. count += i;
  7588. } while (bench_stats_check(start)
  7589. #ifdef MULTI_VALUE_STATISTICS
  7590. || runs < minimum_runs
  7591. #endif
  7592. );
  7593. PRIVATE_KEY_LOCK();
  7594. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7595. #ifdef MULTI_VALUE_STATISTICS
  7596. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7597. #endif
  7598. }
  7599. #endif
  7600. #ifndef NO_RSA
  7601. #if defined(WOLFSSL_KEY_GEN)
  7602. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7603. {
  7604. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7605. sizeof(RsaKey), HEAP_HINT);
  7606. double start = 0;
  7607. int ret = 0, i, count = 0, times, pending = 0;
  7608. const long rsa_e_val = WC_RSA_EXPONENT;
  7609. const char**desc = bench_desc_words[lng_index];
  7610. DECLARE_MULTI_VALUE_STATS_VARS()
  7611. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7612. sizeof(RsaKey), HEAP_HINT);
  7613. bench_stats_start(&count, &start);
  7614. do {
  7615. /* while free pending slots in queue, submit ops */
  7616. for (times = 0; times < genTimes || pending > 0; ) {
  7617. bench_async_poll(&pending);
  7618. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7619. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7620. 0, &times, genTimes, &pending)) {
  7621. wc_FreeRsaKey(genKey[i]);
  7622. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7623. if (ret < 0) {
  7624. goto exit;
  7625. }
  7626. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7627. &gRng);
  7628. if (!bench_async_handle(&ret,
  7629. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7630. &times, &pending)) {
  7631. goto exit;
  7632. }
  7633. }
  7634. } /* for i */
  7635. RECORD_MULTI_VALUE_STATS();
  7636. } /* for times */
  7637. count += times;
  7638. } while (bench_stats_check(start)
  7639. #ifdef MULTI_VALUE_STATISTICS
  7640. || runs < minimum_runs
  7641. #endif
  7642. );
  7643. exit:
  7644. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7645. start, ret);
  7646. #ifdef MULTI_VALUE_STATISTICS
  7647. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7648. #endif
  7649. /* cleanup */
  7650. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7651. wc_FreeRsaKey(genKey[i]);
  7652. }
  7653. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7654. }
  7655. void bench_rsaKeyGen(int useDeviceID)
  7656. {
  7657. int k;
  7658. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7659. static const word32 keySizes[2] = {1024, 2048 };
  7660. #elif RSA_MAX_SIZE >= 4096
  7661. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7662. (RSA_MIN_SIZE <= 1024)
  7663. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7664. #else
  7665. static const word32 keySizes[3] = {2048, 3072, 4096};
  7666. #endif
  7667. #elif RSA_MAX_SIZE >= 3072
  7668. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7669. (RSA_MIN_SIZE <= 1024)
  7670. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7671. #else
  7672. static const word32 keySizes[2] = {2048, 3072 };
  7673. #endif
  7674. #elif RSA_MAX_SIZE >= 2048
  7675. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7676. (RSA_MIN_SIZE <= 1024)
  7677. static const word32 keySizes[2] = {1024, 2048 };
  7678. #else
  7679. static const word32 keySizes[1] = {2048};
  7680. #endif
  7681. #else
  7682. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7683. (RSA_MIN_SIZE <= 1024)
  7684. static const word32 keySizes[1] = {1024 };
  7685. #else
  7686. #error No candidate RSA key sizes to benchmark.
  7687. #endif
  7688. #endif
  7689. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7690. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7691. }
  7692. }
  7693. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7694. {
  7695. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7696. }
  7697. #endif /* WOLFSSL_KEY_GEN */
  7698. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7699. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7700. #if defined(WOLFSSL_MDK_SHELL)
  7701. static char *certRSAname = "certs/rsa2048.der";
  7702. /* set by shell command */
  7703. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7704. #elif defined(FREESCALE_MQX)
  7705. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7706. #else
  7707. static const char *certRSAname = "certs/rsa2048.der";
  7708. #endif
  7709. #endif
  7710. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7711. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7712. #if defined(USE_CERT_BUFFERS_2048)
  7713. static const unsigned char rsa_2048_sig[] = {
  7714. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7715. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7716. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7717. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7718. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7719. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7720. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7721. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7722. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7723. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7724. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7725. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7726. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7727. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7728. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7729. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7730. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7731. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7732. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7733. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7734. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7735. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7736. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7737. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7738. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7739. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7740. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7741. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7742. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7743. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7744. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7745. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7746. };
  7747. #elif defined(USE_CERT_BUFFERS_3072)
  7748. static const unsigned char rsa_3072_sig[] = {
  7749. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7750. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7751. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7752. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7753. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7754. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7755. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7756. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7757. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7758. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7759. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7760. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7761. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7762. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7763. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7764. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7765. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7766. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7767. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7768. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7769. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7770. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7771. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7772. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7773. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7774. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7775. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7776. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7777. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7778. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7779. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7780. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7781. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7782. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7783. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7784. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7785. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7786. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7787. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7788. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7789. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7790. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7791. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7792. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7793. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7794. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7795. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7796. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7797. };
  7798. #else
  7799. #error Not Supported Yet!
  7800. #endif
  7801. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7802. static void bench_rsa_helper(int useDeviceID,
  7803. WC_ARRAY_ARG(rsaKey,
  7804. RsaKey,
  7805. BENCH_MAX_PENDING,
  7806. sizeof(RsaKey)),
  7807. word32 rsaKeySz)
  7808. {
  7809. int ret = 0, i, times, count = 0, pending = 0;
  7810. word32 idx = 0;
  7811. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7812. const char* messageStr = TEST_STRING;
  7813. const int len = (int)TEST_STRING_SZ;
  7814. #endif
  7815. double start = 0.0F;
  7816. const char**desc = bench_desc_words[lng_index];
  7817. DECLARE_MULTI_VALUE_STATS_VARS()
  7818. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7819. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7820. #endif
  7821. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7822. rsaKeySz, HEAP_HINT);
  7823. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7824. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7825. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7826. rsaKeySz, HEAP_HINT);
  7827. #else
  7828. byte* out[BENCH_MAX_PENDING];
  7829. #endif
  7830. XMEMSET(out, 0, sizeof(out));
  7831. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7832. rsaKeySz, HEAP_HINT);
  7833. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7834. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7835. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7836. rsaKeySz, HEAP_HINT);
  7837. if (out[0] == NULL) {
  7838. ret = MEMORY_E;
  7839. goto exit;
  7840. }
  7841. #endif
  7842. if (enc[0] == NULL) {
  7843. ret = MEMORY_E;
  7844. goto exit;
  7845. }
  7846. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7847. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7848. XMEMCPY(message, messageStr, len);
  7849. #endif
  7850. if (!rsa_sign_verify) {
  7851. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7852. /* begin public RSA */
  7853. bench_stats_start(&count, &start);
  7854. do {
  7855. for (times = 0; times < ntimes || pending > 0; ) {
  7856. bench_async_poll(&pending);
  7857. /* while free pending slots in queue, submit ops */
  7858. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7859. if (bench_async_check(&ret,
  7860. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7861. 1, &times, ntimes, &pending)) {
  7862. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7863. rsaKeySz/8, rsaKey[i],
  7864. GLOBAL_RNG);
  7865. if (!bench_async_handle(&ret,
  7866. BENCH_ASYNC_GET_DEV(
  7867. rsaKey[i]), 1, &times,
  7868. &pending)) {
  7869. goto exit_rsa_verify;
  7870. }
  7871. }
  7872. } /* for i */
  7873. RECORD_MULTI_VALUE_STATS();
  7874. } /* for times */
  7875. count += times;
  7876. } while (bench_stats_check(start)
  7877. #ifdef MULTI_VALUE_STATISTICS
  7878. || runs < minimum_runs
  7879. #endif
  7880. );
  7881. exit_rsa_verify:
  7882. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7883. useDeviceID, count, start, ret);
  7884. #ifdef MULTI_VALUE_STATISTICS
  7885. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7886. #endif
  7887. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7888. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7889. if (ret < 0) {
  7890. goto exit;
  7891. }
  7892. RESET_MULTI_VALUE_STATS_VARS();
  7893. /* capture resulting encrypt length */
  7894. idx = (word32)(rsaKeySz/8);
  7895. /* begin private async RSA */
  7896. bench_stats_start(&count, &start);
  7897. do {
  7898. for (times = 0; times < ntimes || pending > 0; ) {
  7899. bench_async_poll(&pending);
  7900. /* while free pending slots in queue, submit ops */
  7901. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7902. if (bench_async_check(&ret,
  7903. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7904. 1, &times, ntimes, &pending)) {
  7905. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7906. rsaKeySz/8, rsaKey[i]);
  7907. if (!bench_async_handle(&ret,
  7908. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7909. 1, &times, &pending)) {
  7910. goto exit_rsa_pub;
  7911. }
  7912. }
  7913. } /* for i */
  7914. RECORD_MULTI_VALUE_STATS();
  7915. } /* for times */
  7916. count += times;
  7917. } while (bench_stats_check(start)
  7918. #ifdef MULTI_VALUE_STATISTICS
  7919. || runs < minimum_runs
  7920. #endif
  7921. );
  7922. exit_rsa_pub:
  7923. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7924. useDeviceID, count, start, ret);
  7925. #ifdef MULTI_VALUE_STATISTICS
  7926. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7927. #endif
  7928. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7929. }
  7930. else {
  7931. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7932. /* begin RSA sign */
  7933. bench_stats_start(&count, &start);
  7934. do {
  7935. for (times = 0; times < ntimes || pending > 0; ) {
  7936. bench_async_poll(&pending);
  7937. /* while free pending slots in queue, submit ops */
  7938. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7939. if (bench_async_check(&ret,
  7940. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7941. 1, &times, ntimes, &pending)) {
  7942. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7943. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7944. if (!bench_async_handle(&ret,
  7945. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7946. 1, &times, &pending)) {
  7947. goto exit_rsa_sign;
  7948. }
  7949. }
  7950. } /* for i */
  7951. RECORD_MULTI_VALUE_STATS();
  7952. } /* for times */
  7953. count += times;
  7954. } while (bench_stats_check(start)
  7955. #ifdef MULTI_VALUE_STATISTICS
  7956. || runs < minimum_runs
  7957. #endif
  7958. );
  7959. exit_rsa_sign:
  7960. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7961. count, start, ret);
  7962. #ifdef MULTI_VALUE_STATISTICS
  7963. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7964. #endif
  7965. if (ret < 0) {
  7966. goto exit;
  7967. }
  7968. RESET_MULTI_VALUE_STATS_VARS();
  7969. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7970. /* capture resulting encrypt length */
  7971. idx = rsaKeySz/8;
  7972. /* begin RSA verify */
  7973. bench_stats_start(&count, &start);
  7974. do {
  7975. for (times = 0; times < ntimes || pending > 0; ) {
  7976. bench_async_poll(&pending);
  7977. /* while free pending slots in queue, submit ops */
  7978. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7979. if (bench_async_check(&ret,
  7980. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7981. 1, &times, ntimes, &pending)) {
  7982. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7983. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7984. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  7985. rsaKeySz/8, rsaKey[i]);
  7986. #elif defined(USE_CERT_BUFFERS_2048)
  7987. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  7988. idx = sizeof(rsa_2048_sig);
  7989. out[i] = NULL;
  7990. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7991. &out[i], rsaKey[i]);
  7992. if (ret > 0) {
  7993. ret = 0;
  7994. }
  7995. #elif defined(USE_CERT_BUFFERS_3072)
  7996. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  7997. idx = sizeof(rsa_3072_sig);
  7998. out[i] = NULL;
  7999. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8000. &out[i], rsaKey[i]);
  8001. if (ret > 0)
  8002. ret = 0;
  8003. #endif
  8004. if (!bench_async_handle(&ret,
  8005. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8006. 1, &times, &pending)) {
  8007. goto exit_rsa_verifyinline;
  8008. }
  8009. }
  8010. } /* for i */
  8011. RECORD_MULTI_VALUE_STATS();
  8012. } /* for times */
  8013. count += times;
  8014. } while (bench_stats_check(start)
  8015. #ifdef MULTI_VALUE_STATISTICS
  8016. || runs < minimum_runs
  8017. #endif
  8018. );
  8019. exit_rsa_verifyinline:
  8020. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8021. useDeviceID, count, start, ret);
  8022. #ifdef MULTI_VALUE_STATISTICS
  8023. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8024. #endif
  8025. }
  8026. exit:
  8027. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8028. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8029. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8030. #endif
  8031. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8032. WC_FREE_VAR(message, HEAP_HINT);
  8033. #endif
  8034. }
  8035. void bench_rsa(int useDeviceID)
  8036. {
  8037. int i;
  8038. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8039. sizeof(RsaKey), HEAP_HINT);
  8040. int ret = 0;
  8041. word32 rsaKeySz = 0;
  8042. const byte* tmp;
  8043. size_t bytes;
  8044. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8045. word32 idx;
  8046. #endif
  8047. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8048. sizeof(RsaKey), HEAP_HINT);
  8049. #ifdef USE_CERT_BUFFERS_1024
  8050. tmp = rsa_key_der_1024;
  8051. bytes = (size_t)sizeof_rsa_key_der_1024;
  8052. rsaKeySz = 1024;
  8053. #elif defined(USE_CERT_BUFFERS_2048)
  8054. tmp = rsa_key_der_2048;
  8055. bytes = (size_t)sizeof_rsa_key_der_2048;
  8056. rsaKeySz = 2048;
  8057. #elif defined(USE_CERT_BUFFERS_3072)
  8058. tmp = rsa_key_der_3072;
  8059. bytes = (size_t)sizeof_rsa_key_der_3072;
  8060. rsaKeySz = 3072;
  8061. #elif defined(USE_CERT_BUFFERS_4096)
  8062. tmp = client_key_der_4096;
  8063. bytes = (size_t)sizeof_client_key_der_4096;
  8064. rsaKeySz = 4096;
  8065. #else
  8066. #error "need a cert buffer size"
  8067. #endif /* USE_CERT_BUFFERS */
  8068. /* init keys */
  8069. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8070. /* setup an async context for each key */
  8071. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8072. useDeviceID ? devId : INVALID_DEVID);
  8073. if (ret < 0) {
  8074. goto exit;
  8075. }
  8076. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8077. #ifdef WC_RSA_BLINDING
  8078. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8079. if (ret != 0)
  8080. goto exit;
  8081. #endif
  8082. #endif
  8083. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8084. /* decode the private key */
  8085. idx = 0;
  8086. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8087. rsaKey[i], (word32)bytes)) != 0) {
  8088. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8089. goto exit;
  8090. }
  8091. #elif defined(WOLFSSL_PUBLIC_MP)
  8092. /* get offset to public portion of the RSA key */
  8093. #ifdef USE_CERT_BUFFERS_1024
  8094. bytes = 11;
  8095. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8096. bytes = 12;
  8097. #endif
  8098. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8099. if (ret != 0) {
  8100. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8101. goto exit;
  8102. }
  8103. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8104. if (ret != 0) {
  8105. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8106. goto exit;
  8107. }
  8108. #else
  8109. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8110. rsaKeySz = 0;
  8111. #endif
  8112. }
  8113. if (rsaKeySz > 0) {
  8114. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8115. }
  8116. (void)bytes;
  8117. (void)tmp;
  8118. exit:
  8119. /* cleanup */
  8120. if (WC_ARRAY_OK(rsaKey)) {
  8121. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8122. wc_FreeRsaKey(rsaKey[i]);
  8123. }
  8124. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8125. }
  8126. }
  8127. #ifdef WOLFSSL_KEY_GEN
  8128. /* bench any size of RSA key */
  8129. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8130. {
  8131. int ret = 0, i, pending = 0;
  8132. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8133. sizeof(RsaKey), HEAP_HINT);
  8134. int isPending[BENCH_MAX_PENDING];
  8135. long exp = 65537L;
  8136. /* clear for done cleanup */
  8137. XMEMSET(isPending, 0, sizeof(isPending));
  8138. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8139. sizeof(RsaKey), HEAP_HINT);
  8140. /* init keys */
  8141. do {
  8142. pending = 0;
  8143. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8144. if (!isPending[i]) { /* if making the key is pending then just call
  8145. * wc_MakeRsaKey again */
  8146. /* setup an async context for each key */
  8147. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8148. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8149. goto exit;
  8150. }
  8151. #ifdef WC_RSA_BLINDING
  8152. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8153. if (ret != 0)
  8154. goto exit;
  8155. #endif
  8156. }
  8157. /* create the RSA key */
  8158. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8159. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8160. isPending[i] = 1;
  8161. pending = 1;
  8162. }
  8163. else if (ret != 0) {
  8164. printf("wc_MakeRsaKey failed! %d\n", ret);
  8165. goto exit;
  8166. }
  8167. } /* for i */
  8168. } while (pending > 0);
  8169. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8170. exit:
  8171. /* cleanup */
  8172. if (WC_ARRAY_OK(rsaKey)) {
  8173. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8174. wc_FreeRsaKey(rsaKey[i]);
  8175. }
  8176. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8177. }
  8178. }
  8179. #endif /* WOLFSSL_KEY_GEN */
  8180. #endif /* !NO_RSA */
  8181. #ifndef NO_DH
  8182. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8183. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8184. #if defined(WOLFSSL_MDK_SHELL)
  8185. static char *certDHname = "certs/dh2048.der";
  8186. /* set by shell command */
  8187. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8188. #elif defined(FREESCALE_MQX)
  8189. static char *certDHname = "a:\\certs\\dh2048.der";
  8190. #elif defined(NO_ASN)
  8191. /* do nothing, but don't need a file */
  8192. #else
  8193. static const char *certDHname = "certs/dh2048.der";
  8194. #endif
  8195. #endif
  8196. #ifdef HAVE_FFDHE_4096
  8197. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8198. #else
  8199. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8200. #endif
  8201. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8202. void bench_dh(int useDeviceID)
  8203. {
  8204. int ret = 0, i;
  8205. int count = 0, times, pending = 0;
  8206. const byte* tmp = NULL;
  8207. double start = 0.0F;
  8208. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8209. sizeof(DhKey), HEAP_HINT);
  8210. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8211. const char**desc = bench_desc_words[lng_index];
  8212. #ifndef NO_ASN
  8213. size_t bytes = 0;
  8214. word32 idx;
  8215. #endif
  8216. word32 pubSz[BENCH_MAX_PENDING];
  8217. word32 privSz[BENCH_MAX_PENDING];
  8218. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8219. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8220. word32 agreeSz[BENCH_MAX_PENDING];
  8221. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8222. #ifdef HAVE_PUBLIC_FFDHE
  8223. const DhParams *params = NULL;
  8224. #else
  8225. int paramName = 0;
  8226. #endif
  8227. #endif
  8228. DECLARE_MULTI_VALUE_STATS_VARS()
  8229. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8230. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8231. WC_DECLARE_VAR(pub2, byte,
  8232. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8233. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8234. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8235. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8236. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8237. WC_DECLARE_VAR(priv2, byte,
  8238. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8239. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8240. XMEMSET(pub, 0, sizeof(pub));
  8241. XMEMSET(agree, 0, sizeof(agree));
  8242. XMEMSET(priv, 0, sizeof(priv));
  8243. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8244. sizeof(DhKey), HEAP_HINT);
  8245. WC_ALLOC_ARRAY(pub, byte,
  8246. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8247. WC_ALLOC_ARRAY(agree, byte,
  8248. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8249. WC_ALLOC_ARRAY(priv, byte,
  8250. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8251. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8252. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8253. (void)tmp;
  8254. if (!use_ffdhe) {
  8255. #if defined(NO_ASN)
  8256. dhKeySz = 1024;
  8257. /* do nothing, but don't use default FILE */
  8258. #elif defined(USE_CERT_BUFFERS_1024)
  8259. tmp = dh_key_der_1024;
  8260. bytes = (size_t)sizeof_dh_key_der_1024;
  8261. dhKeySz = 1024;
  8262. #elif defined(USE_CERT_BUFFERS_2048)
  8263. tmp = dh_key_der_2048;
  8264. bytes = (size_t)sizeof_dh_key_der_2048;
  8265. dhKeySz = 2048;
  8266. #elif defined(USE_CERT_BUFFERS_3072)
  8267. tmp = dh_key_der_3072;
  8268. bytes = (size_t)sizeof_dh_key_der_3072;
  8269. dhKeySz = 3072;
  8270. #elif defined(USE_CERT_BUFFERS_4096)
  8271. tmp = dh_key_der_4096;
  8272. bytes = (size_t)sizeof_dh_key_der_4096;
  8273. dhKeySz = 4096;
  8274. #else
  8275. #error "need to define a cert buffer size"
  8276. #endif /* USE_CERT_BUFFERS */
  8277. }
  8278. #ifdef HAVE_FFDHE_2048
  8279. else if (use_ffdhe == 2048) {
  8280. #ifdef HAVE_PUBLIC_FFDHE
  8281. params = wc_Dh_ffdhe2048_Get();
  8282. #else
  8283. paramName = WC_FFDHE_2048;
  8284. #endif
  8285. dhKeySz = 2048;
  8286. }
  8287. #endif
  8288. #ifdef HAVE_FFDHE_3072
  8289. else if (use_ffdhe == 3072) {
  8290. #ifdef HAVE_PUBLIC_FFDHE
  8291. params = wc_Dh_ffdhe3072_Get();
  8292. #else
  8293. paramName = WC_FFDHE_3072;
  8294. #endif
  8295. dhKeySz = 3072;
  8296. }
  8297. #endif
  8298. #ifdef HAVE_FFDHE_4096
  8299. else if (use_ffdhe == 4096) {
  8300. #ifdef HAVE_PUBLIC_FFDHE
  8301. params = wc_Dh_ffdhe4096_Get();
  8302. #else
  8303. paramName = WC_FFDHE_4096;
  8304. #endif
  8305. dhKeySz = 4096;
  8306. }
  8307. #endif
  8308. /* init keys */
  8309. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8310. /* setup an async context for each key */
  8311. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8312. useDeviceID ? devId : INVALID_DEVID);
  8313. if (ret != 0)
  8314. goto exit;
  8315. /* setup key */
  8316. if (!use_ffdhe) {
  8317. #ifdef NO_ASN
  8318. ret = wc_DhSetKey(dhKey[i], dh_p,
  8319. sizeof(dh_p), dh_g, sizeof(dh_g));
  8320. #else
  8321. idx = 0;
  8322. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8323. #endif
  8324. }
  8325. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8326. #ifdef HAVE_PUBLIC_FFDHE
  8327. else if (params != NULL) {
  8328. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8329. params->g, params->g_len);
  8330. }
  8331. #else
  8332. else if (paramName != 0) {
  8333. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8334. }
  8335. #endif
  8336. #endif
  8337. if (ret != 0) {
  8338. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8339. goto exit;
  8340. }
  8341. }
  8342. /* Key Gen */
  8343. bench_stats_start(&count, &start);
  8344. PRIVATE_KEY_UNLOCK();
  8345. do {
  8346. /* while free pending slots in queue, submit ops */
  8347. for (times = 0; times < genTimes || pending > 0; ) {
  8348. bench_async_poll(&pending);
  8349. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8350. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8351. 0, &times, genTimes, &pending)) {
  8352. privSz[i] = BENCH_DH_PRIV_SIZE;
  8353. pubSz[i] = BENCH_DH_KEY_SIZE;
  8354. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8355. priv[i], &privSz[i],
  8356. pub[i], &pubSz[i]);
  8357. if (!bench_async_handle(&ret,
  8358. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8359. 0, &times, &pending)) {
  8360. goto exit_dh_gen;
  8361. }
  8362. }
  8363. } /* for i */
  8364. RECORD_MULTI_VALUE_STATS();
  8365. } /* for times */
  8366. count += times;
  8367. } while (bench_stats_check(start)
  8368. #ifdef MULTI_VALUE_STATISTICS
  8369. || runs < minimum_runs
  8370. #endif
  8371. );
  8372. PRIVATE_KEY_LOCK();
  8373. exit_dh_gen:
  8374. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8375. useDeviceID, count, start, ret);
  8376. #ifdef MULTI_VALUE_STATISTICS
  8377. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8378. #endif
  8379. if (ret < 0) {
  8380. goto exit;
  8381. }
  8382. RESET_MULTI_VALUE_STATS_VARS();
  8383. /* Generate key to use as other public */
  8384. PRIVATE_KEY_UNLOCK();
  8385. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8386. priv2, &privSz2, pub2, &pubSz2);
  8387. PRIVATE_KEY_LOCK();
  8388. #ifdef WOLFSSL_ASYNC_CRYPT
  8389. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8390. #endif
  8391. /* Key Agree */
  8392. bench_stats_start(&count, &start);
  8393. PRIVATE_KEY_UNLOCK();
  8394. do {
  8395. for (times = 0; times < agreeTimes || pending > 0; ) {
  8396. bench_async_poll(&pending);
  8397. /* while free pending slots in queue, submit ops */
  8398. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8399. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8400. 0, &times, agreeTimes, &pending)) {
  8401. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8402. privSz[i], pub2, pubSz2);
  8403. if (!bench_async_handle(&ret,
  8404. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8405. goto exit;
  8406. }
  8407. }
  8408. } /* for i */
  8409. RECORD_MULTI_VALUE_STATS();
  8410. } /* for times */
  8411. count += times;
  8412. } while (bench_stats_check(start)
  8413. #ifdef MULTI_VALUE_STATISTICS
  8414. || runs < minimum_runs
  8415. #endif
  8416. );
  8417. PRIVATE_KEY_LOCK();
  8418. exit:
  8419. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8420. useDeviceID, count, start, ret);
  8421. #ifdef MULTI_VALUE_STATISTICS
  8422. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8423. #endif
  8424. /* cleanup */
  8425. if (WC_ARRAY_OK(dhKey)) {
  8426. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8427. wc_FreeDhKey(dhKey[i]);
  8428. }
  8429. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8430. }
  8431. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8432. WC_FREE_VAR(pub2, HEAP_HINT);
  8433. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8434. WC_FREE_VAR(priv2, HEAP_HINT);
  8435. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8436. }
  8437. #endif /* !NO_DH */
  8438. #ifdef WOLFSSL_HAVE_KYBER
  8439. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8440. KyberKey* key)
  8441. {
  8442. int ret = 0, times, count, pending = 0;
  8443. double start;
  8444. const char**desc = bench_desc_words[lng_index];
  8445. DECLARE_MULTI_VALUE_STATS_VARS()
  8446. /* KYBER Make Key */
  8447. bench_stats_start(&count, &start);
  8448. do {
  8449. /* while free pending slots in queue, submit ops */
  8450. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8451. wc_KyberKey_Free(key);
  8452. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8453. if (ret != 0)
  8454. goto exit;
  8455. #ifdef KYBER_NONDETERMINISTIC
  8456. ret = wc_KyberKey_MakeKey(key, &gRng);
  8457. #else
  8458. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8459. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8460. #endif
  8461. if (ret != 0)
  8462. goto exit;
  8463. RECORD_MULTI_VALUE_STATS();
  8464. } /* for times */
  8465. count += times;
  8466. } while (bench_stats_check(start)
  8467. #ifdef MULTI_VALUE_STATISTICS
  8468. || runs < minimum_runs
  8469. #endif
  8470. );
  8471. exit:
  8472. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8473. #ifdef MULTI_VALUE_STATISTICS
  8474. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8475. #endif
  8476. }
  8477. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8478. {
  8479. int ret = 0, times, count, pending = 0;
  8480. double start;
  8481. const char**desc = bench_desc_words[lng_index];
  8482. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8483. byte ss[KYBER_SS_SZ];
  8484. word32 ctSz;
  8485. DECLARE_MULTI_VALUE_STATS_VARS()
  8486. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8487. if (ret != 0) {
  8488. return;
  8489. }
  8490. /* KYBER Encapsulate */
  8491. bench_stats_start(&count, &start);
  8492. do {
  8493. /* while free pending slots in queue, submit ops */
  8494. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8495. #ifdef KYBER_NONDETERMINISTIC
  8496. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8497. #else
  8498. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8499. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8500. sizeof(rand));
  8501. #endif
  8502. if (ret != 0)
  8503. goto exit_encap;
  8504. RECORD_MULTI_VALUE_STATS();
  8505. } /* for times */
  8506. count += times;
  8507. } while (bench_stats_check(start)
  8508. #ifdef MULTI_VALUE_STATISTICS
  8509. || runs < minimum_runs
  8510. #endif
  8511. );
  8512. exit_encap:
  8513. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8514. #ifdef MULTI_VALUE_STATISTICS
  8515. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8516. #endif
  8517. RESET_MULTI_VALUE_STATS_VARS();
  8518. /* KYBER Decapsulate */
  8519. bench_stats_start(&count, &start);
  8520. do {
  8521. /* while free pending slots in queue, submit ops */
  8522. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8523. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8524. if (ret != 0)
  8525. goto exit_decap;
  8526. RECORD_MULTI_VALUE_STATS();
  8527. } /* for times */
  8528. count += times;
  8529. } while (bench_stats_check(start)
  8530. #ifdef MULTI_VALUE_STATISTICS
  8531. || runs < minimum_runs
  8532. #endif
  8533. );
  8534. exit_decap:
  8535. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8536. #ifdef MULTI_VALUE_STATISTICS
  8537. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8538. #endif
  8539. }
  8540. void bench_kyber(int type)
  8541. {
  8542. KyberKey key;
  8543. const char* name = NULL;
  8544. int keySize = 0;
  8545. switch (type) {
  8546. #ifdef WOLFSSL_KYBER512
  8547. case KYBER512:
  8548. name = "KYBER512 ";
  8549. keySize = 128;
  8550. break;
  8551. #endif
  8552. #ifdef WOLFSSL_KYBER768
  8553. case KYBER768:
  8554. name = "KYBER768 ";
  8555. keySize = 192;
  8556. break;
  8557. #endif
  8558. #ifdef WOLFSSL_KYBER1024
  8559. case KYBER1024:
  8560. name = "KYBER1024";
  8561. keySize = 256;
  8562. break;
  8563. #endif
  8564. }
  8565. bench_kyber_keygen(type, name, keySize, &key);
  8566. bench_kyber_encap(name, keySize, &key);
  8567. wc_KyberKey_Free(&key);
  8568. }
  8569. #endif
  8570. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8571. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8572. /* WC_LMS_PARM_L2_H10_W2
  8573. * signature length: 9300 */
  8574. static const byte lms_priv_L2_H10_W2[64] =
  8575. {
  8576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8577. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8578. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8579. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8580. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8581. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8582. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8583. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8584. };
  8585. static const byte lms_pub_L2_H10_W2[60] =
  8586. {
  8587. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8588. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8589. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8590. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8591. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8592. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8593. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8594. 0x7F,0xC8,0x91,0xB0
  8595. };
  8596. /* WC_LMS_PARM_L2_H10_W4
  8597. * signature length: 5076 */
  8598. static const byte lms_priv_L2_H10_W4[64] =
  8599. {
  8600. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8601. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8602. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8603. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8604. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8605. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8606. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8607. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8608. };
  8609. static const byte lms_pub_L2_H10_W4[60] =
  8610. {
  8611. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8612. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8613. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8614. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8615. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8616. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8617. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8618. 0x6B,0x9A,0xD3,0x14
  8619. };
  8620. /* WC_LMS_PARM_L3_H5_W4
  8621. * signature length: 7160 */
  8622. static const byte lms_priv_L3_H5_W4[64] =
  8623. {
  8624. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8625. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8626. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8627. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8628. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8629. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8630. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8631. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8632. };
  8633. static const byte lms_pub_L3_H5_W4[60] =
  8634. {
  8635. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8636. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8637. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8638. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8639. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8640. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8641. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8642. 0xAB,0x4B,0x51,0x39
  8643. };
  8644. /* WC_LMS_PARM_L3_H5_W8
  8645. * signature length: 3992 */
  8646. static const byte lms_priv_L3_H5_W8[64] =
  8647. {
  8648. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8649. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8650. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8651. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8652. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8653. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8654. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8655. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8656. };
  8657. static const byte lms_pub_L3_H5_W8[60] =
  8658. {
  8659. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8660. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8661. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8662. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8663. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8664. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8665. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8666. 0x83,0xAB,0x43,0xAF
  8667. };
  8668. /* WC_LMS_PARM_L3_H10_W4
  8669. * signature length: 7640 */
  8670. static const byte lms_priv_L3_H10_W4[64] =
  8671. {
  8672. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8673. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8674. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8675. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8676. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8677. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8678. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8679. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8680. };
  8681. static const byte lms_pub_L3_H10_W4[60] =
  8682. {
  8683. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8684. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8685. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8686. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8687. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8688. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8689. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8690. 0x8D,0x78,0xD5,0xA8
  8691. };
  8692. /* WC_LMS_PARM_L4_H5_W8
  8693. * signature length: 5340 */
  8694. static const byte lms_priv_L4_H5_W8[64] =
  8695. {
  8696. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8697. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8698. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8699. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8700. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8701. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8702. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8703. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8704. };
  8705. static const byte lms_pub_L4_H5_W8[60] =
  8706. {
  8707. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8708. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8709. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8710. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8711. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8712. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8713. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8714. 0x74,0x24,0x12,0xC8
  8715. };
  8716. #endif
  8717. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8718. {
  8719. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8720. * BE USED FOR TESTING PURPOSES! Production applications should
  8721. * write only to non-volatile storage. */
  8722. XMEMCPY(context, priv, privSz);
  8723. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8724. }
  8725. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8726. {
  8727. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8728. * BE USED FOR TESTING PURPOSES! */
  8729. XMEMCPY(priv, context, privSz);
  8730. return WC_LMS_RC_READ_TO_MEMORY;
  8731. }
  8732. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8733. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8734. {
  8735. WC_RNG rng;
  8736. LmsKey key;
  8737. int ret;
  8738. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8739. int times = 0;
  8740. int count = 0;
  8741. double start = 0.0F;
  8742. int levels;
  8743. int height;
  8744. int winternitz;
  8745. const char* str = wc_LmsKey_ParmToStr(parm);
  8746. DECLARE_MULTI_VALUE_STATS_VARS()
  8747. #ifndef HAVE_FIPS
  8748. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8749. #else
  8750. ret = wc_InitRng(&rng);
  8751. #endif
  8752. if (ret != 0) {
  8753. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8754. return;
  8755. }
  8756. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8757. if (ret) {
  8758. printf("wc_LmsKey_Init failed: %d\n", ret);
  8759. wc_FreeRng(&rng);
  8760. return;
  8761. }
  8762. count = 0;
  8763. bench_stats_start(&count, &start);
  8764. do {
  8765. /* LMS is stateful. Async queuing not practical. */
  8766. for (times = 0; times < 1; ++times) {
  8767. wc_LmsKey_Free(&key);
  8768. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8769. if (ret) {
  8770. printf("wc_LmsKey_Init failed: %d\n", ret);
  8771. goto exit_lms_keygen;
  8772. }
  8773. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8774. if (ret) {
  8775. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8776. goto exit_lms_keygen;
  8777. }
  8778. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8779. if (ret) {
  8780. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8781. ret);
  8782. goto exit_lms_keygen;
  8783. }
  8784. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8785. if (ret) {
  8786. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8787. ret);
  8788. goto exit_lms_keygen;
  8789. }
  8790. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8791. if (ret) {
  8792. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8793. goto exit_lms_keygen;
  8794. }
  8795. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8796. if (ret) {
  8797. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8798. ret);
  8799. goto exit_lms_keygen;
  8800. }
  8801. ret = wc_LmsKey_MakeKey(&key, &rng);
  8802. if (ret) {
  8803. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8804. goto exit_lms_keygen;
  8805. }
  8806. RECORD_MULTI_VALUE_STATS();
  8807. }
  8808. count += times;
  8809. } while (bench_stats_check(start)
  8810. #ifdef MULTI_VALUE_STATISTICS
  8811. || runs < minimum_runs
  8812. #endif
  8813. );
  8814. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8815. count, start, ret);
  8816. #ifdef MULTI_VALUE_STATISTICS
  8817. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8818. #endif
  8819. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8820. if (ret) {
  8821. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8822. }
  8823. exit_lms_keygen:
  8824. wc_LmsKey_Free(&key);
  8825. wc_FreeRng(&rng);
  8826. }
  8827. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8828. {
  8829. LmsKey key;
  8830. int ret = 0;
  8831. const char * msg = TEST_STRING;
  8832. word32 msgSz = TEST_STRING_SZ;
  8833. byte * sig = NULL;
  8834. word32 sigSz = 0;
  8835. word32 privLen = 0;
  8836. int loaded = 0;
  8837. int times = 0;
  8838. int count = 0;
  8839. double start = 0.0F;
  8840. const char * str = wc_LmsKey_ParmToStr(parm);
  8841. DECLARE_MULTI_VALUE_STATS_VARS()
  8842. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8843. if (ret) {
  8844. printf("wc_LmsKey_Init failed: %d\n", ret);
  8845. goto exit_lms_sign_verify;
  8846. }
  8847. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8848. if (ret) {
  8849. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8850. goto exit_lms_sign_verify;
  8851. }
  8852. switch (parm) {
  8853. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8854. case WC_LMS_PARM_L2_H10_W2:
  8855. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8856. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8857. break;
  8858. case WC_LMS_PARM_L2_H10_W4:
  8859. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8860. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8861. break;
  8862. case WC_LMS_PARM_L3_H5_W4:
  8863. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8864. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8865. break;
  8866. case WC_LMS_PARM_L3_H5_W8:
  8867. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8868. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8869. break;
  8870. case WC_LMS_PARM_L3_H10_W4:
  8871. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8872. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8873. break;
  8874. case WC_LMS_PARM_L4_H5_W8:
  8875. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8876. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8877. break;
  8878. case WC_LMS_PARM_NONE:
  8879. case WC_LMS_PARM_L1_H15_W2:
  8880. case WC_LMS_PARM_L1_H15_W4:
  8881. case WC_LMS_PARM_L2_H10_W8:
  8882. case WC_LMS_PARM_L3_H5_W2:
  8883. case WC_LMS_PARM_L1_H5_W1:
  8884. case WC_LMS_PARM_L1_H5_W2:
  8885. case WC_LMS_PARM_L1_H5_W4:
  8886. case WC_LMS_PARM_L1_H5_W8:
  8887. case WC_LMS_PARM_L1_H10_W2:
  8888. case WC_LMS_PARM_L1_H10_W4:
  8889. case WC_LMS_PARM_L1_H10_W8:
  8890. case WC_LMS_PARM_L1_H15_W8:
  8891. case WC_LMS_PARM_L1_H20_W2:
  8892. case WC_LMS_PARM_L1_H20_W4:
  8893. case WC_LMS_PARM_L1_H20_W8:
  8894. case WC_LMS_PARM_L2_H5_W2:
  8895. case WC_LMS_PARM_L2_H5_W4:
  8896. case WC_LMS_PARM_L2_H5_W8:
  8897. case WC_LMS_PARM_L2_H15_W2:
  8898. case WC_LMS_PARM_L2_H15_W4:
  8899. case WC_LMS_PARM_L2_H15_W8:
  8900. case WC_LMS_PARM_L2_H20_W2:
  8901. case WC_LMS_PARM_L2_H20_W4:
  8902. case WC_LMS_PARM_L2_H20_W8:
  8903. case WC_LMS_PARM_L3_H10_W8:
  8904. case WC_LMS_PARM_L4_H5_W2:
  8905. case WC_LMS_PARM_L4_H5_W4:
  8906. case WC_LMS_PARM_L4_H10_W4:
  8907. case WC_LMS_PARM_L4_H10_W8:
  8908. #endif
  8909. #ifdef WOLFSSL_LMS_SHA256_192
  8910. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  8911. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  8912. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  8913. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  8914. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  8915. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  8916. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  8917. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  8918. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  8919. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  8920. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  8921. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  8922. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  8923. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  8924. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  8925. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  8926. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  8927. #endif
  8928. default:
  8929. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8930. break;
  8931. }
  8932. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8933. if (ret) {
  8934. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8935. goto exit_lms_sign_verify;
  8936. }
  8937. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8938. if (ret) {
  8939. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8940. goto exit_lms_sign_verify;
  8941. }
  8942. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8943. if (ret) {
  8944. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8945. goto exit_lms_sign_verify;
  8946. }
  8947. /* Even with saved priv/pub keys, we must still reload the private
  8948. * key before using it. Reloading the private key is the bottleneck
  8949. * for larger heights. Only print load time in debug builds. */
  8950. count = 0;
  8951. bench_stats_start(&count, &start);
  8952. #ifndef WOLFSSL_WC_LMS_SMALL
  8953. do {
  8954. #ifdef WOLFSSL_WC_LMS
  8955. key.priv.inited = 0;
  8956. key.state = WC_LMS_STATE_PARMSET;
  8957. #endif
  8958. ret = wc_LmsKey_Reload(&key);
  8959. if (ret) {
  8960. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8961. goto exit_lms_sign_verify;
  8962. }
  8963. RECORD_MULTI_VALUE_STATS();
  8964. count++;
  8965. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8966. if (ret) {
  8967. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8968. goto exit_lms_sign_verify;
  8969. }
  8970. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8971. if (ret) {
  8972. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8973. goto exit_lms_sign_verify;
  8974. }
  8975. #ifdef HAVE_LIBLMS
  8976. break;
  8977. #endif
  8978. } while (bench_stats_check(start)
  8979. #ifdef MULTI_VALUE_STATISTICS
  8980. || runs < minimum_runs
  8981. #endif
  8982. );
  8983. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  8984. count, start, ret);
  8985. #ifdef MULTI_VALUE_STATISTICS
  8986. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8987. #endif
  8988. RESET_MULTI_VALUE_STATS_VARS();
  8989. #else
  8990. ret = wc_LmsKey_Reload(&key);
  8991. if (ret) {
  8992. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8993. goto exit_lms_sign_verify;
  8994. }
  8995. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8996. if (ret) {
  8997. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8998. goto exit_lms_sign_verify;
  8999. }
  9000. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9001. if (ret) {
  9002. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9003. goto exit_lms_sign_verify;
  9004. }
  9005. #endif
  9006. loaded = 1;
  9007. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9008. if (sig == NULL) {
  9009. printf("bench_lms_sign_verify malloc failed\n");
  9010. goto exit_lms_sign_verify;
  9011. }
  9012. count = 0;
  9013. bench_stats_start(&count, &start);
  9014. do {
  9015. /* LMS is stateful. Async queuing not practical. */
  9016. #ifndef WOLFSSL_WC_LMS_SMALL
  9017. for (times = 0; times < ntimes; ++times)
  9018. #else
  9019. for (times = 0; times < 1; ++times)
  9020. #endif
  9021. {
  9022. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9023. if (ret) {
  9024. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9025. goto exit_lms_sign_verify;
  9026. }
  9027. RECORD_MULTI_VALUE_STATS();
  9028. if (!wc_LmsKey_SigsLeft(&key)) {
  9029. break;
  9030. }
  9031. }
  9032. count += times;
  9033. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9034. #ifdef MULTI_VALUE_STATISTICS
  9035. || runs < minimum_runs
  9036. #endif
  9037. ));
  9038. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9039. count, start, ret);
  9040. #ifdef MULTI_VALUE_STATISTICS
  9041. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9042. #endif
  9043. RESET_MULTI_VALUE_STATS_VARS();
  9044. count = 0;
  9045. bench_stats_start(&count, &start);
  9046. do {
  9047. /* LMS is stateful. Async queuing not practical. */
  9048. for (times = 0; times < ntimes; ++times) {
  9049. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9050. if (ret) {
  9051. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9052. goto exit_lms_sign_verify;
  9053. }
  9054. RECORD_MULTI_VALUE_STATS();
  9055. }
  9056. count += times;
  9057. } while (bench_stats_check(start)
  9058. #ifdef MULTI_VALUE_STATISTICS
  9059. || runs < minimum_runs
  9060. #endif
  9061. );
  9062. exit_lms_sign_verify:
  9063. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9064. count, start, ret);
  9065. #ifdef MULTI_VALUE_STATISTICS
  9066. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9067. #endif
  9068. if (loaded) {
  9069. wc_LmsKey_Free(&key);
  9070. }
  9071. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9072. return;
  9073. }
  9074. void bench_lms(void)
  9075. {
  9076. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9077. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9078. #ifdef BENCH_LMS_SLOW_KEYGEN
  9079. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9080. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9081. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9082. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9083. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9084. #undef LMS_PARAMS_BENCHED
  9085. #define LMS_PARAMS_BENCHED
  9086. #endif
  9087. #endif
  9088. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9089. (LMS_MAX_HEIGHT >= 10))
  9090. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9091. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9092. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9093. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9094. #undef LMS_PARAMS_BENCHED
  9095. #define LMS_PARAMS_BENCHED
  9096. #ifdef BENCH_LMS_SLOW_KEYGEN
  9097. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9098. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9099. #endif
  9100. #endif
  9101. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9102. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9103. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9104. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9105. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9106. #undef LMS_PARAMS_BENCHED
  9107. #define LMS_PARAMS_BENCHED
  9108. #endif
  9109. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9110. (LMS_MAX_HEIGHT >= 10))
  9111. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9112. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9113. #endif
  9114. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9115. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9116. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9117. #endif
  9118. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9119. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9120. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9121. #endif
  9122. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9123. #ifdef WOLFSSL_LMS_SHA256_192
  9124. #ifdef BENCH_LMS_SLOW_KEYGEN
  9125. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9126. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9127. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9128. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9129. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9130. #undef LMS_PARAMS_BENCHED
  9131. #define LMS_PARAMS_BENCHED
  9132. #endif
  9133. #endif
  9134. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9135. (LMS_MAX_HEIGHT >= 10))
  9136. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9137. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9138. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9139. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9140. #undef LMS_PARAMS_BENCHED
  9141. #define LMS_PARAMS_BENCHED
  9142. #ifdef BENCH_LMS_SLOW_KEYGEN
  9143. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9144. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9145. #endif
  9146. #endif
  9147. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9148. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9149. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9150. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9151. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9152. #undef LMS_PARAMS_BENCHED
  9153. #define LMS_PARAMS_BENCHED
  9154. #endif
  9155. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9156. (LMS_MAX_HEIGHT >= 10))
  9157. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9158. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9159. #endif
  9160. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9161. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9162. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9163. #endif
  9164. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9165. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9166. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9167. #endif
  9168. #endif /* WOLFSSL_LMS_SHA256_192 */
  9169. return;
  9170. }
  9171. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9172. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9173. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9174. void *context)
  9175. {
  9176. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9177. * BE USED FOR TESTING PURPOSES! Production applications should
  9178. * write only to non-volatile storage. */
  9179. XMEMCPY(context, priv, privSz);
  9180. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9181. }
  9182. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9183. void *context)
  9184. {
  9185. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9186. * BE USED FOR TESTING PURPOSES! */
  9187. XMEMCPY(priv, context, privSz);
  9188. return WC_XMSS_RC_READ_TO_MEMORY;
  9189. }
  9190. static void bench_xmss_sign_verify(const char * params)
  9191. {
  9192. WC_RNG rng;
  9193. XmssKey key;
  9194. word32 pkSz = 0;
  9195. word32 skSz = 0;
  9196. int freeRng = 0;
  9197. int freeKey = 0;
  9198. unsigned char * sk = NULL;
  9199. const char * msg = "XMSS post quantum signature test";
  9200. word32 msgSz = (word32) XSTRLEN(msg);
  9201. int ret = 0;
  9202. byte * sig = NULL;
  9203. word32 sigSz = 0;
  9204. int times = 0;
  9205. int count = 0;
  9206. double start = 0.0F;
  9207. #ifndef HAVE_FIPS
  9208. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9209. #else
  9210. ret = wc_InitRng(&rng);
  9211. #endif
  9212. if (ret != 0) {
  9213. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9214. goto exit_xmss_sign_verify;
  9215. }
  9216. freeRng = 1;
  9217. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9218. if (ret != 0) {
  9219. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9220. goto exit_xmss_sign_verify;
  9221. }
  9222. ret = wc_XmssKey_SetParamStr(&key, params);
  9223. if (ret != 0) {
  9224. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9225. goto exit_xmss_sign_verify;
  9226. }
  9227. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9228. if (ret != 0) {
  9229. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9230. goto exit_xmss_sign_verify;
  9231. }
  9232. #ifndef WOLFSSL_WC_XMSS
  9233. if (pkSz != XMSS_SHA256_PUBLEN) {
  9234. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9235. XMSS_SHA256_PUBLEN);
  9236. goto exit_xmss_sign_verify;
  9237. }
  9238. #endif
  9239. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9240. if (ret != 0 || skSz <= 0) {
  9241. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9242. goto exit_xmss_sign_verify;
  9243. }
  9244. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9245. if (ret != 0 || sigSz <= 0) {
  9246. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9247. goto exit_xmss_sign_verify;
  9248. }
  9249. /* Allocate secret keys.*/
  9250. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9251. if (sk == NULL) {
  9252. fprintf(stderr, "error: allocate xmss sk failed\n");
  9253. goto exit_xmss_sign_verify;
  9254. }
  9255. /* Allocate signature array. */
  9256. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9257. if (sig == NULL) {
  9258. fprintf(stderr, "error: allocate xmss sig failed\n");
  9259. goto exit_xmss_sign_verify;
  9260. }
  9261. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9262. if (ret != 0) {
  9263. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9264. goto exit_xmss_sign_verify;
  9265. }
  9266. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9267. if (ret != 0) {
  9268. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9269. goto exit_xmss_sign_verify;
  9270. }
  9271. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9272. if (ret != 0) {
  9273. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9274. goto exit_xmss_sign_verify;
  9275. }
  9276. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9277. fprintf(stderr, "params: %s\n", params);
  9278. fprintf(stderr, "pkSz: %d\n", pkSz);
  9279. fprintf(stderr, "skSz: %d\n", skSz);
  9280. fprintf(stderr, "sigSz: %d\n", sigSz);
  9281. #endif
  9282. /* Making the private key is the bottleneck for larger heights. */
  9283. count = 0;
  9284. bench_stats_start(&count, &start);
  9285. ret = wc_XmssKey_MakeKey(&key, &rng);
  9286. if (ret != 0) {
  9287. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9288. goto exit_xmss_sign_verify;
  9289. }
  9290. /* Can only do one at a time - state changes after make key. */
  9291. count +=1;
  9292. bench_stats_check(start);
  9293. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9294. freeKey = 1;
  9295. count = 0;
  9296. bench_stats_start(&count, &start);
  9297. do {
  9298. /* XMSS is stateful. Async queuing not practical. */
  9299. #ifndef WOLFSSL_WC_XMSS_SMALL
  9300. for (times = 0; times < ntimes; ++times)
  9301. #else
  9302. for (times = 0; times < 1; ++times)
  9303. #endif
  9304. {
  9305. if (!wc_XmssKey_SigsLeft(&key))
  9306. break;
  9307. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9308. if (ret) {
  9309. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9310. goto exit_xmss_sign_verify;
  9311. }
  9312. }
  9313. count += times;
  9314. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9315. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9316. count = 0;
  9317. bench_stats_start(&count, &start);
  9318. do {
  9319. /* XMSS is stateful. Async queuing not practical. */
  9320. for (times = 0; times < ntimes; ++times) {
  9321. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9322. if (ret) {
  9323. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9324. goto exit_xmss_sign_verify;
  9325. }
  9326. }
  9327. count += times;
  9328. } while (bench_stats_check(start));
  9329. exit_xmss_sign_verify:
  9330. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9331. /* Cleanup everything. */
  9332. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9333. sig = NULL;
  9334. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9335. sk = NULL;
  9336. if (freeRng) {
  9337. wc_FreeRng(&rng);
  9338. }
  9339. if (freeKey) {
  9340. wc_XmssKey_Free(&key);
  9341. }
  9342. return;
  9343. }
  9344. void bench_xmss(int hash)
  9345. {
  9346. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9347. * sets.
  9348. *
  9349. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9350. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9351. * very slow, their signatures and private keys quite large,
  9352. * and xmss private keys are not portable across different
  9353. * XMSS/XMSS^MT implementations.
  9354. *
  9355. * The bottleneck in key generation is the height of the first
  9356. * level tree (or h/d).
  9357. *
  9358. * h is the total height of the hyper tree, and d the number of
  9359. * trees.
  9360. */
  9361. /* h/d h d */
  9362. #ifdef WC_XMSS_SHA256
  9363. if (hash == WC_HASH_TYPE_SHA256) {
  9364. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9365. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9366. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9367. #endif
  9368. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9369. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9370. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9371. #endif
  9372. #endif
  9373. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9374. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9375. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9376. #endif
  9377. #endif
  9378. #endif /* HASH_SIZE 256 */
  9379. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9380. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9381. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9382. #endif
  9383. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9384. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9385. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9386. #endif
  9387. #endif
  9388. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9389. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9390. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9391. #endif
  9392. #endif
  9393. #endif /* HASH_SIZE 192 */
  9394. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9395. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9396. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9397. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9398. #endif
  9399. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9400. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9401. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9402. #endif
  9403. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9404. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9405. #endif
  9406. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9407. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9408. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9409. #endif
  9410. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9411. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9412. #endif
  9413. #endif /* HASH_SIZE 256 */
  9414. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9415. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9416. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9417. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9418. #endif
  9419. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9420. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9421. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9422. #endif
  9423. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9424. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9425. #endif
  9426. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9427. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9428. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9429. #endif
  9430. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9431. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9432. #endif
  9433. #endif /* HASH_SIZE 192 */
  9434. }
  9435. #endif
  9436. #ifdef WC_XMSS_SHA512
  9437. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9438. if (hash == WC_HASH_TYPE_SHA512) {
  9439. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9440. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9441. #endif
  9442. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9443. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9444. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9445. #endif
  9446. #endif
  9447. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9448. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9449. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9450. #endif
  9451. #endif
  9452. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9453. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9454. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9455. #endif
  9456. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9457. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9458. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9459. #endif
  9460. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9461. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9462. #endif
  9463. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9464. #endif
  9465. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9466. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9467. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9468. #endif
  9469. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9470. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9471. #endif
  9472. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9473. #endif
  9474. }
  9475. #endif /* HASH_SIZE 512 */
  9476. #endif
  9477. #ifdef WC_XMSS_SHAKE128
  9478. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9479. if (hash == WC_HASH_TYPE_SHAKE128) {
  9480. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9481. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 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-SHAKE_16_256"); /* 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-SHAKE_20_256"); /* 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-SHAKE_20/2_256"); /* 10 20 2 */
  9495. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 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-SHAKE_40/2_256"); /* 20 40 4 */
  9500. #endif
  9501. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9502. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9503. #endif
  9504. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 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-SHAKE_60/3_256"); /* 20 60 3 */
  9509. #endif
  9510. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9511. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9512. #endif
  9513. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9514. #endif
  9515. }
  9516. #endif /* HASH_SIZE 256 */
  9517. #endif
  9518. #ifdef WC_XMSS_SHAKE256
  9519. if (hash == WC_HASH_TYPE_SHAKE256) {
  9520. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9521. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9522. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 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_512"); /* 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_512"); /* 20 20 1 */
  9532. #endif
  9533. #endif
  9534. #endif /* HASH_SIZE 512 */
  9535. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9536. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9537. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9538. #endif
  9539. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9540. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9541. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9542. #endif
  9543. #endif
  9544. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9545. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9546. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9547. #endif
  9548. #endif
  9549. #endif /* HASH_SIZE 256 */
  9550. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9551. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9552. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9553. #endif
  9554. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9555. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9556. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9557. #endif
  9558. #endif
  9559. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9560. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9561. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9562. #endif
  9563. #endif
  9564. #endif /* HASH_SIZE 192 */
  9565. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9566. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9567. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9568. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9569. #endif
  9570. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9571. #endif
  9572. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9573. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9574. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9575. #endif
  9576. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9577. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9578. #endif
  9579. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9580. #endif
  9581. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9582. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9583. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9584. #endif
  9585. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9586. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9587. #endif
  9588. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9589. #endif
  9590. #endif /* HASH_SIZE 512 */
  9591. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9592. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9593. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9594. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9595. #endif
  9596. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9597. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9598. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9599. #endif
  9600. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9601. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9602. #endif
  9603. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9604. #endif
  9605. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9606. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9607. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9608. #endif
  9609. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9610. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9611. #endif
  9612. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9613. #endif
  9614. #endif /* HASH_SIZE 256 */
  9615. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9616. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9617. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9618. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9619. #endif
  9620. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9621. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9622. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9623. #endif
  9624. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9625. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9626. #endif
  9627. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9628. #endif
  9629. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9630. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9631. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9632. #endif
  9633. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9634. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9635. #endif
  9636. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9637. #endif
  9638. #endif /* HASH_SIZE 192 */
  9639. }
  9640. #endif
  9641. return;
  9642. }
  9643. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9644. #ifdef HAVE_ECC
  9645. /* Maximum ECC name plus null terminator:
  9646. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9647. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9648. /* run all benchmarks on a curve */
  9649. void bench_ecc_curve(int curveId)
  9650. {
  9651. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9652. #ifndef NO_SW_BENCH
  9653. bench_eccMakeKey(0, curveId);
  9654. #endif
  9655. #if defined(BENCH_DEVID)
  9656. bench_eccMakeKey(1, curveId);
  9657. #endif
  9658. }
  9659. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9660. #ifndef NO_SW_BENCH
  9661. bench_ecc(0, curveId);
  9662. #endif
  9663. #if defined(BENCH_DEVID)
  9664. bench_ecc(1, curveId);
  9665. #endif
  9666. }
  9667. #ifdef HAVE_ECC_ENCRYPT
  9668. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9669. bench_eccEncrypt(curveId);
  9670. #endif
  9671. }
  9672. void bench_eccMakeKey(int useDeviceID, int curveId)
  9673. {
  9674. int ret = 0, i, times, count = 0, pending = 0;
  9675. int deviceID;
  9676. int keySize = 0;
  9677. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9678. sizeof(ecc_key), HEAP_HINT);
  9679. char name[BENCH_ECC_NAME_SZ];
  9680. double start = 0;
  9681. const char**desc = bench_desc_words[lng_index];
  9682. DECLARE_MULTI_VALUE_STATS_VARS()
  9683. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9684. sizeof(ecc_key), HEAP_HINT);
  9685. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9686. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9687. /* ECC Make Key */
  9688. bench_stats_start(&count, &start);
  9689. do {
  9690. /* while free pending slots in queue, submit ops */
  9691. for (times = 0; times < agreeTimes || pending > 0; ) {
  9692. bench_async_poll(&pending);
  9693. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9694. if (bench_async_check(&ret,
  9695. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9696. &times, agreeTimes, &pending)) {
  9697. wc_ecc_free(genKey[i]);
  9698. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9699. if (ret < 0) {
  9700. goto exit;
  9701. }
  9702. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9703. curveId);
  9704. if (!bench_async_handle(&ret,
  9705. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9706. &pending)) {
  9707. goto exit;
  9708. }
  9709. }
  9710. } /* for i */
  9711. RECORD_MULTI_VALUE_STATS();
  9712. } /* for times */
  9713. count += times;
  9714. } while (bench_stats_check(start)
  9715. #ifdef MULTI_VALUE_STATISTICS
  9716. || runs < minimum_runs
  9717. #endif
  9718. );
  9719. exit:
  9720. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9721. wc_ecc_get_name(curveId));
  9722. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9723. useDeviceID, count, start, ret);
  9724. #ifdef MULTI_VALUE_STATISTICS
  9725. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9726. #endif
  9727. /* cleanup */
  9728. if (WC_ARRAY_OK(genKey)) {
  9729. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9730. wc_ecc_free(genKey[i]);
  9731. }
  9732. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9733. }
  9734. }
  9735. void bench_ecc(int useDeviceID, int curveId)
  9736. {
  9737. int ret = 0, i, times, count, pending = 0;
  9738. int deviceID;
  9739. int keySize;
  9740. char name[BENCH_ECC_NAME_SZ];
  9741. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9742. sizeof(ecc_key), HEAP_HINT);
  9743. #ifdef HAVE_ECC_DHE
  9744. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9745. sizeof(ecc_key), HEAP_HINT);
  9746. #endif
  9747. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9748. #ifdef HAVE_ECC_VERIFY
  9749. int verify[BENCH_MAX_PENDING];
  9750. #endif
  9751. #endif
  9752. word32 x[BENCH_MAX_PENDING];
  9753. double start = 0;
  9754. const char**desc = bench_desc_words[lng_index];
  9755. DECLARE_MULTI_VALUE_STATS_VARS()
  9756. #ifdef HAVE_ECC_DHE
  9757. WC_DECLARE_ARRAY(shared, byte,
  9758. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9759. #endif
  9760. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9761. WC_DECLARE_ARRAY(sig, byte,
  9762. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9763. WC_DECLARE_ARRAY(digest, byte,
  9764. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9765. #endif
  9766. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9767. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9768. XMEMSET(sig, 0, sizeof(sig));
  9769. XMEMSET(digest, 0, sizeof(digest));
  9770. #endif
  9771. #ifdef HAVE_ECC_DHE
  9772. XMEMSET(shared, 0, sizeof(shared));
  9773. #endif
  9774. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9775. sizeof(ecc_key), HEAP_HINT);
  9776. #ifdef HAVE_ECC_DHE
  9777. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9778. sizeof(ecc_key), HEAP_HINT);
  9779. WC_ALLOC_ARRAY(shared, byte,
  9780. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9781. #endif
  9782. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9783. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9784. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9785. #endif
  9786. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9787. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9788. /* init keys */
  9789. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9790. /* setup an context for each key */
  9791. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9792. goto exit;
  9793. }
  9794. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9795. #ifdef WOLFSSL_ASYNC_CRYPT
  9796. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9797. #endif
  9798. if (ret < 0) {
  9799. goto exit;
  9800. }
  9801. #ifdef HAVE_ECC_DHE
  9802. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9803. goto exit;
  9804. }
  9805. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9806. curveId)) > 0) {
  9807. goto exit;
  9808. }
  9809. #endif
  9810. }
  9811. #ifdef HAVE_ECC_DHE
  9812. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9813. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9814. !defined(HAVE_SELFTEST)
  9815. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9816. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9817. }
  9818. #endif
  9819. /* ECC Shared Secret */
  9820. bench_stats_start(&count, &start);
  9821. PRIVATE_KEY_UNLOCK();
  9822. do {
  9823. for (times = 0; times < agreeTimes || pending > 0; ) {
  9824. bench_async_poll(&pending);
  9825. /* while free pending slots in queue, submit ops */
  9826. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9827. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9828. &times, agreeTimes, &pending)) {
  9829. x[i] = (word32)keySize;
  9830. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9831. shared[i], &x[i]);
  9832. if (!bench_async_handle(&ret,
  9833. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9834. &pending)) {
  9835. goto exit_ecdhe;
  9836. }
  9837. }
  9838. } /* for i */
  9839. RECORD_MULTI_VALUE_STATS();
  9840. } /* for times */
  9841. count += times;
  9842. } while (bench_stats_check(start)
  9843. #ifdef MULTI_VALUE_STATISTICS
  9844. || runs < minimum_runs
  9845. #endif
  9846. );
  9847. PRIVATE_KEY_UNLOCK();
  9848. exit_ecdhe:
  9849. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9850. wc_ecc_get_name(curveId));
  9851. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9852. useDeviceID, count, start, ret);
  9853. #ifdef MULTI_VALUE_STATISTICS
  9854. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9855. #endif
  9856. RESET_MULTI_VALUE_STATS_VARS();
  9857. if (ret < 0) {
  9858. goto exit;
  9859. }
  9860. #endif /* HAVE_ECC_DHE */
  9861. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9862. /* Init digest to sign */
  9863. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9864. for (count = 0; count < keySize; count++) {
  9865. digest[i][count] = (byte)count;
  9866. }
  9867. }
  9868. /* ECC Sign */
  9869. bench_stats_start(&count, &start);
  9870. do {
  9871. for (times = 0; times < agreeTimes || pending > 0; ) {
  9872. bench_async_poll(&pending);
  9873. /* while free pending slots in queue, submit ops */
  9874. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9875. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9876. &times, agreeTimes, &pending)) {
  9877. if (genKey[i]->state == 0) {
  9878. x[i] = ECC_MAX_SIG_SIZE;
  9879. }
  9880. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9881. &x[i], GLOBAL_RNG, genKey[i]);
  9882. if (!bench_async_handle(&ret,
  9883. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9884. &pending)) {
  9885. goto exit_ecdsa_sign;
  9886. }
  9887. } /* bench_async_check */
  9888. } /* for i */
  9889. RECORD_MULTI_VALUE_STATS();
  9890. } /* for times */
  9891. count += times;
  9892. } while (bench_stats_check(start)
  9893. #ifdef MULTI_VALUE_STATISTICS
  9894. || runs < minimum_runs
  9895. #endif
  9896. );
  9897. exit_ecdsa_sign:
  9898. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9899. wc_ecc_get_name(curveId));
  9900. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9901. useDeviceID, count, start, ret);
  9902. #ifdef MULTI_VALUE_STATISTICS
  9903. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9904. #endif
  9905. RESET_MULTI_VALUE_STATS_VARS();
  9906. if (ret < 0) {
  9907. goto exit;
  9908. }
  9909. #ifdef HAVE_ECC_VERIFY
  9910. /* ECC Verify */
  9911. bench_stats_start(&count, &start);
  9912. do {
  9913. for (times = 0; times < agreeTimes || pending > 0; ) {
  9914. bench_async_poll(&pending);
  9915. /* while free pending slots in queue, submit ops */
  9916. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9917. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9918. &times, agreeTimes, &pending)) {
  9919. if (genKey[i]->state == 0) {
  9920. verify[i] = 0;
  9921. }
  9922. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9923. (word32)keySize, &verify[i],
  9924. genKey[i]);
  9925. if (!bench_async_handle(&ret,
  9926. BENCH_ASYNC_GET_DEV(genKey[i]),
  9927. 1, &times,
  9928. &pending)) {
  9929. goto exit_ecdsa_verify;
  9930. }
  9931. } /* if bench_async_check */
  9932. } /* for i */
  9933. RECORD_MULTI_VALUE_STATS();
  9934. } /* for times */
  9935. count += times;
  9936. } while (bench_stats_check(start)
  9937. #ifdef MULTI_VALUE_STATISTICS
  9938. || runs < minimum_runs
  9939. #endif
  9940. );
  9941. exit_ecdsa_verify:
  9942. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9943. wc_ecc_get_name(curveId));
  9944. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9945. useDeviceID, count, start, ret);
  9946. #ifdef MULTI_VALUE_STATISTICS
  9947. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9948. #endif
  9949. #endif /* HAVE_ECC_VERIFY */
  9950. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9951. exit:
  9952. /* cleanup */
  9953. if (WC_ARRAY_OK(genKey)) {
  9954. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9955. wc_ecc_free(genKey[i]);
  9956. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9957. }
  9958. #ifdef HAVE_ECC_DHE
  9959. if (WC_ARRAY_OK(genKey2)) {
  9960. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9961. wc_ecc_free(genKey2[i]);
  9962. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  9963. }
  9964. #endif
  9965. #ifdef HAVE_ECC_DHE
  9966. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  9967. #endif
  9968. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9969. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  9970. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  9971. #endif
  9972. (void)useDeviceID;
  9973. (void)pending;
  9974. (void)x;
  9975. (void)count;
  9976. (void)times;
  9977. (void)desc;
  9978. (void)start;
  9979. (void)name;
  9980. }
  9981. #ifdef HAVE_ECC_ENCRYPT
  9982. void bench_eccEncrypt(int curveId)
  9983. {
  9984. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  9985. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  9986. WC_SHA256_DIGEST_SIZE + \
  9987. (MAX_ECC_BITS+3)/4 + 2)
  9988. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  9989. #ifdef WOLFSSL_SMALL_STACK
  9990. ecc_key *userA = NULL, *userB = NULL;
  9991. byte *msg = NULL;
  9992. byte *out = NULL;
  9993. #else
  9994. ecc_key userA[1], userB[1];
  9995. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  9996. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  9997. #endif
  9998. char name[BENCH_ECC_NAME_SZ];
  9999. int keySize;
  10000. word32 bench_plainSz = bench_size;
  10001. int ret, i, count;
  10002. double start;
  10003. const char**desc = bench_desc_words[lng_index];
  10004. DECLARE_MULTI_VALUE_STATS_VARS()
  10005. #ifdef WOLFSSL_SMALL_STACK
  10006. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10007. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10008. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10009. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10010. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10011. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10012. out = (byte *)XMALLOC(outSz,
  10013. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10014. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10015. printf("bench_eccEncrypt malloc failed\n");
  10016. goto exit;
  10017. }
  10018. #endif
  10019. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10020. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10021. if (ret != 0) {
  10022. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10023. goto exit;
  10024. }
  10025. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10026. if (ret != 0) {
  10027. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10028. goto exit;
  10029. }
  10030. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10031. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10032. !defined(HAVE_SELFTEST)
  10033. ret = wc_ecc_set_rng(userA, &gRng);
  10034. if (ret != 0) {
  10035. goto exit;
  10036. }
  10037. ret = wc_ecc_set_rng(userB, &gRng);
  10038. if (ret != 0) {
  10039. goto exit;
  10040. }
  10041. #endif
  10042. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10043. #ifdef WOLFSSL_ASYNC_CRYPT
  10044. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10045. #endif
  10046. if (ret != 0)
  10047. goto exit;
  10048. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10049. #ifdef WOLFSSL_ASYNC_CRYPT
  10050. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10051. #endif
  10052. if (ret != 0)
  10053. goto exit;
  10054. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10055. msg[i] = (byte)i;
  10056. }
  10057. bench_stats_start(&count, &start);
  10058. do {
  10059. for (i = 0; i < ntimes; i++) {
  10060. /* encrypt msg to B */
  10061. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10062. out, &outSz, NULL);
  10063. if (ret != 0) {
  10064. printf("wc_ecc_encrypt failed! %d\n", ret);
  10065. goto exit_enc;
  10066. }
  10067. RECORD_MULTI_VALUE_STATS();
  10068. }
  10069. count += i;
  10070. } while (bench_stats_check(start)
  10071. #ifdef MULTI_VALUE_STATISTICS
  10072. || runs < minimum_runs
  10073. #endif
  10074. );
  10075. exit_enc:
  10076. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10077. wc_ecc_get_name(curveId));
  10078. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10079. #ifdef MULTI_VALUE_STATISTICS
  10080. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10081. #endif
  10082. RESET_MULTI_VALUE_STATS_VARS();
  10083. if (ret != 0)
  10084. goto exit;
  10085. bench_stats_start(&count, &start);
  10086. do {
  10087. for (i = 0; i < ntimes; i++) {
  10088. /* decrypt msg from A */
  10089. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10090. &bench_plainSz, NULL);
  10091. if (ret != 0) {
  10092. printf("wc_ecc_decrypt failed! %d\n", ret);
  10093. goto exit_dec;
  10094. }
  10095. RECORD_MULTI_VALUE_STATS();
  10096. }
  10097. count += i;
  10098. } while (bench_stats_check(start)
  10099. #ifdef MULTI_VALUE_STATISTICS
  10100. || runs < minimum_runs
  10101. #endif
  10102. );
  10103. exit_dec:
  10104. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10105. #ifdef MULTI_VALUE_STATISTICS
  10106. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10107. #endif
  10108. exit:
  10109. /* cleanup */
  10110. #ifdef WOLFSSL_SMALL_STACK
  10111. if (userA) {
  10112. wc_ecc_free(userA);
  10113. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10114. }
  10115. if (userB) {
  10116. wc_ecc_free(userB);
  10117. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10118. }
  10119. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10120. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10121. #else
  10122. wc_ecc_free(userB);
  10123. wc_ecc_free(userA);
  10124. #endif
  10125. }
  10126. #endif
  10127. #ifdef WOLFSSL_SM2
  10128. static void bench_sm2_MakeKey(int useDeviceID)
  10129. {
  10130. int ret = 0, i, times, count = 0, pending = 0;
  10131. int deviceID;
  10132. int keySize;
  10133. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10134. sizeof(ecc_key), HEAP_HINT);
  10135. char name[BENCH_ECC_NAME_SZ];
  10136. double start = 0;
  10137. const char**desc = bench_desc_words[lng_index];
  10138. DECLARE_MULTI_VALUE_STATS_VARS()
  10139. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10140. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10141. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10142. sizeof(ecc_key), HEAP_HINT);
  10143. /* ECC Make Key */
  10144. bench_stats_start(&count, &start);
  10145. do {
  10146. /* while free pending slots in queue, submit ops */
  10147. for (times = 0; times < agreeTimes || pending > 0; ) {
  10148. bench_async_poll(&pending);
  10149. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10150. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10151. &times, agreeTimes, &pending)) {
  10152. wc_ecc_free(genKey[i]);
  10153. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10154. if (ret < 0) {
  10155. goto exit;
  10156. }
  10157. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10158. WC_ECC_FLAG_NONE);
  10159. if (!bench_async_handle(&ret,
  10160. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10161. &pending)) {
  10162. goto exit;
  10163. }
  10164. }
  10165. } /* for i */
  10166. RECORD_MULTI_VALUE_STATS();
  10167. } /* for times */
  10168. count += times;
  10169. } while (bench_stats_check(start)
  10170. #ifdef MULTI_VALUE_STATISTICS
  10171. || runs < minimum_runs
  10172. #endif
  10173. );
  10174. exit:
  10175. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10176. wc_ecc_get_name(ECC_SM2P256V1));
  10177. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10178. start, ret);
  10179. #ifdef MULTI_VALUE_STATISTICS
  10180. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10181. #endif
  10182. /* cleanup */
  10183. if (WC_ARRAY_OK(genKey)) {
  10184. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10185. wc_ecc_free(genKey[i]);
  10186. }
  10187. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10188. }
  10189. }
  10190. void bench_sm2(int useDeviceID)
  10191. {
  10192. int ret = 0, i, times, count, pending = 0;
  10193. int deviceID;
  10194. int keySize;
  10195. char name[BENCH_ECC_NAME_SZ];
  10196. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10197. sizeof(ecc_key), HEAP_HINT);
  10198. #ifdef HAVE_ECC_DHE
  10199. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10200. sizeof(ecc_key), HEAP_HINT);
  10201. #endif
  10202. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10203. #ifdef HAVE_ECC_VERIFY
  10204. int verify[BENCH_MAX_PENDING];
  10205. #endif
  10206. #endif
  10207. word32 x[BENCH_MAX_PENDING];
  10208. double start = 0;
  10209. const char**desc = bench_desc_words[lng_index];
  10210. DECLARE_MULTI_VALUE_STATS_VARS()
  10211. #ifdef HAVE_ECC_DHE
  10212. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10213. #endif
  10214. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10215. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10216. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10217. #endif
  10218. #ifdef HAVE_ECC_DHE
  10219. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10220. #endif
  10221. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10222. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10223. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10224. #endif
  10225. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10226. bench_sm2_MakeKey(useDeviceID);
  10227. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10228. sizeof(ecc_key), HEAP_HINT);
  10229. #ifdef HAVE_ECC_DHE
  10230. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10231. sizeof(ecc_key), HEAP_HINT);
  10232. #endif
  10233. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10234. /* init keys */
  10235. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10236. /* setup an context for each key */
  10237. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10238. goto exit;
  10239. }
  10240. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10241. #ifdef WOLFSSL_ASYNC_CRYPT
  10242. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10243. #endif
  10244. if (ret < 0) {
  10245. goto exit;
  10246. }
  10247. #ifdef HAVE_ECC_DHE
  10248. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10249. goto exit;
  10250. }
  10251. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10252. WC_ECC_FLAG_NONE)) > 0) {
  10253. goto exit;
  10254. }
  10255. #endif
  10256. }
  10257. #ifdef HAVE_ECC_DHE
  10258. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10259. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10260. !defined(HAVE_SELFTEST)
  10261. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10262. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10263. }
  10264. #endif
  10265. /* ECC Shared Secret */
  10266. bench_stats_start(&count, &start);
  10267. PRIVATE_KEY_UNLOCK();
  10268. do {
  10269. for (times = 0; times < agreeTimes || pending > 0; ) {
  10270. bench_async_poll(&pending);
  10271. /* while free pending slots in queue, submit ops */
  10272. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10273. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10274. &times, agreeTimes, &pending)) {
  10275. x[i] = (word32)keySize;
  10276. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10277. shared[i], &x[i]);
  10278. if (!bench_async_handle(&ret,
  10279. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10280. &pending)) {
  10281. goto exit_ecdhe;
  10282. }
  10283. }
  10284. } /* for i */
  10285. RECORD_MULTI_VALUE_STATS();
  10286. } /* for times */
  10287. count += times;
  10288. } while (bench_stats_check(start)
  10289. #ifdef MULTI_VALUE_STATISTICS
  10290. || runs < minimum_runs
  10291. #endif
  10292. );
  10293. PRIVATE_KEY_UNLOCK();
  10294. exit_ecdhe:
  10295. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10296. wc_ecc_get_name(ECC_SM2P256V1));
  10297. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10298. start, ret);
  10299. #ifdef MULTI_VALUE_STATISTICS
  10300. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10301. #endif
  10302. if (ret < 0) {
  10303. goto exit;
  10304. }
  10305. #endif /* HAVE_ECC_DHE */
  10306. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10307. /* Init digest to sign */
  10308. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10309. for (count = 0; count < keySize; count++) {
  10310. digest[i][count] = (byte)count;
  10311. }
  10312. }
  10313. RESET_MULTI_VALUE_STATS_VARS();
  10314. /* ECC Sign */
  10315. bench_stats_start(&count, &start);
  10316. do {
  10317. for (times = 0; times < agreeTimes || pending > 0; ) {
  10318. bench_async_poll(&pending);
  10319. /* while free pending slots in queue, submit ops */
  10320. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10321. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10322. &times, agreeTimes, &pending)) {
  10323. if (genKey[i]->state == 0)
  10324. x[i] = ECC_MAX_SIG_SIZE;
  10325. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10326. sig[i], &x[i], &gRng, genKey[i]);
  10327. if (!bench_async_handle(&ret,
  10328. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10329. &pending)) {
  10330. goto exit_ecdsa_sign;
  10331. }
  10332. }
  10333. } /* for i */
  10334. RECORD_MULTI_VALUE_STATS();
  10335. } /* for times */
  10336. count += times;
  10337. } while (bench_stats_check(start)
  10338. #ifdef MULTI_VALUE_STATISTICS
  10339. || runs < minimum_runs
  10340. #endif
  10341. );
  10342. exit_ecdsa_sign:
  10343. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10344. wc_ecc_get_name(ECC_SM2P256V1));
  10345. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10346. start, ret);
  10347. #ifdef MULTI_VALUE_STATISTICS
  10348. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10349. #endif
  10350. if (ret < 0) {
  10351. goto exit;
  10352. }
  10353. #ifdef HAVE_ECC_VERIFY
  10354. /* ECC Verify */
  10355. bench_stats_start(&count, &start);
  10356. do {
  10357. for (times = 0; times < agreeTimes || pending > 0; ) {
  10358. bench_async_poll(&pending);
  10359. /* while free pending slots in queue, submit ops */
  10360. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10361. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10362. &times, agreeTimes, &pending)) {
  10363. if (genKey[i]->state == 0)
  10364. verify[i] = 0;
  10365. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10366. (word32)keySize, &verify[i], genKey[i]);
  10367. if (!bench_async_handle(&ret,
  10368. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10369. &pending)) {
  10370. goto exit_ecdsa_verify;
  10371. }
  10372. }
  10373. } /* for i */
  10374. RECORD_MULTI_VALUE_STATS();
  10375. } /* for times */
  10376. count += times;
  10377. } while (bench_stats_check(start)
  10378. #ifdef MULTI_VALUE_STATISTICS
  10379. || runs < minimum_runs
  10380. #endif
  10381. );
  10382. exit_ecdsa_verify:
  10383. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10384. wc_ecc_get_name(ECC_SM2P256V1));
  10385. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10386. start, ret);
  10387. #ifdef MULTI_VALUE_STATISTICS
  10388. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10389. #endif
  10390. #endif /* HAVE_ECC_VERIFY */
  10391. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10392. exit:
  10393. /* cleanup */
  10394. if (WC_ARRAY_OK(genKey)) {
  10395. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10396. wc_ecc_free(genKey[i]);
  10397. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10398. }
  10399. #ifdef HAVE_ECC_DHE
  10400. if (WC_ARRAY_OK(genKey2)) {
  10401. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10402. wc_ecc_free(genKey2[i]);
  10403. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10404. }
  10405. #endif
  10406. #ifdef HAVE_ECC_DHE
  10407. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10408. #endif
  10409. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10410. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10411. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10412. #endif
  10413. (void)useDeviceID;
  10414. (void)pending;
  10415. (void)x;
  10416. (void)count;
  10417. (void)times;
  10418. (void)desc;
  10419. (void)start;
  10420. (void)name;
  10421. }
  10422. #endif /* WOLFSSL_SM2 */
  10423. #endif /* HAVE_ECC */
  10424. #ifdef HAVE_CURVE25519
  10425. void bench_curve25519KeyGen(int useDeviceID)
  10426. {
  10427. curve25519_key genKey;
  10428. double start;
  10429. int ret = 0, i, count;
  10430. const char**desc = bench_desc_words[lng_index];
  10431. DECLARE_MULTI_VALUE_STATS_VARS()
  10432. /* Key Gen */
  10433. bench_stats_start(&count, &start);
  10434. do {
  10435. for (i = 0; i < genTimes; i++) {
  10436. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10437. useDeviceID ? devId : INVALID_DEVID);
  10438. if (ret != 0) {
  10439. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10440. break;
  10441. }
  10442. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10443. wc_curve25519_free(&genKey);
  10444. if (ret != 0) {
  10445. printf("wc_curve25519_make_key failed: %d\n", ret);
  10446. break;
  10447. }
  10448. RECORD_MULTI_VALUE_STATS();
  10449. }
  10450. count += i;
  10451. } while (bench_stats_check(start)
  10452. #ifdef MULTI_VALUE_STATISTICS
  10453. || runs < minimum_runs
  10454. #endif
  10455. );
  10456. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10457. ret);
  10458. #ifdef MULTI_VALUE_STATISTICS
  10459. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10460. #endif
  10461. }
  10462. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10463. void bench_curve25519KeyAgree(int useDeviceID)
  10464. {
  10465. curve25519_key genKey, genKey2;
  10466. double start;
  10467. int ret, i, count;
  10468. byte shared[32];
  10469. const char**desc = bench_desc_words[lng_index];
  10470. word32 x = 0;
  10471. DECLARE_MULTI_VALUE_STATS_VARS()
  10472. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10473. useDeviceID ? devId : INVALID_DEVID);
  10474. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10475. useDeviceID ? devId : INVALID_DEVID);
  10476. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10477. if (ret != 0) {
  10478. printf("curve25519_make_key failed\n");
  10479. return;
  10480. }
  10481. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10482. if (ret != 0) {
  10483. printf("curve25519_make_key failed: %d\n", ret);
  10484. wc_curve25519_free(&genKey);
  10485. return;
  10486. }
  10487. /* Shared secret */
  10488. bench_stats_start(&count, &start);
  10489. do {
  10490. for (i = 0; i < agreeTimes; i++) {
  10491. x = sizeof(shared);
  10492. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10493. if (ret != 0) {
  10494. printf("curve25519_shared_secret failed: %d\n", ret);
  10495. goto exit;
  10496. }
  10497. RECORD_MULTI_VALUE_STATS();
  10498. }
  10499. count += i;
  10500. } while (bench_stats_check(start)
  10501. #ifdef MULTI_VALUE_STATISTICS
  10502. || runs < minimum_runs
  10503. #endif
  10504. );
  10505. exit:
  10506. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10507. ret);
  10508. #ifdef MULTI_VALUE_STATISTICS
  10509. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10510. #endif
  10511. wc_curve25519_free(&genKey2);
  10512. wc_curve25519_free(&genKey);
  10513. }
  10514. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10515. #endif /* HAVE_CURVE25519 */
  10516. #ifdef HAVE_ED25519
  10517. void bench_ed25519KeyGen(void)
  10518. {
  10519. #ifdef HAVE_ED25519_MAKE_KEY
  10520. ed25519_key genKey;
  10521. double start;
  10522. int i, count;
  10523. const char**desc = bench_desc_words[lng_index];
  10524. DECLARE_MULTI_VALUE_STATS_VARS()
  10525. /* Key Gen */
  10526. bench_stats_start(&count, &start);
  10527. do {
  10528. for (i = 0; i < genTimes; i++) {
  10529. wc_ed25519_init(&genKey);
  10530. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10531. wc_ed25519_free(&genKey);
  10532. RECORD_MULTI_VALUE_STATS();
  10533. }
  10534. count += i;
  10535. } while (bench_stats_check(start)
  10536. #ifdef MULTI_VALUE_STATISTICS
  10537. || runs < minimum_runs
  10538. #endif
  10539. );
  10540. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10541. #ifdef MULTI_VALUE_STATISTICS
  10542. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10543. #endif
  10544. #endif /* HAVE_ED25519_MAKE_KEY */
  10545. }
  10546. void bench_ed25519KeySign(void)
  10547. {
  10548. #ifdef HAVE_ED25519_MAKE_KEY
  10549. int ret;
  10550. #endif
  10551. ed25519_key genKey;
  10552. #ifdef HAVE_ED25519_SIGN
  10553. double start;
  10554. int i, count;
  10555. byte sig[ED25519_SIG_SIZE];
  10556. byte msg[512];
  10557. word32 x = 0;
  10558. const char**desc = bench_desc_words[lng_index];
  10559. DECLARE_MULTI_VALUE_STATS_VARS()
  10560. #endif
  10561. wc_ed25519_init(&genKey);
  10562. #ifdef HAVE_ED25519_MAKE_KEY
  10563. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10564. if (ret != 0) {
  10565. printf("ed25519_make_key failed\n");
  10566. return;
  10567. }
  10568. #endif
  10569. #ifdef HAVE_ED25519_SIGN
  10570. /* make dummy msg */
  10571. for (i = 0; i < (int)sizeof(msg); i++)
  10572. msg[i] = (byte)i;
  10573. bench_stats_start(&count, &start);
  10574. do {
  10575. for (i = 0; i < agreeTimes; i++) {
  10576. x = sizeof(sig);
  10577. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10578. if (ret != 0) {
  10579. printf("ed25519_sign_msg failed\n");
  10580. goto exit_ed_sign;
  10581. }
  10582. RECORD_MULTI_VALUE_STATS();
  10583. }
  10584. count += i;
  10585. } while (bench_stats_check(start)
  10586. #ifdef MULTI_VALUE_STATISTICS
  10587. || runs < minimum_runs
  10588. #endif
  10589. );
  10590. exit_ed_sign:
  10591. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10592. #ifdef MULTI_VALUE_STATISTICS
  10593. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10594. #endif
  10595. RESET_MULTI_VALUE_STATS_VARS();
  10596. #ifdef HAVE_ED25519_VERIFY
  10597. bench_stats_start(&count, &start);
  10598. do {
  10599. for (i = 0; i < agreeTimes; i++) {
  10600. int verify = 0;
  10601. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10602. &genKey);
  10603. if (ret != 0 || verify != 1) {
  10604. printf("ed25519_verify_msg failed\n");
  10605. goto exit_ed_verify;
  10606. }
  10607. RECORD_MULTI_VALUE_STATS();
  10608. }
  10609. count += i;
  10610. } while (bench_stats_check(start)
  10611. #ifdef MULTI_VALUE_STATISTICS
  10612. || runs < minimum_runs
  10613. #endif
  10614. );
  10615. exit_ed_verify:
  10616. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10617. #ifdef MULTI_VALUE_STATISTICS
  10618. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10619. #endif
  10620. #endif /* HAVE_ED25519_VERIFY */
  10621. #endif /* HAVE_ED25519_SIGN */
  10622. wc_ed25519_free(&genKey);
  10623. }
  10624. #endif /* HAVE_ED25519 */
  10625. #ifdef HAVE_CURVE448
  10626. void bench_curve448KeyGen(void)
  10627. {
  10628. curve448_key genKey;
  10629. double start;
  10630. int ret = 0, i, count;
  10631. const char**desc = bench_desc_words[lng_index];
  10632. DECLARE_MULTI_VALUE_STATS_VARS()
  10633. /* Key Gen */
  10634. bench_stats_start(&count, &start);
  10635. do {
  10636. for (i = 0; i < genTimes; i++) {
  10637. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10638. wc_curve448_free(&genKey);
  10639. if (ret != 0) {
  10640. printf("wc_curve448_make_key failed: %d\n", ret);
  10641. break;
  10642. }
  10643. RECORD_MULTI_VALUE_STATS();
  10644. }
  10645. count += i;
  10646. } while (bench_stats_check(start)
  10647. #ifdef MULTI_VALUE_STATISTICS
  10648. || runs < minimum_runs
  10649. #endif
  10650. );
  10651. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10652. #ifdef MULTI_VALUE_STATISTICS
  10653. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10654. #endif
  10655. }
  10656. #ifdef HAVE_CURVE448_SHARED_SECRET
  10657. void bench_curve448KeyAgree(void)
  10658. {
  10659. curve448_key genKey, genKey2;
  10660. double start;
  10661. int ret, i, count;
  10662. byte shared[56];
  10663. const char**desc = bench_desc_words[lng_index];
  10664. word32 x = 0;
  10665. DECLARE_MULTI_VALUE_STATS_VARS()
  10666. wc_curve448_init(&genKey);
  10667. wc_curve448_init(&genKey2);
  10668. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10669. if (ret != 0) {
  10670. printf("curve448_make_key failed\n");
  10671. return;
  10672. }
  10673. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10674. if (ret != 0) {
  10675. printf("curve448_make_key failed: %d\n", ret);
  10676. wc_curve448_free(&genKey);
  10677. return;
  10678. }
  10679. /* Shared secret */
  10680. bench_stats_start(&count, &start);
  10681. do {
  10682. for (i = 0; i < agreeTimes; i++) {
  10683. x = sizeof(shared);
  10684. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10685. if (ret != 0) {
  10686. printf("curve448_shared_secret failed: %d\n", ret);
  10687. goto exit;
  10688. }
  10689. RECORD_MULTI_VALUE_STATS();
  10690. }
  10691. count += i;
  10692. } while (bench_stats_check(start)
  10693. #ifdef MULTI_VALUE_STATISTICS
  10694. || runs < minimum_runs
  10695. #endif
  10696. );
  10697. exit:
  10698. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10699. #ifdef MULTI_VALUE_STATISTICS
  10700. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10701. #endif
  10702. wc_curve448_free(&genKey2);
  10703. wc_curve448_free(&genKey);
  10704. }
  10705. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10706. #endif /* HAVE_CURVE448 */
  10707. #ifdef HAVE_ED448
  10708. void bench_ed448KeyGen(void)
  10709. {
  10710. ed448_key genKey;
  10711. double start;
  10712. int i, count;
  10713. const char**desc = bench_desc_words[lng_index];
  10714. DECLARE_MULTI_VALUE_STATS_VARS()
  10715. /* Key Gen */
  10716. bench_stats_start(&count, &start);
  10717. do {
  10718. for (i = 0; i < genTimes; i++) {
  10719. wc_ed448_init(&genKey);
  10720. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10721. wc_ed448_free(&genKey);
  10722. RECORD_MULTI_VALUE_STATS();
  10723. }
  10724. count += i;
  10725. } while (bench_stats_check(start)
  10726. #ifdef MULTI_VALUE_STATISTICS
  10727. || runs < minimum_runs
  10728. #endif
  10729. );
  10730. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10731. #ifdef MULTI_VALUE_STATISTICS
  10732. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10733. #endif
  10734. }
  10735. void bench_ed448KeySign(void)
  10736. {
  10737. int ret;
  10738. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10739. #ifdef HAVE_ED448_SIGN
  10740. double start;
  10741. int i, count;
  10742. byte sig[ED448_SIG_SIZE];
  10743. byte msg[512];
  10744. word32 x = 0;
  10745. const char**desc = bench_desc_words[lng_index];
  10746. DECLARE_MULTI_VALUE_STATS_VARS()
  10747. #endif
  10748. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10749. wc_ed448_init(genKey);
  10750. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10751. if (ret != 0) {
  10752. printf("ed448_make_key failed\n");
  10753. goto exit;
  10754. }
  10755. #ifdef HAVE_ED448_SIGN
  10756. /* make dummy msg */
  10757. for (i = 0; i < (int)sizeof(msg); i++)
  10758. msg[i] = (byte)i;
  10759. bench_stats_start(&count, &start);
  10760. do {
  10761. for (i = 0; i < agreeTimes; i++) {
  10762. x = sizeof(sig);
  10763. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10764. NULL, 0);
  10765. if (ret != 0) {
  10766. printf("ed448_sign_msg failed\n");
  10767. goto exit;
  10768. }
  10769. RECORD_MULTI_VALUE_STATS();
  10770. }
  10771. count += i;
  10772. } while (bench_stats_check(start)
  10773. #ifdef MULTI_VALUE_STATISTICS
  10774. || runs < minimum_runs
  10775. #endif
  10776. );
  10777. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10778. #ifdef MULTI_VALUE_STATISTICS
  10779. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10780. #endif
  10781. RESET_MULTI_VALUE_STATS_VARS();
  10782. #ifdef HAVE_ED448_VERIFY
  10783. bench_stats_start(&count, &start);
  10784. do {
  10785. for (i = 0; i < agreeTimes; i++) {
  10786. int verify = 0;
  10787. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10788. genKey, NULL, 0);
  10789. if (ret != 0 || verify != 1) {
  10790. printf("ed448_verify_msg failed\n");
  10791. goto exit;
  10792. }
  10793. RECORD_MULTI_VALUE_STATS();
  10794. }
  10795. count += i;
  10796. } while (bench_stats_check(start)
  10797. #ifdef MULTI_VALUE_STATISTICS
  10798. || runs < minimum_runs
  10799. #endif
  10800. );
  10801. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10802. #ifdef MULTI_VALUE_STATISTICS
  10803. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10804. #endif
  10805. #endif /* HAVE_ED448_VERIFY */
  10806. #endif /* HAVE_ED448_SIGN */
  10807. exit:
  10808. wc_ed448_free(genKey);
  10809. WC_FREE_VAR(genKey, HEAP_HINT);
  10810. }
  10811. #endif /* HAVE_ED448 */
  10812. #ifdef WOLFCRYPT_HAVE_ECCSI
  10813. #ifdef WOLFCRYPT_ECCSI_KMS
  10814. void bench_eccsiKeyGen(void)
  10815. {
  10816. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10817. double start;
  10818. int i, count;
  10819. const char**desc = bench_desc_words[lng_index];
  10820. int ret;
  10821. DECLARE_MULTI_VALUE_STATS_VARS()
  10822. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10823. /* Key Gen */
  10824. bench_stats_start(&count, &start);
  10825. do {
  10826. for (i = 0; i < genTimes; i++) {
  10827. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10828. ret = wc_MakeEccsiKey(genKey, &gRng);
  10829. wc_FreeEccsiKey(genKey);
  10830. if (ret != 0) {
  10831. printf("wc_MakeEccsiKey failed: %d\n", ret);
  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("ECCSI", 256, desc[2], 0, count, start, 0);
  10843. #ifdef MULTI_VALUE_STATISTICS
  10844. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10845. #endif
  10846. exit:
  10847. WC_FREE_VAR(genKey, HEAP_HINT);
  10848. }
  10849. void bench_eccsiPairGen(void)
  10850. {
  10851. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10852. double start;
  10853. int i, count;
  10854. const char**desc = bench_desc_words[lng_index];
  10855. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10856. ecc_point* pvt;
  10857. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10858. int ret;
  10859. DECLARE_MULTI_VALUE_STATS_VARS()
  10860. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10861. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10862. (void)mp_init(ssk);
  10863. pvt = wc_ecc_new_point();
  10864. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10865. (void)wc_MakeEccsiKey(genKey, &gRng);
  10866. /* RSK Gen */
  10867. bench_stats_start(&count, &start);
  10868. do {
  10869. for (i = 0; i < genTimes; i++) {
  10870. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10871. sizeof(id), ssk, pvt);
  10872. if (ret != 0) {
  10873. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10874. goto exit;
  10875. }
  10876. RECORD_MULTI_VALUE_STATS();
  10877. }
  10878. count += i;
  10879. } while (bench_stats_check(start)
  10880. #ifdef MULTI_VALUE_STATISTICS
  10881. || runs < minimum_runs
  10882. #endif
  10883. );
  10884. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10885. #ifdef MULTI_VALUE_STATISTICS
  10886. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10887. #endif
  10888. wc_FreeEccsiKey(genKey);
  10889. wc_ecc_del_point(pvt);
  10890. mp_free(ssk);
  10891. exit:
  10892. WC_FREE_VAR(genKey, HEAP_HINT);
  10893. WC_FREE_VAR(ssk, HEAP_HINT);
  10894. }
  10895. #endif
  10896. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10897. void bench_eccsiValidate(void)
  10898. {
  10899. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10900. double start;
  10901. int i, count;
  10902. const char**desc = bench_desc_words[lng_index];
  10903. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10904. ecc_point* pvt;
  10905. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10906. int valid;
  10907. int ret;
  10908. DECLARE_MULTI_VALUE_STATS_VARS()
  10909. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10910. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10911. (void)mp_init(ssk);
  10912. pvt = wc_ecc_new_point();
  10913. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10914. (void)wc_MakeEccsiKey(genKey, &gRng);
  10915. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10916. ssk, pvt);
  10917. /* Validation of RSK */
  10918. bench_stats_start(&count, &start);
  10919. do {
  10920. for (i = 0; i < genTimes; i++) {
  10921. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10922. sizeof(id), ssk, pvt, &valid);
  10923. if (ret != 0 || !valid) {
  10924. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10925. valid);
  10926. goto exit;
  10927. }
  10928. RECORD_MULTI_VALUE_STATS();
  10929. }
  10930. count += i;
  10931. } while (bench_stats_check(start)
  10932. #ifdef MULTI_VALUE_STATISTICS
  10933. || runs < minimum_runs
  10934. #endif
  10935. );
  10936. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10937. #ifdef MULTI_VALUE_STATISTICS
  10938. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10939. #endif
  10940. wc_FreeEccsiKey(genKey);
  10941. wc_ecc_del_point(pvt);
  10942. mp_free(ssk);
  10943. exit:
  10944. WC_FREE_VAR(genKey, HEAP_HINT);
  10945. WC_FREE_VAR(ssk, HEAP_HINT);
  10946. }
  10947. void bench_eccsi(void)
  10948. {
  10949. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10950. double start;
  10951. int i, count;
  10952. const char**desc = bench_desc_words[lng_index];
  10953. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10954. ecc_point* pvt;
  10955. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10956. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10957. byte hash[WC_SHA256_DIGEST_SIZE];
  10958. byte hashSz = (byte)sizeof(hash);
  10959. byte sig[257];
  10960. word32 sigSz = sizeof(sig);
  10961. int ret;
  10962. int verified;
  10963. DECLARE_MULTI_VALUE_STATS_VARS()
  10964. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10965. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10966. (void)mp_init(ssk);
  10967. pvt = wc_ecc_new_point();
  10968. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10969. (void)wc_MakeEccsiKey(genKey, &gRng);
  10970. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10971. ssk, pvt);
  10972. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  10973. hash, &hashSz);
  10974. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  10975. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  10976. /* Encapsulate */
  10977. bench_stats_start(&count, &start);
  10978. do {
  10979. for (i = 0; i < genTimes; i++) {
  10980. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  10981. sizeof(msg), sig, &sigSz);
  10982. if (ret != 0) {
  10983. printf("wc_SignEccsiHash failed: %d\n", ret);
  10984. break;
  10985. }
  10986. RECORD_MULTI_VALUE_STATS();
  10987. }
  10988. count += i;
  10989. } while (bench_stats_check(start)
  10990. #ifdef MULTI_VALUE_STATISTICS
  10991. || runs < minimum_runs
  10992. #endif
  10993. );
  10994. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  10995. #ifdef MULTI_VALUE_STATISTICS
  10996. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10997. #endif
  10998. RESET_MULTI_VALUE_STATS_VARS();
  10999. /* Derive */
  11000. bench_stats_start(&count, &start);
  11001. do {
  11002. for (i = 0; i < genTimes; i++) {
  11003. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11004. sizeof(msg), sig, sigSz, &verified);
  11005. if (ret != 0 || !verified) {
  11006. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11007. verified);
  11008. goto exit;
  11009. }
  11010. RECORD_MULTI_VALUE_STATS();
  11011. }
  11012. count += i;
  11013. } while (bench_stats_check(start)
  11014. #ifdef MULTI_VALUE_STATISTICS
  11015. || runs < minimum_runs
  11016. #endif
  11017. );
  11018. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11019. #ifdef MULTI_VALUE_STATISTICS
  11020. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11021. #endif
  11022. wc_FreeEccsiKey(genKey);
  11023. wc_ecc_del_point(pvt);
  11024. exit:
  11025. WC_FREE_VAR(genKey, HEAP_HINT);
  11026. WC_FREE_VAR(ssk, HEAP_HINT);
  11027. }
  11028. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11029. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11030. #ifdef WOLFCRYPT_HAVE_SAKKE
  11031. #ifdef WOLFCRYPT_SAKKE_KMS
  11032. void bench_sakkeKeyGen(void)
  11033. {
  11034. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11035. double start;
  11036. int i, count;
  11037. const char**desc = bench_desc_words[lng_index];
  11038. int ret;
  11039. DECLARE_MULTI_VALUE_STATS_VARS()
  11040. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11041. /* Key Gen */
  11042. bench_stats_start(&count, &start);
  11043. do {
  11044. for (i = 0; i < genTimes; i++) {
  11045. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11046. ret = wc_MakeSakkeKey(genKey, &gRng);
  11047. if (ret != 0) {
  11048. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11049. goto exit;
  11050. }
  11051. wc_FreeSakkeKey(genKey);
  11052. RECORD_MULTI_VALUE_STATS();
  11053. }
  11054. count += i;
  11055. } while (bench_stats_check(start)
  11056. #ifdef MULTI_VALUE_STATISTICS
  11057. || runs < minimum_runs
  11058. #endif
  11059. );
  11060. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  11061. #ifdef MULTI_VALUE_STATISTICS
  11062. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11063. #endif
  11064. exit:
  11065. WC_FREE_VAR(genKey, HEAP_HINT);
  11066. }
  11067. void bench_sakkeRskGen(void)
  11068. {
  11069. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11070. double start;
  11071. int i, count;
  11072. const char**desc = bench_desc_words[lng_index];
  11073. ecc_point* rsk;
  11074. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11075. int ret;
  11076. DECLARE_MULTI_VALUE_STATS_VARS()
  11077. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11078. rsk = wc_ecc_new_point();
  11079. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11080. (void)wc_MakeSakkeKey(genKey, &gRng);
  11081. /* RSK Gen */
  11082. bench_stats_start(&count, &start);
  11083. do {
  11084. for (i = 0; i < genTimes; i++) {
  11085. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11086. if (ret != 0) {
  11087. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11088. goto exit;
  11089. }
  11090. RECORD_MULTI_VALUE_STATS();
  11091. }
  11092. count += i;
  11093. } while (bench_stats_check(start)
  11094. #ifdef MULTI_VALUE_STATISTICS
  11095. || runs < minimum_runs
  11096. #endif
  11097. );
  11098. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11099. #ifdef MULTI_VALUE_STATISTICS
  11100. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11101. #endif
  11102. wc_FreeSakkeKey(genKey);
  11103. wc_ecc_del_point(rsk);
  11104. exit:
  11105. WC_FREE_VAR(genKey, HEAP_HINT);
  11106. }
  11107. #endif
  11108. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11109. void bench_sakkeValidate(void)
  11110. {
  11111. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11112. double start;
  11113. int i, count;
  11114. const char**desc = bench_desc_words[lng_index];
  11115. ecc_point* rsk;
  11116. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11117. int valid;
  11118. int ret;
  11119. DECLARE_MULTI_VALUE_STATS_VARS()
  11120. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11121. rsk = wc_ecc_new_point();
  11122. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11123. (void)wc_MakeSakkeKey(genKey, &gRng);
  11124. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11125. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11126. /* Validation of RSK */
  11127. bench_stats_start(&count, &start);
  11128. do {
  11129. for (i = 0; i < genTimes; i++) {
  11130. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11131. if (ret != 0 || !valid) {
  11132. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11133. valid);
  11134. goto exit;
  11135. }
  11136. RECORD_MULTI_VALUE_STATS();
  11137. }
  11138. count += i;
  11139. } while (bench_stats_check(start)
  11140. #ifdef MULTI_VALUE_STATISTICS
  11141. || runs < minimum_runs
  11142. #endif
  11143. );
  11144. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11145. #ifdef MULTI_VALUE_STATISTICS
  11146. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11147. #endif
  11148. wc_FreeSakkeKey(genKey);
  11149. wc_ecc_del_point(rsk);
  11150. exit:
  11151. WC_FREE_VAR(genKey, HEAP_HINT);
  11152. }
  11153. void bench_sakke(void)
  11154. {
  11155. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11156. double start;
  11157. int i, count;
  11158. const char**desc = bench_desc_words[lng_index];
  11159. ecc_point* rsk;
  11160. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11161. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11162. byte ssv[sizeof(ssv_init)];
  11163. byte derSSV[sizeof(ssv)];
  11164. byte auth[257];
  11165. word16 authSz = sizeof(auth);
  11166. int ret = 0;
  11167. byte* table = NULL;
  11168. word32 len = 0;
  11169. byte* iTable = NULL;
  11170. word32 iTableLen = 0;
  11171. DECLARE_MULTI_VALUE_STATS_VARS()
  11172. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11173. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11174. rsk = wc_ecc_new_point();
  11175. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11176. (void)wc_MakeSakkeKey(genKey, &gRng);
  11177. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11178. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11179. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11180. /* Encapsulate */
  11181. bench_stats_start(&count, &start);
  11182. do {
  11183. for (i = 0; i < genTimes; i++) {
  11184. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11185. WC_HASH_TYPE_SHA256,
  11186. ssv, sizeof(ssv), auth, &authSz);
  11187. if (ret != 0) {
  11188. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11189. break;
  11190. }
  11191. RECORD_MULTI_VALUE_STATS();
  11192. } /* for */
  11193. count += i;
  11194. } while (bench_stats_check(start)
  11195. #ifdef MULTI_VALUE_STATISTICS
  11196. || runs < minimum_runs
  11197. #endif
  11198. );
  11199. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11200. 0, count, start, 0);
  11201. #ifdef MULTI_VALUE_STATISTICS
  11202. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11203. #endif
  11204. RESET_MULTI_VALUE_STATS_VARS();
  11205. /* Derive */
  11206. bench_stats_start(&count, &start);
  11207. do {
  11208. for (i = 0; i < genTimes; i++) {
  11209. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11210. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11211. sizeof(derSSV), auth, authSz);
  11212. if (ret != 0) {
  11213. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11214. break;
  11215. }
  11216. RECORD_MULTI_VALUE_STATS();
  11217. }
  11218. if (ret != 0) break;
  11219. count += i;
  11220. } while (bench_stats_check(start)
  11221. #ifdef MULTI_VALUE_STATISTICS
  11222. || runs < minimum_runs
  11223. #endif
  11224. );
  11225. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11226. 0, count, start, 0);
  11227. #ifdef MULTI_VALUE_STATISTICS
  11228. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11229. #endif
  11230. /* Calculate Point I and generate table. */
  11231. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11232. iTableLen = 0;
  11233. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11234. if (iTableLen != 0) {
  11235. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11236. if (iTable == NULL)
  11237. WC_ALLOC_DO_ON_FAILURE();
  11238. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11239. }
  11240. /* Encapsulate with Point I table */
  11241. bench_stats_start(&count, &start);
  11242. do {
  11243. for (i = 0; i < genTimes; i++) {
  11244. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11245. WC_HASH_TYPE_SHA256, ssv,
  11246. sizeof(ssv), auth, &authSz);
  11247. if (ret != 0) {
  11248. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11249. break;
  11250. }
  11251. RECORD_MULTI_VALUE_STATS();
  11252. }
  11253. count += i;
  11254. } while (bench_stats_check(start)
  11255. #ifdef MULTI_VALUE_STATISTICS
  11256. || runs < minimum_runs
  11257. #endif
  11258. );
  11259. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11260. count, start, 0);
  11261. #ifdef MULTI_VALUE_STATISTICS
  11262. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11263. #endif
  11264. RESET_MULTI_VALUE_STATS_VARS();
  11265. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11266. /* Derive with Point I table */
  11267. bench_stats_start(&count, &start);
  11268. do {
  11269. for (i = 0; i < genTimes; i++) {
  11270. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11271. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11272. sizeof(derSSV), auth, authSz);
  11273. if (ret != 0) {
  11274. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11275. break;
  11276. }
  11277. RECORD_MULTI_VALUE_STATS();
  11278. }
  11279. if (ret != 0) break;
  11280. count += i;
  11281. } while (bench_stats_check(start)
  11282. #ifdef MULTI_VALUE_STATISTICS
  11283. || runs < minimum_runs
  11284. #endif
  11285. );
  11286. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11287. count, start, 0);
  11288. #ifdef MULTI_VALUE_STATISTICS
  11289. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11290. #endif
  11291. RESET_MULTI_VALUE_STATS_VARS();
  11292. len = 0;
  11293. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11294. if (len > 0) {
  11295. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11296. if (table == NULL)
  11297. WC_ALLOC_DO_ON_FAILURE();
  11298. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11299. }
  11300. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11301. /* Derive with Point I table and RSK table */
  11302. bench_stats_start(&count, &start);
  11303. do {
  11304. for (i = 0; i < genTimes; i++) {
  11305. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11306. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11307. sizeof(derSSV), auth, authSz);
  11308. if (ret != 0) {
  11309. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11310. break;
  11311. }
  11312. RECORD_MULTI_VALUE_STATS();
  11313. }
  11314. if (ret != 0) break;
  11315. count += i;
  11316. } while (bench_stats_check(start)
  11317. #ifdef MULTI_VALUE_STATISTICS
  11318. || runs < minimum_runs
  11319. #endif
  11320. );
  11321. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11322. 0, count, start, 0);
  11323. #ifdef MULTI_VALUE_STATISTICS
  11324. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11325. #endif
  11326. RESET_MULTI_VALUE_STATS_VARS();
  11327. wc_ClearSakkePointITable(genKey);
  11328. /* Derive with RSK table */
  11329. bench_stats_start(&count, &start);
  11330. do {
  11331. for (i = 0; i < genTimes; i++) {
  11332. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11333. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11334. sizeof(derSSV), auth, authSz);
  11335. if (ret != 0) {
  11336. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11337. break;
  11338. }
  11339. RECORD_MULTI_VALUE_STATS();
  11340. }
  11341. if (ret != 0) break;
  11342. count += i;
  11343. } while (bench_stats_check(start)
  11344. #ifdef MULTI_VALUE_STATISTICS
  11345. || runs < minimum_runs
  11346. #endif
  11347. );
  11348. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11349. count, start, 0);
  11350. #ifdef MULTI_VALUE_STATISTICS
  11351. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11352. #endif
  11353. wc_FreeSakkeKey(genKey);
  11354. wc_ecc_del_point(rsk);
  11355. exit:
  11356. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11357. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11358. WC_FREE_VAR(genKey, HEAP_HINT);
  11359. }
  11360. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11361. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11362. #ifdef HAVE_FALCON
  11363. void bench_falconKeySign(byte level)
  11364. {
  11365. int ret = 0;
  11366. falcon_key key;
  11367. double start;
  11368. int i, count;
  11369. byte sig[FALCON_MAX_SIG_SIZE];
  11370. byte msg[512];
  11371. word32 x = 0;
  11372. const char**desc = bench_desc_words[lng_index];
  11373. DECLARE_MULTI_VALUE_STATS_VARS()
  11374. ret = wc_falcon_init(&key);
  11375. if (ret != 0) {
  11376. printf("wc_falcon_init failed %d\n", ret);
  11377. return;
  11378. }
  11379. ret = wc_falcon_set_level(&key, level);
  11380. if (ret != 0) {
  11381. printf("wc_falcon_set_level failed %d\n", ret);
  11382. }
  11383. if (ret == 0) {
  11384. if (level == 1) {
  11385. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11386. sizeof_bench_falcon_level1_key,
  11387. NULL, 0, &key);
  11388. }
  11389. else {
  11390. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11391. sizeof_bench_falcon_level5_key,
  11392. NULL, 0, &key);
  11393. }
  11394. if (ret != 0) {
  11395. printf("wc_falcon_import_private_key failed %d\n", ret);
  11396. }
  11397. }
  11398. /* make dummy msg */
  11399. for (i = 0; i < (int)sizeof(msg); i++) {
  11400. msg[i] = (byte)i;
  11401. }
  11402. bench_stats_start(&count, &start);
  11403. do {
  11404. for (i = 0; i < agreeTimes; i++) {
  11405. if (ret == 0) {
  11406. if (level == 1) {
  11407. x = FALCON_LEVEL1_SIG_SIZE;
  11408. }
  11409. else {
  11410. x = FALCON_LEVEL5_SIG_SIZE;
  11411. }
  11412. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11413. if (ret != 0) {
  11414. printf("wc_falcon_sign_msg failed\n");
  11415. }
  11416. }
  11417. RECORD_MULTI_VALUE_STATS();
  11418. }
  11419. count += i;
  11420. } while (bench_stats_check(start)
  11421. #ifdef MULTI_VALUE_STATISTICS
  11422. || runs < minimum_runs
  11423. #endif
  11424. );
  11425. if (ret == 0) {
  11426. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11427. count, start, ret);
  11428. #ifdef MULTI_VALUE_STATISTICS
  11429. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11430. #endif
  11431. }
  11432. RESET_MULTI_VALUE_STATS_VARS();
  11433. bench_stats_start(&count, &start);
  11434. do {
  11435. for (i = 0; i < agreeTimes; i++) {
  11436. if (ret == 0) {
  11437. int verify = 0;
  11438. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11439. &key);
  11440. if (ret != 0 || verify != 1) {
  11441. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11442. ret, verify);
  11443. ret = -1;
  11444. }
  11445. }
  11446. RECORD_MULTI_VALUE_STATS();
  11447. }
  11448. count += i;
  11449. } while (bench_stats_check(start)
  11450. #ifdef MULTI_VALUE_STATISTICS
  11451. || runs < minimum_runs
  11452. #endif
  11453. );
  11454. if (ret == 0) {
  11455. bench_stats_asym_finish("FALCON", level, desc[5],
  11456. 0, count, start, ret);
  11457. #ifdef MULTI_VALUE_STATISTICS
  11458. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11459. #endif
  11460. }
  11461. wc_falcon_free(&key);
  11462. }
  11463. #endif /* HAVE_FALCON */
  11464. #ifdef HAVE_DILITHIUM
  11465. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11466. #ifndef WOLFSSL_NO_ML_DSA_44
  11467. static const unsigned char bench_dilithium_level2_sig[] = {
  11468. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11469. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11470. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11471. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11472. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11473. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11474. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11475. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11476. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11477. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11478. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11479. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11480. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11481. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11482. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11483. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11484. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11485. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11486. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11487. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11488. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11489. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11490. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11491. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11492. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11493. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11494. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11495. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11496. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11497. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11498. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11499. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11500. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11501. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11502. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11503. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11504. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11505. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11506. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11507. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11508. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11509. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11510. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11511. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11512. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11513. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11514. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11515. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11516. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11517. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11518. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11519. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11520. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11521. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11522. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11523. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11524. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11525. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11526. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11527. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11528. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11529. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11530. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11531. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11532. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11533. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11534. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11535. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11536. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11537. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11538. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11539. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11540. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11541. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11542. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11543. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11544. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11545. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11546. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11547. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11548. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11549. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11550. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11551. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11552. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11553. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11554. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11555. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11556. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11557. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11558. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11559. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11560. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11561. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11562. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11563. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11564. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11565. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11566. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11567. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11568. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11569. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11570. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11571. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11572. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11573. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11574. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11575. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11576. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11577. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11578. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11579. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11580. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11581. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11582. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11583. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11584. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11585. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11586. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11587. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11588. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11589. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11590. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11591. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11592. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11593. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11594. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11595. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11596. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11597. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11598. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11599. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11600. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11601. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11602. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11603. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11604. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11605. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11606. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11607. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11608. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11609. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11610. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11611. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11612. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11613. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11614. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11615. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11616. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11617. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11618. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11619. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11620. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11621. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11622. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11623. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11624. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11625. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11626. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11627. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11628. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11629. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11630. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11631. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11632. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11633. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11634. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11635. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11636. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11637. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11638. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11639. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11640. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11641. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11642. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11643. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11644. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11645. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11646. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11647. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11648. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11649. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11650. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11651. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11652. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11653. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11654. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11655. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11656. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11657. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11658. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11659. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11660. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11661. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11662. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11663. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11664. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11665. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11666. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11667. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11668. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11669. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11670. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11671. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11672. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11673. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11674. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11675. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11676. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11677. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11678. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11679. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11680. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11681. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11682. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11683. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11684. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11685. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11686. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11687. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11688. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11689. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11690. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11691. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11692. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11693. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11694. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11695. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11696. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11697. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11698. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11699. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11700. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11701. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11702. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11703. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11704. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11705. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11706. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11707. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11708. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11709. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11710. };
  11711. static const int sizeof_bench_dilithium_level2_sig =
  11712. sizeof(bench_dilithium_level2_sig);
  11713. #endif
  11714. #ifndef WOLFSSL_NO_ML_DSA_65
  11715. static const unsigned char bench_dilithium_level3_sig[] = {
  11716. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11717. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11718. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11719. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11720. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11721. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11722. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11723. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11724. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11725. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11726. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11727. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11728. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11729. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11730. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11731. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11732. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11733. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11734. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11735. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11736. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11737. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11738. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11739. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11740. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11741. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11742. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11743. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11744. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11745. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11746. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11747. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11748. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11749. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11750. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11751. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11752. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11753. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11754. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11755. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11756. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11757. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11758. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11759. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11760. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11761. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11762. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11763. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11764. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11765. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11766. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11767. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11768. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11769. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11770. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11771. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11772. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11773. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11774. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11775. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11776. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11777. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11778. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11779. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11780. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11781. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11782. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11783. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11784. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11785. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11786. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11787. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11788. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11789. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11790. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11791. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11792. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11793. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11794. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11795. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11796. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11797. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11798. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11799. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11800. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11801. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11802. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11803. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11804. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11805. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11806. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11807. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11808. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11809. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11810. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11811. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11812. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11813. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11814. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11815. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11816. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11817. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11818. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11819. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11820. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11821. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11822. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11823. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11824. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11825. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11826. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11827. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11828. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11829. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11830. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11831. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11832. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11833. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11834. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11835. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11836. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11837. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11838. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11839. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11840. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11841. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11842. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11843. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11844. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11845. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11846. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11847. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11848. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11849. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11850. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11851. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11852. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11853. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11854. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11855. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11856. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11857. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11858. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11859. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11860. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11861. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11862. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11863. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11864. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11865. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11866. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11867. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11868. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11869. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11870. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11871. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11872. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11873. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11874. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11875. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11876. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11877. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11878. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11879. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11880. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11881. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11882. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11883. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11884. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11885. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11886. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11887. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11888. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11889. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11890. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11891. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11892. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11893. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11894. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11895. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11896. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11897. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11898. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11899. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11900. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11901. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11902. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11903. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11904. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11905. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11906. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11907. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11908. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11909. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11910. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11911. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11912. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11913. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11914. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11915. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11916. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11917. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11918. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11919. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11920. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11921. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11922. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11923. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11924. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11925. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11926. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11927. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11928. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11929. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11930. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11931. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11932. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11933. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11934. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11935. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11936. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11937. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11938. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11939. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11940. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11941. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11942. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11943. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11944. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11945. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11946. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11947. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11948. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11949. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11950. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11951. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11952. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11953. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11954. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11955. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11956. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11957. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  11958. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  11959. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  11960. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  11961. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  11962. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  11963. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  11964. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  11965. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  11966. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  11967. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  11968. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  11969. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  11970. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  11971. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  11972. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  11973. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  11974. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  11975. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  11976. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  11977. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  11978. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  11979. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  11980. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  11981. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  11982. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  11983. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  11984. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  11985. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  11986. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  11987. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  11988. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  11989. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  11990. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  11991. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  11992. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  11993. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  11994. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  11995. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  11996. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  11997. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  11998. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  11999. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12000. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12001. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12002. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12003. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12004. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12005. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12006. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12007. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12008. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12009. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12010. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12011. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12012. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12013. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12014. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12015. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12016. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12017. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12018. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12019. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12020. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12021. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12022. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12023. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12024. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12025. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12026. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12027. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12028. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12029. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12030. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12031. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12032. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12033. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12034. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12035. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12036. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12037. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12038. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12039. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12040. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12041. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12042. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12043. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12044. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12045. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12046. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12047. };
  12048. static const int sizeof_bench_dilithium_level3_sig =
  12049. sizeof(bench_dilithium_level3_sig);
  12050. #endif
  12051. #ifndef WOLFSSL_NO_ML_DSA_87
  12052. static const unsigned char bench_dilithium_level5_sig[] = {
  12053. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12054. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12055. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12056. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12057. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12058. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12059. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12060. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12061. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12062. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12063. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12064. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12065. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12066. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12067. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12068. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12069. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12070. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12071. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12072. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12073. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12074. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12075. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12076. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12077. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12078. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12079. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12080. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12081. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12082. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12083. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12084. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12085. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12086. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12087. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12088. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12089. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12090. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12091. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12092. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12093. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12094. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12095. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12096. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12097. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12098. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12099. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12100. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12101. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12102. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12103. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12104. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12105. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12106. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12107. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12108. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12109. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12110. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12111. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12112. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12113. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12114. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12115. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12116. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12117. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12118. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12119. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12120. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12121. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12122. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12123. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12124. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12125. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12126. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12127. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12128. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12129. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12130. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12131. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12132. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12133. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12134. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12135. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12136. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12137. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12138. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12139. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12140. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12141. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12142. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12143. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12144. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12145. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12146. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12147. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12148. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12149. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12150. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12151. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12152. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12153. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12154. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12155. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12156. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12157. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12158. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12159. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12160. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12161. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12162. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12163. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12164. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12165. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12166. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12167. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12168. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12169. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12170. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12171. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12172. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12173. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12174. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12175. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12176. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12177. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12178. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12179. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12180. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12181. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12182. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12183. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12184. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12185. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12186. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12187. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12188. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12189. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12190. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12191. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12192. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12193. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12194. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12195. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12196. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12197. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12198. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12199. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12200. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12201. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12202. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12203. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12204. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12205. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12206. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12207. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12208. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12209. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12210. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12211. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12212. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12213. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12214. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12215. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12216. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12217. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12218. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12219. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12220. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12221. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12222. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12223. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12224. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12225. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12226. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12227. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12228. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12229. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12230. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12231. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12232. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12233. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12234. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12235. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12236. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12237. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12238. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12239. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12240. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12241. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12242. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12243. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12244. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12245. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12246. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12247. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12248. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12249. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12250. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12251. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12252. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12253. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12254. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12255. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12256. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12257. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12258. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12259. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12260. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12261. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12262. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12263. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12264. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12265. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12266. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12267. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12268. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12269. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12270. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12271. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12272. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12273. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12274. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12275. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12276. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12277. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12278. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12279. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12280. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12281. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12282. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12283. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12284. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12285. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12286. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12287. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12288. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12289. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12290. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12291. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12292. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12293. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12294. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12295. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12296. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12297. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12298. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12299. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12300. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12301. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12302. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12303. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12304. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12305. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12306. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12307. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12308. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12309. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12310. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12311. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12312. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12313. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12314. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12315. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12316. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12317. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12318. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12319. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12320. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12321. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12322. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12323. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12324. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12325. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12326. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12327. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12328. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12329. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12330. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12331. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12332. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12333. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12334. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12335. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12336. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12337. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12338. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12339. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12340. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12341. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12342. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12343. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12344. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12345. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12346. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12347. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12348. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12349. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12350. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12351. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12352. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12353. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12354. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12355. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12356. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12357. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12358. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12359. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12360. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12361. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12362. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12363. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12364. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12365. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12366. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12367. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12368. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12369. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12370. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12371. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12372. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12373. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12374. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12375. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12376. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12377. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12378. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12379. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12380. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12381. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12382. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12383. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12384. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12385. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12386. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12387. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12388. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12389. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12390. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12391. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12392. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12393. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12394. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12395. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12396. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12397. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12398. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12399. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12400. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12401. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12402. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12403. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12404. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12405. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12406. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12407. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12408. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12409. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12410. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12411. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12412. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12413. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12414. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12415. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12416. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12417. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12418. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12419. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12420. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12421. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12422. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12423. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12424. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12425. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12426. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12427. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12428. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12429. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12430. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12431. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12432. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12433. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12434. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12435. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12436. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12437. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12438. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12439. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12440. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12441. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12442. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12443. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12444. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12445. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12446. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12447. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12448. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12449. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12450. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12451. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12452. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12453. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12454. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12455. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12456. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12457. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12458. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12459. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12460. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12461. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12462. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12463. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12464. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12465. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12466. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12467. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12468. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12469. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12470. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12471. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12472. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12473. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12474. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12475. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12476. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12477. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12478. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12479. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12480. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12481. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12482. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12483. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12484. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12485. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12486. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12487. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12488. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12489. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12490. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12491. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12492. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12493. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12494. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12495. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12496. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12497. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12498. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12499. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12500. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12501. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12502. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12503. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12504. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12505. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12506. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12507. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12508. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12509. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12510. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12511. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12512. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12513. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12514. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12515. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12516. };
  12517. static const int sizeof_bench_dilithium_level5_sig =
  12518. sizeof(bench_dilithium_level5_sig);
  12519. #endif
  12520. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12521. void bench_dilithiumKeySign(byte level)
  12522. {
  12523. int ret = 0;
  12524. dilithium_key key;
  12525. double start;
  12526. int i, count;
  12527. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12528. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12529. byte msg[512];
  12530. word32 x = 0;
  12531. #endif
  12532. const char**desc = bench_desc_words[lng_index];
  12533. DECLARE_MULTI_VALUE_STATS_VARS()
  12534. byte params = 0;
  12535. if (level == 2) {
  12536. params = 44;
  12537. }
  12538. else if (level == 3) {
  12539. params = 65;
  12540. }
  12541. else if (level == 5) {
  12542. params = 87;
  12543. }
  12544. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12545. /* make dummy msg */
  12546. for (i = 0; i < (int)sizeof(msg); i++) {
  12547. msg[i] = (byte)i;
  12548. }
  12549. #endif
  12550. ret = wc_dilithium_init(&key);
  12551. if (ret != 0) {
  12552. printf("wc_dilithium_init failed %d\n", ret);
  12553. return;
  12554. }
  12555. ret = wc_dilithium_set_level(&key, level);
  12556. if (ret != 0) {
  12557. printf("wc_dilithium_set_level() failed %d\n", ret);
  12558. }
  12559. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12560. bench_stats_start(&count, &start);
  12561. do {
  12562. for (i = 0; i < agreeTimes; i++) {
  12563. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12564. if (ret != 0) {
  12565. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12566. return;
  12567. }
  12568. }
  12569. count += i;
  12570. } while (bench_stats_check(start)
  12571. #ifdef MULTI_VALUE_STATISTICS
  12572. || runs < minimum_runs
  12573. #endif
  12574. );
  12575. if (ret == 0) {
  12576. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12577. start, ret);
  12578. #ifdef MULTI_VALUE_STATISTICS
  12579. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12580. #endif
  12581. }
  12582. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12583. #ifndef WOLFSSL_NO_ML_DSA_44
  12584. if (level == 2) {
  12585. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12586. sizeof_bench_dilithium_level2_key, &key);
  12587. }
  12588. #endif
  12589. #ifndef WOLFSSL_NO_ML_DSA_65
  12590. if (level == 3) {
  12591. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12592. sizeof_bench_dilithium_level3_key, &key);
  12593. }
  12594. #endif
  12595. #ifndef WOLFSSL_NO_ML_DSA_87
  12596. if (level == 5) {
  12597. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12598. sizeof_bench_dilithium_level5_key, &key);
  12599. }
  12600. #endif
  12601. if (ret != 0) {
  12602. printf("Failed to load private key\n");
  12603. return;
  12604. }
  12605. #endif
  12606. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12607. if (level == 2) {
  12608. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12609. }
  12610. else if (level == 3) {
  12611. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12612. }
  12613. else {
  12614. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12615. }
  12616. RESET_MULTI_VALUE_STATS_VARS();
  12617. bench_stats_start(&count, &start);
  12618. do {
  12619. for (i = 0; i < agreeTimes; i++) {
  12620. if (ret == 0) {
  12621. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12622. GLOBAL_RNG);
  12623. if (ret != 0) {
  12624. printf("wc_dilithium_sign_msg failed\n");
  12625. }
  12626. }
  12627. RECORD_MULTI_VALUE_STATS();
  12628. }
  12629. count += i;
  12630. } while (bench_stats_check(start)
  12631. #ifdef MULTI_VALUE_STATISTICS
  12632. || runs < minimum_runs
  12633. #endif
  12634. );
  12635. if (ret == 0) {
  12636. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12637. ret);
  12638. #ifdef MULTI_VALUE_STATISTICS
  12639. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12640. #endif
  12641. }
  12642. #endif
  12643. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12644. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12645. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12646. #ifndef WOLFSSL_NO_ML_DSA_44
  12647. if (level == 2) {
  12648. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12649. x = sizeof_bench_dilithium_level2_sig;
  12650. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12651. #endif
  12652. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12653. sizeof_bench_dilithium_level2_pubkey, &key);
  12654. }
  12655. #endif
  12656. #ifndef WOLFSSL_NO_ML_DSA_65
  12657. if (level == 3) {
  12658. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12659. x = sizeof_bench_dilithium_level3_sig;
  12660. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12661. #endif
  12662. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12663. sizeof_bench_dilithium_level3_pubkey, &key);
  12664. }
  12665. #endif
  12666. #ifndef WOLFSSL_NO_ML_DSA_87
  12667. if (level == 5) {
  12668. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12669. x = sizeof_bench_dilithium_level5_sig;
  12670. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12671. #endif
  12672. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12673. sizeof_bench_dilithium_level5_pubkey, &key);
  12674. }
  12675. #endif
  12676. if (ret != 0) {
  12677. printf("Failed to load public key\n");
  12678. return;
  12679. }
  12680. #endif
  12681. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12682. RESET_MULTI_VALUE_STATS_VARS();
  12683. bench_stats_start(&count, &start);
  12684. do {
  12685. for (i = 0; i < agreeTimes; i++) {
  12686. if (ret == 0) {
  12687. int verify = 0;
  12688. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12689. &verify, &key);
  12690. if (ret != 0 || verify != 1) {
  12691. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12692. ret, verify);
  12693. ret = -1;
  12694. }
  12695. }
  12696. RECORD_MULTI_VALUE_STATS();
  12697. }
  12698. count += i;
  12699. } while (bench_stats_check(start)
  12700. #ifdef MULTI_VALUE_STATISTICS
  12701. || runs < minimum_runs
  12702. #endif
  12703. );
  12704. if (ret == 0) {
  12705. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12706. ret);
  12707. #ifdef MULTI_VALUE_STATISTICS
  12708. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12709. #endif
  12710. }
  12711. #endif
  12712. wc_dilithium_free(&key);
  12713. }
  12714. #endif /* HAVE_DILITHIUM */
  12715. #ifdef HAVE_SPHINCS
  12716. void bench_sphincsKeySign(byte level, byte optim)
  12717. {
  12718. int ret = 0;
  12719. sphincs_key key;
  12720. double start;
  12721. int i, count;
  12722. byte sig[SPHINCS_MAX_SIG_SIZE];
  12723. byte msg[512];
  12724. word32 x = 0;
  12725. const char**desc = bench_desc_words[lng_index];
  12726. DECLARE_MULTI_VALUE_STATS_VARS()
  12727. ret = wc_sphincs_init(&key);
  12728. if (ret != 0) {
  12729. printf("wc_sphincs_init failed %d\n", ret);
  12730. return;
  12731. }
  12732. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12733. if (ret != 0) {
  12734. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12735. }
  12736. if (ret == 0) {
  12737. ret = -1;
  12738. if ((level == 1) && (optim == FAST_VARIANT)) {
  12739. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12740. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12741. }
  12742. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12743. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12744. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12745. }
  12746. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12747. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12748. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12749. }
  12750. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12751. ret = wc_sphincs_import_private_key(
  12752. bench_sphincs_small_level1_key,
  12753. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12754. }
  12755. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12756. ret = wc_sphincs_import_private_key(
  12757. bench_sphincs_small_level3_key,
  12758. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12759. }
  12760. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12761. ret = wc_sphincs_import_private_key(
  12762. bench_sphincs_small_level5_key,
  12763. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12764. }
  12765. if (ret != 0) {
  12766. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12767. }
  12768. }
  12769. /* make dummy msg */
  12770. for (i = 0; i < (int)sizeof(msg); i++) {
  12771. msg[i] = (byte)i;
  12772. }
  12773. bench_stats_start(&count, &start);
  12774. do {
  12775. for (i = 0; i < agreeTimes; i++) {
  12776. if (ret == 0) {
  12777. if ((level == 1) && (optim == FAST_VARIANT)) {
  12778. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12779. }
  12780. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12781. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12782. }
  12783. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12784. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12785. }
  12786. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12787. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12788. }
  12789. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12790. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12791. }
  12792. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12793. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12794. }
  12795. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12796. if (ret != 0) {
  12797. printf("wc_sphincs_sign_msg failed\n");
  12798. }
  12799. }
  12800. RECORD_MULTI_VALUE_STATS();
  12801. }
  12802. count += i;
  12803. } while (bench_stats_check(start)
  12804. #ifdef MULTI_VALUE_STATISTICS
  12805. || runs < minimum_runs
  12806. #endif
  12807. );
  12808. if (ret == 0) {
  12809. if (optim == FAST_VARIANT) {
  12810. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12811. start, ret);
  12812. }
  12813. else {
  12814. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12815. start, ret);
  12816. }
  12817. #ifdef MULTI_VALUE_STATISTICS
  12818. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12819. #endif
  12820. }
  12821. RESET_MULTI_VALUE_STATS_VARS();
  12822. bench_stats_start(&count, &start);
  12823. do {
  12824. for (i = 0; i < agreeTimes; i++) {
  12825. if (ret == 0) {
  12826. int verify = 0;
  12827. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12828. &key);
  12829. if (ret != 0 || verify != 1) {
  12830. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12831. ret, verify);
  12832. ret = -1;
  12833. }
  12834. }
  12835. RECORD_MULTI_VALUE_STATS();
  12836. }
  12837. count += i;
  12838. } while (bench_stats_check(start)
  12839. #ifdef MULTI_VALUE_STATISTICS
  12840. || runs < minimum_runs
  12841. #endif
  12842. );
  12843. if (ret == 0) {
  12844. if (optim == FAST_VARIANT) {
  12845. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12846. start, ret);
  12847. }
  12848. else {
  12849. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12850. start, ret);
  12851. }
  12852. #ifdef MULTI_VALUE_STATISTICS
  12853. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12854. #endif
  12855. }
  12856. wc_sphincs_free(&key);
  12857. }
  12858. #endif /* HAVE_SPHINCS */
  12859. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12860. #define WIN32_LEAN_AND_MEAN
  12861. #include <windows.h>
  12862. double current_time(int reset)
  12863. {
  12864. static int init = 0;
  12865. static LARGE_INTEGER freq;
  12866. LARGE_INTEGER count;
  12867. (void)reset;
  12868. if (!init) {
  12869. QueryPerformanceFrequency(&freq);
  12870. init = 1;
  12871. }
  12872. QueryPerformanceCounter(&count);
  12873. #ifdef BENCH_MICROSECOND
  12874. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12875. #else
  12876. return (double)count.QuadPart / freq.QuadPart;
  12877. #endif
  12878. }
  12879. #elif defined MICROCHIP_PIC32
  12880. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12881. #define CLOCK 80000000.0
  12882. #else
  12883. #define CLOCK 40000000.0
  12884. #endif
  12885. extern void WriteCoreTimer(word32 t);
  12886. extern word32 ReadCoreTimer(void);
  12887. double current_time(int reset)
  12888. {
  12889. unsigned int ns;
  12890. if (reset) {
  12891. WriteCoreTimer(0);
  12892. }
  12893. /* get timer in ns */
  12894. ns = ReadCoreTimer();
  12895. /* return seconds as a double */
  12896. return ( ns / CLOCK * 2.0);
  12897. }
  12898. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12899. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12900. /* declared above at line 239 */
  12901. /* extern double current_time(int reset); */
  12902. #elif defined(FREERTOS)
  12903. #ifdef PLATFORMIO
  12904. #include <freertos/FreeRTOS.h>
  12905. #include <freertos/task.h>
  12906. #else
  12907. #include "task.h"
  12908. #endif
  12909. #if defined(WOLFSSL_ESPIDF)
  12910. /* prototype definition */
  12911. int construct_argv();
  12912. extern char* __argv[22];
  12913. /* current_time(reset)
  12914. *
  12915. * Benchmark passage of time, in fractional seconds.
  12916. * [reset] is non zero to adjust timer or counter to zero
  12917. *
  12918. * Use care when repeatedly calling calling. See implementation. */
  12919. double current_time(int reset)
  12920. {
  12921. double ret;
  12922. #if ESP_IDF_VERSION_MAJOR >= 4
  12923. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12924. #else
  12925. portTickType tickCount;
  12926. #endif
  12927. #if defined(__XTENSA__)
  12928. (void)reset;
  12929. if (reset) {
  12930. /* TODO: Determine a mechanism for reset that does not interfere
  12931. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12932. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12933. ESP_LOGW(TAG, "Current_time() reset!");
  12934. portTICK_TYPE_ENTER_CRITICAL();
  12935. {
  12936. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12937. _esp_cpu_count_last = xthal_get_ccount();
  12938. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12939. }
  12940. portTICK_TYPE_EXIT_CRITICAL();
  12941. */
  12942. }
  12943. #else
  12944. /* Only reset the CPU counter for RISC-V */
  12945. if (reset) {
  12946. ESP_LOGV(TAG, "current_time() reset!");
  12947. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12948. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12949. * See also esp_get_cycle_count_ex() */
  12950. #ifdef __XTENSA__
  12951. _esp_cpu_count_last = xthal_get_ccount();
  12952. #else
  12953. #if ESP_IDF_VERSION_MAJOR >= 5
  12954. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12955. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12956. #else
  12957. cpu_hal_set_cycle_count((uint32_t)0);
  12958. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  12959. #endif
  12960. #endif
  12961. }
  12962. #endif
  12963. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  12964. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  12965. The count of ticks since vTaskStartScheduler was called,
  12966. typiclly in app_startup.c */
  12967. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12968. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  12969. if (tickCount == last_tickCount) {
  12970. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  12971. }
  12972. if (tickCount < last_tickCount) {
  12973. ESP_LOGW(TAG, "last_tickCount overflow?");
  12974. }
  12975. #endif
  12976. if (reset) {
  12977. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12978. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  12979. #endif
  12980. last_tickCount = tickCount;
  12981. }
  12982. else {
  12983. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12984. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  12985. #endif
  12986. }
  12987. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  12988. ret = (double)tickCount / configTICK_RATE_HZ;
  12989. #else
  12990. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  12991. "assuming 1000 Hz.");
  12992. ret = (double)(tickCount / 1000.0);
  12993. #endif /* configTICK_RATE_HZ */
  12994. return ret;
  12995. } /* current_time */
  12996. #else
  12997. /* current_time(reset)
  12998. *
  12999. * Benchmark passage of time, in fractional seconds.
  13000. * [reset] is non zero to adjust timer or counter to zero
  13001. *
  13002. * Use care when repeatedly calling calling. See implementation. */
  13003. double current_time(int reset)
  13004. {
  13005. portTickType tickCount = xTaskGetTickCount();
  13006. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13007. #ifdef configTICK_RATE_HZ
  13008. return (double)tickCount / configTICK_RATE_HZ;
  13009. #else
  13010. return (double)tickCount / 1000;
  13011. #endif
  13012. }
  13013. #endif
  13014. #elif defined (WOLFSSL_TIRTOS)
  13015. extern double current_time(int reset);
  13016. #elif defined(FREESCALE_MQX)
  13017. double current_time(int reset)
  13018. {
  13019. TIME_STRUCT tv;
  13020. _time_get(&tv);
  13021. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13022. }
  13023. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13024. && defined(MAX3266X_RTC)
  13025. double current_time(int reset)
  13026. {
  13027. (void)reset;
  13028. return wc_MXC_RTC_Time();
  13029. }
  13030. #elif defined(FREESCALE_KSDK_BM)
  13031. double current_time(int reset)
  13032. {
  13033. return (double)OSA_TimeGetMsec() / 1000;
  13034. }
  13035. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13036. double current_time(int reset)
  13037. {
  13038. (void)reset;
  13039. return (double)osKernelGetTickCount() / 1000.0;
  13040. }
  13041. #elif defined(WOLFSSL_EMBOS)
  13042. #include "RTOS.h"
  13043. double current_time(int reset)
  13044. {
  13045. double time_now;
  13046. double current_s = OS_GetTime() / 1000.0;
  13047. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13048. time_now = (double)( current_s + current_us);
  13049. (void) reset;
  13050. return time_now;
  13051. }
  13052. #elif defined(WOLFSSL_SGX)
  13053. double current_time(int reset);
  13054. #elif defined(WOLFSSL_DEOS)
  13055. double current_time(int reset)
  13056. {
  13057. const uint32_t systemTickTimeInHz
  13058. = 1000000 / systemTickInMicroseconds();
  13059. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13060. (void)reset;
  13061. return (double) *systemTickPtr/systemTickTimeInHz;
  13062. }
  13063. #elif defined(MICRIUM)
  13064. double current_time(int reset)
  13065. {
  13066. #if (OS_VERSION < 50000)
  13067. CPU_ERR err;
  13068. (void)reset;
  13069. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13070. #else
  13071. RTOS_ERR err;
  13072. double ret = 0;
  13073. OS_TICK tick = OSTimeGet(&err);
  13074. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13075. (void)reset;
  13076. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13077. ret = ((double)tick)/rate;
  13078. }
  13079. return ret;
  13080. #endif
  13081. }
  13082. #elif defined(WOLFSSL_ZEPHYR)
  13083. #include <time.h>
  13084. double current_time(int reset)
  13085. {
  13086. int64_t t;
  13087. (void)reset;
  13088. #if defined(CONFIG_ARCH_POSIX)
  13089. k_cpu_idle();
  13090. #endif
  13091. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13092. return (double)(t / 1000);
  13093. }
  13094. #elif defined(WOLFSSL_NETBURNER)
  13095. #include <predef.h>
  13096. #include <utils.h>
  13097. #include <constants.h>
  13098. double current_time(int reset)
  13099. {
  13100. DWORD ticks = TimeTick; /* ticks since system start */
  13101. (void)reset;
  13102. return (double) ticks/TICKS_PER_SECOND;
  13103. }
  13104. #elif defined(THREADX)
  13105. #include "tx_api.h"
  13106. double current_time(int reset)
  13107. {
  13108. (void)reset;
  13109. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13110. }
  13111. #elif defined(WOLFSSL_XILINX)
  13112. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13113. #define COUNTS_PER_SECOND \
  13114. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13115. #else
  13116. #define COUNTS_PER_SECOND \
  13117. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13118. #endif
  13119. double current_time(int reset)
  13120. {
  13121. double timer;
  13122. uint64_t cntPct = 0;
  13123. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13124. /* Convert to milliseconds */
  13125. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13126. /* Convert to seconds.millisecond */
  13127. timer /= 1000;
  13128. return timer;
  13129. }
  13130. #elif defined(LINUX_RUSAGE_UTIME)
  13131. #include <sys/time.h>
  13132. #include <sys/resource.h>
  13133. static struct rusage base_rusage;
  13134. static struct rusage cur_rusage;
  13135. double current_time(int reset)
  13136. {
  13137. struct rusage rusage;
  13138. (void)reset;
  13139. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13140. if (reset)
  13141. base_rusage = rusage;
  13142. else
  13143. cur_rusage = rusage;
  13144. /* only consider user time, as system time is host-related overhead
  13145. * outside wolfcrypt.
  13146. */
  13147. return (double)rusage.ru_utime.tv_sec +
  13148. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13149. }
  13150. static void check_for_excessive_stime(const char *desc,
  13151. const char *desc_extra)
  13152. {
  13153. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13154. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13155. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13156. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13157. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13158. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13159. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13160. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13161. double stime_utime_ratio =
  13162. (cur_stime - start_stime) / (cur_utime - start_utime);
  13163. if (stime_utime_ratio > .1)
  13164. printf("%swarning, "
  13165. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13166. err_prefix, desc, desc_extra,
  13167. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13168. }
  13169. #elif defined(WOLFSSL_LINUXKM)
  13170. double current_time(int reset)
  13171. {
  13172. (void)reset;
  13173. u64 ns = ktime_get_ns();
  13174. return (double)ns / 1000000000.0;
  13175. }
  13176. #else
  13177. #include <sys/time.h>
  13178. double current_time(int reset)
  13179. {
  13180. struct timespec tv;
  13181. (void)reset;
  13182. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13183. #ifdef BENCH_MICROSECOND
  13184. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13185. #else
  13186. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13187. #endif
  13188. }
  13189. #endif /* _WIN32 */
  13190. #if defined(HAVE_GET_CYCLES)
  13191. #if defined(WOLFSSL_ESPIDF)
  13192. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13193. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13194. {
  13195. /* Reminder for long duration between calls with
  13196. * multiple overflows will not be detected. */
  13197. return esp_get_cycle_count_ex();
  13198. }
  13199. /* implement other architectures here */
  13200. #else
  13201. static WC_INLINE word64 get_intel_cycles(void)
  13202. {
  13203. unsigned int lo_c, hi_c;
  13204. __asm__ __volatile__ (
  13205. "cpuid\n\t"
  13206. "rdtsc"
  13207. : "=a"(lo_c), "=d"(hi_c) /* out */
  13208. : "a"(0) /* in */
  13209. : "%ebx", "%ecx"); /* clobber */
  13210. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13211. }
  13212. #endif
  13213. #endif /* HAVE_GET_CYCLES */
  13214. void benchmark_configure(word32 block_size)
  13215. {
  13216. /* must be greater than 0 */
  13217. if (block_size > 0) {
  13218. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13219. bench_size = block_size;
  13220. }
  13221. }
  13222. #ifndef NO_MAIN_DRIVER
  13223. #ifndef MAIN_NO_ARGS
  13224. #ifndef WOLFSSL_BENCHMARK_ALL
  13225. /* Display the algorithm string and keep to 80 characters per line.
  13226. *
  13227. * str Algorithm string to print.
  13228. * line Length of line used so far.
  13229. */
  13230. #ifndef BENCH_MAX_LINE
  13231. #define BENCH_MAX_LINE 80
  13232. #endif
  13233. static void print_alg(const char* str, int* line)
  13234. {
  13235. const char* const ident = " ";
  13236. if (*line == 0) {
  13237. printf("%s", ident);
  13238. *line = (int)XSTRLEN(ident);
  13239. }
  13240. printf(" %s", str);
  13241. *line += (int)XSTRLEN(str) + 1;
  13242. if (*line > BENCH_MAX_LINE) {
  13243. printf("\n");
  13244. *line = 0;
  13245. }
  13246. }
  13247. #endif /* WOLFSSL_BENCHMARK_ALL */
  13248. /* Display the usage options of the benchmark program. */
  13249. static void Usage(void)
  13250. {
  13251. int e = 0;
  13252. #ifndef WOLFSSL_BENCHMARK_ALL
  13253. int i;
  13254. int line;
  13255. #endif
  13256. printf("benchmark\n");
  13257. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13258. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13259. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13260. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13261. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13262. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13263. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13264. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13265. #else
  13266. e += 3;
  13267. #endif
  13268. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13269. #ifndef NO_RSA
  13270. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13271. #ifdef WOLFSSL_KEY_GEN
  13272. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13273. #endif
  13274. e++;
  13275. #else
  13276. e += 2;
  13277. #endif
  13278. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13279. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13280. #endif
  13281. e++;
  13282. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13283. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13284. #endif
  13285. e++;
  13286. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13287. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13288. #endif
  13289. e++;
  13290. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13291. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13292. #endif
  13293. e++;
  13294. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13295. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13296. #endif
  13297. e++;
  13298. #if defined(HAVE_ECC)
  13299. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13300. #endif
  13301. e++;
  13302. #ifndef WOLFSSL_BENCHMARK_ALL
  13303. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13304. line = 0;
  13305. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13306. print_alg(bench_cipher_opt[i].str, &line);
  13307. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13308. print_alg(bench_digest_opt[i].str, &line);
  13309. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13310. print_alg(bench_mac_opt[i].str, &line);
  13311. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13312. print_alg(bench_kdf_opt[i].str, &line);
  13313. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13314. print_alg(bench_asym_opt[i].str, &line);
  13315. for (i=0; bench_other_opt[i].str != NULL; i++)
  13316. print_alg(bench_other_opt[i].str, &line);
  13317. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13318. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13319. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13320. print_alg(bench_pq_asym_opt[i].str, &line);
  13321. #if defined(HAVE_SPHINCS)
  13322. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13323. print_alg(bench_pq_asym_opt2[i].str, &line);
  13324. #endif /* HAVE_SPHINCS */
  13325. #endif
  13326. #if defined(BENCH_PQ_STATEFUL_HBS)
  13327. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13328. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13329. #endif /* BENCH_PQ_STATEFUL_HBS */
  13330. printf("\n");
  13331. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13332. e++;
  13333. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13334. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13335. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13336. #ifdef WC_ENABLE_BENCH_THREADING
  13337. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13338. #endif
  13339. e++;
  13340. #ifdef WC_BENCH_TRACK_STATS
  13341. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13342. #endif
  13343. e++;
  13344. #ifndef NO_FILESYSTEM
  13345. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13346. #endif
  13347. e++;
  13348. #ifndef NO_FILESYSTEM
  13349. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13350. #endif
  13351. #ifdef MULTI_VALUE_STATISTICS
  13352. e++;
  13353. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13354. #endif
  13355. }
  13356. /* Match the command line argument with the string.
  13357. *
  13358. * arg Command line argument.
  13359. * str String to check for.
  13360. * return 1 if the command line argument matches the string, 0 otherwise.
  13361. */
  13362. static int string_matches(const char* arg, const char* str)
  13363. {
  13364. return XSTRCMP(arg, str) == 0;
  13365. }
  13366. #endif /* MAIN_NO_ARGS */
  13367. /*
  13368. ** ----------------------------------------------------------------------------
  13369. ** determine how the benchmarks are called, the function name varies:
  13370. ** ----------------------------------------------------------------------------
  13371. */
  13372. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13373. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13374. /* for some environments, we'll call a function wolf_benchmark_task: */
  13375. int wolf_benchmark_task(void)
  13376. #elif defined(MAIN_NO_ARGS)
  13377. /* otherwise we'll use main() with no arguments as desired: */
  13378. int main()
  13379. #else
  13380. /* else we'll be calling main with default arg parameters */
  13381. int main(int argc, char** argv)
  13382. #endif
  13383. {
  13384. /* Code for main() or wolf_benchmark_task() */
  13385. #ifdef WOLFSSL_ESPIDF
  13386. int argc = construct_argv();
  13387. char** argv = (char**)__argv;
  13388. #elif defined(MAIN_NO_ARGS)
  13389. int argc = 0;
  13390. char** argv = NULL;
  13391. #endif
  13392. return wolfcrypt_benchmark_main(argc, argv);
  13393. }
  13394. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13395. int wolfcrypt_benchmark_main(int argc, char** argv)
  13396. {
  13397. int ret = 0;
  13398. #ifndef MAIN_NO_ARGS
  13399. int optMatched;
  13400. #ifndef WOLFSSL_BENCHMARK_ALL
  13401. int i;
  13402. #endif
  13403. #endif
  13404. benchmark_static_init(1);
  13405. printf("%s------------------------------------------------------------------------------\n",
  13406. info_prefix);
  13407. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13408. printf("%s------------------------------------------------------------------------------\n",
  13409. info_prefix);
  13410. #ifndef MAIN_NO_ARGS
  13411. while (argc > 1) {
  13412. if (string_matches(argv[1], "-?")) {
  13413. if (--argc > 1) {
  13414. lng_index = XATOI((++argv)[1]);
  13415. if (lng_index<0 || lng_index>1) {
  13416. lng_index = 0;
  13417. }
  13418. }
  13419. Usage();
  13420. return 0;
  13421. }
  13422. else if (string_matches(argv[1], "-lng")) {
  13423. argc--;
  13424. argv++;
  13425. if (argc > 1) {
  13426. lng_index = XATOI(argv[1]);
  13427. if (lng_index<0 || lng_index>1) {
  13428. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13429. lng_index);
  13430. lng_index = 0;
  13431. }
  13432. }
  13433. }
  13434. else if (string_matches(argv[1], "-base10"))
  13435. base2 = 0;
  13436. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13437. else if (string_matches(argv[1], "-no_aad"))
  13438. aes_aad_options = AAD_SIZE_ZERO;
  13439. else if (string_matches(argv[1], "-all_aad"))
  13440. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13441. else if (string_matches(argv[1], "-aad_size")) {
  13442. argc--;
  13443. argv++;
  13444. if (argc > 1) {
  13445. aes_aad_size = (word32)XATOI(argv[1]);
  13446. aes_aad_options |= AAD_SIZE_CUSTOM;
  13447. }
  13448. }
  13449. #endif
  13450. else if (string_matches(argv[1], "-dgst_full"))
  13451. digest_stream = 0;
  13452. #ifdef HAVE_CHACHA
  13453. else if (string_matches(argv[1], "-enc_only"))
  13454. encrypt_only = 1;
  13455. #endif
  13456. #ifndef NO_RSA
  13457. else if (string_matches(argv[1], "-rsa_sign"))
  13458. rsa_sign_verify = 1;
  13459. #endif
  13460. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13461. else if (string_matches(argv[1], "-ffdhe2048"))
  13462. use_ffdhe = 2048;
  13463. #endif
  13464. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13465. else if (string_matches(argv[1], "-ffdhe3072"))
  13466. use_ffdhe = 3072;
  13467. #endif
  13468. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13469. else if (string_matches(argv[1], "-ffdhe4096"))
  13470. use_ffdhe = 4096;
  13471. #endif
  13472. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13473. else if (string_matches(argv[1], "-p256"))
  13474. bench_asym_algs |= BENCH_ECC_P256;
  13475. #endif
  13476. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13477. else if (string_matches(argv[1], "-p384"))
  13478. bench_asym_algs |= BENCH_ECC_P384;
  13479. #endif
  13480. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13481. else if (string_matches(argv[1], "-p521"))
  13482. bench_asym_algs |= BENCH_ECC_P521;
  13483. #endif
  13484. #ifdef BENCH_ASYM
  13485. else if (string_matches(argv[1], "-csv")) {
  13486. csv_format = 1;
  13487. }
  13488. #endif
  13489. #ifdef WC_ENABLE_BENCH_THREADING
  13490. else if (string_matches(argv[1], "-threads")) {
  13491. argc--;
  13492. argv++;
  13493. if (argc > 1) {
  13494. g_threadCount = XATOI(argv[1]);
  13495. if (g_threadCount < 1 || lng_index > 128){
  13496. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13497. g_threadCount);
  13498. g_threadCount = 0;
  13499. }
  13500. }
  13501. }
  13502. #endif
  13503. #ifdef WC_BENCH_TRACK_STATS
  13504. else if (string_matches(argv[1], "-print")) {
  13505. gPrintStats = 1;
  13506. }
  13507. #endif
  13508. else if (string_matches(argv[1], "-blocks")) {
  13509. argc--;
  13510. argv++;
  13511. if (argc > 1)
  13512. numBlocks = XATOI(argv[1]);
  13513. }
  13514. #ifndef NO_FILESYSTEM
  13515. else if (string_matches(argv[1], "-hash_input")) {
  13516. argc--;
  13517. argv++;
  13518. if (argc > 1)
  13519. hash_input = argv[1];
  13520. }
  13521. else if (string_matches(argv[1], "-cipher_input")) {
  13522. argc--;
  13523. argv++;
  13524. if (argc > 1)
  13525. cipher_input = argv[1];
  13526. }
  13527. #endif
  13528. #ifdef MULTI_VALUE_STATISTICS
  13529. else if (string_matches(argv[1], "-min_runs")) {
  13530. argc--;
  13531. argv++;
  13532. if (argc > 1) {
  13533. minimum_runs = XATOI(argv[1]);
  13534. }
  13535. }
  13536. #endif
  13537. else if (argv[1][0] == '-') {
  13538. optMatched = 0;
  13539. #ifndef WOLFSSL_BENCHMARK_ALL
  13540. /* Check known algorithm choosing command line options. */
  13541. /* Known cipher algorithms */
  13542. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13543. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13544. bench_cipher_algs |= bench_cipher_opt[i].val;
  13545. bench_all = 0;
  13546. optMatched = 1;
  13547. }
  13548. }
  13549. /* Known digest algorithms */
  13550. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13551. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13552. bench_digest_algs |= bench_digest_opt[i].val;
  13553. bench_all = 0;
  13554. optMatched = 1;
  13555. }
  13556. }
  13557. /* Known MAC algorithms */
  13558. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13559. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13560. bench_mac_algs |= bench_mac_opt[i].val;
  13561. bench_all = 0;
  13562. optMatched = 1;
  13563. }
  13564. }
  13565. /* Known KDF algorithms */
  13566. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13567. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13568. bench_kdf_algs |= bench_kdf_opt[i].val;
  13569. bench_all = 0;
  13570. optMatched = 1;
  13571. }
  13572. }
  13573. /* Known asymmetric algorithms */
  13574. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13575. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13576. bench_asym_algs |= bench_asym_opt[i].val;
  13577. bench_all = 0;
  13578. optMatched = 1;
  13579. }
  13580. }
  13581. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13582. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13583. /* Known asymmetric post-quantum algorithms */
  13584. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13585. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13586. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13587. bench_all = 0;
  13588. optMatched = 1;
  13589. }
  13590. }
  13591. #ifdef HAVE_SPHINCS
  13592. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13593. * -pq, so we need to do a special case for -pq since optMatched
  13594. * was set to 1 just above. */
  13595. if ((bench_pq_asym_opt[0].str != NULL) &&
  13596. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13597. {
  13598. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13599. bench_all = 0;
  13600. optMatched = 1;
  13601. }
  13602. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13603. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13604. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13605. bench_all = 0;
  13606. optMatched = 1;
  13607. }
  13608. }
  13609. #endif
  13610. #endif
  13611. /* Other known cryptographic algorithms */
  13612. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13613. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13614. bench_other_algs |= bench_other_opt[i].val;
  13615. bench_all = 0;
  13616. optMatched = 1;
  13617. }
  13618. }
  13619. #if defined(BENCH_PQ_STATEFUL_HBS)
  13620. /* post-quantum stateful hash-based signatures */
  13621. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13622. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13623. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13624. bench_all = 0;
  13625. optMatched = 1;
  13626. }
  13627. }
  13628. #endif /* BENCH_PQ_STATEFUL_HBS */
  13629. #endif
  13630. if (!optMatched) {
  13631. printf("Option not recognized: %s\n", argv[1]);
  13632. Usage();
  13633. return 1;
  13634. }
  13635. }
  13636. else {
  13637. /* parse for block size */
  13638. benchmark_configure((word32)XATOI(argv[1]));
  13639. }
  13640. argc--;
  13641. argv++;
  13642. }
  13643. #endif /* MAIN_NO_ARGS */
  13644. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13645. /* when defined, we'll always output CSV regardless of params.
  13646. ** this is typically convenient in embedded environments.
  13647. */
  13648. csv_format = 1;
  13649. #endif
  13650. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13651. if (g_threadCount > 1) {
  13652. ret = benchmark_test_threaded(NULL);
  13653. }
  13654. else
  13655. #endif
  13656. {
  13657. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13658. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13659. defined(CONFIG_IDF_TARGET_ESP32C6)
  13660. {
  13661. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13662. if (esp_gptimer == NULL) {
  13663. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13664. &esp_gptimer) );
  13665. }
  13666. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13667. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13668. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13669. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13670. }
  13671. #endif
  13672. #ifdef HAVE_STACK_SIZE
  13673. ret = StackSizeCheck(NULL, benchmark_test);
  13674. #else
  13675. ret = benchmark_test(NULL);
  13676. #endif
  13677. }
  13678. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13679. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13680. defined(CONFIG_IDF_TARGET_ESP32C6)
  13681. {
  13682. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13683. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13684. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13685. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13686. }
  13687. #endif
  13688. return ret;
  13689. }
  13690. #endif /* !NO_MAIN_DRIVER */
  13691. #else
  13692. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13693. int main(void) { return 0; }
  13694. #endif
  13695. #endif /* !NO_CRYPT_BENCHMARK */