1
0

benchmark.c 509 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010
  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. #ifdef configTICK_RATE_HZ
  305. /* Define CPU clock cycles per tick of FreeRTOS clock
  306. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  307. * configTICK_RATE_HZ is typically 100 or 1000.
  308. **/
  309. #if defined(CONFIG_IDF_TARGET_ESP8266)
  310. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  311. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  312. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  313. #endif
  314. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  315. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  316. #endif
  317. #endif
  318. #define CPU_TICK_CYCLES ( \
  319. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  320. / configTICK_RATE_HZ \
  321. )
  322. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  323. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  324. #include "driver/gptimer.h"
  325. static gptimer_handle_t esp_gptimer = NULL;
  326. static gptimer_config_t esp_timer_config = {
  327. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  328. .direction = GPTIMER_COUNT_UP,
  329. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  330. };
  331. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  332. defined(CONFIG_IDF_TARGET_ESP32C6)
  333. #include <esp_cpu.h>
  334. #include "driver/gptimer.h"
  335. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  336. #define RESOLUTION_SCALE 100
  337. static gptimer_handle_t esp_gptimer = NULL;
  338. static gptimer_config_t esp_timer_config = {
  339. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  340. .direction = GPTIMER_COUNT_UP,
  341. /* CONFIG_XTAL_FREQ = 40,
  342. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  343. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  344. (MILLION_VALUE / RESOLUTION_SCALE),
  345. };
  346. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  347. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  348. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  349. defined(CONFIG_IDF_TARGET_ESP32S3)
  350. #include <xtensa/hal.h>
  351. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  352. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  353. #include <FreeRTOS.h>
  354. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  355. /* TODO add ESP32-H2 benchmark support */
  356. #else
  357. /* Other platform */
  358. #endif
  359. #include <esp_log.h>
  360. #endif /* WOLFSSL_ESPIDF */
  361. #if defined(HAVE_PTHREAD) || \
  362. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  363. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  364. !defined(BENCH_EMBEDDED))
  365. #include <errno.h>
  366. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  367. #include <unistd.h>
  368. #endif
  369. #endif
  370. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  371. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  372. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  373. #undef XFFLUSH
  374. #define XFFLUSH(...) WC_DO_NOTHING
  375. #endif
  376. /* only for stack size check */
  377. #include <wolfssl/wolfcrypt/mem_track.h>
  378. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  379. #define WC_ENABLE_BENCH_THREADING
  380. #endif
  381. /* enable tracking of stats for threaded benchmark */
  382. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  383. #define WC_BENCH_TRACK_STATS
  384. #endif
  385. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  386. static const char info_prefix[] = "###, ";
  387. static const char err_prefix[] = "!!!, ";
  388. #else
  389. static const char info_prefix[] = "";
  390. static const char err_prefix[] = "";
  391. #endif
  392. /* printf mappings */
  393. #ifdef FREESCALE_MQX
  394. #include <mqx.h>
  395. /* see wc_port.h for fio.h and nio.h includes */
  396. #elif defined(FREESCALE_KSDK_1_3)
  397. #include "fsl_debug_console.h"
  398. #include "fsl_os_abstraction.h"
  399. #undef printf
  400. #define printf PRINTF
  401. #elif defined(WOLFSSL_DEOS)
  402. #include <deos.h>
  403. #include <printx.h>
  404. #undef printf
  405. #define printf printx
  406. #elif defined(MICRIUM)
  407. #if (OS_VERSION < 50000)
  408. #include <bsp_ser.h>
  409. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  410. #undef printf
  411. #define printf BSP_Ser_Printf
  412. #endif
  413. #elif defined(WOLFSSL_ZEPHYR)
  414. #include <stdio.h>
  415. #define BENCH_EMBEDDED
  416. #define printf printfk
  417. static int printfk(const char *fmt, ...)
  418. {
  419. int ret;
  420. char line[WC_BENCH_MAX_LINE_LEN];
  421. va_list ap;
  422. va_start(ap, fmt);
  423. ret = vsnprintf(line, sizeof(line), fmt, ap);
  424. line[sizeof(line)-1] = '\0';
  425. printk("%s", line);
  426. va_end(ap);
  427. return ret;
  428. }
  429. #elif defined(WOLFSSL_TELIT_M2MB)
  430. #include <stdarg.h>
  431. #include <stdio.h>
  432. #include <string.h>
  433. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  434. /* remap printf */
  435. #undef printf
  436. #define printf M2M_LOG_INFO
  437. /* OS requires occasional sleep() */
  438. #ifndef TEST_SLEEP_MS
  439. #define TEST_SLEEP_MS 50
  440. #endif
  441. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  442. /* don't use file system for these tests, since ./certs dir isn't loaded */
  443. #undef NO_FILESYSTEM
  444. #define NO_FILESYSTEM
  445. /* ANDROID_V454 (for android studio) displays information in a textview
  446. * and redirects printf to the textview output instead of using
  447. * __android_log_print() */
  448. #elif defined(ANDROID) && !defined(ANDROID_V454)
  449. #ifdef XMALLOC_USER
  450. #include <stdlib.h> /* we're using malloc / free direct here */
  451. #endif
  452. #ifndef STRING_USER
  453. #include <stdio.h>
  454. #endif
  455. #include <android/log.h>
  456. #define printf(...) \
  457. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  458. #define fprintf(fp, ...) \
  459. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  460. #else
  461. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  462. /* MQX classic needs for EXIT_FAILURE */
  463. #include <stdlib.h> /* we're using malloc / free direct here */
  464. #endif
  465. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  466. #include <string.h>
  467. #include <stdio.h>
  468. #endif
  469. /* enable way for customer to override test/bench printf */
  470. #ifdef XPRINTF
  471. #undef printf
  472. #define printf XPRINTF
  473. #elif defined(NETOS)
  474. #undef printf
  475. #define printf dc_log_printf
  476. #endif
  477. #endif
  478. #ifdef HAVE_FIPS
  479. #include <wolfssl/wolfcrypt/fips_test.h>
  480. static void myFipsCb(int ok, int err, const char* hash)
  481. {
  482. printf("%sin my Fips callback, ok = %d, err = %d\n",
  483. ok ? info_prefix : err_prefix, ok, err);
  484. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  485. wc_GetErrorString(err));
  486. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  487. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  488. printf("%sIn core integrity hash check failure, copy above hash\n",
  489. err_prefix);
  490. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  491. err_prefix);
  492. }
  493. }
  494. #endif
  495. #ifdef WOLFSSL_STATIC_MEMORY
  496. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  497. #else
  498. #define HEAP_HINT NULL
  499. #endif /* WOLFSSL_STATIC_MEMORY */
  500. #ifndef EXIT_FAILURE
  501. #define EXIT_FAILURE 1
  502. #endif
  503. #undef LIBCALL_CHECK_RET
  504. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  505. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  506. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  507. #else
  508. #define LIBCALL_CHECK_RET(...) do { \
  509. int _libcall_ret = (__VA_ARGS__); \
  510. if (_libcall_ret < 0) { \
  511. printf("%s%s L%d error %d for \"%s\"\n", \
  512. err_prefix, __FILE__, __LINE__, \
  513. errno, #__VA_ARGS__); \
  514. XFFLUSH(stdout); \
  515. _exit(1); \
  516. } \
  517. } while(0)
  518. #endif
  519. #undef THREAD_CHECK_RET
  520. #define THREAD_CHECK_RET(...) do { \
  521. int _thread_ret = (__VA_ARGS__); \
  522. if (_thread_ret != 0) { \
  523. errno = _thread_ret; \
  524. printf("%s%s L%d error %d for \"%s\"\n", \
  525. err_prefix, __FILE__, __LINE__, \
  526. _thread_ret, #__VA_ARGS__); \
  527. XFFLUSH(stdout); \
  528. _exit(1); \
  529. } \
  530. } while(0)
  531. /* optional macro to add sleep between tests */
  532. #ifndef TEST_SLEEP
  533. /* stub the sleep macro */
  534. #define TEST_SLEEP() WC_DO_NOTHING
  535. #endif
  536. #define TEST_STRING "Everyone gets Friday off."
  537. #define TEST_STRING_SZ 25
  538. /* Bit values for each algorithm that is able to be benchmarked.
  539. * Common grouping of algorithms also.
  540. * Each algorithm has a unique value for its type e.g. cipher.
  541. */
  542. /* Cipher algorithms. */
  543. #define BENCH_AES_CBC 0x00000001
  544. #define BENCH_AES_GCM 0x00000002
  545. #define BENCH_AES_ECB 0x00000004
  546. #define BENCH_AES_XTS 0x00000008
  547. #define BENCH_AES_CTR 0x00000010
  548. #define BENCH_AES_CCM 0x00000020
  549. #define BENCH_CAMELLIA 0x00000100
  550. #define BENCH_ARC4 0x00000200
  551. #define BENCH_CHACHA20 0x00001000
  552. #define BENCH_CHACHA20_POLY1305 0x00002000
  553. #define BENCH_DES 0x00004000
  554. #define BENCH_AES_CFB 0x00010000
  555. #define BENCH_AES_OFB 0x00020000
  556. #define BENCH_AES_SIV 0x00040000
  557. #define BENCH_SM4_CBC 0x00080000
  558. #define BENCH_SM4_GCM 0x00100000
  559. #define BENCH_SM4_CCM 0x00200000
  560. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  561. /* Digest algorithms. */
  562. #define BENCH_MD5 0x00000001
  563. #define BENCH_POLY1305 0x00000002
  564. #define BENCH_SHA 0x00000004
  565. #define BENCH_SHA224 0x00000010
  566. #define BENCH_SHA256 0x00000020
  567. #define BENCH_SHA384 0x00000040
  568. #define BENCH_SHA512 0x00000080
  569. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  570. BENCH_SHA384 | BENCH_SHA512)
  571. #define BENCH_SHA3_224 0x00000100
  572. #define BENCH_SHA3_256 0x00000200
  573. #define BENCH_SHA3_384 0x00000400
  574. #define BENCH_SHA3_512 0x00000800
  575. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  576. BENCH_SHA3_384 | BENCH_SHA3_512)
  577. #define BENCH_SHAKE128 0x00001000
  578. #define BENCH_SHAKE256 0x00002000
  579. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  580. #define BENCH_RIPEMD 0x00004000
  581. #define BENCH_BLAKE2B 0x00008000
  582. #define BENCH_BLAKE2S 0x00010000
  583. #define BENCH_SM3 0x00020000
  584. /* MAC algorithms. */
  585. #define BENCH_CMAC 0x00000001
  586. #define BENCH_HMAC_MD5 0x00000002
  587. #define BENCH_HMAC_SHA 0x00000004
  588. #define BENCH_HMAC_SHA224 0x00000010
  589. #define BENCH_HMAC_SHA256 0x00000020
  590. #define BENCH_HMAC_SHA384 0x00000040
  591. #define BENCH_HMAC_SHA512 0x00000080
  592. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  593. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  594. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  595. #define BENCH_PBKDF2 0x00000100
  596. #define BENCH_SIPHASH 0x00000200
  597. /* KDF algorithms */
  598. #define BENCH_SRTP_KDF 0x00000001
  599. /* Asymmetric algorithms. */
  600. #define BENCH_RSA_KEYGEN 0x00000001
  601. #define BENCH_RSA 0x00000002
  602. #define BENCH_RSA_SZ 0x00000004
  603. #define BENCH_DH 0x00000010
  604. #define BENCH_ECC_MAKEKEY 0x00001000
  605. #define BENCH_ECC 0x00002000
  606. #define BENCH_ECC_ENCRYPT 0x00004000
  607. #define BENCH_ECC_ALL 0x00008000
  608. #define BENCH_CURVE25519_KEYGEN 0x00010000
  609. #define BENCH_CURVE25519_KA 0x00020000
  610. #define BENCH_ED25519_KEYGEN 0x00040000
  611. #define BENCH_ED25519_SIGN 0x00080000
  612. #define BENCH_CURVE448_KEYGEN 0x00100000
  613. #define BENCH_CURVE448_KA 0x00200000
  614. #define BENCH_ED448_KEYGEN 0x00400000
  615. #define BENCH_ED448_SIGN 0x00800000
  616. #define BENCH_ECC_P256 0x01000000
  617. #define BENCH_ECC_P384 0x02000000
  618. #define BENCH_ECC_P521 0x04000000
  619. #define BENCH_SM2 0x08000000
  620. #define BENCH_ECCSI_KEYGEN 0x00000020
  621. #define BENCH_ECCSI_PAIRGEN 0x00000040
  622. #define BENCH_ECCSI_VALIDATE 0x00000080
  623. #define BENCH_ECCSI 0x00000400
  624. #define BENCH_SAKKE_KEYGEN 0x10000000
  625. #define BENCH_SAKKE_RSKGEN 0x20000000
  626. #define BENCH_SAKKE_VALIDATE 0x40000000
  627. #define BENCH_SAKKE 0x80000000
  628. /* Post-Quantum Asymmetric algorithms. */
  629. #define BENCH_KYBER512 0x00000020
  630. #define BENCH_KYBER768 0x00000040
  631. #define BENCH_KYBER1024 0x00000080
  632. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  633. BENCH_KYBER1024)
  634. #define BENCH_ML_KEM_512 0x00000020
  635. #define BENCH_ML_KEM_768 0x00000040
  636. #define BENCH_ML_KEM_1024 0x00000080
  637. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  638. BENCH_ML_KEM_1024)
  639. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  640. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  641. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  642. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  643. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  644. #define BENCH_ML_DSA_44_SIGN 0x04000000
  645. #define BENCH_ML_DSA_65_SIGN 0x08000000
  646. #define BENCH_ML_DSA_87_SIGN 0x10000000
  647. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  648. BENCH_ML_DSA_65_SIGN | \
  649. BENCH_ML_DSA_87_SIGN)
  650. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  651. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  652. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  653. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  654. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  655. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  656. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  657. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  658. #define BENCH_LMS_HSS 0x00000001
  659. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  660. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  661. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  662. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  663. #ifndef NO_SHA256
  664. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  665. #elif defined(WOLFSSL_SHA512)
  666. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  667. #elif defined(WOLFSSL_SHAKE128)
  668. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  669. #elif defined(WOLFSSL_SHAKE256)
  670. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  671. #else
  672. #define BENCH_XMSS_XMSSMT 0x00000000
  673. #endif
  674. /* Other */
  675. #define BENCH_RNG 0x00000001
  676. #define BENCH_SCRYPT 0x00000002
  677. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  678. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  679. * static declaration of `bench_Usage_msg1`. */
  680. #if !defined(AES_AUTH_ADD_SZ) && \
  681. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  682. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  683. /* For STM32 use multiple of 4 to leverage crypto hardware
  684. * Xilinx Versal requires to use multiples of 16 bytes */
  685. #define AES_AUTH_ADD_SZ 16
  686. #endif
  687. #ifndef AES_AUTH_ADD_SZ
  688. #define AES_AUTH_ADD_SZ 13
  689. #endif
  690. #endif
  691. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  692. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  693. #define BENCH_PQ_STATEFUL_HBS
  694. #endif
  695. /* Benchmark all compiled in algorithms.
  696. * When 1, ignore other benchmark algorithm values.
  697. * 0, only benchmark algorithm values set.
  698. */
  699. static int bench_all = 1;
  700. /* Cipher algorithms to benchmark. */
  701. static word32 bench_cipher_algs = 0;
  702. /* Digest algorithms to benchmark. */
  703. static word32 bench_digest_algs = 0;
  704. /* MAC algorithms to benchmark. */
  705. static word32 bench_mac_algs = 0;
  706. /* KDF algorithms to benchmark. */
  707. static word32 bench_kdf_algs = 0;
  708. /* Asymmetric algorithms to benchmark. */
  709. static word32 bench_asym_algs = 0;
  710. /* Post-Quantum Asymmetric algorithms to benchmark. */
  711. static word32 bench_pq_asym_algs = 0;
  712. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  713. static word32 bench_pq_asym_algs2 = 0;
  714. /* Other cryptographic algorithms to benchmark. */
  715. static word32 bench_other_algs = 0;
  716. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  717. static word32 bench_pq_hash_sig_algs = 0;
  718. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  719. /* The mapping of command line option to bit values. */
  720. typedef struct bench_alg {
  721. /* Command line option string. */
  722. const char* str;
  723. /* Bit values to set. */
  724. word32 val;
  725. } bench_alg;
  726. #ifndef MAIN_NO_ARGS
  727. /* All recognized cipher algorithm choosing command line options. */
  728. static const bench_alg bench_cipher_opt[] = {
  729. { "-cipher", 0xffffffff },
  730. #ifdef HAVE_AES_CBC
  731. { "-aes-cbc", BENCH_AES_CBC },
  732. #endif
  733. #ifdef HAVE_AESGCM
  734. { "-aes-gcm", BENCH_AES_GCM },
  735. #endif
  736. #ifdef WOLFSSL_AES_DIRECT
  737. { "-aes-ecb", BENCH_AES_ECB },
  738. #endif
  739. #ifdef WOLFSSL_AES_XTS
  740. { "-aes-xts", BENCH_AES_XTS },
  741. #endif
  742. #ifdef WOLFSSL_AES_CFB
  743. { "-aes-cfb", BENCH_AES_CFB },
  744. #endif
  745. #ifdef WOLFSSL_AES_OFB
  746. { "-aes-ofb", BENCH_AES_OFB },
  747. #endif
  748. #ifdef WOLFSSL_AES_COUNTER
  749. { "-aes-ctr", BENCH_AES_CTR },
  750. #endif
  751. #ifdef HAVE_AESCCM
  752. { "-aes-ccm", BENCH_AES_CCM },
  753. #endif
  754. #ifdef WOLFSSL_AES_SIV
  755. { "-aes-siv", BENCH_AES_SIV },
  756. #endif
  757. #ifdef HAVE_CAMELLIA
  758. { "-camellia", BENCH_CAMELLIA },
  759. #endif
  760. #ifndef NO_RC4
  761. { "-arc4", BENCH_ARC4 },
  762. #endif
  763. #ifdef HAVE_CHACHA
  764. { "-chacha20", BENCH_CHACHA20 },
  765. #endif
  766. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  767. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  768. #endif
  769. #ifdef WOLFSSL_SM4_CBC
  770. { "-sm4-cbc", BENCH_SM4_CBC },
  771. #endif
  772. #ifdef WOLFSSL_SM4_GCM
  773. { "-sm4-gcm", BENCH_SM4_GCM },
  774. #endif
  775. #ifdef WOLFSSL_SM4_CCM
  776. { "-sm4-ccm", BENCH_SM4_CCM },
  777. #endif
  778. #ifdef WOLFSSL_SM4
  779. { "-sm4", BENCH_SM4 },
  780. #endif
  781. #ifndef NO_DES3
  782. { "-des", BENCH_DES },
  783. #endif
  784. { NULL, 0 }
  785. };
  786. /* All recognized digest algorithm choosing command line options. */
  787. static const bench_alg bench_digest_opt[] = {
  788. { "-digest", 0xffffffff },
  789. #ifndef NO_MD5
  790. { "-md5", BENCH_MD5 },
  791. #endif
  792. #ifdef HAVE_POLY1305
  793. { "-poly1305", BENCH_POLY1305 },
  794. #endif
  795. #ifndef NO_SHA
  796. { "-sha", BENCH_SHA },
  797. #endif
  798. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  799. || defined(WOLFSSL_SHA512)
  800. { "-sha2", BENCH_SHA2 },
  801. #endif
  802. #ifdef WOLFSSL_SHA224
  803. { "-sha224", BENCH_SHA224 },
  804. #endif
  805. #ifndef NO_SHA256
  806. { "-sha256", BENCH_SHA256 },
  807. #endif
  808. #ifdef WOLFSSL_SHA384
  809. { "-sha384", BENCH_SHA384 },
  810. #endif
  811. #ifdef WOLFSSL_SHA512
  812. { "-sha512", BENCH_SHA512 },
  813. #endif
  814. #ifdef WOLFSSL_SHA3
  815. { "-sha3", BENCH_SHA3 },
  816. #ifndef WOLFSSL_NOSHA3_224
  817. { "-sha3-224", BENCH_SHA3_224 },
  818. #endif
  819. #ifndef WOLFSSL_NOSHA3_256
  820. { "-sha3-256", BENCH_SHA3_256 },
  821. #endif
  822. #ifndef WOLFSSL_NOSHA3_384
  823. { "-sha3-384", BENCH_SHA3_384 },
  824. #endif
  825. #ifndef WOLFSSL_NOSHA3_512
  826. { "-sha3-512", BENCH_SHA3_512 },
  827. #endif
  828. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  829. { "-shake", BENCH_SHAKE },
  830. #endif
  831. #ifdef WOLFSSL_SHAKE128
  832. { "-shake128", BENCH_SHAKE128 },
  833. #endif
  834. #ifdef WOLFSSL_SHAKE256
  835. { "-shake256", BENCH_SHAKE256 },
  836. #endif
  837. #endif
  838. #ifdef WOLFSSL_SM3
  839. { "-sm3", BENCH_SM3 },
  840. #endif
  841. #ifdef WOLFSSL_RIPEMD
  842. { "-ripemd", BENCH_RIPEMD },
  843. #endif
  844. #ifdef HAVE_BLAKE2
  845. { "-blake2b", BENCH_BLAKE2B },
  846. #endif
  847. #ifdef HAVE_BLAKE2S
  848. { "-blake2s", BENCH_BLAKE2S },
  849. #endif
  850. { NULL, 0 }
  851. };
  852. /* All recognized MAC algorithm choosing command line options. */
  853. static const bench_alg bench_mac_opt[] = {
  854. { "-mac", 0xffffffff },
  855. #ifdef WOLFSSL_CMAC
  856. { "-cmac", BENCH_CMAC },
  857. #endif
  858. #ifndef NO_HMAC
  859. { "-hmac", BENCH_HMAC },
  860. #ifndef NO_MD5
  861. { "-hmac-md5", BENCH_HMAC_MD5 },
  862. #endif
  863. #ifndef NO_SHA
  864. { "-hmac-sha", BENCH_HMAC_SHA },
  865. #endif
  866. #ifdef WOLFSSL_SHA224
  867. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  868. #endif
  869. #ifndef NO_SHA256
  870. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  871. #endif
  872. #ifdef WOLFSSL_SHA384
  873. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  874. #endif
  875. #ifdef WOLFSSL_SHA512
  876. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  877. #endif
  878. #ifndef NO_PWDBASED
  879. { "-pbkdf2", BENCH_PBKDF2 },
  880. #endif
  881. #endif
  882. #ifdef WOLFSSL_SIPHASH
  883. { "-siphash", BENCH_SIPHASH },
  884. #endif
  885. { NULL, 0 }
  886. };
  887. /* All recognized KDF algorithm choosing command line options. */
  888. static const bench_alg bench_kdf_opt[] = {
  889. { "-kdf", 0xffffffff },
  890. #ifdef WC_SRTP_KDF
  891. { "-srtp-kdf", BENCH_SRTP_KDF },
  892. #endif
  893. { NULL, 0 }
  894. };
  895. /* All recognized asymmetric algorithm choosing command line options. */
  896. static const bench_alg bench_asym_opt[] = {
  897. { "-asym", 0xffffffff },
  898. #ifndef NO_RSA
  899. #ifdef WOLFSSL_KEY_GEN
  900. { "-rsa-kg", BENCH_RSA_KEYGEN },
  901. #endif
  902. { "-rsa", BENCH_RSA },
  903. #ifdef WOLFSSL_KEY_GEN
  904. { "-rsa-sz", BENCH_RSA_SZ },
  905. #endif
  906. #endif
  907. #ifndef NO_DH
  908. { "-dh", BENCH_DH },
  909. #endif
  910. #ifdef HAVE_ECC
  911. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  912. { "-ecc", BENCH_ECC },
  913. #ifdef HAVE_ECC_ENCRYPT
  914. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  915. #endif
  916. { "-ecc-all", BENCH_ECC_ALL },
  917. #endif
  918. #ifdef WOLFSSL_SM2
  919. { "-sm2", BENCH_SM2 },
  920. #endif
  921. #ifdef HAVE_CURVE25519
  922. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  923. #ifdef HAVE_CURVE25519_SHARED_SECRET
  924. { "-x25519", BENCH_CURVE25519_KA },
  925. #endif
  926. #endif
  927. #ifdef HAVE_ED25519
  928. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  929. { "-ed25519", BENCH_ED25519_SIGN },
  930. #endif
  931. #ifdef HAVE_CURVE448
  932. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  933. #ifdef HAVE_CURVE448_SHARED_SECRET
  934. { "-x448", BENCH_CURVE448_KA },
  935. #endif
  936. #endif
  937. #ifdef HAVE_ED448
  938. { "-ed448-kg", BENCH_ED448_KEYGEN },
  939. { "-ed448", BENCH_ED448_SIGN },
  940. #endif
  941. #ifdef WOLFCRYPT_HAVE_ECCSI
  942. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  943. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  944. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  945. { "-eccsi", BENCH_ECCSI },
  946. #endif
  947. #ifdef WOLFCRYPT_HAVE_SAKKE
  948. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  949. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  950. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  951. { "-sakke", BENCH_SAKKE },
  952. #endif
  953. { NULL, 0 }
  954. };
  955. /* All recognized other cryptographic algorithm choosing command line options.
  956. */
  957. static const bench_alg bench_other_opt[] = {
  958. { "-other", 0xffffffff },
  959. #ifndef WC_NO_RNG
  960. { "-rng", BENCH_RNG },
  961. #endif
  962. #ifdef HAVE_SCRYPT
  963. { "-scrypt", BENCH_SCRYPT },
  964. #endif
  965. { NULL, 0}
  966. };
  967. #endif /* MAIN_NO_ARGS */
  968. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  969. #if defined(BENCH_PQ_STATEFUL_HBS)
  970. typedef struct bench_pq_hash_sig_alg {
  971. /* Command line option string. */
  972. const char* str;
  973. /* Bit values to set. */
  974. word32 val;
  975. } bench_pq_hash_sig_alg;
  976. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  977. { "-pq_hash_sig", 0xffffffff},
  978. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  979. { "-lms_hss", BENCH_LMS_HSS},
  980. #endif
  981. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  982. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  983. #ifdef WC_XMSS_SHA256
  984. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  985. #endif
  986. #ifdef WC_XMSS_SHA512
  987. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  988. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  989. #endif
  990. #endif
  991. #ifdef WC_XMSS_SHAKE128
  992. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  993. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  994. #endif
  995. #endif
  996. #ifdef WC_XMSS_SHAKE256
  997. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  998. #endif
  999. #endif
  1000. { NULL, 0}
  1001. };
  1002. #endif /* BENCH_PQ_STATEFUL_HBS */
  1003. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1004. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1005. /* The post-quantum-specific mapping of command line option to bit values and
  1006. * OQS name. */
  1007. typedef struct bench_pq_alg {
  1008. /* Command line option string. */
  1009. const char* str;
  1010. /* Bit values to set. */
  1011. word32 val;
  1012. } bench_pq_alg;
  1013. /* All recognized post-quantum asymmetric algorithm choosing command line
  1014. * options. */
  1015. static const bench_pq_alg bench_pq_asym_opt[] = {
  1016. { "-pq", 0xffffffff },
  1017. #ifdef WOLFSSL_HAVE_KYBER
  1018. { "-kyber", BENCH_KYBER },
  1019. { "-kyber512", BENCH_KYBER512 },
  1020. { "-kyber768", BENCH_KYBER768 },
  1021. { "-kyber1024", BENCH_KYBER1024 },
  1022. { "-ml-kem", BENCH_ML_KEM },
  1023. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1024. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1025. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1026. #endif
  1027. #if defined(HAVE_FALCON)
  1028. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1029. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1030. #endif
  1031. #if defined(HAVE_DILITHIUM)
  1032. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1033. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1034. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1035. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1036. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1037. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1038. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1039. #endif
  1040. { NULL, 0 }
  1041. };
  1042. #if defined(HAVE_SPHINCS)
  1043. /* All recognized post-quantum asymmetric algorithm choosing command line
  1044. * options. (Part 2) */
  1045. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1046. { "-pq", 0xffffffff },
  1047. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1048. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1049. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1050. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1051. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1052. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1053. { NULL, 0, }
  1054. };
  1055. #endif /* HAVE_SPHINCS */
  1056. #endif
  1057. #ifdef HAVE_WNR
  1058. const char* wnrConfigFile = "wnr-example.conf";
  1059. #endif
  1060. #if defined(WOLFSSL_MDK_ARM)
  1061. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1062. #define fopen wolfSSL_fopen
  1063. #endif
  1064. static int lng_index = 0;
  1065. #ifndef NO_MAIN_DRIVER
  1066. #ifndef MAIN_NO_ARGS
  1067. static const char* bench_Usage_msg1[][25] = {
  1068. /* 0 English */
  1069. { "-? <num> Help, print this usage\n",
  1070. " 0: English, 1: Japanese\n",
  1071. "-csv Print terminal output in csv format\n",
  1072. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1073. "-no_aad No additional authentication data passed.\n",
  1074. "-aad_size <num> With <num> bytes of AAD.\n",
  1075. ("-all_aad With AAD length of 0, "
  1076. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1077. " and\n"
  1078. " (if set via -aad_size) <aad_size> bytes.\n"
  1079. ),
  1080. "-dgst_full Full digest operation performed.\n",
  1081. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1082. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1083. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1084. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1085. "-p256 Measure ECC using P-256 curve.\n",
  1086. "-p384 Measure ECC using P-384 curve.\n",
  1087. "-p521 Measure ECC using P-521 curve.\n",
  1088. "-ecc-all Bench all enabled ECC curves.\n",
  1089. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1090. ("-lng <num> Display benchmark result by specified language.\n"
  1091. " 0: English, 1: Japanese\n"
  1092. ),
  1093. "<num> Size of block in bytes\n",
  1094. ("-blocks <num> Number of blocks. Can be used together with the "
  1095. "'Size of block'\n"
  1096. " option, but must be used after that one.\n"
  1097. ),
  1098. "-threads <num> Number of threads to run\n",
  1099. "-print Show benchmark stats summary\n",
  1100. "-hash_input <file> Input data to use for hash benchmarking\n",
  1101. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1102. "-min_runs <num> Specify minimum number of operation runs\n"
  1103. },
  1104. #ifndef NO_MULTIBYTE_PRINT
  1105. /* 1 Japanese */
  1106. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1107. " 0: 英語、 1: 日本語\n",
  1108. "-csv csv 形式で端末に出力します。\n",
  1109. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1110. "-no_aad 追加の認証データを使用しません.\n",
  1111. "-aad_size <num> TBD.\n",
  1112. "-all_aad TBD.\n",
  1113. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1114. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1115. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1116. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1117. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1118. "-p256 Measure ECC using P-256 curve.\n",
  1119. "-p384 Measure ECC using P-384 curve.\n",
  1120. "-p521 Measure ECC using P-521 curve.\n",
  1121. "-ecc-all Bench all enabled ECC curves.\n",
  1122. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1123. " 利用可能なアルゴリズムは下記を含みます:\n"
  1124. ),
  1125. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1126. " 0: 英語、 1: 日本語\n"
  1127. ),
  1128. "<num> ブロックサイズをバイト単位で指定します。\n",
  1129. "-blocks <num> TBD.\n",
  1130. "-threads <num> 実行するスレッド数\n",
  1131. "-print ベンチマーク統計の要約を表示する\n",
  1132. /* TODO: translate below */
  1133. "-hash_input <file> Input data to use for hash benchmarking\n",
  1134. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1135. "-min_runs <num> Specify minimum number of operation runs\n"
  1136. },
  1137. #endif
  1138. };
  1139. #endif /* MAIN_NO_ARGS */
  1140. #endif
  1141. static const char* bench_result_words1[][4] = {
  1142. { "took",
  1143. #ifdef BENCH_MICROSECOND
  1144. "microseconds"
  1145. #else
  1146. "seconds"
  1147. #endif
  1148. , "Cycles per byte", NULL }, /* 0 English */
  1149. #ifndef NO_MULTIBYTE_PRINT
  1150. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1151. #endif
  1152. };
  1153. #if !defined(NO_RSA) || \
  1154. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1155. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1156. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1157. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1158. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1159. static const char* bench_desc_words[][15] = {
  1160. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1161. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1162. #ifndef NO_MULTIBYTE_PRINT
  1163. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1164. #endif
  1165. };
  1166. #endif
  1167. #ifdef MULTI_VALUE_STATISTICS
  1168. static const char* bench_result_words3[][5] = {
  1169. /* 0 English */
  1170. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1171. /* TODO: Add japenese version */
  1172. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1173. };
  1174. #endif
  1175. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1176. #define HAVE_GET_CYCLES
  1177. static WC_INLINE word64 get_intel_cycles(void);
  1178. static THREAD_LS_T word64 total_cycles;
  1179. #define INIT_CYCLE_COUNTER
  1180. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1181. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1182. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1183. #define SHOW_INTEL_CYCLES(b, n, s) \
  1184. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1185. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1186. bench_result_words1[lng_index][2], \
  1187. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1188. (double)total_cycles / ((word64)count*(s))))
  1189. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1190. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1191. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1192. (double)total_cycles / ((word64)count*(s))))
  1193. #elif defined(LINUX_CYCLE_COUNT)
  1194. #include <linux/perf_event.h>
  1195. #include <sys/syscall.h>
  1196. #include <unistd.h>
  1197. static THREAD_LS_T word64 begin_cycles;
  1198. static THREAD_LS_T word64 total_cycles;
  1199. static THREAD_LS_T int cycles = -1;
  1200. static THREAD_LS_T struct perf_event_attr atr;
  1201. #define INIT_CYCLE_COUNTER do { \
  1202. atr.type = PERF_TYPE_HARDWARE; \
  1203. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1204. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1205. } while (0);
  1206. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1207. #define END_INTEL_CYCLES do { \
  1208. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1209. total_cycles = total_cycles - begin_cycles; \
  1210. } while (0);
  1211. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1212. #define SHOW_INTEL_CYCLES(b, n, s) \
  1213. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1214. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1215. bench_result_words1[lng_index][2], \
  1216. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1217. (count*s)))
  1218. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1219. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1220. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1221. / (count*s)))
  1222. #elif defined(SYNERGY_CYCLE_COUNT)
  1223. #include "hal_data.h"
  1224. static THREAD_LS_T word64 begin_cycles;
  1225. static THREAD_LS_T word64 total_cycles;
  1226. #define INIT_CYCLE_COUNTER
  1227. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1228. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1229. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1230. #define SHOW_INTEL_CYCLES(b, n, s) \
  1231. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1232. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1233. bench_result_words1[lng_index][2], \
  1234. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1235. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1236. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1237. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1238. #elif defined(WOLFSSL_ESPIDF)
  1239. /* TAG for ESP_LOGx() */
  1240. static const char* TAG = "wolfssl_benchmark";
  1241. static THREAD_LS_T word64 begin_cycles = 0;
  1242. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1243. static THREAD_LS_T word64 end_cycles = 0;
  1244. static THREAD_LS_T word64 total_cycles = 0;
  1245. /* the return value, as a global var */
  1246. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1247. /* the last value seen, adjusted for an overflow, as a global var */
  1248. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1249. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1250. /* esp_get_cpu_benchmark_cycles(void):
  1251. *
  1252. * Architecture-independant CPU clock counter.
  1253. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1254. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1255. /* Some vars for debugging, compare ticks to cycles */
  1256. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1257. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1258. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1259. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1260. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1261. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1262. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1263. #if ESP_IDF_VERSION_MAJOR >= 5
  1264. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1265. #define HAVE_GET_CYCLES
  1266. #define INIT_CYCLE_COUNTER do { \
  1267. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1268. esp_cpu_set_cycle_count(0); \
  1269. } while (0);
  1270. #else
  1271. #define HAVE_GET_CYCLES
  1272. #define INIT_CYCLE_COUNTER do { \
  1273. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1274. } while (0);
  1275. #endif
  1276. #define BEGIN_ESP_CYCLES do { \
  1277. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1278. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1279. begin_cycles_ticks = xTaskGetTickCount(); \
  1280. } while (0);
  1281. /* since it rolls over, we have something that will tolerate one */
  1282. #define END_ESP_CYCLES \
  1283. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1284. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1285. end_cycles, \
  1286. begin_cycles \
  1287. ); \
  1288. total_cycles = (end_cycles - begin_cycles);
  1289. #define SHOW_ESP_CYCLES(b, n, s) \
  1290. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1291. " %s = " FLT_FMT_PREC2 "\n", \
  1292. bench_result_words1[lng_index][2], \
  1293. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1294. )
  1295. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1296. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1297. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1298. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1299. /* 64 bit, unisgned, absolute difference
  1300. * used in CPU cycle counter debug calcs. */
  1301. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1302. {
  1303. uint64_t ret;
  1304. ret = (x > y) ? (x - y) : (y - x);
  1305. return ret;
  1306. }
  1307. #endif
  1308. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1309. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1310. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1311. ** at least once during full benchmark tests.
  1312. **
  1313. ** To test timing overflow, add a delay longer than max cycles:
  1314. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1315. */
  1316. uint64_t esp_get_cycle_count_ex()
  1317. {
  1318. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1319. /* unsigned int max = 4,294,967,295 */
  1320. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1321. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1322. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1323. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1324. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1325. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1326. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1327. #endif
  1328. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1329. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1330. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1331. * (current - last) */
  1332. #endif
  1333. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1334. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1335. defined(CONFIG_IDF_TARGET_ESP32C6)
  1336. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1337. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1338. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1339. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1340. thisVal = esp_cpu_get_cycle_count();
  1341. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1342. thisVal = esp_cpu_get_cycle_count();
  1343. #else
  1344. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1345. * Calling current_time(1) to reset time causes thisVal overflow,
  1346. * on Xtensa, but not on RISC-V architecture. See also, below */
  1347. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1348. #ifndef configCPU_CLOCK_HZ
  1349. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1350. #define configCPU_CLOCK_HZ \
  1351. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1352. #endif
  1353. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1354. thisVal = (uint64_t)xTaskGetTickCount() *
  1355. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1356. #elif defined(__XTENSA__)
  1357. thisVal = esp_cpu_get_cycle_count();
  1358. #else
  1359. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1360. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1361. #endif
  1362. #endif
  1363. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1364. {
  1365. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1366. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1367. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1368. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1369. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1370. ESP_LOGV(TAG, "last_tickCount = %u", last_tickCount);
  1371. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1372. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1373. }
  1374. #endif
  1375. /* If either thisVal is smaller than last (overflow), and/or the
  1376. * expected value calculated from FreeRTOS tick difference that would
  1377. * have never fit into an unsigned 32 bit integer anyhow... then we
  1378. * need to adjust thisVal to save. */
  1379. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1380. {
  1381. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1382. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1383. **
  1384. ** NOTE for long duration between calls with multiple overflows:
  1385. **
  1386. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1387. **
  1388. ** At this time no single test overflows. This is currently only a
  1389. ** concern for cumulative counts over multiple tests. As long
  1390. ** as well call xthal_get_ccount_ex() with no more than one
  1391. ** overflow CPU tick count, all will be well.
  1392. */
  1393. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1394. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1395. "(%llu < %llu) adding UINT_MAX = %llu.",
  1396. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1397. #endif
  1398. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1399. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1400. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1401. #endif
  1402. /* double check expected diff calc */
  1403. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1404. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1405. * tickDiff / configTICK_RATE_HZ;
  1406. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1407. #endif
  1408. if (expected_diff > UINT_MAX) {
  1409. /* The number of cycles expected from FreeRTOS ticks is
  1410. * greater than the maximum size of an unsigned 32-bit
  1411. * integer, meaning multiple overflows occurred. */
  1412. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1413. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1414. #endif
  1415. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1416. }
  1417. else {
  1418. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1419. }
  1420. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1421. {
  1422. tickBeginDiff = tickCount - begin_cycles_ticks;
  1423. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1424. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1425. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1426. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1427. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1428. }
  1429. #endif
  1430. }
  1431. else {
  1432. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1433. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1434. #endif
  1435. } /* if thisVal adjustment check */
  1436. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1437. if (thisTimerVal < _esp_cpu_timer_last)
  1438. {
  1439. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1440. "adding %ull", UINT_MAX);
  1441. thisTimerVal += (word64)UINT_MAX;
  1442. }
  1443. /* Check an alternate counter using a timer */
  1444. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1445. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1446. /* Adjust our actual returned value that takes into account overflow,
  1447. * increment 64 bit extended total by this 32 bit differential: */
  1448. thisIncrement = (thisVal - _esp_cpu_count_last);
  1449. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1450. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1451. #endif
  1452. /* Add our adjustment, taking into account overflows (see above) */
  1453. _esp_get_cycle_count_ex += thisIncrement;
  1454. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1455. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1456. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1457. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1458. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1459. /* all of this took some time, so reset the "last seen" value
  1460. * for the next measurement. */
  1461. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1462. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1463. defined(CONFIG_IDF_TARGET_ESP32C6)
  1464. {
  1465. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1466. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1467. &_esp_cpu_timer_last));
  1468. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1469. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1470. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1471. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1472. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1473. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1474. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1475. }
  1476. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1477. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1478. #else
  1479. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1480. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1481. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1482. * or thisVal = xthal_get_ccount(); */
  1483. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1484. /* There's no CPU counter on the ESP8266, so we'll estimate
  1485. * cycles based on defined CPU frequency from sdkconfig and
  1486. * the RTOS tick frequency */
  1487. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1488. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1489. #elif ESP_IDF_VERSION_MAJOR < 5
  1490. _esp_cpu_count_last = xthal_get_ccount();
  1491. #else
  1492. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1493. #endif
  1494. #endif
  1495. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1496. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1497. #endif
  1498. /* Return the 64 bit extended total from 32 bit counter. */
  1499. return _esp_get_cycle_count_ex;
  1500. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1501. /* implement other architecture cycle counters here */
  1502. #else
  1503. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1504. #undef HAVE_GET_CYCLES
  1505. #define INIT_CYCLE_COUNTER
  1506. #define BEGIN_INTEL_CYCLES
  1507. #define END_INTEL_CYCLES
  1508. #ifdef MULTI_VALUE_STATISTICS
  1509. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1510. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1511. #else
  1512. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1513. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1514. #endif
  1515. #endif
  1516. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1517. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1518. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1519. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1520. #endif
  1521. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1522. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1523. !defined(NO_DH)
  1524. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1525. #include <wolfssl/certs_test.h>
  1526. #endif
  1527. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1528. #include <wolfssl/wolfcrypt/blake2.h>
  1529. #endif
  1530. #ifdef _MSC_VER
  1531. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1532. #pragma warning(disable: 4996)
  1533. #endif
  1534. #ifdef WOLFSSL_CURRTIME_REMAP
  1535. #define current_time WOLFSSL_CURRTIME_REMAP
  1536. #else
  1537. double current_time(int reset);
  1538. #endif
  1539. #ifdef LINUX_RUSAGE_UTIME
  1540. static void check_for_excessive_stime(const char *desc,
  1541. const char *desc_extra);
  1542. #endif
  1543. #if !defined(WC_NO_RNG) && \
  1544. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1545. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1546. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1547. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1548. || defined(WOLFSSL_HAVE_KYBER))
  1549. #define HAVE_LOCAL_RNG
  1550. static THREAD_LS_T WC_RNG gRng;
  1551. #define GLOBAL_RNG &gRng
  1552. #else
  1553. #define GLOBAL_RNG NULL
  1554. #endif
  1555. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1556. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1557. defined(HAVE_ECC) || !defined(NO_DH) || \
  1558. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1559. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1560. #define BENCH_ASYM
  1561. #endif
  1562. #if defined(BENCH_ASYM)
  1563. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1564. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1565. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1566. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1567. static const char* bench_result_words2[][5] = {
  1568. #ifdef BENCH_MICROSECOND
  1569. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1570. for μsec */
  1571. #else
  1572. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1573. #endif
  1574. #ifndef NO_MULTIBYTE_PRINT
  1575. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1576. #endif
  1577. };
  1578. #endif
  1579. #endif
  1580. #ifdef WOLFSSL_CAAM
  1581. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1582. #ifdef WOLFSSL_SECO_CAAM
  1583. #define SECO_MAX_UPDATES 10000
  1584. #define SECO_BENCHMARK_NONCE 0x7777
  1585. #define SECO_KEY_STORE_ID 1
  1586. #endif
  1587. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1588. #else
  1589. #ifdef WC_USE_DEVID
  1590. static THREAD_LS_T int devId = WC_USE_DEVID;
  1591. #else
  1592. static THREAD_LS_T int devId = INVALID_DEVID;
  1593. #endif
  1594. #endif
  1595. /* Asynchronous helper macros */
  1596. #ifdef WC_ENABLE_BENCH_THREADING
  1597. typedef struct ThreadData {
  1598. pthread_t thread_id;
  1599. } ThreadData;
  1600. static ThreadData* g_threadData;
  1601. static volatile int g_threadCount;
  1602. #endif
  1603. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1604. #ifndef NO_HW_BENCH
  1605. #define BENCH_DEVID
  1606. #endif
  1607. #ifndef HAVE_RENESAS_SYNC
  1608. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1609. #else
  1610. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1611. #endif
  1612. #else
  1613. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1614. #endif
  1615. #ifdef WOLFSSL_ASYNC_CRYPT
  1616. static WOLF_EVENT_QUEUE eventQueue;
  1617. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1618. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1619. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1620. int callAgain, int* times, int limit, int* pending)
  1621. {
  1622. int allowNext = 0;
  1623. /* this state can be set from a different thread */
  1624. WOLF_EVENT_STATE state = asyncDev->event.state;
  1625. /* if algo doesn't require calling again then use this flow */
  1626. if (state == WOLF_EVENT_STATE_DONE) {
  1627. if (callAgain) {
  1628. /* needs called again, so allow it and handle completion in
  1629. * bench_async_handle */
  1630. allowNext = 1;
  1631. }
  1632. else {
  1633. *ret = asyncDev->event.ret;
  1634. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1635. (*times)++;
  1636. if (*pending > 0) /* to support case where async blocks */
  1637. (*pending)--;
  1638. if ((*times + *pending) < limit)
  1639. allowNext = 1;
  1640. }
  1641. }
  1642. /* if slot is available and we haven't reached limit, start another */
  1643. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1644. allowNext = 1;
  1645. }
  1646. return allowNext;
  1647. }
  1648. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1649. int callAgain, int* times, int* pending)
  1650. {
  1651. WOLF_EVENT_STATE state = asyncDev->event.state;
  1652. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1653. if (state == WOLF_EVENT_STATE_DONE) {
  1654. *ret = asyncDev->event.ret;
  1655. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1656. (*times)++;
  1657. (*pending)--;
  1658. }
  1659. else {
  1660. (*pending)++;
  1661. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1662. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1663. }
  1664. }
  1665. else if (*ret >= 0) {
  1666. *ret = asyncDev->event.ret;
  1667. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1668. (*times)++;
  1669. if (*pending > 0) /* to support case where async blocks */
  1670. (*pending)--;
  1671. }
  1672. return (*ret >= 0) ? 1 : 0;
  1673. }
  1674. static WC_INLINE int bench_async_poll(int* pending)
  1675. {
  1676. int ret, asyncDone = 0;
  1677. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1678. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1679. if (ret != 0) {
  1680. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1681. return ret;
  1682. }
  1683. if (asyncDone == 0) {
  1684. #ifndef WC_NO_ASYNC_THREADING
  1685. /* give time to other threads */
  1686. wc_AsyncThreadYield();
  1687. #endif
  1688. }
  1689. (void)pending;
  1690. return asyncDone;
  1691. }
  1692. #else
  1693. #define BENCH_MAX_PENDING 1
  1694. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1695. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1696. int callAgain, int* times, int limit, int* pending)
  1697. {
  1698. (void)ret;
  1699. (void)asyncDev;
  1700. (void)callAgain;
  1701. (void)times;
  1702. (void)limit;
  1703. (void)pending;
  1704. return 1;
  1705. }
  1706. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1707. int callAgain, int* times, int* pending)
  1708. {
  1709. (void)asyncDev;
  1710. (void)callAgain;
  1711. (void)pending;
  1712. if (*ret >= 0) {
  1713. /* operation completed */
  1714. (*times)++;
  1715. return 1;
  1716. }
  1717. return 0;
  1718. }
  1719. #define bench_async_poll(p) WC_DO_NOTHING
  1720. #endif /* WOLFSSL_ASYNC_CRYPT */
  1721. /* maximum runtime for each benchmark */
  1722. #ifndef BENCH_MIN_RUNTIME_SEC
  1723. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1724. #endif
  1725. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1726. #define AES_AUTH_TAG_SZ 16
  1727. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1728. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1729. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1730. #if !defined(NO_MAIN_DRIVER)
  1731. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1732. #else
  1733. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1734. #endif
  1735. #endif
  1736. #define AES_AAD_STRING(s) \
  1737. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1738. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1739. enum en_aad_options {
  1740. AAD_SIZE_DEFAULT = 0x1U,
  1741. AAD_SIZE_ZERO = 0x2U,
  1742. AAD_SIZE_CUSTOM = 0x4U,
  1743. };
  1744. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1745. static word32 aes_aad_size = 0;
  1746. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1747. {
  1748. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1749. word32 options = aes_aad_options;
  1750. while(options) {
  1751. if (options & AAD_SIZE_DEFAULT) {
  1752. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1753. options &= ~(word32)AAD_SIZE_DEFAULT;
  1754. }
  1755. else if (options & AAD_SIZE_ZERO) {
  1756. aesAuthAddSz = 0;
  1757. options &= ~(word32)AAD_SIZE_ZERO;
  1758. }
  1759. else if (options & AAD_SIZE_CUSTOM) {
  1760. aesAuthAddSz = aes_aad_size;
  1761. options &= ~(word32)AAD_SIZE_CUSTOM;
  1762. }
  1763. fn(i);
  1764. aesAuthAddSz = aesAuthAddSz_orig;
  1765. }
  1766. }
  1767. #endif
  1768. #ifndef BENCH_CIPHER_ADD
  1769. #define BENCH_CIPHER_ADD 0
  1770. #endif
  1771. /* use kB instead of mB for embedded benchmarking */
  1772. #ifdef BENCH_EMBEDDED
  1773. #ifndef BENCH_NTIMES
  1774. #define BENCH_NTIMES 2
  1775. #endif
  1776. #ifndef BENCH_AGREETIMES
  1777. #define BENCH_AGREETIMES 2
  1778. #endif
  1779. enum BenchmarkBounds {
  1780. scryptCnt = 1,
  1781. ntimes = BENCH_NTIMES,
  1782. genTimes = BENCH_MAX_PENDING,
  1783. agreeTimes = BENCH_AGREETIMES
  1784. };
  1785. /* how many kB to test (en/de)cryption */
  1786. #define NUM_BLOCKS 25
  1787. #define BENCH_SIZE (1024uL)
  1788. #else
  1789. #ifndef BENCH_NTIMES
  1790. #define BENCH_NTIMES 100
  1791. #endif
  1792. #ifndef BENCH_AGREETIMES
  1793. #define BENCH_AGREETIMES 100
  1794. #endif
  1795. enum BenchmarkBounds {
  1796. scryptCnt = 10,
  1797. ntimes = BENCH_NTIMES,
  1798. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1799. agreeTimes = BENCH_AGREETIMES
  1800. };
  1801. /* how many megs to test (en/de)cryption */
  1802. #define NUM_BLOCKS 5
  1803. #define BENCH_SIZE (1024*1024uL)
  1804. #endif
  1805. static int numBlocks = NUM_BLOCKS;
  1806. static word32 bench_size = BENCH_SIZE;
  1807. static int base2 = 1;
  1808. static int digest_stream = 1;
  1809. #ifdef HAVE_CHACHA
  1810. static int encrypt_only = 0;
  1811. #endif
  1812. #ifdef HAVE_AES_CBC
  1813. static int cipher_same_buffer = 0;
  1814. #endif
  1815. #ifdef MULTI_VALUE_STATISTICS
  1816. static int minimum_runs = 0;
  1817. #endif
  1818. #ifndef NO_RSA
  1819. /* Don't measure RSA sign/verify by default */
  1820. static int rsa_sign_verify = 0;
  1821. #endif
  1822. #ifndef NO_DH
  1823. /* Use the FFDHE parameters */
  1824. static int use_ffdhe = 0;
  1825. #endif
  1826. /* Don't print out in CSV format by default */
  1827. static int csv_format = 0;
  1828. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1829. /* Versal PLM maybe prints an error message to the same console.
  1830. * In order to not mix those outputs up, sleep a little while
  1831. * before erroring out.
  1832. */
  1833. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1834. #else
  1835. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1836. #endif
  1837. /* globals for cipher tests */
  1838. static THREAD_LS_T byte* bench_plain = NULL;
  1839. static THREAD_LS_T byte* bench_cipher = NULL;
  1840. #ifndef NO_FILESYSTEM
  1841. static THREAD_LS_T char* hash_input = NULL;
  1842. static THREAD_LS_T char* cipher_input = NULL;
  1843. #endif
  1844. static const XGEN_ALIGN byte bench_key_buf[] =
  1845. {
  1846. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1847. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1848. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1849. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1850. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1851. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1852. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1853. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1854. };
  1855. static const XGEN_ALIGN byte bench_iv_buf[] =
  1856. {
  1857. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1858. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1859. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1860. };
  1861. static THREAD_LS_T byte* bench_key = NULL;
  1862. static THREAD_LS_T byte* bench_iv = NULL;
  1863. #ifdef HAVE_RENESAS_SYNC
  1864. static THREAD_LS_T byte* bench_key1 = NULL;
  1865. static THREAD_LS_T byte* bench_key2 = NULL;
  1866. #endif
  1867. #ifdef WOLFSSL_STATIC_MEMORY
  1868. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1869. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1870. #elif defined(BENCH_EMBEDDED)
  1871. static byte gBenchMemory[50000];
  1872. #else
  1873. static byte gBenchMemory[400000];
  1874. #endif
  1875. #endif
  1876. /* This code handles cases with systems where static (non cost) ram variables
  1877. aren't properly initialized with data */
  1878. static void benchmark_static_init(int force)
  1879. {
  1880. static int gBenchStaticInit = 0;
  1881. if (gBenchStaticInit == 0 || force) {
  1882. gBenchStaticInit = 1;
  1883. /* Init static variables */
  1884. numBlocks = NUM_BLOCKS;
  1885. bench_size = BENCH_SIZE;
  1886. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1887. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1888. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1889. aes_aad_size = 0;
  1890. #endif
  1891. base2 = 1;
  1892. digest_stream = 1;
  1893. #ifdef MULTI_VALUE_STATISTICS
  1894. minimum_runs = 0;
  1895. #endif
  1896. bench_all = 1;
  1897. bench_cipher_algs = 0;
  1898. bench_digest_algs = 0;
  1899. bench_mac_algs = 0;
  1900. bench_kdf_algs = 0;
  1901. bench_asym_algs = 0;
  1902. bench_pq_asym_algs = 0;
  1903. bench_other_algs = 0;
  1904. bench_pq_hash_sig_algs = 0;
  1905. csv_format = 0;
  1906. }
  1907. }
  1908. /*****************************************************************************/
  1909. /* Begin Stats Functions */
  1910. /*****************************************************************************/
  1911. typedef enum bench_stat_type {
  1912. BENCH_STAT_ASYM,
  1913. BENCH_STAT_SYM,
  1914. BENCH_STAT_IGNORE,
  1915. } bench_stat_type_t;
  1916. #ifdef WC_BENCH_TRACK_STATS
  1917. static int gPrintStats = 0;
  1918. #ifdef WC_ENABLE_BENCH_THREADING
  1919. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1920. #endif
  1921. #ifndef BENCH_MAX_NAME_SZ
  1922. #define BENCH_MAX_NAME_SZ 24
  1923. #endif
  1924. typedef struct bench_stats {
  1925. struct bench_stats* next;
  1926. struct bench_stats* prev;
  1927. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1928. const char* desc;
  1929. double perfsec;
  1930. int strength;
  1931. int useDeviceID;
  1932. int finishCount;
  1933. bench_stat_type_t type;
  1934. int lastRet;
  1935. const char* perftype;
  1936. } bench_stats_t;
  1937. static bench_stats_t* bench_stats_head;
  1938. static bench_stats_t* bench_stats_tail;
  1939. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1940. const char* algo, int strength, const char* desc, int useDeviceID,
  1941. double perfsec, const char* perftype, int ret)
  1942. {
  1943. bench_stats_t* bstat = NULL;
  1944. #ifdef WC_ENABLE_BENCH_THREADING
  1945. /* protect bench_stats_head and bench_stats_tail access */
  1946. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  1947. #endif
  1948. if (algo != NULL) {
  1949. /* locate existing in list */
  1950. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  1951. /* match based on algo, strength and desc */
  1952. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  1953. bstat->strength == strength &&
  1954. bstat->desc == desc &&
  1955. bstat->useDeviceID == useDeviceID) {
  1956. break;
  1957. }
  1958. }
  1959. }
  1960. if (bstat == NULL) {
  1961. /* allocate new and put on list */
  1962. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  1963. DYNAMIC_TYPE_INFO);
  1964. if (bstat) {
  1965. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  1966. /* add to list */
  1967. bstat->next = NULL;
  1968. if (bench_stats_tail == NULL) {
  1969. bench_stats_head = bstat;
  1970. }
  1971. else {
  1972. bench_stats_tail->next = bstat;
  1973. bstat->prev = bench_stats_tail;
  1974. }
  1975. bench_stats_tail = bstat; /* add to the end either way */
  1976. }
  1977. }
  1978. if (bstat) {
  1979. bstat->type = type;
  1980. if (algo != NULL)
  1981. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  1982. bstat->strength = strength;
  1983. bstat->desc = desc;
  1984. bstat->useDeviceID = useDeviceID;
  1985. bstat->perfsec += perfsec;
  1986. bstat->finishCount++;
  1987. bstat->perftype = perftype;
  1988. if (bstat->lastRet > ret)
  1989. bstat->lastRet = ret; /* track last error */
  1990. }
  1991. #ifdef WC_ENABLE_BENCH_THREADING
  1992. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  1993. #endif
  1994. return bstat;
  1995. }
  1996. void bench_stats_print(void)
  1997. {
  1998. bench_stats_t* bstat;
  1999. int digits;
  2000. #ifdef WC_ENABLE_BENCH_THREADING
  2001. /* protect bench_stats_head and bench_stats_tail access */
  2002. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2003. #endif
  2004. #ifdef BENCH_MICROSECOND
  2005. digits = 5;
  2006. #else
  2007. digits = 3;
  2008. #endif
  2009. for (bstat = bench_stats_head; bstat != NULL; ) {
  2010. if (bstat->type == BENCH_STAT_SYM) {
  2011. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2012. "\n", bstat->desc,
  2013. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2014. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2015. base2 ? "MB" : "mB");
  2016. }
  2017. else {
  2018. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2019. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2020. bstat->algo, bstat->strength, bstat->desc,
  2021. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2022. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2023. }
  2024. bstat = bstat->next;
  2025. }
  2026. #ifdef WC_ENABLE_BENCH_THREADING
  2027. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2028. #endif
  2029. }
  2030. #endif /* WC_BENCH_TRACK_STATS */
  2031. static WC_INLINE void bench_stats_init(void)
  2032. {
  2033. #ifdef WC_BENCH_TRACK_STATS
  2034. bench_stats_head = NULL;
  2035. bench_stats_tail = NULL;
  2036. #endif
  2037. INIT_CYCLE_COUNTER
  2038. }
  2039. static WC_INLINE void bench_stats_start(int* count, double* start)
  2040. {
  2041. *count = 0;
  2042. *start = current_time(1);
  2043. #ifdef WOLFSSL_ESPIDF
  2044. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2045. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu, start=" FLT_FMT,
  2046. total_cycles, FLT_FMT_ARGS(*start) );
  2047. #endif
  2048. BEGIN_ESP_CYCLES
  2049. #else
  2050. BEGIN_INTEL_CYCLES
  2051. #endif
  2052. }
  2053. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2054. #define bench_stats_start(count, start) do { \
  2055. SAVE_VECTOR_REGISTERS(pr_err( \
  2056. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2057. return; ); \
  2058. bench_stats_start(count, start); \
  2059. } while (0)
  2060. #endif
  2061. static WC_INLINE int bench_stats_check(double start)
  2062. {
  2063. int ret = 0;
  2064. double this_current_time;
  2065. this_current_time = current_time(0); /* get the timestamp, no reset */
  2066. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2067. ESP_LOGV(TAG, "bench_stats_check: Current time %f, start %f",
  2068. this_current_time, start );
  2069. #endif
  2070. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2071. #ifdef BENCH_MICROSECOND
  2072. * 1000000
  2073. #endif
  2074. );
  2075. return ret;
  2076. }
  2077. /* return text for units and scale the value of blocks as needed */
  2078. static const char* get_blocktype(double* blocks)
  2079. {
  2080. const char* rt;
  2081. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2082. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2083. #undef WOLFSSL_FIXED_UNIT
  2084. #define WOLFSSL_FIXED_UNIT "GB"
  2085. *blocks /= (1024UL * 1024UL * 1024UL);
  2086. rt = "GiB";
  2087. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2088. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2089. #undef WOLFSSL_FIXED_UNIT
  2090. #define WOLFSSL_FIXED_UNIT "MB"
  2091. *blocks /= (1024UL * 1024UL);
  2092. rt = "MiB";
  2093. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2094. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2095. #undef WOLFSSL_FIXED_UNIT
  2096. #define WOLFSSL_FIXED_UNIT "KB"
  2097. *blocks /= 1024;
  2098. rt = "KiB";
  2099. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2100. #undef WOLFSSL_FIXED_UNIT
  2101. #define WOLFSSL_FIXED_UNIT "bytes"
  2102. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2103. rt = "bytes";
  2104. #else
  2105. /* If no user-specified, auto-scale each metric (results vary).
  2106. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2107. if (*blocks > (1024UL * 1024UL)) {
  2108. *blocks /= (1024UL * 1024UL);
  2109. rt = "MiB";
  2110. }
  2111. else if (*blocks > 1024) {
  2112. *blocks /= 1024;
  2113. rt = "KiB";
  2114. }
  2115. else {
  2116. rt = "bytes";
  2117. }
  2118. #endif
  2119. return rt;
  2120. }
  2121. /* return text for units and scale the value of blocks as needed for base2 */
  2122. static const char* get_blocktype_base10(double* blocks)
  2123. {
  2124. const char* rt;
  2125. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2126. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2127. *blocks /= (1000UL * 1000UL * 1000UL);
  2128. rt = "GB";
  2129. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2130. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2131. *blocks /= (1000UL * 1000UL);
  2132. rt = "MB";
  2133. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2134. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2135. *blocks /= (1000UL);
  2136. rt = "KB";
  2137. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2138. (void)(*blocks); /* no adjustment, just appease compiler */
  2139. rt = "bytes";
  2140. #else
  2141. /* If not user-specified, auto-scale each metric (results vary).
  2142. * Determine if we should show as KB or MB or bytes */
  2143. if (*blocks > (1000UL * 1000UL)) {
  2144. *blocks /= (1000UL * 1000UL);
  2145. rt = "MB";
  2146. }
  2147. else if (*blocks > 1000) {
  2148. *blocks /= 1000; /* make KB */
  2149. rt = "KB";
  2150. }
  2151. else {
  2152. rt = "bytes";
  2153. }
  2154. #endif
  2155. return rt;
  2156. }
  2157. #ifdef MULTI_VALUE_STATISTICS
  2158. static double wc_sqroot(double in)
  2159. {
  2160. /* do 32 iterations for the sqroot */
  2161. int iter = 32;
  2162. double root = in/3.0;
  2163. if (in < 0.0)
  2164. return -1;
  2165. for (int i=0; i < iter; i++)
  2166. root = (root + in / root) / 2.0;
  2167. return root;
  2168. }
  2169. static void bench_multi_value_stats(double max, double min, double sum,
  2170. double squareSum, int runs)
  2171. {
  2172. double mean = 0;
  2173. double sd = 0;
  2174. char msg[WC_BENCH_MAX_LINE_LEN];
  2175. const char** word = bench_result_words3[lng_index];
  2176. XMEMSET(msg, 0, sizeof(msg));
  2177. mean = sum / runs;
  2178. /* Calculating standard deviation */
  2179. sd = (squareSum / runs) - (mean * mean);
  2180. sd = wc_sqroot(sd);
  2181. if (csv_format == 1) {
  2182. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2183. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2184. FLT_FMT_PREC2_ARGS(3, 3, max),
  2185. FLT_FMT_PREC2_ARGS(3, 3, min),
  2186. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2187. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2188. }
  2189. else{
  2190. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2191. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2192. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2193. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2194. WOLFSSL_FIXED_TIME_UNIT "\n",
  2195. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2196. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2197. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2198. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2199. }
  2200. printf("%s", msg);
  2201. #ifndef WOLFSSL_SGX
  2202. XFFLUSH(stdout);
  2203. #endif
  2204. }
  2205. #endif
  2206. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2207. * except for AES direct that operates on AES_BLOCK_SIZE blocks */
  2208. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2209. int count, word32 countSz,
  2210. double start, int ret)
  2211. {
  2212. double total, persec = 0, blocks = (double)count;
  2213. const char* blockType;
  2214. char msg[WC_BENCH_MAX_LINE_LEN];
  2215. const char** word = bench_result_words1[lng_index];
  2216. static int sym_header_printed = 0;
  2217. XMEMSET(msg, 0, sizeof(msg));
  2218. #ifdef WOLFSSL_ESPIDF
  2219. END_ESP_CYCLES
  2220. #else
  2221. END_INTEL_CYCLES
  2222. #endif
  2223. total = current_time(0) - start;
  2224. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2225. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2226. #endif
  2227. #ifdef LINUX_RUSAGE_UTIME
  2228. check_for_excessive_stime(desc, "");
  2229. #endif
  2230. /* calculate actual bytes */
  2231. blocks *= countSz;
  2232. if (csv_format == 1) {
  2233. /* only print out header once */
  2234. if (sym_header_printed == 0) {
  2235. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2236. /* machine parseable CSV */
  2237. #ifdef HAVE_GET_CYCLES
  2238. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2239. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2240. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2241. ",cycles_total,Cycles per byte,");
  2242. #else
  2243. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2244. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2245. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2246. ",cycles_total,");
  2247. #endif
  2248. #else
  2249. /* normal CSV */
  2250. #ifdef BENCH_DEVID
  2251. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2252. #else
  2253. #define BENCH_DEVID_COLUMN_HEADER
  2254. #endif
  2255. #ifdef HAVE_GET_CYCLES
  2256. printf("\n\nSymmetric Ciphers:\n\n");
  2257. printf("Algorithm,"
  2258. BENCH_DEVID_COLUMN_HEADER
  2259. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2260. ",Cycles per byte,");
  2261. #else
  2262. printf("\n\nSymmetric Ciphers:\n\n");
  2263. printf("Algorithm,"
  2264. BENCH_DEVID_COLUMN_HEADER
  2265. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2266. #endif
  2267. #endif
  2268. #ifdef MULTI_VALUE_STATISTICS
  2269. printf("max duration,min duration,mean duration,sd,\n");
  2270. #else
  2271. printf("\n");
  2272. #endif
  2273. sym_header_printed = 1;
  2274. }
  2275. }
  2276. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2277. * note that the blockType text is assigned AND the blocks param is scaled.
  2278. */
  2279. if (base2) {
  2280. blockType = get_blocktype(&blocks);
  2281. }
  2282. else {
  2283. blockType = get_blocktype_base10(&blocks);
  2284. }
  2285. /* calculate blocks per second */
  2286. if (total > 0) {
  2287. persec = (1 / total) * blocks;
  2288. }
  2289. SLEEP_ON_ERROR(ret);
  2290. /* format and print to terminal */
  2291. if (csv_format == 1) {
  2292. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2293. #ifdef WOLFSSL_ESPIDF
  2294. unsigned long bytes_processed =
  2295. (unsigned long)count * (unsigned long)countSz;
  2296. #else
  2297. word64 bytes_processed = (word64)count * (word64)countSz;
  2298. #endif
  2299. /* note this codepath brings in all the fields from the non-CSV case. */
  2300. #ifdef WOLFSSL_ESPIDF
  2301. #ifdef HAVE_GET_CYCLES
  2302. (void)XSNPRINTF(msg, sizeof(msg),
  2303. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2304. BENCH_DEVID_GET_NAME(useDeviceID),
  2305. bytes_processed, FLT_FMT_ARGS(total),
  2306. FLT_FMT_ARGS(persec),
  2307. (long unsigned int) total_cycles);
  2308. #else
  2309. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2310. #endif
  2311. /* implement other architectures here */
  2312. #else
  2313. #ifdef HAVE_GET_CYCLES
  2314. (void)XSNPRINTF(msg, sizeof(msg),
  2315. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2316. BENCH_DEVID_GET_NAME(useDeviceID),
  2317. bytes_processed, FLT_FMT_ARGS(total),
  2318. FLT_FMT_ARGS(persec), total_cycles);
  2319. #else
  2320. (void)XSNPRINTF(msg, sizeof(msg),
  2321. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2322. BENCH_DEVID_GET_NAME(useDeviceID),
  2323. bytes_processed, FLT_FMT_ARGS(total),
  2324. FLT_FMT_ARGS(persec));
  2325. #endif
  2326. #endif
  2327. #elif defined(BENCH_DEVID)
  2328. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2329. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2330. #else
  2331. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2332. FLT_FMT_ARGS(persec));
  2333. #endif
  2334. #ifdef WOLFSSL_ESPIDF
  2335. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2336. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2337. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2338. total_cycles);
  2339. #endif
  2340. /* implement other cycle counters here */
  2341. #else
  2342. /* the default cycle counter is Intel */
  2343. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2344. #endif
  2345. } /* if (csv_format == 1) */
  2346. else {
  2347. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2348. #ifdef HAVE_GET_CYCLES
  2349. (void)XSNPRINTF(msg, sizeof(msg),
  2350. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2351. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2352. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2353. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2354. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2355. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2356. (unsigned long) total_cycles);
  2357. #else
  2358. (void)XSNPRINTF(msg, sizeof(msg),
  2359. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2360. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2361. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2362. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2363. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2364. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2365. #endif /* HAVE_GET_CYCLES */
  2366. #else
  2367. (void)XSNPRINTF(msg, sizeof(msg),
  2368. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2369. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2370. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2371. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2372. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2373. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2374. #endif
  2375. #ifdef WOLFSSL_ESPIDF
  2376. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2377. /* implement other architecture cycle counters here */
  2378. #else
  2379. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2380. #endif
  2381. } /* not CSV format */
  2382. printf("%s", msg);
  2383. /* show errors */
  2384. if (ret < 0) {
  2385. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2386. }
  2387. #ifndef WOLFSSL_SGX
  2388. XFFLUSH(stdout);
  2389. #endif
  2390. #ifdef WC_BENCH_TRACK_STATS
  2391. /* Add to thread stats */
  2392. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2393. blockType, ret);
  2394. #endif
  2395. (void)useDeviceID;
  2396. (void)ret;
  2397. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2398. RESTORE_VECTOR_REGISTERS();
  2399. #endif
  2400. TEST_SLEEP();
  2401. } /* bench_stats_sym_finish */
  2402. #ifdef BENCH_ASYM
  2403. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2404. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2405. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2406. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  2407. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2408. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2409. double start, int ret)
  2410. {
  2411. double total, each = 0, opsSec, milliEach;
  2412. const char **word = bench_result_words2[lng_index];
  2413. #ifdef WC_BENCH_TRACK_STATS
  2414. const char* kOpsSec = "Ops/Sec";
  2415. #endif
  2416. char msg[256];
  2417. static int asym_header_printed = 0;
  2418. #ifdef BENCH_MICROSECOND
  2419. const int digits = 5;
  2420. #else
  2421. const int digits = 3;
  2422. #endif
  2423. XMEMSET(msg, 0, sizeof(msg));
  2424. total = current_time(0) - start;
  2425. #ifdef LINUX_RUSAGE_UTIME
  2426. check_for_excessive_stime(desc, desc_extra);
  2427. #endif
  2428. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2429. #ifdef WOLFSSL_ESPIDF
  2430. END_ESP_CYCLES
  2431. #else
  2432. END_INTEL_CYCLES
  2433. #endif
  2434. #endif
  2435. /* some sanity checks on the final numbers */
  2436. if (count > 0) {
  2437. each = total / count; /* per second */
  2438. }
  2439. else {
  2440. count = 0;
  2441. each = 0;
  2442. }
  2443. if (total > 0) {
  2444. opsSec = count / total; /* ops second */
  2445. }
  2446. else {
  2447. opsSec = 0;
  2448. }
  2449. #ifdef BENCH_MICROSECOND
  2450. milliEach = each / 1000; /* milliseconds */
  2451. #else
  2452. milliEach = each * 1000; /* milliseconds */
  2453. #endif
  2454. SLEEP_ON_ERROR(ret);
  2455. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2456. (void)milliEach;
  2457. /* format and print to terminal */
  2458. if (csv_format == 1) {
  2459. /* only print out header once */
  2460. if (asym_header_printed == 0) {
  2461. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2462. #ifdef HAVE_GET_CYCLES
  2463. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2464. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2465. "ecs,cycles,cycles/op,");
  2466. #else
  2467. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2468. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2469. "ecs,");
  2470. #endif
  2471. #else
  2472. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2473. printf("%sAlgorithm,key size,operation,ops/"
  2474. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2475. #endif
  2476. printf("max duration,min duration,mean duration,sd,\n");
  2477. asym_header_printed = 1;
  2478. }
  2479. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2480. #ifdef HAVE_GET_CYCLES
  2481. (void)XSNPRINTF(msg, sizeof(msg),
  2482. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2483. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2484. algo, strength, desc, desc_extra,
  2485. FLT_FMT_PREC_ARGS(digits, opsSec),
  2486. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2487. FLT_FMT_PREC_ARGS(6,
  2488. (double)total_cycles / (double)count));
  2489. #else
  2490. (void)XSNPRINTF(msg, sizeof(msg),
  2491. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2492. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2493. algo, strength, desc, desc_extra,
  2494. FLT_FMT_PREC_ARGS(digits, opsSec),
  2495. count, FLT_FMT_ARGS(total));
  2496. #endif
  2497. #else
  2498. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2499. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2500. algo, strength, desc, desc_extra,
  2501. FLT_FMT_PREC_ARGS(digits, opsSec));
  2502. #endif
  2503. } /* if (csv_format == 1) */
  2504. else {
  2505. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2506. #ifdef HAVE_GET_CYCLES
  2507. (void)XSNPRINTF(msg, sizeof(msg),
  2508. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2509. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2510. algo, strength, desc, desc_extra,
  2511. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2512. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2513. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2514. (unsigned long)total_cycles);
  2515. #else
  2516. (void)XSNPRINTF(msg, sizeof(msg),
  2517. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2518. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2519. algo, strength, desc, desc_extra,
  2520. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2521. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2522. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2523. #endif /* HAVE_GET_CYCLES */
  2524. #else
  2525. (void)XSNPRINTF(msg, sizeof(msg),
  2526. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2527. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2528. algo, strength, desc, desc_extra,
  2529. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2530. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2531. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2532. #endif
  2533. }
  2534. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2535. /* format and print to terminal */
  2536. if (csv_format == 1) {
  2537. /* only print out header once */
  2538. if (asym_header_printed == 0) {
  2539. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2540. #ifdef HAVE_GET_CYCLES
  2541. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2542. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2543. "ecs,cycles,cycles/op,");
  2544. #else
  2545. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2546. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2547. "ecs,");
  2548. #endif
  2549. #else
  2550. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2551. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2552. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2553. #endif
  2554. printf("\n");
  2555. asym_header_printed = 1;
  2556. }
  2557. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2558. #ifdef HAVE_GET_CYCLES
  2559. (void)XSNPRINTF(msg, sizeof(msg),
  2560. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2561. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2562. algo, strength, desc, desc_extra,
  2563. FLT_FMT_PREC_ARGS(3, milliEach),
  2564. FLT_FMT_PREC_ARGS(digits, opsSec),
  2565. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2566. FLT_FMT_PREC_ARGS(6,
  2567. (double)total_cycles / (double)count));
  2568. #else
  2569. (void)XSNPRINTF(msg, sizeof(msg),
  2570. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2571. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2572. algo, strength, desc, desc_extra,
  2573. FLT_FMT_PREC_ARGS(3, milliEach),
  2574. FLT_FMT_PREC_ARGS(digits, opsSec),
  2575. count, FLT_FMT_ARGS(total));
  2576. #endif
  2577. #else
  2578. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2579. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2580. algo, strength, desc, desc_extra,
  2581. FLT_FMT_PREC_ARGS(3, milliEach),
  2582. FLT_FMT_PREC_ARGS(digits, opsSec));
  2583. #endif
  2584. } /* if (csv_format == 1) */
  2585. else {
  2586. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2587. #ifdef HAVE_GET_CYCLES
  2588. (void)XSNPRINTF(msg, sizeof(msg),
  2589. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2590. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2591. STATS_CLAUSE_SEPARATOR,
  2592. algo, strength, desc, desc_extra,
  2593. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2594. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2595. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2596. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2597. (unsigned long)total_cycles);
  2598. #else
  2599. (void)XSNPRINTF(msg, sizeof(msg),
  2600. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2601. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2602. STATS_CLAUSE_SEPARATOR,
  2603. algo, strength, desc, desc_extra,
  2604. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2605. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2606. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2607. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2608. #endif /* HAVE_GET_CYCLES */
  2609. #else
  2610. (void)XSNPRINTF(msg, sizeof(msg),
  2611. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2612. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2613. STATS_CLAUSE_SEPARATOR,
  2614. algo, strength, desc, desc_extra,
  2615. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2616. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2617. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2618. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2619. #endif
  2620. }
  2621. #endif /* MULTI_VALUE_STATISTICS */
  2622. printf("%s", msg);
  2623. /* show errors */
  2624. if (ret < 0) {
  2625. printf("%sBenchmark %s %s %d failed: %d\n",
  2626. err_prefix, algo, desc, strength, ret);
  2627. }
  2628. #ifndef WOLFSSL_SGX
  2629. XFFLUSH(stdout);
  2630. #endif
  2631. #ifdef WC_BENCH_TRACK_STATS
  2632. /* Add to thread stats */
  2633. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2634. kOpsSec, ret);
  2635. #endif
  2636. (void)useDeviceID;
  2637. (void)ret;
  2638. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2639. RESTORE_VECTOR_REGISTERS();
  2640. #endif
  2641. TEST_SLEEP();
  2642. } /* bench_stats_asym_finish_ex */
  2643. static void bench_stats_asym_finish(const char* algo, int strength,
  2644. const char* desc, int useDeviceID, int count, double start, int ret)
  2645. {
  2646. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2647. start, ret);
  2648. }
  2649. #endif
  2650. #endif /* BENCH_ASYM */
  2651. static WC_INLINE void bench_stats_free(void)
  2652. {
  2653. #ifdef WC_BENCH_TRACK_STATS
  2654. bench_stats_t* bstat;
  2655. for (bstat = bench_stats_head; bstat != NULL; ) {
  2656. bench_stats_t* next = bstat->next;
  2657. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2658. bstat = next;
  2659. }
  2660. bench_stats_head = NULL;
  2661. bench_stats_tail = NULL;
  2662. #endif
  2663. }
  2664. /*****************************************************************************/
  2665. /* End Stats Functions */
  2666. /*****************************************************************************/
  2667. static void* benchmarks_do(void* args)
  2668. {
  2669. long bench_buf_size;
  2670. #ifdef WOLFSSL_ASYNC_CRYPT
  2671. #ifndef WC_NO_ASYNC_THREADING
  2672. ThreadData* threadData = (ThreadData*)args;
  2673. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2674. #else
  2675. if (wolfAsync_DevOpen(&devId) < 0)
  2676. #endif
  2677. {
  2678. printf("%sAsync device open failed\n%sRunning without async\n",
  2679. err_prefix, err_prefix);
  2680. }
  2681. #endif /* WOLFSSL_ASYNC_CRYPT */
  2682. (void)args;
  2683. #ifdef WOLFSSL_ASYNC_CRYPT
  2684. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2685. printf("%sAsync event queue init failure!\n", err_prefix);
  2686. }
  2687. #endif
  2688. #ifdef WOLF_CRYPTO_CB
  2689. #ifdef HAVE_INTEL_QA_SYNC
  2690. devId = wc_CryptoCb_InitIntelQa();
  2691. if (devId == INVALID_DEVID) {
  2692. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2693. }
  2694. #endif
  2695. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2696. devId = wc_CryptoCb_InitOcteon();
  2697. if (devId == INVALID_DEVID) {
  2698. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2699. }
  2700. #endif
  2701. #ifdef HAVE_RENESAS_SYNC
  2702. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2703. if (devId == INVALID_DEVID) {
  2704. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2705. }
  2706. #endif
  2707. #endif
  2708. #if defined(HAVE_LOCAL_RNG)
  2709. {
  2710. int rngRet;
  2711. #ifndef HAVE_FIPS
  2712. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2713. #else
  2714. rngRet = wc_InitRng(&gRng);
  2715. #endif
  2716. if (rngRet < 0) {
  2717. printf("%sInitRNG failed\n", err_prefix);
  2718. return NULL;
  2719. }
  2720. }
  2721. #endif
  2722. /* setup bench plain, cipher, key and iv globals */
  2723. /* make sure bench buffer is multiple of 16 (AES block size) */
  2724. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2725. if (bench_buf_size % 16)
  2726. bench_buf_size += 16 - (bench_buf_size % 16);
  2727. #ifdef WOLFSSL_AFALG_XILINX_AES
  2728. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2729. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2730. #else
  2731. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2732. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2733. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2734. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2735. #endif
  2736. if (bench_plain == NULL || bench_cipher == NULL) {
  2737. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2738. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2739. bench_plain = bench_cipher = NULL;
  2740. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2741. goto exit;
  2742. }
  2743. #ifndef NO_FILESYSTEM
  2744. if (hash_input) {
  2745. size_t rawSz;
  2746. XFILE file;
  2747. file = XFOPEN(hash_input, "rb");
  2748. if (file == XBADFILE)
  2749. goto exit;
  2750. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2751. XFCLOSE(file);
  2752. goto exit;
  2753. }
  2754. bench_buf_size = XFTELL(file);
  2755. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2756. XFCLOSE(file);
  2757. goto exit;
  2758. }
  2759. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2760. rawSz = (size_t)bench_buf_size;
  2761. if (bench_buf_size % 16)
  2762. bench_buf_size += 16 - (bench_buf_size % 16);
  2763. bench_size = (word32)bench_buf_size;
  2764. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2765. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2766. if (bench_plain == NULL) {
  2767. XFCLOSE(file);
  2768. goto exit;
  2769. }
  2770. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2771. != rawSz) {
  2772. XFCLOSE(file);
  2773. goto exit;
  2774. }
  2775. XFCLOSE(file);
  2776. }
  2777. else {
  2778. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2779. }
  2780. if (cipher_input) {
  2781. size_t rawSz;
  2782. XFILE file;
  2783. file = XFOPEN(cipher_input, "rb");
  2784. if (file == XBADFILE)
  2785. goto exit;
  2786. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2787. XFCLOSE(file);
  2788. goto exit;
  2789. }
  2790. bench_buf_size = XFTELL(file);
  2791. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2792. XFCLOSE(file);
  2793. goto exit;
  2794. }
  2795. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2796. rawSz = (size_t)bench_buf_size;
  2797. if (bench_buf_size % 16)
  2798. bench_buf_size += 16 - (bench_buf_size % 16);
  2799. if (bench_size > (word32)bench_buf_size)
  2800. bench_size = (word32)bench_buf_size;
  2801. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2802. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2803. if (bench_cipher == NULL) {
  2804. XFCLOSE(file);
  2805. goto exit;
  2806. }
  2807. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2808. != rawSz) {
  2809. XFCLOSE(file);
  2810. goto exit;
  2811. }
  2812. XFCLOSE(file);
  2813. }
  2814. else {
  2815. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2816. }
  2817. #endif
  2818. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2819. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2820. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2821. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2822. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2823. if (bench_key == NULL || bench_iv == NULL) {
  2824. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2825. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2826. bench_key = bench_iv = NULL;
  2827. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2828. goto exit;
  2829. }
  2830. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2831. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2832. #elif defined(HAVE_RENESAS_SYNC)
  2833. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2834. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2835. bench_key = (byte*)bench_key_buf;
  2836. bench_iv = (byte*)bench_iv_buf;
  2837. #else
  2838. bench_key = (byte*)bench_key_buf;
  2839. bench_iv = (byte*)bench_iv_buf;
  2840. #endif
  2841. #ifndef WC_NO_RNG
  2842. if (bench_all || (bench_other_algs & BENCH_RNG))
  2843. bench_rng();
  2844. #endif /* WC_NO_RNG */
  2845. #ifndef NO_AES
  2846. #ifdef HAVE_AES_CBC
  2847. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2848. #ifndef NO_SW_BENCH
  2849. bench_aescbc(0);
  2850. #endif
  2851. #if defined(BENCH_DEVID)
  2852. bench_aescbc(1);
  2853. #endif
  2854. }
  2855. #endif
  2856. #ifdef HAVE_AESGCM
  2857. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2858. #ifndef NO_SW_BENCH
  2859. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2860. #endif
  2861. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2862. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2863. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2864. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2865. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2866. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2867. #endif
  2868. #ifndef NO_SW_BENCH
  2869. bench_gmac(0);
  2870. #endif
  2871. #if defined(BENCH_DEVID)
  2872. bench_gmac(1);
  2873. #endif
  2874. }
  2875. #endif
  2876. #ifdef HAVE_AES_ECB
  2877. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2878. #ifndef NO_SW_BENCH
  2879. bench_aesecb(0);
  2880. #endif
  2881. #ifdef BENCH_DEVID
  2882. bench_aesecb(1);
  2883. #endif
  2884. }
  2885. #endif
  2886. #ifdef WOLFSSL_AES_XTS
  2887. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2888. bench_aesxts();
  2889. #endif
  2890. #ifdef WOLFSSL_AES_CFB
  2891. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2892. bench_aescfb();
  2893. #endif
  2894. #ifdef WOLFSSL_AES_OFB
  2895. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2896. bench_aesofb();
  2897. #endif
  2898. #ifdef WOLFSSL_AES_COUNTER
  2899. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2900. bench_aesctr(0);
  2901. #ifdef BENCH_DEVID
  2902. bench_aesctr(1);
  2903. #endif
  2904. }
  2905. #endif
  2906. #ifdef HAVE_AESCCM
  2907. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2908. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2909. #ifdef BENCH_DEVID
  2910. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2911. #endif
  2912. }
  2913. #endif
  2914. #ifdef WOLFSSL_AES_SIV
  2915. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2916. bench_aessiv();
  2917. #endif
  2918. #endif /* !NO_AES */
  2919. #ifdef HAVE_CAMELLIA
  2920. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2921. bench_camellia();
  2922. #endif
  2923. #ifdef WOLFSSL_SM4_CBC
  2924. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2925. bench_sm4_cbc();
  2926. #endif
  2927. #ifdef WOLFSSL_SM4_GCM
  2928. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2929. bench_sm4_gcm();
  2930. #endif
  2931. #ifdef WOLFSSL_SM4_CCM
  2932. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2933. bench_sm4_ccm();
  2934. #endif
  2935. #ifndef NO_RC4
  2936. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2937. #ifndef NO_SW_BENCH
  2938. bench_arc4(0);
  2939. #endif
  2940. #ifdef BENCH_DEVID
  2941. bench_arc4(1);
  2942. #endif
  2943. }
  2944. #endif
  2945. #ifdef HAVE_CHACHA
  2946. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  2947. bench_chacha();
  2948. #endif
  2949. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  2950. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  2951. bench_chacha20_poly1305_aead();
  2952. #endif
  2953. #ifndef NO_DES3
  2954. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  2955. #ifndef NO_SW_BENCH
  2956. bench_des(0);
  2957. #endif
  2958. #ifdef BENCH_DEVID
  2959. bench_des(1);
  2960. #endif
  2961. }
  2962. #endif
  2963. #ifndef NO_MD5
  2964. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  2965. #ifndef NO_SW_BENCH
  2966. bench_md5(0);
  2967. #endif
  2968. #ifdef BENCH_DEVID
  2969. bench_md5(1);
  2970. #endif
  2971. }
  2972. #endif
  2973. #ifdef HAVE_POLY1305
  2974. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  2975. bench_poly1305();
  2976. #endif
  2977. #ifndef NO_SHA
  2978. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  2979. #ifndef NO_SW_BENCH
  2980. bench_sha(0);
  2981. #endif
  2982. #ifdef BENCH_DEVID
  2983. bench_sha(1);
  2984. #endif
  2985. }
  2986. #endif
  2987. #ifdef WOLFSSL_SHA224
  2988. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  2989. #ifndef NO_SW_BENCH
  2990. bench_sha224(0);
  2991. #endif
  2992. #ifdef BENCH_DEVID
  2993. bench_sha224(1);
  2994. #endif
  2995. }
  2996. #endif
  2997. #ifndef NO_SHA256
  2998. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  2999. #ifndef NO_SW_BENCH
  3000. bench_sha256(0);
  3001. #endif
  3002. #ifdef BENCH_DEVID
  3003. bench_sha256(1);
  3004. #endif
  3005. }
  3006. #endif
  3007. #ifdef WOLFSSL_SHA384
  3008. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3009. #ifndef NO_SW_BENCH
  3010. bench_sha384(0);
  3011. #endif
  3012. #ifdef BENCH_DEVID
  3013. bench_sha384(1);
  3014. #endif
  3015. }
  3016. #endif
  3017. #ifdef WOLFSSL_SHA512
  3018. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3019. #ifndef NO_SW_BENCH
  3020. bench_sha512(0);
  3021. #endif
  3022. #ifdef BENCH_DEVID
  3023. bench_sha512(1);
  3024. #endif
  3025. }
  3026. #if !defined(WOLFSSL_NOSHA512_224) && \
  3027. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3028. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3029. #ifndef NO_SW_BENCH
  3030. bench_sha512_224(0);
  3031. #endif
  3032. #ifdef BENCH_DEVID
  3033. bench_sha512_224(1);
  3034. #endif
  3035. }
  3036. #endif /* WOLFSSL_NOSHA512_224 */
  3037. #if !defined(WOLFSSL_NOSHA512_256) && \
  3038. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3039. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3040. #ifndef NO_SW_BENCH
  3041. bench_sha512_256(0);
  3042. #endif
  3043. #ifdef BENCH_DEVID
  3044. bench_sha512_256(1);
  3045. #endif
  3046. }
  3047. #endif /* WOLFSSL_NOSHA512_256 */
  3048. #endif /* WOLFSSL_SHA512 */
  3049. #ifdef WOLFSSL_SHA3
  3050. #ifndef WOLFSSL_NOSHA3_224
  3051. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3052. #ifndef NO_SW_BENCH
  3053. bench_sha3_224(0);
  3054. #endif
  3055. #ifdef BENCH_DEVID
  3056. bench_sha3_224(1);
  3057. #endif
  3058. }
  3059. #endif /* WOLFSSL_NOSHA3_224 */
  3060. #ifndef WOLFSSL_NOSHA3_256
  3061. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3062. #ifndef NO_SW_BENCH
  3063. bench_sha3_256(0);
  3064. #endif
  3065. #ifdef BENCH_DEVID
  3066. bench_sha3_256(1);
  3067. #endif
  3068. }
  3069. #endif /* WOLFSSL_NOSHA3_256 */
  3070. #ifndef WOLFSSL_NOSHA3_384
  3071. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3072. #ifndef NO_SW_BENCH
  3073. bench_sha3_384(0);
  3074. #endif
  3075. #ifdef BENCH_DEVID
  3076. bench_sha3_384(1);
  3077. #endif
  3078. }
  3079. #endif /* WOLFSSL_NOSHA3_384 */
  3080. #ifndef WOLFSSL_NOSHA3_512
  3081. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3082. #ifndef NO_SW_BENCH
  3083. bench_sha3_512(0);
  3084. #endif
  3085. #ifdef BENCH_DEVID
  3086. bench_sha3_512(1);
  3087. #endif
  3088. }
  3089. #endif /* WOLFSSL_NOSHA3_512 */
  3090. #ifdef WOLFSSL_SHAKE128
  3091. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3092. #ifndef NO_SW_BENCH
  3093. bench_shake128(0);
  3094. #endif
  3095. #ifdef BENCH_DEVID
  3096. bench_shake128(1);
  3097. #endif
  3098. }
  3099. #endif /* WOLFSSL_SHAKE128 */
  3100. #ifdef WOLFSSL_SHAKE256
  3101. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3102. #ifndef NO_SW_BENCH
  3103. bench_shake256(0);
  3104. #endif
  3105. #ifdef BENCH_DEVID
  3106. bench_shake256(1);
  3107. #endif
  3108. }
  3109. #endif /* WOLFSSL_SHAKE256 */
  3110. #endif
  3111. #ifdef WOLFSSL_SM3
  3112. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3113. #ifndef NO_SW_BENCH
  3114. bench_sm3(0);
  3115. #endif
  3116. #ifdef BENCH_DEVID
  3117. bench_sm3(1);
  3118. #endif
  3119. }
  3120. #endif
  3121. #ifdef WOLFSSL_RIPEMD
  3122. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3123. bench_ripemd();
  3124. #endif
  3125. #ifdef HAVE_BLAKE2
  3126. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3127. bench_blake2b();
  3128. #endif
  3129. #ifdef HAVE_BLAKE2S
  3130. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3131. bench_blake2s();
  3132. #endif
  3133. #ifdef WOLFSSL_CMAC
  3134. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3135. bench_cmac(0);
  3136. #ifdef BENCH_DEVID
  3137. bench_cmac(1);
  3138. #endif
  3139. }
  3140. #endif
  3141. #ifndef NO_HMAC
  3142. #ifndef NO_MD5
  3143. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3144. #ifndef NO_SW_BENCH
  3145. bench_hmac_md5(0);
  3146. #endif
  3147. #ifdef BENCH_DEVID
  3148. bench_hmac_md5(1);
  3149. #endif
  3150. }
  3151. #endif
  3152. #ifndef NO_SHA
  3153. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3154. #ifndef NO_SW_BENCH
  3155. bench_hmac_sha(0);
  3156. #endif
  3157. #ifdef BENCH_DEVID
  3158. bench_hmac_sha(1);
  3159. #endif
  3160. }
  3161. #endif
  3162. #ifdef WOLFSSL_SHA224
  3163. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3164. #ifndef NO_SW_BENCH
  3165. bench_hmac_sha224(0);
  3166. #endif
  3167. #ifdef BENCH_DEVID
  3168. bench_hmac_sha224(1);
  3169. #endif
  3170. }
  3171. #endif
  3172. #ifndef NO_SHA256
  3173. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3174. #ifndef NO_SW_BENCH
  3175. bench_hmac_sha256(0);
  3176. #endif
  3177. #ifdef BENCH_DEVID
  3178. bench_hmac_sha256(1);
  3179. #endif
  3180. }
  3181. #endif
  3182. #ifdef WOLFSSL_SHA384
  3183. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3184. #ifndef NO_SW_BENCH
  3185. bench_hmac_sha384(0);
  3186. #endif
  3187. #ifdef BENCH_DEVID
  3188. bench_hmac_sha384(1);
  3189. #endif
  3190. }
  3191. #endif
  3192. #ifdef WOLFSSL_SHA512
  3193. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3194. #ifndef NO_SW_BENCH
  3195. bench_hmac_sha512(0);
  3196. #endif
  3197. #ifdef BENCH_DEVID
  3198. bench_hmac_sha512(1);
  3199. #endif
  3200. }
  3201. #endif
  3202. #ifndef NO_PWDBASED
  3203. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3204. bench_pbkdf2();
  3205. }
  3206. #endif
  3207. #endif /* NO_HMAC */
  3208. #ifdef WOLFSSL_SIPHASH
  3209. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3210. bench_siphash();
  3211. }
  3212. #endif
  3213. #ifdef WC_SRTP_KDF
  3214. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3215. bench_srtpkdf();
  3216. }
  3217. #endif
  3218. #ifdef HAVE_SCRYPT
  3219. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3220. bench_scrypt();
  3221. #endif
  3222. #ifndef NO_RSA
  3223. #ifndef HAVE_RENESAS_SYNC
  3224. #ifdef WOLFSSL_KEY_GEN
  3225. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3226. #ifndef NO_SW_BENCH
  3227. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3228. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3229. bench_rsaKeyGen(0);
  3230. }
  3231. else {
  3232. bench_rsaKeyGen_size(0, bench_size);
  3233. }
  3234. #endif
  3235. #ifdef BENCH_DEVID
  3236. if (bench_asym_algs & BENCH_RSA_SZ) {
  3237. bench_rsaKeyGen_size(1, bench_size);
  3238. }
  3239. else {
  3240. bench_rsaKeyGen(1);
  3241. }
  3242. #endif
  3243. }
  3244. #endif
  3245. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3246. #ifndef NO_SW_BENCH
  3247. bench_rsa(0);
  3248. #endif
  3249. #ifdef BENCH_DEVID
  3250. bench_rsa(1);
  3251. #endif
  3252. }
  3253. #ifdef WOLFSSL_KEY_GEN
  3254. if (bench_asym_algs & BENCH_RSA_SZ) {
  3255. #ifndef NO_SW_BENCH
  3256. bench_rsa_key(0, bench_size);
  3257. #endif
  3258. #ifdef BENCH_DEVID
  3259. bench_rsa_key(1, bench_size);
  3260. #endif
  3261. }
  3262. #endif
  3263. #endif
  3264. #endif
  3265. #ifndef NO_DH
  3266. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3267. #ifndef NO_SW_BENCH
  3268. bench_dh(0);
  3269. #endif
  3270. #ifdef BENCH_DEVID
  3271. bench_dh(1);
  3272. #endif
  3273. }
  3274. #endif
  3275. #ifdef WOLFSSL_HAVE_KYBER
  3276. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3277. #ifdef WOLFSSL_KYBER512
  3278. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3279. bench_kyber(KYBER512);
  3280. }
  3281. #endif
  3282. #ifdef WOLFSSL_KYBER768
  3283. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3284. bench_kyber(KYBER768);
  3285. }
  3286. #endif
  3287. #ifdef WOLFSSL_KYBER1024
  3288. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3289. bench_kyber(KYBER1024);
  3290. }
  3291. #endif
  3292. }
  3293. #endif
  3294. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3295. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3296. bench_lms();
  3297. }
  3298. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3299. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3300. if (bench_all) {
  3301. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3302. }
  3303. #ifndef NO_SHA256
  3304. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3305. bench_xmss(WC_HASH_TYPE_SHA256);
  3306. }
  3307. #endif
  3308. #ifdef WOLFSSL_SHA512
  3309. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3310. bench_xmss(WC_HASH_TYPE_SHA512);
  3311. }
  3312. #endif
  3313. #ifdef WOLFSSL_SHAKE128
  3314. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3315. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3316. }
  3317. #endif
  3318. #ifdef WOLFSSL_SHAKE256
  3319. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3320. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3321. }
  3322. #endif
  3323. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3324. #ifdef HAVE_ECC
  3325. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3326. (bench_asym_algs & BENCH_ECC) ||
  3327. (bench_asym_algs & BENCH_ECC_ALL) ||
  3328. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3329. if (bench_asym_algs & BENCH_ECC_ALL) {
  3330. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3331. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3332. err_prefix);
  3333. #else
  3334. int curveId = (int)ECC_SECP192R1;
  3335. /* set make key and encrypt */
  3336. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3337. BENCH_ECC_ENCRYPT;
  3338. if (csv_format != 1) {
  3339. printf("\n%sECC Benchmarks:\n", info_prefix);
  3340. }
  3341. do {
  3342. #ifdef WOLFCRYPT_HAVE_SAKKE
  3343. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3344. if (curveId == ECC_SAKKE_1) {
  3345. curveId++;
  3346. continue;
  3347. }
  3348. #endif
  3349. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3350. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3351. bench_ecc_curve(curveId);
  3352. if (csv_format != 1) {
  3353. printf("\n");
  3354. }
  3355. }
  3356. curveId++;
  3357. } while (curveId != (int)ECC_CURVE_MAX);
  3358. #endif
  3359. }
  3360. else if (bench_asym_algs & BENCH_ECC_P256) {
  3361. bench_ecc_curve((int)ECC_SECP256R1);
  3362. }
  3363. else if (bench_asym_algs & BENCH_ECC_P384) {
  3364. bench_ecc_curve((int)ECC_SECP384R1);
  3365. }
  3366. else if (bench_asym_algs & BENCH_ECC_P521) {
  3367. bench_ecc_curve((int)ECC_SECP521R1);
  3368. }
  3369. else {
  3370. #ifndef NO_ECC256
  3371. bench_ecc_curve((int)ECC_SECP256R1);
  3372. #elif defined(HAVE_ECC384)
  3373. bench_ecc_curve((int)ECC_SECP384R1);
  3374. #elif defined(HAVE_ECC521)
  3375. bench_ecc_curve((int)ECC_SECP521R1);
  3376. #endif
  3377. #ifdef HAVE_ECC_BRAINPOOL
  3378. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3379. #endif
  3380. }
  3381. }
  3382. #endif
  3383. #ifdef WOLFSSL_SM2
  3384. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3385. bench_sm2(0);
  3386. }
  3387. #endif
  3388. #ifdef HAVE_CURVE25519
  3389. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3390. bench_curve25519KeyGen(0);
  3391. #ifdef BENCH_DEVID
  3392. bench_curve25519KeyGen(1);
  3393. #endif
  3394. }
  3395. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3396. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3397. bench_curve25519KeyAgree(0);
  3398. #ifdef BENCH_DEVID
  3399. bench_curve25519KeyAgree(1);
  3400. #endif
  3401. }
  3402. #endif
  3403. #endif
  3404. #ifdef HAVE_ED25519
  3405. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3406. bench_ed25519KeyGen();
  3407. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3408. bench_ed25519KeySign();
  3409. #endif
  3410. #ifdef HAVE_CURVE448
  3411. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3412. bench_curve448KeyGen();
  3413. #ifdef HAVE_CURVE448_SHARED_SECRET
  3414. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3415. bench_curve448KeyAgree();
  3416. #endif
  3417. #endif
  3418. #ifdef HAVE_ED448
  3419. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3420. bench_ed448KeyGen();
  3421. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3422. bench_ed448KeySign();
  3423. #endif
  3424. #ifdef WOLFCRYPT_HAVE_ECCSI
  3425. #ifdef WOLFCRYPT_ECCSI_KMS
  3426. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3427. bench_eccsiKeyGen();
  3428. }
  3429. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3430. bench_eccsiPairGen();
  3431. }
  3432. #endif
  3433. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3434. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3435. bench_eccsiValidate();
  3436. }
  3437. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3438. bench_eccsi();
  3439. }
  3440. #endif
  3441. #endif
  3442. #ifdef WOLFCRYPT_HAVE_SAKKE
  3443. #ifdef WOLFCRYPT_SAKKE_KMS
  3444. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3445. bench_sakkeKeyGen();
  3446. }
  3447. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3448. bench_sakkeRskGen();
  3449. }
  3450. #endif
  3451. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3452. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3453. bench_sakkeValidate();
  3454. }
  3455. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3456. bench_sakke();
  3457. }
  3458. #endif
  3459. #endif
  3460. #ifdef HAVE_FALCON
  3461. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3462. bench_falconKeySign(1);
  3463. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3464. bench_falconKeySign(5);
  3465. #endif
  3466. #ifdef HAVE_DILITHIUM
  3467. #ifndef WOLFSSL_NO_ML_DSA_44
  3468. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3469. bench_dilithiumKeySign(2);
  3470. #endif
  3471. #ifndef WOLFSSL_NO_ML_DSA_65
  3472. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3473. bench_dilithiumKeySign(3);
  3474. #endif
  3475. #ifndef WOLFSSL_NO_ML_DSA_87
  3476. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3477. bench_dilithiumKeySign(5);
  3478. #endif
  3479. #endif
  3480. #ifdef HAVE_SPHINCS
  3481. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3482. bench_sphincsKeySign(1, FAST_VARIANT);
  3483. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3484. bench_sphincsKeySign(3, FAST_VARIANT);
  3485. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3486. bench_sphincsKeySign(5, FAST_VARIANT);
  3487. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3488. bench_sphincsKeySign(1, SMALL_VARIANT);
  3489. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3490. bench_sphincsKeySign(3, SMALL_VARIANT);
  3491. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3492. bench_sphincsKeySign(5, SMALL_VARIANT);
  3493. #endif
  3494. exit:
  3495. /* free benchmark buffers */
  3496. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3497. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3498. #ifdef WOLFSSL_ASYNC_CRYPT
  3499. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3500. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3501. #endif
  3502. #if defined(HAVE_LOCAL_RNG)
  3503. wc_FreeRng(&gRng);
  3504. #endif
  3505. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3506. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3507. wc_ecc_fp_free();
  3508. #endif
  3509. (void)bench_cipher_algs;
  3510. (void)bench_digest_algs;
  3511. (void)bench_mac_algs;
  3512. (void)bench_asym_algs;
  3513. (void)bench_other_algs;
  3514. (void)bench_pq_asym_algs;
  3515. (void)bench_pq_asym_algs2;
  3516. return NULL;
  3517. }
  3518. int benchmark_init(void)
  3519. {
  3520. int ret = 0;
  3521. benchmark_static_init(0);
  3522. #ifdef WOLFSSL_STATIC_MEMORY
  3523. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3524. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3525. if (ret != 0) {
  3526. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3527. }
  3528. #endif /* WOLFSSL_STATIC_MEMORY */
  3529. if ((ret = wolfCrypt_Init()) != 0) {
  3530. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3531. return EXIT_FAILURE;
  3532. }
  3533. #ifdef HAVE_WC_INTROSPECTION
  3534. printf("Math: %s\n", wc_GetMathInfo());
  3535. #endif
  3536. #ifdef WOLFSSL_SECO_CAAM
  3537. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3538. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3539. != 0) {
  3540. printf("%sunable to open HSM\n", err_prefix);
  3541. wolfCrypt_Cleanup();
  3542. return EXIT_FAILURE;
  3543. }
  3544. #endif
  3545. #ifdef WC_RNG_SEED_CB
  3546. wc_SetSeed_Cb(wc_GenerateSeed);
  3547. #endif
  3548. bench_stats_init();
  3549. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3550. wolfSSL_Debugging_ON();
  3551. #endif
  3552. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3553. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3554. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3555. if (csv_format == 1) {
  3556. printf("This format allows you to easily copy "
  3557. "the output to a csv file.");
  3558. }
  3559. #endif
  3560. #ifdef HAVE_WNR
  3561. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3562. if (ret != 0) {
  3563. printf("%sWhitewood netRandom config init failed %d\n",
  3564. err_prefix, ret);
  3565. }
  3566. #endif /* HAVE_WNR */
  3567. return ret;
  3568. }
  3569. int benchmark_free(void)
  3570. {
  3571. int ret;
  3572. #ifdef WC_BENCH_TRACK_STATS
  3573. if (gPrintStats || devId != INVALID_DEVID) {
  3574. bench_stats_print();
  3575. }
  3576. #endif
  3577. bench_stats_free();
  3578. #ifdef WOLF_CRYPTO_CB
  3579. #ifdef HAVE_INTEL_QA_SYNC
  3580. wc_CryptoCb_CleanupIntelQa(&devId);
  3581. #endif
  3582. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3583. wc_CryptoCb_CleanupOcteon(&devId);
  3584. #endif
  3585. #ifdef HAVE_RENESAS_SYNC
  3586. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3587. #endif
  3588. #endif
  3589. #ifdef WOLFSSL_ASYNC_CRYPT
  3590. /* free event queue */
  3591. wolfEventQueue_Free(&eventQueue);
  3592. /* close device */
  3593. wolfAsync_DevClose(&devId);
  3594. #endif
  3595. #ifdef HAVE_WNR
  3596. ret = wc_FreeNetRandom();
  3597. if (ret < 0) {
  3598. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3599. }
  3600. #endif
  3601. #ifdef WOLFSSL_SECO_CAAM
  3602. if (wc_SECO_CloseHSM() != 0) {
  3603. printf("%sError closing down the key store\n", err_prefix);
  3604. }
  3605. #endif
  3606. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3607. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3608. }
  3609. return ret;
  3610. }
  3611. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3612. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3613. {
  3614. benchmark_test(args);
  3615. EXIT_TEST(0);
  3616. }
  3617. static int benchmark_test_threaded(void* args)
  3618. {
  3619. int i;
  3620. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3621. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3622. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3623. if (g_threadData == NULL) {
  3624. printf("%sThread data alloc failed!\n", err_prefix);
  3625. return EXIT_FAILURE;
  3626. }
  3627. for (i = 0; i < g_threadCount; i++) {
  3628. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3629. NULL, run_bench, args));
  3630. }
  3631. for (i = 0; i < g_threadCount; i++) {
  3632. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3633. }
  3634. printf("\n");
  3635. bench_stats_print();
  3636. return 0;
  3637. }
  3638. #endif
  3639. /* so embedded projects can pull in tests on their own */
  3640. #ifdef HAVE_STACK_SIZE
  3641. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3642. #else
  3643. int benchmark_test(void *args)
  3644. #endif
  3645. {
  3646. int ret;
  3647. (void)args;
  3648. #ifdef HAVE_FIPS
  3649. wolfCrypt_SetCb_fips(myFipsCb);
  3650. #endif
  3651. ret = benchmark_init();
  3652. if (ret != 0)
  3653. EXIT_TEST(ret);
  3654. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3655. {
  3656. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3657. **
  3658. ** Chapter Two, Build Options:
  3659. **
  3660. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3661. **
  3662. ** asynchronous cryptography using hardware based adapters such as
  3663. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3664. */
  3665. int i;
  3666. if (g_threadCount == 0) {
  3667. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3668. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3669. #else
  3670. g_threadCount = wc_AsyncGetNumberOfCpus();
  3671. if (g_threadCount > 0) {
  3672. g_threadCount /= 2; /* use physical core count */
  3673. }
  3674. #endif
  3675. }
  3676. if (g_threadCount <= 0) {
  3677. g_threadCount = 1;
  3678. }
  3679. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3680. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3681. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3682. if (g_threadData == NULL) {
  3683. printf("%sThread data alloc failed!\n", err_prefix);
  3684. EXIT_TEST(EXIT_FAILURE);
  3685. }
  3686. /* Create threads */
  3687. for (i = 0; i < g_threadCount; i++) {
  3688. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3689. benchmarks_do, &g_threadData[i]);
  3690. if (ret != 0) {
  3691. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3692. EXIT_TEST(EXIT_FAILURE);
  3693. }
  3694. }
  3695. /* Start threads */
  3696. for (i = 0; i < g_threadCount; i++) {
  3697. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3698. }
  3699. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3700. }
  3701. #else
  3702. benchmarks_do(NULL);
  3703. #endif
  3704. SLEEP_ON_ERROR(1);
  3705. printf("%sBenchmark complete\n", info_prefix);
  3706. ret = benchmark_free();
  3707. EXIT_TEST(ret);
  3708. }
  3709. #ifndef WC_NO_RNG
  3710. void bench_rng(void)
  3711. {
  3712. int ret, i, count;
  3713. double start;
  3714. long pos, len, remain;
  3715. WC_RNG myrng;
  3716. DECLARE_MULTI_VALUE_STATS_VARS()
  3717. #ifndef HAVE_FIPS
  3718. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3719. #else
  3720. ret = wc_InitRng(&myrng);
  3721. #endif
  3722. if (ret < 0) {
  3723. printf("InitRNG failed %d\n", ret);
  3724. return;
  3725. }
  3726. bench_stats_start(&count, &start);
  3727. do {
  3728. for (i = 0; i < numBlocks; i++) {
  3729. /* Split request to handle large RNG request */
  3730. pos = 0;
  3731. remain = (int)bench_size;
  3732. while (remain > 0) {
  3733. len = remain;
  3734. if (len > RNG_MAX_BLOCK_LEN)
  3735. len = RNG_MAX_BLOCK_LEN;
  3736. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3737. (word32)len);
  3738. if (ret < 0)
  3739. goto exit_rng;
  3740. remain -= len;
  3741. pos += len;
  3742. }
  3743. RECORD_MULTI_VALUE_STATS();
  3744. }
  3745. count += i;
  3746. } while (bench_stats_check(start)
  3747. #ifdef MULTI_VALUE_STATISTICS
  3748. || runs < minimum_runs
  3749. #endif
  3750. );
  3751. exit_rng:
  3752. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3753. #ifdef MULTI_VALUE_STATISTICS
  3754. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3755. #endif
  3756. wc_FreeRng(&myrng);
  3757. }
  3758. #endif /* WC_NO_RNG */
  3759. #ifndef NO_AES
  3760. #ifdef HAVE_AES_CBC
  3761. static void bench_aescbc_internal(int useDeviceID,
  3762. const byte* key, word32 keySz,
  3763. const byte* iv, const char* encLabel,
  3764. const char* decLabel)
  3765. {
  3766. const byte* in = bench_cipher;
  3767. byte* out = bench_plain;
  3768. int ret = 0, i, count = 0, times, pending = 0;
  3769. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3770. sizeof(Aes), HEAP_HINT);
  3771. double start;
  3772. DECLARE_MULTI_VALUE_STATS_VARS()
  3773. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3774. sizeof(Aes), HEAP_HINT);
  3775. /* init keys */
  3776. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3777. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3778. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3779. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3780. goto exit;
  3781. }
  3782. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3783. if (ret != 0) {
  3784. printf("AesSetKey failed, ret = %d\n", ret);
  3785. goto exit;
  3786. }
  3787. }
  3788. if (cipher_same_buffer) {
  3789. in = bench_plain;
  3790. }
  3791. bench_stats_start(&count, &start);
  3792. do {
  3793. for (times = 0; times < numBlocks || pending > 0; ) {
  3794. bench_async_poll(&pending);
  3795. /* while free pending slots in queue, submit ops */
  3796. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3797. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3798. &times, numBlocks, &pending)) {
  3799. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3800. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3801. 0, &times, &pending)) {
  3802. goto exit_aes_enc;
  3803. }
  3804. }
  3805. } /* for i */
  3806. RECORD_MULTI_VALUE_STATS();
  3807. } /* for times */
  3808. count += times;
  3809. } while (bench_stats_check(start)
  3810. #ifdef MULTI_VALUE_STATISTICS
  3811. || runs < minimum_runs
  3812. #endif
  3813. );
  3814. exit_aes_enc:
  3815. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3816. bench_size, start, ret);
  3817. #ifdef MULTI_VALUE_STATISTICS
  3818. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3819. #endif
  3820. if (ret < 0) {
  3821. goto exit;
  3822. }
  3823. #ifdef HAVE_AES_DECRYPT
  3824. /* init keys */
  3825. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3826. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3827. if (ret != 0) {
  3828. printf("AesSetKey failed, ret = %d\n", ret);
  3829. goto exit;
  3830. }
  3831. }
  3832. RESET_MULTI_VALUE_STATS_VARS();
  3833. bench_stats_start(&count, &start);
  3834. do {
  3835. for (times = 0; times < numBlocks || pending > 0; ) {
  3836. bench_async_poll(&pending);
  3837. /* while free pending slots in queue, submit ops */
  3838. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3839. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3840. &times, numBlocks, &pending)) {
  3841. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3842. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3843. 0, &times, &pending)) {
  3844. goto exit_aes_dec;
  3845. }
  3846. }
  3847. } /* for i */
  3848. RECORD_MULTI_VALUE_STATS();
  3849. } /* for times */
  3850. count += times;
  3851. } while (bench_stats_check(start)
  3852. #ifdef MULTI_VALUE_STATISTICS
  3853. || runs < minimum_runs
  3854. #endif
  3855. );
  3856. exit_aes_dec:
  3857. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3858. start, ret);
  3859. #ifdef MULTI_VALUE_STATISTICS
  3860. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3861. #endif
  3862. #endif /* HAVE_AES_DECRYPT */
  3863. (void)decLabel;
  3864. exit:
  3865. if (WC_ARRAY_OK(enc)) {
  3866. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3867. wc_AesFree(enc[i]);
  3868. }
  3869. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3870. }
  3871. }
  3872. void bench_aescbc(int useDeviceID)
  3873. {
  3874. #ifdef WOLFSSL_AES_128
  3875. #ifdef HAVE_RENESAS_SYNC
  3876. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3877. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3878. #else
  3879. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3880. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3881. #endif
  3882. #endif
  3883. #ifdef WOLFSSL_AES_192
  3884. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3885. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3886. #endif
  3887. #ifdef WOLFSSL_AES_256
  3888. #ifdef HAVE_RENESAS_SYNC
  3889. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3890. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3891. #else
  3892. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3893. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3894. #endif
  3895. #endif
  3896. }
  3897. #endif /* HAVE_AES_CBC */
  3898. #ifdef HAVE_AESGCM
  3899. static void bench_aesgcm_internal(int useDeviceID,
  3900. const byte* key, word32 keySz,
  3901. const byte* iv, word32 ivSz,
  3902. const char* encLabel, const char* decLabel)
  3903. {
  3904. int ret = 0, i, count = 0, times, pending = 0;
  3905. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3906. sizeof(Aes), HEAP_HINT);
  3907. #ifdef HAVE_AES_DECRYPT
  3908. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3909. sizeof(Aes), HEAP_HINT);
  3910. #endif
  3911. double start;
  3912. DECLARE_MULTI_VALUE_STATS_VARS()
  3913. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3914. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3915. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3916. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3917. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3918. sizeof(Aes), HEAP_HINT);
  3919. #ifdef HAVE_AES_DECRYPT
  3920. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3921. sizeof(Aes), HEAP_HINT);
  3922. #endif
  3923. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3924. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3925. /* init keys */
  3926. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3927. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3928. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3929. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3930. goto exit;
  3931. }
  3932. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  3933. if (ret != 0) {
  3934. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3935. goto exit;
  3936. }
  3937. }
  3938. /* GCM uses same routine in backend for both encrypt and decrypt */
  3939. bench_stats_start(&count, &start);
  3940. do {
  3941. for (times = 0; times < numBlocks || pending > 0; ) {
  3942. bench_async_poll(&pending);
  3943. /* while free pending slots in queue, submit ops */
  3944. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3945. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3946. &times, numBlocks, &pending)) {
  3947. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  3948. bench_plain, bench_size,
  3949. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  3950. bench_additional, aesAuthAddSz);
  3951. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3952. 0, &times, &pending)) {
  3953. goto exit_aes_gcm;
  3954. }
  3955. }
  3956. } /* for i */
  3957. RECORD_MULTI_VALUE_STATS();
  3958. } /* for times */
  3959. count += times;
  3960. } while (bench_stats_check(start)
  3961. #ifdef MULTI_VALUE_STATISTICS
  3962. || runs < minimum_runs
  3963. #endif
  3964. );
  3965. exit_aes_gcm:
  3966. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  3967. start, ret);
  3968. #ifdef MULTI_VALUE_STATISTICS
  3969. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3970. #endif
  3971. #ifdef HAVE_AES_DECRYPT
  3972. RESET_MULTI_VALUE_STATS_VARS();
  3973. /* init keys */
  3974. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3975. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  3976. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3977. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3978. goto exit;
  3979. }
  3980. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  3981. if (ret != 0) {
  3982. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3983. goto exit;
  3984. }
  3985. }
  3986. bench_stats_start(&count, &start);
  3987. do {
  3988. for (times = 0; times < numBlocks || pending > 0; ) {
  3989. bench_async_poll(&pending);
  3990. /* while free pending slots in queue, submit ops */
  3991. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3992. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  3993. &times, numBlocks, &pending)) {
  3994. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  3995. bench_cipher, bench_size,
  3996. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  3997. bench_additional, aesAuthAddSz);
  3998. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  3999. 0, &times, &pending)) {
  4000. goto exit_aes_gcm_dec;
  4001. }
  4002. }
  4003. } /* for i */
  4004. RECORD_MULTI_VALUE_STATS();
  4005. } /* for times */
  4006. count += times;
  4007. } while (bench_stats_check(start)
  4008. #ifdef MULTI_VALUE_STATISTICS
  4009. || runs < minimum_runs
  4010. #endif
  4011. );
  4012. exit_aes_gcm_dec:
  4013. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4014. start, ret);
  4015. #ifdef MULTI_VALUE_STATISTICS
  4016. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4017. #endif
  4018. #endif /* HAVE_AES_DECRYPT */
  4019. (void)decLabel;
  4020. exit:
  4021. if (ret < 0) {
  4022. printf("bench_aesgcm failed: %d\n", ret);
  4023. }
  4024. #ifdef HAVE_AES_DECRYPT
  4025. if (WC_ARRAY_OK(dec)) {
  4026. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4027. wc_AesFree(dec[i]);
  4028. }
  4029. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4030. }
  4031. #endif
  4032. if (WC_ARRAY_OK(enc)) {
  4033. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4034. wc_AesFree(enc[i]);
  4035. }
  4036. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4037. }
  4038. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4039. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4040. }
  4041. #ifdef WOLFSSL_AESGCM_STREAM
  4042. static void bench_aesgcm_stream_internal(int useDeviceID,
  4043. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4044. const char* encLabel, const char* decLabel)
  4045. {
  4046. int ret = 0, i, count = 0, times, pending = 0;
  4047. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4048. sizeof(Aes), HEAP_HINT);
  4049. #ifdef HAVE_AES_DECRYPT
  4050. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4051. sizeof(Aes), HEAP_HINT);
  4052. #endif
  4053. double start;
  4054. DECLARE_MULTI_VALUE_STATS_VARS()
  4055. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4056. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4057. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4058. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4059. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4060. sizeof(Aes), HEAP_HINT);
  4061. #ifdef HAVE_AES_DECRYPT
  4062. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4063. sizeof(Aes), HEAP_HINT);
  4064. #endif
  4065. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4066. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4067. /* init keys */
  4068. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4069. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4070. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4071. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4072. goto exit;
  4073. }
  4074. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4075. if (ret != 0) {
  4076. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4077. goto exit;
  4078. }
  4079. }
  4080. /* GCM uses same routine in backend for both encrypt and decrypt */
  4081. bench_stats_start(&count, &start);
  4082. do {
  4083. for (times = 0; times < numBlocks || pending > 0; ) {
  4084. bench_async_poll(&pending);
  4085. /* while free pending slots in queue, submit ops */
  4086. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4087. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4088. &times, numBlocks, &pending)) {
  4089. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4090. if (ret == 0) {
  4091. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4092. bench_plain, bench_size, bench_additional,
  4093. aesAuthAddSz);
  4094. }
  4095. if (ret == 0) {
  4096. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4097. AES_AUTH_TAG_SZ);
  4098. }
  4099. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4100. 0, &times, &pending)) {
  4101. goto exit_aes_gcm;
  4102. }
  4103. }
  4104. } /* for i */
  4105. RECORD_MULTI_VALUE_STATS();
  4106. } /* for times */
  4107. count += times;
  4108. } while (bench_stats_check(start)
  4109. #ifdef MULTI_VALUE_STATISTICS
  4110. || runs < minimum_runs
  4111. #endif
  4112. );
  4113. exit_aes_gcm:
  4114. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4115. start, ret);
  4116. #ifdef MULTI_VALUE_STATISTICS
  4117. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4118. #endif
  4119. #ifdef HAVE_AES_DECRYPT
  4120. /* init keys */
  4121. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4122. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4123. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4124. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4125. goto exit;
  4126. }
  4127. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4128. if (ret != 0) {
  4129. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4130. goto exit;
  4131. }
  4132. }
  4133. RESET_MULTI_VALUE_STATS_VARS();
  4134. bench_stats_start(&count, &start);
  4135. do {
  4136. for (times = 0; times < numBlocks || pending > 0; ) {
  4137. bench_async_poll(&pending);
  4138. /* while free pending slots in queue, submit ops */
  4139. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4140. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4141. &times, numBlocks, &pending)) {
  4142. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4143. if (ret == 0) {
  4144. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4145. bench_cipher, bench_size, bench_additional,
  4146. aesAuthAddSz);
  4147. }
  4148. if (ret == 0) {
  4149. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4150. AES_AUTH_TAG_SZ);
  4151. }
  4152. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4153. 0, &times, &pending)) {
  4154. goto exit_aes_gcm_dec;
  4155. }
  4156. }
  4157. } /* for i */
  4158. RECORD_MULTI_VALUE_STATS();
  4159. } /* for times */
  4160. count += times;
  4161. } while (bench_stats_check(start)
  4162. #ifdef MULTI_VALUE_STATISTICS
  4163. || runs < minimum_runs
  4164. #endif
  4165. );
  4166. exit_aes_gcm_dec:
  4167. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4168. start, ret);
  4169. #ifdef MULTI_VALUE_STATISTICS
  4170. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4171. #endif
  4172. #endif /* HAVE_AES_DECRYPT */
  4173. (void)decLabel;
  4174. exit:
  4175. if (ret < 0) {
  4176. printf("bench_aesgcm failed: %d\n", ret);
  4177. }
  4178. #ifdef HAVE_AES_DECRYPT
  4179. if (WC_ARRAY_OK(dec)) {
  4180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4181. wc_AesFree(dec[i]);
  4182. }
  4183. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4184. }
  4185. #endif
  4186. if (WC_ARRAY_OK(enc)) {
  4187. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4188. wc_AesFree(enc[i]);
  4189. }
  4190. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4191. }
  4192. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4193. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4194. }
  4195. #endif
  4196. void bench_aesgcm(int useDeviceID)
  4197. {
  4198. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4199. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4200. && !defined(WOLFSSL_XILINX_CRYPT) \
  4201. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4202. #ifdef HAVE_RENESAS_SYNC
  4203. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4204. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4205. #else
  4206. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4207. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4208. #endif
  4209. #endif
  4210. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4211. && !defined(WOLFSSL_XILINX_CRYPT)
  4212. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4213. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4214. #endif
  4215. #ifdef WOLFSSL_AES_256
  4216. #ifdef HAVE_RENESAS_SYNC
  4217. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4218. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4219. #else
  4220. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4221. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4222. #endif
  4223. #endif
  4224. #ifdef WOLFSSL_AESGCM_STREAM
  4225. #undef AES_GCM_STRING
  4226. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4227. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4228. && !defined(WOLFSSL_XILINX_CRYPT) \
  4229. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4230. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4231. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4232. #endif
  4233. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4234. && !defined(WOLFSSL_XILINX_CRYPT)
  4235. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4236. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4237. #endif
  4238. #ifdef WOLFSSL_AES_256
  4239. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4240. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4241. #endif
  4242. #endif /* WOLFSSL_AESGCM_STREAM */
  4243. #undef AES_GCM_STRING
  4244. }
  4245. /* GMAC */
  4246. void bench_gmac(int useDeviceID)
  4247. {
  4248. int ret, count = 0;
  4249. Gmac gmac;
  4250. double start;
  4251. byte tag[AES_AUTH_TAG_SZ];
  4252. DECLARE_MULTI_VALUE_STATS_VARS()
  4253. /* determine GCM GHASH method */
  4254. #ifdef GCM_SMALL
  4255. const char* gmacStr = "GMAC Small";
  4256. #elif defined(GCM_TABLE)
  4257. const char* gmacStr = "GMAC Table";
  4258. #elif defined(GCM_TABLE_4BIT)
  4259. const char* gmacStr = "GMAC Table 4-bit";
  4260. #elif defined(GCM_WORD32)
  4261. const char* gmacStr = "GMAC Word32";
  4262. #else
  4263. const char* gmacStr = "GMAC Default";
  4264. #endif
  4265. /* init keys */
  4266. XMEMSET(bench_plain, 0, bench_size);
  4267. XMEMSET(tag, 0, sizeof(tag));
  4268. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4269. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4270. useDeviceID ? devId: INVALID_DEVID);
  4271. #ifdef HAVE_RENESAS_SYNC
  4272. wc_GmacSetKey(&gmac, bench_key1, 16);
  4273. #else
  4274. wc_GmacSetKey(&gmac, bench_key, 16);
  4275. #endif
  4276. bench_stats_start(&count, &start);
  4277. do {
  4278. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4279. tag, sizeof(tag));
  4280. count++;
  4281. RECORD_MULTI_VALUE_STATS();
  4282. } while (bench_stats_check(start)
  4283. #ifdef MULTI_VALUE_STATISTICS
  4284. || runs < minimum_runs
  4285. #endif
  4286. );
  4287. wc_AesFree((Aes*)&gmac);
  4288. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4289. #ifdef MULTI_VALUE_STATISTICS
  4290. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4291. #endif
  4292. }
  4293. #endif /* HAVE_AESGCM */
  4294. #ifdef HAVE_AES_ECB
  4295. static void bench_aesecb_internal(int useDeviceID,
  4296. const byte* key, word32 keySz,
  4297. const char* encLabel, const char* decLabel)
  4298. {
  4299. int ret = 0, i, count = 0, times, pending = 0;
  4300. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4301. sizeof(Aes), HEAP_HINT);
  4302. double start;
  4303. DECLARE_MULTI_VALUE_STATS_VARS()
  4304. #ifdef HAVE_FIPS
  4305. const word32 benchSz = AES_BLOCK_SIZE;
  4306. #else
  4307. const word32 benchSz = bench_size;
  4308. #endif
  4309. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4310. sizeof(Aes), HEAP_HINT);
  4311. /* init keys */
  4312. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4313. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4314. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4315. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4316. goto exit;
  4317. }
  4318. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4319. if (ret != 0) {
  4320. printf("AesSetKey failed, ret = %d\n", ret);
  4321. goto exit;
  4322. }
  4323. }
  4324. bench_stats_start(&count, &start);
  4325. do {
  4326. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4327. for (times = 0;
  4328. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4329. ) {
  4330. bench_async_poll(&pending);
  4331. /* while free pending slots in queue, submit ops */
  4332. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4333. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4334. &times, outer_loop_limit, &pending)) {
  4335. #ifdef HAVE_FIPS
  4336. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4337. #else
  4338. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4339. benchSz);
  4340. #endif
  4341. ret = 0;
  4342. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4343. 0, &times, &pending)) {
  4344. goto exit_aes_enc;
  4345. }
  4346. }
  4347. } /* for i */
  4348. RECORD_MULTI_VALUE_STATS();
  4349. } /* for times */
  4350. count += times;
  4351. } while (bench_stats_check(start)
  4352. #ifdef MULTI_VALUE_STATISTICS
  4353. || runs < minimum_runs
  4354. #endif
  4355. );
  4356. exit_aes_enc:
  4357. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4358. start, ret);
  4359. #ifdef MULTI_VALUE_STATISTICS
  4360. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4361. #endif
  4362. #ifdef HAVE_AES_DECRYPT
  4363. /* init keys */
  4364. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4365. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4366. if (ret != 0) {
  4367. printf("AesSetKey failed, ret = %d\n", ret);
  4368. goto exit;
  4369. }
  4370. }
  4371. RESET_MULTI_VALUE_STATS_VARS();
  4372. bench_stats_start(&count, &start);
  4373. do {
  4374. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4375. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4376. bench_async_poll(&pending);
  4377. /* while free pending slots in queue, submit ops */
  4378. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4379. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4380. &times, outer_loop_limit, &pending)) {
  4381. #ifdef HAVE_FIPS
  4382. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4383. #else
  4384. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4385. benchSz);
  4386. #endif
  4387. ret = 0;
  4388. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4389. 0, &times, &pending)) {
  4390. goto exit_aes_dec;
  4391. }
  4392. }
  4393. } /* for i */
  4394. RECORD_MULTI_VALUE_STATS();
  4395. } /* for times */
  4396. count += times;
  4397. } while (bench_stats_check(start)
  4398. #ifdef MULTI_VALUE_STATISTICS
  4399. || runs < minimum_runs
  4400. #endif
  4401. );
  4402. exit_aes_dec:
  4403. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4404. start, ret);
  4405. #ifdef MULTI_VALUE_STATISTICS
  4406. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4407. #endif
  4408. #endif /* HAVE_AES_DECRYPT */
  4409. (void)decLabel;
  4410. exit:
  4411. if (WC_ARRAY_OK(enc)) {
  4412. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4413. wc_AesFree(enc[i]);
  4414. }
  4415. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4416. }
  4417. }
  4418. void bench_aesecb(int useDeviceID)
  4419. {
  4420. #ifdef WOLFSSL_AES_128
  4421. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4422. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4423. #endif
  4424. #ifdef WOLFSSL_AES_192
  4425. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4426. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4427. #endif
  4428. #ifdef WOLFSSL_AES_256
  4429. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4430. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4431. #endif
  4432. }
  4433. #endif /* HAVE_AES_ECB */
  4434. #ifdef WOLFSSL_AES_CFB
  4435. static void bench_aescfb_internal(const byte* key,
  4436. word32 keySz, const byte* iv,
  4437. const char* label)
  4438. {
  4439. Aes enc;
  4440. double start;
  4441. int i, ret, count;
  4442. DECLARE_MULTI_VALUE_STATS_VARS()
  4443. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4444. if (ret != 0) {
  4445. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4446. return;
  4447. }
  4448. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4449. if (ret != 0) {
  4450. printf("AesSetKey failed, ret = %d\n", ret);
  4451. goto out;
  4452. }
  4453. bench_stats_start(&count, &start);
  4454. do {
  4455. for (i = 0; i < numBlocks; i++) {
  4456. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4457. bench_size)) != 0) {
  4458. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4459. goto out;
  4460. }
  4461. RECORD_MULTI_VALUE_STATS();
  4462. }
  4463. count += i;
  4464. } while (bench_stats_check(start)
  4465. #ifdef MULTI_VALUE_STATISTICS
  4466. || runs < minimum_runs
  4467. #endif
  4468. );
  4469. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4470. #ifdef MULTI_VALUE_STATISTICS
  4471. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4472. #endif
  4473. out:
  4474. wc_AesFree(&enc);
  4475. return;
  4476. }
  4477. void bench_aescfb(void)
  4478. {
  4479. #ifdef WOLFSSL_AES_128
  4480. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4481. #endif
  4482. #ifdef WOLFSSL_AES_192
  4483. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4484. #endif
  4485. #ifdef WOLFSSL_AES_256
  4486. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4487. #endif
  4488. }
  4489. #endif /* WOLFSSL_AES_CFB */
  4490. #ifdef WOLFSSL_AES_OFB
  4491. static void bench_aesofb_internal(const byte* key,
  4492. word32 keySz, const byte* iv,
  4493. const char* label)
  4494. {
  4495. Aes enc;
  4496. double start;
  4497. int i, ret, count;
  4498. DECLARE_MULTI_VALUE_STATS_VARS()
  4499. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4500. if (ret != 0) {
  4501. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4502. return;
  4503. }
  4504. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4505. if (ret != 0) {
  4506. printf("AesSetKey failed, ret = %d\n", ret);
  4507. return;
  4508. }
  4509. bench_stats_start(&count, &start);
  4510. do {
  4511. for (i = 0; i < numBlocks; i++) {
  4512. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4513. bench_size)) != 0) {
  4514. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4515. return;
  4516. }
  4517. RECORD_MULTI_VALUE_STATS();
  4518. }
  4519. count += i;
  4520. } while (bench_stats_check(start)
  4521. #ifdef MULTI_VALUE_STATISTICS
  4522. || runs < minimum_runs
  4523. #endif
  4524. );
  4525. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4526. #ifdef MULTI_VALUE_STATISTICS
  4527. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4528. #endif
  4529. wc_AesFree(&enc);
  4530. }
  4531. void bench_aesofb(void)
  4532. {
  4533. #ifdef WOLFSSL_AES_128
  4534. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4535. #endif
  4536. #ifdef WOLFSSL_AES_192
  4537. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4538. #endif
  4539. #ifdef WOLFSSL_AES_256
  4540. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4541. #endif
  4542. }
  4543. #endif /* WOLFSSL_AES_CFB */
  4544. #ifdef WOLFSSL_AES_XTS
  4545. void bench_aesxts(void)
  4546. {
  4547. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4548. double start;
  4549. int i, count, ret;
  4550. DECLARE_MULTI_VALUE_STATS_VARS()
  4551. static const unsigned char k1[] = {
  4552. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4553. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4554. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4555. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4556. };
  4557. static const unsigned char i1[] = {
  4558. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4559. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4560. };
  4561. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4562. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4563. HEAP_HINT, devId);
  4564. if (ret != 0) {
  4565. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4566. goto exit;
  4567. }
  4568. bench_stats_start(&count, &start);
  4569. do {
  4570. for (i = 0; i < numBlocks; i++) {
  4571. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4572. bench_size, i1, sizeof(i1))) != 0) {
  4573. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4574. goto exit;
  4575. }
  4576. RECORD_MULTI_VALUE_STATS();
  4577. }
  4578. count += i;
  4579. } while (bench_stats_check(start)
  4580. #ifdef MULTI_VALUE_STATISTICS
  4581. || runs < minimum_runs
  4582. #endif
  4583. );
  4584. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4585. #ifdef MULTI_VALUE_STATISTICS
  4586. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4587. #endif
  4588. wc_AesXtsFree(aes);
  4589. /* decryption benchmark */
  4590. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4591. HEAP_HINT, devId);
  4592. if (ret != 0) {
  4593. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4594. goto exit;
  4595. }
  4596. RESET_MULTI_VALUE_STATS_VARS();
  4597. bench_stats_start(&count, &start);
  4598. do {
  4599. for (i = 0; i < numBlocks; i++) {
  4600. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4601. bench_size, i1, sizeof(i1))) != 0) {
  4602. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4603. goto exit;
  4604. }
  4605. RECORD_MULTI_VALUE_STATS();
  4606. }
  4607. count += i;
  4608. } while (bench_stats_check(start)
  4609. #ifdef MULTI_VALUE_STATISTICS
  4610. || runs < minimum_runs
  4611. #endif
  4612. );
  4613. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4614. #ifdef MULTI_VALUE_STATISTICS
  4615. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4616. #endif
  4617. exit:
  4618. wc_AesXtsFree(aes);
  4619. WC_FREE_VAR(aes, HEAP_HINT);
  4620. }
  4621. #endif /* WOLFSSL_AES_XTS */
  4622. #ifdef WOLFSSL_AES_COUNTER
  4623. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4624. const byte* iv, const char* label,
  4625. int useDeviceID)
  4626. {
  4627. Aes enc;
  4628. double start;
  4629. int i, count, ret = 0;
  4630. DECLARE_MULTI_VALUE_STATS_VARS()
  4631. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4632. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4633. printf("wc_AesInit failed, ret = %d\n", ret);
  4634. }
  4635. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4636. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4637. return;
  4638. }
  4639. bench_stats_start(&count, &start);
  4640. do {
  4641. for (i = 0; i < numBlocks; i++) {
  4642. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4643. bench_size)) != 0) {
  4644. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4645. return;
  4646. }
  4647. RECORD_MULTI_VALUE_STATS();
  4648. }
  4649. count += i;
  4650. } while (bench_stats_check(start)
  4651. #ifdef MULTI_VALUE_STATISTICS
  4652. || runs < minimum_runs
  4653. #endif
  4654. );
  4655. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4656. #ifdef MULTI_VALUE_STATISTICS
  4657. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4658. #endif
  4659. wc_AesFree(&enc);
  4660. }
  4661. void bench_aesctr(int useDeviceID)
  4662. {
  4663. #ifdef WOLFSSL_AES_128
  4664. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4665. #endif
  4666. #ifdef WOLFSSL_AES_192
  4667. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4668. #endif
  4669. #ifdef WOLFSSL_AES_256
  4670. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4671. #endif
  4672. }
  4673. #endif /* WOLFSSL_AES_COUNTER */
  4674. #ifdef HAVE_AESCCM
  4675. void bench_aesccm(int useDeviceID)
  4676. {
  4677. Aes enc;
  4678. int enc_inited = 0;
  4679. double start;
  4680. int ret, i, count;
  4681. DECLARE_MULTI_VALUE_STATS_VARS()
  4682. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4683. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4684. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4685. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4686. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4687. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4688. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4689. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4690. {
  4691. printf("wc_AesInit failed, ret = %d\n", ret);
  4692. goto exit;
  4693. }
  4694. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4695. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4696. goto exit;
  4697. }
  4698. enc_inited = 1;
  4699. bench_stats_start(&count, &start);
  4700. do {
  4701. for (i = 0; i < numBlocks; i++) {
  4702. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4703. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4704. bench_additional, 0);
  4705. RECORD_MULTI_VALUE_STATS();
  4706. }
  4707. count += i;
  4708. } while (bench_stats_check(start)
  4709. #ifdef MULTI_VALUE_STATISTICS
  4710. || runs < minimum_runs
  4711. #endif
  4712. );
  4713. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4714. bench_size, start, ret);
  4715. #ifdef MULTI_VALUE_STATISTICS
  4716. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4717. #endif
  4718. if (ret != 0) {
  4719. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4720. goto exit;
  4721. }
  4722. #ifdef HAVE_AES_DECRYPT
  4723. RESET_MULTI_VALUE_STATS_VARS();
  4724. bench_stats_start(&count, &start);
  4725. do {
  4726. for (i = 0; i < numBlocks; i++) {
  4727. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4728. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4729. bench_additional, 0);
  4730. RECORD_MULTI_VALUE_STATS();
  4731. }
  4732. count += i;
  4733. } while (bench_stats_check(start)
  4734. #ifdef MULTI_VALUE_STATISTICS
  4735. || runs < minimum_runs
  4736. #endif
  4737. );
  4738. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4739. bench_size, start, ret);
  4740. #ifdef MULTI_VALUE_STATISTICS
  4741. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4742. #endif
  4743. if (ret != 0) {
  4744. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4745. goto exit;
  4746. }
  4747. #endif
  4748. exit:
  4749. if (enc_inited)
  4750. wc_AesFree(&enc);
  4751. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4752. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4753. }
  4754. #endif /* HAVE_AESCCM */
  4755. #ifdef WOLFSSL_AES_SIV
  4756. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4757. encLabel, const char* decLabel)
  4758. {
  4759. int i;
  4760. int ret = 0;
  4761. byte assoc[AES_BLOCK_SIZE];
  4762. byte nonce[AES_BLOCK_SIZE];
  4763. byte siv[AES_BLOCK_SIZE];
  4764. int count = 0;
  4765. double start;
  4766. DECLARE_MULTI_VALUE_STATS_VARS()
  4767. bench_stats_start(&count, &start);
  4768. do {
  4769. for (i = 0; i < numBlocks; i++) {
  4770. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4771. AES_BLOCK_SIZE, bench_plain, bench_size,
  4772. siv, bench_cipher);
  4773. if (ret != 0) {
  4774. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4775. return;
  4776. }
  4777. RECORD_MULTI_VALUE_STATS();
  4778. }
  4779. count += i;
  4780. } while (bench_stats_check(start)
  4781. #ifdef MULTI_VALUE_STATISTICS
  4782. || runs < minimum_runs
  4783. #endif
  4784. );
  4785. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4786. #ifdef MULTI_VALUE_STATISTICS
  4787. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4788. #endif
  4789. RESET_MULTI_VALUE_STATS_VARS();
  4790. bench_stats_start(&count, &start);
  4791. do {
  4792. for (i = 0; i < numBlocks; i++) {
  4793. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4794. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4795. siv, bench_plain);
  4796. if (ret != 0) {
  4797. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4798. return;
  4799. }
  4800. RECORD_MULTI_VALUE_STATS();
  4801. }
  4802. count += i;
  4803. } while (bench_stats_check(start)
  4804. #ifdef MULTI_VALUE_STATISTICS
  4805. || runs < minimum_runs
  4806. #endif
  4807. );
  4808. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4809. #ifdef MULTI_VALUE_STATISTICS
  4810. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4811. #endif
  4812. }
  4813. void bench_aessiv(void)
  4814. {
  4815. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4816. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4817. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4818. }
  4819. #endif /* WOLFSSL_AES_SIV */
  4820. #endif /* !NO_AES */
  4821. #ifdef HAVE_POLY1305
  4822. void bench_poly1305(void)
  4823. {
  4824. Poly1305 enc;
  4825. byte mac[16];
  4826. double start;
  4827. int ret = 0, i, count;
  4828. DECLARE_MULTI_VALUE_STATS_VARS()
  4829. if (digest_stream) {
  4830. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4831. if (ret != 0) {
  4832. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4833. return;
  4834. }
  4835. bench_stats_start(&count, &start);
  4836. do {
  4837. for (i = 0; i < numBlocks; i++) {
  4838. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4839. if (ret != 0) {
  4840. printf("Poly1305Update failed: %d\n", ret);
  4841. break;
  4842. }
  4843. RECORD_MULTI_VALUE_STATS();
  4844. }
  4845. wc_Poly1305Final(&enc, mac);
  4846. count += i;
  4847. } while (bench_stats_check(start)
  4848. #ifdef MULTI_VALUE_STATISTICS
  4849. || runs < minimum_runs
  4850. #endif
  4851. );
  4852. }
  4853. else {
  4854. bench_stats_start(&count, &start);
  4855. do {
  4856. for (i = 0; i < numBlocks; i++) {
  4857. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4858. if (ret != 0) {
  4859. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4860. return;
  4861. }
  4862. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4863. if (ret != 0) {
  4864. printf("Poly1305Update failed: %d\n", ret);
  4865. break;
  4866. }
  4867. wc_Poly1305Final(&enc, mac);
  4868. RECORD_MULTI_VALUE_STATS();
  4869. }
  4870. count += i;
  4871. } while (bench_stats_check(start)
  4872. #ifdef MULTI_VALUE_STATISTICS
  4873. || runs < minimum_runs
  4874. #endif
  4875. );
  4876. }
  4877. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4878. #ifdef MULTI_VALUE_STATISTICS
  4879. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4880. #endif
  4881. }
  4882. #endif /* HAVE_POLY1305 */
  4883. #ifdef HAVE_CAMELLIA
  4884. void bench_camellia(void)
  4885. {
  4886. Camellia cam;
  4887. double start;
  4888. int ret, i, count;
  4889. DECLARE_MULTI_VALUE_STATS_VARS()
  4890. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4891. if (ret != 0) {
  4892. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4893. return;
  4894. }
  4895. bench_stats_start(&count, &start);
  4896. do {
  4897. for (i = 0; i < numBlocks; i++) {
  4898. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4899. bench_size);
  4900. if (ret < 0) {
  4901. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4902. return;
  4903. }
  4904. RECORD_MULTI_VALUE_STATS();
  4905. }
  4906. count += i;
  4907. } while (bench_stats_check(start)
  4908. #ifdef MULTI_VALUE_STATISTICS
  4909. || runs < minimum_runs
  4910. #endif
  4911. );
  4912. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4913. #ifdef MULTI_VALUE_STATISTICS
  4914. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4915. #endif
  4916. }
  4917. #endif
  4918. #ifdef WOLFSSL_SM4_CBC
  4919. void bench_sm4_cbc(void)
  4920. {
  4921. wc_Sm4 sm4;
  4922. double start;
  4923. int ret;
  4924. int i;
  4925. int count;
  4926. DECLARE_MULTI_VALUE_STATS_VARS()
  4927. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4928. if (ret != 0) {
  4929. printf("Sm4SetKey failed, ret = %d\n", ret);
  4930. return;
  4931. }
  4932. ret = wc_Sm4SetIV(&sm4, bench_iv);
  4933. if (ret != 0) {
  4934. printf("Sm4SetIV failed, ret = %d\n", ret);
  4935. return;
  4936. }
  4937. bench_stats_start(&count, &start);
  4938. do {
  4939. for (i = 0; i < numBlocks; i++) {
  4940. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  4941. if (ret < 0) {
  4942. printf("Sm4CbcEncrypt failed: %d\n", ret);
  4943. return;
  4944. }
  4945. RECORD_MULTI_VALUE_STATS();
  4946. }
  4947. count += i;
  4948. } while (bench_stats_check(start)
  4949. #ifdef MULTI_VALUE_STATISTICS
  4950. || runs < minimum_runs
  4951. #endif
  4952. );
  4953. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  4954. #ifdef MULTI_VALUE_STATISTICS
  4955. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4956. #endif
  4957. RESET_MULTI_VALUE_STATS_VARS();
  4958. bench_stats_start(&count, &start);
  4959. do {
  4960. for (i = 0; i < numBlocks; i++) {
  4961. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  4962. if (ret < 0) {
  4963. printf("Sm4CbcDecrypt failed: %d\n", ret);
  4964. return;
  4965. }
  4966. RECORD_MULTI_VALUE_STATS();
  4967. }
  4968. count += i;
  4969. } while (bench_stats_check(start)
  4970. #ifdef MULTI_VALUE_STATISTICS
  4971. || runs < minimum_runs
  4972. #endif
  4973. );
  4974. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  4975. #ifdef MULTI_VALUE_STATISTICS
  4976. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4977. #endif
  4978. }
  4979. #endif
  4980. #ifdef WOLFSSL_SM4_GCM
  4981. void bench_sm4_gcm(void)
  4982. {
  4983. wc_Sm4 sm4;
  4984. double start;
  4985. int ret;
  4986. int i;
  4987. int count;
  4988. DECLARE_MULTI_VALUE_STATS_VARS()
  4989. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4990. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4991. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4992. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4993. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4994. if (ret != 0) {
  4995. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  4996. goto exit;
  4997. }
  4998. bench_stats_start(&count, &start);
  4999. do {
  5000. for (i = 0; i < numBlocks; i++) {
  5001. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5002. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5003. bench_additional, aesAuthAddSz);
  5004. if (ret < 0) {
  5005. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5006. goto exit;
  5007. }
  5008. RECORD_MULTI_VALUE_STATS();
  5009. }
  5010. count += i;
  5011. } while (bench_stats_check(start)
  5012. #ifdef MULTI_VALUE_STATISTICS
  5013. || runs < minimum_runs
  5014. #endif
  5015. );
  5016. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5017. #ifdef MULTI_VALUE_STATISTICS
  5018. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5019. #endif
  5020. RESET_MULTI_VALUE_STATS_VARS();
  5021. bench_stats_start(&count, &start);
  5022. do {
  5023. for (i = 0; i < numBlocks; i++) {
  5024. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5025. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5026. bench_additional, aesAuthAddSz);
  5027. if (ret < 0) {
  5028. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5029. goto exit;
  5030. }
  5031. RECORD_MULTI_VALUE_STATS();
  5032. }
  5033. count += i;
  5034. } while (bench_stats_check(start)
  5035. #ifdef MULTI_VALUE_STATISTICS
  5036. || runs < minimum_runs
  5037. #endif
  5038. );
  5039. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5040. #ifdef MULTI_VALUE_STATISTICS
  5041. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5042. #endif
  5043. exit:
  5044. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5045. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5046. }
  5047. #endif
  5048. #ifdef WOLFSSL_SM4_CCM
  5049. void bench_sm4_ccm(void)
  5050. {
  5051. wc_Sm4 enc;
  5052. double start;
  5053. int ret, i, count;
  5054. DECLARE_MULTI_VALUE_STATS_VARS()
  5055. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5056. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5057. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5058. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5059. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5060. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5061. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5062. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5063. goto exit;
  5064. }
  5065. bench_stats_start(&count, &start);
  5066. do {
  5067. for (i = 0; i < numBlocks; i++) {
  5068. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5069. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5070. bench_additional, 0);
  5071. RECORD_MULTI_VALUE_STATS();
  5072. }
  5073. count += i;
  5074. } while (bench_stats_check(start)
  5075. #ifdef MULTI_VALUE_STATISTICS
  5076. || runs < minimum_runs
  5077. #endif
  5078. );
  5079. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5080. #ifdef MULTI_VALUE_STATISTICS
  5081. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5082. #endif
  5083. if (ret != 0) {
  5084. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5085. goto exit;
  5086. }
  5087. RESET_MULTI_VALUE_STATS_VARS();
  5088. bench_stats_start(&count, &start);
  5089. do {
  5090. for (i = 0; i < numBlocks; i++) {
  5091. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5092. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5093. bench_additional, 0);
  5094. RECORD_MULTI_VALUE_STATS();
  5095. }
  5096. count += i;
  5097. } while (bench_stats_check(start)
  5098. #ifdef MULTI_VALUE_STATISTICS
  5099. || runs < minimum_runs
  5100. #endif
  5101. );
  5102. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5103. #ifdef MULTI_VALUE_STATISTICS
  5104. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5105. #endif
  5106. if (ret != 0) {
  5107. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5108. goto exit;
  5109. }
  5110. exit:
  5111. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5112. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5113. }
  5114. #endif /* HAVE_AESCCM */
  5115. #ifndef NO_DES3
  5116. void bench_des(int useDeviceID)
  5117. {
  5118. int ret = 0, i, count = 0, times, pending = 0;
  5119. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5120. sizeof(Des3), HEAP_HINT);
  5121. double start;
  5122. DECLARE_MULTI_VALUE_STATS_VARS()
  5123. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5124. sizeof(Des3), HEAP_HINT);
  5125. /* init keys */
  5126. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5127. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5128. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5129. printf("Des3Init failed, ret = %d\n", ret);
  5130. goto exit;
  5131. }
  5132. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5133. if (ret != 0) {
  5134. printf("Des3_SetKey failed, ret = %d\n", ret);
  5135. goto exit;
  5136. }
  5137. }
  5138. bench_stats_start(&count, &start);
  5139. do {
  5140. for (times = 0; times < numBlocks || pending > 0; ) {
  5141. bench_async_poll(&pending);
  5142. /* while free pending slots in queue, submit ops */
  5143. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5144. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5145. &times, numBlocks, &pending)) {
  5146. ret = wc_Des3_CbcEncrypt(enc[i],
  5147. bench_cipher,
  5148. bench_plain, bench_size);
  5149. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5150. 0, &times, &pending)) {
  5151. goto exit_3des;
  5152. }
  5153. }
  5154. } /* for i */
  5155. RECORD_MULTI_VALUE_STATS();
  5156. } /* for times */
  5157. count += times;
  5158. } while (bench_stats_check(start)
  5159. #ifdef MULTI_VALUE_STATISTICS
  5160. || runs < minimum_runs
  5161. #endif
  5162. );
  5163. exit_3des:
  5164. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5165. #ifdef MULTI_VALUE_STATISTICS
  5166. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5167. #endif
  5168. exit:
  5169. if (WC_ARRAY_OK(enc)) {
  5170. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5171. wc_Des3Free(enc[i]);
  5172. }
  5173. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5174. }
  5175. }
  5176. #endif /* !NO_DES3 */
  5177. #ifndef NO_RC4
  5178. void bench_arc4(int useDeviceID)
  5179. {
  5180. int ret = 0, i, count = 0, times, pending = 0;
  5181. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5182. sizeof(Arc4), HEAP_HINT);
  5183. double start;
  5184. DECLARE_MULTI_VALUE_STATS_VARS()
  5185. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5186. sizeof(Arc4), HEAP_HINT);
  5187. /* init keys */
  5188. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5189. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5190. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5191. printf("Arc4Init failed, ret = %d\n", ret);
  5192. goto exit;
  5193. }
  5194. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5195. if (ret != 0) {
  5196. printf("Arc4SetKey failed, ret = %d\n", ret);
  5197. goto exit;
  5198. }
  5199. }
  5200. bench_stats_start(&count, &start);
  5201. do {
  5202. for (times = 0; times < numBlocks || pending > 0; ) {
  5203. bench_async_poll(&pending);
  5204. /* while free pending slots in queue, submit ops */
  5205. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5206. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5207. &times, numBlocks, &pending)) {
  5208. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5209. bench_size);
  5210. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5211. 0, &times, &pending)) {
  5212. goto exit_arc4;
  5213. }
  5214. }
  5215. } /* for i */
  5216. RECORD_MULTI_VALUE_STATS();
  5217. } /* for times */
  5218. count += times;
  5219. } while (bench_stats_check(start)
  5220. #ifdef MULTI_VALUE_STATISTICS
  5221. || runs < minimum_runs
  5222. #endif
  5223. );
  5224. exit_arc4:
  5225. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5226. #ifdef MULTI_VALUE_STATISTICS
  5227. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5228. #endif
  5229. exit:
  5230. if (WC_ARRAY_OK(enc)) {
  5231. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5232. wc_Arc4Free(enc[i]);
  5233. }
  5234. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5235. }
  5236. }
  5237. #endif /* !NO_RC4 */
  5238. #ifdef HAVE_CHACHA
  5239. void bench_chacha(void)
  5240. {
  5241. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5242. double start;
  5243. int ret, i, count;
  5244. DECLARE_MULTI_VALUE_STATS_VARS()
  5245. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5246. XMEMSET(enc, 0, sizeof(ChaCha));
  5247. wc_Chacha_SetKey(enc, bench_key, 16);
  5248. if (encrypt_only) {
  5249. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5250. if (ret < 0) {
  5251. printf("wc_Chacha_SetIV error: %d\n", ret);
  5252. goto exit;
  5253. }
  5254. bench_stats_start(&count, &start);
  5255. do {
  5256. for (i = 0; i < numBlocks; i++) {
  5257. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5258. bench_size);
  5259. if (ret < 0) {
  5260. printf("wc_Chacha_Process error: %d\n", ret);
  5261. goto exit;
  5262. }
  5263. RECORD_MULTI_VALUE_STATS();
  5264. }
  5265. count += i;
  5266. } while (bench_stats_check(start)
  5267. #ifdef MULTI_VALUE_STATISTICS
  5268. || runs < minimum_runs
  5269. #endif
  5270. );
  5271. }
  5272. else {
  5273. bench_stats_start(&count, &start);
  5274. do {
  5275. for (i = 0; i < numBlocks; i++) {
  5276. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5277. if (ret < 0) {
  5278. printf("wc_Chacha_SetIV error: %d\n", ret);
  5279. goto exit;
  5280. }
  5281. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5282. bench_size);
  5283. if (ret < 0) {
  5284. printf("wc_Chacha_Process error: %d\n", ret);
  5285. goto exit;
  5286. }
  5287. RECORD_MULTI_VALUE_STATS();
  5288. }
  5289. count += i;
  5290. } while (bench_stats_check(start)
  5291. #ifdef MULTI_VALUE_STATISTICS
  5292. || runs < minimum_runs
  5293. #endif
  5294. );
  5295. }
  5296. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5297. #ifdef MULTI_VALUE_STATISTICS
  5298. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5299. #endif
  5300. exit:
  5301. WC_FREE_VAR(enc, HEAP_HINT);
  5302. }
  5303. #endif /* HAVE_CHACHA*/
  5304. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5305. void bench_chacha20_poly1305_aead(void)
  5306. {
  5307. double start;
  5308. int ret = 0, i, count;
  5309. DECLARE_MULTI_VALUE_STATS_VARS()
  5310. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5311. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5312. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5313. bench_stats_start(&count, &start);
  5314. do {
  5315. for (i = 0; i < numBlocks; i++) {
  5316. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5317. bench_plain, bench_size, bench_cipher, authTag);
  5318. if (ret < 0) {
  5319. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5320. goto exit;
  5321. }
  5322. RECORD_MULTI_VALUE_STATS();
  5323. }
  5324. count += i;
  5325. } while (bench_stats_check(start)
  5326. #ifdef MULTI_VALUE_STATISTICS
  5327. || runs < minimum_runs
  5328. #endif
  5329. );
  5330. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5331. #ifdef MULTI_VALUE_STATISTICS
  5332. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5333. #endif
  5334. exit:
  5335. WC_FREE_VAR(authTag, HEAP_HINT);
  5336. }
  5337. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5338. #ifndef NO_MD5
  5339. void bench_md5(int useDeviceID)
  5340. {
  5341. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5342. sizeof(wc_Md5), HEAP_HINT);
  5343. double start = 0;
  5344. int ret = 0, i, count = 0, times, pending = 0;
  5345. DECLARE_MULTI_VALUE_STATS_VARS()
  5346. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5347. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5348. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5349. sizeof(wc_Md5), HEAP_HINT);
  5350. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5351. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5352. if (digest_stream) {
  5353. /* init keys */
  5354. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5355. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5356. useDeviceID ? devId : INVALID_DEVID);
  5357. if (ret != 0) {
  5358. printf("InitMd5_ex failed, ret = %d\n", ret);
  5359. goto exit;
  5360. }
  5361. #ifdef WOLFSSL_PIC32MZ_HASH
  5362. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5363. #endif
  5364. }
  5365. bench_stats_start(&count, &start);
  5366. do {
  5367. for (times = 0; times < numBlocks || pending > 0; ) {
  5368. bench_async_poll(&pending);
  5369. /* while free pending slots in queue, submit ops */
  5370. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5371. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5372. 0, &times, numBlocks, &pending)) {
  5373. ret = wc_Md5Update(hash[i], bench_plain,
  5374. bench_size);
  5375. if (!bench_async_handle(&ret,
  5376. BENCH_ASYNC_GET_DEV(hash[i]),
  5377. 0, &times, &pending)) {
  5378. goto exit_md5;
  5379. }
  5380. }
  5381. } /* for i */
  5382. RECORD_MULTI_VALUE_STATS();
  5383. } /* for times */
  5384. count += times;
  5385. times = 0;
  5386. do {
  5387. bench_async_poll(&pending);
  5388. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5389. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5390. 0, &times, numBlocks, &pending)) {
  5391. ret = wc_Md5Final(hash[i], digest[i]);
  5392. if (!bench_async_handle(&ret,
  5393. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5394. &times, &pending)) {
  5395. goto exit_md5;
  5396. }
  5397. }
  5398. } /* for i */
  5399. } while (pending > 0);
  5400. } while (bench_stats_check(start)
  5401. #ifdef MULTI_VALUE_STATISTICS
  5402. || runs < minimum_runs
  5403. #endif
  5404. );
  5405. }
  5406. else {
  5407. bench_stats_start(&count, &start);
  5408. do {
  5409. for (times = 0; times < numBlocks; times++) {
  5410. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5411. if (ret == 0)
  5412. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5413. if (ret == 0)
  5414. ret = wc_Md5Final(hash[0], digest[0]);
  5415. if (ret != 0)
  5416. goto exit_md5;
  5417. RECORD_MULTI_VALUE_STATS();
  5418. } /* for times */
  5419. count += times;
  5420. } while (bench_stats_check(start)
  5421. #ifdef MULTI_VALUE_STATISTICS
  5422. || runs < minimum_runs
  5423. #endif
  5424. );
  5425. }
  5426. exit_md5:
  5427. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5428. #ifdef MULTI_VALUE_STATISTICS
  5429. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5430. #endif
  5431. exit:
  5432. #ifdef WOLFSSL_ASYNC_CRYPT
  5433. if (WC_ARRAY_OK(hash)) {
  5434. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5435. wc_Md5Free(hash[i]);
  5436. }
  5437. }
  5438. #endif
  5439. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5440. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5441. }
  5442. #endif /* !NO_MD5 */
  5443. #ifndef NO_SHA
  5444. void bench_sha(int useDeviceID)
  5445. {
  5446. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5447. sizeof(wc_Sha), HEAP_HINT);
  5448. double start;
  5449. int ret = 0, i, count = 0, times, pending = 0;
  5450. DECLARE_MULTI_VALUE_STATS_VARS()
  5451. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5452. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5453. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5454. sizeof(wc_Sha), HEAP_HINT);
  5455. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5456. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5457. if (digest_stream) {
  5458. /* init keys */
  5459. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5460. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5461. useDeviceID ? devId : INVALID_DEVID);
  5462. if (ret != 0) {
  5463. printf("InitSha failed, ret = %d\n", ret);
  5464. goto exit;
  5465. }
  5466. #ifdef WOLFSSL_PIC32MZ_HASH
  5467. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5468. #endif
  5469. }
  5470. bench_stats_start(&count, &start);
  5471. do {
  5472. for (times = 0; times < numBlocks || pending > 0; ) {
  5473. bench_async_poll(&pending);
  5474. /* while free pending slots in queue, submit ops */
  5475. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5476. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5477. 0, &times, numBlocks, &pending)) {
  5478. ret = wc_ShaUpdate(hash[i], bench_plain,
  5479. bench_size);
  5480. if (!bench_async_handle(&ret,
  5481. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5482. &times, &pending)) {
  5483. goto exit_sha;
  5484. }
  5485. }
  5486. } /* for i */
  5487. RECORD_MULTI_VALUE_STATS();
  5488. } /* for times */
  5489. count += times;
  5490. times = 0;
  5491. do {
  5492. bench_async_poll(&pending);
  5493. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5494. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5495. 0, &times, numBlocks, &pending)) {
  5496. ret = wc_ShaFinal(hash[i], digest[i]);
  5497. if (!bench_async_handle(&ret,
  5498. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5499. &times, &pending)) {
  5500. goto exit_sha;
  5501. }
  5502. }
  5503. } /* for i */
  5504. } while (pending > 0);
  5505. } while (bench_stats_check(start)
  5506. #ifdef MULTI_VALUE_STATISTICS
  5507. || runs < minimum_runs
  5508. #endif
  5509. );
  5510. }
  5511. else {
  5512. bench_stats_start(&count, &start);
  5513. do {
  5514. for (times = 0; times < numBlocks; times++) {
  5515. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5516. useDeviceID ? devId : INVALID_DEVID);
  5517. if (ret == 0)
  5518. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5519. if (ret == 0)
  5520. ret = wc_ShaFinal(hash[0], digest[0]);
  5521. if (ret != 0)
  5522. goto exit_sha;
  5523. RECORD_MULTI_VALUE_STATS();
  5524. } /* for times */
  5525. count += times;
  5526. } while (bench_stats_check(start)
  5527. #ifdef MULTI_VALUE_STATISTICS
  5528. || runs < minimum_runs
  5529. #endif
  5530. );
  5531. }
  5532. exit_sha:
  5533. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5534. #ifdef MULTI_VALUE_STATISTICS
  5535. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5536. #endif
  5537. exit:
  5538. if (WC_ARRAY_OK(hash)) {
  5539. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5540. wc_ShaFree(hash[i]);
  5541. }
  5542. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5543. }
  5544. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5545. }
  5546. #endif /* NO_SHA */
  5547. #ifdef WOLFSSL_SHA224
  5548. void bench_sha224(int useDeviceID)
  5549. {
  5550. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5551. sizeof(wc_Sha224), HEAP_HINT);
  5552. double start;
  5553. int ret = 0, i, count = 0, times, pending = 0;
  5554. DECLARE_MULTI_VALUE_STATS_VARS()
  5555. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5556. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5557. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5558. sizeof(wc_Sha224), HEAP_HINT);
  5559. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5560. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5561. if (digest_stream) {
  5562. /* init keys */
  5563. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5564. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5565. useDeviceID ? devId : INVALID_DEVID);
  5566. if (ret != 0) {
  5567. printf("InitSha224_ex failed, ret = %d\n", ret);
  5568. goto exit;
  5569. }
  5570. }
  5571. bench_stats_start(&count, &start);
  5572. do {
  5573. for (times = 0; times < numBlocks || pending > 0; ) {
  5574. bench_async_poll(&pending);
  5575. /* while free pending slots in queue, submit ops */
  5576. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5577. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5578. 0, &times, numBlocks, &pending)) {
  5579. ret = wc_Sha224Update(hash[i], bench_plain,
  5580. bench_size);
  5581. if (!bench_async_handle(&ret,
  5582. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5583. &times, &pending)) {
  5584. goto exit_sha224;
  5585. }
  5586. }
  5587. } /* for i */
  5588. RECORD_MULTI_VALUE_STATS();
  5589. } /* for times */
  5590. count += times;
  5591. times = 0;
  5592. do {
  5593. bench_async_poll(&pending);
  5594. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5595. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5596. 0, &times, numBlocks, &pending)) {
  5597. ret = wc_Sha224Final(hash[i], digest[i]);
  5598. if (!bench_async_handle(&ret,
  5599. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5600. &times, &pending)) {
  5601. goto exit_sha224;
  5602. }
  5603. }
  5604. } /* for i */
  5605. } while (pending > 0);
  5606. } while (bench_stats_check(start)
  5607. #ifdef MULTI_VALUE_STATISTICS
  5608. || runs < minimum_runs
  5609. #endif
  5610. );
  5611. }
  5612. else {
  5613. bench_stats_start(&count, &start);
  5614. do {
  5615. for (times = 0; times < numBlocks; times++) {
  5616. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5617. useDeviceID ? devId : INVALID_DEVID);
  5618. if (ret == 0)
  5619. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5620. if (ret == 0)
  5621. ret = wc_Sha224Final(hash[0], digest[0]);
  5622. if (ret != 0)
  5623. goto exit_sha224;
  5624. } /* for times */
  5625. count += times;
  5626. } while (bench_stats_check(start)
  5627. #ifdef MULTI_VALUE_STATISTICS
  5628. || runs < minimum_runs
  5629. #endif
  5630. );
  5631. }
  5632. exit_sha224:
  5633. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5634. bench_size, start, ret);
  5635. #ifdef MULTI_VALUE_STATISTICS
  5636. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5637. #endif
  5638. exit:
  5639. if (WC_ARRAY_OK(hash)) {
  5640. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5641. wc_Sha224Free(hash[i]);
  5642. }
  5643. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5644. }
  5645. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5646. }
  5647. #endif
  5648. #ifndef NO_SHA256
  5649. void bench_sha256(int useDeviceID)
  5650. {
  5651. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5652. sizeof(wc_Sha256), HEAP_HINT);
  5653. double start;
  5654. int ret = 0, i, count = 0, times, pending = 0;
  5655. DECLARE_MULTI_VALUE_STATS_VARS()
  5656. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5657. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5658. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5659. sizeof(wc_Sha256), HEAP_HINT);
  5660. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5661. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5662. if (digest_stream) {
  5663. /* init keys */
  5664. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5665. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5666. useDeviceID ? devId: INVALID_DEVID);
  5667. if (ret != 0) {
  5668. printf("InitSha256_ex failed, ret = %d\n", ret);
  5669. goto exit;
  5670. }
  5671. #ifdef WOLFSSL_PIC32MZ_HASH
  5672. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5673. #endif
  5674. }
  5675. bench_stats_start(&count, &start);
  5676. do {
  5677. for (times = 0; times < numBlocks || pending > 0; ) {
  5678. bench_async_poll(&pending);
  5679. /* while free pending slots in queue, submit ops */
  5680. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5681. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5682. 0, &times, numBlocks, &pending)) {
  5683. ret = wc_Sha256Update(hash[i], bench_plain,
  5684. bench_size);
  5685. if (!bench_async_handle(&ret,
  5686. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5687. &times, &pending)) {
  5688. goto exit_sha256;
  5689. }
  5690. }
  5691. } /* for i */
  5692. RECORD_MULTI_VALUE_STATS();
  5693. } /* for times */
  5694. count += times;
  5695. times = 0;
  5696. do {
  5697. bench_async_poll(&pending);
  5698. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5699. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5700. 0, &times, numBlocks, &pending)) {
  5701. ret = wc_Sha256Final(hash[i], digest[i]);
  5702. if (!bench_async_handle(&ret,
  5703. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5704. &times, &pending)) {
  5705. goto exit_sha256;
  5706. }
  5707. }
  5708. } /* for i */
  5709. } while (pending > 0);
  5710. } while (bench_stats_check(start)
  5711. #ifdef MULTI_VALUE_STATISTICS
  5712. || runs < minimum_runs
  5713. #endif
  5714. );
  5715. }
  5716. else {
  5717. bench_stats_start(&count, &start);
  5718. do {
  5719. for (times = 0; times < numBlocks; times++) {
  5720. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5721. useDeviceID ? devId: INVALID_DEVID);
  5722. if (ret == 0)
  5723. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5724. if (ret == 0)
  5725. ret = wc_Sha256Final(hash[0], digest[0]);
  5726. if (ret != 0)
  5727. goto exit_sha256;
  5728. RECORD_MULTI_VALUE_STATS();
  5729. } /* for times */
  5730. count += times;
  5731. } while (bench_stats_check(start)
  5732. #ifdef MULTI_VALUE_STATISTICS
  5733. || runs < minimum_runs
  5734. #endif
  5735. );
  5736. }
  5737. exit_sha256:
  5738. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5739. start, ret);
  5740. #ifdef MULTI_VALUE_STATISTICS
  5741. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5742. #endif
  5743. exit:
  5744. if (WC_ARRAY_OK(hash)) {
  5745. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5746. wc_Sha256Free(hash[i]);
  5747. }
  5748. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5749. }
  5750. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5751. }
  5752. #endif
  5753. #ifdef WOLFSSL_SHA384
  5754. void bench_sha384(int useDeviceID)
  5755. {
  5756. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5757. sizeof(wc_Sha384), HEAP_HINT);
  5758. double start;
  5759. int ret = 0, i, count = 0, times, pending = 0;
  5760. DECLARE_MULTI_VALUE_STATS_VARS()
  5761. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5762. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5763. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5764. sizeof(wc_Sha384), HEAP_HINT);
  5765. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5766. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5767. if (digest_stream) {
  5768. /* init keys */
  5769. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5770. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5771. useDeviceID ? devId : INVALID_DEVID);
  5772. if (ret != 0) {
  5773. printf("InitSha384_ex failed, ret = %d\n", ret);
  5774. goto exit;
  5775. }
  5776. }
  5777. bench_stats_start(&count, &start);
  5778. do {
  5779. for (times = 0; times < numBlocks || pending > 0; ) {
  5780. bench_async_poll(&pending);
  5781. /* while free pending slots in queue, submit ops */
  5782. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5783. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5784. 0, &times, numBlocks, &pending)) {
  5785. ret = wc_Sha384Update(hash[i], bench_plain,
  5786. bench_size);
  5787. if (!bench_async_handle(&ret,
  5788. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5789. &times, &pending)) {
  5790. goto exit_sha384;
  5791. }
  5792. }
  5793. } /* for i */
  5794. RECORD_MULTI_VALUE_STATS();
  5795. } /* for times */
  5796. count += times;
  5797. times = 0;
  5798. do {
  5799. bench_async_poll(&pending);
  5800. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5801. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5802. 0, &times, numBlocks, &pending)) {
  5803. ret = wc_Sha384Final(hash[i], digest[i]);
  5804. if (!bench_async_handle(&ret,
  5805. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5806. &times, &pending)) {
  5807. goto exit_sha384;
  5808. }
  5809. }
  5810. } /* for i */
  5811. } while (pending > 0);
  5812. } while (bench_stats_check(start)
  5813. #ifdef MULTI_VALUE_STATISTICS
  5814. || runs < minimum_runs
  5815. #endif
  5816. );
  5817. }
  5818. else {
  5819. bench_stats_start(&count, &start);
  5820. do {
  5821. for (times = 0; times < numBlocks; times++) {
  5822. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5823. useDeviceID ? devId : INVALID_DEVID);
  5824. if (ret == 0)
  5825. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5826. if (ret == 0)
  5827. ret = wc_Sha384Final(hash[0], digest[0]);
  5828. if (ret != 0)
  5829. goto exit_sha384;
  5830. RECORD_MULTI_VALUE_STATS();
  5831. } /* for times */
  5832. count += times;
  5833. } while (bench_stats_check(start)
  5834. #ifdef MULTI_VALUE_STATISTICS
  5835. || runs < minimum_runs
  5836. #endif
  5837. );
  5838. }
  5839. exit_sha384:
  5840. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5841. start, ret);
  5842. #ifdef MULTI_VALUE_STATISTICS
  5843. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5844. #endif
  5845. exit:
  5846. if (WC_ARRAY_OK(hash)) {
  5847. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5848. wc_Sha384Free(hash[i]);
  5849. }
  5850. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5851. }
  5852. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5853. }
  5854. #endif
  5855. #ifdef WOLFSSL_SHA512
  5856. void bench_sha512(int useDeviceID)
  5857. {
  5858. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5859. sizeof(wc_Sha512), HEAP_HINT);
  5860. double start;
  5861. int ret = 0, i, count = 0, times, pending = 0;
  5862. DECLARE_MULTI_VALUE_STATS_VARS()
  5863. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5864. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5865. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5866. sizeof(wc_Sha512), HEAP_HINT);
  5867. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5868. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5869. if (digest_stream) {
  5870. /* init keys */
  5871. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5872. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5873. useDeviceID ? devId : INVALID_DEVID);
  5874. if (ret != 0) {
  5875. printf("InitSha512_ex failed, ret = %d\n", ret);
  5876. goto exit;
  5877. }
  5878. }
  5879. bench_stats_start(&count, &start);
  5880. do {
  5881. for (times = 0; times < numBlocks || pending > 0; ) {
  5882. bench_async_poll(&pending);
  5883. /* while free pending slots in queue, submit ops */
  5884. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5885. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5886. 0, &times, numBlocks, &pending)) {
  5887. ret = wc_Sha512Update(hash[i], bench_plain,
  5888. bench_size);
  5889. if (!bench_async_handle(&ret,
  5890. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5891. &times, &pending)) {
  5892. goto exit_sha512;
  5893. }
  5894. }
  5895. } /* for i */
  5896. RECORD_MULTI_VALUE_STATS();
  5897. } /* for times */
  5898. count += times;
  5899. times = 0;
  5900. do {
  5901. bench_async_poll(&pending);
  5902. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5903. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5904. 0, &times, numBlocks, &pending)) {
  5905. ret = wc_Sha512Final(hash[i], digest[i]);
  5906. if (!bench_async_handle(&ret,
  5907. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5908. &times, &pending)) {
  5909. goto exit_sha512;
  5910. }
  5911. }
  5912. } /* for i */
  5913. } while (pending > 0);
  5914. } while (bench_stats_check(start)
  5915. #ifdef MULTI_VALUE_STATISTICS
  5916. || runs < minimum_runs
  5917. #endif
  5918. );
  5919. }
  5920. else {
  5921. bench_stats_start(&count, &start);
  5922. do {
  5923. for (times = 0; times < numBlocks; times++) {
  5924. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5925. useDeviceID ? devId : INVALID_DEVID);
  5926. if (ret == 0)
  5927. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  5928. if (ret == 0)
  5929. ret = wc_Sha512Final(hash[0], digest[0]);
  5930. if (ret != 0)
  5931. goto exit_sha512;
  5932. RECORD_MULTI_VALUE_STATS();
  5933. } /* for times */
  5934. count += times;
  5935. } while (bench_stats_check(start)
  5936. #ifdef MULTI_VALUE_STATISTICS
  5937. || runs < minimum_runs
  5938. #endif
  5939. );
  5940. }
  5941. exit_sha512:
  5942. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  5943. start, ret);
  5944. #ifdef MULTI_VALUE_STATISTICS
  5945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5946. #endif
  5947. exit:
  5948. if (WC_ARRAY_OK(hash)) {
  5949. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5950. wc_Sha512Free(hash[i]);
  5951. }
  5952. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5953. }
  5954. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5955. }
  5956. #if !defined(WOLFSSL_NOSHA512_224) && \
  5957. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  5958. void bench_sha512_224(int useDeviceID)
  5959. {
  5960. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  5961. sizeof(wc_Sha512_224), HEAP_HINT);
  5962. double start;
  5963. int ret = 0, i, count = 0, times, pending = 0;
  5964. DECLARE_MULTI_VALUE_STATS_VARS()
  5965. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5966. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  5967. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  5968. sizeof(wc_Sha512_224), HEAP_HINT);
  5969. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5970. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  5971. if (digest_stream) {
  5972. /* init keys */
  5973. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5974. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  5975. useDeviceID ? devId : INVALID_DEVID);
  5976. if (ret != 0) {
  5977. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  5978. goto exit;
  5979. }
  5980. }
  5981. bench_stats_start(&count, &start);
  5982. do {
  5983. for (times = 0; times < numBlocks || pending > 0; ) {
  5984. bench_async_poll(&pending);
  5985. /* while free pending slots in queue, submit ops */
  5986. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5987. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5988. 0, &times, numBlocks, &pending)) {
  5989. ret = wc_Sha512_224Update(hash[i], bench_plain,
  5990. bench_size);
  5991. if (!bench_async_handle(&ret,
  5992. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5993. &times, &pending)) {
  5994. goto exit_sha512_224;
  5995. }
  5996. }
  5997. } /* for i */
  5998. RECORD_MULTI_VALUE_STATS();
  5999. } /* for times */
  6000. count += times;
  6001. times = 0;
  6002. do {
  6003. bench_async_poll(&pending);
  6004. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6005. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6006. 0, &times, numBlocks, &pending)) {
  6007. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6008. if (!bench_async_handle(&ret,
  6009. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6010. &times, &pending)) {
  6011. goto exit_sha512_224;
  6012. }
  6013. }
  6014. } /* for i */
  6015. } while (pending > 0);
  6016. } while (bench_stats_check(start)
  6017. #ifdef MULTI_VALUE_STATISTICS
  6018. || runs < minimum_runs
  6019. #endif
  6020. );
  6021. }
  6022. else {
  6023. bench_stats_start(&count, &start);
  6024. do {
  6025. for (times = 0; times < numBlocks; times++) {
  6026. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6027. useDeviceID ? devId : INVALID_DEVID);
  6028. if (ret == 0)
  6029. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6030. if (ret == 0)
  6031. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6032. if (ret != 0)
  6033. goto exit_sha512_224;
  6034. RECORD_MULTI_VALUE_STATS();
  6035. } /* for times */
  6036. count += times;
  6037. } while (bench_stats_check(start)
  6038. #ifdef MULTI_VALUE_STATISTICS
  6039. || runs < minimum_runs
  6040. #endif
  6041. );
  6042. }
  6043. exit_sha512_224:
  6044. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6045. start, ret);
  6046. #ifdef MULTI_VALUE_STATISTICS
  6047. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6048. #endif
  6049. exit:
  6050. if (WC_ARRAY_OK(hash)) {
  6051. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6052. wc_Sha512_224Free(hash[i]);
  6053. }
  6054. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6055. }
  6056. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6057. }
  6058. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6059. #if !defined(WOLFSSL_NOSHA512_256) && \
  6060. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6061. void bench_sha512_256(int useDeviceID)
  6062. {
  6063. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6064. sizeof(wc_Sha512_256), HEAP_HINT);
  6065. double start;
  6066. int ret = 0, i, count = 0, times, pending = 0;
  6067. DECLARE_MULTI_VALUE_STATS_VARS()
  6068. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6069. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6070. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6071. sizeof(wc_Sha512_256), HEAP_HINT);
  6072. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6073. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6074. if (digest_stream) {
  6075. /* init keys */
  6076. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6077. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6078. useDeviceID ? devId : INVALID_DEVID);
  6079. if (ret != 0) {
  6080. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6081. goto exit;
  6082. }
  6083. }
  6084. bench_stats_start(&count, &start);
  6085. do {
  6086. for (times = 0; times < numBlocks || pending > 0; ) {
  6087. bench_async_poll(&pending);
  6088. /* while free pending slots in queue, submit ops */
  6089. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6090. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6091. 0, &times, numBlocks, &pending)) {
  6092. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6093. bench_size);
  6094. if (!bench_async_handle(&ret,
  6095. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6096. &times, &pending)) {
  6097. goto exit_sha512_256;
  6098. }
  6099. }
  6100. } /* for i */
  6101. RECORD_MULTI_VALUE_STATS();
  6102. } /* for times */
  6103. count += times;
  6104. times = 0;
  6105. do {
  6106. bench_async_poll(&pending);
  6107. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6108. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6109. 0, &times, numBlocks, &pending)) {
  6110. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6111. if (!bench_async_handle(&ret,
  6112. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6113. &times, &pending)) {
  6114. goto exit_sha512_256;
  6115. }
  6116. }
  6117. } /* for i */
  6118. } while (pending > 0);
  6119. } while (bench_stats_check(start)
  6120. #ifdef MULTI_VALUE_STATISTICS
  6121. || runs < minimum_runs
  6122. #endif
  6123. );
  6124. }
  6125. else {
  6126. bench_stats_start(&count, &start);
  6127. do {
  6128. for (times = 0; times < numBlocks; times++) {
  6129. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6130. useDeviceID ? devId : INVALID_DEVID);
  6131. if (ret == 0)
  6132. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6133. if (ret == 0)
  6134. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6135. if (ret != 0)
  6136. goto exit_sha512_256;
  6137. RECORD_MULTI_VALUE_STATS();
  6138. } /* for times */
  6139. count += times;
  6140. } while (bench_stats_check(start)
  6141. #ifdef MULTI_VALUE_STATISTICS
  6142. || runs < minimum_runs
  6143. #endif
  6144. );
  6145. }
  6146. exit_sha512_256:
  6147. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6148. start, ret);
  6149. #ifdef MULTI_VALUE_STATISTICS
  6150. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6151. #endif
  6152. exit:
  6153. if (WC_ARRAY_OK(hash)) {
  6154. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6155. wc_Sha512_256Free(hash[i]);
  6156. }
  6157. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6158. }
  6159. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6160. }
  6161. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6162. #endif /* WOLFSSL_SHA512 */
  6163. #ifdef WOLFSSL_SHA3
  6164. #ifndef WOLFSSL_NOSHA3_224
  6165. void bench_sha3_224(int useDeviceID)
  6166. {
  6167. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6168. sizeof(wc_Sha3), HEAP_HINT);
  6169. double start;
  6170. int ret = 0, i, count = 0, times, pending = 0;
  6171. DECLARE_MULTI_VALUE_STATS_VARS()
  6172. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6173. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6174. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6175. sizeof(wc_Sha3), HEAP_HINT);
  6176. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6177. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6178. if (digest_stream) {
  6179. /* init keys */
  6180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6181. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6182. useDeviceID ? devId : INVALID_DEVID);
  6183. if (ret != 0) {
  6184. printf("InitSha3_224 failed, ret = %d\n", ret);
  6185. goto exit;
  6186. }
  6187. }
  6188. bench_stats_start(&count, &start);
  6189. do {
  6190. for (times = 0; times < numBlocks || pending > 0; ) {
  6191. bench_async_poll(&pending);
  6192. /* while free pending slots in queue, submit ops */
  6193. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6194. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6195. 0, &times, numBlocks, &pending)) {
  6196. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6197. bench_size);
  6198. if (!bench_async_handle(&ret,
  6199. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6200. &times, &pending)) {
  6201. goto exit_sha3_224;
  6202. }
  6203. }
  6204. } /* for i */
  6205. RECORD_MULTI_VALUE_STATS();
  6206. } /* for times */
  6207. count += times;
  6208. times = 0;
  6209. do {
  6210. bench_async_poll(&pending);
  6211. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6212. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6213. 0, &times, numBlocks, &pending)) {
  6214. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6215. if (!bench_async_handle(&ret,
  6216. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6217. &times, &pending)) {
  6218. goto exit_sha3_224;
  6219. }
  6220. }
  6221. } /* for i */
  6222. } while (pending > 0);
  6223. } while (bench_stats_check(start)
  6224. #ifdef MULTI_VALUE_STATISTICS
  6225. || runs < minimum_runs
  6226. #endif
  6227. );
  6228. }
  6229. else {
  6230. bench_stats_start(&count, &start);
  6231. do {
  6232. for (times = 0; times < numBlocks; times++) {
  6233. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6234. useDeviceID ? devId : INVALID_DEVID);
  6235. if (ret == 0)
  6236. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6237. if (ret == 0)
  6238. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6239. if (ret != 0)
  6240. goto exit_sha3_224;
  6241. RECORD_MULTI_VALUE_STATS();
  6242. } /* for times */
  6243. count += times;
  6244. } while (bench_stats_check(start)
  6245. #ifdef MULTI_VALUE_STATISTICS
  6246. || runs < minimum_runs
  6247. #endif
  6248. );
  6249. }
  6250. exit_sha3_224:
  6251. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6252. start, ret);
  6253. #ifdef MULTI_VALUE_STATISTICS
  6254. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6255. #endif
  6256. exit:
  6257. if (WC_ARRAY_OK(hash)) {
  6258. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6259. wc_Sha3_224_Free(hash[i]);
  6260. }
  6261. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6262. }
  6263. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6264. }
  6265. #endif /* WOLFSSL_NOSHA3_224 */
  6266. #ifndef WOLFSSL_NOSHA3_256
  6267. void bench_sha3_256(int useDeviceID)
  6268. {
  6269. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6270. sizeof(wc_Sha3), HEAP_HINT);
  6271. double start;
  6272. DECLARE_MULTI_VALUE_STATS_VARS()
  6273. int ret = 0, i, count = 0, times, pending = 0;
  6274. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6275. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6276. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6277. sizeof(wc_Sha3), HEAP_HINT);
  6278. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6279. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6280. if (digest_stream) {
  6281. /* init keys */
  6282. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6283. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6284. useDeviceID ? devId : INVALID_DEVID);
  6285. if (ret != 0) {
  6286. printf("InitSha3_256 failed, ret = %d\n", ret);
  6287. goto exit;
  6288. }
  6289. }
  6290. bench_stats_start(&count, &start);
  6291. do {
  6292. for (times = 0; times < numBlocks || pending > 0; ) {
  6293. bench_async_poll(&pending);
  6294. /* while free pending slots in queue, submit ops */
  6295. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6296. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6297. 0, &times, numBlocks, &pending)) {
  6298. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6299. bench_size);
  6300. if (!bench_async_handle(&ret,
  6301. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6302. &times, &pending)) {
  6303. goto exit_sha3_256;
  6304. }
  6305. }
  6306. } /* for i */
  6307. RECORD_MULTI_VALUE_STATS();
  6308. } /* for times */
  6309. count += times;
  6310. times = 0;
  6311. do {
  6312. bench_async_poll(&pending);
  6313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6314. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6315. 0, &times, numBlocks, &pending)) {
  6316. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6317. if (!bench_async_handle(&ret,
  6318. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6319. &times, &pending)) {
  6320. goto exit_sha3_256;
  6321. }
  6322. }
  6323. } /* for i */
  6324. } while (pending > 0);
  6325. } while (bench_stats_check(start)
  6326. #ifdef MULTI_VALUE_STATISTICS
  6327. || runs < minimum_runs
  6328. #endif
  6329. );
  6330. }
  6331. else {
  6332. bench_stats_start(&count, &start);
  6333. do {
  6334. for (times = 0; times < numBlocks; times++) {
  6335. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6336. useDeviceID ? devId : INVALID_DEVID);
  6337. if (ret == 0)
  6338. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6339. if (ret == 0)
  6340. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6341. if (ret != 0)
  6342. goto exit_sha3_256;
  6343. RECORD_MULTI_VALUE_STATS();
  6344. } /* for times */
  6345. count += times;
  6346. } while (bench_stats_check(start)
  6347. #ifdef MULTI_VALUE_STATISTICS
  6348. || runs < minimum_runs
  6349. #endif
  6350. );
  6351. }
  6352. exit_sha3_256:
  6353. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6354. start, ret);
  6355. #ifdef MULTI_VALUE_STATISTICS
  6356. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6357. #endif
  6358. exit:
  6359. if (WC_ARRAY_OK(hash)) {
  6360. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6361. wc_Sha3_256_Free(hash[i]);
  6362. }
  6363. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6364. }
  6365. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6366. }
  6367. #endif /* WOLFSSL_NOSHA3_256 */
  6368. #ifndef WOLFSSL_NOSHA3_384
  6369. void bench_sha3_384(int useDeviceID)
  6370. {
  6371. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6372. sizeof(wc_Sha3), HEAP_HINT);
  6373. double start;
  6374. int ret = 0, i, count = 0, times, pending = 0;
  6375. DECLARE_MULTI_VALUE_STATS_VARS()
  6376. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6377. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6378. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6379. sizeof(wc_Sha3), HEAP_HINT);
  6380. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6381. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6382. if (digest_stream) {
  6383. /* init keys */
  6384. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6385. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6386. useDeviceID ? devId : INVALID_DEVID);
  6387. if (ret != 0) {
  6388. printf("InitSha3_384 failed, ret = %d\n", ret);
  6389. goto exit;
  6390. }
  6391. }
  6392. bench_stats_start(&count, &start);
  6393. do {
  6394. for (times = 0; times < numBlocks || pending > 0; ) {
  6395. bench_async_poll(&pending);
  6396. /* while free pending slots in queue, submit ops */
  6397. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6398. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6399. 0, &times, numBlocks, &pending)) {
  6400. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6401. bench_size);
  6402. if (!bench_async_handle(&ret,
  6403. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6404. &times, &pending)) {
  6405. goto exit_sha3_384;
  6406. }
  6407. }
  6408. } /* for i */
  6409. RECORD_MULTI_VALUE_STATS();
  6410. } /* for times */
  6411. count += times;
  6412. times = 0;
  6413. do {
  6414. bench_async_poll(&pending);
  6415. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6416. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6417. 0, &times, numBlocks, &pending)) {
  6418. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6419. if (!bench_async_handle(&ret,
  6420. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6421. &times, &pending)) {
  6422. goto exit_sha3_384;
  6423. }
  6424. }
  6425. } /* for i */
  6426. } while (pending > 0);
  6427. } while (bench_stats_check(start)
  6428. #ifdef MULTI_VALUE_STATISTICS
  6429. || runs < minimum_runs
  6430. #endif
  6431. );
  6432. }
  6433. else {
  6434. bench_stats_start(&count, &start);
  6435. do {
  6436. for (times = 0; times < numBlocks; times++) {
  6437. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6438. useDeviceID ? devId : INVALID_DEVID);
  6439. if (ret == 0)
  6440. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6441. if (ret == 0)
  6442. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6443. if (ret != 0)
  6444. goto exit_sha3_384;
  6445. RECORD_MULTI_VALUE_STATS();
  6446. } /* for times */
  6447. count += times;
  6448. } while (bench_stats_check(start)
  6449. #ifdef MULTI_VALUE_STATISTICS
  6450. || runs < minimum_runs
  6451. #endif
  6452. );
  6453. }
  6454. exit_sha3_384:
  6455. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6456. start, ret);
  6457. #ifdef MULTI_VALUE_STATISTICS
  6458. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6459. #endif
  6460. exit:
  6461. if (WC_ARRAY_OK(hash)) {
  6462. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6463. wc_Sha3_384_Free(hash[i]);
  6464. }
  6465. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6466. }
  6467. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6468. }
  6469. #endif /* WOLFSSL_NOSHA3_384 */
  6470. #ifndef WOLFSSL_NOSHA3_512
  6471. void bench_sha3_512(int useDeviceID)
  6472. {
  6473. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6474. sizeof(wc_Sha3), HEAP_HINT);
  6475. double start;
  6476. int ret = 0, i, count = 0, times, pending = 0;
  6477. DECLARE_MULTI_VALUE_STATS_VARS()
  6478. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6479. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6480. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6481. sizeof(wc_Sha3), HEAP_HINT);
  6482. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6483. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6484. if (digest_stream) {
  6485. /* init keys */
  6486. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6487. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6488. useDeviceID ? devId : INVALID_DEVID);
  6489. if (ret != 0) {
  6490. printf("InitSha3_512 failed, ret = %d\n", ret);
  6491. goto exit;
  6492. }
  6493. }
  6494. bench_stats_start(&count, &start);
  6495. do {
  6496. for (times = 0; times < numBlocks || pending > 0; ) {
  6497. bench_async_poll(&pending);
  6498. /* while free pending slots in queue, submit ops */
  6499. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6500. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6501. 0, &times, numBlocks, &pending)) {
  6502. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6503. bench_size);
  6504. if (!bench_async_handle(&ret,
  6505. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6506. &times, &pending)) {
  6507. goto exit_sha3_512;
  6508. }
  6509. }
  6510. } /* for i */
  6511. RECORD_MULTI_VALUE_STATS();
  6512. } /* for times */
  6513. count += times;
  6514. times = 0;
  6515. do {
  6516. bench_async_poll(&pending);
  6517. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6518. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6519. 0, &times, numBlocks, &pending)) {
  6520. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6521. if (!bench_async_handle(&ret,
  6522. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6523. &times, &pending)) {
  6524. goto exit_sha3_512;
  6525. }
  6526. }
  6527. } /* for i */
  6528. } while (pending > 0);
  6529. } while (bench_stats_check(start)
  6530. #ifdef MULTI_VALUE_STATISTICS
  6531. || runs < minimum_runs
  6532. #endif
  6533. );
  6534. }
  6535. else {
  6536. bench_stats_start(&count, &start);
  6537. do {
  6538. for (times = 0; times < numBlocks; times++) {
  6539. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6540. useDeviceID ? devId : INVALID_DEVID);
  6541. if (ret == 0)
  6542. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6543. if (ret == 0)
  6544. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6545. if (ret != 0)
  6546. goto exit_sha3_512;
  6547. RECORD_MULTI_VALUE_STATS();
  6548. } /* for times */
  6549. count += times;
  6550. } while (bench_stats_check(start)
  6551. #ifdef MULTI_VALUE_STATISTICS
  6552. || runs < minimum_runs
  6553. #endif
  6554. );
  6555. }
  6556. exit_sha3_512:
  6557. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6558. start, ret);
  6559. #ifdef MULTI_VALUE_STATISTICS
  6560. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6561. #endif
  6562. exit:
  6563. if (WC_ARRAY_OK(hash)) {
  6564. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6565. wc_Sha3_512_Free(hash[i]);
  6566. }
  6567. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6568. }
  6569. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6570. }
  6571. #endif /* WOLFSSL_NOSHA3_512 */
  6572. #ifdef WOLFSSL_SHAKE128
  6573. void bench_shake128(int useDeviceID)
  6574. {
  6575. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6576. sizeof(wc_Shake), HEAP_HINT);
  6577. double start;
  6578. int ret = 0, i, count = 0, times, pending = 0;
  6579. DECLARE_MULTI_VALUE_STATS_VARS()
  6580. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6581. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6582. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6583. sizeof(wc_Shake), HEAP_HINT);
  6584. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6585. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6586. if (digest_stream) {
  6587. /* init keys */
  6588. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6589. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6590. useDeviceID ? devId : INVALID_DEVID);
  6591. if (ret != 0) {
  6592. printf("InitShake128 failed, ret = %d\n", ret);
  6593. goto exit;
  6594. }
  6595. }
  6596. bench_stats_start(&count, &start);
  6597. do {
  6598. for (times = 0; times < numBlocks || pending > 0; ) {
  6599. bench_async_poll(&pending);
  6600. /* while free pending slots in queue, submit ops */
  6601. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6602. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6603. 0, &times, numBlocks, &pending)) {
  6604. ret = wc_Shake128_Update(hash[i], bench_plain,
  6605. bench_size);
  6606. if (!bench_async_handle(&ret,
  6607. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6608. &times, &pending)) {
  6609. goto exit_shake128;
  6610. }
  6611. }
  6612. } /* for i */
  6613. RECORD_MULTI_VALUE_STATS();
  6614. } /* for times */
  6615. count += times;
  6616. times = 0;
  6617. do {
  6618. bench_async_poll(&pending);
  6619. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6620. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6621. 0, &times, numBlocks, &pending)) {
  6622. ret = wc_Shake128_Final(hash[i], digest[i],
  6623. WC_SHA3_128_BLOCK_SIZE);
  6624. if (!bench_async_handle(&ret,
  6625. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6626. &times, &pending)) {
  6627. goto exit_shake128;
  6628. }
  6629. }
  6630. } /* for i */
  6631. } while (pending > 0);
  6632. } while (bench_stats_check(start)
  6633. #ifdef MULTI_VALUE_STATISTICS
  6634. || runs < minimum_runs
  6635. #endif
  6636. );
  6637. }
  6638. else {
  6639. bench_stats_start(&count, &start);
  6640. do {
  6641. for (times = 0; times < numBlocks; times++) {
  6642. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6643. useDeviceID ? devId : INVALID_DEVID);
  6644. if (ret == 0)
  6645. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6646. if (ret == 0)
  6647. ret = wc_Shake128_Final(hash[0], digest[0],
  6648. WC_SHA3_128_BLOCK_SIZE);
  6649. if (ret != 0)
  6650. goto exit_shake128;
  6651. RECORD_MULTI_VALUE_STATS();
  6652. } /* for times */
  6653. count += times;
  6654. } while (bench_stats_check(start)
  6655. #ifdef MULTI_VALUE_STATISTICS
  6656. || runs < minimum_runs
  6657. #endif
  6658. );
  6659. }
  6660. exit_shake128:
  6661. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6662. start, ret);
  6663. #ifdef MULTI_VALUE_STATISTICS
  6664. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6665. #endif
  6666. exit:
  6667. if (WC_ARRAY_OK(hash)) {
  6668. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6669. wc_Shake128_Free(hash[i]);
  6670. }
  6671. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6672. }
  6673. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6674. }
  6675. #endif /* WOLFSSL_SHAKE128 */
  6676. #ifdef WOLFSSL_SHAKE256
  6677. void bench_shake256(int useDeviceID)
  6678. {
  6679. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6680. sizeof(wc_Shake), HEAP_HINT);
  6681. double start;
  6682. int ret = 0, i, count = 0, times, pending = 0;
  6683. DECLARE_MULTI_VALUE_STATS_VARS()
  6684. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6685. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6686. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6687. sizeof(wc_Shake), HEAP_HINT);
  6688. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6689. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6690. if (digest_stream) {
  6691. /* init keys */
  6692. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6693. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6694. useDeviceID ? devId : INVALID_DEVID);
  6695. if (ret != 0) {
  6696. printf("InitShake256 failed, ret = %d\n", ret);
  6697. goto exit;
  6698. }
  6699. }
  6700. bench_stats_start(&count, &start);
  6701. do {
  6702. for (times = 0; times < numBlocks || pending > 0; ) {
  6703. bench_async_poll(&pending);
  6704. /* while free pending slots in queue, submit ops */
  6705. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6706. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6707. 0, &times, numBlocks, &pending)) {
  6708. ret = wc_Shake256_Update(hash[i], bench_plain,
  6709. bench_size);
  6710. if (!bench_async_handle(&ret,
  6711. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6712. &times, &pending)) {
  6713. goto exit_shake256;
  6714. }
  6715. }
  6716. } /* for i */
  6717. RECORD_MULTI_VALUE_STATS();
  6718. } /* for times */
  6719. count += times;
  6720. times = 0;
  6721. do {
  6722. bench_async_poll(&pending);
  6723. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6724. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6725. 0, &times, numBlocks, &pending)) {
  6726. ret = wc_Shake256_Final(hash[i], digest[i],
  6727. WC_SHA3_256_BLOCK_SIZE);
  6728. if (!bench_async_handle(&ret,
  6729. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6730. &times, &pending)) {
  6731. goto exit_shake256;
  6732. }
  6733. }
  6734. } /* for i */
  6735. } while (pending > 0);
  6736. } while (bench_stats_check(start)
  6737. #ifdef MULTI_VALUE_STATISTICS
  6738. || runs < minimum_runs
  6739. #endif
  6740. );
  6741. }
  6742. else {
  6743. bench_stats_start(&count, &start);
  6744. do {
  6745. for (times = 0; times < numBlocks; times++) {
  6746. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6747. useDeviceID ? devId : INVALID_DEVID);
  6748. if (ret == 0)
  6749. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6750. if (ret == 0)
  6751. ret = wc_Shake256_Final(hash[0], digest[0],
  6752. WC_SHA3_256_BLOCK_SIZE);
  6753. if (ret != 0)
  6754. goto exit_shake256;
  6755. RECORD_MULTI_VALUE_STATS();
  6756. } /* for times */
  6757. count += times;
  6758. } while (bench_stats_check(start)
  6759. #ifdef MULTI_VALUE_STATISTICS
  6760. || runs < minimum_runs
  6761. #endif
  6762. );
  6763. }
  6764. exit_shake256:
  6765. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6766. start, ret);
  6767. #ifdef MULTI_VALUE_STATISTICS
  6768. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6769. #endif
  6770. exit:
  6771. if (WC_ARRAY_OK(hash)) {
  6772. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6773. wc_Shake256_Free(hash[i]);
  6774. }
  6775. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6776. }
  6777. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6778. }
  6779. #endif /* WOLFSSL_SHAKE256 */
  6780. #endif
  6781. #ifdef WOLFSSL_SM3
  6782. void bench_sm3(int useDeviceID)
  6783. {
  6784. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6785. sizeof(wc_Sm3), HEAP_HINT);
  6786. double start;
  6787. int ret = 0, i, count = 0, times, pending = 0;
  6788. DECLARE_MULTI_VALUE_STATS_VARS()
  6789. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6790. HEAP_HINT);
  6791. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6792. sizeof(wc_Sm3), HEAP_HINT);
  6793. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6794. HEAP_HINT);
  6795. if (digest_stream) {
  6796. /* init keys */
  6797. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6798. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6799. useDeviceID ? devId: INVALID_DEVID);
  6800. if (ret != 0) {
  6801. printf("InitSm3 failed, ret = %d\n", ret);
  6802. goto exit;
  6803. }
  6804. }
  6805. bench_stats_start(&count, &start);
  6806. do {
  6807. for (times = 0; times < numBlocks || pending > 0; ) {
  6808. bench_async_poll(&pending);
  6809. /* while free pending slots in queue, submit ops */
  6810. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6811. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6812. 0, &times, numBlocks, &pending)) {
  6813. ret = wc_Sm3Update(hash[i], bench_plain,
  6814. bench_size);
  6815. if (!bench_async_handle(&ret,
  6816. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6817. goto exit_sm3;
  6818. }
  6819. }
  6820. } /* for i */
  6821. RECORD_MULTI_VALUE_STATS();
  6822. } /* for times */
  6823. count += times;
  6824. times = 0;
  6825. do {
  6826. bench_async_poll(&pending);
  6827. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6828. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6829. 0, &times, numBlocks, &pending)) {
  6830. ret = wc_Sm3Final(hash[i], digest[i]);
  6831. if (!bench_async_handle(&ret,
  6832. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6833. goto exit_sm3;
  6834. }
  6835. }
  6836. } /* for i */
  6837. } while (pending > 0);
  6838. } while (bench_stats_check(start)
  6839. #ifdef MULTI_VALUE_STATISTICS
  6840. || runs < minimum_runs
  6841. #endif
  6842. );
  6843. }
  6844. else {
  6845. bench_stats_start(&count, &start);
  6846. do {
  6847. for (times = 0; times < numBlocks; times++) {
  6848. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6849. useDeviceID ? devId: INVALID_DEVID);
  6850. if (ret == 0)
  6851. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6852. if (ret == 0)
  6853. ret = wc_Sm3Final(hash[0], digest[0]);
  6854. if (ret != 0)
  6855. goto exit_sm3;
  6856. RECORD_MULTI_VALUE_STATS();
  6857. } /* for times */
  6858. count += times;
  6859. } while (bench_stats_check(start)
  6860. #ifdef MULTI_VALUE_STATISTICS
  6861. || runs < minimum_runs
  6862. #endif
  6863. );
  6864. }
  6865. exit_sm3:
  6866. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6867. #ifdef MULTI_VALUE_STATISTICS
  6868. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6869. #endif
  6870. exit:
  6871. if (WC_ARRAY_OK(hash)) {
  6872. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6873. wc_Sm3Free(hash[i]);
  6874. }
  6875. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6876. }
  6877. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6878. }
  6879. #endif
  6880. #ifdef WOLFSSL_RIPEMD
  6881. void bench_ripemd(void)
  6882. {
  6883. RipeMd hash;
  6884. byte digest[RIPEMD_DIGEST_SIZE];
  6885. double start;
  6886. int i, count, ret = 0;
  6887. DECLARE_MULTI_VALUE_STATS_VARS()
  6888. if (digest_stream) {
  6889. ret = wc_InitRipeMd(&hash);
  6890. if (ret != 0) {
  6891. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6892. return;
  6893. }
  6894. bench_stats_start(&count, &start);
  6895. do {
  6896. for (i = 0; i < numBlocks; i++) {
  6897. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6898. if (ret != 0) {
  6899. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6900. return;
  6901. }
  6902. RECORD_MULTI_VALUE_STATS();
  6903. }
  6904. ret = wc_RipeMdFinal(&hash, digest);
  6905. if (ret != 0) {
  6906. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6907. return;
  6908. }
  6909. count += i;
  6910. } while (bench_stats_check(start)
  6911. #ifdef MULTI_VALUE_STATISTICS
  6912. || runs < minimum_runs
  6913. #endif
  6914. );
  6915. }
  6916. else {
  6917. bench_stats_start(&count, &start);
  6918. do {
  6919. for (i = 0; i < numBlocks; i++) {
  6920. ret = wc_InitRipeMd(&hash);
  6921. if (ret != 0) {
  6922. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6923. return;
  6924. }
  6925. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6926. if (ret != 0) {
  6927. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6928. return;
  6929. }
  6930. ret = wc_RipeMdFinal(&hash, digest);
  6931. if (ret != 0) {
  6932. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6933. return;
  6934. }
  6935. RECORD_MULTI_VALUE_STATS();
  6936. }
  6937. count += i;
  6938. } while (bench_stats_check(start)
  6939. #ifdef MULTI_VALUE_STATISTICS
  6940. || runs < minimum_runs
  6941. #endif
  6942. );
  6943. }
  6944. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  6945. #ifdef MULTI_VALUE_STATISTICS
  6946. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6947. #endif
  6948. return;
  6949. }
  6950. #endif
  6951. #ifdef HAVE_BLAKE2
  6952. void bench_blake2b(void)
  6953. {
  6954. Blake2b b2b;
  6955. byte digest[64];
  6956. double start;
  6957. int ret = 0, i, count;
  6958. DECLARE_MULTI_VALUE_STATS_VARS()
  6959. if (digest_stream) {
  6960. ret = wc_InitBlake2b(&b2b, 64);
  6961. if (ret != 0) {
  6962. printf("InitBlake2b failed, ret = %d\n", ret);
  6963. return;
  6964. }
  6965. bench_stats_start(&count, &start);
  6966. do {
  6967. for (i = 0; i < numBlocks; i++) {
  6968. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  6969. if (ret != 0) {
  6970. printf("Blake2bUpdate failed, ret = %d\n", ret);
  6971. return;
  6972. }
  6973. RECORD_MULTI_VALUE_STATS();
  6974. }
  6975. ret = wc_Blake2bFinal(&b2b, digest, 64);
  6976. if (ret != 0) {
  6977. printf("Blake2bFinal failed, ret = %d\n", ret);
  6978. return;
  6979. }
  6980. count += i;
  6981. } while (bench_stats_check(start)
  6982. #ifdef MULTI_VALUE_STATISTICS
  6983. || runs < minimum_runs
  6984. #endif
  6985. );
  6986. }
  6987. else {
  6988. bench_stats_start(&count, &start);
  6989. do {
  6990. for (i = 0; i < numBlocks; i++) {
  6991. ret = wc_InitBlake2b(&b2b, 64);
  6992. if (ret != 0) {
  6993. printf("InitBlake2b failed, ret = %d\n", ret);
  6994. return;
  6995. }
  6996. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  6997. if (ret != 0) {
  6998. printf("Blake2bUpdate failed, ret = %d\n", ret);
  6999. return;
  7000. }
  7001. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7002. if (ret != 0) {
  7003. printf("Blake2bFinal failed, ret = %d\n", ret);
  7004. return;
  7005. }
  7006. RECORD_MULTI_VALUE_STATS();
  7007. }
  7008. count += i;
  7009. } while (bench_stats_check(start)
  7010. #ifdef MULTI_VALUE_STATISTICS
  7011. || runs < minimum_runs
  7012. #endif
  7013. );
  7014. }
  7015. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7016. #ifdef MULTI_VALUE_STATISTICS
  7017. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7018. #endif
  7019. }
  7020. #endif
  7021. #if defined(HAVE_BLAKE2S)
  7022. void bench_blake2s(void)
  7023. {
  7024. Blake2s b2s;
  7025. byte digest[32];
  7026. double start;
  7027. int ret = 0, i, count;
  7028. DECLARE_MULTI_VALUE_STATS_VARS()
  7029. if (digest_stream) {
  7030. ret = wc_InitBlake2s(&b2s, 32);
  7031. if (ret != 0) {
  7032. printf("InitBlake2s failed, ret = %d\n", ret);
  7033. return;
  7034. }
  7035. bench_stats_start(&count, &start);
  7036. do {
  7037. for (i = 0; i < numBlocks; i++) {
  7038. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7039. if (ret != 0) {
  7040. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7041. return;
  7042. }
  7043. RECORD_MULTI_VALUE_STATS();
  7044. }
  7045. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7046. if (ret != 0) {
  7047. printf("Blake2sFinal failed, ret = %d\n", ret);
  7048. return;
  7049. }
  7050. count += i;
  7051. } while (bench_stats_check(start)
  7052. #ifdef MULTI_VALUE_STATISTICS
  7053. || runs < minimum_runs
  7054. #endif
  7055. );
  7056. }
  7057. else {
  7058. bench_stats_start(&count, &start);
  7059. do {
  7060. for (i = 0; i < numBlocks; i++) {
  7061. ret = wc_InitBlake2s(&b2s, 32);
  7062. if (ret != 0) {
  7063. printf("InitBlake2b failed, ret = %d\n", ret);
  7064. return;
  7065. }
  7066. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7067. if (ret != 0) {
  7068. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7069. return;
  7070. }
  7071. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7072. if (ret != 0) {
  7073. printf("Blake2sFinal failed, ret = %d\n", ret);
  7074. return;
  7075. }
  7076. RECORD_MULTI_VALUE_STATS();
  7077. }
  7078. count += i;
  7079. } while (bench_stats_check(start)
  7080. #ifdef MULTI_VALUE_STATISTICS
  7081. || runs < minimum_runs
  7082. #endif
  7083. );
  7084. }
  7085. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7086. #ifdef MULTI_VALUE_STATISTICS
  7087. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7088. #endif
  7089. }
  7090. #endif
  7091. #ifdef WOLFSSL_CMAC
  7092. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7093. {
  7094. Cmac cmac;
  7095. byte digest[AES_BLOCK_SIZE];
  7096. word32 digestSz = sizeof(digest);
  7097. double start;
  7098. int ret, i, count;
  7099. DECLARE_MULTI_VALUE_STATS_VARS()
  7100. #ifdef WOLFSSL_SECO_CAAM
  7101. unsigned int keyID;
  7102. int keyGroup = 1; /* group one was chosen arbitrarily */
  7103. int keyInfo = CAAM_KEY_TRANSIENT;
  7104. int keyType = CAAM_KEYTYPE_AES128;
  7105. byte pubKey[AES_256_KEY_SIZE];
  7106. if (keySz == AES_256_KEY_SIZE) {
  7107. keyType = CAAM_KEYTYPE_AES256;
  7108. }
  7109. if (useDeviceID &&
  7110. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7111. keyInfo, &keyID) != 0) {
  7112. printf("Error generating key in hsm\n");
  7113. return;
  7114. }
  7115. #endif
  7116. (void)useDeviceID;
  7117. bench_stats_start(&count, &start);
  7118. do {
  7119. #ifdef HAVE_FIPS
  7120. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7121. #else
  7122. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7123. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7124. #endif
  7125. if (ret != 0) {
  7126. printf("InitCmac failed, ret = %d\n", ret);
  7127. return;
  7128. }
  7129. #ifdef WOLFSSL_SECO_CAAM
  7130. if (useDeviceID) {
  7131. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7132. }
  7133. #endif
  7134. for (i = 0; i < numBlocks; i++) {
  7135. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7136. if (ret != 0) {
  7137. printf("CmacUpdate failed, ret = %d\n", ret);
  7138. return;
  7139. }
  7140. RECORD_MULTI_VALUE_STATS();
  7141. }
  7142. /* Note: final force zero's the Cmac struct */
  7143. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7144. if (ret != 0) {
  7145. printf("CmacFinal failed, ret = %d\n", ret);
  7146. return;
  7147. }
  7148. count += i;
  7149. } while (bench_stats_check(start)
  7150. #ifdef MULTI_VALUE_STATISTICS
  7151. || runs < minimum_runs
  7152. #endif
  7153. );
  7154. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7155. #ifdef MULTI_VALUE_STATISTICS
  7156. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7157. #endif
  7158. }
  7159. void bench_cmac(int useDeviceID)
  7160. {
  7161. #ifdef WOLFSSL_AES_128
  7162. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7163. #endif
  7164. #ifdef WOLFSSL_AES_256
  7165. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7166. #endif
  7167. }
  7168. #endif /* WOLFSSL_CMAC */
  7169. #ifdef HAVE_SCRYPT
  7170. void bench_scrypt(void)
  7171. {
  7172. byte derived[64];
  7173. double start;
  7174. int ret, i, count;
  7175. DECLARE_MULTI_VALUE_STATS_VARS()
  7176. bench_stats_start(&count, &start);
  7177. do {
  7178. for (i = 0; i < scryptCnt; i++) {
  7179. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7180. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7181. sizeof(derived));
  7182. if (ret != 0) {
  7183. printf("scrypt failed, ret = %d\n", ret);
  7184. goto exit;
  7185. }
  7186. RECORD_MULTI_VALUE_STATS();
  7187. }
  7188. count += i;
  7189. } while (bench_stats_check(start)
  7190. #ifdef MULTI_VALUE_STATISTICS
  7191. || runs < minimum_runs
  7192. #endif
  7193. );
  7194. exit:
  7195. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7196. #ifdef MULTI_VALUE_STATISTICS
  7197. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7198. #endif
  7199. }
  7200. #endif /* HAVE_SCRYPT */
  7201. #ifndef NO_HMAC
  7202. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7203. const byte* key, word32 keySz, const char* label)
  7204. {
  7205. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7206. sizeof(Hmac), HEAP_HINT);
  7207. double start;
  7208. int ret = 0, i, count = 0, times, pending = 0;
  7209. DECLARE_MULTI_VALUE_STATS_VARS()
  7210. #ifdef WOLFSSL_ASYNC_CRYPT
  7211. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7212. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7213. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7214. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7215. #else
  7216. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7217. #endif
  7218. (void)digestSz;
  7219. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7220. sizeof(Hmac), HEAP_HINT);
  7221. /* init keys */
  7222. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7223. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7224. useDeviceID ? devId : INVALID_DEVID);
  7225. if (ret != 0) {
  7226. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7227. goto exit;
  7228. }
  7229. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7230. if (ret != 0) {
  7231. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7232. goto exit;
  7233. }
  7234. }
  7235. bench_stats_start(&count, &start);
  7236. do {
  7237. for (times = 0; times < numBlocks || pending > 0; ) {
  7238. bench_async_poll(&pending);
  7239. /* while free pending slots in queue, submit ops */
  7240. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7241. if (bench_async_check(&ret,
  7242. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7243. &times, numBlocks, &pending)) {
  7244. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7245. if (!bench_async_handle(&ret,
  7246. BENCH_ASYNC_GET_DEV(hmac[i]),
  7247. 0, &times, &pending)) {
  7248. goto exit_hmac;
  7249. }
  7250. }
  7251. } /* for i */
  7252. } /* for times */
  7253. count += times;
  7254. times = 0;
  7255. do {
  7256. bench_async_poll(&pending);
  7257. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7258. if (bench_async_check(&ret,
  7259. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7260. &times, numBlocks, &pending)) {
  7261. ret = wc_HmacFinal(hmac[i], digest[i]);
  7262. if (!bench_async_handle(&ret,
  7263. BENCH_ASYNC_GET_DEV(hmac[i]),
  7264. 0, &times, &pending)) {
  7265. goto exit_hmac;
  7266. }
  7267. }
  7268. RECORD_MULTI_VALUE_STATS();
  7269. } /* for i */
  7270. } while (pending > 0);
  7271. } while (bench_stats_check(start)
  7272. #ifdef MULTI_VALUE_STATISTICS
  7273. || runs < minimum_runs
  7274. #endif
  7275. );
  7276. exit_hmac:
  7277. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7278. #ifdef MULTI_VALUE_STATISTICS
  7279. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7280. #endif
  7281. exit:
  7282. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7283. wc_HmacFree(hmac[i]);
  7284. }
  7285. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7286. #ifdef WOLFSSL_ASYNC_CRYPT
  7287. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7288. #endif
  7289. }
  7290. #ifndef NO_MD5
  7291. void bench_hmac_md5(int useDeviceID)
  7292. {
  7293. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7294. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7295. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7296. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7297. "HMAC-MD5");
  7298. }
  7299. #endif /* NO_MD5 */
  7300. #ifndef NO_SHA
  7301. void bench_hmac_sha(int useDeviceID)
  7302. {
  7303. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7304. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7305. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7306. 0x0b, 0x0b, 0x0b, 0x0b };
  7307. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7308. "HMAC-SHA");
  7309. }
  7310. #endif /* NO_SHA */
  7311. #ifdef WOLFSSL_SHA224
  7312. void bench_hmac_sha224(int useDeviceID)
  7313. {
  7314. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7315. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7316. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7317. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7318. 0x0b, 0x0b, 0x0b, 0x0b };
  7319. bench_hmac(useDeviceID, WC_SHA224,
  7320. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7321. "HMAC-SHA224");
  7322. }
  7323. #endif /* WOLFSSL_SHA224 */
  7324. #ifndef NO_SHA256
  7325. void bench_hmac_sha256(int useDeviceID)
  7326. {
  7327. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7328. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7329. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7330. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7331. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7332. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7333. "HMAC-SHA256");
  7334. }
  7335. #endif /* NO_SHA256 */
  7336. #ifdef WOLFSSL_SHA384
  7337. void bench_hmac_sha384(int useDeviceID)
  7338. {
  7339. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7340. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7341. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7342. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7343. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7344. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7345. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7346. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7347. "HMAC-SHA384");
  7348. }
  7349. #endif /* WOLFSSL_SHA384 */
  7350. #ifdef WOLFSSL_SHA512
  7351. void bench_hmac_sha512(int useDeviceID)
  7352. {
  7353. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7354. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7355. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7356. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7357. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7358. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7359. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7360. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7361. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7362. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7363. "HMAC-SHA512");
  7364. }
  7365. #endif /* WOLFSSL_SHA512 */
  7366. #ifndef NO_PWDBASED
  7367. void bench_pbkdf2(void)
  7368. {
  7369. double start;
  7370. int ret = 0, count = 0;
  7371. const char* passwd32 = "passwordpasswordpasswordpassword";
  7372. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7373. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7374. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7375. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7376. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7377. byte derived[32];
  7378. DECLARE_MULTI_VALUE_STATS_VARS()
  7379. bench_stats_start(&count, &start);
  7380. PRIVATE_KEY_UNLOCK();
  7381. do {
  7382. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7383. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7384. count++;
  7385. RECORD_MULTI_VALUE_STATS();
  7386. } while (bench_stats_check(start)
  7387. #ifdef MULTI_VALUE_STATISTICS
  7388. || runs < minimum_runs
  7389. #endif
  7390. );
  7391. PRIVATE_KEY_LOCK();
  7392. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7393. #ifdef MULTI_VALUE_STATISTICS
  7394. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7395. #endif
  7396. }
  7397. #endif /* !NO_PWDBASED */
  7398. #endif /* NO_HMAC */
  7399. #ifdef WOLFSSL_SIPHASH
  7400. void bench_siphash(void)
  7401. {
  7402. double start;
  7403. int ret = 0, count;
  7404. const char* passwd16 = "passwordpassword";
  7405. byte out[16];
  7406. int i;
  7407. DECLARE_MULTI_VALUE_STATS_VARS()
  7408. bench_stats_start(&count, &start);
  7409. do {
  7410. for (i = 0; i < numBlocks; i++) {
  7411. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7412. out, 8);
  7413. RECORD_MULTI_VALUE_STATS();
  7414. }
  7415. count += i;
  7416. } while (bench_stats_check(start)
  7417. #ifdef MULTI_VALUE_STATISTICS
  7418. || runs < minimum_runs
  7419. #endif
  7420. );
  7421. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7422. #ifdef MULTI_VALUE_STATISTICS
  7423. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7424. #endif
  7425. RESET_MULTI_VALUE_STATS_VARS();
  7426. bench_stats_start(&count, &start);
  7427. do {
  7428. for (i = 0; i < numBlocks; i++) {
  7429. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7430. out, 16);
  7431. RECORD_MULTI_VALUE_STATS();
  7432. }
  7433. count += i;
  7434. } while (bench_stats_check(start)
  7435. #ifdef MULTI_VALUE_STATISTICS
  7436. || runs < minimum_runs
  7437. #endif
  7438. );
  7439. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7440. #ifdef MULTI_VALUE_STATISTICS
  7441. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7442. #endif
  7443. }
  7444. #endif
  7445. #ifdef WC_SRTP_KDF
  7446. void bench_srtpkdf(void)
  7447. {
  7448. double start;
  7449. int count;
  7450. int ret = 0;
  7451. byte keyE[32];
  7452. byte keyA[20];
  7453. byte keyS[14];
  7454. const byte *key = bench_key_buf;
  7455. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7456. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7457. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7458. int kdrIdx = 0;
  7459. int i;
  7460. DECLARE_MULTI_VALUE_STATS_VARS()
  7461. bench_stats_start(&count, &start);
  7462. PRIVATE_KEY_UNLOCK();
  7463. do {
  7464. for (i = 0; i < numBlocks; i++) {
  7465. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7466. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7467. keyS, sizeof(keyS));
  7468. RECORD_MULTI_VALUE_STATS();
  7469. }
  7470. count += i;
  7471. } while (bench_stats_check(start)
  7472. #ifdef MULTI_VALUE_STATISTICS
  7473. || runs < minimum_runs
  7474. #endif
  7475. );
  7476. PRIVATE_KEY_LOCK();
  7477. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7478. #ifdef MULTI_VALUE_STATISTICS
  7479. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7480. #endif
  7481. RESET_MULTI_VALUE_STATS_VARS();
  7482. bench_stats_start(&count, &start);
  7483. PRIVATE_KEY_UNLOCK();
  7484. do {
  7485. for (i = 0; i < numBlocks; i++) {
  7486. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7487. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7488. keyS, sizeof(keyS));
  7489. RECORD_MULTI_VALUE_STATS();
  7490. }
  7491. count += i;
  7492. } while (bench_stats_check(start)
  7493. #ifdef MULTI_VALUE_STATISTICS
  7494. || runs < minimum_runs
  7495. #endif
  7496. );
  7497. PRIVATE_KEY_LOCK();
  7498. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7499. #ifdef MULTI_VALUE_STATISTICS
  7500. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7501. #endif
  7502. RESET_MULTI_VALUE_STATS_VARS();
  7503. bench_stats_start(&count, &start);
  7504. PRIVATE_KEY_UNLOCK();
  7505. do {
  7506. for (i = 0; i < numBlocks; i++) {
  7507. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7508. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7509. keyS, sizeof(keyS));
  7510. RECORD_MULTI_VALUE_STATS();
  7511. }
  7512. count += i;
  7513. } while (bench_stats_check(start)
  7514. #ifdef MULTI_VALUE_STATISTICS
  7515. || runs < minimum_runs
  7516. #endif
  7517. );
  7518. PRIVATE_KEY_LOCK();
  7519. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7520. #ifdef MULTI_VALUE_STATISTICS
  7521. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7522. #endif
  7523. RESET_MULTI_VALUE_STATS_VARS();
  7524. bench_stats_start(&count, &start);
  7525. PRIVATE_KEY_UNLOCK();
  7526. do {
  7527. for (i = 0; i < numBlocks; i++) {
  7528. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7529. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7530. keyS, sizeof(keyS));
  7531. RECORD_MULTI_VALUE_STATS();
  7532. }
  7533. count += i;
  7534. } while (bench_stats_check(start)
  7535. #ifdef MULTI_VALUE_STATISTICS
  7536. || runs < minimum_runs
  7537. #endif
  7538. );
  7539. PRIVATE_KEY_LOCK();
  7540. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7541. #ifdef MULTI_VALUE_STATISTICS
  7542. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7543. #endif
  7544. }
  7545. #endif
  7546. #ifndef NO_RSA
  7547. #if defined(WOLFSSL_KEY_GEN)
  7548. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7549. {
  7550. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7551. sizeof(RsaKey), HEAP_HINT);
  7552. double start = 0;
  7553. int ret = 0, i, count = 0, times, pending = 0;
  7554. const long rsa_e_val = WC_RSA_EXPONENT;
  7555. const char**desc = bench_desc_words[lng_index];
  7556. DECLARE_MULTI_VALUE_STATS_VARS()
  7557. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7558. sizeof(RsaKey), HEAP_HINT);
  7559. bench_stats_start(&count, &start);
  7560. do {
  7561. /* while free pending slots in queue, submit ops */
  7562. for (times = 0; times < genTimes || pending > 0; ) {
  7563. bench_async_poll(&pending);
  7564. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7565. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7566. 0, &times, genTimes, &pending)) {
  7567. wc_FreeRsaKey(genKey[i]);
  7568. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7569. if (ret < 0) {
  7570. goto exit;
  7571. }
  7572. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7573. &gRng);
  7574. if (!bench_async_handle(&ret,
  7575. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7576. &times, &pending)) {
  7577. goto exit;
  7578. }
  7579. }
  7580. } /* for i */
  7581. RECORD_MULTI_VALUE_STATS();
  7582. } /* for times */
  7583. count += times;
  7584. } while (bench_stats_check(start)
  7585. #ifdef MULTI_VALUE_STATISTICS
  7586. || runs < minimum_runs
  7587. #endif
  7588. );
  7589. exit:
  7590. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7591. start, ret);
  7592. #ifdef MULTI_VALUE_STATISTICS
  7593. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7594. #endif
  7595. /* cleanup */
  7596. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7597. wc_FreeRsaKey(genKey[i]);
  7598. }
  7599. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7600. }
  7601. void bench_rsaKeyGen(int useDeviceID)
  7602. {
  7603. int k;
  7604. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7605. static const word32 keySizes[2] = {1024, 2048 };
  7606. #elif RSA_MAX_SIZE >= 4096
  7607. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7608. (RSA_MIN_SIZE <= 1024)
  7609. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7610. #else
  7611. static const word32 keySizes[3] = {2048, 3072, 4096};
  7612. #endif
  7613. #elif RSA_MAX_SIZE >= 3072
  7614. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7615. (RSA_MIN_SIZE <= 1024)
  7616. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7617. #else
  7618. static const word32 keySizes[2] = {2048, 3072 };
  7619. #endif
  7620. #elif RSA_MAX_SIZE >= 2048
  7621. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7622. (RSA_MIN_SIZE <= 1024)
  7623. static const word32 keySizes[2] = {1024, 2048 };
  7624. #else
  7625. static const word32 keySizes[1] = {2048};
  7626. #endif
  7627. #else
  7628. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7629. (RSA_MIN_SIZE <= 1024)
  7630. static const word32 keySizes[1] = {1024 };
  7631. #else
  7632. #error No candidate RSA key sizes to benchmark.
  7633. #endif
  7634. #endif
  7635. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7636. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7637. }
  7638. }
  7639. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7640. {
  7641. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7642. }
  7643. #endif /* WOLFSSL_KEY_GEN */
  7644. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7645. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7646. #if defined(WOLFSSL_MDK_SHELL)
  7647. static char *certRSAname = "certs/rsa2048.der";
  7648. /* set by shell command */
  7649. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7650. #elif defined(FREESCALE_MQX)
  7651. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7652. #else
  7653. static const char *certRSAname = "certs/rsa2048.der";
  7654. #endif
  7655. #endif
  7656. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7657. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7658. #if defined(USE_CERT_BUFFERS_2048)
  7659. static const unsigned char rsa_2048_sig[] = {
  7660. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7661. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7662. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7663. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7664. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7665. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7666. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7667. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7668. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7669. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7670. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7671. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7672. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7673. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7674. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7675. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7676. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7677. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7678. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7679. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7680. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7681. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7682. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7683. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7684. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7685. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7686. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7687. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7688. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7689. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7690. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7691. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7692. };
  7693. #elif defined(USE_CERT_BUFFERS_3072)
  7694. static const unsigned char rsa_3072_sig[] = {
  7695. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7696. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7697. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7698. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7699. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7700. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7701. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7702. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7703. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7704. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7705. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7706. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7707. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7708. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7709. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7710. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7711. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7712. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7713. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7714. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7715. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7716. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7717. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7718. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7719. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7720. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7721. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7722. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7723. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7724. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7725. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7726. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7727. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7728. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7729. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7730. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7731. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7732. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7733. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7734. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7735. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7736. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7737. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7738. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7739. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7740. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7741. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7742. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7743. };
  7744. #else
  7745. #error Not Supported Yet!
  7746. #endif
  7747. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7748. static void bench_rsa_helper(int useDeviceID,
  7749. WC_ARRAY_ARG(rsaKey,
  7750. RsaKey,
  7751. BENCH_MAX_PENDING,
  7752. sizeof(RsaKey)),
  7753. word32 rsaKeySz)
  7754. {
  7755. int ret = 0, i, times, count = 0, pending = 0;
  7756. word32 idx = 0;
  7757. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7758. const char* messageStr = TEST_STRING;
  7759. const int len = (int)TEST_STRING_SZ;
  7760. #endif
  7761. double start = 0.0F;
  7762. const char**desc = bench_desc_words[lng_index];
  7763. DECLARE_MULTI_VALUE_STATS_VARS()
  7764. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7765. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7766. #endif
  7767. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7768. rsaKeySz, HEAP_HINT);
  7769. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7770. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7771. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7772. rsaKeySz, HEAP_HINT);
  7773. #else
  7774. byte* out[BENCH_MAX_PENDING];
  7775. #endif
  7776. XMEMSET(out, 0, sizeof(out));
  7777. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7778. rsaKeySz, HEAP_HINT);
  7779. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7780. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7781. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7782. rsaKeySz, HEAP_HINT);
  7783. if (out[0] == NULL) {
  7784. ret = MEMORY_E;
  7785. goto exit;
  7786. }
  7787. #endif
  7788. if (enc[0] == NULL) {
  7789. ret = MEMORY_E;
  7790. goto exit;
  7791. }
  7792. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7793. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7794. XMEMCPY(message, messageStr, len);
  7795. #endif
  7796. if (!rsa_sign_verify) {
  7797. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7798. /* begin public RSA */
  7799. bench_stats_start(&count, &start);
  7800. do {
  7801. for (times = 0; times < ntimes || pending > 0; ) {
  7802. bench_async_poll(&pending);
  7803. /* while free pending slots in queue, submit ops */
  7804. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7805. if (bench_async_check(&ret,
  7806. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7807. 1, &times, ntimes, &pending)) {
  7808. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7809. rsaKeySz/8, rsaKey[i],
  7810. GLOBAL_RNG);
  7811. if (!bench_async_handle(&ret,
  7812. BENCH_ASYNC_GET_DEV(
  7813. rsaKey[i]), 1, &times,
  7814. &pending)) {
  7815. goto exit_rsa_verify;
  7816. }
  7817. }
  7818. } /* for i */
  7819. RECORD_MULTI_VALUE_STATS();
  7820. } /* for times */
  7821. count += times;
  7822. } while (bench_stats_check(start)
  7823. #ifdef MULTI_VALUE_STATISTICS
  7824. || runs < minimum_runs
  7825. #endif
  7826. );
  7827. exit_rsa_verify:
  7828. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7829. useDeviceID, count, start, ret);
  7830. #ifdef MULTI_VALUE_STATISTICS
  7831. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7832. #endif
  7833. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7834. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7835. if (ret < 0) {
  7836. goto exit;
  7837. }
  7838. RESET_MULTI_VALUE_STATS_VARS();
  7839. /* capture resulting encrypt length */
  7840. idx = (word32)(rsaKeySz/8);
  7841. /* begin private async RSA */
  7842. bench_stats_start(&count, &start);
  7843. do {
  7844. for (times = 0; times < ntimes || pending > 0; ) {
  7845. bench_async_poll(&pending);
  7846. /* while free pending slots in queue, submit ops */
  7847. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7848. if (bench_async_check(&ret,
  7849. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7850. 1, &times, ntimes, &pending)) {
  7851. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7852. rsaKeySz/8, rsaKey[i]);
  7853. if (!bench_async_handle(&ret,
  7854. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7855. 1, &times, &pending)) {
  7856. goto exit_rsa_pub;
  7857. }
  7858. }
  7859. } /* for i */
  7860. RECORD_MULTI_VALUE_STATS();
  7861. } /* for times */
  7862. count += times;
  7863. } while (bench_stats_check(start)
  7864. #ifdef MULTI_VALUE_STATISTICS
  7865. || runs < minimum_runs
  7866. #endif
  7867. );
  7868. exit_rsa_pub:
  7869. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7870. useDeviceID, count, start, ret);
  7871. #ifdef MULTI_VALUE_STATISTICS
  7872. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7873. #endif
  7874. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7875. }
  7876. else {
  7877. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7878. /* begin RSA sign */
  7879. bench_stats_start(&count, &start);
  7880. do {
  7881. for (times = 0; times < ntimes || pending > 0; ) {
  7882. bench_async_poll(&pending);
  7883. /* while free pending slots in queue, submit ops */
  7884. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7885. if (bench_async_check(&ret,
  7886. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7887. 1, &times, ntimes, &pending)) {
  7888. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7889. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7890. if (!bench_async_handle(&ret,
  7891. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7892. 1, &times, &pending)) {
  7893. goto exit_rsa_sign;
  7894. }
  7895. }
  7896. } /* for i */
  7897. RECORD_MULTI_VALUE_STATS();
  7898. } /* for times */
  7899. count += times;
  7900. } while (bench_stats_check(start)
  7901. #ifdef MULTI_VALUE_STATISTICS
  7902. || runs < minimum_runs
  7903. #endif
  7904. );
  7905. exit_rsa_sign:
  7906. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7907. count, start, ret);
  7908. #ifdef MULTI_VALUE_STATISTICS
  7909. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7910. #endif
  7911. if (ret < 0) {
  7912. goto exit;
  7913. }
  7914. RESET_MULTI_VALUE_STATS_VARS();
  7915. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7916. /* capture resulting encrypt length */
  7917. idx = rsaKeySz/8;
  7918. /* begin RSA verify */
  7919. bench_stats_start(&count, &start);
  7920. do {
  7921. for (times = 0; times < ntimes || pending > 0; ) {
  7922. bench_async_poll(&pending);
  7923. /* while free pending slots in queue, submit ops */
  7924. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7925. if (bench_async_check(&ret,
  7926. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7927. 1, &times, ntimes, &pending)) {
  7928. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7929. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7930. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  7931. rsaKeySz/8, rsaKey[i]);
  7932. #elif defined(USE_CERT_BUFFERS_2048)
  7933. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  7934. idx = sizeof(rsa_2048_sig);
  7935. out[i] = NULL;
  7936. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7937. &out[i], rsaKey[i]);
  7938. if (ret > 0) {
  7939. ret = 0;
  7940. }
  7941. #elif defined(USE_CERT_BUFFERS_3072)
  7942. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  7943. idx = sizeof(rsa_3072_sig);
  7944. out[i] = NULL;
  7945. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7946. &out[i], rsaKey[i]);
  7947. if (ret > 0)
  7948. ret = 0;
  7949. #endif
  7950. if (!bench_async_handle(&ret,
  7951. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7952. 1, &times, &pending)) {
  7953. goto exit_rsa_verifyinline;
  7954. }
  7955. }
  7956. } /* for i */
  7957. RECORD_MULTI_VALUE_STATS();
  7958. } /* for times */
  7959. count += times;
  7960. } while (bench_stats_check(start)
  7961. #ifdef MULTI_VALUE_STATISTICS
  7962. || runs < minimum_runs
  7963. #endif
  7964. );
  7965. exit_rsa_verifyinline:
  7966. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  7967. useDeviceID, count, start, ret);
  7968. #ifdef MULTI_VALUE_STATISTICS
  7969. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7970. #endif
  7971. }
  7972. exit:
  7973. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  7974. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7975. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  7976. #endif
  7977. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7978. WC_FREE_VAR(message, HEAP_HINT);
  7979. #endif
  7980. }
  7981. void bench_rsa(int useDeviceID)
  7982. {
  7983. int i;
  7984. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  7985. sizeof(RsaKey), HEAP_HINT);
  7986. int ret = 0;
  7987. word32 rsaKeySz = 0;
  7988. const byte* tmp;
  7989. size_t bytes;
  7990. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7991. word32 idx;
  7992. #endif
  7993. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  7994. sizeof(RsaKey), HEAP_HINT);
  7995. #ifdef USE_CERT_BUFFERS_1024
  7996. tmp = rsa_key_der_1024;
  7997. bytes = (size_t)sizeof_rsa_key_der_1024;
  7998. rsaKeySz = 1024;
  7999. #elif defined(USE_CERT_BUFFERS_2048)
  8000. tmp = rsa_key_der_2048;
  8001. bytes = (size_t)sizeof_rsa_key_der_2048;
  8002. rsaKeySz = 2048;
  8003. #elif defined(USE_CERT_BUFFERS_3072)
  8004. tmp = rsa_key_der_3072;
  8005. bytes = (size_t)sizeof_rsa_key_der_3072;
  8006. rsaKeySz = 3072;
  8007. #elif defined(USE_CERT_BUFFERS_4096)
  8008. tmp = client_key_der_4096;
  8009. bytes = (size_t)sizeof_client_key_der_4096;
  8010. rsaKeySz = 4096;
  8011. #else
  8012. #error "need a cert buffer size"
  8013. #endif /* USE_CERT_BUFFERS */
  8014. /* init keys */
  8015. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8016. /* setup an async context for each key */
  8017. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8018. useDeviceID ? devId : INVALID_DEVID);
  8019. if (ret < 0) {
  8020. goto exit;
  8021. }
  8022. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8023. #ifdef WC_RSA_BLINDING
  8024. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8025. if (ret != 0)
  8026. goto exit;
  8027. #endif
  8028. #endif
  8029. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8030. /* decode the private key */
  8031. idx = 0;
  8032. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8033. rsaKey[i], (word32)bytes)) != 0) {
  8034. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8035. goto exit;
  8036. }
  8037. #elif defined(WOLFSSL_PUBLIC_MP)
  8038. /* get offset to public portion of the RSA key */
  8039. #ifdef USE_CERT_BUFFERS_1024
  8040. bytes = 11;
  8041. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8042. bytes = 12;
  8043. #endif
  8044. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8045. if (ret != 0) {
  8046. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8047. goto exit;
  8048. }
  8049. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8050. if (ret != 0) {
  8051. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8052. goto exit;
  8053. }
  8054. #else
  8055. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8056. rsaKeySz = 0;
  8057. #endif
  8058. }
  8059. if (rsaKeySz > 0) {
  8060. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8061. }
  8062. (void)bytes;
  8063. (void)tmp;
  8064. exit:
  8065. /* cleanup */
  8066. if (WC_ARRAY_OK(rsaKey)) {
  8067. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8068. wc_FreeRsaKey(rsaKey[i]);
  8069. }
  8070. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8071. }
  8072. }
  8073. #ifdef WOLFSSL_KEY_GEN
  8074. /* bench any size of RSA key */
  8075. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8076. {
  8077. int ret = 0, i, pending = 0;
  8078. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8079. sizeof(RsaKey), HEAP_HINT);
  8080. int isPending[BENCH_MAX_PENDING];
  8081. long exp = 65537L;
  8082. /* clear for done cleanup */
  8083. XMEMSET(isPending, 0, sizeof(isPending));
  8084. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8085. sizeof(RsaKey), HEAP_HINT);
  8086. /* init keys */
  8087. do {
  8088. pending = 0;
  8089. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8090. if (!isPending[i]) { /* if making the key is pending then just call
  8091. * wc_MakeRsaKey again */
  8092. /* setup an async context for each key */
  8093. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8094. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8095. goto exit;
  8096. }
  8097. #ifdef WC_RSA_BLINDING
  8098. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8099. if (ret != 0)
  8100. goto exit;
  8101. #endif
  8102. }
  8103. /* create the RSA key */
  8104. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8105. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8106. isPending[i] = 1;
  8107. pending = 1;
  8108. }
  8109. else if (ret != 0) {
  8110. printf("wc_MakeRsaKey failed! %d\n", ret);
  8111. goto exit;
  8112. }
  8113. } /* for i */
  8114. } while (pending > 0);
  8115. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8116. exit:
  8117. /* cleanup */
  8118. if (WC_ARRAY_OK(rsaKey)) {
  8119. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8120. wc_FreeRsaKey(rsaKey[i]);
  8121. }
  8122. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8123. }
  8124. }
  8125. #endif /* WOLFSSL_KEY_GEN */
  8126. #endif /* !NO_RSA */
  8127. #ifndef NO_DH
  8128. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8129. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8130. #if defined(WOLFSSL_MDK_SHELL)
  8131. static char *certDHname = "certs/dh2048.der";
  8132. /* set by shell command */
  8133. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8134. #elif defined(FREESCALE_MQX)
  8135. static char *certDHname = "a:\\certs\\dh2048.der";
  8136. #elif defined(NO_ASN)
  8137. /* do nothing, but don't need a file */
  8138. #else
  8139. static const char *certDHname = "certs/dh2048.der";
  8140. #endif
  8141. #endif
  8142. #ifdef HAVE_FFDHE_4096
  8143. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8144. #else
  8145. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8146. #endif
  8147. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8148. void bench_dh(int useDeviceID)
  8149. {
  8150. int ret = 0, i;
  8151. int count = 0, times, pending = 0;
  8152. const byte* tmp = NULL;
  8153. double start = 0.0F;
  8154. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8155. sizeof(DhKey), HEAP_HINT);
  8156. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8157. const char**desc = bench_desc_words[lng_index];
  8158. #ifndef NO_ASN
  8159. size_t bytes = 0;
  8160. word32 idx;
  8161. #endif
  8162. word32 pubSz[BENCH_MAX_PENDING];
  8163. word32 privSz[BENCH_MAX_PENDING];
  8164. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8165. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8166. word32 agreeSz[BENCH_MAX_PENDING];
  8167. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8168. #ifdef HAVE_PUBLIC_FFDHE
  8169. const DhParams *params = NULL;
  8170. #else
  8171. int paramName = 0;
  8172. #endif
  8173. #endif
  8174. DECLARE_MULTI_VALUE_STATS_VARS()
  8175. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8176. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8177. WC_DECLARE_VAR(pub2, byte,
  8178. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8179. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8180. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8181. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8182. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8183. WC_DECLARE_VAR(priv2, byte,
  8184. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8185. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8186. XMEMSET(pub, 0, sizeof(pub));
  8187. XMEMSET(agree, 0, sizeof(agree));
  8188. XMEMSET(priv, 0, sizeof(priv));
  8189. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8190. sizeof(DhKey), HEAP_HINT);
  8191. WC_ALLOC_ARRAY(pub, byte,
  8192. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8193. WC_ALLOC_ARRAY(agree, byte,
  8194. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8195. WC_ALLOC_ARRAY(priv, byte,
  8196. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8197. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8198. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8199. (void)tmp;
  8200. if (!use_ffdhe) {
  8201. #if defined(NO_ASN)
  8202. dhKeySz = 1024;
  8203. /* do nothing, but don't use default FILE */
  8204. #elif defined(USE_CERT_BUFFERS_1024)
  8205. tmp = dh_key_der_1024;
  8206. bytes = (size_t)sizeof_dh_key_der_1024;
  8207. dhKeySz = 1024;
  8208. #elif defined(USE_CERT_BUFFERS_2048)
  8209. tmp = dh_key_der_2048;
  8210. bytes = (size_t)sizeof_dh_key_der_2048;
  8211. dhKeySz = 2048;
  8212. #elif defined(USE_CERT_BUFFERS_3072)
  8213. tmp = dh_key_der_3072;
  8214. bytes = (size_t)sizeof_dh_key_der_3072;
  8215. dhKeySz = 3072;
  8216. #elif defined(USE_CERT_BUFFERS_4096)
  8217. tmp = dh_key_der_4096;
  8218. bytes = (size_t)sizeof_dh_key_der_4096;
  8219. dhKeySz = 4096;
  8220. #else
  8221. #error "need to define a cert buffer size"
  8222. #endif /* USE_CERT_BUFFERS */
  8223. }
  8224. #ifdef HAVE_FFDHE_2048
  8225. else if (use_ffdhe == 2048) {
  8226. #ifdef HAVE_PUBLIC_FFDHE
  8227. params = wc_Dh_ffdhe2048_Get();
  8228. #else
  8229. paramName = WC_FFDHE_2048;
  8230. #endif
  8231. dhKeySz = 2048;
  8232. }
  8233. #endif
  8234. #ifdef HAVE_FFDHE_3072
  8235. else if (use_ffdhe == 3072) {
  8236. #ifdef HAVE_PUBLIC_FFDHE
  8237. params = wc_Dh_ffdhe3072_Get();
  8238. #else
  8239. paramName = WC_FFDHE_3072;
  8240. #endif
  8241. dhKeySz = 3072;
  8242. }
  8243. #endif
  8244. #ifdef HAVE_FFDHE_4096
  8245. else if (use_ffdhe == 4096) {
  8246. #ifdef HAVE_PUBLIC_FFDHE
  8247. params = wc_Dh_ffdhe4096_Get();
  8248. #else
  8249. paramName = WC_FFDHE_4096;
  8250. #endif
  8251. dhKeySz = 4096;
  8252. }
  8253. #endif
  8254. /* init keys */
  8255. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8256. /* setup an async context for each key */
  8257. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8258. useDeviceID ? devId : INVALID_DEVID);
  8259. if (ret != 0)
  8260. goto exit;
  8261. /* setup key */
  8262. if (!use_ffdhe) {
  8263. #ifdef NO_ASN
  8264. ret = wc_DhSetKey(dhKey[i], dh_p,
  8265. sizeof(dh_p), dh_g, sizeof(dh_g));
  8266. #else
  8267. idx = 0;
  8268. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8269. #endif
  8270. }
  8271. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8272. #ifdef HAVE_PUBLIC_FFDHE
  8273. else if (params != NULL) {
  8274. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8275. params->g, params->g_len);
  8276. }
  8277. #else
  8278. else if (paramName != 0) {
  8279. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8280. }
  8281. #endif
  8282. #endif
  8283. if (ret != 0) {
  8284. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8285. goto exit;
  8286. }
  8287. }
  8288. /* Key Gen */
  8289. bench_stats_start(&count, &start);
  8290. PRIVATE_KEY_UNLOCK();
  8291. do {
  8292. /* while free pending slots in queue, submit ops */
  8293. for (times = 0; times < genTimes || pending > 0; ) {
  8294. bench_async_poll(&pending);
  8295. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8296. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8297. 0, &times, genTimes, &pending)) {
  8298. privSz[i] = BENCH_DH_PRIV_SIZE;
  8299. pubSz[i] = BENCH_DH_KEY_SIZE;
  8300. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8301. priv[i], &privSz[i],
  8302. pub[i], &pubSz[i]);
  8303. if (!bench_async_handle(&ret,
  8304. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8305. 0, &times, &pending)) {
  8306. goto exit_dh_gen;
  8307. }
  8308. }
  8309. } /* for i */
  8310. RECORD_MULTI_VALUE_STATS();
  8311. } /* for times */
  8312. count += times;
  8313. } while (bench_stats_check(start)
  8314. #ifdef MULTI_VALUE_STATISTICS
  8315. || runs < minimum_runs
  8316. #endif
  8317. );
  8318. PRIVATE_KEY_LOCK();
  8319. exit_dh_gen:
  8320. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8321. useDeviceID, count, start, ret);
  8322. #ifdef MULTI_VALUE_STATISTICS
  8323. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8324. #endif
  8325. if (ret < 0) {
  8326. goto exit;
  8327. }
  8328. RESET_MULTI_VALUE_STATS_VARS();
  8329. /* Generate key to use as other public */
  8330. PRIVATE_KEY_UNLOCK();
  8331. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8332. priv2, &privSz2, pub2, &pubSz2);
  8333. PRIVATE_KEY_LOCK();
  8334. #ifdef WOLFSSL_ASYNC_CRYPT
  8335. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8336. #endif
  8337. /* Key Agree */
  8338. bench_stats_start(&count, &start);
  8339. PRIVATE_KEY_UNLOCK();
  8340. do {
  8341. for (times = 0; times < agreeTimes || pending > 0; ) {
  8342. bench_async_poll(&pending);
  8343. /* while free pending slots in queue, submit ops */
  8344. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8345. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8346. 0, &times, agreeTimes, &pending)) {
  8347. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8348. privSz[i], pub2, pubSz2);
  8349. if (!bench_async_handle(&ret,
  8350. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8351. goto exit;
  8352. }
  8353. }
  8354. } /* for i */
  8355. RECORD_MULTI_VALUE_STATS();
  8356. } /* for times */
  8357. count += times;
  8358. } while (bench_stats_check(start)
  8359. #ifdef MULTI_VALUE_STATISTICS
  8360. || runs < minimum_runs
  8361. #endif
  8362. );
  8363. PRIVATE_KEY_LOCK();
  8364. exit:
  8365. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8366. useDeviceID, count, start, ret);
  8367. #ifdef MULTI_VALUE_STATISTICS
  8368. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8369. #endif
  8370. /* cleanup */
  8371. if (WC_ARRAY_OK(dhKey)) {
  8372. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8373. wc_FreeDhKey(dhKey[i]);
  8374. }
  8375. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8376. }
  8377. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8378. WC_FREE_VAR(pub2, HEAP_HINT);
  8379. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8380. WC_FREE_VAR(priv2, HEAP_HINT);
  8381. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8382. }
  8383. #endif /* !NO_DH */
  8384. #ifdef WOLFSSL_HAVE_KYBER
  8385. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8386. KyberKey* key)
  8387. {
  8388. int ret = 0, times, count, pending = 0;
  8389. double start;
  8390. const char**desc = bench_desc_words[lng_index];
  8391. DECLARE_MULTI_VALUE_STATS_VARS()
  8392. /* KYBER Make Key */
  8393. bench_stats_start(&count, &start);
  8394. do {
  8395. /* while free pending slots in queue, submit ops */
  8396. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8397. wc_KyberKey_Free(key);
  8398. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8399. if (ret != 0)
  8400. goto exit;
  8401. #ifdef KYBER_NONDETERMINISTIC
  8402. ret = wc_KyberKey_MakeKey(key, &gRng);
  8403. #else
  8404. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8405. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8406. #endif
  8407. if (ret != 0)
  8408. goto exit;
  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. exit:
  8418. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8419. #ifdef MULTI_VALUE_STATISTICS
  8420. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8421. #endif
  8422. }
  8423. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8424. {
  8425. int ret = 0, times, count, pending = 0;
  8426. double start;
  8427. const char**desc = bench_desc_words[lng_index];
  8428. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8429. byte ss[KYBER_SS_SZ];
  8430. word32 ctSz;
  8431. DECLARE_MULTI_VALUE_STATS_VARS()
  8432. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8433. if (ret != 0) {
  8434. return;
  8435. }
  8436. /* KYBER Encapsulate */
  8437. bench_stats_start(&count, &start);
  8438. do {
  8439. /* while free pending slots in queue, submit ops */
  8440. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8441. #ifdef KYBER_NONDETERMINISTIC
  8442. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8443. #else
  8444. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8445. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8446. sizeof(rand));
  8447. #endif
  8448. if (ret != 0)
  8449. goto exit_encap;
  8450. RECORD_MULTI_VALUE_STATS();
  8451. } /* for times */
  8452. count += times;
  8453. } while (bench_stats_check(start)
  8454. #ifdef MULTI_VALUE_STATISTICS
  8455. || runs < minimum_runs
  8456. #endif
  8457. );
  8458. exit_encap:
  8459. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8460. #ifdef MULTI_VALUE_STATISTICS
  8461. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8462. #endif
  8463. RESET_MULTI_VALUE_STATS_VARS();
  8464. /* KYBER Decapsulate */
  8465. bench_stats_start(&count, &start);
  8466. do {
  8467. /* while free pending slots in queue, submit ops */
  8468. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8469. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8470. if (ret != 0)
  8471. goto exit_decap;
  8472. RECORD_MULTI_VALUE_STATS();
  8473. } /* for times */
  8474. count += times;
  8475. } while (bench_stats_check(start)
  8476. #ifdef MULTI_VALUE_STATISTICS
  8477. || runs < minimum_runs
  8478. #endif
  8479. );
  8480. exit_decap:
  8481. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8482. #ifdef MULTI_VALUE_STATISTICS
  8483. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8484. #endif
  8485. }
  8486. void bench_kyber(int type)
  8487. {
  8488. KyberKey key;
  8489. const char* name = NULL;
  8490. int keySize = 0;
  8491. switch (type) {
  8492. #ifdef WOLFSSL_KYBER512
  8493. case KYBER512:
  8494. name = "KYBER512 ";
  8495. keySize = 128;
  8496. break;
  8497. #endif
  8498. #ifdef WOLFSSL_KYBER768
  8499. case KYBER768:
  8500. name = "KYBER768 ";
  8501. keySize = 192;
  8502. break;
  8503. #endif
  8504. #ifdef WOLFSSL_KYBER1024
  8505. case KYBER1024:
  8506. name = "KYBER1024";
  8507. keySize = 256;
  8508. break;
  8509. #endif
  8510. }
  8511. bench_kyber_keygen(type, name, keySize, &key);
  8512. bench_kyber_encap(name, keySize, &key);
  8513. wc_KyberKey_Free(&key);
  8514. }
  8515. #endif
  8516. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8517. /* WC_LMS_PARM_L2_H10_W2
  8518. * signature length: 9300 */
  8519. static const byte lms_priv_L2_H10_W2[64] =
  8520. {
  8521. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8522. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8523. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8524. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8525. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8526. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8527. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8528. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8529. };
  8530. static const byte lms_pub_L2_H10_W2[60] =
  8531. {
  8532. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8533. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8534. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8535. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8536. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8537. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8538. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8539. 0x7F,0xC8,0x91,0xB0
  8540. };
  8541. /* WC_LMS_PARM_L2_H10_W4
  8542. * signature length: 5076 */
  8543. static const byte lms_priv_L2_H10_W4[64] =
  8544. {
  8545. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8546. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8547. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8548. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8549. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8550. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8551. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8552. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8553. };
  8554. static const byte lms_pub_L2_H10_W4[60] =
  8555. {
  8556. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8557. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8558. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8559. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8560. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8561. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8562. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8563. 0x6B,0x9A,0xD3,0x14
  8564. };
  8565. /* WC_LMS_PARM_L3_H5_W4
  8566. * signature length: 7160 */
  8567. static const byte lms_priv_L3_H5_W4[64] =
  8568. {
  8569. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8570. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8571. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8572. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8573. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8574. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8575. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8576. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8577. };
  8578. static const byte lms_pub_L3_H5_W4[60] =
  8579. {
  8580. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8581. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8582. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8583. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8584. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8585. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8586. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8587. 0xAB,0x4B,0x51,0x39
  8588. };
  8589. /* WC_LMS_PARM_L3_H5_W8
  8590. * signature length: 3992 */
  8591. static const byte lms_priv_L3_H5_W8[64] =
  8592. {
  8593. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8594. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8595. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8596. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8597. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8598. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8599. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8600. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8601. };
  8602. static const byte lms_pub_L3_H5_W8[60] =
  8603. {
  8604. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8605. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8606. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8607. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8608. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8609. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8610. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8611. 0x83,0xAB,0x43,0xAF
  8612. };
  8613. /* WC_LMS_PARM_L3_H10_W4
  8614. * signature length: 7640 */
  8615. static const byte lms_priv_L3_H10_W4[64] =
  8616. {
  8617. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8618. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8619. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8620. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8621. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8622. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8623. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8624. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8625. };
  8626. static const byte lms_pub_L3_H10_W4[60] =
  8627. {
  8628. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8629. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8630. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8631. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8632. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8633. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8634. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8635. 0x8D,0x78,0xD5,0xA8
  8636. };
  8637. /* WC_LMS_PARM_L4_H5_W8
  8638. * signature length: 5340 */
  8639. static const byte lms_priv_L4_H5_W8[64] =
  8640. {
  8641. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8642. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8643. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8644. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8645. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8646. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8647. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8648. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8649. };
  8650. static const byte lms_pub_L4_H5_W8[60] =
  8651. {
  8652. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8653. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8654. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8655. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8656. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8657. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8658. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8659. 0x74,0x24,0x12,0xC8
  8660. };
  8661. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8662. {
  8663. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8664. * BE USED FOR TESTING PURPOSES! Production applications should
  8665. * write only to non-volatile storage. */
  8666. XMEMCPY(context, priv, privSz);
  8667. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8668. }
  8669. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8670. {
  8671. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8672. * BE USED FOR TESTING PURPOSES! */
  8673. XMEMCPY(priv, context, privSz);
  8674. return WC_LMS_RC_READ_TO_MEMORY;
  8675. }
  8676. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8677. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8678. {
  8679. WC_RNG rng;
  8680. LmsKey key;
  8681. int ret;
  8682. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8683. int times = 0;
  8684. int count = 0;
  8685. double start = 0.0F;
  8686. int levels;
  8687. int height;
  8688. int winternitz;
  8689. const char* str = wc_LmsKey_ParmToStr(parm);
  8690. DECLARE_MULTI_VALUE_STATS_VARS()
  8691. #ifndef HAVE_FIPS
  8692. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8693. #else
  8694. ret = wc_InitRng(&rng);
  8695. #endif
  8696. if (ret != 0) {
  8697. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8698. return;
  8699. }
  8700. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8701. if (ret) {
  8702. printf("wc_LmsKey_Init failed: %d\n", ret);
  8703. wc_FreeRng(&rng);
  8704. return;
  8705. }
  8706. count = 0;
  8707. bench_stats_start(&count, &start);
  8708. do {
  8709. /* LMS is stateful. Async queuing not practical. */
  8710. for (times = 0; times < 1; ++times) {
  8711. wc_LmsKey_Free(&key);
  8712. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8713. if (ret) {
  8714. printf("wc_LmsKey_Init failed: %d\n", ret);
  8715. goto exit_lms_keygen;
  8716. }
  8717. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8718. if (ret) {
  8719. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8720. goto exit_lms_keygen;
  8721. }
  8722. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8723. if (ret) {
  8724. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8725. ret);
  8726. goto exit_lms_keygen;
  8727. }
  8728. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8729. if (ret) {
  8730. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8731. ret);
  8732. goto exit_lms_keygen;
  8733. }
  8734. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8735. if (ret) {
  8736. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8737. goto exit_lms_keygen;
  8738. }
  8739. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8740. if (ret) {
  8741. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8742. ret);
  8743. goto exit_lms_keygen;
  8744. }
  8745. ret = wc_LmsKey_MakeKey(&key, &rng);
  8746. if (ret) {
  8747. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8748. goto exit_lms_keygen;
  8749. }
  8750. RECORD_MULTI_VALUE_STATS();
  8751. }
  8752. count += times;
  8753. } while (bench_stats_check(start)
  8754. #ifdef MULTI_VALUE_STATISTICS
  8755. || runs < minimum_runs
  8756. #endif
  8757. );
  8758. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8759. count, start, ret);
  8760. #ifdef MULTI_VALUE_STATISTICS
  8761. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8762. #endif
  8763. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8764. if (ret) {
  8765. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8766. }
  8767. exit_lms_keygen:
  8768. wc_LmsKey_Free(&key);
  8769. wc_FreeRng(&rng);
  8770. }
  8771. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8772. {
  8773. LmsKey key;
  8774. int ret = 0;
  8775. const char * msg = TEST_STRING;
  8776. word32 msgSz = TEST_STRING_SZ;
  8777. byte * sig = NULL;
  8778. word32 sigSz = 0;
  8779. word32 privLen = 0;
  8780. int loaded = 0;
  8781. int times = 0;
  8782. int count = 0;
  8783. double start = 0.0F;
  8784. const char * str = wc_LmsKey_ParmToStr(parm);
  8785. DECLARE_MULTI_VALUE_STATS_VARS()
  8786. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8787. if (ret) {
  8788. printf("wc_LmsKey_Init failed: %d\n", ret);
  8789. goto exit_lms_sign_verify;
  8790. }
  8791. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8792. if (ret) {
  8793. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8794. goto exit_lms_sign_verify;
  8795. }
  8796. switch (parm) {
  8797. case WC_LMS_PARM_L2_H10_W2:
  8798. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8799. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8800. break;
  8801. case WC_LMS_PARM_L2_H10_W4:
  8802. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8803. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8804. break;
  8805. case WC_LMS_PARM_L3_H5_W4:
  8806. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8807. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8808. break;
  8809. case WC_LMS_PARM_L3_H5_W8:
  8810. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8811. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8812. break;
  8813. case WC_LMS_PARM_L3_H10_W4:
  8814. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8815. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8816. break;
  8817. case WC_LMS_PARM_L4_H5_W8:
  8818. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8819. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8820. break;
  8821. case WC_LMS_PARM_NONE:
  8822. case WC_LMS_PARM_L1_H15_W2:
  8823. case WC_LMS_PARM_L1_H15_W4:
  8824. case WC_LMS_PARM_L2_H10_W8:
  8825. case WC_LMS_PARM_L3_H5_W2:
  8826. case WC_LMS_PARM_L1_H5_W1:
  8827. case WC_LMS_PARM_L1_H5_W2:
  8828. case WC_LMS_PARM_L1_H5_W4:
  8829. case WC_LMS_PARM_L1_H5_W8:
  8830. case WC_LMS_PARM_L1_H10_W2:
  8831. case WC_LMS_PARM_L1_H10_W4:
  8832. case WC_LMS_PARM_L1_H10_W8:
  8833. case WC_LMS_PARM_L1_H15_W8:
  8834. case WC_LMS_PARM_L1_H20_W2:
  8835. case WC_LMS_PARM_L1_H20_W4:
  8836. case WC_LMS_PARM_L1_H20_W8:
  8837. case WC_LMS_PARM_L2_H5_W2:
  8838. case WC_LMS_PARM_L2_H5_W4:
  8839. case WC_LMS_PARM_L2_H5_W8:
  8840. case WC_LMS_PARM_L2_H15_W2:
  8841. case WC_LMS_PARM_L2_H15_W4:
  8842. case WC_LMS_PARM_L2_H15_W8:
  8843. case WC_LMS_PARM_L2_H20_W2:
  8844. case WC_LMS_PARM_L2_H20_W4:
  8845. case WC_LMS_PARM_L2_H20_W8:
  8846. case WC_LMS_PARM_L3_H10_W8:
  8847. case WC_LMS_PARM_L4_H5_W2:
  8848. case WC_LMS_PARM_L4_H5_W4:
  8849. case WC_LMS_PARM_L4_H10_W4:
  8850. case WC_LMS_PARM_L4_H10_W8:
  8851. default:
  8852. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8853. break;
  8854. }
  8855. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8856. if (ret) {
  8857. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8858. goto exit_lms_sign_verify;
  8859. }
  8860. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8861. if (ret) {
  8862. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8863. goto exit_lms_sign_verify;
  8864. }
  8865. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8866. if (ret) {
  8867. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8868. goto exit_lms_sign_verify;
  8869. }
  8870. /* Even with saved priv/pub keys, we must still reload the private
  8871. * key before using it. Reloading the private key is the bottleneck
  8872. * for larger heights. Only print load time in debug builds. */
  8873. count = 0;
  8874. bench_stats_start(&count, &start);
  8875. #ifndef WOLFSSL_WC_LMS_SMALL
  8876. do {
  8877. #ifdef WOLFSSL_WC_LMS
  8878. key.priv.inited = 0;
  8879. key.state = WC_LMS_STATE_PARMSET;
  8880. #endif
  8881. ret = wc_LmsKey_Reload(&key);
  8882. if (ret) {
  8883. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8884. goto exit_lms_sign_verify;
  8885. }
  8886. RECORD_MULTI_VALUE_STATS();
  8887. count++;
  8888. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8889. if (ret) {
  8890. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8891. goto exit_lms_sign_verify;
  8892. }
  8893. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8894. if (ret) {
  8895. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8896. goto exit_lms_sign_verify;
  8897. }
  8898. #ifdef HAVE_LIBLMS
  8899. break;
  8900. #endif
  8901. } while (bench_stats_check(start)
  8902. #ifdef MULTI_VALUE_STATISTICS
  8903. || runs < minimum_runs
  8904. #endif
  8905. );
  8906. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  8907. count, start, ret);
  8908. #ifdef MULTI_VALUE_STATISTICS
  8909. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8910. #endif
  8911. RESET_MULTI_VALUE_STATS_VARS();
  8912. #else
  8913. ret = wc_LmsKey_Reload(&key);
  8914. if (ret) {
  8915. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8916. goto exit_lms_sign_verify;
  8917. }
  8918. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8919. if (ret) {
  8920. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8921. goto exit_lms_sign_verify;
  8922. }
  8923. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8924. if (ret) {
  8925. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8926. goto exit_lms_sign_verify;
  8927. }
  8928. #endif
  8929. loaded = 1;
  8930. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8931. if (sig == NULL) {
  8932. printf("bench_lms_sign_verify malloc failed\n");
  8933. goto exit_lms_sign_verify;
  8934. }
  8935. count = 0;
  8936. bench_stats_start(&count, &start);
  8937. do {
  8938. /* LMS is stateful. Async queuing not practical. */
  8939. #ifndef WOLFSSL_WC_LMS_SMALL
  8940. for (times = 0; times < ntimes; ++times)
  8941. #else
  8942. for (times = 0; times < 1; ++times)
  8943. #endif
  8944. {
  8945. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  8946. if (ret) {
  8947. printf("wc_LmsKey_Sign failed: %d\n", ret);
  8948. goto exit_lms_sign_verify;
  8949. }
  8950. RECORD_MULTI_VALUE_STATS();
  8951. if (!wc_LmsKey_SigsLeft(&key)) {
  8952. break;
  8953. }
  8954. }
  8955. count += times;
  8956. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  8957. #ifdef MULTI_VALUE_STATISTICS
  8958. || runs < minimum_runs
  8959. #endif
  8960. ));
  8961. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  8962. count, start, ret);
  8963. #ifdef MULTI_VALUE_STATISTICS
  8964. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8965. #endif
  8966. RESET_MULTI_VALUE_STATS_VARS();
  8967. count = 0;
  8968. bench_stats_start(&count, &start);
  8969. do {
  8970. /* LMS is stateful. Async queuing not practical. */
  8971. for (times = 0; times < ntimes; ++times) {
  8972. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  8973. if (ret) {
  8974. printf("wc_LmsKey_Verify failed: %d\n", ret);
  8975. goto exit_lms_sign_verify;
  8976. }
  8977. RECORD_MULTI_VALUE_STATS();
  8978. }
  8979. count += times;
  8980. } while (bench_stats_check(start)
  8981. #ifdef MULTI_VALUE_STATISTICS
  8982. || runs < minimum_runs
  8983. #endif
  8984. );
  8985. exit_lms_sign_verify:
  8986. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  8987. count, start, ret);
  8988. #ifdef MULTI_VALUE_STATISTICS
  8989. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8990. #endif
  8991. if (loaded) {
  8992. wc_LmsKey_Free(&key);
  8993. }
  8994. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8995. return;
  8996. }
  8997. void bench_lms(void)
  8998. {
  8999. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9000. #ifdef BENCH_LMS_SLOW_KEYGEN
  9001. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9002. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9003. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9004. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9005. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9006. #undef LMS_PARAMS_BENCHED
  9007. #define LMS_PARAMS_BENCHED
  9008. #endif
  9009. #endif
  9010. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9011. (LMS_MAX_HEIGHT >= 10))
  9012. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9013. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9014. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9015. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9016. #undef LMS_PARAMS_BENCHED
  9017. #define LMS_PARAMS_BENCHED
  9018. #ifdef BENCH_LMS_SLOW_KEYGEN
  9019. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9020. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9021. #endif
  9022. #endif
  9023. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9024. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9025. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9026. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9027. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9028. #undef LMS_PARAMS_BENCHED
  9029. #define LMS_PARAMS_BENCHED
  9030. #endif
  9031. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9032. (LMS_MAX_HEIGHT >= 10))
  9033. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9034. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9035. #endif
  9036. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9037. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9038. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9039. #endif
  9040. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9041. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9042. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9043. #endif
  9044. return;
  9045. }
  9046. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9047. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9048. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9049. void *context)
  9050. {
  9051. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9052. * BE USED FOR TESTING PURPOSES! Production applications should
  9053. * write only to non-volatile storage. */
  9054. XMEMCPY(context, priv, privSz);
  9055. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9056. }
  9057. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9058. void *context)
  9059. {
  9060. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9061. * BE USED FOR TESTING PURPOSES! */
  9062. XMEMCPY(priv, context, privSz);
  9063. return WC_XMSS_RC_READ_TO_MEMORY;
  9064. }
  9065. static void bench_xmss_sign_verify(const char * params)
  9066. {
  9067. WC_RNG rng;
  9068. XmssKey key;
  9069. word32 pkSz = 0;
  9070. word32 skSz = 0;
  9071. int freeRng = 0;
  9072. int freeKey = 0;
  9073. unsigned char * sk = NULL;
  9074. const char * msg = "XMSS post quantum signature test";
  9075. word32 msgSz = (word32) XSTRLEN(msg);
  9076. int ret = 0;
  9077. byte * sig = NULL;
  9078. word32 sigSz = 0;
  9079. int times = 0;
  9080. int count = 0;
  9081. double start = 0.0F;
  9082. #ifndef HAVE_FIPS
  9083. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9084. #else
  9085. ret = wc_InitRng(&rng);
  9086. #endif
  9087. if (ret != 0) {
  9088. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9089. goto exit_xmss_sign_verify;
  9090. }
  9091. freeRng = 1;
  9092. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9093. if (ret != 0) {
  9094. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9095. goto exit_xmss_sign_verify;
  9096. }
  9097. ret = wc_XmssKey_SetParamStr(&key, params);
  9098. if (ret != 0) {
  9099. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9100. goto exit_xmss_sign_verify;
  9101. }
  9102. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9103. if (ret != 0) {
  9104. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9105. goto exit_xmss_sign_verify;
  9106. }
  9107. #ifndef WOLFSSL_WC_XMSS
  9108. if (pkSz != XMSS_SHA256_PUBLEN) {
  9109. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9110. XMSS_SHA256_PUBLEN);
  9111. goto exit_xmss_sign_verify;
  9112. }
  9113. #endif
  9114. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9115. if (ret != 0 || skSz <= 0) {
  9116. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9117. goto exit_xmss_sign_verify;
  9118. }
  9119. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9120. if (ret != 0 || sigSz <= 0) {
  9121. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9122. goto exit_xmss_sign_verify;
  9123. }
  9124. /* Allocate secret keys.*/
  9125. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9126. if (sk == NULL) {
  9127. fprintf(stderr, "error: allocate xmss sk failed\n");
  9128. goto exit_xmss_sign_verify;
  9129. }
  9130. /* Allocate signature array. */
  9131. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9132. if (sig == NULL) {
  9133. fprintf(stderr, "error: allocate xmss sig failed\n");
  9134. goto exit_xmss_sign_verify;
  9135. }
  9136. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9137. if (ret != 0) {
  9138. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9139. goto exit_xmss_sign_verify;
  9140. }
  9141. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9142. if (ret != 0) {
  9143. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9144. goto exit_xmss_sign_verify;
  9145. }
  9146. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9147. if (ret != 0) {
  9148. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9149. goto exit_xmss_sign_verify;
  9150. }
  9151. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9152. fprintf(stderr, "params: %s\n", params);
  9153. fprintf(stderr, "pkSz: %d\n", pkSz);
  9154. fprintf(stderr, "skSz: %d\n", skSz);
  9155. fprintf(stderr, "sigSz: %d\n", sigSz);
  9156. #endif
  9157. /* Making the private key is the bottleneck for larger heights. */
  9158. count = 0;
  9159. bench_stats_start(&count, &start);
  9160. ret = wc_XmssKey_MakeKey(&key, &rng);
  9161. if (ret != 0) {
  9162. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9163. goto exit_xmss_sign_verify;
  9164. }
  9165. /* Can only do one at a time - state changes after make key. */
  9166. count +=1;
  9167. bench_stats_check(start);
  9168. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9169. freeKey = 1;
  9170. count = 0;
  9171. bench_stats_start(&count, &start);
  9172. do {
  9173. /* XMSS is stateful. Async queuing not practical. */
  9174. #ifndef WOLFSSL_WC_XMSS_SMALL
  9175. for (times = 0; times < ntimes; ++times)
  9176. #else
  9177. for (times = 0; times < 1; ++times)
  9178. #endif
  9179. {
  9180. if (!wc_XmssKey_SigsLeft(&key))
  9181. break;
  9182. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9183. if (ret) {
  9184. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9185. goto exit_xmss_sign_verify;
  9186. }
  9187. }
  9188. count += times;
  9189. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9190. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9191. count = 0;
  9192. bench_stats_start(&count, &start);
  9193. do {
  9194. /* XMSS is stateful. Async queuing not practical. */
  9195. for (times = 0; times < ntimes; ++times) {
  9196. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9197. if (ret) {
  9198. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9199. goto exit_xmss_sign_verify;
  9200. }
  9201. }
  9202. count += times;
  9203. } while (bench_stats_check(start));
  9204. exit_xmss_sign_verify:
  9205. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9206. /* Cleanup everything. */
  9207. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9208. sig = NULL;
  9209. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9210. sk = NULL;
  9211. if (freeRng) {
  9212. wc_FreeRng(&rng);
  9213. }
  9214. if (freeKey) {
  9215. wc_XmssKey_Free(&key);
  9216. }
  9217. return;
  9218. }
  9219. void bench_xmss(int hash)
  9220. {
  9221. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9222. * sets.
  9223. *
  9224. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9225. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9226. * very slow, their signatures and private keys quite large,
  9227. * and xmss private keys are not portable across different
  9228. * XMSS/XMSS^MT implementations.
  9229. *
  9230. * The bottleneck in key generation is the height of the first
  9231. * level tree (or h/d).
  9232. *
  9233. * h is the total height of the hyper tree, and d the number of
  9234. * trees.
  9235. */
  9236. /* h/d h d */
  9237. #ifdef WC_XMSS_SHA256
  9238. if (hash == WC_HASH_TYPE_SHA256) {
  9239. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9240. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9241. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9242. #endif
  9243. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9244. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9245. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9246. #endif
  9247. #endif
  9248. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9249. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9250. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9251. #endif
  9252. #endif
  9253. #endif /* HASH_SIZE 256 */
  9254. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9255. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9256. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9257. #endif
  9258. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9259. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9260. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9261. #endif
  9262. #endif
  9263. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9264. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9265. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9266. #endif
  9267. #endif
  9268. #endif /* HASH_SIZE 192 */
  9269. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9270. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9271. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9272. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9273. #endif
  9274. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9275. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9276. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9277. #endif
  9278. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9279. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9280. #endif
  9281. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9282. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9283. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9284. #endif
  9285. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9286. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9287. #endif
  9288. #endif /* HASH_SIZE 256 */
  9289. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9290. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9291. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9292. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9293. #endif
  9294. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9295. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9296. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9297. #endif
  9298. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9299. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9300. #endif
  9301. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9302. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9303. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9304. #endif
  9305. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9306. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9307. #endif
  9308. #endif /* HASH_SIZE 192 */
  9309. }
  9310. #endif
  9311. #ifdef WC_XMSS_SHA512
  9312. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9313. if (hash == WC_HASH_TYPE_SHA512) {
  9314. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9315. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9316. #endif
  9317. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9318. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9319. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9320. #endif
  9321. #endif
  9322. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9323. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9324. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9325. #endif
  9326. #endif
  9327. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9328. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9329. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9330. #endif
  9331. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9332. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9333. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9334. #endif
  9335. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9336. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9337. #endif
  9338. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9339. #endif
  9340. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9341. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9342. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9343. #endif
  9344. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9345. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9346. #endif
  9347. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9348. #endif
  9349. }
  9350. #endif /* HASH_SIZE 512 */
  9351. #endif
  9352. #ifdef WC_XMSS_SHAKE128
  9353. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9354. if (hash == WC_HASH_TYPE_SHAKE128) {
  9355. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9356. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9357. #endif
  9358. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9359. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9360. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9361. #endif
  9362. #endif
  9363. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9364. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9365. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9366. #endif
  9367. #endif
  9368. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9369. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9370. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9371. #endif
  9372. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9373. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9374. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9375. #endif
  9376. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9377. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9378. #endif
  9379. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9380. #endif
  9381. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9382. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9383. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9384. #endif
  9385. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9386. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9387. #endif
  9388. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9389. #endif
  9390. }
  9391. #endif /* HASH_SIZE 256 */
  9392. #endif
  9393. #ifdef WC_XMSS_SHAKE256
  9394. if (hash == WC_HASH_TYPE_SHAKE256) {
  9395. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9396. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9397. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9398. #endif
  9399. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9400. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9401. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9402. #endif
  9403. #endif
  9404. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9405. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9406. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9407. #endif
  9408. #endif
  9409. #endif /* HASH_SIZE 512 */
  9410. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9411. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9412. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9413. #endif
  9414. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9415. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9416. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9417. #endif
  9418. #endif
  9419. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9420. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9421. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9422. #endif
  9423. #endif
  9424. #endif /* HASH_SIZE 256 */
  9425. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9426. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9427. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9428. #endif
  9429. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9430. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9431. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9432. #endif
  9433. #endif
  9434. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9435. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9436. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9437. #endif
  9438. #endif
  9439. #endif /* HASH_SIZE 192 */
  9440. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9441. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9442. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9443. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9444. #endif
  9445. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9446. #endif
  9447. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9448. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9449. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9450. #endif
  9451. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9452. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9453. #endif
  9454. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9455. #endif
  9456. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9457. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9458. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9459. #endif
  9460. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9461. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9462. #endif
  9463. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9464. #endif
  9465. #endif /* HASH_SIZE 512 */
  9466. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9467. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9468. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9469. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9470. #endif
  9471. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9472. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9473. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9474. #endif
  9475. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9476. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9477. #endif
  9478. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9479. #endif
  9480. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9481. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9482. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9483. #endif
  9484. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9485. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9486. #endif
  9487. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9488. #endif
  9489. #endif /* HASH_SIZE 256 */
  9490. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9491. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9492. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9493. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9494. #endif
  9495. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9496. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9497. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9498. #endif
  9499. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9500. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9501. #endif
  9502. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9503. #endif
  9504. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9505. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9506. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9507. #endif
  9508. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9509. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9510. #endif
  9511. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9512. #endif
  9513. #endif /* HASH_SIZE 192 */
  9514. }
  9515. #endif
  9516. return;
  9517. }
  9518. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9519. #ifdef HAVE_ECC
  9520. /* Maximum ECC name plus null terminator:
  9521. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9522. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9523. /* run all benchmarks on a curve */
  9524. void bench_ecc_curve(int curveId)
  9525. {
  9526. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9527. #ifndef NO_SW_BENCH
  9528. bench_eccMakeKey(0, curveId);
  9529. #endif
  9530. #if defined(BENCH_DEVID)
  9531. bench_eccMakeKey(1, curveId);
  9532. #endif
  9533. }
  9534. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9535. #ifndef NO_SW_BENCH
  9536. bench_ecc(0, curveId);
  9537. #endif
  9538. #if defined(BENCH_DEVID)
  9539. bench_ecc(1, curveId);
  9540. #endif
  9541. }
  9542. #ifdef HAVE_ECC_ENCRYPT
  9543. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9544. bench_eccEncrypt(curveId);
  9545. #endif
  9546. }
  9547. void bench_eccMakeKey(int useDeviceID, int curveId)
  9548. {
  9549. int ret = 0, i, times, count = 0, pending = 0;
  9550. int deviceID;
  9551. int keySize = 0;
  9552. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9553. sizeof(ecc_key), HEAP_HINT);
  9554. char name[BENCH_ECC_NAME_SZ];
  9555. double start = 0;
  9556. const char**desc = bench_desc_words[lng_index];
  9557. DECLARE_MULTI_VALUE_STATS_VARS()
  9558. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9559. sizeof(ecc_key), HEAP_HINT);
  9560. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9561. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9562. /* ECC Make Key */
  9563. bench_stats_start(&count, &start);
  9564. do {
  9565. /* while free pending slots in queue, submit ops */
  9566. for (times = 0; times < agreeTimes || pending > 0; ) {
  9567. bench_async_poll(&pending);
  9568. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9569. if (bench_async_check(&ret,
  9570. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9571. &times, agreeTimes, &pending)) {
  9572. wc_ecc_free(genKey[i]);
  9573. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9574. if (ret < 0) {
  9575. goto exit;
  9576. }
  9577. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9578. curveId);
  9579. if (!bench_async_handle(&ret,
  9580. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9581. &pending)) {
  9582. goto exit;
  9583. }
  9584. }
  9585. } /* for i */
  9586. RECORD_MULTI_VALUE_STATS();
  9587. } /* for times */
  9588. count += times;
  9589. } while (bench_stats_check(start)
  9590. #ifdef MULTI_VALUE_STATISTICS
  9591. || runs < minimum_runs
  9592. #endif
  9593. );
  9594. exit:
  9595. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9596. wc_ecc_get_name(curveId));
  9597. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9598. useDeviceID, count, start, ret);
  9599. #ifdef MULTI_VALUE_STATISTICS
  9600. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9601. #endif
  9602. /* cleanup */
  9603. if (WC_ARRAY_OK(genKey)) {
  9604. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9605. wc_ecc_free(genKey[i]);
  9606. }
  9607. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9608. }
  9609. }
  9610. void bench_ecc(int useDeviceID, int curveId)
  9611. {
  9612. int ret = 0, i, times, count, pending = 0;
  9613. int deviceID;
  9614. int keySize;
  9615. char name[BENCH_ECC_NAME_SZ];
  9616. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9617. sizeof(ecc_key), HEAP_HINT);
  9618. #ifdef HAVE_ECC_DHE
  9619. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9620. sizeof(ecc_key), HEAP_HINT);
  9621. #endif
  9622. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9623. #ifdef HAVE_ECC_VERIFY
  9624. int verify[BENCH_MAX_PENDING];
  9625. #endif
  9626. #endif
  9627. word32 x[BENCH_MAX_PENDING];
  9628. double start = 0;
  9629. const char**desc = bench_desc_words[lng_index];
  9630. DECLARE_MULTI_VALUE_STATS_VARS()
  9631. #ifdef HAVE_ECC_DHE
  9632. WC_DECLARE_ARRAY(shared, byte,
  9633. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9634. #endif
  9635. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9636. WC_DECLARE_ARRAY(sig, byte,
  9637. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9638. WC_DECLARE_ARRAY(digest, byte,
  9639. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9640. #endif
  9641. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9642. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9643. XMEMSET(sig, 0, sizeof(sig));
  9644. XMEMSET(digest, 0, sizeof(digest));
  9645. #endif
  9646. #ifdef HAVE_ECC_DHE
  9647. XMEMSET(shared, 0, sizeof(shared));
  9648. #endif
  9649. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9650. sizeof(ecc_key), HEAP_HINT);
  9651. #ifdef HAVE_ECC_DHE
  9652. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9653. sizeof(ecc_key), HEAP_HINT);
  9654. WC_ALLOC_ARRAY(shared, byte,
  9655. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9656. #endif
  9657. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9658. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9659. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9660. #endif
  9661. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9662. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9663. /* init keys */
  9664. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9665. /* setup an context for each key */
  9666. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9667. goto exit;
  9668. }
  9669. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9670. #ifdef WOLFSSL_ASYNC_CRYPT
  9671. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9672. #endif
  9673. if (ret < 0) {
  9674. goto exit;
  9675. }
  9676. #ifdef HAVE_ECC_DHE
  9677. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9678. goto exit;
  9679. }
  9680. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9681. curveId)) > 0) {
  9682. goto exit;
  9683. }
  9684. #endif
  9685. }
  9686. #ifdef HAVE_ECC_DHE
  9687. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9688. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9689. !defined(HAVE_SELFTEST)
  9690. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9691. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9692. }
  9693. #endif
  9694. /* ECC Shared Secret */
  9695. bench_stats_start(&count, &start);
  9696. PRIVATE_KEY_UNLOCK();
  9697. do {
  9698. for (times = 0; times < agreeTimes || pending > 0; ) {
  9699. bench_async_poll(&pending);
  9700. /* while free pending slots in queue, submit ops */
  9701. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9702. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9703. &times, agreeTimes, &pending)) {
  9704. x[i] = (word32)keySize;
  9705. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9706. shared[i], &x[i]);
  9707. if (!bench_async_handle(&ret,
  9708. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9709. &pending)) {
  9710. goto exit_ecdhe;
  9711. }
  9712. }
  9713. } /* for i */
  9714. RECORD_MULTI_VALUE_STATS();
  9715. } /* for times */
  9716. count += times;
  9717. } while (bench_stats_check(start)
  9718. #ifdef MULTI_VALUE_STATISTICS
  9719. || runs < minimum_runs
  9720. #endif
  9721. );
  9722. PRIVATE_KEY_UNLOCK();
  9723. exit_ecdhe:
  9724. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9725. wc_ecc_get_name(curveId));
  9726. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9727. useDeviceID, count, start, ret);
  9728. #ifdef MULTI_VALUE_STATISTICS
  9729. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9730. #endif
  9731. RESET_MULTI_VALUE_STATS_VARS();
  9732. if (ret < 0) {
  9733. goto exit;
  9734. }
  9735. #endif /* HAVE_ECC_DHE */
  9736. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9737. /* Init digest to sign */
  9738. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9739. for (count = 0; count < keySize; count++) {
  9740. digest[i][count] = (byte)count;
  9741. }
  9742. }
  9743. /* ECC Sign */
  9744. bench_stats_start(&count, &start);
  9745. do {
  9746. for (times = 0; times < agreeTimes || pending > 0; ) {
  9747. bench_async_poll(&pending);
  9748. /* while free pending slots in queue, submit ops */
  9749. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9750. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9751. &times, agreeTimes, &pending)) {
  9752. if (genKey[i]->state == 0) {
  9753. x[i] = ECC_MAX_SIG_SIZE;
  9754. }
  9755. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9756. &x[i], GLOBAL_RNG, genKey[i]);
  9757. if (!bench_async_handle(&ret,
  9758. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9759. &pending)) {
  9760. goto exit_ecdsa_sign;
  9761. }
  9762. } /* bench_async_check */
  9763. } /* for i */
  9764. RECORD_MULTI_VALUE_STATS();
  9765. } /* for times */
  9766. count += times;
  9767. } while (bench_stats_check(start)
  9768. #ifdef MULTI_VALUE_STATISTICS
  9769. || runs < minimum_runs
  9770. #endif
  9771. );
  9772. exit_ecdsa_sign:
  9773. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9774. wc_ecc_get_name(curveId));
  9775. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9776. useDeviceID, count, start, ret);
  9777. #ifdef MULTI_VALUE_STATISTICS
  9778. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9779. #endif
  9780. RESET_MULTI_VALUE_STATS_VARS();
  9781. if (ret < 0) {
  9782. goto exit;
  9783. }
  9784. #ifdef HAVE_ECC_VERIFY
  9785. /* ECC Verify */
  9786. bench_stats_start(&count, &start);
  9787. do {
  9788. for (times = 0; times < agreeTimes || pending > 0; ) {
  9789. bench_async_poll(&pending);
  9790. /* while free pending slots in queue, submit ops */
  9791. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9792. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9793. &times, agreeTimes, &pending)) {
  9794. if (genKey[i]->state == 0) {
  9795. verify[i] = 0;
  9796. }
  9797. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9798. (word32)keySize, &verify[i],
  9799. genKey[i]);
  9800. if (!bench_async_handle(&ret,
  9801. BENCH_ASYNC_GET_DEV(genKey[i]),
  9802. 1, &times,
  9803. &pending)) {
  9804. goto exit_ecdsa_verify;
  9805. }
  9806. } /* if bench_async_check */
  9807. } /* for i */
  9808. RECORD_MULTI_VALUE_STATS();
  9809. } /* for times */
  9810. count += times;
  9811. } while (bench_stats_check(start)
  9812. #ifdef MULTI_VALUE_STATISTICS
  9813. || runs < minimum_runs
  9814. #endif
  9815. );
  9816. exit_ecdsa_verify:
  9817. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9818. wc_ecc_get_name(curveId));
  9819. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9820. useDeviceID, count, start, ret);
  9821. #ifdef MULTI_VALUE_STATISTICS
  9822. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9823. #endif
  9824. #endif /* HAVE_ECC_VERIFY */
  9825. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9826. exit:
  9827. /* cleanup */
  9828. if (WC_ARRAY_OK(genKey)) {
  9829. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9830. wc_ecc_free(genKey[i]);
  9831. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9832. }
  9833. #ifdef HAVE_ECC_DHE
  9834. if (WC_ARRAY_OK(genKey2)) {
  9835. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9836. wc_ecc_free(genKey2[i]);
  9837. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  9838. }
  9839. #endif
  9840. #ifdef HAVE_ECC_DHE
  9841. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  9842. #endif
  9843. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9844. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  9845. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  9846. #endif
  9847. (void)useDeviceID;
  9848. (void)pending;
  9849. (void)x;
  9850. (void)count;
  9851. (void)times;
  9852. (void)desc;
  9853. (void)start;
  9854. (void)name;
  9855. }
  9856. #ifdef HAVE_ECC_ENCRYPT
  9857. void bench_eccEncrypt(int curveId)
  9858. {
  9859. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  9860. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  9861. WC_SHA256_DIGEST_SIZE + \
  9862. (MAX_ECC_BITS+3)/4 + 2)
  9863. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  9864. #ifdef WOLFSSL_SMALL_STACK
  9865. ecc_key *userA = NULL, *userB = NULL;
  9866. byte *msg = NULL;
  9867. byte *out = NULL;
  9868. #else
  9869. ecc_key userA[1], userB[1];
  9870. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  9871. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  9872. #endif
  9873. char name[BENCH_ECC_NAME_SZ];
  9874. int keySize;
  9875. word32 bench_plainSz = bench_size;
  9876. int ret, i, count;
  9877. double start;
  9878. const char**desc = bench_desc_words[lng_index];
  9879. DECLARE_MULTI_VALUE_STATS_VARS()
  9880. #ifdef WOLFSSL_SMALL_STACK
  9881. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  9882. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9883. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  9884. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9885. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  9886. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9887. out = (byte *)XMALLOC(outSz,
  9888. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9889. if ((! userA) || (! userB) || (! msg) || (! out)) {
  9890. printf("bench_eccEncrypt malloc failed\n");
  9891. goto exit;
  9892. }
  9893. #endif
  9894. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9895. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  9896. if (ret != 0) {
  9897. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  9898. goto exit;
  9899. }
  9900. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  9901. if (ret != 0) {
  9902. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  9903. goto exit;
  9904. }
  9905. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9906. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9907. !defined(HAVE_SELFTEST)
  9908. ret = wc_ecc_set_rng(userA, &gRng);
  9909. if (ret != 0) {
  9910. goto exit;
  9911. }
  9912. ret = wc_ecc_set_rng(userB, &gRng);
  9913. if (ret != 0) {
  9914. goto exit;
  9915. }
  9916. #endif
  9917. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  9918. #ifdef WOLFSSL_ASYNC_CRYPT
  9919. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  9920. #endif
  9921. if (ret != 0)
  9922. goto exit;
  9923. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  9924. #ifdef WOLFSSL_ASYNC_CRYPT
  9925. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  9926. #endif
  9927. if (ret != 0)
  9928. goto exit;
  9929. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  9930. msg[i] = (byte)i;
  9931. }
  9932. bench_stats_start(&count, &start);
  9933. do {
  9934. for (i = 0; i < ntimes; i++) {
  9935. /* encrypt msg to B */
  9936. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  9937. out, &outSz, NULL);
  9938. if (ret != 0) {
  9939. printf("wc_ecc_encrypt failed! %d\n", ret);
  9940. goto exit_enc;
  9941. }
  9942. RECORD_MULTI_VALUE_STATS();
  9943. }
  9944. count += i;
  9945. } while (bench_stats_check(start)
  9946. #ifdef MULTI_VALUE_STATISTICS
  9947. || runs < minimum_runs
  9948. #endif
  9949. );
  9950. exit_enc:
  9951. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9952. wc_ecc_get_name(curveId));
  9953. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  9954. #ifdef MULTI_VALUE_STATISTICS
  9955. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9956. #endif
  9957. RESET_MULTI_VALUE_STATS_VARS();
  9958. if (ret != 0)
  9959. goto exit;
  9960. bench_stats_start(&count, &start);
  9961. do {
  9962. for (i = 0; i < ntimes; i++) {
  9963. /* decrypt msg from A */
  9964. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  9965. &bench_plainSz, NULL);
  9966. if (ret != 0) {
  9967. printf("wc_ecc_decrypt failed! %d\n", ret);
  9968. goto exit_dec;
  9969. }
  9970. RECORD_MULTI_VALUE_STATS();
  9971. }
  9972. count += i;
  9973. } while (bench_stats_check(start)
  9974. #ifdef MULTI_VALUE_STATISTICS
  9975. || runs < minimum_runs
  9976. #endif
  9977. );
  9978. exit_dec:
  9979. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  9980. #ifdef MULTI_VALUE_STATISTICS
  9981. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9982. #endif
  9983. exit:
  9984. /* cleanup */
  9985. #ifdef WOLFSSL_SMALL_STACK
  9986. if (userA) {
  9987. wc_ecc_free(userA);
  9988. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9989. }
  9990. if (userB) {
  9991. wc_ecc_free(userB);
  9992. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9993. }
  9994. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9995. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9996. #else
  9997. wc_ecc_free(userB);
  9998. wc_ecc_free(userA);
  9999. #endif
  10000. }
  10001. #endif
  10002. #ifdef WOLFSSL_SM2
  10003. static void bench_sm2_MakeKey(int useDeviceID)
  10004. {
  10005. int ret = 0, i, times, count = 0, pending = 0;
  10006. int deviceID;
  10007. int keySize;
  10008. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10009. sizeof(ecc_key), HEAP_HINT);
  10010. char name[BENCH_ECC_NAME_SZ];
  10011. double start = 0;
  10012. const char**desc = bench_desc_words[lng_index];
  10013. DECLARE_MULTI_VALUE_STATS_VARS()
  10014. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10015. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10016. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10017. sizeof(ecc_key), HEAP_HINT);
  10018. /* ECC Make Key */
  10019. bench_stats_start(&count, &start);
  10020. do {
  10021. /* while free pending slots in queue, submit ops */
  10022. for (times = 0; times < agreeTimes || pending > 0; ) {
  10023. bench_async_poll(&pending);
  10024. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10025. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10026. &times, agreeTimes, &pending)) {
  10027. wc_ecc_free(genKey[i]);
  10028. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10029. if (ret < 0) {
  10030. goto exit;
  10031. }
  10032. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10033. WC_ECC_FLAG_NONE);
  10034. if (!bench_async_handle(&ret,
  10035. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10036. &pending)) {
  10037. goto exit;
  10038. }
  10039. }
  10040. } /* for i */
  10041. RECORD_MULTI_VALUE_STATS();
  10042. } /* for times */
  10043. count += times;
  10044. } while (bench_stats_check(start)
  10045. #ifdef MULTI_VALUE_STATISTICS
  10046. || runs < minimum_runs
  10047. #endif
  10048. );
  10049. exit:
  10050. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10051. wc_ecc_get_name(ECC_SM2P256V1));
  10052. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10053. start, ret);
  10054. #ifdef MULTI_VALUE_STATISTICS
  10055. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10056. #endif
  10057. /* cleanup */
  10058. if (WC_ARRAY_OK(genKey)) {
  10059. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10060. wc_ecc_free(genKey[i]);
  10061. }
  10062. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10063. }
  10064. }
  10065. void bench_sm2(int useDeviceID)
  10066. {
  10067. int ret = 0, i, times, count, pending = 0;
  10068. int deviceID;
  10069. int keySize;
  10070. char name[BENCH_ECC_NAME_SZ];
  10071. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10072. sizeof(ecc_key), HEAP_HINT);
  10073. #ifdef HAVE_ECC_DHE
  10074. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10075. sizeof(ecc_key), HEAP_HINT);
  10076. #endif
  10077. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10078. #ifdef HAVE_ECC_VERIFY
  10079. int verify[BENCH_MAX_PENDING];
  10080. #endif
  10081. #endif
  10082. word32 x[BENCH_MAX_PENDING];
  10083. double start = 0;
  10084. const char**desc = bench_desc_words[lng_index];
  10085. DECLARE_MULTI_VALUE_STATS_VARS()
  10086. #ifdef HAVE_ECC_DHE
  10087. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10088. #endif
  10089. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10090. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10091. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10092. #endif
  10093. #ifdef HAVE_ECC_DHE
  10094. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10095. #endif
  10096. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10097. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10098. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10099. #endif
  10100. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10101. bench_sm2_MakeKey(useDeviceID);
  10102. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10103. sizeof(ecc_key), HEAP_HINT);
  10104. #ifdef HAVE_ECC_DHE
  10105. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10106. sizeof(ecc_key), HEAP_HINT);
  10107. #endif
  10108. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10109. /* init keys */
  10110. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10111. /* setup an context for each key */
  10112. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10113. goto exit;
  10114. }
  10115. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10116. #ifdef WOLFSSL_ASYNC_CRYPT
  10117. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10118. #endif
  10119. if (ret < 0) {
  10120. goto exit;
  10121. }
  10122. #ifdef HAVE_ECC_DHE
  10123. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10124. goto exit;
  10125. }
  10126. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10127. WC_ECC_FLAG_NONE)) > 0) {
  10128. goto exit;
  10129. }
  10130. #endif
  10131. }
  10132. #ifdef HAVE_ECC_DHE
  10133. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10134. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10135. !defined(HAVE_SELFTEST)
  10136. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10137. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10138. }
  10139. #endif
  10140. /* ECC Shared Secret */
  10141. bench_stats_start(&count, &start);
  10142. PRIVATE_KEY_UNLOCK();
  10143. do {
  10144. for (times = 0; times < agreeTimes || pending > 0; ) {
  10145. bench_async_poll(&pending);
  10146. /* while free pending slots in queue, submit ops */
  10147. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10148. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10149. &times, agreeTimes, &pending)) {
  10150. x[i] = (word32)keySize;
  10151. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10152. shared[i], &x[i]);
  10153. if (!bench_async_handle(&ret,
  10154. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10155. &pending)) {
  10156. goto exit_ecdhe;
  10157. }
  10158. }
  10159. } /* for i */
  10160. RECORD_MULTI_VALUE_STATS();
  10161. } /* for times */
  10162. count += times;
  10163. } while (bench_stats_check(start)
  10164. #ifdef MULTI_VALUE_STATISTICS
  10165. || runs < minimum_runs
  10166. #endif
  10167. );
  10168. PRIVATE_KEY_UNLOCK();
  10169. exit_ecdhe:
  10170. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10171. wc_ecc_get_name(ECC_SM2P256V1));
  10172. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10173. start, ret);
  10174. #ifdef MULTI_VALUE_STATISTICS
  10175. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10176. #endif
  10177. if (ret < 0) {
  10178. goto exit;
  10179. }
  10180. #endif /* HAVE_ECC_DHE */
  10181. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10182. /* Init digest to sign */
  10183. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10184. for (count = 0; count < keySize; count++) {
  10185. digest[i][count] = (byte)count;
  10186. }
  10187. }
  10188. RESET_MULTI_VALUE_STATS_VARS();
  10189. /* ECC Sign */
  10190. bench_stats_start(&count, &start);
  10191. do {
  10192. for (times = 0; times < agreeTimes || pending > 0; ) {
  10193. bench_async_poll(&pending);
  10194. /* while free pending slots in queue, submit ops */
  10195. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10196. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10197. &times, agreeTimes, &pending)) {
  10198. if (genKey[i]->state == 0)
  10199. x[i] = ECC_MAX_SIG_SIZE;
  10200. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10201. sig[i], &x[i], &gRng, genKey[i]);
  10202. if (!bench_async_handle(&ret,
  10203. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10204. &pending)) {
  10205. goto exit_ecdsa_sign;
  10206. }
  10207. }
  10208. } /* for i */
  10209. RECORD_MULTI_VALUE_STATS();
  10210. } /* for times */
  10211. count += times;
  10212. } while (bench_stats_check(start)
  10213. #ifdef MULTI_VALUE_STATISTICS
  10214. || runs < minimum_runs
  10215. #endif
  10216. );
  10217. exit_ecdsa_sign:
  10218. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10219. wc_ecc_get_name(ECC_SM2P256V1));
  10220. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10221. start, ret);
  10222. #ifdef MULTI_VALUE_STATISTICS
  10223. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10224. #endif
  10225. if (ret < 0) {
  10226. goto exit;
  10227. }
  10228. #ifdef HAVE_ECC_VERIFY
  10229. /* ECC Verify */
  10230. bench_stats_start(&count, &start);
  10231. do {
  10232. for (times = 0; times < agreeTimes || pending > 0; ) {
  10233. bench_async_poll(&pending);
  10234. /* while free pending slots in queue, submit ops */
  10235. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10236. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10237. &times, agreeTimes, &pending)) {
  10238. if (genKey[i]->state == 0)
  10239. verify[i] = 0;
  10240. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10241. (word32)keySize, &verify[i], genKey[i]);
  10242. if (!bench_async_handle(&ret,
  10243. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10244. &pending)) {
  10245. goto exit_ecdsa_verify;
  10246. }
  10247. }
  10248. } /* for i */
  10249. RECORD_MULTI_VALUE_STATS();
  10250. } /* for times */
  10251. count += times;
  10252. } while (bench_stats_check(start)
  10253. #ifdef MULTI_VALUE_STATISTICS
  10254. || runs < minimum_runs
  10255. #endif
  10256. );
  10257. exit_ecdsa_verify:
  10258. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10259. wc_ecc_get_name(ECC_SM2P256V1));
  10260. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10261. start, ret);
  10262. #ifdef MULTI_VALUE_STATISTICS
  10263. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10264. #endif
  10265. #endif /* HAVE_ECC_VERIFY */
  10266. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10267. exit:
  10268. /* cleanup */
  10269. if (WC_ARRAY_OK(genKey)) {
  10270. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10271. wc_ecc_free(genKey[i]);
  10272. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10273. }
  10274. #ifdef HAVE_ECC_DHE
  10275. if (WC_ARRAY_OK(genKey2)) {
  10276. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10277. wc_ecc_free(genKey2[i]);
  10278. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10279. }
  10280. #endif
  10281. #ifdef HAVE_ECC_DHE
  10282. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10283. #endif
  10284. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10285. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10286. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10287. #endif
  10288. (void)useDeviceID;
  10289. (void)pending;
  10290. (void)x;
  10291. (void)count;
  10292. (void)times;
  10293. (void)desc;
  10294. (void)start;
  10295. (void)name;
  10296. }
  10297. #endif /* WOLFSSL_SM2 */
  10298. #endif /* HAVE_ECC */
  10299. #ifdef HAVE_CURVE25519
  10300. void bench_curve25519KeyGen(int useDeviceID)
  10301. {
  10302. curve25519_key genKey;
  10303. double start;
  10304. int ret = 0, i, count;
  10305. const char**desc = bench_desc_words[lng_index];
  10306. DECLARE_MULTI_VALUE_STATS_VARS()
  10307. /* Key Gen */
  10308. bench_stats_start(&count, &start);
  10309. do {
  10310. for (i = 0; i < genTimes; i++) {
  10311. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10312. useDeviceID ? devId : INVALID_DEVID);
  10313. if (ret != 0) {
  10314. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10315. break;
  10316. }
  10317. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10318. wc_curve25519_free(&genKey);
  10319. if (ret != 0) {
  10320. printf("wc_curve25519_make_key failed: %d\n", ret);
  10321. break;
  10322. }
  10323. RECORD_MULTI_VALUE_STATS();
  10324. }
  10325. count += i;
  10326. } while (bench_stats_check(start)
  10327. #ifdef MULTI_VALUE_STATISTICS
  10328. || runs < minimum_runs
  10329. #endif
  10330. );
  10331. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10332. ret);
  10333. #ifdef MULTI_VALUE_STATISTICS
  10334. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10335. #endif
  10336. }
  10337. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10338. void bench_curve25519KeyAgree(int useDeviceID)
  10339. {
  10340. curve25519_key genKey, genKey2;
  10341. double start;
  10342. int ret, i, count;
  10343. byte shared[32];
  10344. const char**desc = bench_desc_words[lng_index];
  10345. word32 x = 0;
  10346. DECLARE_MULTI_VALUE_STATS_VARS()
  10347. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10348. useDeviceID ? devId : INVALID_DEVID);
  10349. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10350. useDeviceID ? devId : INVALID_DEVID);
  10351. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10352. if (ret != 0) {
  10353. printf("curve25519_make_key failed\n");
  10354. return;
  10355. }
  10356. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10357. if (ret != 0) {
  10358. printf("curve25519_make_key failed: %d\n", ret);
  10359. wc_curve25519_free(&genKey);
  10360. return;
  10361. }
  10362. /* Shared secret */
  10363. bench_stats_start(&count, &start);
  10364. do {
  10365. for (i = 0; i < agreeTimes; i++) {
  10366. x = sizeof(shared);
  10367. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10368. if (ret != 0) {
  10369. printf("curve25519_shared_secret failed: %d\n", ret);
  10370. goto exit;
  10371. }
  10372. RECORD_MULTI_VALUE_STATS();
  10373. }
  10374. count += i;
  10375. } while (bench_stats_check(start)
  10376. #ifdef MULTI_VALUE_STATISTICS
  10377. || runs < minimum_runs
  10378. #endif
  10379. );
  10380. exit:
  10381. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10382. ret);
  10383. #ifdef MULTI_VALUE_STATISTICS
  10384. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10385. #endif
  10386. wc_curve25519_free(&genKey2);
  10387. wc_curve25519_free(&genKey);
  10388. }
  10389. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10390. #endif /* HAVE_CURVE25519 */
  10391. #ifdef HAVE_ED25519
  10392. void bench_ed25519KeyGen(void)
  10393. {
  10394. #ifdef HAVE_ED25519_MAKE_KEY
  10395. ed25519_key genKey;
  10396. double start;
  10397. int i, count;
  10398. const char**desc = bench_desc_words[lng_index];
  10399. DECLARE_MULTI_VALUE_STATS_VARS()
  10400. /* Key Gen */
  10401. bench_stats_start(&count, &start);
  10402. do {
  10403. for (i = 0; i < genTimes; i++) {
  10404. wc_ed25519_init(&genKey);
  10405. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10406. wc_ed25519_free(&genKey);
  10407. RECORD_MULTI_VALUE_STATS();
  10408. }
  10409. count += i;
  10410. } while (bench_stats_check(start)
  10411. #ifdef MULTI_VALUE_STATISTICS
  10412. || runs < minimum_runs
  10413. #endif
  10414. );
  10415. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10416. #ifdef MULTI_VALUE_STATISTICS
  10417. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10418. #endif
  10419. #endif /* HAVE_ED25519_MAKE_KEY */
  10420. }
  10421. void bench_ed25519KeySign(void)
  10422. {
  10423. #ifdef HAVE_ED25519_MAKE_KEY
  10424. int ret;
  10425. #endif
  10426. ed25519_key genKey;
  10427. #ifdef HAVE_ED25519_SIGN
  10428. double start;
  10429. int i, count;
  10430. byte sig[ED25519_SIG_SIZE];
  10431. byte msg[512];
  10432. word32 x = 0;
  10433. const char**desc = bench_desc_words[lng_index];
  10434. DECLARE_MULTI_VALUE_STATS_VARS()
  10435. #endif
  10436. wc_ed25519_init(&genKey);
  10437. #ifdef HAVE_ED25519_MAKE_KEY
  10438. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10439. if (ret != 0) {
  10440. printf("ed25519_make_key failed\n");
  10441. return;
  10442. }
  10443. #endif
  10444. #ifdef HAVE_ED25519_SIGN
  10445. /* make dummy msg */
  10446. for (i = 0; i < (int)sizeof(msg); i++)
  10447. msg[i] = (byte)i;
  10448. bench_stats_start(&count, &start);
  10449. do {
  10450. for (i = 0; i < agreeTimes; i++) {
  10451. x = sizeof(sig);
  10452. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10453. if (ret != 0) {
  10454. printf("ed25519_sign_msg failed\n");
  10455. goto exit_ed_sign;
  10456. }
  10457. RECORD_MULTI_VALUE_STATS();
  10458. }
  10459. count += i;
  10460. } while (bench_stats_check(start)
  10461. #ifdef MULTI_VALUE_STATISTICS
  10462. || runs < minimum_runs
  10463. #endif
  10464. );
  10465. exit_ed_sign:
  10466. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10467. #ifdef MULTI_VALUE_STATISTICS
  10468. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10469. #endif
  10470. RESET_MULTI_VALUE_STATS_VARS();
  10471. #ifdef HAVE_ED25519_VERIFY
  10472. bench_stats_start(&count, &start);
  10473. do {
  10474. for (i = 0; i < agreeTimes; i++) {
  10475. int verify = 0;
  10476. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10477. &genKey);
  10478. if (ret != 0 || verify != 1) {
  10479. printf("ed25519_verify_msg failed\n");
  10480. goto exit_ed_verify;
  10481. }
  10482. RECORD_MULTI_VALUE_STATS();
  10483. }
  10484. count += i;
  10485. } while (bench_stats_check(start)
  10486. #ifdef MULTI_VALUE_STATISTICS
  10487. || runs < minimum_runs
  10488. #endif
  10489. );
  10490. exit_ed_verify:
  10491. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10492. #ifdef MULTI_VALUE_STATISTICS
  10493. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10494. #endif
  10495. #endif /* HAVE_ED25519_VERIFY */
  10496. #endif /* HAVE_ED25519_SIGN */
  10497. wc_ed25519_free(&genKey);
  10498. }
  10499. #endif /* HAVE_ED25519 */
  10500. #ifdef HAVE_CURVE448
  10501. void bench_curve448KeyGen(void)
  10502. {
  10503. curve448_key genKey;
  10504. double start;
  10505. int ret = 0, i, count;
  10506. const char**desc = bench_desc_words[lng_index];
  10507. DECLARE_MULTI_VALUE_STATS_VARS()
  10508. /* Key Gen */
  10509. bench_stats_start(&count, &start);
  10510. do {
  10511. for (i = 0; i < genTimes; i++) {
  10512. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10513. wc_curve448_free(&genKey);
  10514. if (ret != 0) {
  10515. printf("wc_curve448_make_key failed: %d\n", ret);
  10516. break;
  10517. }
  10518. RECORD_MULTI_VALUE_STATS();
  10519. }
  10520. count += i;
  10521. } while (bench_stats_check(start)
  10522. #ifdef MULTI_VALUE_STATISTICS
  10523. || runs < minimum_runs
  10524. #endif
  10525. );
  10526. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10527. #ifdef MULTI_VALUE_STATISTICS
  10528. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10529. #endif
  10530. }
  10531. #ifdef HAVE_CURVE448_SHARED_SECRET
  10532. void bench_curve448KeyAgree(void)
  10533. {
  10534. curve448_key genKey, genKey2;
  10535. double start;
  10536. int ret, i, count;
  10537. byte shared[56];
  10538. const char**desc = bench_desc_words[lng_index];
  10539. word32 x = 0;
  10540. DECLARE_MULTI_VALUE_STATS_VARS()
  10541. wc_curve448_init(&genKey);
  10542. wc_curve448_init(&genKey2);
  10543. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10544. if (ret != 0) {
  10545. printf("curve448_make_key failed\n");
  10546. return;
  10547. }
  10548. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10549. if (ret != 0) {
  10550. printf("curve448_make_key failed: %d\n", ret);
  10551. wc_curve448_free(&genKey);
  10552. return;
  10553. }
  10554. /* Shared secret */
  10555. bench_stats_start(&count, &start);
  10556. do {
  10557. for (i = 0; i < agreeTimes; i++) {
  10558. x = sizeof(shared);
  10559. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10560. if (ret != 0) {
  10561. printf("curve448_shared_secret failed: %d\n", ret);
  10562. goto exit;
  10563. }
  10564. RECORD_MULTI_VALUE_STATS();
  10565. }
  10566. count += i;
  10567. } while (bench_stats_check(start)
  10568. #ifdef MULTI_VALUE_STATISTICS
  10569. || runs < minimum_runs
  10570. #endif
  10571. );
  10572. exit:
  10573. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10574. #ifdef MULTI_VALUE_STATISTICS
  10575. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10576. #endif
  10577. wc_curve448_free(&genKey2);
  10578. wc_curve448_free(&genKey);
  10579. }
  10580. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10581. #endif /* HAVE_CURVE448 */
  10582. #ifdef HAVE_ED448
  10583. void bench_ed448KeyGen(void)
  10584. {
  10585. ed448_key genKey;
  10586. double start;
  10587. int i, count;
  10588. const char**desc = bench_desc_words[lng_index];
  10589. DECLARE_MULTI_VALUE_STATS_VARS()
  10590. /* Key Gen */
  10591. bench_stats_start(&count, &start);
  10592. do {
  10593. for (i = 0; i < genTimes; i++) {
  10594. wc_ed448_init(&genKey);
  10595. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10596. wc_ed448_free(&genKey);
  10597. RECORD_MULTI_VALUE_STATS();
  10598. }
  10599. count += i;
  10600. } while (bench_stats_check(start)
  10601. #ifdef MULTI_VALUE_STATISTICS
  10602. || runs < minimum_runs
  10603. #endif
  10604. );
  10605. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10606. #ifdef MULTI_VALUE_STATISTICS
  10607. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10608. #endif
  10609. }
  10610. void bench_ed448KeySign(void)
  10611. {
  10612. int ret;
  10613. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10614. #ifdef HAVE_ED448_SIGN
  10615. double start;
  10616. int i, count;
  10617. byte sig[ED448_SIG_SIZE];
  10618. byte msg[512];
  10619. word32 x = 0;
  10620. const char**desc = bench_desc_words[lng_index];
  10621. DECLARE_MULTI_VALUE_STATS_VARS()
  10622. #endif
  10623. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10624. wc_ed448_init(genKey);
  10625. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10626. if (ret != 0) {
  10627. printf("ed448_make_key failed\n");
  10628. goto exit;
  10629. }
  10630. #ifdef HAVE_ED448_SIGN
  10631. /* make dummy msg */
  10632. for (i = 0; i < (int)sizeof(msg); i++)
  10633. msg[i] = (byte)i;
  10634. bench_stats_start(&count, &start);
  10635. do {
  10636. for (i = 0; i < agreeTimes; i++) {
  10637. x = sizeof(sig);
  10638. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10639. NULL, 0);
  10640. if (ret != 0) {
  10641. printf("ed448_sign_msg failed\n");
  10642. goto exit;
  10643. }
  10644. RECORD_MULTI_VALUE_STATS();
  10645. }
  10646. count += i;
  10647. } while (bench_stats_check(start)
  10648. #ifdef MULTI_VALUE_STATISTICS
  10649. || runs < minimum_runs
  10650. #endif
  10651. );
  10652. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10653. #ifdef MULTI_VALUE_STATISTICS
  10654. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10655. #endif
  10656. RESET_MULTI_VALUE_STATS_VARS();
  10657. #ifdef HAVE_ED448_VERIFY
  10658. bench_stats_start(&count, &start);
  10659. do {
  10660. for (i = 0; i < agreeTimes; i++) {
  10661. int verify = 0;
  10662. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10663. genKey, NULL, 0);
  10664. if (ret != 0 || verify != 1) {
  10665. printf("ed448_verify_msg failed\n");
  10666. goto exit;
  10667. }
  10668. RECORD_MULTI_VALUE_STATS();
  10669. }
  10670. count += i;
  10671. } while (bench_stats_check(start)
  10672. #ifdef MULTI_VALUE_STATISTICS
  10673. || runs < minimum_runs
  10674. #endif
  10675. );
  10676. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10677. #ifdef MULTI_VALUE_STATISTICS
  10678. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10679. #endif
  10680. #endif /* HAVE_ED448_VERIFY */
  10681. #endif /* HAVE_ED448_SIGN */
  10682. exit:
  10683. wc_ed448_free(genKey);
  10684. WC_FREE_VAR(genKey, HEAP_HINT);
  10685. }
  10686. #endif /* HAVE_ED448 */
  10687. #ifdef WOLFCRYPT_HAVE_ECCSI
  10688. #ifdef WOLFCRYPT_ECCSI_KMS
  10689. void bench_eccsiKeyGen(void)
  10690. {
  10691. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10692. double start;
  10693. int i, count;
  10694. const char**desc = bench_desc_words[lng_index];
  10695. int ret;
  10696. DECLARE_MULTI_VALUE_STATS_VARS()
  10697. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10698. /* Key Gen */
  10699. bench_stats_start(&count, &start);
  10700. do {
  10701. for (i = 0; i < genTimes; i++) {
  10702. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10703. ret = wc_MakeEccsiKey(genKey, &gRng);
  10704. wc_FreeEccsiKey(genKey);
  10705. if (ret != 0) {
  10706. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10707. goto exit;
  10708. }
  10709. RECORD_MULTI_VALUE_STATS();
  10710. }
  10711. count += i;
  10712. } while (bench_stats_check(start)
  10713. #ifdef MULTI_VALUE_STATISTICS
  10714. || runs < minimum_runs
  10715. #endif
  10716. );
  10717. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10718. #ifdef MULTI_VALUE_STATISTICS
  10719. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10720. #endif
  10721. exit:
  10722. WC_FREE_VAR(genKey, HEAP_HINT);
  10723. }
  10724. void bench_eccsiPairGen(void)
  10725. {
  10726. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10727. double start;
  10728. int i, count;
  10729. const char**desc = bench_desc_words[lng_index];
  10730. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10731. ecc_point* pvt;
  10732. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10733. int ret;
  10734. DECLARE_MULTI_VALUE_STATS_VARS()
  10735. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10736. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10737. (void)mp_init(ssk);
  10738. pvt = wc_ecc_new_point();
  10739. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10740. (void)wc_MakeEccsiKey(genKey, &gRng);
  10741. /* RSK Gen */
  10742. bench_stats_start(&count, &start);
  10743. do {
  10744. for (i = 0; i < genTimes; i++) {
  10745. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10746. sizeof(id), ssk, pvt);
  10747. if (ret != 0) {
  10748. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10749. goto exit;
  10750. }
  10751. RECORD_MULTI_VALUE_STATS();
  10752. }
  10753. count += i;
  10754. } while (bench_stats_check(start)
  10755. #ifdef MULTI_VALUE_STATISTICS
  10756. || runs < minimum_runs
  10757. #endif
  10758. );
  10759. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10760. #ifdef MULTI_VALUE_STATISTICS
  10761. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10762. #endif
  10763. wc_FreeEccsiKey(genKey);
  10764. wc_ecc_del_point(pvt);
  10765. mp_free(ssk);
  10766. exit:
  10767. WC_FREE_VAR(genKey, HEAP_HINT);
  10768. WC_FREE_VAR(ssk, HEAP_HINT);
  10769. }
  10770. #endif
  10771. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10772. void bench_eccsiValidate(void)
  10773. {
  10774. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10775. double start;
  10776. int i, count;
  10777. const char**desc = bench_desc_words[lng_index];
  10778. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10779. ecc_point* pvt;
  10780. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10781. int valid;
  10782. int ret;
  10783. DECLARE_MULTI_VALUE_STATS_VARS()
  10784. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10785. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10786. (void)mp_init(ssk);
  10787. pvt = wc_ecc_new_point();
  10788. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10789. (void)wc_MakeEccsiKey(genKey, &gRng);
  10790. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10791. ssk, pvt);
  10792. /* Validation of RSK */
  10793. bench_stats_start(&count, &start);
  10794. do {
  10795. for (i = 0; i < genTimes; i++) {
  10796. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10797. sizeof(id), ssk, pvt, &valid);
  10798. if (ret != 0 || !valid) {
  10799. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10800. valid);
  10801. goto exit;
  10802. }
  10803. RECORD_MULTI_VALUE_STATS();
  10804. }
  10805. count += i;
  10806. } while (bench_stats_check(start)
  10807. #ifdef MULTI_VALUE_STATISTICS
  10808. || runs < minimum_runs
  10809. #endif
  10810. );
  10811. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10812. #ifdef MULTI_VALUE_STATISTICS
  10813. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10814. #endif
  10815. wc_FreeEccsiKey(genKey);
  10816. wc_ecc_del_point(pvt);
  10817. mp_free(ssk);
  10818. exit:
  10819. WC_FREE_VAR(genKey, HEAP_HINT);
  10820. WC_FREE_VAR(ssk, HEAP_HINT);
  10821. }
  10822. void bench_eccsi(void)
  10823. {
  10824. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10825. double start;
  10826. int i, count;
  10827. const char**desc = bench_desc_words[lng_index];
  10828. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10829. ecc_point* pvt;
  10830. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10831. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10832. byte hash[WC_SHA256_DIGEST_SIZE];
  10833. byte hashSz = (byte)sizeof(hash);
  10834. byte sig[257];
  10835. word32 sigSz = sizeof(sig);
  10836. int ret;
  10837. int verified;
  10838. DECLARE_MULTI_VALUE_STATS_VARS()
  10839. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10840. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10841. (void)mp_init(ssk);
  10842. pvt = wc_ecc_new_point();
  10843. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10844. (void)wc_MakeEccsiKey(genKey, &gRng);
  10845. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10846. ssk, pvt);
  10847. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  10848. hash, &hashSz);
  10849. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  10850. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  10851. /* Encapsulate */
  10852. bench_stats_start(&count, &start);
  10853. do {
  10854. for (i = 0; i < genTimes; i++) {
  10855. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  10856. sizeof(msg), sig, &sigSz);
  10857. if (ret != 0) {
  10858. printf("wc_SignEccsiHash failed: %d\n", ret);
  10859. break;
  10860. }
  10861. RECORD_MULTI_VALUE_STATS();
  10862. }
  10863. count += i;
  10864. } while (bench_stats_check(start)
  10865. #ifdef MULTI_VALUE_STATISTICS
  10866. || runs < minimum_runs
  10867. #endif
  10868. );
  10869. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  10870. #ifdef MULTI_VALUE_STATISTICS
  10871. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10872. #endif
  10873. RESET_MULTI_VALUE_STATS_VARS();
  10874. /* Derive */
  10875. bench_stats_start(&count, &start);
  10876. do {
  10877. for (i = 0; i < genTimes; i++) {
  10878. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  10879. sizeof(msg), sig, sigSz, &verified);
  10880. if (ret != 0 || !verified) {
  10881. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  10882. verified);
  10883. goto exit;
  10884. }
  10885. RECORD_MULTI_VALUE_STATS();
  10886. }
  10887. count += i;
  10888. } while (bench_stats_check(start)
  10889. #ifdef MULTI_VALUE_STATISTICS
  10890. || runs < minimum_runs
  10891. #endif
  10892. );
  10893. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  10894. #ifdef MULTI_VALUE_STATISTICS
  10895. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10896. #endif
  10897. wc_FreeEccsiKey(genKey);
  10898. wc_ecc_del_point(pvt);
  10899. exit:
  10900. WC_FREE_VAR(genKey, HEAP_HINT);
  10901. WC_FREE_VAR(ssk, HEAP_HINT);
  10902. }
  10903. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  10904. #endif /* WOLFCRYPT_HAVE_ECCSI */
  10905. #ifdef WOLFCRYPT_HAVE_SAKKE
  10906. #ifdef WOLFCRYPT_SAKKE_KMS
  10907. void bench_sakkeKeyGen(void)
  10908. {
  10909. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10910. double start;
  10911. int i, count;
  10912. const char**desc = bench_desc_words[lng_index];
  10913. int ret;
  10914. DECLARE_MULTI_VALUE_STATS_VARS()
  10915. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10916. /* Key Gen */
  10917. bench_stats_start(&count, &start);
  10918. do {
  10919. for (i = 0; i < genTimes; i++) {
  10920. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10921. ret = wc_MakeSakkeKey(genKey, &gRng);
  10922. if (ret != 0) {
  10923. printf("wc_MakeSakkeKey failed: %d\n", ret);
  10924. goto exit;
  10925. }
  10926. wc_FreeSakkeKey(genKey);
  10927. RECORD_MULTI_VALUE_STATS();
  10928. }
  10929. count += i;
  10930. } while (bench_stats_check(start)
  10931. #ifdef MULTI_VALUE_STATISTICS
  10932. || runs < minimum_runs
  10933. #endif
  10934. );
  10935. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  10936. #ifdef MULTI_VALUE_STATISTICS
  10937. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10938. #endif
  10939. exit:
  10940. WC_FREE_VAR(genKey, HEAP_HINT);
  10941. }
  10942. void bench_sakkeRskGen(void)
  10943. {
  10944. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10945. double start;
  10946. int i, count;
  10947. const char**desc = bench_desc_words[lng_index];
  10948. ecc_point* rsk;
  10949. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10950. int ret;
  10951. DECLARE_MULTI_VALUE_STATS_VARS()
  10952. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10953. rsk = wc_ecc_new_point();
  10954. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10955. (void)wc_MakeSakkeKey(genKey, &gRng);
  10956. /* RSK Gen */
  10957. bench_stats_start(&count, &start);
  10958. do {
  10959. for (i = 0; i < genTimes; i++) {
  10960. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  10961. if (ret != 0) {
  10962. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  10963. goto exit;
  10964. }
  10965. RECORD_MULTI_VALUE_STATS();
  10966. }
  10967. count += i;
  10968. } while (bench_stats_check(start)
  10969. #ifdef MULTI_VALUE_STATISTICS
  10970. || runs < minimum_runs
  10971. #endif
  10972. );
  10973. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  10974. #ifdef MULTI_VALUE_STATISTICS
  10975. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10976. #endif
  10977. wc_FreeSakkeKey(genKey);
  10978. wc_ecc_del_point(rsk);
  10979. exit:
  10980. WC_FREE_VAR(genKey, HEAP_HINT);
  10981. }
  10982. #endif
  10983. #ifdef WOLFCRYPT_SAKKE_CLIENT
  10984. void bench_sakkeValidate(void)
  10985. {
  10986. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10987. double start;
  10988. int i, count;
  10989. const char**desc = bench_desc_words[lng_index];
  10990. ecc_point* rsk;
  10991. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10992. int valid;
  10993. int ret;
  10994. DECLARE_MULTI_VALUE_STATS_VARS()
  10995. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10996. rsk = wc_ecc_new_point();
  10997. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10998. (void)wc_MakeSakkeKey(genKey, &gRng);
  10999. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11000. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11001. /* Validation of RSK */
  11002. bench_stats_start(&count, &start);
  11003. do {
  11004. for (i = 0; i < genTimes; i++) {
  11005. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11006. if (ret != 0 || !valid) {
  11007. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11008. valid);
  11009. goto exit;
  11010. }
  11011. RECORD_MULTI_VALUE_STATS();
  11012. }
  11013. count += i;
  11014. } while (bench_stats_check(start)
  11015. #ifdef MULTI_VALUE_STATISTICS
  11016. || runs < minimum_runs
  11017. #endif
  11018. );
  11019. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11020. #ifdef MULTI_VALUE_STATISTICS
  11021. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11022. #endif
  11023. wc_FreeSakkeKey(genKey);
  11024. wc_ecc_del_point(rsk);
  11025. exit:
  11026. WC_FREE_VAR(genKey, HEAP_HINT);
  11027. }
  11028. void bench_sakke(void)
  11029. {
  11030. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11031. double start;
  11032. int i, count;
  11033. const char**desc = bench_desc_words[lng_index];
  11034. ecc_point* rsk;
  11035. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11036. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11037. byte ssv[sizeof(ssv_init)];
  11038. byte derSSV[sizeof(ssv)];
  11039. byte auth[257];
  11040. word16 authSz = sizeof(auth);
  11041. int ret = 0;
  11042. byte* table = NULL;
  11043. word32 len = 0;
  11044. byte* iTable = NULL;
  11045. word32 iTableLen = 0;
  11046. DECLARE_MULTI_VALUE_STATS_VARS()
  11047. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11048. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11049. rsk = wc_ecc_new_point();
  11050. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11051. (void)wc_MakeSakkeKey(genKey, &gRng);
  11052. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11053. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11054. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11055. /* Encapsulate */
  11056. bench_stats_start(&count, &start);
  11057. do {
  11058. for (i = 0; i < genTimes; i++) {
  11059. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11060. WC_HASH_TYPE_SHA256,
  11061. ssv, sizeof(ssv), auth, &authSz);
  11062. if (ret != 0) {
  11063. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11064. break;
  11065. }
  11066. RECORD_MULTI_VALUE_STATS();
  11067. } /* for */
  11068. count += i;
  11069. } while (bench_stats_check(start)
  11070. #ifdef MULTI_VALUE_STATISTICS
  11071. || runs < minimum_runs
  11072. #endif
  11073. );
  11074. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11075. 0, count, start, 0);
  11076. #ifdef MULTI_VALUE_STATISTICS
  11077. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11078. #endif
  11079. RESET_MULTI_VALUE_STATS_VARS();
  11080. /* Derive */
  11081. bench_stats_start(&count, &start);
  11082. do {
  11083. for (i = 0; i < genTimes; i++) {
  11084. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11085. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11086. sizeof(derSSV), auth, authSz);
  11087. if (ret != 0) {
  11088. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11089. break;
  11090. }
  11091. RECORD_MULTI_VALUE_STATS();
  11092. }
  11093. if (ret != 0) break;
  11094. count += i;
  11095. } while (bench_stats_check(start)
  11096. #ifdef MULTI_VALUE_STATISTICS
  11097. || runs < minimum_runs
  11098. #endif
  11099. );
  11100. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11101. 0, count, start, 0);
  11102. #ifdef MULTI_VALUE_STATISTICS
  11103. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11104. #endif
  11105. /* Calculate Point I and generate table. */
  11106. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11107. iTableLen = 0;
  11108. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11109. if (iTableLen != 0) {
  11110. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11111. if (iTable == NULL)
  11112. WC_ALLOC_DO_ON_FAILURE();
  11113. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11114. }
  11115. /* Encapsulate with Point I table */
  11116. bench_stats_start(&count, &start);
  11117. do {
  11118. for (i = 0; i < genTimes; i++) {
  11119. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11120. WC_HASH_TYPE_SHA256, ssv,
  11121. sizeof(ssv), auth, &authSz);
  11122. if (ret != 0) {
  11123. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11124. break;
  11125. }
  11126. RECORD_MULTI_VALUE_STATS();
  11127. }
  11128. count += i;
  11129. } while (bench_stats_check(start)
  11130. #ifdef MULTI_VALUE_STATISTICS
  11131. || runs < minimum_runs
  11132. #endif
  11133. );
  11134. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11135. count, start, 0);
  11136. #ifdef MULTI_VALUE_STATISTICS
  11137. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11138. #endif
  11139. RESET_MULTI_VALUE_STATS_VARS();
  11140. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11141. /* Derive with Point I table */
  11142. bench_stats_start(&count, &start);
  11143. do {
  11144. for (i = 0; i < genTimes; i++) {
  11145. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11146. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11147. sizeof(derSSV), auth, authSz);
  11148. if (ret != 0) {
  11149. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11150. break;
  11151. }
  11152. RECORD_MULTI_VALUE_STATS();
  11153. }
  11154. if (ret != 0) break;
  11155. count += i;
  11156. } while (bench_stats_check(start)
  11157. #ifdef MULTI_VALUE_STATISTICS
  11158. || runs < minimum_runs
  11159. #endif
  11160. );
  11161. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11162. count, start, 0);
  11163. #ifdef MULTI_VALUE_STATISTICS
  11164. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11165. #endif
  11166. RESET_MULTI_VALUE_STATS_VARS();
  11167. len = 0;
  11168. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11169. if (len > 0) {
  11170. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11171. if (table == NULL)
  11172. WC_ALLOC_DO_ON_FAILURE();
  11173. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11174. }
  11175. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11176. /* Derive with Point I table and RSK table */
  11177. bench_stats_start(&count, &start);
  11178. do {
  11179. for (i = 0; i < genTimes; i++) {
  11180. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11181. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11182. sizeof(derSSV), auth, authSz);
  11183. if (ret != 0) {
  11184. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11185. break;
  11186. }
  11187. RECORD_MULTI_VALUE_STATS();
  11188. }
  11189. if (ret != 0) break;
  11190. count += i;
  11191. } while (bench_stats_check(start)
  11192. #ifdef MULTI_VALUE_STATISTICS
  11193. || runs < minimum_runs
  11194. #endif
  11195. );
  11196. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11197. 0, count, start, 0);
  11198. #ifdef MULTI_VALUE_STATISTICS
  11199. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11200. #endif
  11201. RESET_MULTI_VALUE_STATS_VARS();
  11202. wc_ClearSakkePointITable(genKey);
  11203. /* Derive with RSK table */
  11204. bench_stats_start(&count, &start);
  11205. do {
  11206. for (i = 0; i < genTimes; i++) {
  11207. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11208. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11209. sizeof(derSSV), auth, authSz);
  11210. if (ret != 0) {
  11211. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11212. break;
  11213. }
  11214. RECORD_MULTI_VALUE_STATS();
  11215. }
  11216. if (ret != 0) break;
  11217. count += i;
  11218. } while (bench_stats_check(start)
  11219. #ifdef MULTI_VALUE_STATISTICS
  11220. || runs < minimum_runs
  11221. #endif
  11222. );
  11223. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11224. count, start, 0);
  11225. #ifdef MULTI_VALUE_STATISTICS
  11226. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11227. #endif
  11228. wc_FreeSakkeKey(genKey);
  11229. wc_ecc_del_point(rsk);
  11230. exit:
  11231. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11232. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11233. WC_FREE_VAR(genKey, HEAP_HINT);
  11234. }
  11235. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11236. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11237. #ifdef HAVE_FALCON
  11238. void bench_falconKeySign(byte level)
  11239. {
  11240. int ret = 0;
  11241. falcon_key key;
  11242. double start;
  11243. int i, count;
  11244. byte sig[FALCON_MAX_SIG_SIZE];
  11245. byte msg[512];
  11246. word32 x = 0;
  11247. const char**desc = bench_desc_words[lng_index];
  11248. DECLARE_MULTI_VALUE_STATS_VARS()
  11249. ret = wc_falcon_init(&key);
  11250. if (ret != 0) {
  11251. printf("wc_falcon_init failed %d\n", ret);
  11252. return;
  11253. }
  11254. ret = wc_falcon_set_level(&key, level);
  11255. if (ret != 0) {
  11256. printf("wc_falcon_set_level failed %d\n", ret);
  11257. }
  11258. if (ret == 0) {
  11259. if (level == 1) {
  11260. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11261. sizeof_bench_falcon_level1_key,
  11262. NULL, 0, &key);
  11263. }
  11264. else {
  11265. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11266. sizeof_bench_falcon_level5_key,
  11267. NULL, 0, &key);
  11268. }
  11269. if (ret != 0) {
  11270. printf("wc_falcon_import_private_key failed %d\n", ret);
  11271. }
  11272. }
  11273. /* make dummy msg */
  11274. for (i = 0; i < (int)sizeof(msg); i++) {
  11275. msg[i] = (byte)i;
  11276. }
  11277. bench_stats_start(&count, &start);
  11278. do {
  11279. for (i = 0; i < agreeTimes; i++) {
  11280. if (ret == 0) {
  11281. if (level == 1) {
  11282. x = FALCON_LEVEL1_SIG_SIZE;
  11283. }
  11284. else {
  11285. x = FALCON_LEVEL5_SIG_SIZE;
  11286. }
  11287. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11288. if (ret != 0) {
  11289. printf("wc_falcon_sign_msg failed\n");
  11290. }
  11291. }
  11292. RECORD_MULTI_VALUE_STATS();
  11293. }
  11294. count += i;
  11295. } while (bench_stats_check(start)
  11296. #ifdef MULTI_VALUE_STATISTICS
  11297. || runs < minimum_runs
  11298. #endif
  11299. );
  11300. if (ret == 0) {
  11301. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11302. count, start, ret);
  11303. #ifdef MULTI_VALUE_STATISTICS
  11304. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11305. #endif
  11306. }
  11307. RESET_MULTI_VALUE_STATS_VARS();
  11308. bench_stats_start(&count, &start);
  11309. do {
  11310. for (i = 0; i < agreeTimes; i++) {
  11311. if (ret == 0) {
  11312. int verify = 0;
  11313. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11314. &key);
  11315. if (ret != 0 || verify != 1) {
  11316. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11317. ret, verify);
  11318. ret = -1;
  11319. }
  11320. }
  11321. RECORD_MULTI_VALUE_STATS();
  11322. }
  11323. count += i;
  11324. } while (bench_stats_check(start)
  11325. #ifdef MULTI_VALUE_STATISTICS
  11326. || runs < minimum_runs
  11327. #endif
  11328. );
  11329. if (ret == 0) {
  11330. bench_stats_asym_finish("FALCON", level, desc[5],
  11331. 0, count, start, ret);
  11332. #ifdef MULTI_VALUE_STATISTICS
  11333. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11334. #endif
  11335. }
  11336. wc_falcon_free(&key);
  11337. }
  11338. #endif /* HAVE_FALCON */
  11339. #ifdef HAVE_DILITHIUM
  11340. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11341. #ifndef WOLFSSL_NO_ML_DSA_44
  11342. static const unsigned char bench_dilithium_level2_sig[] = {
  11343. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11344. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11345. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11346. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11347. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11348. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11349. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11350. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11351. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11352. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11353. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11354. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11355. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11356. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11357. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11358. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11359. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11360. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11361. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11362. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11363. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11364. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11365. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11366. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11367. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11368. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11369. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11370. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11371. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11372. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11373. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11374. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11375. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11376. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11377. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11378. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11379. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11380. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11381. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11382. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11383. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11384. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11385. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11386. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11387. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11388. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11389. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11390. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11391. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11392. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11393. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11394. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11395. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11396. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11397. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11398. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11399. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11400. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11401. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11402. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11403. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11404. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11405. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11406. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11407. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11408. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11409. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11410. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11411. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11412. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11413. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11414. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11415. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11416. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11417. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11418. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11419. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11420. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11421. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11422. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11423. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11424. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11425. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11426. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11427. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11428. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11429. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11430. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11431. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11432. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11433. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11434. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11435. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11436. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11437. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11438. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11439. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11440. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11441. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11442. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11443. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11444. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11445. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11446. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11447. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11448. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11449. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11450. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11451. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11452. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11453. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11454. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11455. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11456. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11457. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11458. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11459. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11460. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11461. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11462. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11463. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11464. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11465. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11466. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11467. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11468. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11469. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11470. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11471. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11472. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11473. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11474. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11475. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11476. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11477. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11478. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11479. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11480. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11481. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11482. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11483. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11484. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11485. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11486. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11487. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11488. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11489. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11490. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11491. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11492. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11493. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11494. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11495. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11496. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11497. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11498. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11499. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11500. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11501. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11502. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11503. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11504. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11505. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11506. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11507. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11508. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11509. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11510. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11511. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11512. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11513. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11514. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11515. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11516. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11517. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11518. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11519. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11520. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11521. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11522. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11523. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11524. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11525. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11526. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11527. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11528. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11529. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11530. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11531. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11532. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11533. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11534. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11535. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11536. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11537. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11538. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11539. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11540. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11541. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11542. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11543. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11544. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11545. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11546. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11547. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11548. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11549. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11550. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11551. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11552. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11553. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11554. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11555. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11556. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11557. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11558. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11559. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11560. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11561. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11562. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11563. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11564. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11565. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11566. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11567. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11568. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11569. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11570. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11571. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11572. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11573. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11574. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11575. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11576. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11577. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11578. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11579. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11580. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11581. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11582. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11583. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11584. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11585. };
  11586. static const int sizeof_bench_dilithium_level2_sig =
  11587. sizeof(bench_dilithium_level2_sig);
  11588. #endif
  11589. #ifndef WOLFSSL_NO_ML_DSA_65
  11590. static const unsigned char bench_dilithium_level3_sig[] = {
  11591. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11592. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11593. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11594. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11595. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11596. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11597. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11598. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11599. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11600. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11601. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11602. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11603. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11604. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11605. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11606. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11607. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11608. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11609. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11610. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11611. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11612. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11613. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11614. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11615. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11616. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11617. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11618. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11619. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11620. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11621. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11622. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11623. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11624. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11625. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11626. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11627. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11628. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11629. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11630. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11631. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11632. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11633. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11634. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11635. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11636. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11637. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11638. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11639. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11640. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11641. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11642. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11643. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11644. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11645. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11646. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11647. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11648. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11649. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11650. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11651. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11652. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11653. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11654. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11655. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11656. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11657. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11658. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11659. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11660. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11661. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11662. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11663. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11664. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11665. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11666. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11667. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11668. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11669. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11670. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11671. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11672. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11673. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11674. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11675. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11676. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11677. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11678. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11679. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11680. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11681. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11682. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11683. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11684. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11685. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11686. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11687. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11688. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11689. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11690. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11691. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11692. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11693. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11694. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11695. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11696. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11697. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11698. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11699. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11700. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11701. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11702. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11703. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11704. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11705. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11706. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11707. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11708. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11709. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11710. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11711. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11712. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11713. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11714. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11715. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11716. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11717. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11718. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11719. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11720. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11721. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11722. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11723. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11724. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11725. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11726. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11727. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11728. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11729. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11730. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11731. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11732. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11733. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11734. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11735. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11736. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11737. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11738. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11739. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11740. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11741. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11742. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11743. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11744. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11745. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11746. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11747. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11748. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11749. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11750. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11751. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11752. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11753. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11754. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11755. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11756. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11757. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11758. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11759. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11760. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11761. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11762. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11763. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11764. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11765. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11766. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11767. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11768. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11769. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11770. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11771. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11772. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11773. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11774. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11775. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11776. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11777. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11778. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11779. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11780. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11781. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11782. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11783. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11784. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11785. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11786. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11787. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11788. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11789. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11790. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11791. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11792. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11793. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11794. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11795. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11796. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11797. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11798. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11799. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11800. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11801. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11802. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11803. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11804. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11805. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11806. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11807. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11808. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11809. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11810. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11811. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11812. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11813. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11814. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11815. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11816. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11817. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11818. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11819. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11820. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11821. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11822. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11823. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11824. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11825. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11826. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11827. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11828. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11829. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11830. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11831. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11832. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  11833. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  11834. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  11835. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  11836. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  11837. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  11838. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  11839. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  11840. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  11841. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  11842. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  11843. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  11844. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  11845. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  11846. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  11847. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  11848. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  11849. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  11850. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  11851. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  11852. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  11853. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  11854. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  11855. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  11856. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  11857. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  11858. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  11859. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  11860. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  11861. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  11862. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  11863. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  11864. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  11865. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  11866. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  11867. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  11868. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  11869. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  11870. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  11871. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  11872. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  11873. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  11874. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  11875. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  11876. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  11877. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  11878. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  11879. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  11880. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  11881. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  11882. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  11883. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  11884. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  11885. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  11886. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  11887. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  11888. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  11889. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  11890. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  11891. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  11892. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  11893. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  11894. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  11895. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  11896. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  11897. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  11898. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  11899. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  11900. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  11901. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  11902. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  11903. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  11904. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  11905. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  11906. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  11907. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  11908. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  11909. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  11910. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  11911. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  11912. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  11913. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  11914. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  11915. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  11916. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  11917. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  11918. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  11919. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  11920. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11921. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  11922. };
  11923. static const int sizeof_bench_dilithium_level3_sig =
  11924. sizeof(bench_dilithium_level3_sig);
  11925. #endif
  11926. #ifndef WOLFSSL_NO_ML_DSA_87
  11927. static const unsigned char bench_dilithium_level5_sig[] = {
  11928. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  11929. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  11930. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  11931. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  11932. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  11933. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  11934. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  11935. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  11936. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  11937. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  11938. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  11939. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  11940. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  11941. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  11942. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  11943. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  11944. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  11945. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  11946. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  11947. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  11948. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  11949. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  11950. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  11951. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  11952. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  11953. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  11954. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  11955. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  11956. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  11957. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  11958. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  11959. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  11960. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  11961. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  11962. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  11963. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  11964. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  11965. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  11966. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  11967. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  11968. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  11969. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  11970. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  11971. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  11972. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  11973. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  11974. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  11975. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  11976. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  11977. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  11978. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  11979. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  11980. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  11981. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  11982. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  11983. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  11984. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  11985. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  11986. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  11987. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  11988. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  11989. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  11990. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  11991. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  11992. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  11993. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  11994. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  11995. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  11996. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  11997. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  11998. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  11999. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12000. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12001. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12002. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12003. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12004. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12005. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12006. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12007. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12008. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12009. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12010. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12011. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12012. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12013. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12014. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12015. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12016. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12017. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12018. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12019. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12020. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12021. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12022. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12023. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12024. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12025. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12026. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12027. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12028. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12029. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12030. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12031. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12032. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12033. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12034. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12035. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12036. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12037. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12038. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12039. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12040. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12041. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12042. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12043. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12044. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12045. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12046. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12047. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12048. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12049. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12050. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12051. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12052. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12053. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12054. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12055. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12056. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12057. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12058. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12059. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12060. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12061. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12062. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12063. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12064. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12065. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12066. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12067. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12068. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12069. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12070. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12071. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12072. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12073. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12074. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12075. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12076. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12077. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12078. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12079. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12080. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12081. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12082. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12083. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12084. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12085. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12086. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12087. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12088. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12089. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12090. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12091. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12092. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12093. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12094. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12095. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12096. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12097. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12098. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12099. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12100. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12101. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12102. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12103. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12104. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12105. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12106. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12107. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12108. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12109. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12110. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12111. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12112. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12113. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12114. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12115. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12116. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12117. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12118. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12119. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12120. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12121. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12122. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12123. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12124. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12125. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12126. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12127. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12128. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12129. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12130. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12131. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12132. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12133. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12134. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12135. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12136. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12137. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12138. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12139. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12140. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12141. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12142. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12143. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12144. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12145. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12146. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12147. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12148. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12149. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12150. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12151. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12152. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12153. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12154. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12155. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12156. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12157. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12158. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12159. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12160. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12161. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12162. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12163. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12164. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12165. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12166. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12167. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12168. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12169. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12170. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12171. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12172. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12173. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12174. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12175. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12176. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12177. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12178. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12179. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12180. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12181. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12182. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12183. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12184. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12185. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12186. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12187. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12188. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12189. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12190. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12191. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12192. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12193. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12194. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12195. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12196. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12197. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12198. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12199. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12200. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12201. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12202. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12203. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12204. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12205. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12206. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12207. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12208. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12209. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12210. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12211. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12212. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12213. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12214. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12215. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12216. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12217. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12218. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12219. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12220. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12221. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12222. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12223. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12224. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12225. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12226. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12227. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12228. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12229. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12230. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12231. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12232. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12233. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12234. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12235. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12236. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12237. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12238. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12239. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12240. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12241. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12242. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12243. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12244. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12245. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12246. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12247. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12248. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12249. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12250. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12251. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12252. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12253. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12254. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12255. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12256. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12257. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12258. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12259. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12260. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12261. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12262. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12263. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12264. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12265. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12266. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12267. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12268. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12269. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12270. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12271. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12272. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12273. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12274. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12275. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12276. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12277. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12278. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12279. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12280. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12281. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12282. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12283. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12284. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12285. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12286. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12287. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12288. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12289. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12290. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12291. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12292. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12293. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12294. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12295. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12296. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12297. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12298. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12299. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12300. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12301. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12302. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12303. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12304. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12305. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12306. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12307. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12308. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12309. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12310. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12311. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12312. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12313. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12314. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12315. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12316. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12317. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12318. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12319. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12320. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12321. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12322. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12323. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12324. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12325. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12326. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12327. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12328. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12329. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12330. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12331. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12332. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12333. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12334. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12335. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12336. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12337. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12338. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12339. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12340. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12341. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12342. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12343. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12344. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12345. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12346. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12347. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12348. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12349. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12350. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12351. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12352. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12353. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12354. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12355. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12356. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12357. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12358. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12359. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12360. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12361. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12362. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12363. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12364. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12365. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12366. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12367. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12368. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12369. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12370. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12371. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12372. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12373. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12374. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12375. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12376. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12377. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12378. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12379. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12380. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12381. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12382. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12383. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12384. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12385. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12386. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12387. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12388. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12389. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12390. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12391. };
  12392. static const int sizeof_bench_dilithium_level5_sig =
  12393. sizeof(bench_dilithium_level5_sig);
  12394. #endif
  12395. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12396. void bench_dilithiumKeySign(byte level)
  12397. {
  12398. int ret = 0;
  12399. dilithium_key key;
  12400. double start;
  12401. int i, count;
  12402. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12403. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12404. byte msg[512];
  12405. word32 x = 0;
  12406. #endif
  12407. const char**desc = bench_desc_words[lng_index];
  12408. DECLARE_MULTI_VALUE_STATS_VARS()
  12409. byte params = 0;
  12410. if (level == 2) {
  12411. params = 44;
  12412. }
  12413. else if (level == 3) {
  12414. params = 65;
  12415. }
  12416. else if (level == 5) {
  12417. params = 87;
  12418. }
  12419. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12420. /* make dummy msg */
  12421. for (i = 0; i < (int)sizeof(msg); i++) {
  12422. msg[i] = (byte)i;
  12423. }
  12424. #endif
  12425. ret = wc_dilithium_init(&key);
  12426. if (ret != 0) {
  12427. printf("wc_dilithium_init failed %d\n", ret);
  12428. return;
  12429. }
  12430. ret = wc_dilithium_set_level(&key, level);
  12431. if (ret != 0) {
  12432. printf("wc_dilithium_set_level() failed %d\n", ret);
  12433. }
  12434. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12435. bench_stats_start(&count, &start);
  12436. do {
  12437. for (i = 0; i < agreeTimes; i++) {
  12438. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12439. if (ret != 0) {
  12440. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12441. return;
  12442. }
  12443. }
  12444. count += i;
  12445. } while (bench_stats_check(start)
  12446. #ifdef MULTI_VALUE_STATISTICS
  12447. || runs < minimum_runs
  12448. #endif
  12449. );
  12450. if (ret == 0) {
  12451. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12452. start, ret);
  12453. #ifdef MULTI_VALUE_STATISTICS
  12454. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12455. #endif
  12456. }
  12457. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12458. #ifndef WOLFSSL_NO_ML_DSA_44
  12459. if (level == 2) {
  12460. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12461. sizeof_bench_dilithium_level2_key, &key);
  12462. }
  12463. #endif
  12464. #ifndef WOLFSSL_NO_ML_DSA_65
  12465. if (level == 3) {
  12466. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12467. sizeof_bench_dilithium_level3_key, &key);
  12468. }
  12469. #endif
  12470. #ifndef WOLFSSL_NO_ML_DSA_87
  12471. if (level == 5) {
  12472. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12473. sizeof_bench_dilithium_level5_key, &key);
  12474. }
  12475. #endif
  12476. if (ret != 0) {
  12477. printf("Failed to load private key\n");
  12478. return;
  12479. }
  12480. #endif
  12481. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12482. if (level == 2) {
  12483. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12484. }
  12485. else if (level == 3) {
  12486. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12487. }
  12488. else {
  12489. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12490. }
  12491. RESET_MULTI_VALUE_STATS_VARS();
  12492. bench_stats_start(&count, &start);
  12493. do {
  12494. for (i = 0; i < agreeTimes; i++) {
  12495. if (ret == 0) {
  12496. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12497. GLOBAL_RNG);
  12498. if (ret != 0) {
  12499. printf("wc_dilithium_sign_msg failed\n");
  12500. }
  12501. }
  12502. RECORD_MULTI_VALUE_STATS();
  12503. }
  12504. count += i;
  12505. } while (bench_stats_check(start)
  12506. #ifdef MULTI_VALUE_STATISTICS
  12507. || runs < minimum_runs
  12508. #endif
  12509. );
  12510. if (ret == 0) {
  12511. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12512. ret);
  12513. #ifdef MULTI_VALUE_STATISTICS
  12514. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12515. #endif
  12516. }
  12517. #endif
  12518. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12519. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12520. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12521. #ifndef WOLFSSL_NO_ML_DSA_44
  12522. if (level == 2) {
  12523. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12524. x = sizeof_bench_dilithium_level2_sig;
  12525. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12526. #endif
  12527. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12528. sizeof_bench_dilithium_level2_pubkey, &key);
  12529. }
  12530. #endif
  12531. #ifndef WOLFSSL_NO_ML_DSA_65
  12532. if (level == 3) {
  12533. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12534. x = sizeof_bench_dilithium_level3_sig;
  12535. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12536. #endif
  12537. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12538. sizeof_bench_dilithium_level3_pubkey, &key);
  12539. }
  12540. #endif
  12541. #ifndef WOLFSSL_NO_ML_DSA_87
  12542. if (level == 5) {
  12543. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12544. x = sizeof_bench_dilithium_level5_sig;
  12545. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12546. #endif
  12547. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12548. sizeof_bench_dilithium_level5_pubkey, &key);
  12549. }
  12550. #endif
  12551. if (ret != 0) {
  12552. printf("Failed to load public key\n");
  12553. return;
  12554. }
  12555. #endif
  12556. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12557. RESET_MULTI_VALUE_STATS_VARS();
  12558. bench_stats_start(&count, &start);
  12559. do {
  12560. for (i = 0; i < agreeTimes; i++) {
  12561. if (ret == 0) {
  12562. int verify = 0;
  12563. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12564. &verify, &key);
  12565. if (ret != 0 || verify != 1) {
  12566. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12567. ret, verify);
  12568. ret = -1;
  12569. }
  12570. }
  12571. RECORD_MULTI_VALUE_STATS();
  12572. }
  12573. count += i;
  12574. } while (bench_stats_check(start)
  12575. #ifdef MULTI_VALUE_STATISTICS
  12576. || runs < minimum_runs
  12577. #endif
  12578. );
  12579. if (ret == 0) {
  12580. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12581. ret);
  12582. #ifdef MULTI_VALUE_STATISTICS
  12583. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12584. #endif
  12585. }
  12586. #endif
  12587. wc_dilithium_free(&key);
  12588. }
  12589. #endif /* HAVE_DILITHIUM */
  12590. #ifdef HAVE_SPHINCS
  12591. void bench_sphincsKeySign(byte level, byte optim)
  12592. {
  12593. int ret = 0;
  12594. sphincs_key key;
  12595. double start;
  12596. int i, count;
  12597. byte sig[SPHINCS_MAX_SIG_SIZE];
  12598. byte msg[512];
  12599. word32 x = 0;
  12600. const char**desc = bench_desc_words[lng_index];
  12601. DECLARE_MULTI_VALUE_STATS_VARS()
  12602. ret = wc_sphincs_init(&key);
  12603. if (ret != 0) {
  12604. printf("wc_sphincs_init failed %d\n", ret);
  12605. return;
  12606. }
  12607. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12608. if (ret != 0) {
  12609. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12610. }
  12611. if (ret == 0) {
  12612. ret = -1;
  12613. if ((level == 1) && (optim == FAST_VARIANT)) {
  12614. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12615. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12616. }
  12617. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12618. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12619. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12620. }
  12621. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12622. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12623. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12624. }
  12625. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12626. ret = wc_sphincs_import_private_key(
  12627. bench_sphincs_small_level1_key,
  12628. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12629. }
  12630. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12631. ret = wc_sphincs_import_private_key(
  12632. bench_sphincs_small_level3_key,
  12633. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12634. }
  12635. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12636. ret = wc_sphincs_import_private_key(
  12637. bench_sphincs_small_level5_key,
  12638. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12639. }
  12640. if (ret != 0) {
  12641. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12642. }
  12643. }
  12644. /* make dummy msg */
  12645. for (i = 0; i < (int)sizeof(msg); i++) {
  12646. msg[i] = (byte)i;
  12647. }
  12648. bench_stats_start(&count, &start);
  12649. do {
  12650. for (i = 0; i < agreeTimes; i++) {
  12651. if (ret == 0) {
  12652. if ((level == 1) && (optim == FAST_VARIANT)) {
  12653. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12654. }
  12655. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12656. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12657. }
  12658. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12659. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12660. }
  12661. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12662. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12663. }
  12664. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12665. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12666. }
  12667. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12668. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12669. }
  12670. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12671. if (ret != 0) {
  12672. printf("wc_sphincs_sign_msg failed\n");
  12673. }
  12674. }
  12675. RECORD_MULTI_VALUE_STATS();
  12676. }
  12677. count += i;
  12678. } while (bench_stats_check(start)
  12679. #ifdef MULTI_VALUE_STATISTICS
  12680. || runs < minimum_runs
  12681. #endif
  12682. );
  12683. if (ret == 0) {
  12684. if (optim == FAST_VARIANT) {
  12685. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12686. start, ret);
  12687. }
  12688. else {
  12689. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12690. start, ret);
  12691. }
  12692. #ifdef MULTI_VALUE_STATISTICS
  12693. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12694. #endif
  12695. }
  12696. RESET_MULTI_VALUE_STATS_VARS();
  12697. bench_stats_start(&count, &start);
  12698. do {
  12699. for (i = 0; i < agreeTimes; i++) {
  12700. if (ret == 0) {
  12701. int verify = 0;
  12702. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12703. &key);
  12704. if (ret != 0 || verify != 1) {
  12705. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12706. ret, verify);
  12707. ret = -1;
  12708. }
  12709. }
  12710. RECORD_MULTI_VALUE_STATS();
  12711. }
  12712. count += i;
  12713. } while (bench_stats_check(start)
  12714. #ifdef MULTI_VALUE_STATISTICS
  12715. || runs < minimum_runs
  12716. #endif
  12717. );
  12718. if (ret == 0) {
  12719. if (optim == FAST_VARIANT) {
  12720. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12721. start, ret);
  12722. }
  12723. else {
  12724. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12725. start, ret);
  12726. }
  12727. #ifdef MULTI_VALUE_STATISTICS
  12728. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12729. #endif
  12730. }
  12731. wc_sphincs_free(&key);
  12732. }
  12733. #endif /* HAVE_SPHINCS */
  12734. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12735. #define WIN32_LEAN_AND_MEAN
  12736. #include <windows.h>
  12737. double current_time(int reset)
  12738. {
  12739. static int init = 0;
  12740. static LARGE_INTEGER freq;
  12741. LARGE_INTEGER count;
  12742. (void)reset;
  12743. if (!init) {
  12744. QueryPerformanceFrequency(&freq);
  12745. init = 1;
  12746. }
  12747. QueryPerformanceCounter(&count);
  12748. #ifdef BENCH_MICROSECOND
  12749. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12750. #else
  12751. return (double)count.QuadPart / freq.QuadPart;
  12752. #endif
  12753. }
  12754. #elif defined MICROCHIP_PIC32
  12755. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12756. #define CLOCK 80000000.0
  12757. #else
  12758. #define CLOCK 40000000.0
  12759. #endif
  12760. extern void WriteCoreTimer(word32 t);
  12761. extern word32 ReadCoreTimer(void);
  12762. double current_time(int reset)
  12763. {
  12764. unsigned int ns;
  12765. if (reset) {
  12766. WriteCoreTimer(0);
  12767. }
  12768. /* get timer in ns */
  12769. ns = ReadCoreTimer();
  12770. /* return seconds as a double */
  12771. return ( ns / CLOCK * 2.0);
  12772. }
  12773. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12774. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12775. /* declared above at line 239 */
  12776. /* extern double current_time(int reset); */
  12777. #elif defined(FREERTOS)
  12778. #ifdef PLATFORMIO
  12779. #include <freertos/FreeRTOS.h>
  12780. #include <freertos/task.h>
  12781. #else
  12782. #include "task.h"
  12783. #endif
  12784. #if defined(WOLFSSL_ESPIDF)
  12785. /* prototype definition */
  12786. int construct_argv();
  12787. extern char* __argv[22];
  12788. /* current_time(reset)
  12789. *
  12790. * Benchmark passage of time, in fractional seconds.
  12791. * [reset] is non zero to adjust timer or counter to zero
  12792. *
  12793. * Use care when repeatedly calling calling. See implementation. */
  12794. double current_time(int reset)
  12795. {
  12796. double ret;
  12797. #if ESP_IDF_VERSION_MAJOR >= 4
  12798. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12799. #else
  12800. portTickType tickCount;
  12801. #endif
  12802. #if defined(__XTENSA__)
  12803. (void)reset;
  12804. if (reset) {
  12805. /* TODO: Determine a mechanism for reset that does not interfere
  12806. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12807. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12808. ESP_LOGW(TAG, "Current_time() reset!");
  12809. portTICK_TYPE_ENTER_CRITICAL();
  12810. {
  12811. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12812. _esp_cpu_count_last = xthal_get_ccount();
  12813. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12814. }
  12815. portTICK_TYPE_EXIT_CRITICAL();
  12816. */
  12817. }
  12818. #else
  12819. /* Only reset the CPU counter for RISC-V */
  12820. if (reset) {
  12821. ESP_LOGV(TAG, "current_time() reset!");
  12822. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12823. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12824. * See also esp_get_cycle_count_ex() */
  12825. #ifdef __XTENSA__
  12826. _esp_cpu_count_last = xthal_get_ccount();
  12827. #else
  12828. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12829. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12830. #endif
  12831. }
  12832. #endif
  12833. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  12834. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  12835. The count of ticks since vTaskStartScheduler was called,
  12836. typiclly in app_startup.c */
  12837. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12838. ESP_LOGV(TAG, "tickCount = %d", tickCount);
  12839. if (tickCount == last_tickCount) {
  12840. ESP_LOGW(TAG, "last_tickCount unchanged? %d", tickCount);
  12841. }
  12842. if (tickCount < last_tickCount) {
  12843. ESP_LOGW(TAG, "last_tickCount overflow?");
  12844. }
  12845. #endif
  12846. if (reset) {
  12847. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12848. ESP_LOGW(TAG, "Assign last_tickCount = %d", tickCount);
  12849. #endif
  12850. last_tickCount = tickCount;
  12851. }
  12852. else {
  12853. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12854. ESP_LOGV(TAG, "No Reset last_tickCount = %d", tickCount);
  12855. #endif
  12856. }
  12857. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  12858. ret = (double)tickCount / configTICK_RATE_HZ;
  12859. #else
  12860. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  12861. "assuming 1000 Hz.");
  12862. ret = (double)(tickCount / 1000.0);
  12863. #endif /* configTICK_RATE_HZ */
  12864. return ret;
  12865. } /* current_time */
  12866. #else
  12867. /* current_time(reset)
  12868. *
  12869. * Benchmark passage of time, in fractional seconds.
  12870. * [reset] is non zero to adjust timer or counter to zero
  12871. *
  12872. * Use care when repeatedly calling calling. See implementation. */
  12873. double current_time(int reset)
  12874. {
  12875. portTickType tickCount = xTaskGetTickCount();
  12876. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  12877. #ifdef configTICK_RATE_HZ
  12878. return (double)tickCount / configTICK_RATE_HZ;
  12879. #else
  12880. return (double)tickCount / 1000;
  12881. #endif
  12882. }
  12883. #endif
  12884. #elif defined (WOLFSSL_TIRTOS)
  12885. extern double current_time(int reset);
  12886. #elif defined(FREESCALE_MQX)
  12887. double current_time(int reset)
  12888. {
  12889. TIME_STRUCT tv;
  12890. _time_get(&tv);
  12891. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  12892. }
  12893. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  12894. && defined(MAX3266X_RTC)
  12895. double current_time(int reset)
  12896. {
  12897. (void)reset;
  12898. return wc_MXC_RTC_Time();
  12899. }
  12900. #elif defined(FREESCALE_KSDK_BM)
  12901. double current_time(int reset)
  12902. {
  12903. return (double)OSA_TimeGetMsec() / 1000;
  12904. }
  12905. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  12906. double current_time(int reset)
  12907. {
  12908. (void)reset;
  12909. return (double)osKernelGetTickCount() / 1000.0;
  12910. }
  12911. #elif defined(WOLFSSL_EMBOS)
  12912. #include "RTOS.h"
  12913. double current_time(int reset)
  12914. {
  12915. double time_now;
  12916. double current_s = OS_GetTime() / 1000.0;
  12917. double current_us = OS_GetTime_us() / MILLION_VALUE;
  12918. time_now = (double)( current_s + current_us);
  12919. (void) reset;
  12920. return time_now;
  12921. }
  12922. #elif defined(WOLFSSL_SGX)
  12923. double current_time(int reset);
  12924. #elif defined(WOLFSSL_DEOS)
  12925. double current_time(int reset)
  12926. {
  12927. const uint32_t systemTickTimeInHz
  12928. = 1000000 / systemTickInMicroseconds();
  12929. const volatile uint32_t *systemTickPtr = systemTickPointer();
  12930. (void)reset;
  12931. return (double) *systemTickPtr/systemTickTimeInHz;
  12932. }
  12933. #elif defined(MICRIUM)
  12934. double current_time(int reset)
  12935. {
  12936. #if (OS_VERSION < 50000)
  12937. CPU_ERR err;
  12938. (void)reset;
  12939. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  12940. #else
  12941. RTOS_ERR err;
  12942. double ret = 0;
  12943. OS_TICK tick = OSTimeGet(&err);
  12944. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  12945. (void)reset;
  12946. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  12947. ret = ((double)tick)/rate;
  12948. }
  12949. return ret;
  12950. #endif
  12951. }
  12952. #elif defined(WOLFSSL_ZEPHYR)
  12953. #include <time.h>
  12954. double current_time(int reset)
  12955. {
  12956. int64_t t;
  12957. (void)reset;
  12958. #if defined(CONFIG_ARCH_POSIX)
  12959. k_cpu_idle();
  12960. #endif
  12961. t = k_uptime_get(); /* returns current uptime in milliseconds */
  12962. return (double)(t / 1000);
  12963. }
  12964. #elif defined(WOLFSSL_NETBURNER)
  12965. #include <predef.h>
  12966. #include <utils.h>
  12967. #include <constants.h>
  12968. double current_time(int reset)
  12969. {
  12970. DWORD ticks = TimeTick; /* ticks since system start */
  12971. (void)reset;
  12972. return (double) ticks/TICKS_PER_SECOND;
  12973. }
  12974. #elif defined(THREADX)
  12975. #include "tx_api.h"
  12976. double current_time(int reset)
  12977. {
  12978. (void)reset;
  12979. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  12980. }
  12981. #elif defined(WOLFSSL_XILINX)
  12982. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  12983. #define COUNTS_PER_SECOND \
  12984. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  12985. #else
  12986. #define COUNTS_PER_SECOND \
  12987. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  12988. #endif
  12989. double current_time(int reset)
  12990. {
  12991. double timer;
  12992. uint64_t cntPct = 0;
  12993. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  12994. /* Convert to milliseconds */
  12995. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  12996. /* Convert to seconds.millisecond */
  12997. timer /= 1000;
  12998. return timer;
  12999. }
  13000. #elif defined(LINUX_RUSAGE_UTIME)
  13001. #include <sys/time.h>
  13002. #include <sys/resource.h>
  13003. static struct rusage base_rusage;
  13004. static struct rusage cur_rusage;
  13005. double current_time(int reset)
  13006. {
  13007. struct rusage rusage;
  13008. (void)reset;
  13009. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13010. if (reset)
  13011. base_rusage = rusage;
  13012. else
  13013. cur_rusage = rusage;
  13014. /* only consider user time, as system time is host-related overhead
  13015. * outside wolfcrypt.
  13016. */
  13017. return (double)rusage.ru_utime.tv_sec +
  13018. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13019. }
  13020. static void check_for_excessive_stime(const char *desc,
  13021. const char *desc_extra)
  13022. {
  13023. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13024. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13025. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13026. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13027. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13028. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13029. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13030. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13031. double stime_utime_ratio =
  13032. (cur_stime - start_stime) / (cur_utime - start_utime);
  13033. if (stime_utime_ratio > .1)
  13034. printf("%swarning, "
  13035. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13036. err_prefix, desc, desc_extra,
  13037. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13038. }
  13039. #elif defined(WOLFSSL_LINUXKM)
  13040. double current_time(int reset)
  13041. {
  13042. (void)reset;
  13043. u64 ns = ktime_get_ns();
  13044. return (double)ns / 1000000000.0;
  13045. }
  13046. #else
  13047. #include <sys/time.h>
  13048. double current_time(int reset)
  13049. {
  13050. struct timespec tv;
  13051. (void)reset;
  13052. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13053. #ifdef BENCH_MICROSECOND
  13054. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13055. #else
  13056. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13057. #endif
  13058. }
  13059. #endif /* _WIN32 */
  13060. #if defined(HAVE_GET_CYCLES)
  13061. #if defined(WOLFSSL_ESPIDF)
  13062. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13063. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13064. {
  13065. /* Reminder for long duration between calls with
  13066. * multiple overflows will not be detected. */
  13067. return esp_get_cycle_count_ex();
  13068. }
  13069. /* implement other architectures here */
  13070. #else
  13071. static WC_INLINE word64 get_intel_cycles(void)
  13072. {
  13073. unsigned int lo_c, hi_c;
  13074. __asm__ __volatile__ (
  13075. "cpuid\n\t"
  13076. "rdtsc"
  13077. : "=a"(lo_c), "=d"(hi_c) /* out */
  13078. : "a"(0) /* in */
  13079. : "%ebx", "%ecx"); /* clobber */
  13080. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13081. }
  13082. #endif
  13083. #endif /* HAVE_GET_CYCLES */
  13084. void benchmark_configure(word32 block_size)
  13085. {
  13086. /* must be greater than 0 */
  13087. if (block_size > 0) {
  13088. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13089. bench_size = block_size;
  13090. }
  13091. }
  13092. #ifndef NO_MAIN_DRIVER
  13093. #ifndef MAIN_NO_ARGS
  13094. #ifndef WOLFSSL_BENCHMARK_ALL
  13095. /* Display the algorithm string and keep to 80 characters per line.
  13096. *
  13097. * str Algorithm string to print.
  13098. * line Length of line used so far.
  13099. */
  13100. #ifndef BENCH_MAX_LINE
  13101. #define BENCH_MAX_LINE 80
  13102. #endif
  13103. static void print_alg(const char* str, int* line)
  13104. {
  13105. const char* const ident = " ";
  13106. if (*line == 0) {
  13107. printf("%s", ident);
  13108. *line = (int)XSTRLEN(ident);
  13109. }
  13110. printf(" %s", str);
  13111. *line += (int)XSTRLEN(str) + 1;
  13112. if (*line > BENCH_MAX_LINE) {
  13113. printf("\n");
  13114. *line = 0;
  13115. }
  13116. }
  13117. #endif /* WOLFSSL_BENCHMARK_ALL */
  13118. /* Display the usage options of the benchmark program. */
  13119. static void Usage(void)
  13120. {
  13121. int e = 0;
  13122. #ifndef WOLFSSL_BENCHMARK_ALL
  13123. int i;
  13124. int line;
  13125. #endif
  13126. printf("benchmark\n");
  13127. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13128. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13129. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13130. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13131. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13132. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13133. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13134. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13135. #else
  13136. e += 3;
  13137. #endif
  13138. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13139. #ifndef NO_RSA
  13140. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13141. #ifdef WOLFSSL_KEY_GEN
  13142. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13143. #endif
  13144. e++;
  13145. #else
  13146. e += 2;
  13147. #endif
  13148. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13149. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13150. #endif
  13151. e++;
  13152. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13153. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13154. #endif
  13155. e++;
  13156. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13157. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13158. #endif
  13159. e++;
  13160. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13161. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13162. #endif
  13163. e++;
  13164. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13165. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13166. #endif
  13167. e++;
  13168. #if defined(HAVE_ECC)
  13169. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13170. #endif
  13171. e++;
  13172. #ifndef WOLFSSL_BENCHMARK_ALL
  13173. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13174. line = 0;
  13175. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13176. print_alg(bench_cipher_opt[i].str, &line);
  13177. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13178. print_alg(bench_digest_opt[i].str, &line);
  13179. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13180. print_alg(bench_mac_opt[i].str, &line);
  13181. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13182. print_alg(bench_kdf_opt[i].str, &line);
  13183. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13184. print_alg(bench_asym_opt[i].str, &line);
  13185. for (i=0; bench_other_opt[i].str != NULL; i++)
  13186. print_alg(bench_other_opt[i].str, &line);
  13187. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13188. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13189. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13190. print_alg(bench_pq_asym_opt[i].str, &line);
  13191. #if defined(HAVE_SPHINCS)
  13192. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13193. print_alg(bench_pq_asym_opt2[i].str, &line);
  13194. #endif /* HAVE_SPHINCS */
  13195. #endif
  13196. #if defined(BENCH_PQ_STATEFUL_HBS)
  13197. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13198. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13199. #endif /* BENCH_PQ_STATEFUL_HBS */
  13200. printf("\n");
  13201. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13202. e++;
  13203. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13204. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13205. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13206. #ifdef WC_ENABLE_BENCH_THREADING
  13207. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13208. #endif
  13209. e++;
  13210. #ifdef WC_BENCH_TRACK_STATS
  13211. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13212. #endif
  13213. e++;
  13214. #ifndef NO_FILESYSTEM
  13215. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13216. #endif
  13217. e++;
  13218. #ifndef NO_FILESYSTEM
  13219. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13220. #endif
  13221. #ifdef MULTI_VALUE_STATISTICS
  13222. e++;
  13223. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13224. #endif
  13225. }
  13226. /* Match the command line argument with the string.
  13227. *
  13228. * arg Command line argument.
  13229. * str String to check for.
  13230. * return 1 if the command line argument matches the string, 0 otherwise.
  13231. */
  13232. static int string_matches(const char* arg, const char* str)
  13233. {
  13234. return XSTRCMP(arg, str) == 0;
  13235. }
  13236. #endif /* MAIN_NO_ARGS */
  13237. /*
  13238. ** ----------------------------------------------------------------------------
  13239. ** determine how the benchmarks are called, the function name varies:
  13240. ** ----------------------------------------------------------------------------
  13241. */
  13242. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13243. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13244. /* for some environments, we'll call a function wolf_benchmark_task: */
  13245. int wolf_benchmark_task(void)
  13246. #elif defined(MAIN_NO_ARGS)
  13247. /* otherwise we'll use main() with no arguments as desired: */
  13248. int main()
  13249. #else
  13250. /* else we'll be calling main with default arg parameters */
  13251. int main(int argc, char** argv)
  13252. #endif
  13253. {
  13254. /* Code for main() or wolf_benchmark_task() */
  13255. #ifdef WOLFSSL_ESPIDF
  13256. int argc = construct_argv();
  13257. char** argv = (char**)__argv;
  13258. #elif defined(MAIN_NO_ARGS)
  13259. int argc = 0;
  13260. char** argv = NULL;
  13261. #endif
  13262. return wolfcrypt_benchmark_main(argc, argv);
  13263. }
  13264. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13265. int wolfcrypt_benchmark_main(int argc, char** argv)
  13266. {
  13267. int ret = 0;
  13268. #ifndef MAIN_NO_ARGS
  13269. int optMatched;
  13270. #ifndef WOLFSSL_BENCHMARK_ALL
  13271. int i;
  13272. #endif
  13273. #endif
  13274. benchmark_static_init(1);
  13275. printf("%s------------------------------------------------------------------------------\n",
  13276. info_prefix);
  13277. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13278. printf("%s------------------------------------------------------------------------------\n",
  13279. info_prefix);
  13280. #ifndef MAIN_NO_ARGS
  13281. while (argc > 1) {
  13282. if (string_matches(argv[1], "-?")) {
  13283. if (--argc > 1) {
  13284. lng_index = XATOI((++argv)[1]);
  13285. if (lng_index<0 || lng_index>1) {
  13286. lng_index = 0;
  13287. }
  13288. }
  13289. Usage();
  13290. return 0;
  13291. }
  13292. else if (string_matches(argv[1], "-lng")) {
  13293. argc--;
  13294. argv++;
  13295. if (argc > 1) {
  13296. lng_index = XATOI(argv[1]);
  13297. if (lng_index<0 || lng_index>1) {
  13298. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13299. lng_index);
  13300. lng_index = 0;
  13301. }
  13302. }
  13303. }
  13304. else if (string_matches(argv[1], "-base10"))
  13305. base2 = 0;
  13306. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13307. else if (string_matches(argv[1], "-no_aad"))
  13308. aes_aad_options = AAD_SIZE_ZERO;
  13309. else if (string_matches(argv[1], "-all_aad"))
  13310. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13311. else if (string_matches(argv[1], "-aad_size")) {
  13312. argc--;
  13313. argv++;
  13314. if (argc > 1) {
  13315. aes_aad_size = (word32)XATOI(argv[1]);
  13316. aes_aad_options |= AAD_SIZE_CUSTOM;
  13317. }
  13318. }
  13319. #endif
  13320. else if (string_matches(argv[1], "-dgst_full"))
  13321. digest_stream = 0;
  13322. #ifdef HAVE_CHACHA
  13323. else if (string_matches(argv[1], "-enc_only"))
  13324. encrypt_only = 1;
  13325. #endif
  13326. #ifndef NO_RSA
  13327. else if (string_matches(argv[1], "-rsa_sign"))
  13328. rsa_sign_verify = 1;
  13329. #endif
  13330. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13331. else if (string_matches(argv[1], "-ffdhe2048"))
  13332. use_ffdhe = 2048;
  13333. #endif
  13334. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13335. else if (string_matches(argv[1], "-ffdhe3072"))
  13336. use_ffdhe = 3072;
  13337. #endif
  13338. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13339. else if (string_matches(argv[1], "-ffdhe4096"))
  13340. use_ffdhe = 4096;
  13341. #endif
  13342. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13343. else if (string_matches(argv[1], "-p256"))
  13344. bench_asym_algs |= BENCH_ECC_P256;
  13345. #endif
  13346. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13347. else if (string_matches(argv[1], "-p384"))
  13348. bench_asym_algs |= BENCH_ECC_P384;
  13349. #endif
  13350. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13351. else if (string_matches(argv[1], "-p521"))
  13352. bench_asym_algs |= BENCH_ECC_P521;
  13353. #endif
  13354. #ifdef BENCH_ASYM
  13355. else if (string_matches(argv[1], "-csv")) {
  13356. csv_format = 1;
  13357. }
  13358. #endif
  13359. #ifdef WC_ENABLE_BENCH_THREADING
  13360. else if (string_matches(argv[1], "-threads")) {
  13361. argc--;
  13362. argv++;
  13363. if (argc > 1) {
  13364. g_threadCount = XATOI(argv[1]);
  13365. if (g_threadCount < 1 || lng_index > 128){
  13366. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13367. g_threadCount);
  13368. g_threadCount = 0;
  13369. }
  13370. }
  13371. }
  13372. #endif
  13373. #ifdef WC_BENCH_TRACK_STATS
  13374. else if (string_matches(argv[1], "-print")) {
  13375. gPrintStats = 1;
  13376. }
  13377. #endif
  13378. else if (string_matches(argv[1], "-blocks")) {
  13379. argc--;
  13380. argv++;
  13381. if (argc > 1)
  13382. numBlocks = XATOI(argv[1]);
  13383. }
  13384. #ifndef NO_FILESYSTEM
  13385. else if (string_matches(argv[1], "-hash_input")) {
  13386. argc--;
  13387. argv++;
  13388. if (argc > 1)
  13389. hash_input = argv[1];
  13390. }
  13391. else if (string_matches(argv[1], "-cipher_input")) {
  13392. argc--;
  13393. argv++;
  13394. if (argc > 1)
  13395. cipher_input = argv[1];
  13396. }
  13397. #endif
  13398. #ifdef MULTI_VALUE_STATISTICS
  13399. else if (string_matches(argv[1], "-min_runs")) {
  13400. argc--;
  13401. argv++;
  13402. if (argc > 1) {
  13403. minimum_runs = XATOI(argv[1]);
  13404. }
  13405. }
  13406. #endif
  13407. else if (argv[1][0] == '-') {
  13408. optMatched = 0;
  13409. #ifndef WOLFSSL_BENCHMARK_ALL
  13410. /* Check known algorithm choosing command line options. */
  13411. /* Known cipher algorithms */
  13412. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13413. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13414. bench_cipher_algs |= bench_cipher_opt[i].val;
  13415. bench_all = 0;
  13416. optMatched = 1;
  13417. }
  13418. }
  13419. /* Known digest algorithms */
  13420. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13421. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13422. bench_digest_algs |= bench_digest_opt[i].val;
  13423. bench_all = 0;
  13424. optMatched = 1;
  13425. }
  13426. }
  13427. /* Known MAC algorithms */
  13428. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13429. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13430. bench_mac_algs |= bench_mac_opt[i].val;
  13431. bench_all = 0;
  13432. optMatched = 1;
  13433. }
  13434. }
  13435. /* Known KDF algorithms */
  13436. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13437. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13438. bench_kdf_algs |= bench_kdf_opt[i].val;
  13439. bench_all = 0;
  13440. optMatched = 1;
  13441. }
  13442. }
  13443. /* Known asymmetric algorithms */
  13444. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13445. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13446. bench_asym_algs |= bench_asym_opt[i].val;
  13447. bench_all = 0;
  13448. optMatched = 1;
  13449. }
  13450. }
  13451. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13452. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13453. /* Known asymmetric post-quantum algorithms */
  13454. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13455. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13456. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13457. bench_all = 0;
  13458. optMatched = 1;
  13459. }
  13460. }
  13461. #ifdef HAVE_SPHINCS
  13462. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13463. * -pq, so we need to do a special case for -pq since optMatched
  13464. * was set to 1 just above. */
  13465. if ((bench_pq_asym_opt[0].str != NULL) &&
  13466. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13467. {
  13468. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13469. bench_all = 0;
  13470. optMatched = 1;
  13471. }
  13472. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13473. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13474. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13475. bench_all = 0;
  13476. optMatched = 1;
  13477. }
  13478. }
  13479. #endif
  13480. #endif
  13481. /* Other known cryptographic algorithms */
  13482. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13483. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13484. bench_other_algs |= bench_other_opt[i].val;
  13485. bench_all = 0;
  13486. optMatched = 1;
  13487. }
  13488. }
  13489. #if defined(BENCH_PQ_STATEFUL_HBS)
  13490. /* post-quantum stateful hash-based signatures */
  13491. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13492. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13493. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13494. bench_all = 0;
  13495. optMatched = 1;
  13496. }
  13497. }
  13498. #endif /* BENCH_PQ_STATEFUL_HBS */
  13499. #endif
  13500. if (!optMatched) {
  13501. printf("Option not recognized: %s\n", argv[1]);
  13502. Usage();
  13503. return 1;
  13504. }
  13505. }
  13506. else {
  13507. /* parse for block size */
  13508. benchmark_configure((word32)XATOI(argv[1]));
  13509. }
  13510. argc--;
  13511. argv++;
  13512. }
  13513. #endif /* MAIN_NO_ARGS */
  13514. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13515. /* when defined, we'll always output CSV regardless of params.
  13516. ** this is typically convenient in embedded environments.
  13517. */
  13518. csv_format = 1;
  13519. #endif
  13520. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13521. if (g_threadCount > 1) {
  13522. ret = benchmark_test_threaded(NULL);
  13523. }
  13524. else
  13525. #endif
  13526. {
  13527. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13528. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13529. defined(CONFIG_IDF_TARGET_ESP32C6)
  13530. {
  13531. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13532. if (esp_gptimer == NULL) {
  13533. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13534. &esp_gptimer) );
  13535. }
  13536. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13537. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13538. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13539. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13540. }
  13541. #endif
  13542. #ifdef HAVE_STACK_SIZE
  13543. ret = StackSizeCheck(NULL, benchmark_test);
  13544. #else
  13545. ret = benchmark_test(NULL);
  13546. #endif
  13547. }
  13548. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13549. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13550. defined(CONFIG_IDF_TARGET_ESP32C6)
  13551. {
  13552. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13553. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13554. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13555. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13556. }
  13557. #endif
  13558. return ret;
  13559. }
  13560. #endif /* !NO_MAIN_DRIVER */
  13561. #else
  13562. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13563. int main(void) { return 0; }
  13564. #endif
  13565. #endif /* !NO_CRYPT_BENCHMARK */