2
0

benchmark.c 518 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273
  1. /* benchmark.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS)
  166. #include <wolfssl/wolfcrypt/ext_kyber.h>
  167. #endif
  168. #endif
  169. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  170. #include <wolfssl/wolfcrypt/lms.h>
  171. #ifdef HAVE_LIBLMS
  172. #include <wolfssl/wolfcrypt/ext_lms.h>
  173. #else
  174. #include <wolfssl/wolfcrypt/wc_lms.h>
  175. #endif
  176. #endif
  177. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  178. #include <wolfssl/wolfcrypt/xmss.h>
  179. #ifdef HAVE_LIBXMSS
  180. #include <wolfssl/wolfcrypt/ext_xmss.h>
  181. #else
  182. #include <wolfssl/wolfcrypt/wc_xmss.h>
  183. #endif
  184. #endif
  185. #ifdef WOLFCRYPT_HAVE_ECCSI
  186. #include <wolfssl/wolfcrypt/eccsi.h>
  187. #endif
  188. #ifdef WOLFCRYPT_HAVE_SAKKE
  189. #include <wolfssl/wolfcrypt/sakke.h>
  190. #endif
  191. #if defined(HAVE_FALCON)
  192. #include <wolfssl/wolfcrypt/falcon.h>
  193. #endif
  194. #if defined(HAVE_DILITHIUM)
  195. #include <wolfssl/wolfcrypt/dilithium.h>
  196. #endif
  197. #if defined(HAVE_SPHINCS)
  198. #include <wolfssl/wolfcrypt/sphincs.h>
  199. #endif
  200. #ifdef WOLF_CRYPTO_CB
  201. #include <wolfssl/wolfcrypt/cryptocb.h>
  202. #ifdef HAVE_INTEL_QA_SYNC
  203. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  204. #endif
  205. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  206. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  207. #endif
  208. #ifdef HAVE_RENESAS_SYNC
  209. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  210. #endif
  211. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  212. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  213. #endif
  214. #endif
  215. #ifdef WOLFSSL_ASYNC_CRYPT
  216. #include <wolfssl/wolfcrypt/async.h>
  217. #endif
  218. #include <wolfssl/wolfcrypt/cpuid.h>
  219. #ifdef USE_FLAT_BENCHMARK_H
  220. #include "benchmark.h"
  221. #else
  222. #include "wolfcrypt/benchmark/benchmark.h"
  223. #endif
  224. /* define the max length for each string of metric reported */
  225. #ifndef WC_BENCH_MAX_LINE_LEN
  226. #define WC_BENCH_MAX_LINE_LEN 150
  227. #endif
  228. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  229. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  230. #define MILLION_VALUE 1000000.0
  231. #ifdef BENCH_MICROSECOND
  232. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  233. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  234. #else
  235. #define WOLFSSL_FIXED_TIME_UNIT "s"
  236. #endif
  237. #ifdef MULTI_VALUE_STATISTICS
  238. #define STATS_CLAUSE_SEPARATOR ""
  239. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  240. squareSum = 0, prev = 0, delta;\
  241. int runs = 0;
  242. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  243. delta = current_time(0) - start;\
  244. min = delta;\
  245. max = delta;\
  246. }\
  247. else {\
  248. delta = current_time(0) - prev;\
  249. }\
  250. if (max < delta)\
  251. max = delta;\
  252. else if (min > delta)\
  253. min = delta;\
  254. sum += delta;\
  255. squareSum += delta * delta;\
  256. runs++;\
  257. prev = current_time(0)
  258. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  259. runs = 0;\
  260. sum = 0;\
  261. squareSum = 0
  262. #else
  263. #define STATS_CLAUSE_SEPARATOR "\n"
  264. #define DECLARE_MULTI_VALUE_STATS_VARS()
  265. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  266. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  267. #endif
  268. #ifdef WOLFSSL_NO_FLOAT_FMT
  269. #define FLT_FMT "%0ld,%09lu"
  270. #define FLT_FMT_PREC "%0ld.%0*lu"
  271. #define FLT_FMT_PREC2 FLT_FMT_PREC
  272. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  273. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  274. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  275. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  276. 10000.0, 100000.0, 1000000.0, \
  277. 10000000.0, 100000000.0, \
  278. 1000000000.0 };
  279. #define FLT_FMT_PREC_ARGS(p, x) \
  280. (long)(x), \
  281. p, \
  282. (x) >= 0.0 ? \
  283. (unsigned long int)((((x) - (double)(long)(x)) * \
  284. pow_10_array[(p)+1]) + 0.5) : \
  285. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  286. pow_10_array[(p)+1]) + 0.5)
  287. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  288. #else
  289. #define FLT_FMT "%f"
  290. #define FLT_FMT_PREC "%.*f"
  291. #define FLT_FMT_PREC2 "%*.*f"
  292. #define FLT_FMT_ARGS(x) x
  293. #define FLT_FMT_PREC_ARGS(p, x) p, x
  294. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  295. #endif /* WOLFSSL_NO_FLOAT_FMT */
  296. #ifdef WOLFSSL_ESPIDF
  297. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  298. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  299. * enabled, all if the values in report are blank. */
  300. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  301. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  302. #error "Nano newlib formatting must not be enabled for benchmark"
  303. #endif
  304. #endif
  305. #if ESP_IDF_VERSION_MAJOR >= 5
  306. #define TFMT "%lu"
  307. #else
  308. #define TFMT "%d"
  309. #endif
  310. #ifdef configTICK_RATE_HZ
  311. /* Define CPU clock cycles per tick of FreeRTOS clock
  312. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  313. * configTICK_RATE_HZ is typically 100 or 1000.
  314. **/
  315. #if defined(CONFIG_IDF_TARGET_ESP8266)
  316. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  317. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  318. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  319. #endif
  320. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  321. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  322. #endif
  323. #endif
  324. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  325. /* This section is for pre-v5 ESP-IDF */
  326. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  327. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  328. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  329. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  330. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  331. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  332. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  333. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  334. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  335. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  336. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  337. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  338. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  339. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  340. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  341. #else
  342. /* TODO unsupported */
  343. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  344. #endif
  345. #define CPU_TICK_CYCLES ( \
  346. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  347. / configTICK_RATE_HZ \
  348. )
  349. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  350. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  351. #include "driver/gptimer.h"
  352. static gptimer_handle_t esp_gptimer = NULL;
  353. static gptimer_config_t esp_timer_config = {
  354. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  355. .direction = GPTIMER_COUNT_UP,
  356. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  357. };
  358. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  359. defined(CONFIG_IDF_TARGET_ESP32C6)
  360. #include <esp_cpu.h>
  361. #if ESP_IDF_VERSION_MAJOR >= 5
  362. #include <driver/gptimer.h>
  363. #endif
  364. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  365. #define RESOLUTION_SCALE 100
  366. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  367. static gptimer_handle_t esp_gptimer = NULL;
  368. static gptimer_config_t esp_timer_config = {
  369. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  370. .direction = GPTIMER_COUNT_UP,
  371. /* CONFIG_XTAL_FREQ = 40,
  372. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  373. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  374. (MILLION_VALUE / RESOLUTION_SCALE),
  375. };
  376. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  377. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  379. defined(CONFIG_IDF_TARGET_ESP32S3)
  380. #include <xtensa/hal.h>
  381. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  382. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  383. #include <FreeRTOS.h>
  384. #include <esp_system.h>
  385. #include <esp_timer.h>
  386. #include <xtensa/hal.h>
  387. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  388. /* TODO add ESP32-H2 benchmark support */
  389. #else
  390. /* Other platform */
  391. #endif
  392. #include <esp_log.h>
  393. #endif /* WOLFSSL_ESPIDF */
  394. #if defined(HAVE_PTHREAD) || \
  395. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  396. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  397. !defined(BENCH_EMBEDDED))
  398. #include <errno.h>
  399. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  400. #include <unistd.h>
  401. #endif
  402. #endif
  403. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  404. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  405. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  406. #undef XFFLUSH
  407. #define XFFLUSH(...) WC_DO_NOTHING
  408. #endif
  409. /* only for stack size check */
  410. #include <wolfssl/wolfcrypt/mem_track.h>
  411. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  412. #define WC_ENABLE_BENCH_THREADING
  413. #endif
  414. /* enable tracking of stats for threaded benchmark */
  415. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  416. #define WC_BENCH_TRACK_STATS
  417. #endif
  418. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  419. static const char info_prefix[] = "###, ";
  420. static const char err_prefix[] = "!!!, ";
  421. #else
  422. static const char info_prefix[] = "";
  423. static const char err_prefix[] = "";
  424. #endif
  425. /* printf mappings */
  426. #ifdef FREESCALE_MQX
  427. #include <mqx.h>
  428. /* see wc_port.h for fio.h and nio.h includes */
  429. #elif defined(FREESCALE_KSDK_1_3)
  430. #include "fsl_debug_console.h"
  431. #include "fsl_os_abstraction.h"
  432. #undef printf
  433. #define printf PRINTF
  434. #elif defined(WOLFSSL_DEOS)
  435. #include <deos.h>
  436. #include <printx.h>
  437. #undef printf
  438. #define printf printx
  439. #elif defined(MICRIUM)
  440. #if (OS_VERSION < 50000)
  441. #include <bsp_ser.h>
  442. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  443. #undef printf
  444. #define printf BSP_Ser_Printf
  445. #endif
  446. #elif defined(WOLFSSL_ZEPHYR)
  447. #include <stdio.h>
  448. #include <stdarg.h>
  449. #define BENCH_EMBEDDED
  450. #define printf printfk
  451. static int printfk(const char *fmt, ...)
  452. {
  453. int ret;
  454. char line[WC_BENCH_MAX_LINE_LEN];
  455. va_list ap;
  456. va_start(ap, fmt);
  457. ret = vsnprintf(line, sizeof(line), fmt, ap);
  458. line[sizeof(line)-1] = '\0';
  459. printk("%s", line);
  460. va_end(ap);
  461. return ret;
  462. }
  463. #elif defined(WOLFSSL_TELIT_M2MB)
  464. #include <stdarg.h>
  465. #include <stdio.h>
  466. #include <string.h>
  467. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  468. /* remap printf */
  469. #undef printf
  470. #define printf M2M_LOG_INFO
  471. /* OS requires occasional sleep() */
  472. #ifndef TEST_SLEEP_MS
  473. #define TEST_SLEEP_MS 50
  474. #endif
  475. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  476. /* don't use file system for these tests, since ./certs dir isn't loaded */
  477. #undef NO_FILESYSTEM
  478. #define NO_FILESYSTEM
  479. /* ANDROID_V454 (for android studio) displays information in a textview
  480. * and redirects printf to the textview output instead of using
  481. * __android_log_print() */
  482. #elif defined(ANDROID) && !defined(ANDROID_V454)
  483. #ifdef XMALLOC_USER
  484. #include <stdlib.h> /* we're using malloc / free direct here */
  485. #endif
  486. #ifndef STRING_USER
  487. #include <stdio.h>
  488. #endif
  489. #include <android/log.h>
  490. #define printf(...) \
  491. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  492. #define fprintf(fp, ...) \
  493. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  494. #else
  495. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  496. /* MQX classic needs for EXIT_FAILURE */
  497. #include <stdlib.h> /* we're using malloc / free direct here */
  498. #endif
  499. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  500. #include <string.h>
  501. #include <stdio.h>
  502. #endif
  503. /* enable way for customer to override test/bench printf */
  504. #ifdef XPRINTF
  505. #undef printf
  506. #define printf XPRINTF
  507. #elif defined(NETOS)
  508. #undef printf
  509. #define printf dc_log_printf
  510. #endif
  511. #endif
  512. #ifdef HAVE_FIPS
  513. #include <wolfssl/wolfcrypt/fips_test.h>
  514. static void myFipsCb(int ok, int err, const char* hash)
  515. {
  516. printf("%sin my Fips callback, ok = %d, err = %d\n",
  517. ok ? info_prefix : err_prefix, ok, err);
  518. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  519. wc_GetErrorString(err));
  520. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  521. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  522. printf("%sIn core integrity hash check failure, copy above hash\n",
  523. err_prefix);
  524. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  525. err_prefix);
  526. }
  527. }
  528. #endif
  529. #ifdef WOLFSSL_STATIC_MEMORY
  530. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  531. #else
  532. #define HEAP_HINT NULL
  533. #endif /* WOLFSSL_STATIC_MEMORY */
  534. #ifndef EXIT_FAILURE
  535. #define EXIT_FAILURE 1
  536. #endif
  537. #undef LIBCALL_CHECK_RET
  538. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  539. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  540. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  541. #else
  542. #define LIBCALL_CHECK_RET(...) do { \
  543. int _libcall_ret = (__VA_ARGS__); \
  544. if (_libcall_ret < 0) { \
  545. printf("%s%s L%d error %d for \"%s\"\n", \
  546. err_prefix, __FILE__, __LINE__, \
  547. errno, #__VA_ARGS__); \
  548. XFFLUSH(stdout); \
  549. _exit(1); \
  550. } \
  551. } while(0)
  552. #endif
  553. #undef THREAD_CHECK_RET
  554. #define THREAD_CHECK_RET(...) do { \
  555. int _thread_ret = (__VA_ARGS__); \
  556. if (_thread_ret != 0) { \
  557. errno = _thread_ret; \
  558. printf("%s%s L%d error %d for \"%s\"\n", \
  559. err_prefix, __FILE__, __LINE__, \
  560. _thread_ret, #__VA_ARGS__); \
  561. XFFLUSH(stdout); \
  562. _exit(1); \
  563. } \
  564. } while(0)
  565. /* optional macro to add sleep between tests */
  566. #ifndef TEST_SLEEP
  567. /* stub the sleep macro */
  568. #define TEST_SLEEP() WC_DO_NOTHING
  569. #endif
  570. #define TEST_STRING "Everyone gets Friday off."
  571. #define TEST_STRING_SZ 25
  572. /* Bit values for each algorithm that is able to be benchmarked.
  573. * Common grouping of algorithms also.
  574. * Each algorithm has a unique value for its type e.g. cipher.
  575. */
  576. /* Cipher algorithms. */
  577. #define BENCH_AES_CBC 0x00000001
  578. #define BENCH_AES_GCM 0x00000002
  579. #define BENCH_AES_ECB 0x00000004
  580. #define BENCH_AES_XTS 0x00000008
  581. #define BENCH_AES_CTR 0x00000010
  582. #define BENCH_AES_CCM 0x00000020
  583. #define BENCH_CAMELLIA 0x00000100
  584. #define BENCH_ARC4 0x00000200
  585. #define BENCH_CHACHA20 0x00001000
  586. #define BENCH_CHACHA20_POLY1305 0x00002000
  587. #define BENCH_DES 0x00004000
  588. #define BENCH_AES_CFB 0x00010000
  589. #define BENCH_AES_OFB 0x00020000
  590. #define BENCH_AES_SIV 0x00040000
  591. #define BENCH_SM4_CBC 0x00080000
  592. #define BENCH_SM4_GCM 0x00100000
  593. #define BENCH_SM4_CCM 0x00200000
  594. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  595. /* Digest algorithms. */
  596. #define BENCH_MD5 0x00000001
  597. #define BENCH_POLY1305 0x00000002
  598. #define BENCH_SHA 0x00000004
  599. #define BENCH_SHA224 0x00000010
  600. #define BENCH_SHA256 0x00000020
  601. #define BENCH_SHA384 0x00000040
  602. #define BENCH_SHA512 0x00000080
  603. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  604. BENCH_SHA384 | BENCH_SHA512)
  605. #define BENCH_SHA3_224 0x00000100
  606. #define BENCH_SHA3_256 0x00000200
  607. #define BENCH_SHA3_384 0x00000400
  608. #define BENCH_SHA3_512 0x00000800
  609. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  610. BENCH_SHA3_384 | BENCH_SHA3_512)
  611. #define BENCH_SHAKE128 0x00001000
  612. #define BENCH_SHAKE256 0x00002000
  613. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  614. #define BENCH_RIPEMD 0x00004000
  615. #define BENCH_BLAKE2B 0x00008000
  616. #define BENCH_BLAKE2S 0x00010000
  617. #define BENCH_SM3 0x00020000
  618. /* MAC algorithms. */
  619. #define BENCH_CMAC 0x00000001
  620. #define BENCH_HMAC_MD5 0x00000002
  621. #define BENCH_HMAC_SHA 0x00000004
  622. #define BENCH_HMAC_SHA224 0x00000010
  623. #define BENCH_HMAC_SHA256 0x00000020
  624. #define BENCH_HMAC_SHA384 0x00000040
  625. #define BENCH_HMAC_SHA512 0x00000080
  626. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  627. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  628. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  629. #define BENCH_PBKDF2 0x00000100
  630. #define BENCH_SIPHASH 0x00000200
  631. /* KDF algorithms */
  632. #define BENCH_SRTP_KDF 0x00000001
  633. /* Asymmetric algorithms. */
  634. #define BENCH_RSA_KEYGEN 0x00000001
  635. #define BENCH_RSA 0x00000002
  636. #define BENCH_RSA_SZ 0x00000004
  637. #define BENCH_DH 0x00000010
  638. #define BENCH_ECC_MAKEKEY 0x00001000
  639. #define BENCH_ECC 0x00002000
  640. #define BENCH_ECC_ENCRYPT 0x00004000
  641. #define BENCH_ECC_ALL 0x00008000
  642. #define BENCH_CURVE25519_KEYGEN 0x00010000
  643. #define BENCH_CURVE25519_KA 0x00020000
  644. #define BENCH_ED25519_KEYGEN 0x00040000
  645. #define BENCH_ED25519_SIGN 0x00080000
  646. #define BENCH_CURVE448_KEYGEN 0x00100000
  647. #define BENCH_CURVE448_KA 0x00200000
  648. #define BENCH_ED448_KEYGEN 0x00400000
  649. #define BENCH_ED448_SIGN 0x00800000
  650. #define BENCH_ECC_P256 0x01000000
  651. #define BENCH_ECC_P384 0x02000000
  652. #define BENCH_ECC_P521 0x04000000
  653. #define BENCH_SM2 0x08000000
  654. #define BENCH_ECCSI_KEYGEN 0x00000020
  655. #define BENCH_ECCSI_PAIRGEN 0x00000040
  656. #define BENCH_ECCSI_VALIDATE 0x00000080
  657. #define BENCH_ECCSI 0x00000400
  658. #define BENCH_SAKKE_KEYGEN 0x10000000
  659. #define BENCH_SAKKE_RSKGEN 0x20000000
  660. #define BENCH_SAKKE_VALIDATE 0x40000000
  661. #define BENCH_SAKKE 0x80000000
  662. /* Post-Quantum Asymmetric algorithms. */
  663. #define BENCH_KYBER512 0x00000020
  664. #define BENCH_KYBER768 0x00000040
  665. #define BENCH_KYBER1024 0x00000080
  666. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  667. BENCH_KYBER1024)
  668. #define BENCH_ML_KEM_512 0x00000020
  669. #define BENCH_ML_KEM_768 0x00000040
  670. #define BENCH_ML_KEM_1024 0x00000080
  671. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  672. BENCH_ML_KEM_1024)
  673. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  674. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  675. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  676. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  677. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  678. #define BENCH_ML_DSA_44_SIGN 0x04000000
  679. #define BENCH_ML_DSA_65_SIGN 0x08000000
  680. #define BENCH_ML_DSA_87_SIGN 0x10000000
  681. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  682. BENCH_ML_DSA_65_SIGN | \
  683. BENCH_ML_DSA_87_SIGN)
  684. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  685. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  686. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  687. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  688. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  689. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  690. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  691. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  692. #define BENCH_LMS_HSS 0x00000001
  693. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  694. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  695. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  696. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  697. #ifndef NO_SHA256
  698. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  699. #elif defined(WOLFSSL_SHA512)
  700. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  701. #elif defined(WOLFSSL_SHAKE128)
  702. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  703. #elif defined(WOLFSSL_SHAKE256)
  704. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  705. #else
  706. #define BENCH_XMSS_XMSSMT 0x00000000
  707. #endif
  708. /* Other */
  709. #define BENCH_RNG 0x00000001
  710. #define BENCH_SCRYPT 0x00000002
  711. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  712. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  713. * static declaration of `bench_Usage_msg1`. */
  714. #if !defined(AES_AUTH_ADD_SZ) && \
  715. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  716. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  717. /* For STM32 use multiple of 4 to leverage crypto hardware
  718. * Xilinx Versal requires to use multiples of 16 bytes */
  719. #define AES_AUTH_ADD_SZ 16
  720. #endif
  721. #ifndef AES_AUTH_ADD_SZ
  722. #define AES_AUTH_ADD_SZ 13
  723. #endif
  724. #endif
  725. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  726. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  727. #define BENCH_PQ_STATEFUL_HBS
  728. #endif
  729. /* Benchmark all compiled in algorithms.
  730. * When 1, ignore other benchmark algorithm values.
  731. * 0, only benchmark algorithm values set.
  732. */
  733. static int bench_all = 1;
  734. /* Cipher algorithms to benchmark. */
  735. static word32 bench_cipher_algs = 0;
  736. /* Digest algorithms to benchmark. */
  737. static word32 bench_digest_algs = 0;
  738. /* MAC algorithms to benchmark. */
  739. static word32 bench_mac_algs = 0;
  740. /* KDF algorithms to benchmark. */
  741. static word32 bench_kdf_algs = 0;
  742. /* Asymmetric algorithms to benchmark. */
  743. static word32 bench_asym_algs = 0;
  744. /* Post-Quantum Asymmetric algorithms to benchmark. */
  745. static word32 bench_pq_asym_algs = 0;
  746. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  747. static word32 bench_pq_asym_algs2 = 0;
  748. /* Other cryptographic algorithms to benchmark. */
  749. static word32 bench_other_algs = 0;
  750. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  751. static word32 bench_pq_hash_sig_algs = 0;
  752. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  753. /* The mapping of command line option to bit values. */
  754. typedef struct bench_alg {
  755. /* Command line option string. */
  756. const char* str;
  757. /* Bit values to set. */
  758. word32 val;
  759. } bench_alg;
  760. #ifndef MAIN_NO_ARGS
  761. /* All recognized cipher algorithm choosing command line options. */
  762. static const bench_alg bench_cipher_opt[] = {
  763. { "-cipher", 0xffffffff },
  764. #ifdef HAVE_AES_CBC
  765. { "-aes-cbc", BENCH_AES_CBC },
  766. #endif
  767. #ifdef HAVE_AESGCM
  768. { "-aes-gcm", BENCH_AES_GCM },
  769. #endif
  770. #ifdef WOLFSSL_AES_DIRECT
  771. { "-aes-ecb", BENCH_AES_ECB },
  772. #endif
  773. #ifdef WOLFSSL_AES_XTS
  774. { "-aes-xts", BENCH_AES_XTS },
  775. #endif
  776. #ifdef WOLFSSL_AES_CFB
  777. { "-aes-cfb", BENCH_AES_CFB },
  778. #endif
  779. #ifdef WOLFSSL_AES_OFB
  780. { "-aes-ofb", BENCH_AES_OFB },
  781. #endif
  782. #ifdef WOLFSSL_AES_COUNTER
  783. { "-aes-ctr", BENCH_AES_CTR },
  784. #endif
  785. #ifdef HAVE_AESCCM
  786. { "-aes-ccm", BENCH_AES_CCM },
  787. #endif
  788. #ifdef WOLFSSL_AES_SIV
  789. { "-aes-siv", BENCH_AES_SIV },
  790. #endif
  791. #ifdef HAVE_CAMELLIA
  792. { "-camellia", BENCH_CAMELLIA },
  793. #endif
  794. #ifndef NO_RC4
  795. { "-arc4", BENCH_ARC4 },
  796. #endif
  797. #ifdef HAVE_CHACHA
  798. { "-chacha20", BENCH_CHACHA20 },
  799. #endif
  800. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  801. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  802. #endif
  803. #ifdef WOLFSSL_SM4_CBC
  804. { "-sm4-cbc", BENCH_SM4_CBC },
  805. #endif
  806. #ifdef WOLFSSL_SM4_GCM
  807. { "-sm4-gcm", BENCH_SM4_GCM },
  808. #endif
  809. #ifdef WOLFSSL_SM4_CCM
  810. { "-sm4-ccm", BENCH_SM4_CCM },
  811. #endif
  812. #ifdef WOLFSSL_SM4
  813. { "-sm4", BENCH_SM4 },
  814. #endif
  815. #ifndef NO_DES3
  816. { "-des", BENCH_DES },
  817. #endif
  818. { NULL, 0 }
  819. };
  820. /* All recognized digest algorithm choosing command line options. */
  821. static const bench_alg bench_digest_opt[] = {
  822. { "-digest", 0xffffffff },
  823. #ifndef NO_MD5
  824. { "-md5", BENCH_MD5 },
  825. #endif
  826. #ifdef HAVE_POLY1305
  827. { "-poly1305", BENCH_POLY1305 },
  828. #endif
  829. #ifndef NO_SHA
  830. { "-sha", BENCH_SHA },
  831. #endif
  832. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  833. || defined(WOLFSSL_SHA512)
  834. { "-sha2", BENCH_SHA2 },
  835. #endif
  836. #ifdef WOLFSSL_SHA224
  837. { "-sha224", BENCH_SHA224 },
  838. #endif
  839. #ifndef NO_SHA256
  840. { "-sha256", BENCH_SHA256 },
  841. #endif
  842. #ifdef WOLFSSL_SHA384
  843. { "-sha384", BENCH_SHA384 },
  844. #endif
  845. #ifdef WOLFSSL_SHA512
  846. { "-sha512", BENCH_SHA512 },
  847. #endif
  848. #ifdef WOLFSSL_SHA3
  849. { "-sha3", BENCH_SHA3 },
  850. #ifndef WOLFSSL_NOSHA3_224
  851. { "-sha3-224", BENCH_SHA3_224 },
  852. #endif
  853. #ifndef WOLFSSL_NOSHA3_256
  854. { "-sha3-256", BENCH_SHA3_256 },
  855. #endif
  856. #ifndef WOLFSSL_NOSHA3_384
  857. { "-sha3-384", BENCH_SHA3_384 },
  858. #endif
  859. #ifndef WOLFSSL_NOSHA3_512
  860. { "-sha3-512", BENCH_SHA3_512 },
  861. #endif
  862. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  863. { "-shake", BENCH_SHAKE },
  864. #endif
  865. #ifdef WOLFSSL_SHAKE128
  866. { "-shake128", BENCH_SHAKE128 },
  867. #endif
  868. #ifdef WOLFSSL_SHAKE256
  869. { "-shake256", BENCH_SHAKE256 },
  870. #endif
  871. #endif
  872. #ifdef WOLFSSL_SM3
  873. { "-sm3", BENCH_SM3 },
  874. #endif
  875. #ifdef WOLFSSL_RIPEMD
  876. { "-ripemd", BENCH_RIPEMD },
  877. #endif
  878. #ifdef HAVE_BLAKE2
  879. { "-blake2b", BENCH_BLAKE2B },
  880. #endif
  881. #ifdef HAVE_BLAKE2S
  882. { "-blake2s", BENCH_BLAKE2S },
  883. #endif
  884. { NULL, 0 }
  885. };
  886. /* All recognized MAC algorithm choosing command line options. */
  887. static const bench_alg bench_mac_opt[] = {
  888. { "-mac", 0xffffffff },
  889. #ifdef WOLFSSL_CMAC
  890. { "-cmac", BENCH_CMAC },
  891. #endif
  892. #ifndef NO_HMAC
  893. { "-hmac", BENCH_HMAC },
  894. #ifndef NO_MD5
  895. { "-hmac-md5", BENCH_HMAC_MD5 },
  896. #endif
  897. #ifndef NO_SHA
  898. { "-hmac-sha", BENCH_HMAC_SHA },
  899. #endif
  900. #ifdef WOLFSSL_SHA224
  901. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  902. #endif
  903. #ifndef NO_SHA256
  904. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  905. #endif
  906. #ifdef WOLFSSL_SHA384
  907. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  908. #endif
  909. #ifdef WOLFSSL_SHA512
  910. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  911. #endif
  912. #ifndef NO_PWDBASED
  913. { "-pbkdf2", BENCH_PBKDF2 },
  914. #endif
  915. #endif
  916. #ifdef WOLFSSL_SIPHASH
  917. { "-siphash", BENCH_SIPHASH },
  918. #endif
  919. { NULL, 0 }
  920. };
  921. /* All recognized KDF algorithm choosing command line options. */
  922. static const bench_alg bench_kdf_opt[] = {
  923. { "-kdf", 0xffffffff },
  924. #ifdef WC_SRTP_KDF
  925. { "-srtp-kdf", BENCH_SRTP_KDF },
  926. #endif
  927. { NULL, 0 }
  928. };
  929. /* All recognized asymmetric algorithm choosing command line options. */
  930. static const bench_alg bench_asym_opt[] = {
  931. { "-asym", 0xffffffff },
  932. #ifndef NO_RSA
  933. #ifdef WOLFSSL_KEY_GEN
  934. { "-rsa-kg", BENCH_RSA_KEYGEN },
  935. #endif
  936. { "-rsa", BENCH_RSA },
  937. #ifdef WOLFSSL_KEY_GEN
  938. { "-rsa-sz", BENCH_RSA_SZ },
  939. #endif
  940. #endif
  941. #ifndef NO_DH
  942. { "-dh", BENCH_DH },
  943. #endif
  944. #ifdef HAVE_ECC
  945. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  946. { "-ecc", BENCH_ECC },
  947. #ifdef HAVE_ECC_ENCRYPT
  948. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  949. #endif
  950. { "-ecc-all", BENCH_ECC_ALL },
  951. #endif
  952. #ifdef WOLFSSL_SM2
  953. { "-sm2", BENCH_SM2 },
  954. #endif
  955. #ifdef HAVE_CURVE25519
  956. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  957. #ifdef HAVE_CURVE25519_SHARED_SECRET
  958. { "-x25519", BENCH_CURVE25519_KA },
  959. #endif
  960. #endif
  961. #ifdef HAVE_ED25519
  962. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  963. { "-ed25519", BENCH_ED25519_SIGN },
  964. #endif
  965. #ifdef HAVE_CURVE448
  966. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  967. #ifdef HAVE_CURVE448_SHARED_SECRET
  968. { "-x448", BENCH_CURVE448_KA },
  969. #endif
  970. #endif
  971. #ifdef HAVE_ED448
  972. { "-ed448-kg", BENCH_ED448_KEYGEN },
  973. { "-ed448", BENCH_ED448_SIGN },
  974. #endif
  975. #ifdef WOLFCRYPT_HAVE_ECCSI
  976. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  977. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  978. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  979. { "-eccsi", BENCH_ECCSI },
  980. #endif
  981. #ifdef WOLFCRYPT_HAVE_SAKKE
  982. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  983. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  984. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  985. { "-sakke", BENCH_SAKKE },
  986. #endif
  987. { NULL, 0 }
  988. };
  989. /* All recognized other cryptographic algorithm choosing command line options.
  990. */
  991. static const bench_alg bench_other_opt[] = {
  992. { "-other", 0xffffffff },
  993. #ifndef WC_NO_RNG
  994. { "-rng", BENCH_RNG },
  995. #endif
  996. #ifdef HAVE_SCRYPT
  997. { "-scrypt", BENCH_SCRYPT },
  998. #endif
  999. { NULL, 0}
  1000. };
  1001. #endif /* MAIN_NO_ARGS */
  1002. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1003. #if defined(BENCH_PQ_STATEFUL_HBS)
  1004. typedef struct bench_pq_hash_sig_alg {
  1005. /* Command line option string. */
  1006. const char* str;
  1007. /* Bit values to set. */
  1008. word32 val;
  1009. } bench_pq_hash_sig_alg;
  1010. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1011. { "-pq_hash_sig", 0xffffffff},
  1012. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1013. { "-lms_hss", BENCH_LMS_HSS},
  1014. #endif
  1015. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1016. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1017. #ifdef WC_XMSS_SHA256
  1018. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1019. #endif
  1020. #ifdef WC_XMSS_SHA512
  1021. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1022. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1023. #endif
  1024. #endif
  1025. #ifdef WC_XMSS_SHAKE128
  1026. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1027. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1028. #endif
  1029. #endif
  1030. #ifdef WC_XMSS_SHAKE256
  1031. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1032. #endif
  1033. #endif
  1034. { NULL, 0}
  1035. };
  1036. #endif /* BENCH_PQ_STATEFUL_HBS */
  1037. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1038. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1039. /* The post-quantum-specific mapping of command line option to bit values and
  1040. * OQS name. */
  1041. typedef struct bench_pq_alg {
  1042. /* Command line option string. */
  1043. const char* str;
  1044. /* Bit values to set. */
  1045. word32 val;
  1046. } bench_pq_alg;
  1047. /* All recognized post-quantum asymmetric algorithm choosing command line
  1048. * options. */
  1049. static const bench_pq_alg bench_pq_asym_opt[] = {
  1050. { "-pq", 0xffffffff },
  1051. #ifdef WOLFSSL_HAVE_KYBER
  1052. { "-kyber", BENCH_KYBER },
  1053. { "-kyber512", BENCH_KYBER512 },
  1054. { "-kyber768", BENCH_KYBER768 },
  1055. { "-kyber1024", BENCH_KYBER1024 },
  1056. { "-ml-kem", BENCH_ML_KEM },
  1057. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1058. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1059. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1060. #endif
  1061. #if defined(HAVE_FALCON)
  1062. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1063. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1064. #endif
  1065. #if defined(HAVE_DILITHIUM)
  1066. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1067. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1068. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1069. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1070. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1071. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1072. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1073. #endif
  1074. { NULL, 0 }
  1075. };
  1076. #if defined(HAVE_SPHINCS)
  1077. /* All recognized post-quantum asymmetric algorithm choosing command line
  1078. * options. (Part 2) */
  1079. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1080. { "-pq", 0xffffffff },
  1081. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1082. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1083. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1084. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1085. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1086. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1087. { NULL, 0, }
  1088. };
  1089. #endif /* HAVE_SPHINCS */
  1090. #endif
  1091. #ifdef HAVE_WNR
  1092. const char* wnrConfigFile = "wnr-example.conf";
  1093. #endif
  1094. #if defined(WOLFSSL_MDK_ARM)
  1095. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1096. #define fopen wolfSSL_fopen
  1097. #endif
  1098. static int lng_index = 0;
  1099. #ifndef NO_MAIN_DRIVER
  1100. #ifndef MAIN_NO_ARGS
  1101. static const char* bench_Usage_msg1[][25] = {
  1102. /* 0 English */
  1103. { "-? <num> Help, print this usage\n",
  1104. " 0: English, 1: Japanese\n",
  1105. "-csv Print terminal output in csv format\n",
  1106. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1107. "-no_aad No additional authentication data passed.\n",
  1108. "-aad_size <num> With <num> bytes of AAD.\n",
  1109. ("-all_aad With AAD length of 0, "
  1110. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1111. " and\n"
  1112. " (if set via -aad_size) <aad_size> bytes.\n"
  1113. ),
  1114. "-dgst_full Full digest operation performed.\n",
  1115. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1116. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1117. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1118. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1119. "-p256 Measure ECC using P-256 curve.\n",
  1120. "-p384 Measure ECC using P-384 curve.\n",
  1121. "-p521 Measure ECC using P-521 curve.\n",
  1122. "-ecc-all Bench all enabled ECC curves.\n",
  1123. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1124. ("-lng <num> Display benchmark result by specified language.\n"
  1125. " 0: English, 1: Japanese\n"
  1126. ),
  1127. "<num> Size of block in bytes\n",
  1128. ("-blocks <num> Number of blocks. Can be used together with the "
  1129. "'Size of block'\n"
  1130. " option, but must be used after that one.\n"
  1131. ),
  1132. "-threads <num> Number of threads to run\n",
  1133. "-print Show benchmark stats summary\n",
  1134. "-hash_input <file> Input data to use for hash benchmarking\n",
  1135. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1136. "-min_runs <num> Specify minimum number of operation runs\n"
  1137. },
  1138. #ifndef NO_MULTIBYTE_PRINT
  1139. /* 1 Japanese */
  1140. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1141. " 0: 英語、 1: 日本語\n",
  1142. "-csv csv 形式で端末に出力します。\n",
  1143. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1144. "-no_aad 追加の認証データを使用しません.\n",
  1145. "-aad_size <num> TBD.\n",
  1146. "-all_aad TBD.\n",
  1147. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1148. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1149. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1150. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1151. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1152. "-p256 Measure ECC using P-256 curve.\n",
  1153. "-p384 Measure ECC using P-384 curve.\n",
  1154. "-p521 Measure ECC using P-521 curve.\n",
  1155. "-ecc-all Bench all enabled ECC curves.\n",
  1156. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1157. " 利用可能なアルゴリズムは下記を含みます:\n"
  1158. ),
  1159. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1160. " 0: 英語、 1: 日本語\n"
  1161. ),
  1162. "<num> ブロックサイズをバイト単位で指定します。\n",
  1163. "-blocks <num> TBD.\n",
  1164. "-threads <num> 実行するスレッド数\n",
  1165. "-print ベンチマーク統計の要約を表示する\n",
  1166. /* TODO: translate below */
  1167. "-hash_input <file> Input data to use for hash benchmarking\n",
  1168. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1169. "-min_runs <num> Specify minimum number of operation runs\n"
  1170. },
  1171. #endif
  1172. };
  1173. #endif /* MAIN_NO_ARGS */
  1174. #endif
  1175. static const char* bench_result_words1[][4] = {
  1176. { "took",
  1177. #ifdef BENCH_MICROSECOND
  1178. "microseconds"
  1179. #else
  1180. "seconds"
  1181. #endif
  1182. , "Cycles per byte", NULL }, /* 0 English */
  1183. #ifndef NO_MULTIBYTE_PRINT
  1184. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1185. #endif
  1186. };
  1187. #if !defined(NO_RSA) || \
  1188. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1189. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1190. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1191. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1192. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1193. static const char* bench_desc_words[][15] = {
  1194. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1195. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1196. #ifndef NO_MULTIBYTE_PRINT
  1197. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1198. #endif
  1199. };
  1200. #endif
  1201. #ifdef MULTI_VALUE_STATISTICS
  1202. static const char* bench_result_words3[][5] = {
  1203. /* 0 English */
  1204. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1205. /* TODO: Add japenese version */
  1206. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1207. };
  1208. #endif
  1209. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1210. #define HAVE_GET_CYCLES
  1211. static WC_INLINE word64 get_intel_cycles(void);
  1212. static THREAD_LS_T word64 total_cycles;
  1213. #define INIT_CYCLE_COUNTER
  1214. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1215. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1216. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1217. #define SHOW_INTEL_CYCLES(b, n, s) \
  1218. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1219. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1220. bench_result_words1[lng_index][2], \
  1221. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1222. (double)total_cycles / ((word64)count*(s))))
  1223. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1224. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1225. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1226. (double)total_cycles / ((word64)count*(s))))
  1227. #elif defined(LINUX_CYCLE_COUNT)
  1228. #include <linux/perf_event.h>
  1229. #include <sys/syscall.h>
  1230. #include <unistd.h>
  1231. static THREAD_LS_T word64 begin_cycles;
  1232. static THREAD_LS_T word64 total_cycles;
  1233. static THREAD_LS_T int cycles = -1;
  1234. static THREAD_LS_T struct perf_event_attr atr;
  1235. #define INIT_CYCLE_COUNTER do { \
  1236. atr.type = PERF_TYPE_HARDWARE; \
  1237. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1238. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1239. } while (0);
  1240. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1241. #define END_INTEL_CYCLES do { \
  1242. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1243. total_cycles = total_cycles - begin_cycles; \
  1244. } while (0);
  1245. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1246. #define SHOW_INTEL_CYCLES(b, n, s) \
  1247. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1248. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1249. bench_result_words1[lng_index][2], \
  1250. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1251. (count*s)))
  1252. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1253. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1254. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1255. / (count*s)))
  1256. #elif defined(SYNERGY_CYCLE_COUNT)
  1257. #include "hal_data.h"
  1258. static THREAD_LS_T word64 begin_cycles;
  1259. static THREAD_LS_T word64 total_cycles;
  1260. #define INIT_CYCLE_COUNTER
  1261. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1262. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1263. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1264. #define SHOW_INTEL_CYCLES(b, n, s) \
  1265. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1266. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1267. bench_result_words1[lng_index][2], \
  1268. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1269. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1270. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1271. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1272. #elif defined(WOLFSSL_ESPIDF)
  1273. /* TAG for ESP_LOGx() */
  1274. static const char* TAG = "wolfssl_benchmark";
  1275. static THREAD_LS_T word64 begin_cycles = 0;
  1276. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1277. static THREAD_LS_T word64 end_cycles = 0;
  1278. static THREAD_LS_T word64 total_cycles = 0;
  1279. /* the return value, as a global var */
  1280. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1281. /* the last value seen, adjusted for an overflow, as a global var */
  1282. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1283. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1284. /* esp_get_cpu_benchmark_cycles(void):
  1285. *
  1286. * Architecture-independant CPU clock counter.
  1287. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1288. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1289. /* Some vars for debugging, compare ticks to cycles */
  1290. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1291. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1292. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1293. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1294. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1295. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1296. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1297. #if ESP_IDF_VERSION_MAJOR >= 5
  1298. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1299. #define HAVE_GET_CYCLES
  1300. #define INIT_CYCLE_COUNTER do { \
  1301. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1302. esp_cpu_set_cycle_count(0); \
  1303. } while (0);
  1304. #else
  1305. #define HAVE_GET_CYCLES
  1306. #define INIT_CYCLE_COUNTER do { \
  1307. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1308. } while (0);
  1309. #endif
  1310. #define BEGIN_ESP_CYCLES do { \
  1311. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1312. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1313. begin_cycles_ticks = xTaskGetTickCount(); \
  1314. } while (0);
  1315. /* since it rolls over, we have something that will tolerate one */
  1316. #define END_ESP_CYCLES \
  1317. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1318. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1319. end_cycles, \
  1320. begin_cycles \
  1321. ); \
  1322. total_cycles = (end_cycles - begin_cycles);
  1323. #define SHOW_ESP_CYCLES(b, n, s) \
  1324. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1325. " %s = " FLT_FMT_PREC2 "\n", \
  1326. bench_result_words1[lng_index][2], \
  1327. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1328. )
  1329. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1330. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1331. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1332. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1333. /* 64 bit, unisgned, absolute difference
  1334. * used in CPU cycle counter debug calcs. */
  1335. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1336. {
  1337. uint64_t ret;
  1338. ret = (x > y) ? (x - y) : (y - x);
  1339. return ret;
  1340. }
  1341. #endif
  1342. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1343. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1344. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1345. ** at least once during full benchmark tests.
  1346. **
  1347. ** To test timing overflow, add a delay longer than max cycles:
  1348. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1349. */
  1350. uint64_t esp_get_cycle_count_ex()
  1351. {
  1352. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1353. /* unsigned int max = 4,294,967,295 */
  1354. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1355. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1356. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1357. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1358. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1359. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1360. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1361. #endif
  1362. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1363. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1364. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1365. * (current - last) */
  1366. #endif
  1367. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1368. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1369. defined(CONFIG_IDF_TARGET_ESP32C6)
  1370. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1371. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1372. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1373. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1374. #if ESP_IDF_VERSION_MAJOR >= 5
  1375. thisVal = esp_cpu_get_cycle_count();
  1376. #else
  1377. thisVal = cpu_hal_get_cycle_count();
  1378. #endif
  1379. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1380. thisVal = esp_cpu_get_cycle_count();
  1381. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1382. thisVal = esp_timer_get_time();
  1383. #else
  1384. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1385. * Calling current_time(1) to reset time causes thisVal overflow,
  1386. * on Xtensa, but not on RISC-V architecture. See also, below */
  1387. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1388. #ifndef configCPU_CLOCK_HZ
  1389. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1390. #define configCPU_CLOCK_HZ \
  1391. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1392. #endif
  1393. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1394. thisVal = (uint64_t)xTaskGetTickCount() *
  1395. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1396. #elif defined(__XTENSA__)
  1397. thisVal = esp_cpu_get_cycle_count();
  1398. #else
  1399. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1400. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1401. #endif
  1402. #endif
  1403. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1404. {
  1405. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1406. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1407. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1408. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1409. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1410. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1411. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1412. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1413. }
  1414. #endif
  1415. /* If either thisVal is smaller than last (overflow), and/or the
  1416. * expected value calculated from FreeRTOS tick difference that would
  1417. * have never fit into an unsigned 32 bit integer anyhow... then we
  1418. * need to adjust thisVal to save. */
  1419. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1420. {
  1421. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1422. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1423. **
  1424. ** NOTE for long duration between calls with multiple overflows:
  1425. **
  1426. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1427. **
  1428. ** At this time no single test overflows. This is currently only a
  1429. ** concern for cumulative counts over multiple tests. As long
  1430. ** as well call xthal_get_ccount_ex() with no more than one
  1431. ** overflow CPU tick count, all will be well.
  1432. */
  1433. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1434. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1435. "(%llu < %llu) adding UINT_MAX = %llu.",
  1436. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1437. #endif
  1438. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1439. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1440. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1441. #endif
  1442. /* double check expected diff calc */
  1443. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1444. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1445. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1446. * MILLION_VALUE)
  1447. * tickDiff / configTICK_RATE_HZ;
  1448. #else
  1449. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1450. * tickDiff / configTICK_RATE_HZ;
  1451. #endif
  1452. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1453. #endif
  1454. if (expected_diff > UINT_MAX) {
  1455. /* The number of cycles expected from FreeRTOS ticks is
  1456. * greater than the maximum size of an unsigned 32-bit
  1457. * integer, meaning multiple overflows occurred. */
  1458. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1459. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1460. #endif
  1461. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1462. }
  1463. else {
  1464. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1465. }
  1466. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1467. {
  1468. tickBeginDiff = tickCount - begin_cycles_ticks;
  1469. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1470. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1471. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1472. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1473. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1474. }
  1475. #endif
  1476. }
  1477. else {
  1478. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1479. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1480. #endif
  1481. } /* if thisVal adjustment check */
  1482. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1483. if (thisTimerVal < _esp_cpu_timer_last)
  1484. {
  1485. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1486. "adding %ull", UINT_MAX);
  1487. thisTimerVal += (word64)UINT_MAX;
  1488. }
  1489. /* Check an alternate counter using a timer */
  1490. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1491. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1492. /* Adjust our actual returned value that takes into account overflow,
  1493. * increment 64 bit extended total by this 32 bit differential: */
  1494. thisIncrement = (thisVal - _esp_cpu_count_last);
  1495. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1496. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1497. #endif
  1498. /* Add our adjustment, taking into account overflows (see above) */
  1499. _esp_get_cycle_count_ex += thisIncrement;
  1500. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1501. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1502. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1503. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1504. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1505. /* all of this took some time, so reset the "last seen" value
  1506. * for the next measurement. */
  1507. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1508. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1509. defined(CONFIG_IDF_TARGET_ESP32C6)
  1510. {
  1511. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1512. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1513. &_esp_cpu_timer_last));
  1514. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1515. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1516. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1517. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1518. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1519. #if ESP_IDF_VERSION_MAJOR >= 5
  1520. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1521. #else
  1522. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1523. #endif
  1524. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1525. }
  1526. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1527. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1528. #else
  1529. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1530. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1531. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1532. * or thisVal = xthal_get_ccount(); */
  1533. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1534. /* There's no CPU counter on the ESP8266, so we'll estimate
  1535. * cycles based on defined CPU frequency from sdkconfig and
  1536. * the RTOS tick frequency */
  1537. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1538. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1539. #elif ESP_IDF_VERSION_MAJOR < 5
  1540. _esp_cpu_count_last = xthal_get_ccount();
  1541. #else
  1542. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1543. #endif
  1544. #endif
  1545. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1546. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1547. #endif
  1548. /* Return the 64 bit extended total from 32 bit counter. */
  1549. return _esp_get_cycle_count_ex;
  1550. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1551. /* implement other architecture cycle counters here */
  1552. #else
  1553. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1554. #undef HAVE_GET_CYCLES
  1555. #define INIT_CYCLE_COUNTER
  1556. #define BEGIN_INTEL_CYCLES
  1557. #define END_INTEL_CYCLES
  1558. #ifdef MULTI_VALUE_STATISTICS
  1559. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1560. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1561. #else
  1562. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1563. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1564. #endif
  1565. #endif
  1566. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1567. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1568. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1569. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1570. #endif
  1571. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1572. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1573. !defined(NO_DH)
  1574. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1575. #include <wolfssl/certs_test.h>
  1576. #endif
  1577. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1578. #include <wolfssl/wolfcrypt/blake2.h>
  1579. #endif
  1580. #ifdef _MSC_VER
  1581. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1582. #pragma warning(disable: 4996)
  1583. #endif
  1584. #ifdef WOLFSSL_CURRTIME_REMAP
  1585. #define current_time WOLFSSL_CURRTIME_REMAP
  1586. #else
  1587. double current_time(int reset);
  1588. #endif
  1589. #ifdef LINUX_RUSAGE_UTIME
  1590. static void check_for_excessive_stime(const char *desc,
  1591. const char *desc_extra);
  1592. #endif
  1593. #if !defined(WC_NO_RNG) && \
  1594. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1595. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1596. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1597. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1598. || defined(WOLFSSL_HAVE_KYBER))
  1599. #define HAVE_LOCAL_RNG
  1600. static THREAD_LS_T WC_RNG gRng;
  1601. #define GLOBAL_RNG &gRng
  1602. #else
  1603. #define GLOBAL_RNG NULL
  1604. #endif
  1605. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1606. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1607. defined(HAVE_ECC) || !defined(NO_DH) || \
  1608. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1609. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1610. defined(WOLFSSL_HAVE_LMS)
  1611. #define BENCH_ASYM
  1612. #endif
  1613. #if defined(BENCH_ASYM)
  1614. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1615. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1616. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1617. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1618. defined(WOLFSSL_HAVE_LMS)
  1619. static const char* bench_result_words2[][5] = {
  1620. #ifdef BENCH_MICROSECOND
  1621. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1622. for μsec */
  1623. #else
  1624. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1625. #endif
  1626. #ifndef NO_MULTIBYTE_PRINT
  1627. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1628. #endif
  1629. };
  1630. #endif
  1631. #endif
  1632. #ifdef WOLFSSL_CAAM
  1633. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1634. #ifdef WOLFSSL_SECO_CAAM
  1635. #define SECO_MAX_UPDATES 10000
  1636. #define SECO_BENCHMARK_NONCE 0x7777
  1637. #define SECO_KEY_STORE_ID 1
  1638. #endif
  1639. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1640. #else
  1641. #ifdef WC_USE_DEVID
  1642. static THREAD_LS_T int devId = WC_USE_DEVID;
  1643. #else
  1644. static THREAD_LS_T int devId = INVALID_DEVID;
  1645. #endif
  1646. #endif
  1647. /* Asynchronous helper macros */
  1648. #ifdef WC_ENABLE_BENCH_THREADING
  1649. typedef struct ThreadData {
  1650. pthread_t thread_id;
  1651. } ThreadData;
  1652. static ThreadData* g_threadData;
  1653. static volatile int g_threadCount;
  1654. #endif
  1655. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1656. #ifndef NO_HW_BENCH
  1657. #define BENCH_DEVID
  1658. #endif
  1659. #ifndef HAVE_RENESAS_SYNC
  1660. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1661. #else
  1662. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1663. #endif
  1664. #else
  1665. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1666. #endif
  1667. #ifdef WOLFSSL_ASYNC_CRYPT
  1668. static WOLF_EVENT_QUEUE eventQueue;
  1669. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1670. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1671. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1672. int callAgain, int* times, int limit, int* pending)
  1673. {
  1674. int allowNext = 0;
  1675. /* this state can be set from a different thread */
  1676. WOLF_EVENT_STATE state = asyncDev->event.state;
  1677. /* if algo doesn't require calling again then use this flow */
  1678. if (state == WOLF_EVENT_STATE_DONE) {
  1679. if (callAgain) {
  1680. /* needs called again, so allow it and handle completion in
  1681. * bench_async_handle */
  1682. allowNext = 1;
  1683. }
  1684. else {
  1685. *ret = asyncDev->event.ret;
  1686. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1687. (*times)++;
  1688. if (*pending > 0) /* to support case where async blocks */
  1689. (*pending)--;
  1690. if ((*times + *pending) < limit)
  1691. allowNext = 1;
  1692. }
  1693. }
  1694. /* if slot is available and we haven't reached limit, start another */
  1695. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1696. allowNext = 1;
  1697. }
  1698. return allowNext;
  1699. }
  1700. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1701. int callAgain, int* times, int* pending)
  1702. {
  1703. WOLF_EVENT_STATE state = asyncDev->event.state;
  1704. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1705. if (state == WOLF_EVENT_STATE_DONE) {
  1706. *ret = asyncDev->event.ret;
  1707. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1708. (*times)++;
  1709. (*pending)--;
  1710. }
  1711. else {
  1712. (*pending)++;
  1713. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1714. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1715. }
  1716. }
  1717. else if (*ret >= 0) {
  1718. *ret = asyncDev->event.ret;
  1719. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1720. (*times)++;
  1721. if (*pending > 0) /* to support case where async blocks */
  1722. (*pending)--;
  1723. }
  1724. return (*ret >= 0) ? 1 : 0;
  1725. }
  1726. static WC_INLINE int bench_async_poll(int* pending)
  1727. {
  1728. int ret, asyncDone = 0;
  1729. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1730. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1731. if (ret != 0) {
  1732. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1733. return ret;
  1734. }
  1735. if (asyncDone == 0) {
  1736. #ifndef WC_NO_ASYNC_THREADING
  1737. /* give time to other threads */
  1738. wc_AsyncThreadYield();
  1739. #endif
  1740. }
  1741. (void)pending;
  1742. return asyncDone;
  1743. }
  1744. #else
  1745. #define BENCH_MAX_PENDING 1
  1746. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1747. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1748. int callAgain, int* times, int limit, int* pending)
  1749. {
  1750. (void)ret;
  1751. (void)asyncDev;
  1752. (void)callAgain;
  1753. (void)times;
  1754. (void)limit;
  1755. (void)pending;
  1756. return 1;
  1757. }
  1758. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1759. int callAgain, int* times, int* pending)
  1760. {
  1761. (void)asyncDev;
  1762. (void)callAgain;
  1763. (void)pending;
  1764. if (*ret >= 0) {
  1765. /* operation completed */
  1766. (*times)++;
  1767. return 1;
  1768. }
  1769. return 0;
  1770. }
  1771. #define bench_async_poll(p) WC_DO_NOTHING
  1772. #endif /* WOLFSSL_ASYNC_CRYPT */
  1773. /* maximum runtime for each benchmark */
  1774. #ifndef BENCH_MIN_RUNTIME_SEC
  1775. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1776. #endif
  1777. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1778. #define AES_AUTH_TAG_SZ 16
  1779. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1780. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1781. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1782. #if !defined(NO_MAIN_DRIVER)
  1783. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1784. #else
  1785. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1786. #endif
  1787. #endif
  1788. #define AES_AAD_STRING(s) \
  1789. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1790. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1791. enum en_aad_options {
  1792. AAD_SIZE_DEFAULT = 0x1U,
  1793. AAD_SIZE_ZERO = 0x2U,
  1794. AAD_SIZE_CUSTOM = 0x4U,
  1795. };
  1796. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1797. static word32 aes_aad_size = 0;
  1798. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1799. {
  1800. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1801. word32 options = aes_aad_options;
  1802. while(options) {
  1803. if (options & AAD_SIZE_DEFAULT) {
  1804. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1805. options &= ~(word32)AAD_SIZE_DEFAULT;
  1806. }
  1807. else if (options & AAD_SIZE_ZERO) {
  1808. aesAuthAddSz = 0;
  1809. options &= ~(word32)AAD_SIZE_ZERO;
  1810. }
  1811. else if (options & AAD_SIZE_CUSTOM) {
  1812. aesAuthAddSz = aes_aad_size;
  1813. options &= ~(word32)AAD_SIZE_CUSTOM;
  1814. }
  1815. fn(i);
  1816. aesAuthAddSz = aesAuthAddSz_orig;
  1817. }
  1818. }
  1819. #endif
  1820. #ifndef BENCH_CIPHER_ADD
  1821. #define BENCH_CIPHER_ADD 0
  1822. #endif
  1823. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  1824. #warning Large/Unalligned AuthSz could result in errors with /dev/crypto
  1825. #endif
  1826. /* use kB instead of mB for embedded benchmarking */
  1827. #ifdef BENCH_EMBEDDED
  1828. #ifndef BENCH_NTIMES
  1829. #define BENCH_NTIMES 2
  1830. #endif
  1831. #ifndef BENCH_AGREETIMES
  1832. #define BENCH_AGREETIMES 2
  1833. #endif
  1834. enum BenchmarkBounds {
  1835. scryptCnt = 1,
  1836. ntimes = BENCH_NTIMES,
  1837. genTimes = BENCH_MAX_PENDING,
  1838. agreeTimes = BENCH_AGREETIMES
  1839. };
  1840. /* how many kB to test (en/de)cryption */
  1841. #define NUM_BLOCKS 25
  1842. #define BENCH_SIZE (1024uL)
  1843. #else
  1844. #ifndef BENCH_NTIMES
  1845. #define BENCH_NTIMES 100
  1846. #endif
  1847. #ifndef BENCH_AGREETIMES
  1848. #define BENCH_AGREETIMES 100
  1849. #endif
  1850. enum BenchmarkBounds {
  1851. scryptCnt = 10,
  1852. ntimes = BENCH_NTIMES,
  1853. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1854. agreeTimes = BENCH_AGREETIMES
  1855. };
  1856. /* how many megs to test (en/de)cryption */
  1857. #define NUM_BLOCKS 5
  1858. #define BENCH_SIZE (1024*1024uL)
  1859. #endif
  1860. static int numBlocks = NUM_BLOCKS;
  1861. static word32 bench_size = BENCH_SIZE;
  1862. static int base2 = 1;
  1863. static int digest_stream = 1;
  1864. #ifdef HAVE_CHACHA
  1865. static int encrypt_only = 0;
  1866. #endif
  1867. #ifdef HAVE_AES_CBC
  1868. static int cipher_same_buffer = 0;
  1869. #endif
  1870. #ifdef MULTI_VALUE_STATISTICS
  1871. static int minimum_runs = 0;
  1872. #endif
  1873. #ifndef NO_RSA
  1874. /* Don't measure RSA sign/verify by default */
  1875. static int rsa_sign_verify = 0;
  1876. #endif
  1877. #ifndef NO_DH
  1878. /* Use the FFDHE parameters */
  1879. static int use_ffdhe = 0;
  1880. #endif
  1881. /* Don't print out in CSV format by default */
  1882. static int csv_format = 0;
  1883. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1884. /* Versal PLM maybe prints an error message to the same console.
  1885. * In order to not mix those outputs up, sleep a little while
  1886. * before erroring out.
  1887. */
  1888. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1889. #else
  1890. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1891. #endif
  1892. /* globals for cipher tests */
  1893. static THREAD_LS_T byte* bench_plain = NULL;
  1894. static THREAD_LS_T byte* bench_cipher = NULL;
  1895. #ifndef NO_FILESYSTEM
  1896. static THREAD_LS_T char* hash_input = NULL;
  1897. static THREAD_LS_T char* cipher_input = NULL;
  1898. #endif
  1899. static const XGEN_ALIGN byte bench_key_buf[] =
  1900. {
  1901. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1902. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1903. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1904. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1905. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1906. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1907. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1908. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1909. };
  1910. static const XGEN_ALIGN byte bench_iv_buf[] =
  1911. {
  1912. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1913. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1914. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1915. };
  1916. static THREAD_LS_T byte* bench_key = NULL;
  1917. static THREAD_LS_T byte* bench_iv = NULL;
  1918. #ifdef HAVE_RENESAS_SYNC
  1919. static THREAD_LS_T byte* bench_key1 = NULL;
  1920. static THREAD_LS_T byte* bench_key2 = NULL;
  1921. #endif
  1922. #ifdef WOLFSSL_STATIC_MEMORY
  1923. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1924. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1925. #elif defined(BENCH_EMBEDDED)
  1926. static byte gBenchMemory[50000];
  1927. #else
  1928. static byte gBenchMemory[400000];
  1929. #endif
  1930. #endif
  1931. /* This code handles cases with systems where static (non cost) ram variables
  1932. aren't properly initialized with data */
  1933. static void benchmark_static_init(int force)
  1934. {
  1935. static int gBenchStaticInit = 0;
  1936. if (gBenchStaticInit == 0 || force) {
  1937. gBenchStaticInit = 1;
  1938. /* Init static variables */
  1939. numBlocks = NUM_BLOCKS;
  1940. bench_size = BENCH_SIZE;
  1941. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1942. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1943. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1944. aes_aad_size = 0;
  1945. #endif
  1946. base2 = 1;
  1947. digest_stream = 1;
  1948. #ifdef MULTI_VALUE_STATISTICS
  1949. minimum_runs = 0;
  1950. #endif
  1951. bench_all = 1;
  1952. bench_cipher_algs = 0;
  1953. bench_digest_algs = 0;
  1954. bench_mac_algs = 0;
  1955. bench_kdf_algs = 0;
  1956. bench_asym_algs = 0;
  1957. bench_pq_asym_algs = 0;
  1958. bench_other_algs = 0;
  1959. bench_pq_hash_sig_algs = 0;
  1960. csv_format = 0;
  1961. }
  1962. }
  1963. /*****************************************************************************/
  1964. /* Begin Stats Functions */
  1965. /*****************************************************************************/
  1966. typedef enum bench_stat_type {
  1967. BENCH_STAT_ASYM,
  1968. BENCH_STAT_SYM,
  1969. BENCH_STAT_IGNORE,
  1970. } bench_stat_type_t;
  1971. #ifdef WC_BENCH_TRACK_STATS
  1972. static int gPrintStats = 0;
  1973. #ifdef WC_ENABLE_BENCH_THREADING
  1974. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1975. #endif
  1976. #ifndef BENCH_MAX_NAME_SZ
  1977. #define BENCH_MAX_NAME_SZ 24
  1978. #endif
  1979. typedef struct bench_stats {
  1980. struct bench_stats* next;
  1981. struct bench_stats* prev;
  1982. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1983. const char* desc;
  1984. double perfsec;
  1985. int strength;
  1986. int useDeviceID;
  1987. int finishCount;
  1988. bench_stat_type_t type;
  1989. int lastRet;
  1990. const char* perftype;
  1991. } bench_stats_t;
  1992. static bench_stats_t* bench_stats_head;
  1993. static bench_stats_t* bench_stats_tail;
  1994. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1995. const char* algo, int strength, const char* desc, int useDeviceID,
  1996. double perfsec, const char* perftype, int ret)
  1997. {
  1998. bench_stats_t* bstat = NULL;
  1999. #ifdef WC_ENABLE_BENCH_THREADING
  2000. /* protect bench_stats_head and bench_stats_tail access */
  2001. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2002. #endif
  2003. if (algo != NULL) {
  2004. /* locate existing in list */
  2005. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  2006. /* match based on algo, strength and desc */
  2007. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2008. bstat->strength == strength &&
  2009. bstat->desc == desc &&
  2010. bstat->useDeviceID == useDeviceID) {
  2011. break;
  2012. }
  2013. }
  2014. }
  2015. if (bstat == NULL) {
  2016. /* allocate new and put on list */
  2017. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2018. DYNAMIC_TYPE_INFO);
  2019. if (bstat) {
  2020. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2021. /* add to list */
  2022. bstat->next = NULL;
  2023. if (bench_stats_tail == NULL) {
  2024. bench_stats_head = bstat;
  2025. }
  2026. else {
  2027. bench_stats_tail->next = bstat;
  2028. bstat->prev = bench_stats_tail;
  2029. }
  2030. bench_stats_tail = bstat; /* add to the end either way */
  2031. }
  2032. }
  2033. if (bstat) {
  2034. bstat->type = type;
  2035. if (algo != NULL)
  2036. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2037. bstat->strength = strength;
  2038. bstat->desc = desc;
  2039. bstat->useDeviceID = useDeviceID;
  2040. bstat->perfsec += perfsec;
  2041. bstat->finishCount++;
  2042. bstat->perftype = perftype;
  2043. if (bstat->lastRet > ret)
  2044. bstat->lastRet = ret; /* track last error */
  2045. }
  2046. #ifdef WC_ENABLE_BENCH_THREADING
  2047. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2048. #endif
  2049. return bstat;
  2050. }
  2051. void bench_stats_print(void)
  2052. {
  2053. bench_stats_t* bstat;
  2054. int digits;
  2055. #ifdef WC_ENABLE_BENCH_THREADING
  2056. /* protect bench_stats_head and bench_stats_tail access */
  2057. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2058. #endif
  2059. #ifdef BENCH_MICROSECOND
  2060. digits = 5;
  2061. #else
  2062. digits = 3;
  2063. #endif
  2064. for (bstat = bench_stats_head; bstat != NULL; ) {
  2065. if (bstat->type == BENCH_STAT_SYM) {
  2066. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2067. "\n", bstat->desc,
  2068. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2069. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2070. base2 ? "MB" : "mB");
  2071. }
  2072. else {
  2073. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2074. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2075. bstat->algo, bstat->strength, bstat->desc,
  2076. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2077. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2078. }
  2079. bstat = bstat->next;
  2080. }
  2081. #ifdef WC_ENABLE_BENCH_THREADING
  2082. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2083. #endif
  2084. }
  2085. #endif /* WC_BENCH_TRACK_STATS */
  2086. static WC_INLINE void bench_stats_init(void)
  2087. {
  2088. #ifdef WC_BENCH_TRACK_STATS
  2089. bench_stats_head = NULL;
  2090. bench_stats_tail = NULL;
  2091. #endif
  2092. INIT_CYCLE_COUNTER
  2093. }
  2094. static WC_INLINE void bench_stats_start(int* count, double* start)
  2095. {
  2096. *count = 0;
  2097. *start = current_time(1);
  2098. #ifdef WOLFSSL_ESPIDF
  2099. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2100. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2101. ", start=" FLT_FMT,
  2102. total_cycles, FLT_FMT_ARGS(*start) );
  2103. #endif
  2104. BEGIN_ESP_CYCLES
  2105. #else
  2106. BEGIN_INTEL_CYCLES
  2107. #endif
  2108. }
  2109. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2110. #define bench_stats_start(count, start) do { \
  2111. SAVE_VECTOR_REGISTERS(pr_err( \
  2112. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2113. return; ); \
  2114. bench_stats_start(count, start); \
  2115. } while (0)
  2116. #endif
  2117. static WC_INLINE int bench_stats_check(double start)
  2118. {
  2119. int ret = 0;
  2120. double this_current_time = 0.0;
  2121. this_current_time = current_time(0); /* get the timestamp, no reset */
  2122. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2123. #if defined(WOLFSSL_ESPIDF)
  2124. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2125. this_current_time, start );
  2126. #endif
  2127. #endif
  2128. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2129. #ifdef BENCH_MICROSECOND
  2130. * 1000000
  2131. #endif
  2132. );
  2133. return ret;
  2134. }
  2135. /* return text for units and scale the value of blocks as needed */
  2136. static const char* get_blocktype(double* blocks)
  2137. {
  2138. const char* rt;
  2139. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2140. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2141. #undef WOLFSSL_FIXED_UNIT
  2142. #define WOLFSSL_FIXED_UNIT "GB"
  2143. *blocks /= (1024UL * 1024UL * 1024UL);
  2144. rt = "GiB";
  2145. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2146. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2147. #undef WOLFSSL_FIXED_UNIT
  2148. #define WOLFSSL_FIXED_UNIT "MB"
  2149. *blocks /= (1024UL * 1024UL);
  2150. rt = "MiB";
  2151. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2152. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2153. #undef WOLFSSL_FIXED_UNIT
  2154. #define WOLFSSL_FIXED_UNIT "KB"
  2155. *blocks /= 1024;
  2156. rt = "KiB";
  2157. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2158. #undef WOLFSSL_FIXED_UNIT
  2159. #define WOLFSSL_FIXED_UNIT "bytes"
  2160. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2161. rt = "bytes";
  2162. #else
  2163. /* If no user-specified, auto-scale each metric (results vary).
  2164. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2165. if (*blocks > (1024UL * 1024UL)) {
  2166. *blocks /= (1024UL * 1024UL);
  2167. rt = "MiB";
  2168. }
  2169. else if (*blocks > 1024) {
  2170. *blocks /= 1024;
  2171. rt = "KiB";
  2172. }
  2173. else {
  2174. rt = "bytes";
  2175. }
  2176. #endif
  2177. return rt;
  2178. }
  2179. /* return text for units and scale the value of blocks as needed for base2 */
  2180. static const char* get_blocktype_base10(double* blocks)
  2181. {
  2182. const char* rt;
  2183. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2184. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2185. *blocks /= (1000UL * 1000UL * 1000UL);
  2186. rt = "GB";
  2187. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2188. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2189. *blocks /= (1000UL * 1000UL);
  2190. rt = "MB";
  2191. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2192. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2193. *blocks /= (1000UL);
  2194. rt = "KB";
  2195. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2196. (void)(*blocks); /* no adjustment, just appease compiler */
  2197. rt = "bytes";
  2198. #else
  2199. /* If not user-specified, auto-scale each metric (results vary).
  2200. * Determine if we should show as KB or MB or bytes */
  2201. if (*blocks > (1000UL * 1000UL)) {
  2202. *blocks /= (1000UL * 1000UL);
  2203. rt = "MB";
  2204. }
  2205. else if (*blocks > 1000) {
  2206. *blocks /= 1000; /* make KB */
  2207. rt = "KB";
  2208. }
  2209. else {
  2210. rt = "bytes";
  2211. }
  2212. #endif
  2213. return rt;
  2214. }
  2215. #ifdef MULTI_VALUE_STATISTICS
  2216. static double wc_sqroot(double in)
  2217. {
  2218. /* do 32 iterations for the sqroot */
  2219. int iter = 32;
  2220. double root = in/3.0;
  2221. if (in < 0.0)
  2222. return -1;
  2223. for (int i=0; i < iter; i++)
  2224. root = (root + in / root) / 2.0;
  2225. return root;
  2226. }
  2227. static void bench_multi_value_stats(double max, double min, double sum,
  2228. double squareSum, int runs)
  2229. {
  2230. double mean = 0;
  2231. double sd = 0;
  2232. char msg[WC_BENCH_MAX_LINE_LEN];
  2233. const char** word = bench_result_words3[lng_index];
  2234. XMEMSET(msg, 0, sizeof(msg));
  2235. mean = sum / runs;
  2236. /* Calculating standard deviation */
  2237. sd = (squareSum / runs) - (mean * mean);
  2238. sd = wc_sqroot(sd);
  2239. if (csv_format == 1) {
  2240. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2241. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2242. FLT_FMT_PREC2_ARGS(3, 3, max),
  2243. FLT_FMT_PREC2_ARGS(3, 3, min),
  2244. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2245. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2246. }
  2247. else{
  2248. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2249. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2250. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2251. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2252. WOLFSSL_FIXED_TIME_UNIT "\n",
  2253. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2254. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2255. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2256. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2257. }
  2258. printf("%s", msg);
  2259. #ifndef WOLFSSL_SGX
  2260. XFFLUSH(stdout);
  2261. #endif
  2262. }
  2263. #endif
  2264. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2265. * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */
  2266. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2267. int count, word32 countSz,
  2268. double start, int ret)
  2269. {
  2270. double total, persec = 0, blocks = (double)count;
  2271. const char* blockType;
  2272. char msg[WC_BENCH_MAX_LINE_LEN];
  2273. const char** word = bench_result_words1[lng_index];
  2274. static int sym_header_printed = 0;
  2275. XMEMSET(msg, 0, sizeof(msg));
  2276. #ifdef WOLFSSL_ESPIDF
  2277. END_ESP_CYCLES
  2278. #else
  2279. END_INTEL_CYCLES
  2280. #endif
  2281. total = current_time(0) - start;
  2282. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2283. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2284. #endif
  2285. #ifdef LINUX_RUSAGE_UTIME
  2286. check_for_excessive_stime(desc, "");
  2287. #endif
  2288. /* calculate actual bytes */
  2289. blocks *= countSz;
  2290. if (csv_format == 1) {
  2291. /* only print out header once */
  2292. if (sym_header_printed == 0) {
  2293. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2294. /* machine parseable CSV */
  2295. #ifdef HAVE_GET_CYCLES
  2296. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2297. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2298. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2299. ",cycles_total,Cycles per byte,");
  2300. #else
  2301. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2302. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2303. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2304. ",cycles_total,");
  2305. #endif
  2306. #else
  2307. /* normal CSV */
  2308. #ifdef BENCH_DEVID
  2309. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2310. #else
  2311. #define BENCH_DEVID_COLUMN_HEADER
  2312. #endif
  2313. #ifdef HAVE_GET_CYCLES
  2314. printf("\n\nSymmetric Ciphers:\n\n");
  2315. printf("Algorithm,"
  2316. BENCH_DEVID_COLUMN_HEADER
  2317. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2318. ",Cycles per byte,");
  2319. #else
  2320. printf("\n\nSymmetric Ciphers:\n\n");
  2321. printf("Algorithm,"
  2322. BENCH_DEVID_COLUMN_HEADER
  2323. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2324. #endif
  2325. #endif
  2326. #ifdef MULTI_VALUE_STATISTICS
  2327. printf("max duration,min duration,mean duration,sd,\n");
  2328. #else
  2329. printf("\n");
  2330. #endif
  2331. sym_header_printed = 1;
  2332. }
  2333. }
  2334. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2335. * note that the blockType text is assigned AND the blocks param is scaled.
  2336. */
  2337. if (base2) {
  2338. blockType = get_blocktype(&blocks);
  2339. }
  2340. else {
  2341. blockType = get_blocktype_base10(&blocks);
  2342. }
  2343. /* calculate blocks per second */
  2344. if (total > 0) {
  2345. persec = (1 / total) * blocks;
  2346. }
  2347. SLEEP_ON_ERROR(ret);
  2348. /* format and print to terminal */
  2349. if (csv_format == 1) {
  2350. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2351. #ifdef WOLFSSL_ESPIDF
  2352. unsigned long bytes_processed =
  2353. (unsigned long)count * (unsigned long)countSz;
  2354. #else
  2355. word64 bytes_processed = (word64)count * (word64)countSz;
  2356. #endif
  2357. /* note this codepath brings in all the fields from the non-CSV case. */
  2358. #ifdef WOLFSSL_ESPIDF
  2359. #ifdef HAVE_GET_CYCLES
  2360. (void)XSNPRINTF(msg, sizeof(msg),
  2361. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2362. BENCH_DEVID_GET_NAME(useDeviceID),
  2363. bytes_processed, FLT_FMT_ARGS(total),
  2364. FLT_FMT_ARGS(persec),
  2365. (long unsigned int) total_cycles);
  2366. #else
  2367. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2368. #endif
  2369. /* implement other architectures here */
  2370. #else
  2371. #ifdef HAVE_GET_CYCLES
  2372. (void)XSNPRINTF(msg, sizeof(msg),
  2373. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2374. BENCH_DEVID_GET_NAME(useDeviceID),
  2375. bytes_processed, FLT_FMT_ARGS(total),
  2376. FLT_FMT_ARGS(persec), total_cycles);
  2377. #else
  2378. (void)XSNPRINTF(msg, sizeof(msg),
  2379. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2380. BENCH_DEVID_GET_NAME(useDeviceID),
  2381. bytes_processed, FLT_FMT_ARGS(total),
  2382. FLT_FMT_ARGS(persec));
  2383. #endif
  2384. #endif
  2385. #elif defined(BENCH_DEVID)
  2386. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2387. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2388. #else
  2389. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2390. FLT_FMT_ARGS(persec));
  2391. #endif
  2392. #ifdef WOLFSSL_ESPIDF
  2393. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2394. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2395. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2396. total_cycles);
  2397. #endif
  2398. /* implement other cycle counters here */
  2399. #else
  2400. /* the default cycle counter is Intel */
  2401. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2402. #endif
  2403. } /* if (csv_format == 1) */
  2404. else {
  2405. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2406. #ifdef HAVE_GET_CYCLES
  2407. (void)XSNPRINTF(msg, sizeof(msg),
  2408. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2409. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2410. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2411. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2412. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2413. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2414. (unsigned long) total_cycles);
  2415. #else
  2416. (void)XSNPRINTF(msg, sizeof(msg),
  2417. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2418. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2419. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2420. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2421. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2422. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2423. #endif /* HAVE_GET_CYCLES */
  2424. #else
  2425. (void)XSNPRINTF(msg, sizeof(msg),
  2426. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2427. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2428. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2429. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2430. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2431. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2432. #endif
  2433. #ifdef WOLFSSL_ESPIDF
  2434. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2435. /* implement other architecture cycle counters here */
  2436. #else
  2437. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2438. #endif
  2439. } /* not CSV format */
  2440. printf("%s", msg);
  2441. /* show errors */
  2442. if (ret < 0) {
  2443. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2444. }
  2445. #ifndef WOLFSSL_SGX
  2446. XFFLUSH(stdout);
  2447. #endif
  2448. #ifdef WC_BENCH_TRACK_STATS
  2449. /* Add to thread stats */
  2450. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2451. blockType, ret);
  2452. #endif
  2453. (void)useDeviceID;
  2454. (void)ret;
  2455. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2456. RESTORE_VECTOR_REGISTERS();
  2457. #endif
  2458. TEST_SLEEP();
  2459. } /* bench_stats_sym_finish */
  2460. #ifdef BENCH_ASYM
  2461. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2462. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2463. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2464. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  2465. defined(WOLFSSL_HAVE_LMS)
  2466. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2467. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2468. double start, int ret)
  2469. {
  2470. double total, each = 0, opsSec, milliEach;
  2471. const char **word = bench_result_words2[lng_index];
  2472. #ifdef WC_BENCH_TRACK_STATS
  2473. const char* kOpsSec = "Ops/Sec";
  2474. #endif
  2475. char msg[256];
  2476. static int asym_header_printed = 0;
  2477. #ifdef BENCH_MICROSECOND
  2478. const int digits = 5;
  2479. #else
  2480. const int digits = 3;
  2481. #endif
  2482. XMEMSET(msg, 0, sizeof(msg));
  2483. total = current_time(0) - start;
  2484. #ifdef LINUX_RUSAGE_UTIME
  2485. check_for_excessive_stime(desc, desc_extra);
  2486. #endif
  2487. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2488. #ifdef WOLFSSL_ESPIDF
  2489. END_ESP_CYCLES
  2490. #else
  2491. END_INTEL_CYCLES
  2492. #endif
  2493. #endif
  2494. /* some sanity checks on the final numbers */
  2495. if (count > 0) {
  2496. each = total / count; /* per second */
  2497. }
  2498. else {
  2499. count = 0;
  2500. each = 0;
  2501. }
  2502. if (total > 0) {
  2503. opsSec = count / total; /* ops second */
  2504. }
  2505. else {
  2506. opsSec = 0;
  2507. }
  2508. #ifdef BENCH_MICROSECOND
  2509. milliEach = each / 1000; /* milliseconds */
  2510. #else
  2511. milliEach = each * 1000; /* milliseconds */
  2512. #endif
  2513. SLEEP_ON_ERROR(ret);
  2514. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2515. (void)milliEach;
  2516. /* format and print to terminal */
  2517. if (csv_format == 1) {
  2518. /* only print out header once */
  2519. if (asym_header_printed == 0) {
  2520. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2521. #ifdef HAVE_GET_CYCLES
  2522. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2523. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2524. "ecs,cycles,cycles/op,");
  2525. #else
  2526. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2527. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2528. "ecs,");
  2529. #endif
  2530. #else
  2531. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2532. printf("%sAlgorithm,key size,operation,ops/"
  2533. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2534. #endif
  2535. printf("max duration,min duration,mean duration,sd,\n");
  2536. asym_header_printed = 1;
  2537. }
  2538. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2539. #ifdef HAVE_GET_CYCLES
  2540. (void)XSNPRINTF(msg, sizeof(msg),
  2541. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2542. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2543. algo, strength, desc, desc_extra,
  2544. FLT_FMT_PREC_ARGS(digits, opsSec),
  2545. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2546. FLT_FMT_PREC_ARGS(6,
  2547. (double)total_cycles / (double)count));
  2548. #else
  2549. (void)XSNPRINTF(msg, sizeof(msg),
  2550. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2551. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2552. algo, strength, desc, desc_extra,
  2553. FLT_FMT_PREC_ARGS(digits, opsSec),
  2554. count, FLT_FMT_ARGS(total));
  2555. #endif
  2556. #else
  2557. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2558. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2559. algo, strength, desc, desc_extra,
  2560. FLT_FMT_PREC_ARGS(digits, opsSec));
  2561. #endif
  2562. } /* if (csv_format == 1) */
  2563. else {
  2564. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2565. #ifdef HAVE_GET_CYCLES
  2566. (void)XSNPRINTF(msg, sizeof(msg),
  2567. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2568. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2569. algo, strength, desc, desc_extra,
  2570. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2571. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2572. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2573. (unsigned long)total_cycles);
  2574. #else
  2575. (void)XSNPRINTF(msg, sizeof(msg),
  2576. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2577. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2578. algo, strength, desc, desc_extra,
  2579. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2580. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2581. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2582. #endif /* HAVE_GET_CYCLES */
  2583. #else
  2584. (void)XSNPRINTF(msg, sizeof(msg),
  2585. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2586. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2587. algo, strength, desc, desc_extra,
  2588. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2589. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2590. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2591. #endif
  2592. }
  2593. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2594. /* format and print to terminal */
  2595. if (csv_format == 1) {
  2596. /* only print out header once */
  2597. if (asym_header_printed == 0) {
  2598. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2599. #ifdef HAVE_GET_CYCLES
  2600. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2601. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2602. "ecs,cycles,cycles/op,");
  2603. #else
  2604. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2605. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2606. "ecs,");
  2607. #endif
  2608. #else
  2609. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2610. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2611. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2612. #endif
  2613. printf("\n");
  2614. asym_header_printed = 1;
  2615. }
  2616. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2617. #ifdef HAVE_GET_CYCLES
  2618. (void)XSNPRINTF(msg, sizeof(msg),
  2619. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2620. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2621. algo, strength, desc, desc_extra,
  2622. FLT_FMT_PREC_ARGS(3, milliEach),
  2623. FLT_FMT_PREC_ARGS(digits, opsSec),
  2624. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2625. FLT_FMT_PREC_ARGS(6,
  2626. (double)total_cycles / (double)count));
  2627. #else
  2628. (void)XSNPRINTF(msg, sizeof(msg),
  2629. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2630. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2631. algo, strength, desc, desc_extra,
  2632. FLT_FMT_PREC_ARGS(3, milliEach),
  2633. FLT_FMT_PREC_ARGS(digits, opsSec),
  2634. count, FLT_FMT_ARGS(total));
  2635. #endif
  2636. #else
  2637. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2638. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2639. algo, strength, desc, desc_extra,
  2640. FLT_FMT_PREC_ARGS(3, milliEach),
  2641. FLT_FMT_PREC_ARGS(digits, opsSec));
  2642. #endif
  2643. } /* if (csv_format == 1) */
  2644. else {
  2645. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2646. #ifdef HAVE_GET_CYCLES
  2647. (void)XSNPRINTF(msg, sizeof(msg),
  2648. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2649. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2650. STATS_CLAUSE_SEPARATOR,
  2651. algo, strength, desc, desc_extra,
  2652. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2653. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2654. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2655. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2656. (unsigned long)total_cycles);
  2657. #else
  2658. (void)XSNPRINTF(msg, sizeof(msg),
  2659. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2660. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2661. STATS_CLAUSE_SEPARATOR,
  2662. algo, strength, desc, desc_extra,
  2663. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2664. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2665. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2666. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2667. #endif /* HAVE_GET_CYCLES */
  2668. #else
  2669. (void)XSNPRINTF(msg, sizeof(msg),
  2670. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2671. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2672. STATS_CLAUSE_SEPARATOR,
  2673. algo, strength, desc, desc_extra,
  2674. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2675. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2676. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2677. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2678. #endif
  2679. }
  2680. #endif /* MULTI_VALUE_STATISTICS */
  2681. printf("%s", msg);
  2682. /* show errors */
  2683. if (ret < 0) {
  2684. printf("%sBenchmark %s %s %d failed: %d\n",
  2685. err_prefix, algo, desc, strength, ret);
  2686. }
  2687. #ifndef WOLFSSL_SGX
  2688. XFFLUSH(stdout);
  2689. #endif
  2690. #ifdef WC_BENCH_TRACK_STATS
  2691. /* Add to thread stats */
  2692. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2693. kOpsSec, ret);
  2694. #endif
  2695. (void)useDeviceID;
  2696. (void)ret;
  2697. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2698. RESTORE_VECTOR_REGISTERS();
  2699. #endif
  2700. TEST_SLEEP();
  2701. } /* bench_stats_asym_finish_ex */
  2702. static void bench_stats_asym_finish(const char* algo, int strength,
  2703. const char* desc, int useDeviceID, int count, double start, int ret)
  2704. {
  2705. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2706. start, ret);
  2707. }
  2708. #endif
  2709. #endif /* BENCH_ASYM */
  2710. static WC_INLINE void bench_stats_free(void)
  2711. {
  2712. #ifdef WC_BENCH_TRACK_STATS
  2713. bench_stats_t* bstat;
  2714. for (bstat = bench_stats_head; bstat != NULL; ) {
  2715. bench_stats_t* next = bstat->next;
  2716. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2717. bstat = next;
  2718. }
  2719. bench_stats_head = NULL;
  2720. bench_stats_tail = NULL;
  2721. #endif
  2722. }
  2723. /*****************************************************************************/
  2724. /* End Stats Functions */
  2725. /*****************************************************************************/
  2726. static void* benchmarks_do(void* args)
  2727. {
  2728. long bench_buf_size;
  2729. #ifdef WOLFSSL_ASYNC_CRYPT
  2730. #ifndef WC_NO_ASYNC_THREADING
  2731. ThreadData* threadData = (ThreadData*)args;
  2732. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2733. #else
  2734. if (wolfAsync_DevOpen(&devId) < 0)
  2735. #endif
  2736. {
  2737. printf("%sAsync device open failed\n%sRunning without async\n",
  2738. err_prefix, err_prefix);
  2739. }
  2740. #endif /* WOLFSSL_ASYNC_CRYPT */
  2741. (void)args;
  2742. #ifdef WOLFSSL_ASYNC_CRYPT
  2743. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2744. printf("%sAsync event queue init failure!\n", err_prefix);
  2745. }
  2746. #endif
  2747. #ifdef WOLF_CRYPTO_CB
  2748. #ifdef HAVE_INTEL_QA_SYNC
  2749. devId = wc_CryptoCb_InitIntelQa();
  2750. if (devId == INVALID_DEVID) {
  2751. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2752. }
  2753. #endif
  2754. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2755. devId = wc_CryptoCb_InitOcteon();
  2756. if (devId == INVALID_DEVID) {
  2757. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2758. }
  2759. #endif
  2760. #ifdef HAVE_RENESAS_SYNC
  2761. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2762. if (devId == INVALID_DEVID) {
  2763. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2764. }
  2765. #endif
  2766. #endif
  2767. #if defined(HAVE_LOCAL_RNG)
  2768. {
  2769. int rngRet;
  2770. #ifndef HAVE_FIPS
  2771. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2772. #else
  2773. rngRet = wc_InitRng(&gRng);
  2774. #endif
  2775. if (rngRet < 0) {
  2776. printf("%sInitRNG failed\n", err_prefix);
  2777. return NULL;
  2778. }
  2779. }
  2780. #endif
  2781. /* setup bench plain, cipher, key and iv globals */
  2782. /* make sure bench buffer is multiple of 16 (AES block size) */
  2783. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2784. if (bench_buf_size % 16)
  2785. bench_buf_size += 16 - (bench_buf_size % 16);
  2786. #ifdef WOLFSSL_AFALG_XILINX_AES
  2787. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2788. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2789. #else
  2790. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2791. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2792. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2793. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2794. #endif
  2795. if (bench_plain == NULL || bench_cipher == NULL) {
  2796. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2797. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2798. bench_plain = bench_cipher = NULL;
  2799. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2800. goto exit;
  2801. }
  2802. #ifndef NO_FILESYSTEM
  2803. if (hash_input) {
  2804. size_t rawSz;
  2805. XFILE file;
  2806. file = XFOPEN(hash_input, "rb");
  2807. if (file == XBADFILE)
  2808. goto exit;
  2809. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2810. XFCLOSE(file);
  2811. goto exit;
  2812. }
  2813. bench_buf_size = XFTELL(file);
  2814. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2815. XFCLOSE(file);
  2816. goto exit;
  2817. }
  2818. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2819. rawSz = (size_t)bench_buf_size;
  2820. if (bench_buf_size % 16)
  2821. bench_buf_size += 16 - (bench_buf_size % 16);
  2822. bench_size = (word32)bench_buf_size;
  2823. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2824. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2825. if (bench_plain == NULL) {
  2826. XFCLOSE(file);
  2827. goto exit;
  2828. }
  2829. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2830. != rawSz) {
  2831. XFCLOSE(file);
  2832. goto exit;
  2833. }
  2834. XFCLOSE(file);
  2835. }
  2836. else {
  2837. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2838. }
  2839. if (cipher_input) {
  2840. size_t rawSz;
  2841. XFILE file;
  2842. file = XFOPEN(cipher_input, "rb");
  2843. if (file == XBADFILE)
  2844. goto exit;
  2845. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2846. XFCLOSE(file);
  2847. goto exit;
  2848. }
  2849. bench_buf_size = XFTELL(file);
  2850. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2851. XFCLOSE(file);
  2852. goto exit;
  2853. }
  2854. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2855. rawSz = (size_t)bench_buf_size;
  2856. if (bench_buf_size % 16)
  2857. bench_buf_size += 16 - (bench_buf_size % 16);
  2858. if (bench_size > (word32)bench_buf_size)
  2859. bench_size = (word32)bench_buf_size;
  2860. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2861. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2862. if (bench_cipher == NULL) {
  2863. XFCLOSE(file);
  2864. goto exit;
  2865. }
  2866. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2867. != rawSz) {
  2868. XFCLOSE(file);
  2869. goto exit;
  2870. }
  2871. XFCLOSE(file);
  2872. }
  2873. else {
  2874. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2875. }
  2876. #endif
  2877. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2878. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2879. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2880. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2881. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2882. if (bench_key == NULL || bench_iv == NULL) {
  2883. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2884. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2885. bench_key = bench_iv = NULL;
  2886. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2887. goto exit;
  2888. }
  2889. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2890. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2891. #elif defined(HAVE_RENESAS_SYNC)
  2892. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2893. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2894. bench_key = (byte*)bench_key_buf;
  2895. bench_iv = (byte*)bench_iv_buf;
  2896. #else
  2897. bench_key = (byte*)bench_key_buf;
  2898. bench_iv = (byte*)bench_iv_buf;
  2899. #endif
  2900. #ifndef WC_NO_RNG
  2901. if (bench_all || (bench_other_algs & BENCH_RNG))
  2902. bench_rng();
  2903. #endif /* WC_NO_RNG */
  2904. #ifndef NO_AES
  2905. #ifdef HAVE_AES_CBC
  2906. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2907. #ifndef NO_SW_BENCH
  2908. bench_aescbc(0);
  2909. #endif
  2910. #if defined(BENCH_DEVID)
  2911. bench_aescbc(1);
  2912. #endif
  2913. }
  2914. #endif
  2915. #ifdef HAVE_AESGCM
  2916. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2917. #ifndef NO_SW_BENCH
  2918. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2919. #endif
  2920. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2921. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2922. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2923. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2924. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2925. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2926. #endif
  2927. #ifndef NO_SW_BENCH
  2928. bench_gmac(0);
  2929. #endif
  2930. #if defined(BENCH_DEVID)
  2931. bench_gmac(1);
  2932. #endif
  2933. }
  2934. #endif
  2935. #ifdef HAVE_AES_ECB
  2936. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2937. #ifndef NO_SW_BENCH
  2938. bench_aesecb(0);
  2939. #endif
  2940. #ifdef BENCH_DEVID
  2941. bench_aesecb(1);
  2942. #endif
  2943. }
  2944. #endif
  2945. #ifdef WOLFSSL_AES_XTS
  2946. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2947. bench_aesxts();
  2948. #endif
  2949. #ifdef WOLFSSL_AES_CFB
  2950. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2951. bench_aescfb();
  2952. #endif
  2953. #ifdef WOLFSSL_AES_OFB
  2954. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2955. bench_aesofb();
  2956. #endif
  2957. #ifdef WOLFSSL_AES_COUNTER
  2958. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2959. bench_aesctr(0);
  2960. #ifdef BENCH_DEVID
  2961. bench_aesctr(1);
  2962. #endif
  2963. }
  2964. #endif
  2965. #ifdef HAVE_AESCCM
  2966. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2967. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2968. #ifdef BENCH_DEVID
  2969. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2970. #endif
  2971. }
  2972. #endif
  2973. #ifdef WOLFSSL_AES_SIV
  2974. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2975. bench_aessiv();
  2976. #endif
  2977. #endif /* !NO_AES */
  2978. #ifdef HAVE_CAMELLIA
  2979. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2980. bench_camellia();
  2981. #endif
  2982. #ifdef WOLFSSL_SM4_CBC
  2983. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2984. bench_sm4_cbc();
  2985. #endif
  2986. #ifdef WOLFSSL_SM4_GCM
  2987. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2988. bench_sm4_gcm();
  2989. #endif
  2990. #ifdef WOLFSSL_SM4_CCM
  2991. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2992. bench_sm4_ccm();
  2993. #endif
  2994. #ifndef NO_RC4
  2995. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2996. #ifndef NO_SW_BENCH
  2997. bench_arc4(0);
  2998. #endif
  2999. #ifdef BENCH_DEVID
  3000. bench_arc4(1);
  3001. #endif
  3002. }
  3003. #endif
  3004. #ifdef HAVE_CHACHA
  3005. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  3006. bench_chacha();
  3007. #endif
  3008. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3009. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3010. bench_chacha20_poly1305_aead();
  3011. #endif
  3012. #ifndef NO_DES3
  3013. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3014. #ifndef NO_SW_BENCH
  3015. bench_des(0);
  3016. #endif
  3017. #ifdef BENCH_DEVID
  3018. bench_des(1);
  3019. #endif
  3020. }
  3021. #endif
  3022. #ifndef NO_MD5
  3023. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3024. #ifndef NO_SW_BENCH
  3025. bench_md5(0);
  3026. #endif
  3027. #ifdef BENCH_DEVID
  3028. bench_md5(1);
  3029. #endif
  3030. }
  3031. #endif
  3032. #ifdef HAVE_POLY1305
  3033. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3034. bench_poly1305();
  3035. #endif
  3036. #ifndef NO_SHA
  3037. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3038. #ifndef NO_SW_BENCH
  3039. bench_sha(0);
  3040. #endif
  3041. #ifdef BENCH_DEVID
  3042. bench_sha(1);
  3043. #endif
  3044. }
  3045. #endif
  3046. #ifdef WOLFSSL_SHA224
  3047. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3048. #ifndef NO_SW_BENCH
  3049. bench_sha224(0);
  3050. #endif
  3051. #ifdef BENCH_DEVID
  3052. bench_sha224(1);
  3053. #endif
  3054. }
  3055. #endif
  3056. #ifndef NO_SHA256
  3057. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3058. #ifndef NO_SW_BENCH
  3059. bench_sha256(0);
  3060. #endif
  3061. #ifdef BENCH_DEVID
  3062. bench_sha256(1);
  3063. #endif
  3064. }
  3065. #endif
  3066. #ifdef WOLFSSL_SHA384
  3067. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3068. #ifndef NO_SW_BENCH
  3069. bench_sha384(0);
  3070. #endif
  3071. #ifdef BENCH_DEVID
  3072. bench_sha384(1);
  3073. #endif
  3074. }
  3075. #endif
  3076. #ifdef WOLFSSL_SHA512
  3077. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3078. #ifndef NO_SW_BENCH
  3079. bench_sha512(0);
  3080. #endif
  3081. #ifdef BENCH_DEVID
  3082. bench_sha512(1);
  3083. #endif
  3084. }
  3085. #if !defined(WOLFSSL_NOSHA512_224) && \
  3086. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3087. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3088. #ifndef NO_SW_BENCH
  3089. bench_sha512_224(0);
  3090. #endif
  3091. #ifdef BENCH_DEVID
  3092. bench_sha512_224(1);
  3093. #endif
  3094. }
  3095. #endif /* WOLFSSL_NOSHA512_224 */
  3096. #if !defined(WOLFSSL_NOSHA512_256) && \
  3097. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3098. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3099. #ifndef NO_SW_BENCH
  3100. bench_sha512_256(0);
  3101. #endif
  3102. #ifdef BENCH_DEVID
  3103. bench_sha512_256(1);
  3104. #endif
  3105. }
  3106. #endif /* WOLFSSL_NOSHA512_256 */
  3107. #endif /* WOLFSSL_SHA512 */
  3108. #ifdef WOLFSSL_SHA3
  3109. #ifndef WOLFSSL_NOSHA3_224
  3110. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3111. #ifndef NO_SW_BENCH
  3112. bench_sha3_224(0);
  3113. #endif
  3114. #ifdef BENCH_DEVID
  3115. bench_sha3_224(1);
  3116. #endif
  3117. }
  3118. #endif /* WOLFSSL_NOSHA3_224 */
  3119. #ifndef WOLFSSL_NOSHA3_256
  3120. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3121. #ifndef NO_SW_BENCH
  3122. bench_sha3_256(0);
  3123. #endif
  3124. #ifdef BENCH_DEVID
  3125. bench_sha3_256(1);
  3126. #endif
  3127. }
  3128. #endif /* WOLFSSL_NOSHA3_256 */
  3129. #ifndef WOLFSSL_NOSHA3_384
  3130. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3131. #ifndef NO_SW_BENCH
  3132. bench_sha3_384(0);
  3133. #endif
  3134. #ifdef BENCH_DEVID
  3135. bench_sha3_384(1);
  3136. #endif
  3137. }
  3138. #endif /* WOLFSSL_NOSHA3_384 */
  3139. #ifndef WOLFSSL_NOSHA3_512
  3140. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3141. #ifndef NO_SW_BENCH
  3142. bench_sha3_512(0);
  3143. #endif
  3144. #ifdef BENCH_DEVID
  3145. bench_sha3_512(1);
  3146. #endif
  3147. }
  3148. #endif /* WOLFSSL_NOSHA3_512 */
  3149. #ifdef WOLFSSL_SHAKE128
  3150. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3151. #ifndef NO_SW_BENCH
  3152. bench_shake128(0);
  3153. #endif
  3154. #ifdef BENCH_DEVID
  3155. bench_shake128(1);
  3156. #endif
  3157. }
  3158. #endif /* WOLFSSL_SHAKE128 */
  3159. #ifdef WOLFSSL_SHAKE256
  3160. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3161. #ifndef NO_SW_BENCH
  3162. bench_shake256(0);
  3163. #endif
  3164. #ifdef BENCH_DEVID
  3165. bench_shake256(1);
  3166. #endif
  3167. }
  3168. #endif /* WOLFSSL_SHAKE256 */
  3169. #endif
  3170. #ifdef WOLFSSL_SM3
  3171. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3172. #ifndef NO_SW_BENCH
  3173. bench_sm3(0);
  3174. #endif
  3175. #ifdef BENCH_DEVID
  3176. bench_sm3(1);
  3177. #endif
  3178. }
  3179. #endif
  3180. #ifdef WOLFSSL_RIPEMD
  3181. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3182. bench_ripemd();
  3183. #endif
  3184. #ifdef HAVE_BLAKE2
  3185. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3186. bench_blake2b();
  3187. #endif
  3188. #ifdef HAVE_BLAKE2S
  3189. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3190. bench_blake2s();
  3191. #endif
  3192. #ifdef WOLFSSL_CMAC
  3193. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3194. bench_cmac(0);
  3195. #ifdef BENCH_DEVID
  3196. bench_cmac(1);
  3197. #endif
  3198. }
  3199. #endif
  3200. #ifndef NO_HMAC
  3201. #ifndef NO_MD5
  3202. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3203. #ifndef NO_SW_BENCH
  3204. bench_hmac_md5(0);
  3205. #endif
  3206. #ifdef BENCH_DEVID
  3207. bench_hmac_md5(1);
  3208. #endif
  3209. }
  3210. #endif
  3211. #ifndef NO_SHA
  3212. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3213. #ifndef NO_SW_BENCH
  3214. bench_hmac_sha(0);
  3215. #endif
  3216. #ifdef BENCH_DEVID
  3217. bench_hmac_sha(1);
  3218. #endif
  3219. }
  3220. #endif
  3221. #ifdef WOLFSSL_SHA224
  3222. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3223. #ifndef NO_SW_BENCH
  3224. bench_hmac_sha224(0);
  3225. #endif
  3226. #ifdef BENCH_DEVID
  3227. bench_hmac_sha224(1);
  3228. #endif
  3229. }
  3230. #endif
  3231. #ifndef NO_SHA256
  3232. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3233. #ifndef NO_SW_BENCH
  3234. bench_hmac_sha256(0);
  3235. #endif
  3236. #ifdef BENCH_DEVID
  3237. bench_hmac_sha256(1);
  3238. #endif
  3239. }
  3240. #endif
  3241. #ifdef WOLFSSL_SHA384
  3242. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3243. #ifndef NO_SW_BENCH
  3244. bench_hmac_sha384(0);
  3245. #endif
  3246. #ifdef BENCH_DEVID
  3247. bench_hmac_sha384(1);
  3248. #endif
  3249. }
  3250. #endif
  3251. #ifdef WOLFSSL_SHA512
  3252. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3253. #ifndef NO_SW_BENCH
  3254. bench_hmac_sha512(0);
  3255. #endif
  3256. #ifdef BENCH_DEVID
  3257. bench_hmac_sha512(1);
  3258. #endif
  3259. }
  3260. #endif
  3261. #ifndef NO_PWDBASED
  3262. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3263. bench_pbkdf2();
  3264. }
  3265. #endif
  3266. #endif /* NO_HMAC */
  3267. #ifdef WOLFSSL_SIPHASH
  3268. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3269. bench_siphash();
  3270. }
  3271. #endif
  3272. #ifdef WC_SRTP_KDF
  3273. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3274. bench_srtpkdf();
  3275. }
  3276. #endif
  3277. #ifdef HAVE_SCRYPT
  3278. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3279. bench_scrypt();
  3280. #endif
  3281. #ifndef NO_RSA
  3282. #ifndef HAVE_RENESAS_SYNC
  3283. #ifdef WOLFSSL_KEY_GEN
  3284. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3285. #ifndef NO_SW_BENCH
  3286. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3287. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3288. bench_rsaKeyGen(0);
  3289. }
  3290. else {
  3291. bench_rsaKeyGen_size(0, bench_size);
  3292. }
  3293. #endif
  3294. #ifdef BENCH_DEVID
  3295. if (bench_asym_algs & BENCH_RSA_SZ) {
  3296. bench_rsaKeyGen_size(1, bench_size);
  3297. }
  3298. else {
  3299. bench_rsaKeyGen(1);
  3300. }
  3301. #endif
  3302. }
  3303. #endif
  3304. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3305. #ifndef NO_SW_BENCH
  3306. bench_rsa(0);
  3307. #endif
  3308. #ifdef BENCH_DEVID
  3309. bench_rsa(1);
  3310. #endif
  3311. }
  3312. #ifdef WOLFSSL_KEY_GEN
  3313. if (bench_asym_algs & BENCH_RSA_SZ) {
  3314. #ifndef NO_SW_BENCH
  3315. bench_rsa_key(0, bench_size);
  3316. #endif
  3317. #ifdef BENCH_DEVID
  3318. bench_rsa_key(1, bench_size);
  3319. #endif
  3320. }
  3321. #endif
  3322. #endif
  3323. #endif
  3324. #ifndef NO_DH
  3325. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3326. #ifndef NO_SW_BENCH
  3327. bench_dh(0);
  3328. #endif
  3329. #ifdef BENCH_DEVID
  3330. bench_dh(1);
  3331. #endif
  3332. }
  3333. #endif
  3334. #ifdef WOLFSSL_HAVE_KYBER
  3335. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3336. #ifndef WOLFSSL_NO_ML_KEM
  3337. #ifdef WOLFSSL_KYBER512
  3338. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3339. bench_kyber(WC_ML_KEM_512);
  3340. }
  3341. #endif
  3342. #ifdef WOLFSSL_KYBER768
  3343. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3344. bench_kyber(WC_ML_KEM_768);
  3345. }
  3346. #endif
  3347. #ifdef WOLFSSL_KYBER1024
  3348. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3349. bench_kyber(WC_ML_KEM_1024);
  3350. }
  3351. #endif
  3352. #endif
  3353. #ifdef WOLFSSL_KYBER_ORIGINAL
  3354. #ifdef WOLFSSL_KYBER512
  3355. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3356. bench_kyber(KYBER512);
  3357. }
  3358. #endif
  3359. #ifdef WOLFSSL_KYBER768
  3360. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3361. bench_kyber(KYBER768);
  3362. }
  3363. #endif
  3364. #ifdef WOLFSSL_KYBER1024
  3365. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3366. bench_kyber(KYBER1024);
  3367. }
  3368. #endif
  3369. #endif
  3370. }
  3371. #endif
  3372. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3373. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3374. bench_lms();
  3375. }
  3376. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3377. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3378. if (bench_all) {
  3379. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3380. }
  3381. #ifndef NO_SHA256
  3382. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3383. bench_xmss(WC_HASH_TYPE_SHA256);
  3384. }
  3385. #endif
  3386. #ifdef WOLFSSL_SHA512
  3387. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3388. bench_xmss(WC_HASH_TYPE_SHA512);
  3389. }
  3390. #endif
  3391. #ifdef WOLFSSL_SHAKE128
  3392. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3393. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3394. }
  3395. #endif
  3396. #ifdef WOLFSSL_SHAKE256
  3397. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3398. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3399. }
  3400. #endif
  3401. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3402. #ifdef HAVE_ECC
  3403. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3404. (bench_asym_algs & BENCH_ECC) ||
  3405. (bench_asym_algs & BENCH_ECC_ALL) ||
  3406. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3407. if (bench_asym_algs & BENCH_ECC_ALL) {
  3408. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3409. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3410. err_prefix);
  3411. #else
  3412. int curveId = (int)ECC_SECP192R1;
  3413. /* set make key and encrypt */
  3414. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3415. BENCH_ECC_ENCRYPT;
  3416. if (csv_format != 1) {
  3417. printf("\n%sECC Benchmarks:\n", info_prefix);
  3418. }
  3419. do {
  3420. #ifdef WOLFCRYPT_HAVE_SAKKE
  3421. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3422. if (curveId == ECC_SAKKE_1) {
  3423. curveId++;
  3424. continue;
  3425. }
  3426. #endif
  3427. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3428. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3429. bench_ecc_curve(curveId);
  3430. if (csv_format != 1) {
  3431. printf("\n");
  3432. }
  3433. }
  3434. curveId++;
  3435. } while (curveId != (int)ECC_CURVE_MAX);
  3436. #endif
  3437. }
  3438. else if (bench_asym_algs & BENCH_ECC_P256) {
  3439. bench_ecc_curve((int)ECC_SECP256R1);
  3440. }
  3441. else if (bench_asym_algs & BENCH_ECC_P384) {
  3442. bench_ecc_curve((int)ECC_SECP384R1);
  3443. }
  3444. else if (bench_asym_algs & BENCH_ECC_P521) {
  3445. bench_ecc_curve((int)ECC_SECP521R1);
  3446. }
  3447. else {
  3448. #ifndef NO_ECC256
  3449. bench_ecc_curve((int)ECC_SECP256R1);
  3450. #elif defined(HAVE_ECC384)
  3451. bench_ecc_curve((int)ECC_SECP384R1);
  3452. #elif defined(HAVE_ECC521)
  3453. bench_ecc_curve((int)ECC_SECP521R1);
  3454. #endif
  3455. #ifdef HAVE_ECC_BRAINPOOL
  3456. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3457. #endif
  3458. }
  3459. }
  3460. #endif
  3461. #ifdef WOLFSSL_SM2
  3462. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3463. bench_sm2(0);
  3464. }
  3465. #endif
  3466. #ifdef HAVE_CURVE25519
  3467. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3468. bench_curve25519KeyGen(0);
  3469. #ifdef BENCH_DEVID
  3470. bench_curve25519KeyGen(1);
  3471. #endif
  3472. }
  3473. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3474. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3475. bench_curve25519KeyAgree(0);
  3476. #ifdef BENCH_DEVID
  3477. bench_curve25519KeyAgree(1);
  3478. #endif
  3479. }
  3480. #endif
  3481. #endif
  3482. #ifdef HAVE_ED25519
  3483. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3484. bench_ed25519KeyGen();
  3485. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3486. bench_ed25519KeySign();
  3487. #endif
  3488. #ifdef HAVE_CURVE448
  3489. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3490. bench_curve448KeyGen();
  3491. #ifdef HAVE_CURVE448_SHARED_SECRET
  3492. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3493. bench_curve448KeyAgree();
  3494. #endif
  3495. #endif
  3496. #ifdef HAVE_ED448
  3497. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3498. bench_ed448KeyGen();
  3499. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3500. bench_ed448KeySign();
  3501. #endif
  3502. #ifdef WOLFCRYPT_HAVE_ECCSI
  3503. #ifdef WOLFCRYPT_ECCSI_KMS
  3504. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3505. bench_eccsiKeyGen();
  3506. }
  3507. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3508. bench_eccsiPairGen();
  3509. }
  3510. #endif
  3511. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3512. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3513. bench_eccsiValidate();
  3514. }
  3515. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3516. bench_eccsi();
  3517. }
  3518. #endif
  3519. #endif
  3520. #ifdef WOLFCRYPT_HAVE_SAKKE
  3521. #ifdef WOLFCRYPT_SAKKE_KMS
  3522. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3523. bench_sakkeKeyGen();
  3524. }
  3525. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3526. bench_sakkeRskGen();
  3527. }
  3528. #endif
  3529. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3530. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3531. bench_sakkeValidate();
  3532. }
  3533. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3534. bench_sakke();
  3535. }
  3536. #endif
  3537. #endif
  3538. #ifdef HAVE_FALCON
  3539. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3540. bench_falconKeySign(1);
  3541. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3542. bench_falconKeySign(5);
  3543. #endif
  3544. #ifdef HAVE_DILITHIUM
  3545. #ifndef WOLFSSL_NO_ML_DSA_44
  3546. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3547. bench_dilithiumKeySign(2);
  3548. #endif
  3549. #ifndef WOLFSSL_NO_ML_DSA_65
  3550. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3551. bench_dilithiumKeySign(3);
  3552. #endif
  3553. #ifndef WOLFSSL_NO_ML_DSA_87
  3554. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3555. bench_dilithiumKeySign(5);
  3556. #endif
  3557. #endif
  3558. #ifdef HAVE_SPHINCS
  3559. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3560. bench_sphincsKeySign(1, FAST_VARIANT);
  3561. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3562. bench_sphincsKeySign(3, FAST_VARIANT);
  3563. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3564. bench_sphincsKeySign(5, FAST_VARIANT);
  3565. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3566. bench_sphincsKeySign(1, SMALL_VARIANT);
  3567. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3568. bench_sphincsKeySign(3, SMALL_VARIANT);
  3569. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3570. bench_sphincsKeySign(5, SMALL_VARIANT);
  3571. #endif
  3572. exit:
  3573. /* free benchmark buffers */
  3574. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3575. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3576. #ifdef WOLFSSL_ASYNC_CRYPT
  3577. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3578. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3579. #endif
  3580. #if defined(HAVE_LOCAL_RNG)
  3581. wc_FreeRng(&gRng);
  3582. #endif
  3583. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3584. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3585. wc_ecc_fp_free();
  3586. #endif
  3587. (void)bench_cipher_algs;
  3588. (void)bench_digest_algs;
  3589. (void)bench_mac_algs;
  3590. (void)bench_asym_algs;
  3591. (void)bench_other_algs;
  3592. (void)bench_pq_asym_algs;
  3593. (void)bench_pq_asym_algs2;
  3594. return NULL;
  3595. }
  3596. #if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
  3597. static void print_cpu_features(void)
  3598. {
  3599. word32 cpuid_flags = cpuid_get_flags();
  3600. printf("CPU: ");
  3601. #ifdef HAVE_CPUID_INTEL
  3602. printf("Intel");
  3603. #ifdef WOLFSSL_X86_64_BUILD
  3604. printf(" x86_64");
  3605. #else
  3606. printf(" x86");
  3607. #endif
  3608. printf(" -");
  3609. if (IS_INTEL_AVX1(cpuid_flags)) printf(" avx1");
  3610. if (IS_INTEL_AVX2(cpuid_flags)) printf(" avx2");
  3611. if (IS_INTEL_RDRAND(cpuid_flags)) printf(" rdrand");
  3612. if (IS_INTEL_RDSEED(cpuid_flags)) printf(" rdseed");
  3613. if (IS_INTEL_BMI2(cpuid_flags)) printf(" bmi2");
  3614. if (IS_INTEL_AESNI(cpuid_flags)) printf(" aesni");
  3615. if (IS_INTEL_ADX(cpuid_flags)) printf(" adx");
  3616. if (IS_INTEL_MOVBE(cpuid_flags)) printf(" movbe");
  3617. if (IS_INTEL_BMI1(cpuid_flags)) printf(" bmi1");
  3618. if (IS_INTEL_SHA(cpuid_flags)) printf(" sha");
  3619. #endif
  3620. #ifdef __aarch64__
  3621. printf("Aarch64 -");
  3622. if (IS_AARCH64_AES(cpuid_flags)) printf(" aes");
  3623. if (IS_AARCH64_PMULL(cpuid_flags)) printf(" pmull");
  3624. if (IS_AARCH64_SHA256(cpuid_flags)) printf(" sha256");
  3625. if (IS_AARCH64_SHA512(cpuid_flags)) printf(" sha512");
  3626. if (IS_AARCH64_RDM(cpuid_flags)) printf(" rdm");
  3627. if (IS_AARCH64_SHA3(cpuid_flags)) printf(" sha3");
  3628. if (IS_AARCH64_SM3(cpuid_flags)) printf(" sm3");
  3629. if (IS_AARCH64_SM4(cpuid_flags)) printf(" sm4");
  3630. #endif
  3631. printf("\n");
  3632. }
  3633. #endif
  3634. int benchmark_init(void)
  3635. {
  3636. int ret = 0;
  3637. benchmark_static_init(0);
  3638. #ifdef WOLFSSL_STATIC_MEMORY
  3639. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3640. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3641. if (ret != 0) {
  3642. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3643. }
  3644. #endif /* WOLFSSL_STATIC_MEMORY */
  3645. if ((ret = wolfCrypt_Init()) != 0) {
  3646. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3647. return EXIT_FAILURE;
  3648. }
  3649. #if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
  3650. print_cpu_features();
  3651. #endif
  3652. #ifdef HAVE_WC_INTROSPECTION
  3653. printf("Math: %s\n", wc_GetMathInfo());
  3654. #endif
  3655. #ifdef WOLFSSL_SECO_CAAM
  3656. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3657. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3658. != 0) {
  3659. printf("%sunable to open HSM\n", err_prefix);
  3660. wolfCrypt_Cleanup();
  3661. return EXIT_FAILURE;
  3662. }
  3663. #endif
  3664. #ifdef WC_RNG_SEED_CB
  3665. wc_SetSeed_Cb(wc_GenerateSeed);
  3666. #endif
  3667. bench_stats_init();
  3668. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3669. wolfSSL_Debugging_ON();
  3670. #endif
  3671. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3672. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3673. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3674. if (csv_format == 1) {
  3675. printf("This format allows you to easily copy "
  3676. "the output to a csv file.");
  3677. }
  3678. #endif
  3679. #ifdef HAVE_WNR
  3680. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3681. if (ret != 0) {
  3682. printf("%sWhitewood netRandom config init failed %d\n",
  3683. err_prefix, ret);
  3684. }
  3685. #endif /* HAVE_WNR */
  3686. return ret;
  3687. }
  3688. int benchmark_free(void)
  3689. {
  3690. int ret;
  3691. #ifdef WC_BENCH_TRACK_STATS
  3692. if (gPrintStats || devId != INVALID_DEVID) {
  3693. bench_stats_print();
  3694. }
  3695. #endif
  3696. bench_stats_free();
  3697. #ifdef WOLF_CRYPTO_CB
  3698. #ifdef HAVE_INTEL_QA_SYNC
  3699. wc_CryptoCb_CleanupIntelQa(&devId);
  3700. #endif
  3701. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3702. wc_CryptoCb_CleanupOcteon(&devId);
  3703. #endif
  3704. #ifdef HAVE_RENESAS_SYNC
  3705. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3706. #endif
  3707. #endif
  3708. #ifdef WOLFSSL_ASYNC_CRYPT
  3709. /* free event queue */
  3710. wolfEventQueue_Free(&eventQueue);
  3711. /* close device */
  3712. wolfAsync_DevClose(&devId);
  3713. #endif
  3714. #ifdef HAVE_WNR
  3715. ret = wc_FreeNetRandom();
  3716. if (ret < 0) {
  3717. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3718. }
  3719. #endif
  3720. #ifdef WOLFSSL_SECO_CAAM
  3721. if (wc_SECO_CloseHSM() != 0) {
  3722. printf("%sError closing down the key store\n", err_prefix);
  3723. }
  3724. #endif
  3725. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3726. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3727. }
  3728. return ret;
  3729. }
  3730. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3731. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3732. {
  3733. benchmark_test(args);
  3734. EXIT_TEST(0);
  3735. }
  3736. static int benchmark_test_threaded(void* args)
  3737. {
  3738. int i;
  3739. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3740. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3741. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3742. if (g_threadData == NULL) {
  3743. printf("%sThread data alloc failed!\n", err_prefix);
  3744. return EXIT_FAILURE;
  3745. }
  3746. for (i = 0; i < g_threadCount; i++) {
  3747. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3748. NULL, run_bench, args));
  3749. }
  3750. for (i = 0; i < g_threadCount; i++) {
  3751. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3752. }
  3753. printf("\n");
  3754. bench_stats_print();
  3755. return 0;
  3756. }
  3757. #endif
  3758. /* so embedded projects can pull in tests on their own */
  3759. #ifdef HAVE_STACK_SIZE
  3760. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3761. #else
  3762. int benchmark_test(void *args)
  3763. #endif
  3764. {
  3765. int ret;
  3766. (void)args;
  3767. #ifdef HAVE_FIPS
  3768. wolfCrypt_SetCb_fips(myFipsCb);
  3769. #endif
  3770. ret = benchmark_init();
  3771. if (ret != 0)
  3772. EXIT_TEST(ret);
  3773. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3774. {
  3775. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3776. **
  3777. ** Chapter Two, Build Options:
  3778. **
  3779. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3780. **
  3781. ** asynchronous cryptography using hardware based adapters such as
  3782. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3783. */
  3784. int i;
  3785. if (g_threadCount == 0) {
  3786. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3787. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3788. #else
  3789. g_threadCount = wc_AsyncGetNumberOfCpus();
  3790. if (g_threadCount > 0) {
  3791. g_threadCount /= 2; /* use physical core count */
  3792. }
  3793. #endif
  3794. }
  3795. if (g_threadCount <= 0) {
  3796. g_threadCount = 1;
  3797. }
  3798. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3799. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3800. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3801. if (g_threadData == NULL) {
  3802. printf("%sThread data alloc failed!\n", err_prefix);
  3803. EXIT_TEST(EXIT_FAILURE);
  3804. }
  3805. /* Create threads */
  3806. for (i = 0; i < g_threadCount; i++) {
  3807. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3808. benchmarks_do, &g_threadData[i]);
  3809. if (ret != 0) {
  3810. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3811. EXIT_TEST(EXIT_FAILURE);
  3812. }
  3813. }
  3814. /* Start threads */
  3815. for (i = 0; i < g_threadCount; i++) {
  3816. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3817. }
  3818. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3819. }
  3820. #else
  3821. benchmarks_do(NULL);
  3822. #endif
  3823. SLEEP_ON_ERROR(1);
  3824. printf("%sBenchmark complete\n", info_prefix);
  3825. ret = benchmark_free();
  3826. EXIT_TEST(ret);
  3827. }
  3828. #ifndef WC_NO_RNG
  3829. void bench_rng(void)
  3830. {
  3831. int ret, i, count;
  3832. double start;
  3833. long pos, len, remain;
  3834. WC_RNG myrng;
  3835. DECLARE_MULTI_VALUE_STATS_VARS()
  3836. #ifndef HAVE_FIPS
  3837. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3838. #else
  3839. ret = wc_InitRng(&myrng);
  3840. #endif
  3841. if (ret < 0) {
  3842. printf("InitRNG failed %d\n", ret);
  3843. return;
  3844. }
  3845. bench_stats_start(&count, &start);
  3846. do {
  3847. for (i = 0; i < numBlocks; i++) {
  3848. /* Split request to handle large RNG request */
  3849. pos = 0;
  3850. remain = (int)bench_size;
  3851. while (remain > 0) {
  3852. len = remain;
  3853. if (len > RNG_MAX_BLOCK_LEN)
  3854. len = RNG_MAX_BLOCK_LEN;
  3855. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3856. (word32)len);
  3857. if (ret < 0)
  3858. goto exit_rng;
  3859. remain -= len;
  3860. pos += len;
  3861. }
  3862. RECORD_MULTI_VALUE_STATS();
  3863. }
  3864. count += i;
  3865. } while (bench_stats_check(start)
  3866. #ifdef MULTI_VALUE_STATISTICS
  3867. || runs < minimum_runs
  3868. #endif
  3869. );
  3870. exit_rng:
  3871. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3872. #ifdef MULTI_VALUE_STATISTICS
  3873. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3874. #endif
  3875. wc_FreeRng(&myrng);
  3876. }
  3877. #endif /* WC_NO_RNG */
  3878. #ifndef NO_AES
  3879. #ifdef HAVE_AES_CBC
  3880. static void bench_aescbc_internal(int useDeviceID,
  3881. const byte* key, word32 keySz,
  3882. const byte* iv, const char* encLabel,
  3883. const char* decLabel)
  3884. {
  3885. const byte* in = bench_cipher;
  3886. byte* out = bench_plain;
  3887. int ret = 0, i, count = 0, times, pending = 0;
  3888. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3889. sizeof(Aes), HEAP_HINT);
  3890. double start;
  3891. DECLARE_MULTI_VALUE_STATS_VARS()
  3892. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3893. sizeof(Aes), HEAP_HINT);
  3894. /* init keys */
  3895. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3896. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3897. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3898. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3899. goto exit;
  3900. }
  3901. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3902. if (ret != 0) {
  3903. printf("AesSetKey failed, ret = %d\n", ret);
  3904. goto exit;
  3905. }
  3906. }
  3907. if (cipher_same_buffer) {
  3908. in = bench_plain;
  3909. }
  3910. bench_stats_start(&count, &start);
  3911. do {
  3912. for (times = 0; times < numBlocks || pending > 0; ) {
  3913. bench_async_poll(&pending);
  3914. /* while free pending slots in queue, submit ops */
  3915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3917. &times, numBlocks, &pending)) {
  3918. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3919. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3920. 0, &times, &pending)) {
  3921. goto exit_aes_enc;
  3922. }
  3923. }
  3924. } /* for i */
  3925. RECORD_MULTI_VALUE_STATS();
  3926. } /* for times */
  3927. count += times;
  3928. } while (bench_stats_check(start)
  3929. #ifdef MULTI_VALUE_STATISTICS
  3930. || runs < minimum_runs
  3931. #endif
  3932. );
  3933. exit_aes_enc:
  3934. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3935. bench_size, start, ret);
  3936. #ifdef MULTI_VALUE_STATISTICS
  3937. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3938. #endif
  3939. if (ret < 0) {
  3940. goto exit;
  3941. }
  3942. #ifdef HAVE_AES_DECRYPT
  3943. /* init keys */
  3944. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3945. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3946. if (ret != 0) {
  3947. printf("AesSetKey failed, ret = %d\n", ret);
  3948. goto exit;
  3949. }
  3950. }
  3951. RESET_MULTI_VALUE_STATS_VARS();
  3952. bench_stats_start(&count, &start);
  3953. do {
  3954. for (times = 0; times < numBlocks || pending > 0; ) {
  3955. bench_async_poll(&pending);
  3956. /* while free pending slots in queue, submit ops */
  3957. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3958. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3959. &times, numBlocks, &pending)) {
  3960. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3961. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3962. 0, &times, &pending)) {
  3963. goto exit_aes_dec;
  3964. }
  3965. }
  3966. } /* for i */
  3967. RECORD_MULTI_VALUE_STATS();
  3968. } /* for times */
  3969. count += times;
  3970. } while (bench_stats_check(start)
  3971. #ifdef MULTI_VALUE_STATISTICS
  3972. || runs < minimum_runs
  3973. #endif
  3974. );
  3975. exit_aes_dec:
  3976. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3977. start, ret);
  3978. #ifdef MULTI_VALUE_STATISTICS
  3979. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3980. #endif
  3981. #endif /* HAVE_AES_DECRYPT */
  3982. (void)decLabel;
  3983. exit:
  3984. if (WC_ARRAY_OK(enc)) {
  3985. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3986. wc_AesFree(enc[i]);
  3987. }
  3988. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3989. }
  3990. }
  3991. void bench_aescbc(int useDeviceID)
  3992. {
  3993. #ifdef WOLFSSL_AES_128
  3994. #ifdef HAVE_RENESAS_SYNC
  3995. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3996. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3997. #else
  3998. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3999. "AES-128-CBC-enc", "AES-128-CBC-dec");
  4000. #endif
  4001. #endif
  4002. #ifdef WOLFSSL_AES_192
  4003. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  4004. "AES-192-CBC-enc", "AES-192-CBC-dec");
  4005. #endif
  4006. #ifdef WOLFSSL_AES_256
  4007. #ifdef HAVE_RENESAS_SYNC
  4008. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  4009. "AES-256-CBC-enc", "AES-256-CBC-dec");
  4010. #else
  4011. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  4012. "AES-256-CBC-enc", "AES-256-CBC-dec");
  4013. #endif
  4014. #endif
  4015. }
  4016. #endif /* HAVE_AES_CBC */
  4017. #ifdef HAVE_AESGCM
  4018. static void bench_aesgcm_internal(int useDeviceID,
  4019. const byte* key, word32 keySz,
  4020. const byte* iv, word32 ivSz,
  4021. const char* encLabel, const char* decLabel)
  4022. {
  4023. int ret = 0, i, count = 0, times, pending = 0;
  4024. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4025. sizeof(Aes), HEAP_HINT);
  4026. #ifdef HAVE_AES_DECRYPT
  4027. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4028. sizeof(Aes), HEAP_HINT);
  4029. #endif
  4030. double start;
  4031. DECLARE_MULTI_VALUE_STATS_VARS()
  4032. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4033. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4034. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4035. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4036. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4037. sizeof(Aes), HEAP_HINT);
  4038. #ifdef HAVE_AES_DECRYPT
  4039. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4040. sizeof(Aes), HEAP_HINT);
  4041. #endif
  4042. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4043. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4044. /* init keys */
  4045. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4046. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4047. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4048. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4049. goto exit;
  4050. }
  4051. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4052. if (ret != 0) {
  4053. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4054. goto exit;
  4055. }
  4056. }
  4057. /* GCM uses same routine in backend for both encrypt and decrypt */
  4058. bench_stats_start(&count, &start);
  4059. do {
  4060. for (times = 0; times < numBlocks || pending > 0; ) {
  4061. bench_async_poll(&pending);
  4062. /* while free pending slots in queue, submit ops */
  4063. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4064. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4065. &times, numBlocks, &pending)) {
  4066. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4067. bench_plain, bench_size,
  4068. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4069. bench_additional, aesAuthAddSz);
  4070. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4071. 0, &times, &pending)) {
  4072. goto exit_aes_gcm;
  4073. }
  4074. }
  4075. } /* for i */
  4076. RECORD_MULTI_VALUE_STATS();
  4077. } /* for times */
  4078. count += times;
  4079. } while (bench_stats_check(start)
  4080. #ifdef MULTI_VALUE_STATISTICS
  4081. || runs < minimum_runs
  4082. #endif
  4083. );
  4084. exit_aes_gcm:
  4085. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4086. start, ret);
  4087. #ifdef MULTI_VALUE_STATISTICS
  4088. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4089. #endif
  4090. #ifdef HAVE_AES_DECRYPT
  4091. RESET_MULTI_VALUE_STATS_VARS();
  4092. /* init keys */
  4093. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4094. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4095. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4096. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4097. goto exit;
  4098. }
  4099. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4100. if (ret != 0) {
  4101. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4102. goto exit;
  4103. }
  4104. }
  4105. bench_stats_start(&count, &start);
  4106. do {
  4107. for (times = 0; times < numBlocks || pending > 0; ) {
  4108. bench_async_poll(&pending);
  4109. /* while free pending slots in queue, submit ops */
  4110. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4111. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4112. &times, numBlocks, &pending)) {
  4113. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4114. bench_cipher, bench_size,
  4115. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4116. bench_additional, aesAuthAddSz);
  4117. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4118. 0, &times, &pending)) {
  4119. goto exit_aes_gcm_dec;
  4120. }
  4121. }
  4122. } /* for i */
  4123. RECORD_MULTI_VALUE_STATS();
  4124. } /* for times */
  4125. count += times;
  4126. } while (bench_stats_check(start)
  4127. #ifdef MULTI_VALUE_STATISTICS
  4128. || runs < minimum_runs
  4129. #endif
  4130. );
  4131. exit_aes_gcm_dec:
  4132. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4133. start, ret);
  4134. #ifdef MULTI_VALUE_STATISTICS
  4135. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4136. #endif
  4137. #endif /* HAVE_AES_DECRYPT */
  4138. (void)decLabel;
  4139. exit:
  4140. if (ret < 0) {
  4141. printf("bench_aesgcm failed: %d\n", ret);
  4142. }
  4143. #ifdef HAVE_AES_DECRYPT
  4144. if (WC_ARRAY_OK(dec)) {
  4145. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4146. wc_AesFree(dec[i]);
  4147. }
  4148. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4149. }
  4150. #endif
  4151. if (WC_ARRAY_OK(enc)) {
  4152. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4153. wc_AesFree(enc[i]);
  4154. }
  4155. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4156. }
  4157. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4158. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4159. }
  4160. #ifdef WOLFSSL_AESGCM_STREAM
  4161. static void bench_aesgcm_stream_internal(int useDeviceID,
  4162. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4163. const char* encLabel, const char* decLabel)
  4164. {
  4165. int ret = 0, i, count = 0, times, pending = 0;
  4166. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4167. sizeof(Aes), HEAP_HINT);
  4168. #ifdef HAVE_AES_DECRYPT
  4169. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4170. sizeof(Aes), HEAP_HINT);
  4171. #endif
  4172. double start;
  4173. DECLARE_MULTI_VALUE_STATS_VARS()
  4174. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4175. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4176. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4177. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4178. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4179. sizeof(Aes), HEAP_HINT);
  4180. #ifdef HAVE_AES_DECRYPT
  4181. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4182. sizeof(Aes), HEAP_HINT);
  4183. #endif
  4184. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4185. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4186. /* init keys */
  4187. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4188. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4189. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4190. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4191. goto exit;
  4192. }
  4193. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4194. if (ret != 0) {
  4195. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4196. goto exit;
  4197. }
  4198. }
  4199. /* GCM uses same routine in backend for both encrypt and decrypt */
  4200. bench_stats_start(&count, &start);
  4201. do {
  4202. for (times = 0; times < numBlocks || pending > 0; ) {
  4203. bench_async_poll(&pending);
  4204. /* while free pending slots in queue, submit ops */
  4205. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4206. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4207. &times, numBlocks, &pending)) {
  4208. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4209. if (ret == 0) {
  4210. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4211. bench_plain, bench_size, bench_additional,
  4212. aesAuthAddSz);
  4213. }
  4214. if (ret == 0) {
  4215. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4216. AES_AUTH_TAG_SZ);
  4217. }
  4218. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4219. 0, &times, &pending)) {
  4220. goto exit_aes_gcm;
  4221. }
  4222. }
  4223. } /* for i */
  4224. RECORD_MULTI_VALUE_STATS();
  4225. } /* for times */
  4226. count += times;
  4227. } while (bench_stats_check(start)
  4228. #ifdef MULTI_VALUE_STATISTICS
  4229. || runs < minimum_runs
  4230. #endif
  4231. );
  4232. exit_aes_gcm:
  4233. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4234. start, ret);
  4235. #ifdef MULTI_VALUE_STATISTICS
  4236. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4237. #endif
  4238. #ifdef HAVE_AES_DECRYPT
  4239. /* init keys */
  4240. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4241. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4242. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4243. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4244. goto exit;
  4245. }
  4246. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4247. if (ret != 0) {
  4248. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4249. goto exit;
  4250. }
  4251. }
  4252. RESET_MULTI_VALUE_STATS_VARS();
  4253. bench_stats_start(&count, &start);
  4254. do {
  4255. for (times = 0; times < numBlocks || pending > 0; ) {
  4256. bench_async_poll(&pending);
  4257. /* while free pending slots in queue, submit ops */
  4258. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4259. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4260. &times, numBlocks, &pending)) {
  4261. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4262. if (ret == 0) {
  4263. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4264. bench_cipher, bench_size, bench_additional,
  4265. aesAuthAddSz);
  4266. }
  4267. if (ret == 0) {
  4268. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4269. AES_AUTH_TAG_SZ);
  4270. }
  4271. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4272. 0, &times, &pending)) {
  4273. goto exit_aes_gcm_dec;
  4274. }
  4275. }
  4276. } /* for i */
  4277. RECORD_MULTI_VALUE_STATS();
  4278. } /* for times */
  4279. count += times;
  4280. } while (bench_stats_check(start)
  4281. #ifdef MULTI_VALUE_STATISTICS
  4282. || runs < minimum_runs
  4283. #endif
  4284. );
  4285. exit_aes_gcm_dec:
  4286. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4287. start, ret);
  4288. #ifdef MULTI_VALUE_STATISTICS
  4289. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4290. #endif
  4291. #endif /* HAVE_AES_DECRYPT */
  4292. (void)decLabel;
  4293. exit:
  4294. if (ret < 0) {
  4295. printf("bench_aesgcm failed: %d\n", ret);
  4296. }
  4297. #ifdef HAVE_AES_DECRYPT
  4298. if (WC_ARRAY_OK(dec)) {
  4299. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4300. wc_AesFree(dec[i]);
  4301. }
  4302. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4303. }
  4304. #endif
  4305. if (WC_ARRAY_OK(enc)) {
  4306. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4307. wc_AesFree(enc[i]);
  4308. }
  4309. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4310. }
  4311. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4312. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4313. }
  4314. #endif
  4315. void bench_aesgcm(int useDeviceID)
  4316. {
  4317. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4318. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4319. && !defined(WOLFSSL_XILINX_CRYPT) \
  4320. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4321. #ifdef HAVE_RENESAS_SYNC
  4322. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4323. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4324. #else
  4325. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4326. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4327. #endif
  4328. #endif
  4329. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4330. && !defined(WOLFSSL_XILINX_CRYPT)
  4331. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4332. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4333. #endif
  4334. #ifdef WOLFSSL_AES_256
  4335. #ifdef HAVE_RENESAS_SYNC
  4336. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4337. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4338. #else
  4339. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4340. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4341. #endif
  4342. #endif
  4343. #ifdef WOLFSSL_AESGCM_STREAM
  4344. #undef AES_GCM_STRING
  4345. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4346. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4347. && !defined(WOLFSSL_XILINX_CRYPT) \
  4348. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4349. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4350. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4351. #endif
  4352. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4353. && !defined(WOLFSSL_XILINX_CRYPT)
  4354. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4355. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4356. #endif
  4357. #ifdef WOLFSSL_AES_256
  4358. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4359. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4360. #endif
  4361. #endif /* WOLFSSL_AESGCM_STREAM */
  4362. #undef AES_GCM_STRING
  4363. }
  4364. /* GMAC */
  4365. void bench_gmac(int useDeviceID)
  4366. {
  4367. int ret, count = 0;
  4368. Gmac gmac;
  4369. double start;
  4370. byte tag[AES_AUTH_TAG_SZ];
  4371. DECLARE_MULTI_VALUE_STATS_VARS()
  4372. /* determine GCM GHASH method */
  4373. #ifdef GCM_SMALL
  4374. const char* gmacStr = "GMAC Small";
  4375. #elif defined(GCM_TABLE)
  4376. const char* gmacStr = "GMAC Table";
  4377. #elif defined(GCM_TABLE_4BIT)
  4378. const char* gmacStr = "GMAC Table 4-bit";
  4379. #elif defined(GCM_WORD32)
  4380. const char* gmacStr = "GMAC Word32";
  4381. #else
  4382. const char* gmacStr = "GMAC Default";
  4383. #endif
  4384. /* Implementations of /Dev/Crypto will error out if the size of Auth in is */
  4385. /* greater than the system's page size */
  4386. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  4387. bench_size = WOLFSSL_AUTHSZ_BENCH;
  4388. #elif defined(WOLFSSL_DEVCRYPTO)
  4389. bench_size = sysconf(_SC_PAGESIZE);
  4390. #endif
  4391. /* init keys */
  4392. XMEMSET(bench_plain, 0, bench_size);
  4393. XMEMSET(tag, 0, sizeof(tag));
  4394. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4395. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4396. useDeviceID ? devId: INVALID_DEVID);
  4397. #ifdef HAVE_RENESAS_SYNC
  4398. wc_GmacSetKey(&gmac, bench_key1, 16);
  4399. #else
  4400. wc_GmacSetKey(&gmac, bench_key, 16);
  4401. #endif
  4402. bench_stats_start(&count, &start);
  4403. do {
  4404. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4405. tag, sizeof(tag));
  4406. count++;
  4407. RECORD_MULTI_VALUE_STATS();
  4408. } while (bench_stats_check(start)
  4409. #ifdef MULTI_VALUE_STATISTICS
  4410. || runs < minimum_runs
  4411. #endif
  4412. );
  4413. wc_AesFree((Aes*)&gmac);
  4414. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4415. #ifdef MULTI_VALUE_STATISTICS
  4416. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4417. #endif
  4418. #if defined(WOLFSSL_DEVCRYPTO)
  4419. if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) {
  4420. printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n",
  4421. bench_size, sysconf(_SC_PAGESIZE));
  4422. }
  4423. bench_size = BENCH_SIZE;
  4424. #endif
  4425. }
  4426. #endif /* HAVE_AESGCM */
  4427. #ifdef HAVE_AES_ECB
  4428. static void bench_aesecb_internal(int useDeviceID,
  4429. const byte* key, word32 keySz,
  4430. const char* encLabel, const char* decLabel)
  4431. {
  4432. int ret = 0, i, count = 0, times, pending = 0;
  4433. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4434. sizeof(Aes), HEAP_HINT);
  4435. double start;
  4436. DECLARE_MULTI_VALUE_STATS_VARS()
  4437. #ifdef HAVE_FIPS
  4438. const word32 benchSz = WC_AES_BLOCK_SIZE;
  4439. #else
  4440. const word32 benchSz = bench_size;
  4441. #endif
  4442. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4443. sizeof(Aes), HEAP_HINT);
  4444. /* init keys */
  4445. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4446. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4447. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4448. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4449. goto exit;
  4450. }
  4451. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4452. if (ret != 0) {
  4453. printf("AesSetKey failed, ret = %d\n", ret);
  4454. goto exit;
  4455. }
  4456. }
  4457. bench_stats_start(&count, &start);
  4458. do {
  4459. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4460. for (times = 0;
  4461. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4462. ) {
  4463. bench_async_poll(&pending);
  4464. /* while free pending slots in queue, submit ops */
  4465. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4466. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4467. &times, outer_loop_limit, &pending)) {
  4468. #ifdef HAVE_FIPS
  4469. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4470. #else
  4471. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4472. benchSz);
  4473. #endif
  4474. ret = 0;
  4475. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4476. 0, &times, &pending)) {
  4477. goto exit_aes_enc;
  4478. }
  4479. }
  4480. } /* for i */
  4481. RECORD_MULTI_VALUE_STATS();
  4482. } /* for times */
  4483. count += times;
  4484. } while (bench_stats_check(start)
  4485. #ifdef MULTI_VALUE_STATISTICS
  4486. || runs < minimum_runs
  4487. #endif
  4488. );
  4489. exit_aes_enc:
  4490. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4491. start, ret);
  4492. #ifdef MULTI_VALUE_STATISTICS
  4493. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4494. #endif
  4495. #ifdef HAVE_AES_DECRYPT
  4496. /* init keys */
  4497. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4498. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4499. if (ret != 0) {
  4500. printf("AesSetKey failed, ret = %d\n", ret);
  4501. goto exit;
  4502. }
  4503. }
  4504. RESET_MULTI_VALUE_STATS_VARS();
  4505. bench_stats_start(&count, &start);
  4506. do {
  4507. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4508. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4509. bench_async_poll(&pending);
  4510. /* while free pending slots in queue, submit ops */
  4511. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4512. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4513. &times, outer_loop_limit, &pending)) {
  4514. #ifdef HAVE_FIPS
  4515. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4516. #else
  4517. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4518. benchSz);
  4519. #endif
  4520. ret = 0;
  4521. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4522. 0, &times, &pending)) {
  4523. goto exit_aes_dec;
  4524. }
  4525. }
  4526. } /* for i */
  4527. RECORD_MULTI_VALUE_STATS();
  4528. } /* for times */
  4529. count += times;
  4530. } while (bench_stats_check(start)
  4531. #ifdef MULTI_VALUE_STATISTICS
  4532. || runs < minimum_runs
  4533. #endif
  4534. );
  4535. exit_aes_dec:
  4536. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4537. start, ret);
  4538. #ifdef MULTI_VALUE_STATISTICS
  4539. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4540. #endif
  4541. #endif /* HAVE_AES_DECRYPT */
  4542. (void)decLabel;
  4543. exit:
  4544. if (WC_ARRAY_OK(enc)) {
  4545. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4546. wc_AesFree(enc[i]);
  4547. }
  4548. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4549. }
  4550. }
  4551. void bench_aesecb(int useDeviceID)
  4552. {
  4553. #ifdef WOLFSSL_AES_128
  4554. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4555. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4556. #endif
  4557. #ifdef WOLFSSL_AES_192
  4558. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4559. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4560. #endif
  4561. #ifdef WOLFSSL_AES_256
  4562. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4563. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4564. #endif
  4565. }
  4566. #endif /* HAVE_AES_ECB */
  4567. #ifdef WOLFSSL_AES_CFB
  4568. static void bench_aescfb_internal(const byte* key,
  4569. word32 keySz, const byte* iv,
  4570. const char* label)
  4571. {
  4572. Aes enc;
  4573. double start;
  4574. int i, ret, count;
  4575. DECLARE_MULTI_VALUE_STATS_VARS()
  4576. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4577. if (ret != 0) {
  4578. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4579. return;
  4580. }
  4581. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4582. if (ret != 0) {
  4583. printf("AesSetKey failed, ret = %d\n", ret);
  4584. goto out;
  4585. }
  4586. bench_stats_start(&count, &start);
  4587. do {
  4588. for (i = 0; i < numBlocks; i++) {
  4589. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4590. bench_size)) != 0) {
  4591. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4592. goto out;
  4593. }
  4594. RECORD_MULTI_VALUE_STATS();
  4595. }
  4596. count += i;
  4597. } while (bench_stats_check(start)
  4598. #ifdef MULTI_VALUE_STATISTICS
  4599. || runs < minimum_runs
  4600. #endif
  4601. );
  4602. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4603. #ifdef MULTI_VALUE_STATISTICS
  4604. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4605. #endif
  4606. out:
  4607. wc_AesFree(&enc);
  4608. return;
  4609. }
  4610. void bench_aescfb(void)
  4611. {
  4612. #ifdef WOLFSSL_AES_128
  4613. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4614. #endif
  4615. #ifdef WOLFSSL_AES_192
  4616. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4617. #endif
  4618. #ifdef WOLFSSL_AES_256
  4619. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4620. #endif
  4621. }
  4622. #endif /* WOLFSSL_AES_CFB */
  4623. #ifdef WOLFSSL_AES_OFB
  4624. static void bench_aesofb_internal(const byte* key,
  4625. word32 keySz, const byte* iv,
  4626. const char* label)
  4627. {
  4628. Aes enc;
  4629. double start;
  4630. int i, ret, count;
  4631. DECLARE_MULTI_VALUE_STATS_VARS()
  4632. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4633. if (ret != 0) {
  4634. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4635. return;
  4636. }
  4637. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4638. if (ret != 0) {
  4639. printf("AesSetKey failed, ret = %d\n", ret);
  4640. return;
  4641. }
  4642. bench_stats_start(&count, &start);
  4643. do {
  4644. for (i = 0; i < numBlocks; i++) {
  4645. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4646. bench_size)) != 0) {
  4647. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4648. return;
  4649. }
  4650. RECORD_MULTI_VALUE_STATS();
  4651. }
  4652. count += i;
  4653. } while (bench_stats_check(start)
  4654. #ifdef MULTI_VALUE_STATISTICS
  4655. || runs < minimum_runs
  4656. #endif
  4657. );
  4658. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4659. #ifdef MULTI_VALUE_STATISTICS
  4660. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4661. #endif
  4662. wc_AesFree(&enc);
  4663. }
  4664. void bench_aesofb(void)
  4665. {
  4666. #ifdef WOLFSSL_AES_128
  4667. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4668. #endif
  4669. #ifdef WOLFSSL_AES_192
  4670. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4671. #endif
  4672. #ifdef WOLFSSL_AES_256
  4673. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4674. #endif
  4675. }
  4676. #endif /* WOLFSSL_AES_CFB */
  4677. #ifdef WOLFSSL_AES_XTS
  4678. void bench_aesxts(void)
  4679. {
  4680. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4681. double start;
  4682. int i, count, ret;
  4683. DECLARE_MULTI_VALUE_STATS_VARS()
  4684. static const unsigned char k1[] = {
  4685. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4686. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4687. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4688. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4689. };
  4690. static const unsigned char i1[] = {
  4691. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4692. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4693. };
  4694. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4695. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4696. HEAP_HINT, devId);
  4697. if (ret != 0) {
  4698. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4699. goto exit;
  4700. }
  4701. bench_stats_start(&count, &start);
  4702. do {
  4703. for (i = 0; i < numBlocks; i++) {
  4704. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4705. bench_size, i1, sizeof(i1))) != 0) {
  4706. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4707. goto exit;
  4708. }
  4709. RECORD_MULTI_VALUE_STATS();
  4710. }
  4711. count += i;
  4712. } while (bench_stats_check(start)
  4713. #ifdef MULTI_VALUE_STATISTICS
  4714. || runs < minimum_runs
  4715. #endif
  4716. );
  4717. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4718. #ifdef MULTI_VALUE_STATISTICS
  4719. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4720. #endif
  4721. wc_AesXtsFree(aes);
  4722. /* decryption benchmark */
  4723. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4724. HEAP_HINT, devId);
  4725. if (ret != 0) {
  4726. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4727. goto exit;
  4728. }
  4729. RESET_MULTI_VALUE_STATS_VARS();
  4730. bench_stats_start(&count, &start);
  4731. do {
  4732. for (i = 0; i < numBlocks; i++) {
  4733. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4734. bench_size, i1, sizeof(i1))) != 0) {
  4735. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4736. goto exit;
  4737. }
  4738. RECORD_MULTI_VALUE_STATS();
  4739. }
  4740. count += i;
  4741. } while (bench_stats_check(start)
  4742. #ifdef MULTI_VALUE_STATISTICS
  4743. || runs < minimum_runs
  4744. #endif
  4745. );
  4746. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4747. #ifdef MULTI_VALUE_STATISTICS
  4748. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4749. #endif
  4750. exit:
  4751. wc_AesXtsFree(aes);
  4752. WC_FREE_VAR(aes, HEAP_HINT);
  4753. }
  4754. #endif /* WOLFSSL_AES_XTS */
  4755. #ifdef WOLFSSL_AES_COUNTER
  4756. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4757. const byte* iv, const char* label,
  4758. int useDeviceID)
  4759. {
  4760. Aes enc;
  4761. double start;
  4762. int i, count, ret = 0;
  4763. DECLARE_MULTI_VALUE_STATS_VARS()
  4764. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4765. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4766. printf("wc_AesInit failed, ret = %d\n", ret);
  4767. }
  4768. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4769. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4770. return;
  4771. }
  4772. bench_stats_start(&count, &start);
  4773. do {
  4774. for (i = 0; i < numBlocks; i++) {
  4775. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4776. bench_size)) != 0) {
  4777. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4778. return;
  4779. }
  4780. RECORD_MULTI_VALUE_STATS();
  4781. }
  4782. count += i;
  4783. } while (bench_stats_check(start)
  4784. #ifdef MULTI_VALUE_STATISTICS
  4785. || runs < minimum_runs
  4786. #endif
  4787. );
  4788. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4789. #ifdef MULTI_VALUE_STATISTICS
  4790. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4791. #endif
  4792. wc_AesFree(&enc);
  4793. }
  4794. void bench_aesctr(int useDeviceID)
  4795. {
  4796. #ifdef WOLFSSL_AES_128
  4797. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4798. #endif
  4799. #ifdef WOLFSSL_AES_192
  4800. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4801. #endif
  4802. #ifdef WOLFSSL_AES_256
  4803. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4804. #endif
  4805. }
  4806. #endif /* WOLFSSL_AES_COUNTER */
  4807. #ifdef HAVE_AESCCM
  4808. void bench_aesccm(int useDeviceID)
  4809. {
  4810. Aes enc;
  4811. int enc_inited = 0;
  4812. double start;
  4813. int ret, i, count;
  4814. DECLARE_MULTI_VALUE_STATS_VARS()
  4815. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4816. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4817. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4818. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4819. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4820. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4821. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4822. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4823. {
  4824. printf("wc_AesInit failed, ret = %d\n", ret);
  4825. goto exit;
  4826. }
  4827. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4828. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4829. goto exit;
  4830. }
  4831. enc_inited = 1;
  4832. bench_stats_start(&count, &start);
  4833. do {
  4834. for (i = 0; i < numBlocks; i++) {
  4835. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4836. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4837. bench_additional, 0);
  4838. RECORD_MULTI_VALUE_STATS();
  4839. }
  4840. count += i;
  4841. } while (bench_stats_check(start)
  4842. #ifdef MULTI_VALUE_STATISTICS
  4843. || runs < minimum_runs
  4844. #endif
  4845. );
  4846. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4847. bench_size, start, ret);
  4848. #ifdef MULTI_VALUE_STATISTICS
  4849. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4850. #endif
  4851. if (ret != 0) {
  4852. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4853. goto exit;
  4854. }
  4855. #ifdef HAVE_AES_DECRYPT
  4856. RESET_MULTI_VALUE_STATS_VARS();
  4857. bench_stats_start(&count, &start);
  4858. do {
  4859. for (i = 0; i < numBlocks; i++) {
  4860. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4861. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4862. bench_additional, 0);
  4863. RECORD_MULTI_VALUE_STATS();
  4864. }
  4865. count += i;
  4866. } while (bench_stats_check(start)
  4867. #ifdef MULTI_VALUE_STATISTICS
  4868. || runs < minimum_runs
  4869. #endif
  4870. );
  4871. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4872. bench_size, start, ret);
  4873. #ifdef MULTI_VALUE_STATISTICS
  4874. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4875. #endif
  4876. if (ret != 0) {
  4877. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4878. goto exit;
  4879. }
  4880. #endif
  4881. exit:
  4882. if (enc_inited)
  4883. wc_AesFree(&enc);
  4884. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4885. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4886. }
  4887. #endif /* HAVE_AESCCM */
  4888. #ifdef WOLFSSL_AES_SIV
  4889. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4890. encLabel, const char* decLabel)
  4891. {
  4892. int i;
  4893. int ret = 0;
  4894. byte assoc[WC_AES_BLOCK_SIZE];
  4895. byte nonce[WC_AES_BLOCK_SIZE];
  4896. byte siv[WC_AES_BLOCK_SIZE];
  4897. int count = 0;
  4898. double start;
  4899. DECLARE_MULTI_VALUE_STATS_VARS()
  4900. bench_stats_start(&count, &start);
  4901. do {
  4902. for (i = 0; i < numBlocks; i++) {
  4903. ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4904. WC_AES_BLOCK_SIZE, bench_plain, bench_size,
  4905. siv, bench_cipher);
  4906. if (ret != 0) {
  4907. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4908. return;
  4909. }
  4910. RECORD_MULTI_VALUE_STATS();
  4911. }
  4912. count += i;
  4913. } while (bench_stats_check(start)
  4914. #ifdef MULTI_VALUE_STATISTICS
  4915. || runs < minimum_runs
  4916. #endif
  4917. );
  4918. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4919. #ifdef MULTI_VALUE_STATISTICS
  4920. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4921. #endif
  4922. RESET_MULTI_VALUE_STATS_VARS();
  4923. bench_stats_start(&count, &start);
  4924. do {
  4925. for (i = 0; i < numBlocks; i++) {
  4926. ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4927. WC_AES_BLOCK_SIZE, bench_cipher, bench_size,
  4928. siv, bench_plain);
  4929. if (ret != 0) {
  4930. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4931. return;
  4932. }
  4933. RECORD_MULTI_VALUE_STATS();
  4934. }
  4935. count += i;
  4936. } while (bench_stats_check(start)
  4937. #ifdef MULTI_VALUE_STATISTICS
  4938. || runs < minimum_runs
  4939. #endif
  4940. );
  4941. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4942. #ifdef MULTI_VALUE_STATISTICS
  4943. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4944. #endif
  4945. }
  4946. void bench_aessiv(void)
  4947. {
  4948. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4949. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4950. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4951. }
  4952. #endif /* WOLFSSL_AES_SIV */
  4953. #endif /* !NO_AES */
  4954. #ifdef HAVE_POLY1305
  4955. void bench_poly1305(void)
  4956. {
  4957. Poly1305 enc;
  4958. byte mac[16];
  4959. double start;
  4960. int ret = 0, i, count;
  4961. DECLARE_MULTI_VALUE_STATS_VARS()
  4962. if (digest_stream) {
  4963. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4964. if (ret != 0) {
  4965. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4966. return;
  4967. }
  4968. bench_stats_start(&count, &start);
  4969. do {
  4970. for (i = 0; i < numBlocks; i++) {
  4971. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4972. if (ret != 0) {
  4973. printf("Poly1305Update failed: %d\n", ret);
  4974. break;
  4975. }
  4976. RECORD_MULTI_VALUE_STATS();
  4977. }
  4978. wc_Poly1305Final(&enc, mac);
  4979. count += i;
  4980. } while (bench_stats_check(start)
  4981. #ifdef MULTI_VALUE_STATISTICS
  4982. || runs < minimum_runs
  4983. #endif
  4984. );
  4985. }
  4986. else {
  4987. bench_stats_start(&count, &start);
  4988. do {
  4989. for (i = 0; i < numBlocks; i++) {
  4990. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4991. if (ret != 0) {
  4992. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4993. return;
  4994. }
  4995. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4996. if (ret != 0) {
  4997. printf("Poly1305Update failed: %d\n", ret);
  4998. break;
  4999. }
  5000. wc_Poly1305Final(&enc, mac);
  5001. RECORD_MULTI_VALUE_STATS();
  5002. }
  5003. count += i;
  5004. } while (bench_stats_check(start)
  5005. #ifdef MULTI_VALUE_STATISTICS
  5006. || runs < minimum_runs
  5007. #endif
  5008. );
  5009. }
  5010. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  5011. #ifdef MULTI_VALUE_STATISTICS
  5012. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5013. #endif
  5014. }
  5015. #endif /* HAVE_POLY1305 */
  5016. #ifdef HAVE_CAMELLIA
  5017. void bench_camellia(void)
  5018. {
  5019. wc_Camellia cam;
  5020. double start;
  5021. int ret, i, count;
  5022. DECLARE_MULTI_VALUE_STATS_VARS()
  5023. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  5024. if (ret != 0) {
  5025. printf("CamelliaSetKey failed, ret = %d\n", ret);
  5026. return;
  5027. }
  5028. bench_stats_start(&count, &start);
  5029. do {
  5030. for (i = 0; i < numBlocks; i++) {
  5031. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  5032. bench_size);
  5033. if (ret < 0) {
  5034. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  5035. return;
  5036. }
  5037. RECORD_MULTI_VALUE_STATS();
  5038. }
  5039. count += i;
  5040. } while (bench_stats_check(start)
  5041. #ifdef MULTI_VALUE_STATISTICS
  5042. || runs < minimum_runs
  5043. #endif
  5044. );
  5045. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  5046. #ifdef MULTI_VALUE_STATISTICS
  5047. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5048. #endif
  5049. }
  5050. #endif
  5051. #ifdef WOLFSSL_SM4_CBC
  5052. void bench_sm4_cbc(void)
  5053. {
  5054. wc_Sm4 sm4;
  5055. double start;
  5056. int ret;
  5057. int i;
  5058. int count;
  5059. DECLARE_MULTI_VALUE_STATS_VARS()
  5060. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5061. if (ret != 0) {
  5062. printf("Sm4SetKey failed, ret = %d\n", ret);
  5063. return;
  5064. }
  5065. ret = wc_Sm4SetIV(&sm4, bench_iv);
  5066. if (ret != 0) {
  5067. printf("Sm4SetIV failed, ret = %d\n", ret);
  5068. return;
  5069. }
  5070. bench_stats_start(&count, &start);
  5071. do {
  5072. for (i = 0; i < numBlocks; i++) {
  5073. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  5074. if (ret < 0) {
  5075. printf("Sm4CbcEncrypt failed: %d\n", ret);
  5076. return;
  5077. }
  5078. RECORD_MULTI_VALUE_STATS();
  5079. }
  5080. count += i;
  5081. } while (bench_stats_check(start)
  5082. #ifdef MULTI_VALUE_STATISTICS
  5083. || runs < minimum_runs
  5084. #endif
  5085. );
  5086. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5087. #ifdef MULTI_VALUE_STATISTICS
  5088. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5089. #endif
  5090. RESET_MULTI_VALUE_STATS_VARS();
  5091. bench_stats_start(&count, &start);
  5092. do {
  5093. for (i = 0; i < numBlocks; i++) {
  5094. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5095. if (ret < 0) {
  5096. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5097. return;
  5098. }
  5099. RECORD_MULTI_VALUE_STATS();
  5100. }
  5101. count += i;
  5102. } while (bench_stats_check(start)
  5103. #ifdef MULTI_VALUE_STATISTICS
  5104. || runs < minimum_runs
  5105. #endif
  5106. );
  5107. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5108. #ifdef MULTI_VALUE_STATISTICS
  5109. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5110. #endif
  5111. }
  5112. #endif
  5113. #ifdef WOLFSSL_SM4_GCM
  5114. void bench_sm4_gcm(void)
  5115. {
  5116. wc_Sm4 sm4;
  5117. double start;
  5118. int ret;
  5119. int i;
  5120. int count;
  5121. DECLARE_MULTI_VALUE_STATS_VARS()
  5122. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5123. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5124. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5125. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5126. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5127. if (ret != 0) {
  5128. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5129. goto exit;
  5130. }
  5131. bench_stats_start(&count, &start);
  5132. do {
  5133. for (i = 0; i < numBlocks; i++) {
  5134. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5135. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5136. bench_additional, aesAuthAddSz);
  5137. if (ret < 0) {
  5138. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5139. goto exit;
  5140. }
  5141. RECORD_MULTI_VALUE_STATS();
  5142. }
  5143. count += i;
  5144. } while (bench_stats_check(start)
  5145. #ifdef MULTI_VALUE_STATISTICS
  5146. || runs < minimum_runs
  5147. #endif
  5148. );
  5149. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5150. #ifdef MULTI_VALUE_STATISTICS
  5151. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5152. #endif
  5153. RESET_MULTI_VALUE_STATS_VARS();
  5154. bench_stats_start(&count, &start);
  5155. do {
  5156. for (i = 0; i < numBlocks; i++) {
  5157. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5158. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5159. bench_additional, aesAuthAddSz);
  5160. if (ret < 0) {
  5161. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5162. goto exit;
  5163. }
  5164. RECORD_MULTI_VALUE_STATS();
  5165. }
  5166. count += i;
  5167. } while (bench_stats_check(start)
  5168. #ifdef MULTI_VALUE_STATISTICS
  5169. || runs < minimum_runs
  5170. #endif
  5171. );
  5172. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5173. #ifdef MULTI_VALUE_STATISTICS
  5174. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5175. #endif
  5176. exit:
  5177. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5178. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5179. }
  5180. #endif
  5181. #ifdef WOLFSSL_SM4_CCM
  5182. void bench_sm4_ccm(void)
  5183. {
  5184. wc_Sm4 enc;
  5185. double start;
  5186. int ret, i, count;
  5187. DECLARE_MULTI_VALUE_STATS_VARS()
  5188. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5189. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5190. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5191. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5192. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5193. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5194. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5195. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5196. goto exit;
  5197. }
  5198. bench_stats_start(&count, &start);
  5199. do {
  5200. for (i = 0; i < numBlocks; i++) {
  5201. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5202. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5203. bench_additional, 0);
  5204. RECORD_MULTI_VALUE_STATS();
  5205. }
  5206. count += i;
  5207. } while (bench_stats_check(start)
  5208. #ifdef MULTI_VALUE_STATISTICS
  5209. || runs < minimum_runs
  5210. #endif
  5211. );
  5212. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5213. #ifdef MULTI_VALUE_STATISTICS
  5214. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5215. #endif
  5216. if (ret != 0) {
  5217. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5218. goto exit;
  5219. }
  5220. RESET_MULTI_VALUE_STATS_VARS();
  5221. bench_stats_start(&count, &start);
  5222. do {
  5223. for (i = 0; i < numBlocks; i++) {
  5224. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5225. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5226. bench_additional, 0);
  5227. RECORD_MULTI_VALUE_STATS();
  5228. }
  5229. count += i;
  5230. } while (bench_stats_check(start)
  5231. #ifdef MULTI_VALUE_STATISTICS
  5232. || runs < minimum_runs
  5233. #endif
  5234. );
  5235. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5236. #ifdef MULTI_VALUE_STATISTICS
  5237. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5238. #endif
  5239. if (ret != 0) {
  5240. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5241. goto exit;
  5242. }
  5243. exit:
  5244. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5245. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5246. }
  5247. #endif /* HAVE_AESCCM */
  5248. #ifndef NO_DES3
  5249. void bench_des(int useDeviceID)
  5250. {
  5251. int ret = 0, i, count = 0, times, pending = 0;
  5252. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5253. sizeof(Des3), HEAP_HINT);
  5254. double start;
  5255. DECLARE_MULTI_VALUE_STATS_VARS()
  5256. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5257. sizeof(Des3), HEAP_HINT);
  5258. /* init keys */
  5259. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5260. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5261. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5262. printf("Des3Init failed, ret = %d\n", ret);
  5263. goto exit;
  5264. }
  5265. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5266. if (ret != 0) {
  5267. printf("Des3_SetKey failed, ret = %d\n", ret);
  5268. goto exit;
  5269. }
  5270. }
  5271. bench_stats_start(&count, &start);
  5272. do {
  5273. for (times = 0; times < numBlocks || pending > 0; ) {
  5274. bench_async_poll(&pending);
  5275. /* while free pending slots in queue, submit ops */
  5276. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5277. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5278. &times, numBlocks, &pending)) {
  5279. ret = wc_Des3_CbcEncrypt(enc[i],
  5280. bench_cipher,
  5281. bench_plain, bench_size);
  5282. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5283. 0, &times, &pending)) {
  5284. goto exit_3des;
  5285. }
  5286. }
  5287. } /* for i */
  5288. RECORD_MULTI_VALUE_STATS();
  5289. } /* for times */
  5290. count += times;
  5291. } while (bench_stats_check(start)
  5292. #ifdef MULTI_VALUE_STATISTICS
  5293. || runs < minimum_runs
  5294. #endif
  5295. );
  5296. exit_3des:
  5297. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5298. #ifdef MULTI_VALUE_STATISTICS
  5299. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5300. #endif
  5301. exit:
  5302. if (WC_ARRAY_OK(enc)) {
  5303. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5304. wc_Des3Free(enc[i]);
  5305. }
  5306. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5307. }
  5308. }
  5309. #endif /* !NO_DES3 */
  5310. #ifndef NO_RC4
  5311. void bench_arc4(int useDeviceID)
  5312. {
  5313. int ret = 0, i, count = 0, times, pending = 0;
  5314. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5315. sizeof(Arc4), HEAP_HINT);
  5316. double start;
  5317. DECLARE_MULTI_VALUE_STATS_VARS()
  5318. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5319. sizeof(Arc4), HEAP_HINT);
  5320. /* init keys */
  5321. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5322. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5323. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5324. printf("Arc4Init failed, ret = %d\n", ret);
  5325. goto exit;
  5326. }
  5327. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5328. if (ret != 0) {
  5329. printf("Arc4SetKey failed, ret = %d\n", ret);
  5330. goto exit;
  5331. }
  5332. }
  5333. bench_stats_start(&count, &start);
  5334. do {
  5335. for (times = 0; times < numBlocks || pending > 0; ) {
  5336. bench_async_poll(&pending);
  5337. /* while free pending slots in queue, submit ops */
  5338. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5339. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5340. &times, numBlocks, &pending)) {
  5341. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5342. bench_size);
  5343. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5344. 0, &times, &pending)) {
  5345. goto exit_arc4;
  5346. }
  5347. }
  5348. } /* for i */
  5349. RECORD_MULTI_VALUE_STATS();
  5350. } /* for times */
  5351. count += times;
  5352. } while (bench_stats_check(start)
  5353. #ifdef MULTI_VALUE_STATISTICS
  5354. || runs < minimum_runs
  5355. #endif
  5356. );
  5357. exit_arc4:
  5358. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5359. #ifdef MULTI_VALUE_STATISTICS
  5360. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5361. #endif
  5362. exit:
  5363. if (WC_ARRAY_OK(enc)) {
  5364. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5365. wc_Arc4Free(enc[i]);
  5366. }
  5367. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5368. }
  5369. }
  5370. #endif /* !NO_RC4 */
  5371. #ifdef HAVE_CHACHA
  5372. void bench_chacha(void)
  5373. {
  5374. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5375. double start;
  5376. int ret, i, count;
  5377. DECLARE_MULTI_VALUE_STATS_VARS()
  5378. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5379. XMEMSET(enc, 0, sizeof(ChaCha));
  5380. wc_Chacha_SetKey(enc, bench_key, 16);
  5381. if (encrypt_only) {
  5382. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5383. if (ret < 0) {
  5384. printf("wc_Chacha_SetIV error: %d\n", ret);
  5385. goto exit;
  5386. }
  5387. bench_stats_start(&count, &start);
  5388. do {
  5389. for (i = 0; i < numBlocks; i++) {
  5390. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5391. bench_size);
  5392. if (ret < 0) {
  5393. printf("wc_Chacha_Process error: %d\n", ret);
  5394. goto exit;
  5395. }
  5396. RECORD_MULTI_VALUE_STATS();
  5397. }
  5398. count += i;
  5399. } while (bench_stats_check(start)
  5400. #ifdef MULTI_VALUE_STATISTICS
  5401. || runs < minimum_runs
  5402. #endif
  5403. );
  5404. }
  5405. else {
  5406. bench_stats_start(&count, &start);
  5407. do {
  5408. for (i = 0; i < numBlocks; i++) {
  5409. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5410. if (ret < 0) {
  5411. printf("wc_Chacha_SetIV error: %d\n", ret);
  5412. goto exit;
  5413. }
  5414. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5415. bench_size);
  5416. if (ret < 0) {
  5417. printf("wc_Chacha_Process error: %d\n", ret);
  5418. goto exit;
  5419. }
  5420. RECORD_MULTI_VALUE_STATS();
  5421. }
  5422. count += i;
  5423. } while (bench_stats_check(start)
  5424. #ifdef MULTI_VALUE_STATISTICS
  5425. || runs < minimum_runs
  5426. #endif
  5427. );
  5428. }
  5429. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5430. #ifdef MULTI_VALUE_STATISTICS
  5431. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5432. #endif
  5433. exit:
  5434. WC_FREE_VAR(enc, HEAP_HINT);
  5435. }
  5436. #endif /* HAVE_CHACHA*/
  5437. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5438. void bench_chacha20_poly1305_aead(void)
  5439. {
  5440. double start;
  5441. int ret = 0, i, count;
  5442. DECLARE_MULTI_VALUE_STATS_VARS()
  5443. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5444. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5445. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5446. bench_stats_start(&count, &start);
  5447. do {
  5448. for (i = 0; i < numBlocks; i++) {
  5449. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5450. bench_plain, bench_size, bench_cipher, authTag);
  5451. if (ret < 0) {
  5452. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5453. goto exit;
  5454. }
  5455. RECORD_MULTI_VALUE_STATS();
  5456. }
  5457. count += i;
  5458. } while (bench_stats_check(start)
  5459. #ifdef MULTI_VALUE_STATISTICS
  5460. || runs < minimum_runs
  5461. #endif
  5462. );
  5463. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5464. #ifdef MULTI_VALUE_STATISTICS
  5465. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5466. #endif
  5467. exit:
  5468. WC_FREE_VAR(authTag, HEAP_HINT);
  5469. }
  5470. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5471. #ifndef NO_MD5
  5472. void bench_md5(int useDeviceID)
  5473. {
  5474. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5475. sizeof(wc_Md5), HEAP_HINT);
  5476. double start = 0;
  5477. int ret = 0, i, count = 0, times, pending = 0;
  5478. DECLARE_MULTI_VALUE_STATS_VARS()
  5479. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5480. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5481. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5482. sizeof(wc_Md5), HEAP_HINT);
  5483. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5484. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5485. if (digest_stream) {
  5486. /* init keys */
  5487. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5488. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5489. useDeviceID ? devId : INVALID_DEVID);
  5490. if (ret != 0) {
  5491. printf("InitMd5_ex failed, ret = %d\n", ret);
  5492. goto exit;
  5493. }
  5494. #ifdef WOLFSSL_PIC32MZ_HASH
  5495. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5496. #endif
  5497. }
  5498. bench_stats_start(&count, &start);
  5499. do {
  5500. for (times = 0; times < numBlocks || pending > 0; ) {
  5501. bench_async_poll(&pending);
  5502. /* while free pending slots in queue, submit ops */
  5503. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5504. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5505. 0, &times, numBlocks, &pending)) {
  5506. ret = wc_Md5Update(hash[i], bench_plain,
  5507. bench_size);
  5508. if (!bench_async_handle(&ret,
  5509. BENCH_ASYNC_GET_DEV(hash[i]),
  5510. 0, &times, &pending)) {
  5511. goto exit_md5;
  5512. }
  5513. }
  5514. } /* for i */
  5515. RECORD_MULTI_VALUE_STATS();
  5516. } /* for times */
  5517. count += times;
  5518. times = 0;
  5519. do {
  5520. bench_async_poll(&pending);
  5521. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5522. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5523. 0, &times, numBlocks, &pending)) {
  5524. ret = wc_Md5Final(hash[i], digest[i]);
  5525. if (!bench_async_handle(&ret,
  5526. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5527. &times, &pending)) {
  5528. goto exit_md5;
  5529. }
  5530. }
  5531. } /* for i */
  5532. } while (pending > 0);
  5533. } while (bench_stats_check(start)
  5534. #ifdef MULTI_VALUE_STATISTICS
  5535. || runs < minimum_runs
  5536. #endif
  5537. );
  5538. }
  5539. else {
  5540. bench_stats_start(&count, &start);
  5541. do {
  5542. for (times = 0; times < numBlocks; times++) {
  5543. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5544. if (ret == 0)
  5545. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5546. if (ret == 0)
  5547. ret = wc_Md5Final(hash[0], digest[0]);
  5548. if (ret != 0)
  5549. goto exit_md5;
  5550. RECORD_MULTI_VALUE_STATS();
  5551. } /* for times */
  5552. count += times;
  5553. } while (bench_stats_check(start)
  5554. #ifdef MULTI_VALUE_STATISTICS
  5555. || runs < minimum_runs
  5556. #endif
  5557. );
  5558. }
  5559. exit_md5:
  5560. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5561. #ifdef MULTI_VALUE_STATISTICS
  5562. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5563. #endif
  5564. exit:
  5565. #ifdef WOLFSSL_ASYNC_CRYPT
  5566. if (WC_ARRAY_OK(hash)) {
  5567. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5568. wc_Md5Free(hash[i]);
  5569. }
  5570. }
  5571. #endif
  5572. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5573. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5574. }
  5575. #endif /* !NO_MD5 */
  5576. #ifndef NO_SHA
  5577. void bench_sha(int useDeviceID)
  5578. {
  5579. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5580. sizeof(wc_Sha), HEAP_HINT);
  5581. double start;
  5582. int ret = 0, i, count = 0, times, pending = 0;
  5583. DECLARE_MULTI_VALUE_STATS_VARS()
  5584. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5585. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5586. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5587. sizeof(wc_Sha), HEAP_HINT);
  5588. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5589. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5590. if (digest_stream) {
  5591. /* init keys */
  5592. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5593. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5594. useDeviceID ? devId : INVALID_DEVID);
  5595. if (ret != 0) {
  5596. printf("InitSha failed, ret = %d\n", ret);
  5597. goto exit;
  5598. }
  5599. #ifdef WOLFSSL_PIC32MZ_HASH
  5600. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5601. #endif
  5602. }
  5603. bench_stats_start(&count, &start);
  5604. do {
  5605. for (times = 0; times < numBlocks || pending > 0; ) {
  5606. bench_async_poll(&pending);
  5607. /* while free pending slots in queue, submit ops */
  5608. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5609. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5610. 0, &times, numBlocks, &pending)) {
  5611. ret = wc_ShaUpdate(hash[i], bench_plain,
  5612. bench_size);
  5613. if (!bench_async_handle(&ret,
  5614. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5615. &times, &pending)) {
  5616. goto exit_sha;
  5617. }
  5618. }
  5619. } /* for i */
  5620. RECORD_MULTI_VALUE_STATS();
  5621. } /* for times */
  5622. count += times;
  5623. times = 0;
  5624. do {
  5625. bench_async_poll(&pending);
  5626. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5627. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5628. 0, &times, numBlocks, &pending)) {
  5629. ret = wc_ShaFinal(hash[i], digest[i]);
  5630. if (!bench_async_handle(&ret,
  5631. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5632. &times, &pending)) {
  5633. goto exit_sha;
  5634. }
  5635. }
  5636. } /* for i */
  5637. } while (pending > 0);
  5638. } while (bench_stats_check(start)
  5639. #ifdef MULTI_VALUE_STATISTICS
  5640. || runs < minimum_runs
  5641. #endif
  5642. );
  5643. }
  5644. else {
  5645. bench_stats_start(&count, &start);
  5646. do {
  5647. for (times = 0; times < numBlocks; times++) {
  5648. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5649. useDeviceID ? devId : INVALID_DEVID);
  5650. if (ret == 0)
  5651. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5652. if (ret == 0)
  5653. ret = wc_ShaFinal(hash[0], digest[0]);
  5654. if (ret != 0)
  5655. goto exit_sha;
  5656. RECORD_MULTI_VALUE_STATS();
  5657. } /* for times */
  5658. count += times;
  5659. } while (bench_stats_check(start)
  5660. #ifdef MULTI_VALUE_STATISTICS
  5661. || runs < minimum_runs
  5662. #endif
  5663. );
  5664. }
  5665. exit_sha:
  5666. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5667. #ifdef MULTI_VALUE_STATISTICS
  5668. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5669. #endif
  5670. exit:
  5671. if (WC_ARRAY_OK(hash)) {
  5672. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5673. wc_ShaFree(hash[i]);
  5674. }
  5675. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5676. }
  5677. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5678. }
  5679. #endif /* NO_SHA */
  5680. #ifdef WOLFSSL_SHA224
  5681. void bench_sha224(int useDeviceID)
  5682. {
  5683. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5684. sizeof(wc_Sha224), HEAP_HINT);
  5685. double start;
  5686. int ret = 0, i, count = 0, times, pending = 0;
  5687. DECLARE_MULTI_VALUE_STATS_VARS()
  5688. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5689. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5690. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5691. sizeof(wc_Sha224), HEAP_HINT);
  5692. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5693. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5694. if (digest_stream) {
  5695. /* init keys */
  5696. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5697. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5698. useDeviceID ? devId : INVALID_DEVID);
  5699. if (ret != 0) {
  5700. printf("InitSha224_ex failed, ret = %d\n", ret);
  5701. goto exit;
  5702. }
  5703. }
  5704. bench_stats_start(&count, &start);
  5705. do {
  5706. for (times = 0; times < numBlocks || pending > 0; ) {
  5707. bench_async_poll(&pending);
  5708. /* while free pending slots in queue, submit ops */
  5709. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5710. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5711. 0, &times, numBlocks, &pending)) {
  5712. ret = wc_Sha224Update(hash[i], bench_plain,
  5713. bench_size);
  5714. if (!bench_async_handle(&ret,
  5715. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5716. &times, &pending)) {
  5717. goto exit_sha224;
  5718. }
  5719. }
  5720. } /* for i */
  5721. RECORD_MULTI_VALUE_STATS();
  5722. } /* for times */
  5723. count += times;
  5724. times = 0;
  5725. do {
  5726. bench_async_poll(&pending);
  5727. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5728. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5729. 0, &times, numBlocks, &pending)) {
  5730. ret = wc_Sha224Final(hash[i], digest[i]);
  5731. if (!bench_async_handle(&ret,
  5732. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5733. &times, &pending)) {
  5734. goto exit_sha224;
  5735. }
  5736. }
  5737. } /* for i */
  5738. } while (pending > 0);
  5739. } while (bench_stats_check(start)
  5740. #ifdef MULTI_VALUE_STATISTICS
  5741. || runs < minimum_runs
  5742. #endif
  5743. );
  5744. }
  5745. else {
  5746. bench_stats_start(&count, &start);
  5747. do {
  5748. for (times = 0; times < numBlocks; times++) {
  5749. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5750. useDeviceID ? devId : INVALID_DEVID);
  5751. if (ret == 0)
  5752. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5753. if (ret == 0)
  5754. ret = wc_Sha224Final(hash[0], digest[0]);
  5755. if (ret != 0)
  5756. goto exit_sha224;
  5757. } /* for times */
  5758. count += times;
  5759. } while (bench_stats_check(start)
  5760. #ifdef MULTI_VALUE_STATISTICS
  5761. || runs < minimum_runs
  5762. #endif
  5763. );
  5764. }
  5765. exit_sha224:
  5766. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5767. bench_size, start, ret);
  5768. #ifdef MULTI_VALUE_STATISTICS
  5769. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5770. #endif
  5771. exit:
  5772. if (WC_ARRAY_OK(hash)) {
  5773. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5774. wc_Sha224Free(hash[i]);
  5775. }
  5776. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5777. }
  5778. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5779. }
  5780. #endif
  5781. #ifndef NO_SHA256
  5782. void bench_sha256(int useDeviceID)
  5783. {
  5784. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5785. sizeof(wc_Sha256), HEAP_HINT);
  5786. double start;
  5787. int ret = 0, i, count = 0, times, pending = 0;
  5788. DECLARE_MULTI_VALUE_STATS_VARS()
  5789. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5790. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5791. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5792. sizeof(wc_Sha256), HEAP_HINT);
  5793. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5794. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5795. if (digest_stream) {
  5796. /* init keys */
  5797. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5798. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5799. useDeviceID ? devId: INVALID_DEVID);
  5800. if (ret != 0) {
  5801. printf("InitSha256_ex failed, ret = %d\n", ret);
  5802. goto exit;
  5803. }
  5804. #ifdef WOLFSSL_PIC32MZ_HASH
  5805. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5806. #endif
  5807. }
  5808. bench_stats_start(&count, &start);
  5809. do {
  5810. for (times = 0; times < numBlocks || pending > 0; ) {
  5811. bench_async_poll(&pending);
  5812. /* while free pending slots in queue, submit ops */
  5813. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5814. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5815. 0, &times, numBlocks, &pending)) {
  5816. ret = wc_Sha256Update(hash[i], bench_plain,
  5817. bench_size);
  5818. if (!bench_async_handle(&ret,
  5819. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5820. &times, &pending)) {
  5821. goto exit_sha256;
  5822. }
  5823. }
  5824. } /* for i */
  5825. RECORD_MULTI_VALUE_STATS();
  5826. } /* for times */
  5827. count += times;
  5828. times = 0;
  5829. do {
  5830. bench_async_poll(&pending);
  5831. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5832. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5833. 0, &times, numBlocks, &pending)) {
  5834. ret = wc_Sha256Final(hash[i], digest[i]);
  5835. if (!bench_async_handle(&ret,
  5836. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5837. &times, &pending)) {
  5838. goto exit_sha256;
  5839. }
  5840. }
  5841. } /* for i */
  5842. } while (pending > 0);
  5843. } while (bench_stats_check(start)
  5844. #ifdef MULTI_VALUE_STATISTICS
  5845. || runs < minimum_runs
  5846. #endif
  5847. );
  5848. }
  5849. else {
  5850. bench_stats_start(&count, &start);
  5851. do {
  5852. for (times = 0; times < numBlocks; times++) {
  5853. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5854. useDeviceID ? devId: INVALID_DEVID);
  5855. if (ret == 0)
  5856. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5857. if (ret == 0)
  5858. ret = wc_Sha256Final(hash[0], digest[0]);
  5859. if (ret != 0)
  5860. goto exit_sha256;
  5861. RECORD_MULTI_VALUE_STATS();
  5862. } /* for times */
  5863. count += times;
  5864. } while (bench_stats_check(start)
  5865. #ifdef MULTI_VALUE_STATISTICS
  5866. || runs < minimum_runs
  5867. #endif
  5868. );
  5869. }
  5870. exit_sha256:
  5871. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5872. start, ret);
  5873. #ifdef MULTI_VALUE_STATISTICS
  5874. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5875. #endif
  5876. exit:
  5877. if (WC_ARRAY_OK(hash)) {
  5878. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5879. wc_Sha256Free(hash[i]);
  5880. }
  5881. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5882. }
  5883. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5884. }
  5885. #endif
  5886. #ifdef WOLFSSL_SHA384
  5887. void bench_sha384(int useDeviceID)
  5888. {
  5889. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5890. sizeof(wc_Sha384), HEAP_HINT);
  5891. double start;
  5892. int ret = 0, i, count = 0, times, pending = 0;
  5893. DECLARE_MULTI_VALUE_STATS_VARS()
  5894. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5895. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5896. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5897. sizeof(wc_Sha384), HEAP_HINT);
  5898. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5899. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5900. if (digest_stream) {
  5901. /* init keys */
  5902. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5903. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5904. useDeviceID ? devId : INVALID_DEVID);
  5905. if (ret != 0) {
  5906. printf("InitSha384_ex failed, ret = %d\n", ret);
  5907. goto exit;
  5908. }
  5909. }
  5910. bench_stats_start(&count, &start);
  5911. do {
  5912. for (times = 0; times < numBlocks || pending > 0; ) {
  5913. bench_async_poll(&pending);
  5914. /* while free pending slots in queue, submit ops */
  5915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5917. 0, &times, numBlocks, &pending)) {
  5918. ret = wc_Sha384Update(hash[i], bench_plain,
  5919. bench_size);
  5920. if (!bench_async_handle(&ret,
  5921. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5922. &times, &pending)) {
  5923. goto exit_sha384;
  5924. }
  5925. }
  5926. } /* for i */
  5927. RECORD_MULTI_VALUE_STATS();
  5928. } /* for times */
  5929. count += times;
  5930. times = 0;
  5931. do {
  5932. bench_async_poll(&pending);
  5933. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5934. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5935. 0, &times, numBlocks, &pending)) {
  5936. ret = wc_Sha384Final(hash[i], digest[i]);
  5937. if (!bench_async_handle(&ret,
  5938. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5939. &times, &pending)) {
  5940. goto exit_sha384;
  5941. }
  5942. }
  5943. } /* for i */
  5944. } while (pending > 0);
  5945. } while (bench_stats_check(start)
  5946. #ifdef MULTI_VALUE_STATISTICS
  5947. || runs < minimum_runs
  5948. #endif
  5949. );
  5950. }
  5951. else {
  5952. bench_stats_start(&count, &start);
  5953. do {
  5954. for (times = 0; times < numBlocks; times++) {
  5955. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5956. useDeviceID ? devId : INVALID_DEVID);
  5957. if (ret == 0)
  5958. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5959. if (ret == 0)
  5960. ret = wc_Sha384Final(hash[0], digest[0]);
  5961. if (ret != 0)
  5962. goto exit_sha384;
  5963. RECORD_MULTI_VALUE_STATS();
  5964. } /* for times */
  5965. count += times;
  5966. } while (bench_stats_check(start)
  5967. #ifdef MULTI_VALUE_STATISTICS
  5968. || runs < minimum_runs
  5969. #endif
  5970. );
  5971. }
  5972. exit_sha384:
  5973. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5974. start, ret);
  5975. #ifdef MULTI_VALUE_STATISTICS
  5976. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5977. #endif
  5978. exit:
  5979. if (WC_ARRAY_OK(hash)) {
  5980. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5981. wc_Sha384Free(hash[i]);
  5982. }
  5983. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5984. }
  5985. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5986. }
  5987. #endif
  5988. #ifdef WOLFSSL_SHA512
  5989. void bench_sha512(int useDeviceID)
  5990. {
  5991. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5992. sizeof(wc_Sha512), HEAP_HINT);
  5993. double start;
  5994. int ret = 0, i, count = 0, times, pending = 0;
  5995. DECLARE_MULTI_VALUE_STATS_VARS()
  5996. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5997. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5998. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5999. sizeof(wc_Sha512), HEAP_HINT);
  6000. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6001. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  6002. if (digest_stream) {
  6003. /* init keys */
  6004. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6005. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  6006. useDeviceID ? devId : INVALID_DEVID);
  6007. if (ret != 0) {
  6008. printf("InitSha512_ex failed, ret = %d\n", ret);
  6009. goto exit;
  6010. }
  6011. }
  6012. bench_stats_start(&count, &start);
  6013. do {
  6014. for (times = 0; times < numBlocks || pending > 0; ) {
  6015. bench_async_poll(&pending);
  6016. /* while free pending slots in queue, submit ops */
  6017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6018. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6019. 0, &times, numBlocks, &pending)) {
  6020. ret = wc_Sha512Update(hash[i], bench_plain,
  6021. bench_size);
  6022. if (!bench_async_handle(&ret,
  6023. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6024. &times, &pending)) {
  6025. goto exit_sha512;
  6026. }
  6027. }
  6028. } /* for i */
  6029. RECORD_MULTI_VALUE_STATS();
  6030. } /* for times */
  6031. count += times;
  6032. times = 0;
  6033. do {
  6034. bench_async_poll(&pending);
  6035. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6036. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6037. 0, &times, numBlocks, &pending)) {
  6038. ret = wc_Sha512Final(hash[i], digest[i]);
  6039. if (!bench_async_handle(&ret,
  6040. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6041. &times, &pending)) {
  6042. goto exit_sha512;
  6043. }
  6044. }
  6045. } /* for i */
  6046. } while (pending > 0);
  6047. } while (bench_stats_check(start)
  6048. #ifdef MULTI_VALUE_STATISTICS
  6049. || runs < minimum_runs
  6050. #endif
  6051. );
  6052. }
  6053. else {
  6054. bench_stats_start(&count, &start);
  6055. do {
  6056. for (times = 0; times < numBlocks; times++) {
  6057. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  6058. useDeviceID ? devId : INVALID_DEVID);
  6059. if (ret == 0)
  6060. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  6061. if (ret == 0)
  6062. ret = wc_Sha512Final(hash[0], digest[0]);
  6063. if (ret != 0)
  6064. goto exit_sha512;
  6065. RECORD_MULTI_VALUE_STATS();
  6066. } /* for times */
  6067. count += times;
  6068. } while (bench_stats_check(start)
  6069. #ifdef MULTI_VALUE_STATISTICS
  6070. || runs < minimum_runs
  6071. #endif
  6072. );
  6073. }
  6074. exit_sha512:
  6075. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  6076. start, ret);
  6077. #ifdef MULTI_VALUE_STATISTICS
  6078. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6079. #endif
  6080. exit:
  6081. if (WC_ARRAY_OK(hash)) {
  6082. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6083. wc_Sha512Free(hash[i]);
  6084. }
  6085. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6086. }
  6087. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6088. }
  6089. #if !defined(WOLFSSL_NOSHA512_224) && \
  6090. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6091. void bench_sha512_224(int useDeviceID)
  6092. {
  6093. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6094. sizeof(wc_Sha512_224), HEAP_HINT);
  6095. double start;
  6096. int ret = 0, i, count = 0, times, pending = 0;
  6097. DECLARE_MULTI_VALUE_STATS_VARS()
  6098. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6099. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6100. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6101. sizeof(wc_Sha512_224), HEAP_HINT);
  6102. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6103. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6104. if (digest_stream) {
  6105. /* init keys */
  6106. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6107. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6108. useDeviceID ? devId : INVALID_DEVID);
  6109. if (ret != 0) {
  6110. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6111. goto exit;
  6112. }
  6113. }
  6114. bench_stats_start(&count, &start);
  6115. do {
  6116. for (times = 0; times < numBlocks || pending > 0; ) {
  6117. bench_async_poll(&pending);
  6118. /* while free pending slots in queue, submit ops */
  6119. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6120. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6121. 0, &times, numBlocks, &pending)) {
  6122. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6123. bench_size);
  6124. if (!bench_async_handle(&ret,
  6125. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6126. &times, &pending)) {
  6127. goto exit_sha512_224;
  6128. }
  6129. }
  6130. } /* for i */
  6131. RECORD_MULTI_VALUE_STATS();
  6132. } /* for times */
  6133. count += times;
  6134. times = 0;
  6135. do {
  6136. bench_async_poll(&pending);
  6137. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6138. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6139. 0, &times, numBlocks, &pending)) {
  6140. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6141. if (!bench_async_handle(&ret,
  6142. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6143. &times, &pending)) {
  6144. goto exit_sha512_224;
  6145. }
  6146. }
  6147. } /* for i */
  6148. } while (pending > 0);
  6149. } while (bench_stats_check(start)
  6150. #ifdef MULTI_VALUE_STATISTICS
  6151. || runs < minimum_runs
  6152. #endif
  6153. );
  6154. }
  6155. else {
  6156. bench_stats_start(&count, &start);
  6157. do {
  6158. for (times = 0; times < numBlocks; times++) {
  6159. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6160. useDeviceID ? devId : INVALID_DEVID);
  6161. if (ret == 0)
  6162. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6163. if (ret == 0)
  6164. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6165. if (ret != 0)
  6166. goto exit_sha512_224;
  6167. RECORD_MULTI_VALUE_STATS();
  6168. } /* for times */
  6169. count += times;
  6170. } while (bench_stats_check(start)
  6171. #ifdef MULTI_VALUE_STATISTICS
  6172. || runs < minimum_runs
  6173. #endif
  6174. );
  6175. }
  6176. exit_sha512_224:
  6177. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6178. start, ret);
  6179. #ifdef MULTI_VALUE_STATISTICS
  6180. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6181. #endif
  6182. exit:
  6183. if (WC_ARRAY_OK(hash)) {
  6184. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6185. wc_Sha512_224Free(hash[i]);
  6186. }
  6187. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6188. }
  6189. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6190. }
  6191. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6192. #if !defined(WOLFSSL_NOSHA512_256) && \
  6193. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6194. void bench_sha512_256(int useDeviceID)
  6195. {
  6196. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6197. sizeof(wc_Sha512_256), HEAP_HINT);
  6198. double start;
  6199. int ret = 0, i, count = 0, times, pending = 0;
  6200. DECLARE_MULTI_VALUE_STATS_VARS()
  6201. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6202. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6203. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6204. sizeof(wc_Sha512_256), HEAP_HINT);
  6205. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6206. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6207. if (digest_stream) {
  6208. /* init keys */
  6209. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6210. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6211. useDeviceID ? devId : INVALID_DEVID);
  6212. if (ret != 0) {
  6213. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6214. goto exit;
  6215. }
  6216. }
  6217. bench_stats_start(&count, &start);
  6218. do {
  6219. for (times = 0; times < numBlocks || pending > 0; ) {
  6220. bench_async_poll(&pending);
  6221. /* while free pending slots in queue, submit ops */
  6222. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6223. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6224. 0, &times, numBlocks, &pending)) {
  6225. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6226. bench_size);
  6227. if (!bench_async_handle(&ret,
  6228. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6229. &times, &pending)) {
  6230. goto exit_sha512_256;
  6231. }
  6232. }
  6233. } /* for i */
  6234. RECORD_MULTI_VALUE_STATS();
  6235. } /* for times */
  6236. count += times;
  6237. times = 0;
  6238. do {
  6239. bench_async_poll(&pending);
  6240. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6241. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6242. 0, &times, numBlocks, &pending)) {
  6243. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6244. if (!bench_async_handle(&ret,
  6245. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6246. &times, &pending)) {
  6247. goto exit_sha512_256;
  6248. }
  6249. }
  6250. } /* for i */
  6251. } while (pending > 0);
  6252. } while (bench_stats_check(start)
  6253. #ifdef MULTI_VALUE_STATISTICS
  6254. || runs < minimum_runs
  6255. #endif
  6256. );
  6257. }
  6258. else {
  6259. bench_stats_start(&count, &start);
  6260. do {
  6261. for (times = 0; times < numBlocks; times++) {
  6262. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6263. useDeviceID ? devId : INVALID_DEVID);
  6264. if (ret == 0)
  6265. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6266. if (ret == 0)
  6267. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6268. if (ret != 0)
  6269. goto exit_sha512_256;
  6270. RECORD_MULTI_VALUE_STATS();
  6271. } /* for times */
  6272. count += times;
  6273. } while (bench_stats_check(start)
  6274. #ifdef MULTI_VALUE_STATISTICS
  6275. || runs < minimum_runs
  6276. #endif
  6277. );
  6278. }
  6279. exit_sha512_256:
  6280. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6281. start, ret);
  6282. #ifdef MULTI_VALUE_STATISTICS
  6283. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6284. #endif
  6285. exit:
  6286. if (WC_ARRAY_OK(hash)) {
  6287. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6288. wc_Sha512_256Free(hash[i]);
  6289. }
  6290. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6291. }
  6292. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6293. }
  6294. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6295. #endif /* WOLFSSL_SHA512 */
  6296. #ifdef WOLFSSL_SHA3
  6297. #ifndef WOLFSSL_NOSHA3_224
  6298. void bench_sha3_224(int useDeviceID)
  6299. {
  6300. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6301. sizeof(wc_Sha3), HEAP_HINT);
  6302. double start;
  6303. int ret = 0, i, count = 0, times, pending = 0;
  6304. DECLARE_MULTI_VALUE_STATS_VARS()
  6305. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6306. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6307. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6308. sizeof(wc_Sha3), HEAP_HINT);
  6309. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6310. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6311. if (digest_stream) {
  6312. /* init keys */
  6313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6314. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6315. useDeviceID ? devId : INVALID_DEVID);
  6316. if (ret != 0) {
  6317. printf("InitSha3_224 failed, ret = %d\n", ret);
  6318. goto exit;
  6319. }
  6320. }
  6321. bench_stats_start(&count, &start);
  6322. do {
  6323. for (times = 0; times < numBlocks || pending > 0; ) {
  6324. bench_async_poll(&pending);
  6325. /* while free pending slots in queue, submit ops */
  6326. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6327. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6328. 0, &times, numBlocks, &pending)) {
  6329. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6330. bench_size);
  6331. if (!bench_async_handle(&ret,
  6332. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6333. &times, &pending)) {
  6334. goto exit_sha3_224;
  6335. }
  6336. }
  6337. } /* for i */
  6338. RECORD_MULTI_VALUE_STATS();
  6339. } /* for times */
  6340. count += times;
  6341. times = 0;
  6342. do {
  6343. bench_async_poll(&pending);
  6344. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6345. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6346. 0, &times, numBlocks, &pending)) {
  6347. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6348. if (!bench_async_handle(&ret,
  6349. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6350. &times, &pending)) {
  6351. goto exit_sha3_224;
  6352. }
  6353. }
  6354. } /* for i */
  6355. } while (pending > 0);
  6356. } while (bench_stats_check(start)
  6357. #ifdef MULTI_VALUE_STATISTICS
  6358. || runs < minimum_runs
  6359. #endif
  6360. );
  6361. }
  6362. else {
  6363. bench_stats_start(&count, &start);
  6364. do {
  6365. for (times = 0; times < numBlocks; times++) {
  6366. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6367. useDeviceID ? devId : INVALID_DEVID);
  6368. if (ret == 0)
  6369. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6370. if (ret == 0)
  6371. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6372. if (ret != 0)
  6373. goto exit_sha3_224;
  6374. RECORD_MULTI_VALUE_STATS();
  6375. } /* for times */
  6376. count += times;
  6377. } while (bench_stats_check(start)
  6378. #ifdef MULTI_VALUE_STATISTICS
  6379. || runs < minimum_runs
  6380. #endif
  6381. );
  6382. }
  6383. exit_sha3_224:
  6384. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6385. start, ret);
  6386. #ifdef MULTI_VALUE_STATISTICS
  6387. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6388. #endif
  6389. exit:
  6390. if (WC_ARRAY_OK(hash)) {
  6391. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6392. wc_Sha3_224_Free(hash[i]);
  6393. }
  6394. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6395. }
  6396. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6397. }
  6398. #endif /* WOLFSSL_NOSHA3_224 */
  6399. #ifndef WOLFSSL_NOSHA3_256
  6400. void bench_sha3_256(int useDeviceID)
  6401. {
  6402. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6403. sizeof(wc_Sha3), HEAP_HINT);
  6404. double start;
  6405. DECLARE_MULTI_VALUE_STATS_VARS()
  6406. int ret = 0, i, count = 0, times, pending = 0;
  6407. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6408. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6409. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6410. sizeof(wc_Sha3), HEAP_HINT);
  6411. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6412. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6413. if (digest_stream) {
  6414. /* init keys */
  6415. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6416. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6417. useDeviceID ? devId : INVALID_DEVID);
  6418. if (ret != 0) {
  6419. printf("InitSha3_256 failed, ret = %d\n", ret);
  6420. goto exit;
  6421. }
  6422. }
  6423. bench_stats_start(&count, &start);
  6424. do {
  6425. for (times = 0; times < numBlocks || pending > 0; ) {
  6426. bench_async_poll(&pending);
  6427. /* while free pending slots in queue, submit ops */
  6428. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6429. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6430. 0, &times, numBlocks, &pending)) {
  6431. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6432. bench_size);
  6433. if (!bench_async_handle(&ret,
  6434. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6435. &times, &pending)) {
  6436. goto exit_sha3_256;
  6437. }
  6438. }
  6439. } /* for i */
  6440. RECORD_MULTI_VALUE_STATS();
  6441. } /* for times */
  6442. count += times;
  6443. times = 0;
  6444. do {
  6445. bench_async_poll(&pending);
  6446. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6447. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6448. 0, &times, numBlocks, &pending)) {
  6449. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6450. if (!bench_async_handle(&ret,
  6451. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6452. &times, &pending)) {
  6453. goto exit_sha3_256;
  6454. }
  6455. }
  6456. } /* for i */
  6457. } while (pending > 0);
  6458. } while (bench_stats_check(start)
  6459. #ifdef MULTI_VALUE_STATISTICS
  6460. || runs < minimum_runs
  6461. #endif
  6462. );
  6463. }
  6464. else {
  6465. bench_stats_start(&count, &start);
  6466. do {
  6467. for (times = 0; times < numBlocks; times++) {
  6468. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6469. useDeviceID ? devId : INVALID_DEVID);
  6470. if (ret == 0)
  6471. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6472. if (ret == 0)
  6473. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6474. if (ret != 0)
  6475. goto exit_sha3_256;
  6476. RECORD_MULTI_VALUE_STATS();
  6477. } /* for times */
  6478. count += times;
  6479. } while (bench_stats_check(start)
  6480. #ifdef MULTI_VALUE_STATISTICS
  6481. || runs < minimum_runs
  6482. #endif
  6483. );
  6484. }
  6485. exit_sha3_256:
  6486. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6487. start, ret);
  6488. #ifdef MULTI_VALUE_STATISTICS
  6489. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6490. #endif
  6491. exit:
  6492. if (WC_ARRAY_OK(hash)) {
  6493. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6494. wc_Sha3_256_Free(hash[i]);
  6495. }
  6496. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6497. }
  6498. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6499. }
  6500. #endif /* WOLFSSL_NOSHA3_256 */
  6501. #ifndef WOLFSSL_NOSHA3_384
  6502. void bench_sha3_384(int useDeviceID)
  6503. {
  6504. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6505. sizeof(wc_Sha3), HEAP_HINT);
  6506. double start;
  6507. int ret = 0, i, count = 0, times, pending = 0;
  6508. DECLARE_MULTI_VALUE_STATS_VARS()
  6509. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6510. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6511. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6512. sizeof(wc_Sha3), HEAP_HINT);
  6513. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6514. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6515. if (digest_stream) {
  6516. /* init keys */
  6517. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6518. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6519. useDeviceID ? devId : INVALID_DEVID);
  6520. if (ret != 0) {
  6521. printf("InitSha3_384 failed, ret = %d\n", ret);
  6522. goto exit;
  6523. }
  6524. }
  6525. bench_stats_start(&count, &start);
  6526. do {
  6527. for (times = 0; times < numBlocks || pending > 0; ) {
  6528. bench_async_poll(&pending);
  6529. /* while free pending slots in queue, submit ops */
  6530. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6531. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6532. 0, &times, numBlocks, &pending)) {
  6533. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6534. bench_size);
  6535. if (!bench_async_handle(&ret,
  6536. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6537. &times, &pending)) {
  6538. goto exit_sha3_384;
  6539. }
  6540. }
  6541. } /* for i */
  6542. RECORD_MULTI_VALUE_STATS();
  6543. } /* for times */
  6544. count += times;
  6545. times = 0;
  6546. do {
  6547. bench_async_poll(&pending);
  6548. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6549. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6550. 0, &times, numBlocks, &pending)) {
  6551. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6552. if (!bench_async_handle(&ret,
  6553. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6554. &times, &pending)) {
  6555. goto exit_sha3_384;
  6556. }
  6557. }
  6558. } /* for i */
  6559. } while (pending > 0);
  6560. } while (bench_stats_check(start)
  6561. #ifdef MULTI_VALUE_STATISTICS
  6562. || runs < minimum_runs
  6563. #endif
  6564. );
  6565. }
  6566. else {
  6567. bench_stats_start(&count, &start);
  6568. do {
  6569. for (times = 0; times < numBlocks; times++) {
  6570. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6571. useDeviceID ? devId : INVALID_DEVID);
  6572. if (ret == 0)
  6573. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6574. if (ret == 0)
  6575. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6576. if (ret != 0)
  6577. goto exit_sha3_384;
  6578. RECORD_MULTI_VALUE_STATS();
  6579. } /* for times */
  6580. count += times;
  6581. } while (bench_stats_check(start)
  6582. #ifdef MULTI_VALUE_STATISTICS
  6583. || runs < minimum_runs
  6584. #endif
  6585. );
  6586. }
  6587. exit_sha3_384:
  6588. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6589. start, ret);
  6590. #ifdef MULTI_VALUE_STATISTICS
  6591. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6592. #endif
  6593. exit:
  6594. if (WC_ARRAY_OK(hash)) {
  6595. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6596. wc_Sha3_384_Free(hash[i]);
  6597. }
  6598. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6599. }
  6600. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6601. }
  6602. #endif /* WOLFSSL_NOSHA3_384 */
  6603. #ifndef WOLFSSL_NOSHA3_512
  6604. void bench_sha3_512(int useDeviceID)
  6605. {
  6606. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6607. sizeof(wc_Sha3), HEAP_HINT);
  6608. double start;
  6609. int ret = 0, i, count = 0, times, pending = 0;
  6610. DECLARE_MULTI_VALUE_STATS_VARS()
  6611. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6612. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6613. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6614. sizeof(wc_Sha3), HEAP_HINT);
  6615. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6616. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6617. if (digest_stream) {
  6618. /* init keys */
  6619. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6620. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6621. useDeviceID ? devId : INVALID_DEVID);
  6622. if (ret != 0) {
  6623. printf("InitSha3_512 failed, ret = %d\n", ret);
  6624. goto exit;
  6625. }
  6626. }
  6627. bench_stats_start(&count, &start);
  6628. do {
  6629. for (times = 0; times < numBlocks || pending > 0; ) {
  6630. bench_async_poll(&pending);
  6631. /* while free pending slots in queue, submit ops */
  6632. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6633. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6634. 0, &times, numBlocks, &pending)) {
  6635. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6636. bench_size);
  6637. if (!bench_async_handle(&ret,
  6638. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6639. &times, &pending)) {
  6640. goto exit_sha3_512;
  6641. }
  6642. }
  6643. } /* for i */
  6644. RECORD_MULTI_VALUE_STATS();
  6645. } /* for times */
  6646. count += times;
  6647. times = 0;
  6648. do {
  6649. bench_async_poll(&pending);
  6650. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6651. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6652. 0, &times, numBlocks, &pending)) {
  6653. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6654. if (!bench_async_handle(&ret,
  6655. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6656. &times, &pending)) {
  6657. goto exit_sha3_512;
  6658. }
  6659. }
  6660. } /* for i */
  6661. } while (pending > 0);
  6662. } while (bench_stats_check(start)
  6663. #ifdef MULTI_VALUE_STATISTICS
  6664. || runs < minimum_runs
  6665. #endif
  6666. );
  6667. }
  6668. else {
  6669. bench_stats_start(&count, &start);
  6670. do {
  6671. for (times = 0; times < numBlocks; times++) {
  6672. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6673. useDeviceID ? devId : INVALID_DEVID);
  6674. if (ret == 0)
  6675. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6676. if (ret == 0)
  6677. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6678. if (ret != 0)
  6679. goto exit_sha3_512;
  6680. RECORD_MULTI_VALUE_STATS();
  6681. } /* for times */
  6682. count += times;
  6683. } while (bench_stats_check(start)
  6684. #ifdef MULTI_VALUE_STATISTICS
  6685. || runs < minimum_runs
  6686. #endif
  6687. );
  6688. }
  6689. exit_sha3_512:
  6690. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6691. start, ret);
  6692. #ifdef MULTI_VALUE_STATISTICS
  6693. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6694. #endif
  6695. exit:
  6696. if (WC_ARRAY_OK(hash)) {
  6697. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6698. wc_Sha3_512_Free(hash[i]);
  6699. }
  6700. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6701. }
  6702. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6703. }
  6704. #endif /* WOLFSSL_NOSHA3_512 */
  6705. #ifdef WOLFSSL_SHAKE128
  6706. void bench_shake128(int useDeviceID)
  6707. {
  6708. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6709. sizeof(wc_Shake), HEAP_HINT);
  6710. double start;
  6711. int ret = 0, i, count = 0, times, pending = 0;
  6712. DECLARE_MULTI_VALUE_STATS_VARS()
  6713. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6714. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6715. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6716. sizeof(wc_Shake), HEAP_HINT);
  6717. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6718. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6719. if (digest_stream) {
  6720. /* init keys */
  6721. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6722. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6723. useDeviceID ? devId : INVALID_DEVID);
  6724. if (ret != 0) {
  6725. printf("InitShake128 failed, ret = %d\n", ret);
  6726. goto exit;
  6727. }
  6728. }
  6729. bench_stats_start(&count, &start);
  6730. do {
  6731. for (times = 0; times < numBlocks || pending > 0; ) {
  6732. bench_async_poll(&pending);
  6733. /* while free pending slots in queue, submit ops */
  6734. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6735. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6736. 0, &times, numBlocks, &pending)) {
  6737. ret = wc_Shake128_Update(hash[i], bench_plain,
  6738. bench_size);
  6739. if (!bench_async_handle(&ret,
  6740. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6741. &times, &pending)) {
  6742. goto exit_shake128;
  6743. }
  6744. }
  6745. } /* for i */
  6746. RECORD_MULTI_VALUE_STATS();
  6747. } /* for times */
  6748. count += times;
  6749. times = 0;
  6750. do {
  6751. bench_async_poll(&pending);
  6752. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6753. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6754. 0, &times, numBlocks, &pending)) {
  6755. ret = wc_Shake128_Final(hash[i], digest[i],
  6756. WC_SHA3_128_BLOCK_SIZE);
  6757. if (!bench_async_handle(&ret,
  6758. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6759. &times, &pending)) {
  6760. goto exit_shake128;
  6761. }
  6762. }
  6763. } /* for i */
  6764. } while (pending > 0);
  6765. } while (bench_stats_check(start)
  6766. #ifdef MULTI_VALUE_STATISTICS
  6767. || runs < minimum_runs
  6768. #endif
  6769. );
  6770. }
  6771. else {
  6772. bench_stats_start(&count, &start);
  6773. do {
  6774. for (times = 0; times < numBlocks; times++) {
  6775. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6776. useDeviceID ? devId : INVALID_DEVID);
  6777. if (ret == 0)
  6778. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6779. if (ret == 0)
  6780. ret = wc_Shake128_Final(hash[0], digest[0],
  6781. WC_SHA3_128_BLOCK_SIZE);
  6782. if (ret != 0)
  6783. goto exit_shake128;
  6784. RECORD_MULTI_VALUE_STATS();
  6785. } /* for times */
  6786. count += times;
  6787. } while (bench_stats_check(start)
  6788. #ifdef MULTI_VALUE_STATISTICS
  6789. || runs < minimum_runs
  6790. #endif
  6791. );
  6792. }
  6793. exit_shake128:
  6794. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6795. start, ret);
  6796. #ifdef MULTI_VALUE_STATISTICS
  6797. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6798. #endif
  6799. exit:
  6800. if (WC_ARRAY_OK(hash)) {
  6801. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6802. wc_Shake128_Free(hash[i]);
  6803. }
  6804. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6805. }
  6806. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6807. }
  6808. #endif /* WOLFSSL_SHAKE128 */
  6809. #ifdef WOLFSSL_SHAKE256
  6810. void bench_shake256(int useDeviceID)
  6811. {
  6812. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6813. sizeof(wc_Shake), HEAP_HINT);
  6814. double start;
  6815. int ret = 0, i, count = 0, times, pending = 0;
  6816. DECLARE_MULTI_VALUE_STATS_VARS()
  6817. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6818. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6819. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6820. sizeof(wc_Shake), HEAP_HINT);
  6821. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6822. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6823. if (digest_stream) {
  6824. /* init keys */
  6825. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6826. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6827. useDeviceID ? devId : INVALID_DEVID);
  6828. if (ret != 0) {
  6829. printf("InitShake256 failed, ret = %d\n", ret);
  6830. goto exit;
  6831. }
  6832. }
  6833. bench_stats_start(&count, &start);
  6834. do {
  6835. for (times = 0; times < numBlocks || pending > 0; ) {
  6836. bench_async_poll(&pending);
  6837. /* while free pending slots in queue, submit ops */
  6838. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6839. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6840. 0, &times, numBlocks, &pending)) {
  6841. ret = wc_Shake256_Update(hash[i], bench_plain,
  6842. bench_size);
  6843. if (!bench_async_handle(&ret,
  6844. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6845. &times, &pending)) {
  6846. goto exit_shake256;
  6847. }
  6848. }
  6849. } /* for i */
  6850. RECORD_MULTI_VALUE_STATS();
  6851. } /* for times */
  6852. count += times;
  6853. times = 0;
  6854. do {
  6855. bench_async_poll(&pending);
  6856. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6857. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6858. 0, &times, numBlocks, &pending)) {
  6859. ret = wc_Shake256_Final(hash[i], digest[i],
  6860. WC_SHA3_256_BLOCK_SIZE);
  6861. if (!bench_async_handle(&ret,
  6862. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6863. &times, &pending)) {
  6864. goto exit_shake256;
  6865. }
  6866. }
  6867. } /* for i */
  6868. } while (pending > 0);
  6869. } while (bench_stats_check(start)
  6870. #ifdef MULTI_VALUE_STATISTICS
  6871. || runs < minimum_runs
  6872. #endif
  6873. );
  6874. }
  6875. else {
  6876. bench_stats_start(&count, &start);
  6877. do {
  6878. for (times = 0; times < numBlocks; times++) {
  6879. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6880. useDeviceID ? devId : INVALID_DEVID);
  6881. if (ret == 0)
  6882. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6883. if (ret == 0)
  6884. ret = wc_Shake256_Final(hash[0], digest[0],
  6885. WC_SHA3_256_BLOCK_SIZE);
  6886. if (ret != 0)
  6887. goto exit_shake256;
  6888. RECORD_MULTI_VALUE_STATS();
  6889. } /* for times */
  6890. count += times;
  6891. } while (bench_stats_check(start)
  6892. #ifdef MULTI_VALUE_STATISTICS
  6893. || runs < minimum_runs
  6894. #endif
  6895. );
  6896. }
  6897. exit_shake256:
  6898. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6899. start, ret);
  6900. #ifdef MULTI_VALUE_STATISTICS
  6901. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6902. #endif
  6903. exit:
  6904. if (WC_ARRAY_OK(hash)) {
  6905. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6906. wc_Shake256_Free(hash[i]);
  6907. }
  6908. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6909. }
  6910. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6911. }
  6912. #endif /* WOLFSSL_SHAKE256 */
  6913. #endif
  6914. #ifdef WOLFSSL_SM3
  6915. void bench_sm3(int useDeviceID)
  6916. {
  6917. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6918. sizeof(wc_Sm3), HEAP_HINT);
  6919. double start;
  6920. int ret = 0, i, count = 0, times, pending = 0;
  6921. DECLARE_MULTI_VALUE_STATS_VARS()
  6922. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6923. HEAP_HINT);
  6924. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6925. sizeof(wc_Sm3), HEAP_HINT);
  6926. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6927. HEAP_HINT);
  6928. if (digest_stream) {
  6929. /* init keys */
  6930. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6931. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6932. useDeviceID ? devId: INVALID_DEVID);
  6933. if (ret != 0) {
  6934. printf("InitSm3 failed, ret = %d\n", ret);
  6935. goto exit;
  6936. }
  6937. }
  6938. bench_stats_start(&count, &start);
  6939. do {
  6940. for (times = 0; times < numBlocks || pending > 0; ) {
  6941. bench_async_poll(&pending);
  6942. /* while free pending slots in queue, submit ops */
  6943. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6944. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6945. 0, &times, numBlocks, &pending)) {
  6946. ret = wc_Sm3Update(hash[i], bench_plain,
  6947. bench_size);
  6948. if (!bench_async_handle(&ret,
  6949. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6950. goto exit_sm3;
  6951. }
  6952. }
  6953. } /* for i */
  6954. RECORD_MULTI_VALUE_STATS();
  6955. } /* for times */
  6956. count += times;
  6957. times = 0;
  6958. do {
  6959. bench_async_poll(&pending);
  6960. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6961. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6962. 0, &times, numBlocks, &pending)) {
  6963. ret = wc_Sm3Final(hash[i], digest[i]);
  6964. if (!bench_async_handle(&ret,
  6965. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6966. goto exit_sm3;
  6967. }
  6968. }
  6969. } /* for i */
  6970. } while (pending > 0);
  6971. } while (bench_stats_check(start)
  6972. #ifdef MULTI_VALUE_STATISTICS
  6973. || runs < minimum_runs
  6974. #endif
  6975. );
  6976. }
  6977. else {
  6978. bench_stats_start(&count, &start);
  6979. do {
  6980. for (times = 0; times < numBlocks; times++) {
  6981. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6982. useDeviceID ? devId: INVALID_DEVID);
  6983. if (ret == 0)
  6984. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6985. if (ret == 0)
  6986. ret = wc_Sm3Final(hash[0], digest[0]);
  6987. if (ret != 0)
  6988. goto exit_sm3;
  6989. RECORD_MULTI_VALUE_STATS();
  6990. } /* for times */
  6991. count += times;
  6992. } while (bench_stats_check(start)
  6993. #ifdef MULTI_VALUE_STATISTICS
  6994. || runs < minimum_runs
  6995. #endif
  6996. );
  6997. }
  6998. exit_sm3:
  6999. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  7000. #ifdef MULTI_VALUE_STATISTICS
  7001. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7002. #endif
  7003. exit:
  7004. if (WC_ARRAY_OK(hash)) {
  7005. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7006. wc_Sm3Free(hash[i]);
  7007. }
  7008. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  7009. }
  7010. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7011. }
  7012. #endif
  7013. #ifdef WOLFSSL_RIPEMD
  7014. void bench_ripemd(void)
  7015. {
  7016. RipeMd hash;
  7017. byte digest[RIPEMD_DIGEST_SIZE];
  7018. double start;
  7019. int i, count, ret = 0;
  7020. DECLARE_MULTI_VALUE_STATS_VARS()
  7021. if (digest_stream) {
  7022. ret = wc_InitRipeMd(&hash);
  7023. if (ret != 0) {
  7024. printf("wc_InitRipeMd failed, retval %d\n", ret);
  7025. return;
  7026. }
  7027. bench_stats_start(&count, &start);
  7028. do {
  7029. for (i = 0; i < numBlocks; i++) {
  7030. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7031. if (ret != 0) {
  7032. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7033. return;
  7034. }
  7035. RECORD_MULTI_VALUE_STATS();
  7036. }
  7037. ret = wc_RipeMdFinal(&hash, digest);
  7038. if (ret != 0) {
  7039. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7040. return;
  7041. }
  7042. count += i;
  7043. } while (bench_stats_check(start)
  7044. #ifdef MULTI_VALUE_STATISTICS
  7045. || runs < minimum_runs
  7046. #endif
  7047. );
  7048. }
  7049. else {
  7050. bench_stats_start(&count, &start);
  7051. do {
  7052. for (i = 0; i < numBlocks; i++) {
  7053. ret = wc_InitRipeMd(&hash);
  7054. if (ret != 0) {
  7055. printf("wc_InitRipeMd failed, retval %d\n", ret);
  7056. return;
  7057. }
  7058. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7059. if (ret != 0) {
  7060. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7061. return;
  7062. }
  7063. ret = wc_RipeMdFinal(&hash, digest);
  7064. if (ret != 0) {
  7065. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7066. return;
  7067. }
  7068. RECORD_MULTI_VALUE_STATS();
  7069. }
  7070. count += i;
  7071. } while (bench_stats_check(start)
  7072. #ifdef MULTI_VALUE_STATISTICS
  7073. || runs < minimum_runs
  7074. #endif
  7075. );
  7076. }
  7077. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  7078. #ifdef MULTI_VALUE_STATISTICS
  7079. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7080. #endif
  7081. return;
  7082. }
  7083. #endif
  7084. #ifdef HAVE_BLAKE2
  7085. void bench_blake2b(void)
  7086. {
  7087. Blake2b b2b;
  7088. byte digest[64];
  7089. double start;
  7090. int ret = 0, i, count;
  7091. DECLARE_MULTI_VALUE_STATS_VARS()
  7092. if (digest_stream) {
  7093. ret = wc_InitBlake2b(&b2b, 64);
  7094. if (ret != 0) {
  7095. printf("InitBlake2b failed, ret = %d\n", ret);
  7096. return;
  7097. }
  7098. bench_stats_start(&count, &start);
  7099. do {
  7100. for (i = 0; i < numBlocks; i++) {
  7101. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7102. if (ret != 0) {
  7103. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7104. return;
  7105. }
  7106. RECORD_MULTI_VALUE_STATS();
  7107. }
  7108. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7109. if (ret != 0) {
  7110. printf("Blake2bFinal failed, ret = %d\n", ret);
  7111. return;
  7112. }
  7113. count += i;
  7114. } while (bench_stats_check(start)
  7115. #ifdef MULTI_VALUE_STATISTICS
  7116. || runs < minimum_runs
  7117. #endif
  7118. );
  7119. }
  7120. else {
  7121. bench_stats_start(&count, &start);
  7122. do {
  7123. for (i = 0; i < numBlocks; i++) {
  7124. ret = wc_InitBlake2b(&b2b, 64);
  7125. if (ret != 0) {
  7126. printf("InitBlake2b failed, ret = %d\n", ret);
  7127. return;
  7128. }
  7129. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7130. if (ret != 0) {
  7131. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7132. return;
  7133. }
  7134. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7135. if (ret != 0) {
  7136. printf("Blake2bFinal failed, ret = %d\n", ret);
  7137. return;
  7138. }
  7139. RECORD_MULTI_VALUE_STATS();
  7140. }
  7141. count += i;
  7142. } while (bench_stats_check(start)
  7143. #ifdef MULTI_VALUE_STATISTICS
  7144. || runs < minimum_runs
  7145. #endif
  7146. );
  7147. }
  7148. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7149. #ifdef MULTI_VALUE_STATISTICS
  7150. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7151. #endif
  7152. }
  7153. #endif
  7154. #if defined(HAVE_BLAKE2S)
  7155. void bench_blake2s(void)
  7156. {
  7157. Blake2s b2s;
  7158. byte digest[32];
  7159. double start;
  7160. int ret = 0, i, count;
  7161. DECLARE_MULTI_VALUE_STATS_VARS()
  7162. if (digest_stream) {
  7163. ret = wc_InitBlake2s(&b2s, 32);
  7164. if (ret != 0) {
  7165. printf("InitBlake2s failed, ret = %d\n", ret);
  7166. return;
  7167. }
  7168. bench_stats_start(&count, &start);
  7169. do {
  7170. for (i = 0; i < numBlocks; i++) {
  7171. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7172. if (ret != 0) {
  7173. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7174. return;
  7175. }
  7176. RECORD_MULTI_VALUE_STATS();
  7177. }
  7178. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7179. if (ret != 0) {
  7180. printf("Blake2sFinal failed, ret = %d\n", ret);
  7181. return;
  7182. }
  7183. count += i;
  7184. } while (bench_stats_check(start)
  7185. #ifdef MULTI_VALUE_STATISTICS
  7186. || runs < minimum_runs
  7187. #endif
  7188. );
  7189. }
  7190. else {
  7191. bench_stats_start(&count, &start);
  7192. do {
  7193. for (i = 0; i < numBlocks; i++) {
  7194. ret = wc_InitBlake2s(&b2s, 32);
  7195. if (ret != 0) {
  7196. printf("InitBlake2b failed, ret = %d\n", ret);
  7197. return;
  7198. }
  7199. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7200. if (ret != 0) {
  7201. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7202. return;
  7203. }
  7204. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7205. if (ret != 0) {
  7206. printf("Blake2sFinal failed, ret = %d\n", ret);
  7207. return;
  7208. }
  7209. RECORD_MULTI_VALUE_STATS();
  7210. }
  7211. count += i;
  7212. } while (bench_stats_check(start)
  7213. #ifdef MULTI_VALUE_STATISTICS
  7214. || runs < minimum_runs
  7215. #endif
  7216. );
  7217. }
  7218. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7219. #ifdef MULTI_VALUE_STATISTICS
  7220. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7221. #endif
  7222. }
  7223. #endif
  7224. #ifdef WOLFSSL_CMAC
  7225. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7226. {
  7227. Cmac cmac;
  7228. byte digest[WC_AES_BLOCK_SIZE];
  7229. word32 digestSz = sizeof(digest);
  7230. double start;
  7231. int ret, i, count;
  7232. DECLARE_MULTI_VALUE_STATS_VARS()
  7233. #ifdef WOLFSSL_SECO_CAAM
  7234. unsigned int keyID;
  7235. int keyGroup = 1; /* group one was chosen arbitrarily */
  7236. int keyInfo = CAAM_KEY_TRANSIENT;
  7237. int keyType = CAAM_KEYTYPE_AES128;
  7238. byte pubKey[AES_256_KEY_SIZE];
  7239. if (keySz == AES_256_KEY_SIZE) {
  7240. keyType = CAAM_KEYTYPE_AES256;
  7241. }
  7242. if (useDeviceID &&
  7243. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7244. keyInfo, &keyID) != 0) {
  7245. printf("Error generating key in hsm\n");
  7246. return;
  7247. }
  7248. #endif
  7249. (void)useDeviceID;
  7250. bench_stats_start(&count, &start);
  7251. do {
  7252. #ifdef HAVE_FIPS
  7253. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7254. #else
  7255. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7256. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7257. #endif
  7258. if (ret != 0) {
  7259. printf("InitCmac failed, ret = %d\n", ret);
  7260. return;
  7261. }
  7262. #ifdef WOLFSSL_SECO_CAAM
  7263. if (useDeviceID) {
  7264. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7265. }
  7266. #endif
  7267. for (i = 0; i < numBlocks; i++) {
  7268. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7269. if (ret != 0) {
  7270. printf("CmacUpdate failed, ret = %d\n", ret);
  7271. return;
  7272. }
  7273. RECORD_MULTI_VALUE_STATS();
  7274. }
  7275. /* Note: final force zero's the Cmac struct */
  7276. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7277. if (ret != 0) {
  7278. printf("CmacFinal failed, ret = %d\n", ret);
  7279. return;
  7280. }
  7281. count += i;
  7282. } while (bench_stats_check(start)
  7283. #ifdef MULTI_VALUE_STATISTICS
  7284. || runs < minimum_runs
  7285. #endif
  7286. );
  7287. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7288. #ifdef MULTI_VALUE_STATISTICS
  7289. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7290. #endif
  7291. }
  7292. void bench_cmac(int useDeviceID)
  7293. {
  7294. #ifdef WOLFSSL_AES_128
  7295. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7296. #endif
  7297. #ifdef WOLFSSL_AES_256
  7298. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7299. #endif
  7300. }
  7301. #endif /* WOLFSSL_CMAC */
  7302. #ifdef HAVE_SCRYPT
  7303. void bench_scrypt(void)
  7304. {
  7305. byte derived[64];
  7306. double start;
  7307. int ret, i, count;
  7308. DECLARE_MULTI_VALUE_STATS_VARS()
  7309. bench_stats_start(&count, &start);
  7310. do {
  7311. for (i = 0; i < scryptCnt; i++) {
  7312. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7313. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7314. sizeof(derived));
  7315. if (ret != 0) {
  7316. printf("scrypt failed, ret = %d\n", ret);
  7317. goto exit;
  7318. }
  7319. RECORD_MULTI_VALUE_STATS();
  7320. }
  7321. count += i;
  7322. } while (bench_stats_check(start)
  7323. #ifdef MULTI_VALUE_STATISTICS
  7324. || runs < minimum_runs
  7325. #endif
  7326. );
  7327. exit:
  7328. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7329. #ifdef MULTI_VALUE_STATISTICS
  7330. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7331. #endif
  7332. }
  7333. #endif /* HAVE_SCRYPT */
  7334. #ifndef NO_HMAC
  7335. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7336. const byte* key, word32 keySz, const char* label)
  7337. {
  7338. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7339. sizeof(Hmac), HEAP_HINT);
  7340. double start;
  7341. int ret = 0, i, count = 0, times, pending = 0;
  7342. DECLARE_MULTI_VALUE_STATS_VARS()
  7343. #ifdef WOLFSSL_ASYNC_CRYPT
  7344. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7345. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7346. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7347. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7348. #else
  7349. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7350. #endif
  7351. (void)digestSz;
  7352. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7353. sizeof(Hmac), HEAP_HINT);
  7354. /* init keys */
  7355. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7356. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7357. useDeviceID ? devId : INVALID_DEVID);
  7358. if (ret != 0) {
  7359. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7360. goto exit;
  7361. }
  7362. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7363. if (ret != 0) {
  7364. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7365. goto exit;
  7366. }
  7367. }
  7368. bench_stats_start(&count, &start);
  7369. do {
  7370. for (times = 0; times < numBlocks || pending > 0; ) {
  7371. bench_async_poll(&pending);
  7372. /* while free pending slots in queue, submit ops */
  7373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7374. if (bench_async_check(&ret,
  7375. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7376. &times, numBlocks, &pending)) {
  7377. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7378. if (!bench_async_handle(&ret,
  7379. BENCH_ASYNC_GET_DEV(hmac[i]),
  7380. 0, &times, &pending)) {
  7381. goto exit_hmac;
  7382. }
  7383. }
  7384. } /* for i */
  7385. } /* for times */
  7386. count += times;
  7387. times = 0;
  7388. do {
  7389. bench_async_poll(&pending);
  7390. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7391. if (bench_async_check(&ret,
  7392. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7393. &times, numBlocks, &pending)) {
  7394. ret = wc_HmacFinal(hmac[i], digest[i]);
  7395. if (!bench_async_handle(&ret,
  7396. BENCH_ASYNC_GET_DEV(hmac[i]),
  7397. 0, &times, &pending)) {
  7398. goto exit_hmac;
  7399. }
  7400. }
  7401. RECORD_MULTI_VALUE_STATS();
  7402. } /* for i */
  7403. } while (pending > 0);
  7404. } while (bench_stats_check(start)
  7405. #ifdef MULTI_VALUE_STATISTICS
  7406. || runs < minimum_runs
  7407. #endif
  7408. );
  7409. exit_hmac:
  7410. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7411. #ifdef MULTI_VALUE_STATISTICS
  7412. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7413. #endif
  7414. exit:
  7415. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7416. wc_HmacFree(hmac[i]);
  7417. }
  7418. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7419. #ifdef WOLFSSL_ASYNC_CRYPT
  7420. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7421. #endif
  7422. }
  7423. #ifndef NO_MD5
  7424. void bench_hmac_md5(int useDeviceID)
  7425. {
  7426. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7427. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7428. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7429. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7430. "HMAC-MD5");
  7431. }
  7432. #endif /* NO_MD5 */
  7433. #ifndef NO_SHA
  7434. void bench_hmac_sha(int useDeviceID)
  7435. {
  7436. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7437. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7438. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7439. 0x0b, 0x0b, 0x0b, 0x0b };
  7440. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7441. "HMAC-SHA");
  7442. }
  7443. #endif /* NO_SHA */
  7444. #ifdef WOLFSSL_SHA224
  7445. void bench_hmac_sha224(int useDeviceID)
  7446. {
  7447. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7448. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7449. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7450. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7451. 0x0b, 0x0b, 0x0b, 0x0b };
  7452. bench_hmac(useDeviceID, WC_SHA224,
  7453. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7454. "HMAC-SHA224");
  7455. }
  7456. #endif /* WOLFSSL_SHA224 */
  7457. #ifndef NO_SHA256
  7458. void bench_hmac_sha256(int useDeviceID)
  7459. {
  7460. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7461. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7462. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7463. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7464. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7465. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7466. "HMAC-SHA256");
  7467. }
  7468. #endif /* NO_SHA256 */
  7469. #ifdef WOLFSSL_SHA384
  7470. void bench_hmac_sha384(int useDeviceID)
  7471. {
  7472. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7473. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7474. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7475. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7476. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7477. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7478. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7479. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7480. "HMAC-SHA384");
  7481. }
  7482. #endif /* WOLFSSL_SHA384 */
  7483. #ifdef WOLFSSL_SHA512
  7484. void bench_hmac_sha512(int useDeviceID)
  7485. {
  7486. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7487. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7488. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7489. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7490. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7491. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7492. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7493. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7494. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7495. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7496. "HMAC-SHA512");
  7497. }
  7498. #endif /* WOLFSSL_SHA512 */
  7499. #ifndef NO_PWDBASED
  7500. void bench_pbkdf2(void)
  7501. {
  7502. double start;
  7503. int ret = 0, count = 0;
  7504. const char* passwd32 = "passwordpasswordpasswordpassword";
  7505. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7506. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7507. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7508. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7509. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7510. byte derived[32];
  7511. DECLARE_MULTI_VALUE_STATS_VARS()
  7512. bench_stats_start(&count, &start);
  7513. PRIVATE_KEY_UNLOCK();
  7514. do {
  7515. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7516. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7517. count++;
  7518. RECORD_MULTI_VALUE_STATS();
  7519. } while (bench_stats_check(start)
  7520. #ifdef MULTI_VALUE_STATISTICS
  7521. || runs < minimum_runs
  7522. #endif
  7523. );
  7524. PRIVATE_KEY_LOCK();
  7525. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7526. #ifdef MULTI_VALUE_STATISTICS
  7527. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7528. #endif
  7529. }
  7530. #endif /* !NO_PWDBASED */
  7531. #endif /* NO_HMAC */
  7532. #ifdef WOLFSSL_SIPHASH
  7533. void bench_siphash(void)
  7534. {
  7535. double start;
  7536. int ret = 0, count;
  7537. const char* passwd16 = "passwordpassword";
  7538. byte out[16];
  7539. int i;
  7540. DECLARE_MULTI_VALUE_STATS_VARS()
  7541. bench_stats_start(&count, &start);
  7542. do {
  7543. for (i = 0; i < numBlocks; i++) {
  7544. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7545. out, 8);
  7546. RECORD_MULTI_VALUE_STATS();
  7547. }
  7548. count += i;
  7549. } while (bench_stats_check(start)
  7550. #ifdef MULTI_VALUE_STATISTICS
  7551. || runs < minimum_runs
  7552. #endif
  7553. );
  7554. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7555. #ifdef MULTI_VALUE_STATISTICS
  7556. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7557. #endif
  7558. RESET_MULTI_VALUE_STATS_VARS();
  7559. bench_stats_start(&count, &start);
  7560. do {
  7561. for (i = 0; i < numBlocks; i++) {
  7562. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7563. out, 16);
  7564. RECORD_MULTI_VALUE_STATS();
  7565. }
  7566. count += i;
  7567. } while (bench_stats_check(start)
  7568. #ifdef MULTI_VALUE_STATISTICS
  7569. || runs < minimum_runs
  7570. #endif
  7571. );
  7572. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7573. #ifdef MULTI_VALUE_STATISTICS
  7574. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7575. #endif
  7576. }
  7577. #endif
  7578. #ifdef WC_SRTP_KDF
  7579. void bench_srtpkdf(void)
  7580. {
  7581. double start;
  7582. int count;
  7583. int ret = 0;
  7584. byte keyE[32];
  7585. byte keyA[20];
  7586. byte keyS[14];
  7587. const byte *key = bench_key_buf;
  7588. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7589. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7590. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7591. int kdrIdx = 0;
  7592. int i;
  7593. DECLARE_MULTI_VALUE_STATS_VARS()
  7594. bench_stats_start(&count, &start);
  7595. PRIVATE_KEY_UNLOCK();
  7596. do {
  7597. for (i = 0; i < numBlocks; i++) {
  7598. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7599. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7600. keyS, sizeof(keyS));
  7601. RECORD_MULTI_VALUE_STATS();
  7602. }
  7603. count += i;
  7604. } while (bench_stats_check(start)
  7605. #ifdef MULTI_VALUE_STATISTICS
  7606. || runs < minimum_runs
  7607. #endif
  7608. );
  7609. PRIVATE_KEY_LOCK();
  7610. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7611. #ifdef MULTI_VALUE_STATISTICS
  7612. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7613. #endif
  7614. RESET_MULTI_VALUE_STATS_VARS();
  7615. bench_stats_start(&count, &start);
  7616. PRIVATE_KEY_UNLOCK();
  7617. do {
  7618. for (i = 0; i < numBlocks; i++) {
  7619. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7620. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7621. keyS, sizeof(keyS));
  7622. RECORD_MULTI_VALUE_STATS();
  7623. }
  7624. count += i;
  7625. } while (bench_stats_check(start)
  7626. #ifdef MULTI_VALUE_STATISTICS
  7627. || runs < minimum_runs
  7628. #endif
  7629. );
  7630. PRIVATE_KEY_LOCK();
  7631. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7632. #ifdef MULTI_VALUE_STATISTICS
  7633. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7634. #endif
  7635. RESET_MULTI_VALUE_STATS_VARS();
  7636. bench_stats_start(&count, &start);
  7637. PRIVATE_KEY_UNLOCK();
  7638. do {
  7639. for (i = 0; i < numBlocks; i++) {
  7640. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7641. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7642. keyS, sizeof(keyS));
  7643. RECORD_MULTI_VALUE_STATS();
  7644. }
  7645. count += i;
  7646. } while (bench_stats_check(start)
  7647. #ifdef MULTI_VALUE_STATISTICS
  7648. || runs < minimum_runs
  7649. #endif
  7650. );
  7651. PRIVATE_KEY_LOCK();
  7652. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7653. #ifdef MULTI_VALUE_STATISTICS
  7654. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7655. #endif
  7656. RESET_MULTI_VALUE_STATS_VARS();
  7657. bench_stats_start(&count, &start);
  7658. PRIVATE_KEY_UNLOCK();
  7659. do {
  7660. for (i = 0; i < numBlocks; i++) {
  7661. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7662. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7663. keyS, sizeof(keyS));
  7664. RECORD_MULTI_VALUE_STATS();
  7665. }
  7666. count += i;
  7667. } while (bench_stats_check(start)
  7668. #ifdef MULTI_VALUE_STATISTICS
  7669. || runs < minimum_runs
  7670. #endif
  7671. );
  7672. PRIVATE_KEY_LOCK();
  7673. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7674. #ifdef MULTI_VALUE_STATISTICS
  7675. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7676. #endif
  7677. }
  7678. #endif
  7679. #ifndef NO_RSA
  7680. #if defined(WOLFSSL_KEY_GEN)
  7681. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7682. {
  7683. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7684. sizeof(RsaKey), HEAP_HINT);
  7685. double start = 0;
  7686. int ret = 0, i, count = 0, times, pending = 0;
  7687. const long rsa_e_val = WC_RSA_EXPONENT;
  7688. const char**desc = bench_desc_words[lng_index];
  7689. DECLARE_MULTI_VALUE_STATS_VARS()
  7690. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7691. sizeof(RsaKey), HEAP_HINT);
  7692. bench_stats_start(&count, &start);
  7693. do {
  7694. /* while free pending slots in queue, submit ops */
  7695. for (times = 0; times < genTimes || pending > 0; ) {
  7696. bench_async_poll(&pending);
  7697. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7698. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7699. 0, &times, genTimes, &pending)) {
  7700. wc_FreeRsaKey(genKey[i]);
  7701. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7702. if (ret < 0) {
  7703. goto exit;
  7704. }
  7705. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7706. &gRng);
  7707. if (!bench_async_handle(&ret,
  7708. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7709. &times, &pending)) {
  7710. goto exit;
  7711. }
  7712. }
  7713. } /* for i */
  7714. RECORD_MULTI_VALUE_STATS();
  7715. } /* for times */
  7716. count += times;
  7717. } while (bench_stats_check(start)
  7718. #ifdef MULTI_VALUE_STATISTICS
  7719. || runs < minimum_runs
  7720. #endif
  7721. );
  7722. exit:
  7723. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7724. start, ret);
  7725. #ifdef MULTI_VALUE_STATISTICS
  7726. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7727. #endif
  7728. /* cleanup */
  7729. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7730. wc_FreeRsaKey(genKey[i]);
  7731. }
  7732. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7733. }
  7734. void bench_rsaKeyGen(int useDeviceID)
  7735. {
  7736. int k;
  7737. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7738. static const word32 keySizes[2] = {1024, 2048 };
  7739. #elif RSA_MAX_SIZE >= 4096
  7740. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7741. (RSA_MIN_SIZE <= 1024)
  7742. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7743. #else
  7744. static const word32 keySizes[3] = {2048, 3072, 4096};
  7745. #endif
  7746. #elif RSA_MAX_SIZE >= 3072
  7747. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7748. (RSA_MIN_SIZE <= 1024)
  7749. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7750. #else
  7751. static const word32 keySizes[2] = {2048, 3072 };
  7752. #endif
  7753. #elif RSA_MAX_SIZE >= 2048
  7754. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7755. (RSA_MIN_SIZE <= 1024)
  7756. static const word32 keySizes[2] = {1024, 2048 };
  7757. #else
  7758. static const word32 keySizes[1] = {2048};
  7759. #endif
  7760. #else
  7761. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7762. (RSA_MIN_SIZE <= 1024)
  7763. static const word32 keySizes[1] = {1024 };
  7764. #else
  7765. #error No candidate RSA key sizes to benchmark.
  7766. #endif
  7767. #endif
  7768. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7769. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7770. }
  7771. }
  7772. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7773. {
  7774. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7775. }
  7776. #endif /* WOLFSSL_KEY_GEN */
  7777. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7778. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7779. #if defined(WOLFSSL_MDK_SHELL)
  7780. static char *certRSAname = "certs/rsa2048.der";
  7781. /* set by shell command */
  7782. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7783. #elif defined(FREESCALE_MQX)
  7784. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7785. #else
  7786. static const char *certRSAname = "certs/rsa2048.der";
  7787. #endif
  7788. #endif
  7789. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7790. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7791. #if defined(USE_CERT_BUFFERS_2048)
  7792. static const unsigned char rsa_2048_sig[] = {
  7793. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7794. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7795. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7796. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7797. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7798. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7799. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7800. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7801. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7802. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7803. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7804. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7805. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7806. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7807. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7808. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7809. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7810. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7811. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7812. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7813. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7814. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7815. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7816. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7817. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7818. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7819. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7820. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7821. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7822. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7823. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7824. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7825. };
  7826. #elif defined(USE_CERT_BUFFERS_3072)
  7827. static const unsigned char rsa_3072_sig[] = {
  7828. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7829. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7830. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7831. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7832. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7833. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7834. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7835. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7836. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7837. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7838. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7839. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7840. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7841. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7842. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7843. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7844. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7845. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7846. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7847. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7848. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7849. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7850. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7851. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7852. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7853. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7854. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7855. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7856. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7857. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7858. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7859. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7860. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7861. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7862. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7863. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7864. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7865. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7866. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7867. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7868. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7869. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7870. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7871. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7872. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7873. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7874. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7875. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7876. };
  7877. #else
  7878. #error Not Supported Yet!
  7879. #endif
  7880. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7881. static void bench_rsa_helper(int useDeviceID,
  7882. WC_ARRAY_ARG(rsaKey,
  7883. RsaKey,
  7884. BENCH_MAX_PENDING,
  7885. sizeof(RsaKey)),
  7886. word32 rsaKeySz)
  7887. {
  7888. int ret = 0, i, times, count = 0, pending = 0;
  7889. word32 idx = 0;
  7890. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7891. const char* messageStr = TEST_STRING;
  7892. const int len = (int)TEST_STRING_SZ;
  7893. #endif
  7894. double start = 0.0F;
  7895. const char**desc = bench_desc_words[lng_index];
  7896. DECLARE_MULTI_VALUE_STATS_VARS()
  7897. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7898. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7899. #endif
  7900. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7901. rsaKeySz, HEAP_HINT);
  7902. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7903. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7904. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7905. rsaKeySz, HEAP_HINT);
  7906. #else
  7907. byte* out[BENCH_MAX_PENDING];
  7908. #endif
  7909. XMEMSET(out, 0, sizeof(out));
  7910. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7911. rsaKeySz, HEAP_HINT);
  7912. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7913. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7914. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7915. rsaKeySz, HEAP_HINT);
  7916. if (out[0] == NULL) {
  7917. ret = MEMORY_E;
  7918. goto exit;
  7919. }
  7920. #endif
  7921. if (enc[0] == NULL) {
  7922. ret = MEMORY_E;
  7923. goto exit;
  7924. }
  7925. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7926. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7927. XMEMCPY(message, messageStr, len);
  7928. #endif
  7929. if (!rsa_sign_verify) {
  7930. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7931. /* begin public RSA */
  7932. bench_stats_start(&count, &start);
  7933. do {
  7934. for (times = 0; times < ntimes || pending > 0; ) {
  7935. bench_async_poll(&pending);
  7936. /* while free pending slots in queue, submit ops */
  7937. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7938. if (bench_async_check(&ret,
  7939. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7940. 1, &times, ntimes, &pending)) {
  7941. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7942. rsaKeySz/8, rsaKey[i],
  7943. GLOBAL_RNG);
  7944. if (!bench_async_handle(&ret,
  7945. BENCH_ASYNC_GET_DEV(
  7946. rsaKey[i]), 1, &times,
  7947. &pending)) {
  7948. goto exit_rsa_verify;
  7949. }
  7950. }
  7951. } /* for i */
  7952. RECORD_MULTI_VALUE_STATS();
  7953. } /* for times */
  7954. count += times;
  7955. } while (bench_stats_check(start)
  7956. #ifdef MULTI_VALUE_STATISTICS
  7957. || runs < minimum_runs
  7958. #endif
  7959. );
  7960. exit_rsa_verify:
  7961. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7962. useDeviceID, count, start, ret);
  7963. #ifdef MULTI_VALUE_STATISTICS
  7964. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7965. #endif
  7966. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7967. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7968. if (ret < 0) {
  7969. goto exit;
  7970. }
  7971. RESET_MULTI_VALUE_STATS_VARS();
  7972. /* capture resulting encrypt length */
  7973. idx = (word32)(rsaKeySz/8);
  7974. /* begin private async RSA */
  7975. bench_stats_start(&count, &start);
  7976. do {
  7977. for (times = 0; times < ntimes || pending > 0; ) {
  7978. bench_async_poll(&pending);
  7979. /* while free pending slots in queue, submit ops */
  7980. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7981. if (bench_async_check(&ret,
  7982. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7983. 1, &times, ntimes, &pending)) {
  7984. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7985. rsaKeySz/8, rsaKey[i]);
  7986. if (!bench_async_handle(&ret,
  7987. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7988. 1, &times, &pending)) {
  7989. goto exit_rsa_pub;
  7990. }
  7991. }
  7992. } /* for i */
  7993. RECORD_MULTI_VALUE_STATS();
  7994. } /* for times */
  7995. count += times;
  7996. } while (bench_stats_check(start)
  7997. #ifdef MULTI_VALUE_STATISTICS
  7998. || runs < minimum_runs
  7999. #endif
  8000. );
  8001. exit_rsa_pub:
  8002. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  8003. useDeviceID, count, start, ret);
  8004. #ifdef MULTI_VALUE_STATISTICS
  8005. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8006. #endif
  8007. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  8008. }
  8009. else {
  8010. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8011. /* begin RSA sign */
  8012. bench_stats_start(&count, &start);
  8013. do {
  8014. for (times = 0; times < ntimes || pending > 0; ) {
  8015. bench_async_poll(&pending);
  8016. /* while free pending slots in queue, submit ops */
  8017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8018. if (bench_async_check(&ret,
  8019. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8020. 1, &times, ntimes, &pending)) {
  8021. ret = wc_RsaSSL_Sign(message, len, enc[i],
  8022. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  8023. if (!bench_async_handle(&ret,
  8024. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8025. 1, &times, &pending)) {
  8026. goto exit_rsa_sign;
  8027. }
  8028. }
  8029. } /* for i */
  8030. RECORD_MULTI_VALUE_STATS();
  8031. } /* for times */
  8032. count += times;
  8033. } while (bench_stats_check(start)
  8034. #ifdef MULTI_VALUE_STATISTICS
  8035. || runs < minimum_runs
  8036. #endif
  8037. );
  8038. exit_rsa_sign:
  8039. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  8040. count, start, ret);
  8041. #ifdef MULTI_VALUE_STATISTICS
  8042. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8043. #endif
  8044. if (ret < 0) {
  8045. goto exit;
  8046. }
  8047. RESET_MULTI_VALUE_STATS_VARS();
  8048. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  8049. /* capture resulting encrypt length */
  8050. idx = rsaKeySz/8;
  8051. /* begin RSA verify */
  8052. bench_stats_start(&count, &start);
  8053. do {
  8054. for (times = 0; times < ntimes || pending > 0; ) {
  8055. bench_async_poll(&pending);
  8056. /* while free pending slots in queue, submit ops */
  8057. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8058. if (bench_async_check(&ret,
  8059. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8060. 1, &times, ntimes, &pending)) {
  8061. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  8062. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8063. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  8064. rsaKeySz/8, rsaKey[i]);
  8065. #elif defined(USE_CERT_BUFFERS_2048)
  8066. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  8067. idx = sizeof(rsa_2048_sig);
  8068. out[i] = NULL;
  8069. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8070. &out[i], rsaKey[i]);
  8071. if (ret > 0) {
  8072. ret = 0;
  8073. }
  8074. #elif defined(USE_CERT_BUFFERS_3072)
  8075. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  8076. idx = sizeof(rsa_3072_sig);
  8077. out[i] = NULL;
  8078. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8079. &out[i], rsaKey[i]);
  8080. if (ret > 0)
  8081. ret = 0;
  8082. #endif
  8083. if (!bench_async_handle(&ret,
  8084. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8085. 1, &times, &pending)) {
  8086. goto exit_rsa_verifyinline;
  8087. }
  8088. }
  8089. } /* for i */
  8090. RECORD_MULTI_VALUE_STATS();
  8091. } /* for times */
  8092. count += times;
  8093. } while (bench_stats_check(start)
  8094. #ifdef MULTI_VALUE_STATISTICS
  8095. || runs < minimum_runs
  8096. #endif
  8097. );
  8098. exit_rsa_verifyinline:
  8099. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8100. useDeviceID, count, start, ret);
  8101. #ifdef MULTI_VALUE_STATISTICS
  8102. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8103. #endif
  8104. }
  8105. exit:
  8106. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8107. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8108. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8109. #endif
  8110. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8111. WC_FREE_VAR(message, HEAP_HINT);
  8112. #endif
  8113. }
  8114. void bench_rsa(int useDeviceID)
  8115. {
  8116. int i;
  8117. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8118. sizeof(RsaKey), HEAP_HINT);
  8119. int ret = 0;
  8120. word32 rsaKeySz = 0;
  8121. const byte* tmp;
  8122. size_t bytes;
  8123. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8124. word32 idx;
  8125. #endif
  8126. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8127. sizeof(RsaKey), HEAP_HINT);
  8128. #ifdef USE_CERT_BUFFERS_1024
  8129. tmp = rsa_key_der_1024;
  8130. bytes = (size_t)sizeof_rsa_key_der_1024;
  8131. rsaKeySz = 1024;
  8132. #elif defined(USE_CERT_BUFFERS_2048)
  8133. tmp = rsa_key_der_2048;
  8134. bytes = (size_t)sizeof_rsa_key_der_2048;
  8135. rsaKeySz = 2048;
  8136. #elif defined(USE_CERT_BUFFERS_3072)
  8137. tmp = rsa_key_der_3072;
  8138. bytes = (size_t)sizeof_rsa_key_der_3072;
  8139. rsaKeySz = 3072;
  8140. #elif defined(USE_CERT_BUFFERS_4096)
  8141. tmp = client_key_der_4096;
  8142. bytes = (size_t)sizeof_client_key_der_4096;
  8143. rsaKeySz = 4096;
  8144. #else
  8145. #error "need a cert buffer size"
  8146. #endif /* USE_CERT_BUFFERS */
  8147. /* init keys */
  8148. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8149. /* setup an async context for each key */
  8150. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8151. useDeviceID ? devId : INVALID_DEVID);
  8152. if (ret < 0) {
  8153. goto exit;
  8154. }
  8155. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8156. #ifdef WC_RSA_BLINDING
  8157. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8158. if (ret != 0)
  8159. goto exit;
  8160. #endif
  8161. #endif
  8162. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8163. /* decode the private key */
  8164. idx = 0;
  8165. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8166. rsaKey[i], (word32)bytes)) != 0) {
  8167. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8168. goto exit;
  8169. }
  8170. #elif defined(WOLFSSL_PUBLIC_MP)
  8171. /* get offset to public portion of the RSA key */
  8172. #ifdef USE_CERT_BUFFERS_1024
  8173. bytes = 11;
  8174. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8175. bytes = 12;
  8176. #endif
  8177. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8178. if (ret != 0) {
  8179. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8180. goto exit;
  8181. }
  8182. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8183. if (ret != 0) {
  8184. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8185. goto exit;
  8186. }
  8187. #else
  8188. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8189. rsaKeySz = 0;
  8190. #endif
  8191. }
  8192. if (rsaKeySz > 0) {
  8193. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8194. }
  8195. (void)bytes;
  8196. (void)tmp;
  8197. exit:
  8198. /* cleanup */
  8199. if (WC_ARRAY_OK(rsaKey)) {
  8200. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8201. wc_FreeRsaKey(rsaKey[i]);
  8202. }
  8203. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8204. }
  8205. }
  8206. #ifdef WOLFSSL_KEY_GEN
  8207. /* bench any size of RSA key */
  8208. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8209. {
  8210. int ret = 0, i, pending = 0;
  8211. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8212. sizeof(RsaKey), HEAP_HINT);
  8213. int isPending[BENCH_MAX_PENDING];
  8214. long exp = 65537L;
  8215. /* clear for done cleanup */
  8216. XMEMSET(isPending, 0, sizeof(isPending));
  8217. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8218. sizeof(RsaKey), HEAP_HINT);
  8219. /* init keys */
  8220. do {
  8221. pending = 0;
  8222. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8223. if (!isPending[i]) { /* if making the key is pending then just call
  8224. * wc_MakeRsaKey again */
  8225. /* setup an async context for each key */
  8226. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8227. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8228. goto exit;
  8229. }
  8230. #ifdef WC_RSA_BLINDING
  8231. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8232. if (ret != 0)
  8233. goto exit;
  8234. #endif
  8235. }
  8236. /* create the RSA key */
  8237. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8238. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8239. isPending[i] = 1;
  8240. pending = 1;
  8241. }
  8242. else if (ret != 0) {
  8243. printf("wc_MakeRsaKey failed! %d\n", ret);
  8244. goto exit;
  8245. }
  8246. } /* for i */
  8247. } while (pending > 0);
  8248. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8249. exit:
  8250. /* cleanup */
  8251. if (WC_ARRAY_OK(rsaKey)) {
  8252. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8253. wc_FreeRsaKey(rsaKey[i]);
  8254. }
  8255. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8256. }
  8257. }
  8258. #endif /* WOLFSSL_KEY_GEN */
  8259. #endif /* !NO_RSA */
  8260. #ifndef NO_DH
  8261. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8262. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8263. #if defined(WOLFSSL_MDK_SHELL)
  8264. static char *certDHname = "certs/dh2048.der";
  8265. /* set by shell command */
  8266. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8267. #elif defined(FREESCALE_MQX)
  8268. static char *certDHname = "a:\\certs\\dh2048.der";
  8269. #elif defined(NO_ASN)
  8270. /* do nothing, but don't need a file */
  8271. #else
  8272. static const char *certDHname = "certs/dh2048.der";
  8273. #endif
  8274. #endif
  8275. #ifdef HAVE_FFDHE_4096
  8276. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8277. #else
  8278. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8279. #endif
  8280. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8281. void bench_dh(int useDeviceID)
  8282. {
  8283. int ret = 0, i;
  8284. int count = 0, times, pending = 0;
  8285. const byte* tmp = NULL;
  8286. double start = 0.0F;
  8287. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8288. sizeof(DhKey), HEAP_HINT);
  8289. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8290. const char**desc = bench_desc_words[lng_index];
  8291. #ifndef NO_ASN
  8292. size_t bytes = 0;
  8293. word32 idx;
  8294. #endif
  8295. word32 pubSz[BENCH_MAX_PENDING];
  8296. word32 privSz[BENCH_MAX_PENDING];
  8297. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8298. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8299. word32 agreeSz[BENCH_MAX_PENDING];
  8300. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8301. #ifdef HAVE_PUBLIC_FFDHE
  8302. const DhParams *params = NULL;
  8303. #else
  8304. int paramName = 0;
  8305. #endif
  8306. #endif
  8307. DECLARE_MULTI_VALUE_STATS_VARS()
  8308. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8309. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8310. WC_DECLARE_VAR(pub2, byte,
  8311. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8312. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8313. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8314. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8315. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8316. WC_DECLARE_VAR(priv2, byte,
  8317. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8318. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8319. XMEMSET(pub, 0, sizeof(pub));
  8320. XMEMSET(agree, 0, sizeof(agree));
  8321. XMEMSET(priv, 0, sizeof(priv));
  8322. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8323. sizeof(DhKey), HEAP_HINT);
  8324. WC_ALLOC_ARRAY(pub, byte,
  8325. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8326. WC_ALLOC_ARRAY(agree, byte,
  8327. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8328. WC_ALLOC_ARRAY(priv, byte,
  8329. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8330. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8331. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8332. (void)tmp;
  8333. if (!use_ffdhe) {
  8334. #if defined(NO_ASN)
  8335. dhKeySz = 1024;
  8336. /* do nothing, but don't use default FILE */
  8337. #elif defined(USE_CERT_BUFFERS_1024)
  8338. tmp = dh_key_der_1024;
  8339. bytes = (size_t)sizeof_dh_key_der_1024;
  8340. dhKeySz = 1024;
  8341. #elif defined(USE_CERT_BUFFERS_2048)
  8342. tmp = dh_key_der_2048;
  8343. bytes = (size_t)sizeof_dh_key_der_2048;
  8344. dhKeySz = 2048;
  8345. #elif defined(USE_CERT_BUFFERS_3072)
  8346. tmp = dh_key_der_3072;
  8347. bytes = (size_t)sizeof_dh_key_der_3072;
  8348. dhKeySz = 3072;
  8349. #elif defined(USE_CERT_BUFFERS_4096)
  8350. tmp = dh_key_der_4096;
  8351. bytes = (size_t)sizeof_dh_key_der_4096;
  8352. dhKeySz = 4096;
  8353. #else
  8354. #error "need to define a cert buffer size"
  8355. #endif /* USE_CERT_BUFFERS */
  8356. }
  8357. #ifdef HAVE_FFDHE_2048
  8358. else if (use_ffdhe == 2048) {
  8359. #ifdef HAVE_PUBLIC_FFDHE
  8360. params = wc_Dh_ffdhe2048_Get();
  8361. #else
  8362. paramName = WC_FFDHE_2048;
  8363. #endif
  8364. dhKeySz = 2048;
  8365. }
  8366. #endif
  8367. #ifdef HAVE_FFDHE_3072
  8368. else if (use_ffdhe == 3072) {
  8369. #ifdef HAVE_PUBLIC_FFDHE
  8370. params = wc_Dh_ffdhe3072_Get();
  8371. #else
  8372. paramName = WC_FFDHE_3072;
  8373. #endif
  8374. dhKeySz = 3072;
  8375. }
  8376. #endif
  8377. #ifdef HAVE_FFDHE_4096
  8378. else if (use_ffdhe == 4096) {
  8379. #ifdef HAVE_PUBLIC_FFDHE
  8380. params = wc_Dh_ffdhe4096_Get();
  8381. #else
  8382. paramName = WC_FFDHE_4096;
  8383. #endif
  8384. dhKeySz = 4096;
  8385. }
  8386. #endif
  8387. /* init keys */
  8388. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8389. /* setup an async context for each key */
  8390. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8391. useDeviceID ? devId : INVALID_DEVID);
  8392. if (ret != 0)
  8393. goto exit;
  8394. /* setup key */
  8395. if (!use_ffdhe) {
  8396. #ifdef NO_ASN
  8397. ret = wc_DhSetKey(dhKey[i], dh_p,
  8398. sizeof(dh_p), dh_g, sizeof(dh_g));
  8399. #else
  8400. idx = 0;
  8401. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8402. #endif
  8403. }
  8404. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8405. #ifdef HAVE_PUBLIC_FFDHE
  8406. else if (params != NULL) {
  8407. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8408. params->g, params->g_len);
  8409. }
  8410. #else
  8411. else if (paramName != 0) {
  8412. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8413. }
  8414. #endif
  8415. #endif
  8416. if (ret != 0) {
  8417. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8418. goto exit;
  8419. }
  8420. }
  8421. /* Key Gen */
  8422. bench_stats_start(&count, &start);
  8423. PRIVATE_KEY_UNLOCK();
  8424. do {
  8425. /* while free pending slots in queue, submit ops */
  8426. for (times = 0; times < genTimes || pending > 0; ) {
  8427. bench_async_poll(&pending);
  8428. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8429. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8430. 0, &times, genTimes, &pending)) {
  8431. privSz[i] = BENCH_DH_PRIV_SIZE;
  8432. pubSz[i] = BENCH_DH_KEY_SIZE;
  8433. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8434. priv[i], &privSz[i],
  8435. pub[i], &pubSz[i]);
  8436. if (!bench_async_handle(&ret,
  8437. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8438. 0, &times, &pending)) {
  8439. goto exit_dh_gen;
  8440. }
  8441. }
  8442. } /* for i */
  8443. RECORD_MULTI_VALUE_STATS();
  8444. } /* for times */
  8445. count += times;
  8446. } while (bench_stats_check(start)
  8447. #ifdef MULTI_VALUE_STATISTICS
  8448. || runs < minimum_runs
  8449. #endif
  8450. );
  8451. PRIVATE_KEY_LOCK();
  8452. exit_dh_gen:
  8453. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8454. useDeviceID, count, start, ret);
  8455. #ifdef MULTI_VALUE_STATISTICS
  8456. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8457. #endif
  8458. if (ret < 0) {
  8459. goto exit;
  8460. }
  8461. RESET_MULTI_VALUE_STATS_VARS();
  8462. /* Generate key to use as other public */
  8463. PRIVATE_KEY_UNLOCK();
  8464. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8465. priv2, &privSz2, pub2, &pubSz2);
  8466. PRIVATE_KEY_LOCK();
  8467. #ifdef WOLFSSL_ASYNC_CRYPT
  8468. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8469. #endif
  8470. /* Key Agree */
  8471. bench_stats_start(&count, &start);
  8472. PRIVATE_KEY_UNLOCK();
  8473. do {
  8474. for (times = 0; times < agreeTimes || pending > 0; ) {
  8475. bench_async_poll(&pending);
  8476. /* while free pending slots in queue, submit ops */
  8477. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8478. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8479. 0, &times, agreeTimes, &pending)) {
  8480. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8481. privSz[i], pub2, pubSz2);
  8482. if (!bench_async_handle(&ret,
  8483. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8484. goto exit;
  8485. }
  8486. }
  8487. } /* for i */
  8488. RECORD_MULTI_VALUE_STATS();
  8489. } /* for times */
  8490. count += times;
  8491. } while (bench_stats_check(start)
  8492. #ifdef MULTI_VALUE_STATISTICS
  8493. || runs < minimum_runs
  8494. #endif
  8495. );
  8496. PRIVATE_KEY_LOCK();
  8497. exit:
  8498. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8499. useDeviceID, count, start, ret);
  8500. #ifdef MULTI_VALUE_STATISTICS
  8501. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8502. #endif
  8503. /* cleanup */
  8504. if (WC_ARRAY_OK(dhKey)) {
  8505. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8506. wc_FreeDhKey(dhKey[i]);
  8507. }
  8508. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8509. }
  8510. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8511. WC_FREE_VAR(pub2, HEAP_HINT);
  8512. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8513. WC_FREE_VAR(priv2, HEAP_HINT);
  8514. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8515. }
  8516. #endif /* !NO_DH */
  8517. #ifdef WOLFSSL_HAVE_KYBER
  8518. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8519. KyberKey* key)
  8520. {
  8521. int ret = 0, times, count, pending = 0;
  8522. double start;
  8523. const char**desc = bench_desc_words[lng_index];
  8524. DECLARE_MULTI_VALUE_STATS_VARS()
  8525. /* KYBER Make Key */
  8526. bench_stats_start(&count, &start);
  8527. do {
  8528. /* while free pending slots in queue, submit ops */
  8529. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8530. wc_KyberKey_Free(key);
  8531. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8532. if (ret != 0)
  8533. goto exit;
  8534. #ifdef KYBER_NONDETERMINISTIC
  8535. ret = wc_KyberKey_MakeKey(key, &gRng);
  8536. #else
  8537. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8538. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8539. #endif
  8540. if (ret != 0)
  8541. goto exit;
  8542. RECORD_MULTI_VALUE_STATS();
  8543. } /* for times */
  8544. count += times;
  8545. } while (bench_stats_check(start)
  8546. #ifdef MULTI_VALUE_STATISTICS
  8547. || runs < minimum_runs
  8548. #endif
  8549. );
  8550. exit:
  8551. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8552. #ifdef MULTI_VALUE_STATISTICS
  8553. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8554. #endif
  8555. }
  8556. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8557. {
  8558. int ret = 0, times, count, pending = 0;
  8559. double start;
  8560. const char**desc = bench_desc_words[lng_index];
  8561. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8562. byte ss[KYBER_SS_SZ];
  8563. word32 ctSz;
  8564. DECLARE_MULTI_VALUE_STATS_VARS()
  8565. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8566. if (ret != 0) {
  8567. return;
  8568. }
  8569. /* KYBER Encapsulate */
  8570. bench_stats_start(&count, &start);
  8571. do {
  8572. /* while free pending slots in queue, submit ops */
  8573. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8574. #ifdef KYBER_NONDETERMINISTIC
  8575. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8576. #else
  8577. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8578. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8579. sizeof(rand));
  8580. #endif
  8581. if (ret != 0)
  8582. goto exit_encap;
  8583. RECORD_MULTI_VALUE_STATS();
  8584. } /* for times */
  8585. count += times;
  8586. } while (bench_stats_check(start)
  8587. #ifdef MULTI_VALUE_STATISTICS
  8588. || runs < minimum_runs
  8589. #endif
  8590. );
  8591. exit_encap:
  8592. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8593. #ifdef MULTI_VALUE_STATISTICS
  8594. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8595. #endif
  8596. RESET_MULTI_VALUE_STATS_VARS();
  8597. /* KYBER Decapsulate */
  8598. bench_stats_start(&count, &start);
  8599. do {
  8600. /* while free pending slots in queue, submit ops */
  8601. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8602. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8603. if (ret != 0)
  8604. goto exit_decap;
  8605. RECORD_MULTI_VALUE_STATS();
  8606. } /* for times */
  8607. count += times;
  8608. } while (bench_stats_check(start)
  8609. #ifdef MULTI_VALUE_STATISTICS
  8610. || runs < minimum_runs
  8611. #endif
  8612. );
  8613. exit_decap:
  8614. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8615. #ifdef MULTI_VALUE_STATISTICS
  8616. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8617. #endif
  8618. }
  8619. void bench_kyber(int type)
  8620. {
  8621. KyberKey key;
  8622. const char* name = NULL;
  8623. int keySize = 0;
  8624. switch (type) {
  8625. #ifndef WOLFSSL_NO_ML_KEM
  8626. #ifdef WOLFSSL_WC_ML_KEM_512
  8627. case WC_ML_KEM_512:
  8628. name = "ML-KEM 512 ";
  8629. keySize = 128;
  8630. break;
  8631. #endif
  8632. #ifdef WOLFSSL_WC_ML_KEM_768
  8633. case WC_ML_KEM_768:
  8634. name = "ML-KEM 768 ";
  8635. keySize = 192;
  8636. break;
  8637. #endif
  8638. #ifdef WOLFSSL_WC_ML_KEM_1024
  8639. case WC_ML_KEM_1024:
  8640. name = "ML-KEM 1024 ";
  8641. keySize = 256;
  8642. break;
  8643. #endif
  8644. #endif
  8645. #ifdef WOLFSSL_KYBER_ORIGINAL
  8646. #ifdef WOLFSSL_KYBER512
  8647. case KYBER512:
  8648. name = "KYBER512 ";
  8649. keySize = 128;
  8650. break;
  8651. #endif
  8652. #ifdef WOLFSSL_KYBER768
  8653. case KYBER768:
  8654. name = "KYBER768 ";
  8655. keySize = 192;
  8656. break;
  8657. #endif
  8658. #ifdef WOLFSSL_KYBER1024
  8659. case KYBER1024:
  8660. name = "KYBER1024";
  8661. keySize = 256;
  8662. break;
  8663. #endif
  8664. #endif
  8665. }
  8666. bench_kyber_keygen(type, name, keySize, &key);
  8667. bench_kyber_encap(name, keySize, &key);
  8668. wc_KyberKey_Free(&key);
  8669. }
  8670. #endif
  8671. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8672. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8673. /* WC_LMS_PARM_L2_H10_W2
  8674. * signature length: 9300 */
  8675. static const byte lms_priv_L2_H10_W2[64] =
  8676. {
  8677. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8678. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8679. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8680. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8681. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8682. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8683. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8684. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8685. };
  8686. static const byte lms_pub_L2_H10_W2[60] =
  8687. {
  8688. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8689. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8690. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8691. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8692. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8693. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8694. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8695. 0x7F,0xC8,0x91,0xB0
  8696. };
  8697. /* WC_LMS_PARM_L2_H10_W4
  8698. * signature length: 5076 */
  8699. static const byte lms_priv_L2_H10_W4[64] =
  8700. {
  8701. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8702. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8703. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8704. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8705. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8706. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8707. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8708. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8709. };
  8710. static const byte lms_pub_L2_H10_W4[60] =
  8711. {
  8712. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8713. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8714. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8715. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8716. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8717. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8718. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8719. 0x6B,0x9A,0xD3,0x14
  8720. };
  8721. /* WC_LMS_PARM_L3_H5_W4
  8722. * signature length: 7160 */
  8723. static const byte lms_priv_L3_H5_W4[64] =
  8724. {
  8725. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8726. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8727. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8728. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8729. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8730. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8731. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8732. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8733. };
  8734. static const byte lms_pub_L3_H5_W4[60] =
  8735. {
  8736. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8737. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8738. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8739. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8740. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8741. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8742. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8743. 0xAB,0x4B,0x51,0x39
  8744. };
  8745. /* WC_LMS_PARM_L3_H5_W8
  8746. * signature length: 3992 */
  8747. static const byte lms_priv_L3_H5_W8[64] =
  8748. {
  8749. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8750. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8751. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8752. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8753. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8754. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8755. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8756. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8757. };
  8758. static const byte lms_pub_L3_H5_W8[60] =
  8759. {
  8760. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8761. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8762. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8763. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8764. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8765. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8766. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8767. 0x83,0xAB,0x43,0xAF
  8768. };
  8769. /* WC_LMS_PARM_L3_H10_W4
  8770. * signature length: 7640 */
  8771. static const byte lms_priv_L3_H10_W4[64] =
  8772. {
  8773. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8774. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8775. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8776. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8777. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8778. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8779. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8780. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8781. };
  8782. static const byte lms_pub_L3_H10_W4[60] =
  8783. {
  8784. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8785. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8786. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8787. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8788. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8789. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8790. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8791. 0x8D,0x78,0xD5,0xA8
  8792. };
  8793. /* WC_LMS_PARM_L4_H5_W8
  8794. * signature length: 5340 */
  8795. static const byte lms_priv_L4_H5_W8[64] =
  8796. {
  8797. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8798. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8799. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8800. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8801. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8802. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8803. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8804. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8805. };
  8806. static const byte lms_pub_L4_H5_W8[60] =
  8807. {
  8808. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8809. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8810. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8811. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8812. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8813. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8814. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8815. 0x74,0x24,0x12,0xC8
  8816. };
  8817. #endif
  8818. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8819. {
  8820. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8821. * BE USED FOR TESTING PURPOSES! Production applications should
  8822. * write only to non-volatile storage. */
  8823. XMEMCPY(context, priv, privSz);
  8824. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8825. }
  8826. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8827. {
  8828. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8829. * BE USED FOR TESTING PURPOSES! */
  8830. XMEMCPY(priv, context, privSz);
  8831. return WC_LMS_RC_READ_TO_MEMORY;
  8832. }
  8833. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8834. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8835. {
  8836. WC_RNG rng;
  8837. LmsKey key;
  8838. int ret;
  8839. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8840. int times = 0;
  8841. int count = 0;
  8842. double start = 0.0F;
  8843. int levels;
  8844. int height;
  8845. int winternitz;
  8846. const char* str = wc_LmsKey_ParmToStr(parm);
  8847. DECLARE_MULTI_VALUE_STATS_VARS()
  8848. #ifndef HAVE_FIPS
  8849. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8850. #else
  8851. ret = wc_InitRng(&rng);
  8852. #endif
  8853. if (ret != 0) {
  8854. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8855. return;
  8856. }
  8857. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8858. if (ret) {
  8859. printf("wc_LmsKey_Init failed: %d\n", ret);
  8860. wc_FreeRng(&rng);
  8861. return;
  8862. }
  8863. count = 0;
  8864. bench_stats_start(&count, &start);
  8865. do {
  8866. /* LMS is stateful. Async queuing not practical. */
  8867. for (times = 0; times < 1; ++times) {
  8868. wc_LmsKey_Free(&key);
  8869. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8870. if (ret) {
  8871. printf("wc_LmsKey_Init failed: %d\n", ret);
  8872. goto exit_lms_keygen;
  8873. }
  8874. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8875. if (ret) {
  8876. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8877. goto exit_lms_keygen;
  8878. }
  8879. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8880. if (ret) {
  8881. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8882. ret);
  8883. goto exit_lms_keygen;
  8884. }
  8885. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8886. if (ret) {
  8887. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8888. ret);
  8889. goto exit_lms_keygen;
  8890. }
  8891. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8892. if (ret) {
  8893. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8894. goto exit_lms_keygen;
  8895. }
  8896. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8897. if (ret) {
  8898. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8899. ret);
  8900. goto exit_lms_keygen;
  8901. }
  8902. ret = wc_LmsKey_MakeKey(&key, &rng);
  8903. if (ret) {
  8904. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8905. goto exit_lms_keygen;
  8906. }
  8907. RECORD_MULTI_VALUE_STATS();
  8908. }
  8909. count += times;
  8910. } while (bench_stats_check(start)
  8911. #ifdef MULTI_VALUE_STATISTICS
  8912. || runs < minimum_runs
  8913. #endif
  8914. );
  8915. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8916. count, start, ret);
  8917. #ifdef MULTI_VALUE_STATISTICS
  8918. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8919. #endif
  8920. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8921. if (ret) {
  8922. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8923. }
  8924. exit_lms_keygen:
  8925. wc_LmsKey_Free(&key);
  8926. wc_FreeRng(&rng);
  8927. }
  8928. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8929. {
  8930. LmsKey key;
  8931. int ret = 0;
  8932. const char * msg = TEST_STRING;
  8933. word32 msgSz = TEST_STRING_SZ;
  8934. byte * sig = NULL;
  8935. word32 sigSz = 0;
  8936. word32 privLen = 0;
  8937. int loaded = 0;
  8938. int times = 0;
  8939. int count = 0;
  8940. double start = 0.0F;
  8941. const char * str = wc_LmsKey_ParmToStr(parm);
  8942. DECLARE_MULTI_VALUE_STATS_VARS()
  8943. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8944. if (ret) {
  8945. printf("wc_LmsKey_Init failed: %d\n", ret);
  8946. goto exit_lms_sign_verify;
  8947. }
  8948. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8949. if (ret) {
  8950. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8951. goto exit_lms_sign_verify;
  8952. }
  8953. switch (parm) {
  8954. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8955. case WC_LMS_PARM_L2_H10_W2:
  8956. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8957. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8958. break;
  8959. case WC_LMS_PARM_L2_H10_W4:
  8960. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8961. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8962. break;
  8963. case WC_LMS_PARM_L3_H5_W4:
  8964. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8965. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8966. break;
  8967. case WC_LMS_PARM_L3_H5_W8:
  8968. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8969. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8970. break;
  8971. case WC_LMS_PARM_L3_H10_W4:
  8972. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8973. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8974. break;
  8975. case WC_LMS_PARM_L4_H5_W8:
  8976. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8977. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8978. break;
  8979. case WC_LMS_PARM_NONE:
  8980. case WC_LMS_PARM_L1_H15_W2:
  8981. case WC_LMS_PARM_L1_H15_W4:
  8982. case WC_LMS_PARM_L2_H10_W8:
  8983. case WC_LMS_PARM_L3_H5_W2:
  8984. case WC_LMS_PARM_L1_H5_W1:
  8985. case WC_LMS_PARM_L1_H5_W2:
  8986. case WC_LMS_PARM_L1_H5_W4:
  8987. case WC_LMS_PARM_L1_H5_W8:
  8988. case WC_LMS_PARM_L1_H10_W2:
  8989. case WC_LMS_PARM_L1_H10_W4:
  8990. case WC_LMS_PARM_L1_H10_W8:
  8991. case WC_LMS_PARM_L1_H15_W8:
  8992. case WC_LMS_PARM_L1_H20_W2:
  8993. case WC_LMS_PARM_L1_H20_W4:
  8994. case WC_LMS_PARM_L1_H20_W8:
  8995. case WC_LMS_PARM_L2_H5_W2:
  8996. case WC_LMS_PARM_L2_H5_W4:
  8997. case WC_LMS_PARM_L2_H5_W8:
  8998. case WC_LMS_PARM_L2_H15_W2:
  8999. case WC_LMS_PARM_L2_H15_W4:
  9000. case WC_LMS_PARM_L2_H15_W8:
  9001. case WC_LMS_PARM_L2_H20_W2:
  9002. case WC_LMS_PARM_L2_H20_W4:
  9003. case WC_LMS_PARM_L2_H20_W8:
  9004. case WC_LMS_PARM_L3_H10_W8:
  9005. case WC_LMS_PARM_L4_H5_W2:
  9006. case WC_LMS_PARM_L4_H5_W4:
  9007. case WC_LMS_PARM_L4_H10_W4:
  9008. case WC_LMS_PARM_L4_H10_W8:
  9009. #endif
  9010. #ifdef WOLFSSL_LMS_SHA256_192
  9011. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  9012. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  9013. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  9014. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  9015. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  9016. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  9017. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  9018. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  9019. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  9020. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  9021. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  9022. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  9023. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  9024. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  9025. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  9026. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  9027. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  9028. #endif
  9029. default:
  9030. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  9031. break;
  9032. }
  9033. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  9034. if (ret) {
  9035. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  9036. goto exit_lms_sign_verify;
  9037. }
  9038. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  9039. if (ret) {
  9040. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  9041. goto exit_lms_sign_verify;
  9042. }
  9043. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  9044. if (ret) {
  9045. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  9046. goto exit_lms_sign_verify;
  9047. }
  9048. /* Even with saved priv/pub keys, we must still reload the private
  9049. * key before using it. Reloading the private key is the bottleneck
  9050. * for larger heights. Only print load time in debug builds. */
  9051. count = 0;
  9052. bench_stats_start(&count, &start);
  9053. #ifndef WOLFSSL_WC_LMS_SMALL
  9054. do {
  9055. #ifdef WOLFSSL_WC_LMS
  9056. key.priv.inited = 0;
  9057. key.state = WC_LMS_STATE_PARMSET;
  9058. #endif
  9059. ret = wc_LmsKey_Reload(&key);
  9060. if (ret) {
  9061. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9062. goto exit_lms_sign_verify;
  9063. }
  9064. RECORD_MULTI_VALUE_STATS();
  9065. count++;
  9066. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9067. if (ret) {
  9068. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9069. goto exit_lms_sign_verify;
  9070. }
  9071. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9072. if (ret) {
  9073. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9074. goto exit_lms_sign_verify;
  9075. }
  9076. #ifdef HAVE_LIBLMS
  9077. break;
  9078. #endif
  9079. } while (bench_stats_check(start)
  9080. #ifdef MULTI_VALUE_STATISTICS
  9081. || runs < minimum_runs
  9082. #endif
  9083. );
  9084. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  9085. count, start, ret);
  9086. #ifdef MULTI_VALUE_STATISTICS
  9087. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9088. #endif
  9089. RESET_MULTI_VALUE_STATS_VARS();
  9090. #else
  9091. ret = wc_LmsKey_Reload(&key);
  9092. if (ret) {
  9093. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9094. goto exit_lms_sign_verify;
  9095. }
  9096. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9097. if (ret) {
  9098. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9099. goto exit_lms_sign_verify;
  9100. }
  9101. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9102. if (ret) {
  9103. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9104. goto exit_lms_sign_verify;
  9105. }
  9106. #endif
  9107. loaded = 1;
  9108. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9109. if (sig == NULL) {
  9110. printf("bench_lms_sign_verify malloc failed\n");
  9111. goto exit_lms_sign_verify;
  9112. }
  9113. count = 0;
  9114. bench_stats_start(&count, &start);
  9115. do {
  9116. /* LMS is stateful. Async queuing not practical. */
  9117. #ifndef WOLFSSL_WC_LMS_SMALL
  9118. for (times = 0; times < ntimes; ++times)
  9119. #else
  9120. for (times = 0; times < 1; ++times)
  9121. #endif
  9122. {
  9123. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9124. if (ret) {
  9125. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9126. goto exit_lms_sign_verify;
  9127. }
  9128. RECORD_MULTI_VALUE_STATS();
  9129. if (!wc_LmsKey_SigsLeft(&key)) {
  9130. break;
  9131. }
  9132. }
  9133. count += times;
  9134. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9135. #ifdef MULTI_VALUE_STATISTICS
  9136. || runs < minimum_runs
  9137. #endif
  9138. ));
  9139. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9140. count, start, ret);
  9141. #ifdef MULTI_VALUE_STATISTICS
  9142. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9143. #endif
  9144. RESET_MULTI_VALUE_STATS_VARS();
  9145. count = 0;
  9146. bench_stats_start(&count, &start);
  9147. do {
  9148. /* LMS is stateful. Async queuing not practical. */
  9149. for (times = 0; times < ntimes; ++times) {
  9150. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9151. if (ret) {
  9152. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9153. goto exit_lms_sign_verify;
  9154. }
  9155. RECORD_MULTI_VALUE_STATS();
  9156. }
  9157. count += times;
  9158. } while (bench_stats_check(start)
  9159. #ifdef MULTI_VALUE_STATISTICS
  9160. || runs < minimum_runs
  9161. #endif
  9162. );
  9163. exit_lms_sign_verify:
  9164. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9165. count, start, ret);
  9166. #ifdef MULTI_VALUE_STATISTICS
  9167. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9168. #endif
  9169. if (loaded) {
  9170. wc_LmsKey_Free(&key);
  9171. }
  9172. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9173. return;
  9174. }
  9175. void bench_lms(void)
  9176. {
  9177. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9178. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9179. #ifdef BENCH_LMS_SLOW_KEYGEN
  9180. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9181. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9182. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9183. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9184. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9185. #undef LMS_PARAMS_BENCHED
  9186. #define LMS_PARAMS_BENCHED
  9187. #endif
  9188. #endif
  9189. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9190. (LMS_MAX_HEIGHT >= 10))
  9191. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9192. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9193. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9194. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9195. #undef LMS_PARAMS_BENCHED
  9196. #define LMS_PARAMS_BENCHED
  9197. #ifdef BENCH_LMS_SLOW_KEYGEN
  9198. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9199. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9200. #endif
  9201. #endif
  9202. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9203. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9204. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9205. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9206. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9207. #undef LMS_PARAMS_BENCHED
  9208. #define LMS_PARAMS_BENCHED
  9209. #endif
  9210. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9211. (LMS_MAX_HEIGHT >= 10))
  9212. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9213. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9214. #endif
  9215. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9216. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9217. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9218. #endif
  9219. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9220. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9221. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9222. #endif
  9223. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9224. #ifdef WOLFSSL_LMS_SHA256_192
  9225. #ifdef BENCH_LMS_SLOW_KEYGEN
  9226. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9227. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9228. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9229. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9230. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9231. #undef LMS_PARAMS_BENCHED
  9232. #define LMS_PARAMS_BENCHED
  9233. #endif
  9234. #endif
  9235. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9236. (LMS_MAX_HEIGHT >= 10))
  9237. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9238. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9239. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9240. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9241. #undef LMS_PARAMS_BENCHED
  9242. #define LMS_PARAMS_BENCHED
  9243. #ifdef BENCH_LMS_SLOW_KEYGEN
  9244. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9245. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9246. #endif
  9247. #endif
  9248. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9249. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9250. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9251. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9252. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9253. #undef LMS_PARAMS_BENCHED
  9254. #define LMS_PARAMS_BENCHED
  9255. #endif
  9256. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9257. (LMS_MAX_HEIGHT >= 10))
  9258. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9259. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9260. #endif
  9261. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9262. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9263. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9264. #endif
  9265. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9266. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9267. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9268. #endif
  9269. #endif /* WOLFSSL_LMS_SHA256_192 */
  9270. return;
  9271. }
  9272. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9273. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9274. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9275. void *context)
  9276. {
  9277. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9278. * BE USED FOR TESTING PURPOSES! Production applications should
  9279. * write only to non-volatile storage. */
  9280. XMEMCPY(context, priv, privSz);
  9281. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9282. }
  9283. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9284. void *context)
  9285. {
  9286. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9287. * BE USED FOR TESTING PURPOSES! */
  9288. XMEMCPY(priv, context, privSz);
  9289. return WC_XMSS_RC_READ_TO_MEMORY;
  9290. }
  9291. static void bench_xmss_sign_verify(const char * params)
  9292. {
  9293. WC_RNG rng;
  9294. XmssKey key;
  9295. word32 pkSz = 0;
  9296. word32 skSz = 0;
  9297. int freeRng = 0;
  9298. int freeKey = 0;
  9299. unsigned char * sk = NULL;
  9300. const char * msg = "XMSS post quantum signature test";
  9301. word32 msgSz = (word32) XSTRLEN(msg);
  9302. int ret = 0;
  9303. byte * sig = NULL;
  9304. word32 sigSz = 0;
  9305. int times = 0;
  9306. int count = 0;
  9307. double start = 0.0F;
  9308. #ifndef HAVE_FIPS
  9309. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9310. #else
  9311. ret = wc_InitRng(&rng);
  9312. #endif
  9313. if (ret != 0) {
  9314. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9315. goto exit_xmss_sign_verify;
  9316. }
  9317. freeRng = 1;
  9318. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9319. if (ret != 0) {
  9320. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9321. goto exit_xmss_sign_verify;
  9322. }
  9323. ret = wc_XmssKey_SetParamStr(&key, params);
  9324. if (ret != 0) {
  9325. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9326. goto exit_xmss_sign_verify;
  9327. }
  9328. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9329. if (ret != 0) {
  9330. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9331. goto exit_xmss_sign_verify;
  9332. }
  9333. #ifndef WOLFSSL_WC_XMSS
  9334. if (pkSz != XMSS_SHA256_PUBLEN) {
  9335. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9336. XMSS_SHA256_PUBLEN);
  9337. goto exit_xmss_sign_verify;
  9338. }
  9339. #endif
  9340. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9341. if (ret != 0 || skSz <= 0) {
  9342. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9343. goto exit_xmss_sign_verify;
  9344. }
  9345. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9346. if (ret != 0 || sigSz <= 0) {
  9347. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9348. goto exit_xmss_sign_verify;
  9349. }
  9350. /* Allocate secret keys.*/
  9351. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9352. if (sk == NULL) {
  9353. fprintf(stderr, "error: allocate xmss sk failed\n");
  9354. goto exit_xmss_sign_verify;
  9355. }
  9356. /* Allocate signature array. */
  9357. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9358. if (sig == NULL) {
  9359. fprintf(stderr, "error: allocate xmss sig failed\n");
  9360. goto exit_xmss_sign_verify;
  9361. }
  9362. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9363. if (ret != 0) {
  9364. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9365. goto exit_xmss_sign_verify;
  9366. }
  9367. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9368. if (ret != 0) {
  9369. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9370. goto exit_xmss_sign_verify;
  9371. }
  9372. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9373. if (ret != 0) {
  9374. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9375. goto exit_xmss_sign_verify;
  9376. }
  9377. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9378. fprintf(stderr, "params: %s\n", params);
  9379. fprintf(stderr, "pkSz: %d\n", pkSz);
  9380. fprintf(stderr, "skSz: %d\n", skSz);
  9381. fprintf(stderr, "sigSz: %d\n", sigSz);
  9382. #endif
  9383. /* Making the private key is the bottleneck for larger heights. */
  9384. count = 0;
  9385. bench_stats_start(&count, &start);
  9386. ret = wc_XmssKey_MakeKey(&key, &rng);
  9387. if (ret != 0) {
  9388. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9389. goto exit_xmss_sign_verify;
  9390. }
  9391. /* Can only do one at a time - state changes after make key. */
  9392. count +=1;
  9393. bench_stats_check(start);
  9394. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9395. freeKey = 1;
  9396. count = 0;
  9397. bench_stats_start(&count, &start);
  9398. do {
  9399. /* XMSS is stateful. Async queuing not practical. */
  9400. #ifndef WOLFSSL_WC_XMSS_SMALL
  9401. for (times = 0; times < ntimes; ++times)
  9402. #else
  9403. for (times = 0; times < 1; ++times)
  9404. #endif
  9405. {
  9406. if (!wc_XmssKey_SigsLeft(&key))
  9407. break;
  9408. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9409. if (ret) {
  9410. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9411. goto exit_xmss_sign_verify;
  9412. }
  9413. }
  9414. count += times;
  9415. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9416. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9417. count = 0;
  9418. bench_stats_start(&count, &start);
  9419. do {
  9420. /* XMSS is stateful. Async queuing not practical. */
  9421. for (times = 0; times < ntimes; ++times) {
  9422. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9423. if (ret) {
  9424. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9425. goto exit_xmss_sign_verify;
  9426. }
  9427. }
  9428. count += times;
  9429. } while (bench_stats_check(start));
  9430. exit_xmss_sign_verify:
  9431. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9432. /* Cleanup everything. */
  9433. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9434. sig = NULL;
  9435. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9436. sk = NULL;
  9437. if (freeRng) {
  9438. wc_FreeRng(&rng);
  9439. }
  9440. if (freeKey) {
  9441. wc_XmssKey_Free(&key);
  9442. }
  9443. return;
  9444. }
  9445. void bench_xmss(int hash)
  9446. {
  9447. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9448. * sets.
  9449. *
  9450. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9451. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9452. * very slow, their signatures and private keys quite large,
  9453. * and xmss private keys are not portable across different
  9454. * XMSS/XMSS^MT implementations.
  9455. *
  9456. * The bottleneck in key generation is the height of the first
  9457. * level tree (or h/d).
  9458. *
  9459. * h is the total height of the hyper tree, and d the number of
  9460. * trees.
  9461. */
  9462. /* h/d h d */
  9463. #ifdef WC_XMSS_SHA256
  9464. if (hash == WC_HASH_TYPE_SHA256) {
  9465. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9466. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9467. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9468. #endif
  9469. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9470. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9471. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9472. #endif
  9473. #endif
  9474. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9475. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9476. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9477. #endif
  9478. #endif
  9479. #endif /* HASH_SIZE 256 */
  9480. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9481. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9482. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9483. #endif
  9484. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9485. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9486. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9487. #endif
  9488. #endif
  9489. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9490. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9491. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9492. #endif
  9493. #endif
  9494. #endif /* HASH_SIZE 192 */
  9495. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9496. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9497. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9498. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9499. #endif
  9500. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9501. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9502. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9503. #endif
  9504. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9505. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9506. #endif
  9507. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9508. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9509. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9510. #endif
  9511. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9512. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9513. #endif
  9514. #endif /* HASH_SIZE 256 */
  9515. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9516. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9517. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9518. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9519. #endif
  9520. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9521. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9522. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9523. #endif
  9524. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9525. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9526. #endif
  9527. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9528. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9529. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9530. #endif
  9531. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9532. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9533. #endif
  9534. #endif /* HASH_SIZE 192 */
  9535. }
  9536. #endif
  9537. #ifdef WC_XMSS_SHA512
  9538. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9539. if (hash == WC_HASH_TYPE_SHA512) {
  9540. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9541. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9542. #endif
  9543. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9544. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9545. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9546. #endif
  9547. #endif
  9548. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9549. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9550. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9551. #endif
  9552. #endif
  9553. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9554. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9555. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9556. #endif
  9557. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9558. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9559. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9560. #endif
  9561. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9562. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9563. #endif
  9564. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9565. #endif
  9566. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9567. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9568. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9569. #endif
  9570. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9571. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9572. #endif
  9573. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9574. #endif
  9575. }
  9576. #endif /* HASH_SIZE 512 */
  9577. #endif
  9578. #ifdef WC_XMSS_SHAKE128
  9579. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9580. if (hash == WC_HASH_TYPE_SHAKE128) {
  9581. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9582. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9583. #endif
  9584. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9585. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9586. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9587. #endif
  9588. #endif
  9589. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9590. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9591. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9592. #endif
  9593. #endif
  9594. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9595. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9596. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9597. #endif
  9598. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9599. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9600. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9601. #endif
  9602. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9603. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9604. #endif
  9605. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9606. #endif
  9607. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9608. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9609. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9610. #endif
  9611. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9612. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9613. #endif
  9614. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9615. #endif
  9616. }
  9617. #endif /* HASH_SIZE 256 */
  9618. #endif
  9619. #ifdef WC_XMSS_SHAKE256
  9620. if (hash == WC_HASH_TYPE_SHAKE256) {
  9621. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9622. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9623. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9624. #endif
  9625. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9626. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9627. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9628. #endif
  9629. #endif
  9630. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9631. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9632. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9633. #endif
  9634. #endif
  9635. #endif /* HASH_SIZE 512 */
  9636. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9637. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9638. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9639. #endif
  9640. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9641. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9642. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9643. #endif
  9644. #endif
  9645. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9646. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9647. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9648. #endif
  9649. #endif
  9650. #endif /* HASH_SIZE 256 */
  9651. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9652. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9653. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9654. #endif
  9655. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9656. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9657. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9658. #endif
  9659. #endif
  9660. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9661. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9662. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9663. #endif
  9664. #endif
  9665. #endif /* HASH_SIZE 192 */
  9666. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9667. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9668. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9669. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9670. #endif
  9671. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9672. #endif
  9673. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9674. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9675. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9676. #endif
  9677. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9678. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9679. #endif
  9680. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9681. #endif
  9682. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9683. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9684. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9685. #endif
  9686. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9687. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9688. #endif
  9689. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9690. #endif
  9691. #endif /* HASH_SIZE 512 */
  9692. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9693. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9694. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9695. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9696. #endif
  9697. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9698. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9699. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9700. #endif
  9701. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9702. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9703. #endif
  9704. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9705. #endif
  9706. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9707. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9708. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9709. #endif
  9710. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9711. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9712. #endif
  9713. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9714. #endif
  9715. #endif /* HASH_SIZE 256 */
  9716. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9717. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9718. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9719. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9720. #endif
  9721. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9722. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9723. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9724. #endif
  9725. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9726. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9727. #endif
  9728. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9729. #endif
  9730. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9731. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9732. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9733. #endif
  9734. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9735. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9736. #endif
  9737. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9738. #endif
  9739. #endif /* HASH_SIZE 192 */
  9740. }
  9741. #endif
  9742. return;
  9743. }
  9744. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9745. #ifdef HAVE_ECC
  9746. /* Maximum ECC name plus null terminator:
  9747. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9748. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9749. /* run all benchmarks on a curve */
  9750. void bench_ecc_curve(int curveId)
  9751. {
  9752. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9753. #ifndef NO_SW_BENCH
  9754. bench_eccMakeKey(0, curveId);
  9755. #endif
  9756. #if defined(BENCH_DEVID)
  9757. bench_eccMakeKey(1, curveId);
  9758. #endif
  9759. }
  9760. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9761. #ifndef NO_SW_BENCH
  9762. bench_ecc(0, curveId);
  9763. #endif
  9764. #if defined(BENCH_DEVID)
  9765. bench_ecc(1, curveId);
  9766. #endif
  9767. }
  9768. #ifdef HAVE_ECC_ENCRYPT
  9769. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9770. bench_eccEncrypt(curveId);
  9771. #endif
  9772. }
  9773. void bench_eccMakeKey(int useDeviceID, int curveId)
  9774. {
  9775. int ret = 0, i, times, count = 0, pending = 0;
  9776. int deviceID;
  9777. int keySize = 0;
  9778. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9779. sizeof(ecc_key), HEAP_HINT);
  9780. char name[BENCH_ECC_NAME_SZ];
  9781. double start = 0;
  9782. const char**desc = bench_desc_words[lng_index];
  9783. DECLARE_MULTI_VALUE_STATS_VARS()
  9784. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9785. sizeof(ecc_key), HEAP_HINT);
  9786. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9787. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9788. /* ECC Make Key */
  9789. bench_stats_start(&count, &start);
  9790. do {
  9791. /* while free pending slots in queue, submit ops */
  9792. for (times = 0; times < agreeTimes || pending > 0; ) {
  9793. bench_async_poll(&pending);
  9794. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9795. if (bench_async_check(&ret,
  9796. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9797. &times, agreeTimes, &pending)) {
  9798. wc_ecc_free(genKey[i]);
  9799. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9800. if (ret < 0) {
  9801. goto exit;
  9802. }
  9803. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9804. curveId);
  9805. if (!bench_async_handle(&ret,
  9806. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9807. &pending)) {
  9808. goto exit;
  9809. }
  9810. }
  9811. } /* for i */
  9812. RECORD_MULTI_VALUE_STATS();
  9813. } /* for times */
  9814. count += times;
  9815. } while (bench_stats_check(start)
  9816. #ifdef MULTI_VALUE_STATISTICS
  9817. || runs < minimum_runs
  9818. #endif
  9819. );
  9820. exit:
  9821. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9822. wc_ecc_get_name(curveId));
  9823. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9824. useDeviceID, count, start, ret);
  9825. #ifdef MULTI_VALUE_STATISTICS
  9826. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9827. #endif
  9828. /* cleanup */
  9829. if (WC_ARRAY_OK(genKey)) {
  9830. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9831. wc_ecc_free(genKey[i]);
  9832. }
  9833. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9834. }
  9835. }
  9836. void bench_ecc(int useDeviceID, int curveId)
  9837. {
  9838. int ret = 0, i, times, count, pending = 0;
  9839. int deviceID;
  9840. int keySize;
  9841. char name[BENCH_ECC_NAME_SZ];
  9842. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9843. sizeof(ecc_key), HEAP_HINT);
  9844. #ifdef HAVE_ECC_DHE
  9845. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9846. sizeof(ecc_key), HEAP_HINT);
  9847. #endif
  9848. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9849. #ifdef HAVE_ECC_VERIFY
  9850. int verify[BENCH_MAX_PENDING];
  9851. #endif
  9852. #endif
  9853. word32 x[BENCH_MAX_PENDING];
  9854. double start = 0;
  9855. const char**desc = bench_desc_words[lng_index];
  9856. DECLARE_MULTI_VALUE_STATS_VARS()
  9857. #ifdef HAVE_ECC_DHE
  9858. WC_DECLARE_ARRAY(shared, byte,
  9859. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9860. #endif
  9861. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9862. WC_DECLARE_ARRAY(sig, byte,
  9863. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9864. WC_DECLARE_ARRAY(digest, byte,
  9865. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9866. #endif
  9867. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9868. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9869. XMEMSET(sig, 0, sizeof(sig));
  9870. XMEMSET(digest, 0, sizeof(digest));
  9871. #endif
  9872. #ifdef HAVE_ECC_DHE
  9873. XMEMSET(shared, 0, sizeof(shared));
  9874. #endif
  9875. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9876. sizeof(ecc_key), HEAP_HINT);
  9877. #ifdef HAVE_ECC_DHE
  9878. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9879. sizeof(ecc_key), HEAP_HINT);
  9880. WC_ALLOC_ARRAY(shared, byte,
  9881. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9882. #endif
  9883. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9884. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9885. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9886. #endif
  9887. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9888. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9889. /* init keys */
  9890. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9891. /* setup an context for each key */
  9892. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9893. goto exit;
  9894. }
  9895. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9896. #ifdef WOLFSSL_ASYNC_CRYPT
  9897. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9898. #endif
  9899. if (ret < 0) {
  9900. goto exit;
  9901. }
  9902. #ifdef HAVE_ECC_DHE
  9903. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9904. goto exit;
  9905. }
  9906. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9907. curveId)) > 0) {
  9908. goto exit;
  9909. }
  9910. #endif
  9911. }
  9912. #ifdef HAVE_ECC_DHE
  9913. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9914. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9915. !defined(HAVE_SELFTEST)
  9916. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9917. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9918. }
  9919. #endif
  9920. /* ECC Shared Secret */
  9921. bench_stats_start(&count, &start);
  9922. PRIVATE_KEY_UNLOCK();
  9923. do {
  9924. for (times = 0; times < agreeTimes || pending > 0; ) {
  9925. bench_async_poll(&pending);
  9926. /* while free pending slots in queue, submit ops */
  9927. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9928. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9929. &times, agreeTimes, &pending)) {
  9930. x[i] = (word32)keySize;
  9931. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9932. shared[i], &x[i]);
  9933. if (!bench_async_handle(&ret,
  9934. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9935. &pending)) {
  9936. goto exit_ecdhe;
  9937. }
  9938. }
  9939. } /* for i */
  9940. RECORD_MULTI_VALUE_STATS();
  9941. } /* for times */
  9942. count += times;
  9943. } while (bench_stats_check(start)
  9944. #ifdef MULTI_VALUE_STATISTICS
  9945. || runs < minimum_runs
  9946. #endif
  9947. );
  9948. PRIVATE_KEY_UNLOCK();
  9949. exit_ecdhe:
  9950. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9951. wc_ecc_get_name(curveId));
  9952. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9953. useDeviceID, 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. }
  9961. #endif /* HAVE_ECC_DHE */
  9962. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9963. /* Init digest to sign */
  9964. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9965. for (count = 0; count < keySize; count++) {
  9966. digest[i][count] = (byte)count;
  9967. }
  9968. }
  9969. /* ECC Sign */
  9970. bench_stats_start(&count, &start);
  9971. do {
  9972. for (times = 0; times < agreeTimes || pending > 0; ) {
  9973. bench_async_poll(&pending);
  9974. /* while free pending slots in queue, submit ops */
  9975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9976. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9977. &times, agreeTimes, &pending)) {
  9978. if (genKey[i]->state == 0) {
  9979. x[i] = ECC_MAX_SIG_SIZE;
  9980. }
  9981. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9982. &x[i], GLOBAL_RNG, genKey[i]);
  9983. if (!bench_async_handle(&ret,
  9984. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9985. &pending)) {
  9986. goto exit_ecdsa_sign;
  9987. }
  9988. } /* bench_async_check */
  9989. } /* for i */
  9990. RECORD_MULTI_VALUE_STATS();
  9991. } /* for times */
  9992. count += times;
  9993. } while (bench_stats_check(start)
  9994. #ifdef MULTI_VALUE_STATISTICS
  9995. || runs < minimum_runs
  9996. #endif
  9997. );
  9998. exit_ecdsa_sign:
  9999. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10000. wc_ecc_get_name(curveId));
  10001. bench_stats_asym_finish(name, keySize * 8, desc[4],
  10002. useDeviceID, count, start, ret);
  10003. #ifdef MULTI_VALUE_STATISTICS
  10004. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10005. #endif
  10006. RESET_MULTI_VALUE_STATS_VARS();
  10007. if (ret < 0) {
  10008. goto exit;
  10009. }
  10010. #ifdef HAVE_ECC_VERIFY
  10011. /* ECC Verify */
  10012. bench_stats_start(&count, &start);
  10013. do {
  10014. for (times = 0; times < agreeTimes || pending > 0; ) {
  10015. bench_async_poll(&pending);
  10016. /* while free pending slots in queue, submit ops */
  10017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10018. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10019. &times, agreeTimes, &pending)) {
  10020. if (genKey[i]->state == 0) {
  10021. verify[i] = 0;
  10022. }
  10023. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  10024. (word32)keySize, &verify[i],
  10025. genKey[i]);
  10026. if (!bench_async_handle(&ret,
  10027. BENCH_ASYNC_GET_DEV(genKey[i]),
  10028. 1, &times,
  10029. &pending)) {
  10030. goto exit_ecdsa_verify;
  10031. }
  10032. } /* if bench_async_check */
  10033. } /* for i */
  10034. RECORD_MULTI_VALUE_STATS();
  10035. } /* for times */
  10036. count += times;
  10037. } while (bench_stats_check(start)
  10038. #ifdef MULTI_VALUE_STATISTICS
  10039. || runs < minimum_runs
  10040. #endif
  10041. );
  10042. exit_ecdsa_verify:
  10043. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10044. wc_ecc_get_name(curveId));
  10045. bench_stats_asym_finish(name, keySize * 8, desc[5],
  10046. useDeviceID, count, start, ret);
  10047. #ifdef MULTI_VALUE_STATISTICS
  10048. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10049. #endif
  10050. #endif /* HAVE_ECC_VERIFY */
  10051. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10052. exit:
  10053. /* cleanup */
  10054. if (WC_ARRAY_OK(genKey)) {
  10055. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10056. wc_ecc_free(genKey[i]);
  10057. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10058. }
  10059. #ifdef HAVE_ECC_DHE
  10060. if (WC_ARRAY_OK(genKey2)) {
  10061. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10062. wc_ecc_free(genKey2[i]);
  10063. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10064. }
  10065. #endif
  10066. #ifdef HAVE_ECC_DHE
  10067. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10068. #endif
  10069. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10070. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10071. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10072. #endif
  10073. (void)useDeviceID;
  10074. (void)pending;
  10075. (void)x;
  10076. (void)count;
  10077. (void)times;
  10078. (void)desc;
  10079. (void)start;
  10080. (void)name;
  10081. }
  10082. #ifdef HAVE_ECC_ENCRYPT
  10083. void bench_eccEncrypt(int curveId)
  10084. {
  10085. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  10086. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  10087. WC_SHA256_DIGEST_SIZE + \
  10088. (MAX_ECC_BITS+3)/4 + 2)
  10089. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  10090. #ifdef WOLFSSL_SMALL_STACK
  10091. ecc_key *userA = NULL, *userB = NULL;
  10092. byte *msg = NULL;
  10093. byte *out = NULL;
  10094. #else
  10095. ecc_key userA[1], userB[1];
  10096. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  10097. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  10098. #endif
  10099. char name[BENCH_ECC_NAME_SZ];
  10100. int keySize;
  10101. word32 bench_plainSz = bench_size;
  10102. int ret, i, count;
  10103. double start;
  10104. const char**desc = bench_desc_words[lng_index];
  10105. DECLARE_MULTI_VALUE_STATS_VARS()
  10106. #ifdef WOLFSSL_SMALL_STACK
  10107. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10108. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10109. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10110. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10111. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10112. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10113. out = (byte *)XMALLOC(outSz,
  10114. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10115. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10116. printf("bench_eccEncrypt malloc failed\n");
  10117. goto exit;
  10118. }
  10119. #endif
  10120. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10121. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10122. if (ret != 0) {
  10123. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10124. goto exit;
  10125. }
  10126. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10127. if (ret != 0) {
  10128. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10129. goto exit;
  10130. }
  10131. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10132. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10133. !defined(HAVE_SELFTEST)
  10134. ret = wc_ecc_set_rng(userA, &gRng);
  10135. if (ret != 0) {
  10136. goto exit;
  10137. }
  10138. ret = wc_ecc_set_rng(userB, &gRng);
  10139. if (ret != 0) {
  10140. goto exit;
  10141. }
  10142. #endif
  10143. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10144. #ifdef WOLFSSL_ASYNC_CRYPT
  10145. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10146. #endif
  10147. if (ret != 0)
  10148. goto exit;
  10149. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10150. #ifdef WOLFSSL_ASYNC_CRYPT
  10151. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10152. #endif
  10153. if (ret != 0)
  10154. goto exit;
  10155. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10156. msg[i] = (byte)i;
  10157. }
  10158. bench_stats_start(&count, &start);
  10159. do {
  10160. for (i = 0; i < ntimes; i++) {
  10161. /* encrypt msg to B */
  10162. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10163. out, &outSz, NULL);
  10164. if (ret != 0) {
  10165. printf("wc_ecc_encrypt failed! %d\n", ret);
  10166. goto exit_enc;
  10167. }
  10168. RECORD_MULTI_VALUE_STATS();
  10169. }
  10170. count += i;
  10171. } while (bench_stats_check(start)
  10172. #ifdef MULTI_VALUE_STATISTICS
  10173. || runs < minimum_runs
  10174. #endif
  10175. );
  10176. exit_enc:
  10177. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10178. wc_ecc_get_name(curveId));
  10179. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10180. #ifdef MULTI_VALUE_STATISTICS
  10181. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10182. #endif
  10183. RESET_MULTI_VALUE_STATS_VARS();
  10184. if (ret != 0)
  10185. goto exit;
  10186. bench_stats_start(&count, &start);
  10187. do {
  10188. for (i = 0; i < ntimes; i++) {
  10189. /* decrypt msg from A */
  10190. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10191. &bench_plainSz, NULL);
  10192. if (ret != 0) {
  10193. printf("wc_ecc_decrypt failed! %d\n", ret);
  10194. goto exit_dec;
  10195. }
  10196. RECORD_MULTI_VALUE_STATS();
  10197. }
  10198. count += i;
  10199. } while (bench_stats_check(start)
  10200. #ifdef MULTI_VALUE_STATISTICS
  10201. || runs < minimum_runs
  10202. #endif
  10203. );
  10204. exit_dec:
  10205. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10206. #ifdef MULTI_VALUE_STATISTICS
  10207. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10208. #endif
  10209. exit:
  10210. /* cleanup */
  10211. #ifdef WOLFSSL_SMALL_STACK
  10212. if (userA) {
  10213. wc_ecc_free(userA);
  10214. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10215. }
  10216. if (userB) {
  10217. wc_ecc_free(userB);
  10218. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10219. }
  10220. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10221. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10222. #else
  10223. wc_ecc_free(userB);
  10224. wc_ecc_free(userA);
  10225. #endif
  10226. }
  10227. #endif
  10228. #ifdef WOLFSSL_SM2
  10229. static void bench_sm2_MakeKey(int useDeviceID)
  10230. {
  10231. int ret = 0, i, times, count = 0, pending = 0;
  10232. int deviceID;
  10233. int keySize;
  10234. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10235. sizeof(ecc_key), HEAP_HINT);
  10236. char name[BENCH_ECC_NAME_SZ];
  10237. double start = 0;
  10238. const char**desc = bench_desc_words[lng_index];
  10239. DECLARE_MULTI_VALUE_STATS_VARS()
  10240. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10241. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10242. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10243. sizeof(ecc_key), HEAP_HINT);
  10244. /* ECC Make Key */
  10245. bench_stats_start(&count, &start);
  10246. do {
  10247. /* while free pending slots in queue, submit ops */
  10248. for (times = 0; times < agreeTimes || pending > 0; ) {
  10249. bench_async_poll(&pending);
  10250. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10251. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10252. &times, agreeTimes, &pending)) {
  10253. wc_ecc_free(genKey[i]);
  10254. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10255. if (ret < 0) {
  10256. goto exit;
  10257. }
  10258. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10259. WC_ECC_FLAG_NONE);
  10260. if (!bench_async_handle(&ret,
  10261. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10262. &pending)) {
  10263. goto exit;
  10264. }
  10265. }
  10266. } /* for i */
  10267. RECORD_MULTI_VALUE_STATS();
  10268. } /* for times */
  10269. count += times;
  10270. } while (bench_stats_check(start)
  10271. #ifdef MULTI_VALUE_STATISTICS
  10272. || runs < minimum_runs
  10273. #endif
  10274. );
  10275. exit:
  10276. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10277. wc_ecc_get_name(ECC_SM2P256V1));
  10278. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10279. start, ret);
  10280. #ifdef MULTI_VALUE_STATISTICS
  10281. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10282. #endif
  10283. /* cleanup */
  10284. if (WC_ARRAY_OK(genKey)) {
  10285. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10286. wc_ecc_free(genKey[i]);
  10287. }
  10288. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10289. }
  10290. }
  10291. void bench_sm2(int useDeviceID)
  10292. {
  10293. int ret = 0, i, times, count, pending = 0;
  10294. int deviceID;
  10295. int keySize;
  10296. char name[BENCH_ECC_NAME_SZ];
  10297. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10298. sizeof(ecc_key), HEAP_HINT);
  10299. #ifdef HAVE_ECC_DHE
  10300. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10301. sizeof(ecc_key), HEAP_HINT);
  10302. #endif
  10303. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10304. #ifdef HAVE_ECC_VERIFY
  10305. int verify[BENCH_MAX_PENDING];
  10306. #endif
  10307. #endif
  10308. word32 x[BENCH_MAX_PENDING];
  10309. double start = 0;
  10310. const char**desc = bench_desc_words[lng_index];
  10311. DECLARE_MULTI_VALUE_STATS_VARS()
  10312. #ifdef HAVE_ECC_DHE
  10313. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10314. #endif
  10315. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10316. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10317. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10318. #endif
  10319. #ifdef HAVE_ECC_DHE
  10320. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10321. #endif
  10322. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10323. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10324. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10325. #endif
  10326. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10327. bench_sm2_MakeKey(useDeviceID);
  10328. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10329. sizeof(ecc_key), HEAP_HINT);
  10330. #ifdef HAVE_ECC_DHE
  10331. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10332. sizeof(ecc_key), HEAP_HINT);
  10333. #endif
  10334. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10335. /* init keys */
  10336. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10337. /* setup an context for each key */
  10338. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10339. goto exit;
  10340. }
  10341. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10342. #ifdef WOLFSSL_ASYNC_CRYPT
  10343. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10344. #endif
  10345. if (ret < 0) {
  10346. goto exit;
  10347. }
  10348. #ifdef HAVE_ECC_DHE
  10349. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10350. goto exit;
  10351. }
  10352. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10353. WC_ECC_FLAG_NONE)) > 0) {
  10354. goto exit;
  10355. }
  10356. #endif
  10357. }
  10358. #ifdef HAVE_ECC_DHE
  10359. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10360. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10361. !defined(HAVE_SELFTEST)
  10362. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10363. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10364. }
  10365. #endif
  10366. /* ECC Shared Secret */
  10367. bench_stats_start(&count, &start);
  10368. PRIVATE_KEY_UNLOCK();
  10369. do {
  10370. for (times = 0; times < agreeTimes || pending > 0; ) {
  10371. bench_async_poll(&pending);
  10372. /* while free pending slots in queue, submit ops */
  10373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10374. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10375. &times, agreeTimes, &pending)) {
  10376. x[i] = (word32)keySize;
  10377. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10378. shared[i], &x[i]);
  10379. if (!bench_async_handle(&ret,
  10380. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10381. &pending)) {
  10382. goto exit_ecdhe;
  10383. }
  10384. }
  10385. } /* for i */
  10386. RECORD_MULTI_VALUE_STATS();
  10387. } /* for times */
  10388. count += times;
  10389. } while (bench_stats_check(start)
  10390. #ifdef MULTI_VALUE_STATISTICS
  10391. || runs < minimum_runs
  10392. #endif
  10393. );
  10394. PRIVATE_KEY_UNLOCK();
  10395. exit_ecdhe:
  10396. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10397. wc_ecc_get_name(ECC_SM2P256V1));
  10398. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10399. start, ret);
  10400. #ifdef MULTI_VALUE_STATISTICS
  10401. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10402. #endif
  10403. if (ret < 0) {
  10404. goto exit;
  10405. }
  10406. #endif /* HAVE_ECC_DHE */
  10407. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10408. /* Init digest to sign */
  10409. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10410. for (count = 0; count < keySize; count++) {
  10411. digest[i][count] = (byte)count;
  10412. }
  10413. }
  10414. RESET_MULTI_VALUE_STATS_VARS();
  10415. /* ECC Sign */
  10416. bench_stats_start(&count, &start);
  10417. do {
  10418. for (times = 0; times < agreeTimes || pending > 0; ) {
  10419. bench_async_poll(&pending);
  10420. /* while free pending slots in queue, submit ops */
  10421. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10422. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10423. &times, agreeTimes, &pending)) {
  10424. if (genKey[i]->state == 0)
  10425. x[i] = ECC_MAX_SIG_SIZE;
  10426. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10427. sig[i], &x[i], &gRng, genKey[i]);
  10428. if (!bench_async_handle(&ret,
  10429. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10430. &pending)) {
  10431. goto exit_ecdsa_sign;
  10432. }
  10433. }
  10434. } /* for i */
  10435. RECORD_MULTI_VALUE_STATS();
  10436. } /* for times */
  10437. count += times;
  10438. } while (bench_stats_check(start)
  10439. #ifdef MULTI_VALUE_STATISTICS
  10440. || runs < minimum_runs
  10441. #endif
  10442. );
  10443. exit_ecdsa_sign:
  10444. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10445. wc_ecc_get_name(ECC_SM2P256V1));
  10446. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10447. start, ret);
  10448. #ifdef MULTI_VALUE_STATISTICS
  10449. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10450. #endif
  10451. if (ret < 0) {
  10452. goto exit;
  10453. }
  10454. #ifdef HAVE_ECC_VERIFY
  10455. /* ECC Verify */
  10456. bench_stats_start(&count, &start);
  10457. do {
  10458. for (times = 0; times < agreeTimes || pending > 0; ) {
  10459. bench_async_poll(&pending);
  10460. /* while free pending slots in queue, submit ops */
  10461. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10462. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10463. &times, agreeTimes, &pending)) {
  10464. if (genKey[i]->state == 0)
  10465. verify[i] = 0;
  10466. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10467. (word32)keySize, &verify[i], genKey[i]);
  10468. if (!bench_async_handle(&ret,
  10469. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10470. &pending)) {
  10471. goto exit_ecdsa_verify;
  10472. }
  10473. }
  10474. } /* for i */
  10475. RECORD_MULTI_VALUE_STATS();
  10476. } /* for times */
  10477. count += times;
  10478. } while (bench_stats_check(start)
  10479. #ifdef MULTI_VALUE_STATISTICS
  10480. || runs < minimum_runs
  10481. #endif
  10482. );
  10483. exit_ecdsa_verify:
  10484. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10485. wc_ecc_get_name(ECC_SM2P256V1));
  10486. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10487. start, ret);
  10488. #ifdef MULTI_VALUE_STATISTICS
  10489. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10490. #endif
  10491. #endif /* HAVE_ECC_VERIFY */
  10492. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10493. exit:
  10494. /* cleanup */
  10495. if (WC_ARRAY_OK(genKey)) {
  10496. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10497. wc_ecc_free(genKey[i]);
  10498. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10499. }
  10500. #ifdef HAVE_ECC_DHE
  10501. if (WC_ARRAY_OK(genKey2)) {
  10502. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10503. wc_ecc_free(genKey2[i]);
  10504. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10505. }
  10506. #endif
  10507. #ifdef HAVE_ECC_DHE
  10508. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10509. #endif
  10510. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10511. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10512. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10513. #endif
  10514. (void)useDeviceID;
  10515. (void)pending;
  10516. (void)x;
  10517. (void)count;
  10518. (void)times;
  10519. (void)desc;
  10520. (void)start;
  10521. (void)name;
  10522. }
  10523. #endif /* WOLFSSL_SM2 */
  10524. #endif /* HAVE_ECC */
  10525. #ifdef HAVE_CURVE25519
  10526. void bench_curve25519KeyGen(int useDeviceID)
  10527. {
  10528. curve25519_key genKey;
  10529. double start;
  10530. int ret = 0, i, count;
  10531. const char**desc = bench_desc_words[lng_index];
  10532. DECLARE_MULTI_VALUE_STATS_VARS()
  10533. /* Key Gen */
  10534. bench_stats_start(&count, &start);
  10535. do {
  10536. for (i = 0; i < genTimes; i++) {
  10537. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10538. useDeviceID ? devId : INVALID_DEVID);
  10539. if (ret != 0) {
  10540. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10541. break;
  10542. }
  10543. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10544. wc_curve25519_free(&genKey);
  10545. if (ret != 0) {
  10546. printf("wc_curve25519_make_key failed: %d\n", ret);
  10547. break;
  10548. }
  10549. RECORD_MULTI_VALUE_STATS();
  10550. }
  10551. count += i;
  10552. } while (bench_stats_check(start)
  10553. #ifdef MULTI_VALUE_STATISTICS
  10554. || runs < minimum_runs
  10555. #endif
  10556. );
  10557. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10558. ret);
  10559. #ifdef MULTI_VALUE_STATISTICS
  10560. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10561. #endif
  10562. }
  10563. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10564. void bench_curve25519KeyAgree(int useDeviceID)
  10565. {
  10566. curve25519_key genKey, genKey2;
  10567. double start;
  10568. int ret, i, count;
  10569. byte shared[32];
  10570. const char**desc = bench_desc_words[lng_index];
  10571. word32 x = 0;
  10572. DECLARE_MULTI_VALUE_STATS_VARS()
  10573. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10574. useDeviceID ? devId : INVALID_DEVID);
  10575. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10576. useDeviceID ? devId : INVALID_DEVID);
  10577. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10578. if (ret != 0) {
  10579. printf("curve25519_make_key failed\n");
  10580. return;
  10581. }
  10582. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10583. if (ret != 0) {
  10584. printf("curve25519_make_key failed: %d\n", ret);
  10585. wc_curve25519_free(&genKey);
  10586. return;
  10587. }
  10588. /* Shared secret */
  10589. bench_stats_start(&count, &start);
  10590. do {
  10591. for (i = 0; i < agreeTimes; i++) {
  10592. x = sizeof(shared);
  10593. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10594. if (ret != 0) {
  10595. printf("curve25519_shared_secret failed: %d\n", ret);
  10596. goto exit;
  10597. }
  10598. RECORD_MULTI_VALUE_STATS();
  10599. }
  10600. count += i;
  10601. } while (bench_stats_check(start)
  10602. #ifdef MULTI_VALUE_STATISTICS
  10603. || runs < minimum_runs
  10604. #endif
  10605. );
  10606. exit:
  10607. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10608. ret);
  10609. #ifdef MULTI_VALUE_STATISTICS
  10610. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10611. #endif
  10612. wc_curve25519_free(&genKey2);
  10613. wc_curve25519_free(&genKey);
  10614. }
  10615. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10616. #endif /* HAVE_CURVE25519 */
  10617. #ifdef HAVE_ED25519
  10618. void bench_ed25519KeyGen(void)
  10619. {
  10620. #ifdef HAVE_ED25519_MAKE_KEY
  10621. ed25519_key genKey;
  10622. double start;
  10623. int i, count;
  10624. const char**desc = bench_desc_words[lng_index];
  10625. DECLARE_MULTI_VALUE_STATS_VARS()
  10626. /* Key Gen */
  10627. bench_stats_start(&count, &start);
  10628. do {
  10629. for (i = 0; i < genTimes; i++) {
  10630. wc_ed25519_init(&genKey);
  10631. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10632. wc_ed25519_free(&genKey);
  10633. RECORD_MULTI_VALUE_STATS();
  10634. }
  10635. count += i;
  10636. } while (bench_stats_check(start)
  10637. #ifdef MULTI_VALUE_STATISTICS
  10638. || runs < minimum_runs
  10639. #endif
  10640. );
  10641. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10642. #ifdef MULTI_VALUE_STATISTICS
  10643. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10644. #endif
  10645. #endif /* HAVE_ED25519_MAKE_KEY */
  10646. }
  10647. void bench_ed25519KeySign(void)
  10648. {
  10649. #ifdef HAVE_ED25519_MAKE_KEY
  10650. int ret;
  10651. #endif
  10652. ed25519_key genKey;
  10653. #ifdef HAVE_ED25519_SIGN
  10654. double start;
  10655. int i, count;
  10656. byte sig[ED25519_SIG_SIZE];
  10657. byte msg[512];
  10658. word32 x = 0;
  10659. const char**desc = bench_desc_words[lng_index];
  10660. DECLARE_MULTI_VALUE_STATS_VARS()
  10661. #endif
  10662. wc_ed25519_init(&genKey);
  10663. #ifdef HAVE_ED25519_MAKE_KEY
  10664. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10665. if (ret != 0) {
  10666. printf("ed25519_make_key failed\n");
  10667. return;
  10668. }
  10669. #endif
  10670. #ifdef HAVE_ED25519_SIGN
  10671. /* make dummy msg */
  10672. for (i = 0; i < (int)sizeof(msg); i++)
  10673. msg[i] = (byte)i;
  10674. bench_stats_start(&count, &start);
  10675. do {
  10676. for (i = 0; i < agreeTimes; i++) {
  10677. x = sizeof(sig);
  10678. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10679. if (ret != 0) {
  10680. printf("ed25519_sign_msg failed\n");
  10681. goto exit_ed_sign;
  10682. }
  10683. RECORD_MULTI_VALUE_STATS();
  10684. }
  10685. count += i;
  10686. } while (bench_stats_check(start)
  10687. #ifdef MULTI_VALUE_STATISTICS
  10688. || runs < minimum_runs
  10689. #endif
  10690. );
  10691. exit_ed_sign:
  10692. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10693. #ifdef MULTI_VALUE_STATISTICS
  10694. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10695. #endif
  10696. RESET_MULTI_VALUE_STATS_VARS();
  10697. #ifdef HAVE_ED25519_VERIFY
  10698. bench_stats_start(&count, &start);
  10699. do {
  10700. for (i = 0; i < agreeTimes; i++) {
  10701. int verify = 0;
  10702. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10703. &genKey);
  10704. if (ret != 0 || verify != 1) {
  10705. printf("ed25519_verify_msg failed\n");
  10706. goto exit_ed_verify;
  10707. }
  10708. RECORD_MULTI_VALUE_STATS();
  10709. }
  10710. count += i;
  10711. } while (bench_stats_check(start)
  10712. #ifdef MULTI_VALUE_STATISTICS
  10713. || runs < minimum_runs
  10714. #endif
  10715. );
  10716. exit_ed_verify:
  10717. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10718. #ifdef MULTI_VALUE_STATISTICS
  10719. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10720. #endif
  10721. #endif /* HAVE_ED25519_VERIFY */
  10722. #endif /* HAVE_ED25519_SIGN */
  10723. wc_ed25519_free(&genKey);
  10724. }
  10725. #endif /* HAVE_ED25519 */
  10726. #ifdef HAVE_CURVE448
  10727. void bench_curve448KeyGen(void)
  10728. {
  10729. curve448_key genKey;
  10730. double start;
  10731. int ret = 0, i, count;
  10732. const char**desc = bench_desc_words[lng_index];
  10733. DECLARE_MULTI_VALUE_STATS_VARS()
  10734. /* Key Gen */
  10735. bench_stats_start(&count, &start);
  10736. do {
  10737. for (i = 0; i < genTimes; i++) {
  10738. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10739. wc_curve448_free(&genKey);
  10740. if (ret != 0) {
  10741. printf("wc_curve448_make_key failed: %d\n", ret);
  10742. break;
  10743. }
  10744. RECORD_MULTI_VALUE_STATS();
  10745. }
  10746. count += i;
  10747. } while (bench_stats_check(start)
  10748. #ifdef MULTI_VALUE_STATISTICS
  10749. || runs < minimum_runs
  10750. #endif
  10751. );
  10752. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10753. #ifdef MULTI_VALUE_STATISTICS
  10754. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10755. #endif
  10756. }
  10757. #ifdef HAVE_CURVE448_SHARED_SECRET
  10758. void bench_curve448KeyAgree(void)
  10759. {
  10760. curve448_key genKey, genKey2;
  10761. double start;
  10762. int ret, i, count;
  10763. byte shared[56];
  10764. const char**desc = bench_desc_words[lng_index];
  10765. word32 x = 0;
  10766. DECLARE_MULTI_VALUE_STATS_VARS()
  10767. wc_curve448_init(&genKey);
  10768. wc_curve448_init(&genKey2);
  10769. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10770. if (ret != 0) {
  10771. printf("curve448_make_key failed\n");
  10772. return;
  10773. }
  10774. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10775. if (ret != 0) {
  10776. printf("curve448_make_key failed: %d\n", ret);
  10777. wc_curve448_free(&genKey);
  10778. return;
  10779. }
  10780. /* Shared secret */
  10781. bench_stats_start(&count, &start);
  10782. do {
  10783. for (i = 0; i < agreeTimes; i++) {
  10784. x = sizeof(shared);
  10785. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10786. if (ret != 0) {
  10787. printf("curve448_shared_secret failed: %d\n", ret);
  10788. goto exit;
  10789. }
  10790. RECORD_MULTI_VALUE_STATS();
  10791. }
  10792. count += i;
  10793. } while (bench_stats_check(start)
  10794. #ifdef MULTI_VALUE_STATISTICS
  10795. || runs < minimum_runs
  10796. #endif
  10797. );
  10798. exit:
  10799. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10800. #ifdef MULTI_VALUE_STATISTICS
  10801. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10802. #endif
  10803. wc_curve448_free(&genKey2);
  10804. wc_curve448_free(&genKey);
  10805. }
  10806. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10807. #endif /* HAVE_CURVE448 */
  10808. #ifdef HAVE_ED448
  10809. void bench_ed448KeyGen(void)
  10810. {
  10811. ed448_key genKey;
  10812. double start;
  10813. int i, count;
  10814. const char**desc = bench_desc_words[lng_index];
  10815. DECLARE_MULTI_VALUE_STATS_VARS()
  10816. /* Key Gen */
  10817. bench_stats_start(&count, &start);
  10818. do {
  10819. for (i = 0; i < genTimes; i++) {
  10820. wc_ed448_init(&genKey);
  10821. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10822. wc_ed448_free(&genKey);
  10823. RECORD_MULTI_VALUE_STATS();
  10824. }
  10825. count += i;
  10826. } while (bench_stats_check(start)
  10827. #ifdef MULTI_VALUE_STATISTICS
  10828. || runs < minimum_runs
  10829. #endif
  10830. );
  10831. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10832. #ifdef MULTI_VALUE_STATISTICS
  10833. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10834. #endif
  10835. }
  10836. void bench_ed448KeySign(void)
  10837. {
  10838. int ret;
  10839. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10840. #ifdef HAVE_ED448_SIGN
  10841. double start;
  10842. int i, count;
  10843. byte sig[ED448_SIG_SIZE];
  10844. byte msg[512];
  10845. word32 x = 0;
  10846. const char**desc = bench_desc_words[lng_index];
  10847. DECLARE_MULTI_VALUE_STATS_VARS()
  10848. #endif
  10849. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10850. wc_ed448_init(genKey);
  10851. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10852. if (ret != 0) {
  10853. printf("ed448_make_key failed\n");
  10854. goto exit;
  10855. }
  10856. #ifdef HAVE_ED448_SIGN
  10857. /* make dummy msg */
  10858. for (i = 0; i < (int)sizeof(msg); i++)
  10859. msg[i] = (byte)i;
  10860. bench_stats_start(&count, &start);
  10861. do {
  10862. for (i = 0; i < agreeTimes; i++) {
  10863. x = sizeof(sig);
  10864. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10865. NULL, 0);
  10866. if (ret != 0) {
  10867. printf("ed448_sign_msg failed\n");
  10868. goto exit;
  10869. }
  10870. RECORD_MULTI_VALUE_STATS();
  10871. }
  10872. count += i;
  10873. } while (bench_stats_check(start)
  10874. #ifdef MULTI_VALUE_STATISTICS
  10875. || runs < minimum_runs
  10876. #endif
  10877. );
  10878. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10879. #ifdef MULTI_VALUE_STATISTICS
  10880. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10881. #endif
  10882. RESET_MULTI_VALUE_STATS_VARS();
  10883. #ifdef HAVE_ED448_VERIFY
  10884. bench_stats_start(&count, &start);
  10885. do {
  10886. for (i = 0; i < agreeTimes; i++) {
  10887. int verify = 0;
  10888. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10889. genKey, NULL, 0);
  10890. if (ret != 0 || verify != 1) {
  10891. printf("ed448_verify_msg failed\n");
  10892. goto exit;
  10893. }
  10894. RECORD_MULTI_VALUE_STATS();
  10895. }
  10896. count += i;
  10897. } while (bench_stats_check(start)
  10898. #ifdef MULTI_VALUE_STATISTICS
  10899. || runs < minimum_runs
  10900. #endif
  10901. );
  10902. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10903. #ifdef MULTI_VALUE_STATISTICS
  10904. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10905. #endif
  10906. #endif /* HAVE_ED448_VERIFY */
  10907. #endif /* HAVE_ED448_SIGN */
  10908. exit:
  10909. wc_ed448_free(genKey);
  10910. WC_FREE_VAR(genKey, HEAP_HINT);
  10911. }
  10912. #endif /* HAVE_ED448 */
  10913. #ifdef WOLFCRYPT_HAVE_ECCSI
  10914. #ifdef WOLFCRYPT_ECCSI_KMS
  10915. void bench_eccsiKeyGen(void)
  10916. {
  10917. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10918. double start;
  10919. int i, count;
  10920. const char**desc = bench_desc_words[lng_index];
  10921. int ret;
  10922. DECLARE_MULTI_VALUE_STATS_VARS()
  10923. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10924. /* Key Gen */
  10925. bench_stats_start(&count, &start);
  10926. do {
  10927. for (i = 0; i < genTimes; i++) {
  10928. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10929. ret = wc_MakeEccsiKey(genKey, &gRng);
  10930. wc_FreeEccsiKey(genKey);
  10931. if (ret != 0) {
  10932. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10933. goto exit;
  10934. }
  10935. RECORD_MULTI_VALUE_STATS();
  10936. }
  10937. count += i;
  10938. } while (bench_stats_check(start)
  10939. #ifdef MULTI_VALUE_STATISTICS
  10940. || runs < minimum_runs
  10941. #endif
  10942. );
  10943. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10944. #ifdef MULTI_VALUE_STATISTICS
  10945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10946. #endif
  10947. exit:
  10948. WC_FREE_VAR(genKey, HEAP_HINT);
  10949. }
  10950. void bench_eccsiPairGen(void)
  10951. {
  10952. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10953. double start;
  10954. int i, count;
  10955. const char**desc = bench_desc_words[lng_index];
  10956. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10957. ecc_point* pvt;
  10958. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10959. int ret;
  10960. DECLARE_MULTI_VALUE_STATS_VARS()
  10961. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10962. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10963. (void)mp_init(ssk);
  10964. pvt = wc_ecc_new_point();
  10965. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10966. (void)wc_MakeEccsiKey(genKey, &gRng);
  10967. /* RSK Gen */
  10968. bench_stats_start(&count, &start);
  10969. do {
  10970. for (i = 0; i < genTimes; i++) {
  10971. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10972. sizeof(id), ssk, pvt);
  10973. if (ret != 0) {
  10974. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10975. goto exit;
  10976. }
  10977. RECORD_MULTI_VALUE_STATS();
  10978. }
  10979. count += i;
  10980. } while (bench_stats_check(start)
  10981. #ifdef MULTI_VALUE_STATISTICS
  10982. || runs < minimum_runs
  10983. #endif
  10984. );
  10985. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10986. #ifdef MULTI_VALUE_STATISTICS
  10987. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10988. #endif
  10989. wc_FreeEccsiKey(genKey);
  10990. wc_ecc_del_point(pvt);
  10991. mp_free(ssk);
  10992. exit:
  10993. WC_FREE_VAR(genKey, HEAP_HINT);
  10994. WC_FREE_VAR(ssk, HEAP_HINT);
  10995. }
  10996. #endif
  10997. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10998. void bench_eccsiValidate(void)
  10999. {
  11000. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11001. double start;
  11002. int i, count;
  11003. const char**desc = bench_desc_words[lng_index];
  11004. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  11005. ecc_point* pvt;
  11006. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11007. int valid;
  11008. int ret;
  11009. DECLARE_MULTI_VALUE_STATS_VARS()
  11010. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11011. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11012. (void)mp_init(ssk);
  11013. pvt = wc_ecc_new_point();
  11014. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11015. (void)wc_MakeEccsiKey(genKey, &gRng);
  11016. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11017. ssk, pvt);
  11018. /* Validation of RSK */
  11019. bench_stats_start(&count, &start);
  11020. do {
  11021. for (i = 0; i < genTimes; i++) {
  11022. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  11023. sizeof(id), ssk, pvt, &valid);
  11024. if (ret != 0 || !valid) {
  11025. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  11026. valid);
  11027. goto exit;
  11028. }
  11029. RECORD_MULTI_VALUE_STATS();
  11030. }
  11031. count += i;
  11032. } while (bench_stats_check(start)
  11033. #ifdef MULTI_VALUE_STATISTICS
  11034. || runs < minimum_runs
  11035. #endif
  11036. );
  11037. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  11038. #ifdef MULTI_VALUE_STATISTICS
  11039. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11040. #endif
  11041. wc_FreeEccsiKey(genKey);
  11042. wc_ecc_del_point(pvt);
  11043. mp_free(ssk);
  11044. exit:
  11045. WC_FREE_VAR(genKey, HEAP_HINT);
  11046. WC_FREE_VAR(ssk, HEAP_HINT);
  11047. }
  11048. void bench_eccsi(void)
  11049. {
  11050. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11051. double start;
  11052. int i, count;
  11053. const char**desc = bench_desc_words[lng_index];
  11054. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  11055. ecc_point* pvt;
  11056. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11057. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  11058. byte hash[WC_SHA256_DIGEST_SIZE];
  11059. byte hashSz = (byte)sizeof(hash);
  11060. byte sig[257];
  11061. word32 sigSz = sizeof(sig);
  11062. int ret;
  11063. int verified;
  11064. DECLARE_MULTI_VALUE_STATS_VARS()
  11065. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11066. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11067. (void)mp_init(ssk);
  11068. pvt = wc_ecc_new_point();
  11069. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11070. (void)wc_MakeEccsiKey(genKey, &gRng);
  11071. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11072. ssk, pvt);
  11073. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  11074. hash, &hashSz);
  11075. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  11076. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  11077. /* Encapsulate */
  11078. bench_stats_start(&count, &start);
  11079. do {
  11080. for (i = 0; i < genTimes; i++) {
  11081. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  11082. sizeof(msg), sig, &sigSz);
  11083. if (ret != 0) {
  11084. printf("wc_SignEccsiHash failed: %d\n", ret);
  11085. break;
  11086. }
  11087. RECORD_MULTI_VALUE_STATS();
  11088. }
  11089. count += i;
  11090. } while (bench_stats_check(start)
  11091. #ifdef MULTI_VALUE_STATISTICS
  11092. || runs < minimum_runs
  11093. #endif
  11094. );
  11095. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  11096. #ifdef MULTI_VALUE_STATISTICS
  11097. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11098. #endif
  11099. RESET_MULTI_VALUE_STATS_VARS();
  11100. /* Derive */
  11101. bench_stats_start(&count, &start);
  11102. do {
  11103. for (i = 0; i < genTimes; i++) {
  11104. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11105. sizeof(msg), sig, sigSz, &verified);
  11106. if (ret != 0 || !verified) {
  11107. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11108. verified);
  11109. goto exit;
  11110. }
  11111. RECORD_MULTI_VALUE_STATS();
  11112. }
  11113. count += i;
  11114. } while (bench_stats_check(start)
  11115. #ifdef MULTI_VALUE_STATISTICS
  11116. || runs < minimum_runs
  11117. #endif
  11118. );
  11119. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11120. #ifdef MULTI_VALUE_STATISTICS
  11121. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11122. #endif
  11123. wc_FreeEccsiKey(genKey);
  11124. wc_ecc_del_point(pvt);
  11125. exit:
  11126. WC_FREE_VAR(genKey, HEAP_HINT);
  11127. WC_FREE_VAR(ssk, HEAP_HINT);
  11128. }
  11129. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11130. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11131. #ifdef WOLFCRYPT_HAVE_SAKKE
  11132. #ifdef WOLFCRYPT_SAKKE_KMS
  11133. void bench_sakkeKeyGen(void)
  11134. {
  11135. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11136. double start;
  11137. int i, count;
  11138. const char**desc = bench_desc_words[lng_index];
  11139. int ret;
  11140. DECLARE_MULTI_VALUE_STATS_VARS()
  11141. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11142. /* Key Gen */
  11143. bench_stats_start(&count, &start);
  11144. do {
  11145. for (i = 0; i < genTimes; i++) {
  11146. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11147. ret = wc_MakeSakkeKey(genKey, &gRng);
  11148. if (ret != 0) {
  11149. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11150. goto exit;
  11151. }
  11152. wc_FreeSakkeKey(genKey);
  11153. RECORD_MULTI_VALUE_STATS();
  11154. }
  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("SAKKE", 1024, desc[2], 0, count, start, 0);
  11162. #ifdef MULTI_VALUE_STATISTICS
  11163. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11164. #endif
  11165. exit:
  11166. WC_FREE_VAR(genKey, HEAP_HINT);
  11167. }
  11168. void bench_sakkeRskGen(void)
  11169. {
  11170. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11171. double start;
  11172. int i, count;
  11173. const char**desc = bench_desc_words[lng_index];
  11174. ecc_point* rsk;
  11175. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11176. int ret;
  11177. DECLARE_MULTI_VALUE_STATS_VARS()
  11178. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11179. rsk = wc_ecc_new_point();
  11180. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11181. (void)wc_MakeSakkeKey(genKey, &gRng);
  11182. /* RSK Gen */
  11183. bench_stats_start(&count, &start);
  11184. do {
  11185. for (i = 0; i < genTimes; i++) {
  11186. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11187. if (ret != 0) {
  11188. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11189. goto exit;
  11190. }
  11191. RECORD_MULTI_VALUE_STATS();
  11192. }
  11193. count += i;
  11194. } while (bench_stats_check(start)
  11195. #ifdef MULTI_VALUE_STATISTICS
  11196. || runs < minimum_runs
  11197. #endif
  11198. );
  11199. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11200. #ifdef MULTI_VALUE_STATISTICS
  11201. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11202. #endif
  11203. wc_FreeSakkeKey(genKey);
  11204. wc_ecc_del_point(rsk);
  11205. exit:
  11206. WC_FREE_VAR(genKey, HEAP_HINT);
  11207. }
  11208. #endif
  11209. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11210. void bench_sakkeValidate(void)
  11211. {
  11212. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11213. double start;
  11214. int i, count;
  11215. const char**desc = bench_desc_words[lng_index];
  11216. ecc_point* rsk;
  11217. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11218. int valid;
  11219. int ret;
  11220. DECLARE_MULTI_VALUE_STATS_VARS()
  11221. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11222. rsk = wc_ecc_new_point();
  11223. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11224. (void)wc_MakeSakkeKey(genKey, &gRng);
  11225. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11226. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11227. /* Validation of RSK */
  11228. bench_stats_start(&count, &start);
  11229. do {
  11230. for (i = 0; i < genTimes; i++) {
  11231. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11232. if (ret != 0 || !valid) {
  11233. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11234. valid);
  11235. goto exit;
  11236. }
  11237. RECORD_MULTI_VALUE_STATS();
  11238. }
  11239. count += i;
  11240. } while (bench_stats_check(start)
  11241. #ifdef MULTI_VALUE_STATISTICS
  11242. || runs < minimum_runs
  11243. #endif
  11244. );
  11245. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11246. #ifdef MULTI_VALUE_STATISTICS
  11247. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11248. #endif
  11249. wc_FreeSakkeKey(genKey);
  11250. wc_ecc_del_point(rsk);
  11251. exit:
  11252. WC_FREE_VAR(genKey, HEAP_HINT);
  11253. }
  11254. void bench_sakke(void)
  11255. {
  11256. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11257. double start;
  11258. int i, count;
  11259. const char**desc = bench_desc_words[lng_index];
  11260. ecc_point* rsk;
  11261. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11262. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11263. byte ssv[sizeof(ssv_init)];
  11264. byte derSSV[sizeof(ssv)];
  11265. byte auth[257];
  11266. word16 authSz = sizeof(auth);
  11267. int ret = 0;
  11268. byte* table = NULL;
  11269. word32 len = 0;
  11270. byte* iTable = NULL;
  11271. word32 iTableLen = 0;
  11272. DECLARE_MULTI_VALUE_STATS_VARS()
  11273. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11274. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11275. rsk = wc_ecc_new_point();
  11276. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11277. (void)wc_MakeSakkeKey(genKey, &gRng);
  11278. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11279. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11280. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11281. /* Encapsulate */
  11282. bench_stats_start(&count, &start);
  11283. do {
  11284. for (i = 0; i < genTimes; i++) {
  11285. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11286. WC_HASH_TYPE_SHA256,
  11287. ssv, sizeof(ssv), auth, &authSz);
  11288. if (ret != 0) {
  11289. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11290. break;
  11291. }
  11292. RECORD_MULTI_VALUE_STATS();
  11293. } /* for */
  11294. count += i;
  11295. } while (bench_stats_check(start)
  11296. #ifdef MULTI_VALUE_STATISTICS
  11297. || runs < minimum_runs
  11298. #endif
  11299. );
  11300. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11301. 0, count, start, 0);
  11302. #ifdef MULTI_VALUE_STATISTICS
  11303. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11304. #endif
  11305. RESET_MULTI_VALUE_STATS_VARS();
  11306. /* Derive */
  11307. bench_stats_start(&count, &start);
  11308. do {
  11309. for (i = 0; i < genTimes; i++) {
  11310. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11311. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11312. sizeof(derSSV), auth, authSz);
  11313. if (ret != 0) {
  11314. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11315. break;
  11316. }
  11317. RECORD_MULTI_VALUE_STATS();
  11318. }
  11319. if (ret != 0) break;
  11320. count += i;
  11321. } while (bench_stats_check(start)
  11322. #ifdef MULTI_VALUE_STATISTICS
  11323. || runs < minimum_runs
  11324. #endif
  11325. );
  11326. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11327. 0, count, start, 0);
  11328. #ifdef MULTI_VALUE_STATISTICS
  11329. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11330. #endif
  11331. /* Calculate Point I and generate table. */
  11332. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11333. iTableLen = 0;
  11334. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11335. if (iTableLen != 0) {
  11336. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11337. if (iTable == NULL)
  11338. WC_ALLOC_DO_ON_FAILURE();
  11339. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11340. }
  11341. /* Encapsulate with Point I table */
  11342. bench_stats_start(&count, &start);
  11343. do {
  11344. for (i = 0; i < genTimes; i++) {
  11345. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11346. WC_HASH_TYPE_SHA256, ssv,
  11347. sizeof(ssv), auth, &authSz);
  11348. if (ret != 0) {
  11349. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11350. break;
  11351. }
  11352. RECORD_MULTI_VALUE_STATS();
  11353. }
  11354. count += i;
  11355. } while (bench_stats_check(start)
  11356. #ifdef MULTI_VALUE_STATISTICS
  11357. || runs < minimum_runs
  11358. #endif
  11359. );
  11360. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11361. count, start, 0);
  11362. #ifdef MULTI_VALUE_STATISTICS
  11363. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11364. #endif
  11365. RESET_MULTI_VALUE_STATS_VARS();
  11366. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11367. /* Derive with Point I table */
  11368. bench_stats_start(&count, &start);
  11369. do {
  11370. for (i = 0; i < genTimes; i++) {
  11371. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11372. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11373. sizeof(derSSV), auth, authSz);
  11374. if (ret != 0) {
  11375. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11376. break;
  11377. }
  11378. RECORD_MULTI_VALUE_STATS();
  11379. }
  11380. if (ret != 0) break;
  11381. count += i;
  11382. } while (bench_stats_check(start)
  11383. #ifdef MULTI_VALUE_STATISTICS
  11384. || runs < minimum_runs
  11385. #endif
  11386. );
  11387. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11388. count, start, 0);
  11389. #ifdef MULTI_VALUE_STATISTICS
  11390. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11391. #endif
  11392. RESET_MULTI_VALUE_STATS_VARS();
  11393. len = 0;
  11394. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11395. if (len > 0) {
  11396. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11397. if (table == NULL)
  11398. WC_ALLOC_DO_ON_FAILURE();
  11399. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11400. }
  11401. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11402. /* Derive with Point I table and RSK table */
  11403. bench_stats_start(&count, &start);
  11404. do {
  11405. for (i = 0; i < genTimes; i++) {
  11406. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11407. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11408. sizeof(derSSV), auth, authSz);
  11409. if (ret != 0) {
  11410. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11411. break;
  11412. }
  11413. RECORD_MULTI_VALUE_STATS();
  11414. }
  11415. if (ret != 0) break;
  11416. count += i;
  11417. } while (bench_stats_check(start)
  11418. #ifdef MULTI_VALUE_STATISTICS
  11419. || runs < minimum_runs
  11420. #endif
  11421. );
  11422. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11423. 0, count, start, 0);
  11424. #ifdef MULTI_VALUE_STATISTICS
  11425. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11426. #endif
  11427. RESET_MULTI_VALUE_STATS_VARS();
  11428. wc_ClearSakkePointITable(genKey);
  11429. /* Derive with RSK table */
  11430. bench_stats_start(&count, &start);
  11431. do {
  11432. for (i = 0; i < genTimes; i++) {
  11433. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11434. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11435. sizeof(derSSV), auth, authSz);
  11436. if (ret != 0) {
  11437. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11438. break;
  11439. }
  11440. RECORD_MULTI_VALUE_STATS();
  11441. }
  11442. if (ret != 0) break;
  11443. count += i;
  11444. } while (bench_stats_check(start)
  11445. #ifdef MULTI_VALUE_STATISTICS
  11446. || runs < minimum_runs
  11447. #endif
  11448. );
  11449. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11450. count, start, 0);
  11451. #ifdef MULTI_VALUE_STATISTICS
  11452. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11453. #endif
  11454. wc_FreeSakkeKey(genKey);
  11455. wc_ecc_del_point(rsk);
  11456. exit:
  11457. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11458. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11459. WC_FREE_VAR(genKey, HEAP_HINT);
  11460. }
  11461. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11462. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11463. #ifdef HAVE_FALCON
  11464. void bench_falconKeySign(byte level)
  11465. {
  11466. int ret = 0;
  11467. falcon_key key;
  11468. double start;
  11469. int i, count;
  11470. byte sig[FALCON_MAX_SIG_SIZE];
  11471. byte msg[512];
  11472. word32 x = 0;
  11473. const char**desc = bench_desc_words[lng_index];
  11474. DECLARE_MULTI_VALUE_STATS_VARS()
  11475. ret = wc_falcon_init(&key);
  11476. if (ret != 0) {
  11477. printf("wc_falcon_init failed %d\n", ret);
  11478. return;
  11479. }
  11480. ret = wc_falcon_set_level(&key, level);
  11481. if (ret != 0) {
  11482. printf("wc_falcon_set_level failed %d\n", ret);
  11483. }
  11484. if (ret == 0) {
  11485. if (level == 1) {
  11486. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11487. sizeof_bench_falcon_level1_key,
  11488. NULL, 0, &key);
  11489. }
  11490. else {
  11491. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11492. sizeof_bench_falcon_level5_key,
  11493. NULL, 0, &key);
  11494. }
  11495. if (ret != 0) {
  11496. printf("wc_falcon_import_private_key failed %d\n", ret);
  11497. }
  11498. }
  11499. /* make dummy msg */
  11500. for (i = 0; i < (int)sizeof(msg); i++) {
  11501. msg[i] = (byte)i;
  11502. }
  11503. bench_stats_start(&count, &start);
  11504. do {
  11505. for (i = 0; i < agreeTimes; i++) {
  11506. if (ret == 0) {
  11507. if (level == 1) {
  11508. x = FALCON_LEVEL1_SIG_SIZE;
  11509. }
  11510. else {
  11511. x = FALCON_LEVEL5_SIG_SIZE;
  11512. }
  11513. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11514. if (ret != 0) {
  11515. printf("wc_falcon_sign_msg failed\n");
  11516. }
  11517. }
  11518. RECORD_MULTI_VALUE_STATS();
  11519. }
  11520. count += i;
  11521. } while (bench_stats_check(start)
  11522. #ifdef MULTI_VALUE_STATISTICS
  11523. || runs < minimum_runs
  11524. #endif
  11525. );
  11526. if (ret == 0) {
  11527. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11528. count, start, ret);
  11529. #ifdef MULTI_VALUE_STATISTICS
  11530. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11531. #endif
  11532. }
  11533. RESET_MULTI_VALUE_STATS_VARS();
  11534. bench_stats_start(&count, &start);
  11535. do {
  11536. for (i = 0; i < agreeTimes; i++) {
  11537. if (ret == 0) {
  11538. int verify = 0;
  11539. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11540. &key);
  11541. if (ret != 0 || verify != 1) {
  11542. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11543. ret, verify);
  11544. ret = -1;
  11545. }
  11546. }
  11547. RECORD_MULTI_VALUE_STATS();
  11548. }
  11549. count += i;
  11550. } while (bench_stats_check(start)
  11551. #ifdef MULTI_VALUE_STATISTICS
  11552. || runs < minimum_runs
  11553. #endif
  11554. );
  11555. if (ret == 0) {
  11556. bench_stats_asym_finish("FALCON", level, desc[5],
  11557. 0, count, start, ret);
  11558. #ifdef MULTI_VALUE_STATISTICS
  11559. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11560. #endif
  11561. }
  11562. wc_falcon_free(&key);
  11563. }
  11564. #endif /* HAVE_FALCON */
  11565. #ifdef HAVE_DILITHIUM
  11566. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11567. #ifndef WOLFSSL_NO_ML_DSA_44
  11568. static const unsigned char bench_dilithium_level2_sig[] = {
  11569. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11570. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11571. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11572. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11573. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11574. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11575. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11576. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11577. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11578. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11579. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11580. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11581. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11582. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11583. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11584. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11585. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11586. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11587. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11588. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11589. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11590. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11591. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11592. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11593. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11594. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11595. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11596. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11597. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11598. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11599. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11600. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11601. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11602. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11603. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11604. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11605. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11606. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11607. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11608. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11609. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11610. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11611. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11612. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11613. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11614. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11615. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11616. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11617. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11618. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11619. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11620. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11621. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11622. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11623. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11624. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11625. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11626. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11627. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11628. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11629. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11630. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11631. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11632. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11633. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11634. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11635. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11636. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11637. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11638. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11639. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11640. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11641. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11642. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11643. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11644. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11645. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11646. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11647. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11648. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11649. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11650. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11651. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11652. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11653. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11654. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11655. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11656. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11657. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11658. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11659. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11660. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11661. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11662. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11663. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11664. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11665. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11666. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11667. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11668. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11669. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11670. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11671. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11672. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11673. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11674. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11675. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11676. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11677. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11678. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11679. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11680. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11681. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11682. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11683. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11684. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11685. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11686. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11687. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11688. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11689. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11690. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11691. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11692. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11693. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11694. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11695. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11696. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11697. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11698. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11699. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11700. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11701. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11702. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11703. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11704. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11705. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11706. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11707. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11708. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11709. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11710. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11711. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11712. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11713. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11714. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11715. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11716. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11717. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11718. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11719. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11720. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11721. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11722. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11723. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11724. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11725. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11726. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11727. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11728. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11729. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11730. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11731. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11732. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11733. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11734. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11735. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11736. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11737. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11738. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11739. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11740. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11741. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11742. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11743. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11744. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11745. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11746. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11747. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11748. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11749. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11750. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11751. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11752. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11753. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11754. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11755. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11756. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11757. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11758. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11759. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11760. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11761. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11762. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11763. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11764. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11765. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11766. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11767. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11768. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11769. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11770. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11771. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11772. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11773. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11774. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11775. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11776. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11777. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11778. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11779. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11780. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11781. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11782. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11783. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11784. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11785. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11786. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11787. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11788. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11789. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11790. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11791. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11792. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11793. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11794. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11795. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11796. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11797. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11798. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11799. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11800. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11801. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11802. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11803. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11804. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11805. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11806. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11807. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11808. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11809. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11810. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11811. };
  11812. static const int sizeof_bench_dilithium_level2_sig =
  11813. sizeof(bench_dilithium_level2_sig);
  11814. #endif
  11815. #ifndef WOLFSSL_NO_ML_DSA_65
  11816. static const unsigned char bench_dilithium_level3_sig[] = {
  11817. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11818. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11819. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11820. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11821. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11822. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11823. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11824. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11825. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11826. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11827. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11828. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11829. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11830. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11831. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11832. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11833. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11834. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11835. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11836. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11837. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11838. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11839. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11840. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11841. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11842. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11843. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11844. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11845. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11846. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11847. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11848. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11849. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11850. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11851. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11852. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11853. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11854. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11855. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11856. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11857. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11858. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11859. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11860. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11861. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11862. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11863. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11864. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11865. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11866. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11867. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11868. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11869. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11870. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11871. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11872. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11873. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11874. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11875. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11876. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11877. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11878. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11879. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11880. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11881. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11882. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11883. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11884. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11885. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11886. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11887. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11888. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11889. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11890. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11891. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11892. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11893. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11894. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11895. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11896. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11897. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11898. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11899. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11900. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11901. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11902. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11903. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11904. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11905. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11906. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11907. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11908. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11909. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11910. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11911. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11912. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11913. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11914. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11915. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11916. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11917. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11918. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11919. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11920. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11921. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11922. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11923. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11924. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11925. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11926. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11927. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11928. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11929. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11930. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11931. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11932. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11933. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11934. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11935. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11936. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11937. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11938. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11939. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11940. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11941. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11942. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11943. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11944. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11945. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11946. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11947. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11948. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11949. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11950. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11951. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11952. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11953. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11954. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11955. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11956. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11957. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11958. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11959. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11960. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11961. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11962. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11963. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11964. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11965. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11966. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11967. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11968. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11969. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11970. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11971. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11972. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11973. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11974. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11975. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11976. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11977. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11978. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11979. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11980. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11981. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11982. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11983. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11984. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11985. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11986. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11987. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11988. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11989. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11990. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11991. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11992. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11993. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11994. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11995. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11996. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11997. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11998. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11999. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  12000. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  12001. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  12002. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  12003. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  12004. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  12005. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  12006. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  12007. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  12008. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  12009. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  12010. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  12011. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  12012. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  12013. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  12014. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  12015. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  12016. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  12017. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  12018. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  12019. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  12020. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  12021. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  12022. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  12023. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  12024. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  12025. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  12026. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  12027. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  12028. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  12029. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  12030. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  12031. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  12032. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  12033. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  12034. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  12035. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  12036. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  12037. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  12038. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  12039. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  12040. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  12041. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  12042. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  12043. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  12044. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  12045. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  12046. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  12047. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  12048. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  12049. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  12050. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  12051. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  12052. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  12053. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  12054. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  12055. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  12056. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  12057. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  12058. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  12059. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  12060. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  12061. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  12062. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  12063. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  12064. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  12065. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  12066. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  12067. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  12068. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  12069. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  12070. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  12071. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  12072. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  12073. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  12074. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  12075. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  12076. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  12077. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  12078. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  12079. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  12080. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  12081. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  12082. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  12083. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  12084. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  12085. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  12086. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  12087. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  12088. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  12089. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  12090. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  12091. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  12092. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  12093. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  12094. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  12095. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  12096. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  12097. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  12098. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  12099. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  12100. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12101. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12102. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12103. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12104. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12105. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12106. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12107. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12108. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12109. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12110. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12111. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12112. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12113. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12114. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12115. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12116. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12117. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12118. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12119. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12120. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12121. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12122. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12123. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12124. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12125. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12126. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12127. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12128. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12129. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12130. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12131. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12132. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12133. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12134. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12135. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12136. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12137. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12138. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12139. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12140. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12141. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12142. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12143. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12144. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12145. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12147. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12148. };
  12149. static const int sizeof_bench_dilithium_level3_sig =
  12150. sizeof(bench_dilithium_level3_sig);
  12151. #endif
  12152. #ifndef WOLFSSL_NO_ML_DSA_87
  12153. static const unsigned char bench_dilithium_level5_sig[] = {
  12154. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12155. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12156. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12157. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12158. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12159. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12160. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12161. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12162. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12163. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12164. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12165. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12166. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12167. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12168. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12169. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12170. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12171. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12172. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12173. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12174. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12175. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12176. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12177. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12178. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12179. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12180. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12181. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12182. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12183. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12184. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12185. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12186. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12187. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12188. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12189. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12190. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12191. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12192. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12193. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12194. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12195. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12196. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12197. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12198. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12199. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12200. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12201. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12202. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12203. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12204. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12205. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12206. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12207. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12208. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12209. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12210. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12211. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12212. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12213. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12214. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12215. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12216. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12217. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12218. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12219. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12220. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12221. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12222. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12223. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12224. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12225. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12226. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12227. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12228. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12229. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12230. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12231. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12232. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12233. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12234. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12235. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12236. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12237. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12238. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12239. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12240. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12241. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12242. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12243. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12244. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12245. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12246. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12247. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12248. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12249. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12250. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12251. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12252. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12253. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12254. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12255. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12256. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12257. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12258. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12259. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12260. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12261. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12262. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12263. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12264. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12265. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12266. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12267. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12268. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12269. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12270. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12271. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12272. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12273. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12274. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12275. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12276. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12277. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12278. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12279. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12280. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12281. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12282. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12283. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12284. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12285. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12286. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12287. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12288. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12289. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12290. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12291. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12292. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12293. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12294. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12295. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12296. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12297. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12298. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12299. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12300. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12301. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12302. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12303. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12304. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12305. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12306. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12307. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12308. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12309. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12310. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12311. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12312. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12313. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12314. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12315. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12316. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12317. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12318. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12319. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12320. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12321. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12322. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12323. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12324. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12325. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12326. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12327. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12328. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12329. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12330. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12331. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12332. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12333. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12334. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12335. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12336. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12337. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12338. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12339. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12340. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12341. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12342. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12343. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12344. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12345. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12346. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12347. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12348. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12349. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12350. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12351. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12352. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12353. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12354. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12355. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12356. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12357. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12358. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12359. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12360. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12361. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12362. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12363. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12364. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12365. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12366. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12367. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12368. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12369. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12370. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12371. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12372. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12373. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12374. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12375. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12376. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12377. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12378. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12379. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12380. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12381. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12382. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12383. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12384. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12385. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12386. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12387. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12388. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12389. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12390. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12391. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12392. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12393. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12394. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12395. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12396. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12397. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12398. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12399. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12400. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12401. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12402. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12403. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12404. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12405. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12406. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12407. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12408. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12409. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12410. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12411. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12412. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12413. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12414. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12415. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12416. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12417. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12418. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12419. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12420. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12421. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12422. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12423. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12424. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12425. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12426. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12427. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12428. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12429. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12430. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12431. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12432. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12433. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12434. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12435. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12436. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12437. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12438. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12439. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12440. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12441. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12442. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12443. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12444. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12445. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12446. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12447. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12448. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12449. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12450. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12451. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12452. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12453. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12454. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12455. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12456. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12457. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12458. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12459. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12460. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12461. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12462. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12463. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12464. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12465. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12466. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12467. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12468. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12469. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12470. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12471. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12472. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12473. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12474. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12475. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12476. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12477. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12478. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12479. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12480. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12481. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12482. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12483. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12484. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12485. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12486. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12487. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12488. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12489. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12490. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12491. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12492. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12493. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12494. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12495. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12496. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12497. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12498. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12499. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12500. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12501. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12502. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12503. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12504. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12505. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12506. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12507. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12508. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12509. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12510. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12511. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12512. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12513. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12514. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12515. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12516. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12517. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12518. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12519. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12520. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12521. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12522. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12523. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12524. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12525. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12526. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12527. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12528. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12529. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12530. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12531. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12532. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12533. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12534. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12535. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12536. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12537. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12538. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12539. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12540. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12541. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12542. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12543. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12544. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12545. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12546. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12547. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12548. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12549. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12550. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12551. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12552. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12553. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12554. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12555. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12556. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12557. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12558. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12559. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12560. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12561. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12562. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12563. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12564. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12565. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12566. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12567. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12568. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12569. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12570. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12571. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12572. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12573. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12574. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12575. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12576. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12577. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12578. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12579. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12580. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12581. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12582. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12583. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12584. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12585. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12586. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12587. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12588. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12589. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12590. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12591. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12592. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12593. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12594. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12595. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12596. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12597. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12598. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12599. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12600. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12601. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12602. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12603. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12604. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12605. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12606. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12607. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12608. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12609. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12610. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12611. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12612. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12613. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12614. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12615. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12616. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12617. };
  12618. static const int sizeof_bench_dilithium_level5_sig =
  12619. sizeof(bench_dilithium_level5_sig);
  12620. #endif
  12621. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12622. void bench_dilithiumKeySign(byte level)
  12623. {
  12624. int ret = 0;
  12625. dilithium_key key;
  12626. double start;
  12627. int i, count;
  12628. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12629. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12630. byte msg[512];
  12631. word32 x = 0;
  12632. #endif
  12633. const char**desc = bench_desc_words[lng_index];
  12634. DECLARE_MULTI_VALUE_STATS_VARS()
  12635. byte params = 0;
  12636. if (level == 2) {
  12637. params = 44;
  12638. }
  12639. else if (level == 3) {
  12640. params = 65;
  12641. }
  12642. else if (level == 5) {
  12643. params = 87;
  12644. }
  12645. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12646. /* make dummy msg */
  12647. for (i = 0; i < (int)sizeof(msg); i++) {
  12648. msg[i] = (byte)i;
  12649. }
  12650. #endif
  12651. ret = wc_dilithium_init(&key);
  12652. if (ret != 0) {
  12653. printf("wc_dilithium_init failed %d\n", ret);
  12654. return;
  12655. }
  12656. ret = wc_dilithium_set_level(&key, level);
  12657. if (ret != 0) {
  12658. printf("wc_dilithium_set_level() failed %d\n", ret);
  12659. }
  12660. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12661. bench_stats_start(&count, &start);
  12662. do {
  12663. for (i = 0; i < agreeTimes; i++) {
  12664. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12665. if (ret != 0) {
  12666. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12667. return;
  12668. }
  12669. }
  12670. count += i;
  12671. } while (bench_stats_check(start)
  12672. #ifdef MULTI_VALUE_STATISTICS
  12673. || runs < minimum_runs
  12674. #endif
  12675. );
  12676. if (ret == 0) {
  12677. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12678. start, ret);
  12679. #ifdef MULTI_VALUE_STATISTICS
  12680. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12681. #endif
  12682. }
  12683. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12684. #ifndef WOLFSSL_NO_ML_DSA_44
  12685. if (level == 2) {
  12686. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12687. sizeof_bench_dilithium_level2_key, &key);
  12688. }
  12689. #endif
  12690. #ifndef WOLFSSL_NO_ML_DSA_65
  12691. if (level == 3) {
  12692. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12693. sizeof_bench_dilithium_level3_key, &key);
  12694. }
  12695. #endif
  12696. #ifndef WOLFSSL_NO_ML_DSA_87
  12697. if (level == 5) {
  12698. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12699. sizeof_bench_dilithium_level5_key, &key);
  12700. }
  12701. #endif
  12702. if (ret != 0) {
  12703. printf("Failed to load private key\n");
  12704. return;
  12705. }
  12706. #endif
  12707. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12708. if (level == 2) {
  12709. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12710. }
  12711. else if (level == 3) {
  12712. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12713. }
  12714. else {
  12715. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12716. }
  12717. RESET_MULTI_VALUE_STATS_VARS();
  12718. bench_stats_start(&count, &start);
  12719. do {
  12720. for (i = 0; i < agreeTimes; i++) {
  12721. if (ret == 0) {
  12722. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12723. GLOBAL_RNG);
  12724. if (ret != 0) {
  12725. printf("wc_dilithium_sign_msg failed\n");
  12726. }
  12727. }
  12728. RECORD_MULTI_VALUE_STATS();
  12729. }
  12730. count += i;
  12731. } while (bench_stats_check(start)
  12732. #ifdef MULTI_VALUE_STATISTICS
  12733. || runs < minimum_runs
  12734. #endif
  12735. );
  12736. if (ret == 0) {
  12737. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12738. ret);
  12739. #ifdef MULTI_VALUE_STATISTICS
  12740. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12741. #endif
  12742. }
  12743. #endif
  12744. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12745. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12746. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12747. #ifndef WOLFSSL_NO_ML_DSA_44
  12748. if (level == 2) {
  12749. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12750. x = sizeof_bench_dilithium_level2_sig;
  12751. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12752. #endif
  12753. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12754. sizeof_bench_dilithium_level2_pubkey, &key);
  12755. }
  12756. #endif
  12757. #ifndef WOLFSSL_NO_ML_DSA_65
  12758. if (level == 3) {
  12759. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12760. x = sizeof_bench_dilithium_level3_sig;
  12761. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12762. #endif
  12763. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12764. sizeof_bench_dilithium_level3_pubkey, &key);
  12765. }
  12766. #endif
  12767. #ifndef WOLFSSL_NO_ML_DSA_87
  12768. if (level == 5) {
  12769. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12770. x = sizeof_bench_dilithium_level5_sig;
  12771. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12772. #endif
  12773. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12774. sizeof_bench_dilithium_level5_pubkey, &key);
  12775. }
  12776. #endif
  12777. if (ret != 0) {
  12778. printf("Failed to load public key\n");
  12779. return;
  12780. }
  12781. #endif
  12782. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12783. RESET_MULTI_VALUE_STATS_VARS();
  12784. bench_stats_start(&count, &start);
  12785. do {
  12786. for (i = 0; i < agreeTimes; i++) {
  12787. if (ret == 0) {
  12788. int verify = 0;
  12789. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12790. &verify, &key);
  12791. if (ret != 0 || verify != 1) {
  12792. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12793. ret, verify);
  12794. ret = -1;
  12795. }
  12796. }
  12797. RECORD_MULTI_VALUE_STATS();
  12798. }
  12799. count += i;
  12800. } while (bench_stats_check(start)
  12801. #ifdef MULTI_VALUE_STATISTICS
  12802. || runs < minimum_runs
  12803. #endif
  12804. );
  12805. if (ret == 0) {
  12806. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12807. ret);
  12808. #ifdef MULTI_VALUE_STATISTICS
  12809. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12810. #endif
  12811. }
  12812. #endif
  12813. wc_dilithium_free(&key);
  12814. }
  12815. #endif /* HAVE_DILITHIUM */
  12816. #ifdef HAVE_SPHINCS
  12817. void bench_sphincsKeySign(byte level, byte optim)
  12818. {
  12819. int ret = 0;
  12820. sphincs_key key;
  12821. double start;
  12822. int i, count;
  12823. byte sig[SPHINCS_MAX_SIG_SIZE];
  12824. byte msg[512];
  12825. word32 x = 0;
  12826. const char**desc = bench_desc_words[lng_index];
  12827. DECLARE_MULTI_VALUE_STATS_VARS()
  12828. ret = wc_sphincs_init(&key);
  12829. if (ret != 0) {
  12830. printf("wc_sphincs_init failed %d\n", ret);
  12831. return;
  12832. }
  12833. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12834. if (ret != 0) {
  12835. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12836. }
  12837. if (ret == 0) {
  12838. ret = -1;
  12839. if ((level == 1) && (optim == FAST_VARIANT)) {
  12840. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12841. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12842. }
  12843. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12844. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12845. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12846. }
  12847. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12848. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12849. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12850. }
  12851. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12852. ret = wc_sphincs_import_private_key(
  12853. bench_sphincs_small_level1_key,
  12854. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12855. }
  12856. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12857. ret = wc_sphincs_import_private_key(
  12858. bench_sphincs_small_level3_key,
  12859. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12860. }
  12861. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12862. ret = wc_sphincs_import_private_key(
  12863. bench_sphincs_small_level5_key,
  12864. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12865. }
  12866. if (ret != 0) {
  12867. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12868. }
  12869. }
  12870. /* make dummy msg */
  12871. for (i = 0; i < (int)sizeof(msg); i++) {
  12872. msg[i] = (byte)i;
  12873. }
  12874. bench_stats_start(&count, &start);
  12875. do {
  12876. for (i = 0; i < agreeTimes; i++) {
  12877. if (ret == 0) {
  12878. if ((level == 1) && (optim == FAST_VARIANT)) {
  12879. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12880. }
  12881. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12882. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12883. }
  12884. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12885. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12886. }
  12887. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12888. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12889. }
  12890. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12891. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12892. }
  12893. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12894. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12895. }
  12896. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12897. if (ret != 0) {
  12898. printf("wc_sphincs_sign_msg failed\n");
  12899. }
  12900. }
  12901. RECORD_MULTI_VALUE_STATS();
  12902. }
  12903. count += i;
  12904. } while (bench_stats_check(start)
  12905. #ifdef MULTI_VALUE_STATISTICS
  12906. || runs < minimum_runs
  12907. #endif
  12908. );
  12909. if (ret == 0) {
  12910. if (optim == FAST_VARIANT) {
  12911. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12912. start, ret);
  12913. }
  12914. else {
  12915. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12916. start, ret);
  12917. }
  12918. #ifdef MULTI_VALUE_STATISTICS
  12919. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12920. #endif
  12921. }
  12922. RESET_MULTI_VALUE_STATS_VARS();
  12923. bench_stats_start(&count, &start);
  12924. do {
  12925. for (i = 0; i < agreeTimes; i++) {
  12926. if (ret == 0) {
  12927. int verify = 0;
  12928. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12929. &key);
  12930. if (ret != 0 || verify != 1) {
  12931. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12932. ret, verify);
  12933. ret = -1;
  12934. }
  12935. }
  12936. RECORD_MULTI_VALUE_STATS();
  12937. }
  12938. count += i;
  12939. } while (bench_stats_check(start)
  12940. #ifdef MULTI_VALUE_STATISTICS
  12941. || runs < minimum_runs
  12942. #endif
  12943. );
  12944. if (ret == 0) {
  12945. if (optim == FAST_VARIANT) {
  12946. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12947. start, ret);
  12948. }
  12949. else {
  12950. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12951. start, ret);
  12952. }
  12953. #ifdef MULTI_VALUE_STATISTICS
  12954. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12955. #endif
  12956. }
  12957. wc_sphincs_free(&key);
  12958. }
  12959. #endif /* HAVE_SPHINCS */
  12960. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12961. #define WIN32_LEAN_AND_MEAN
  12962. #include <windows.h>
  12963. double current_time(int reset)
  12964. {
  12965. static int init = 0;
  12966. static LARGE_INTEGER freq;
  12967. LARGE_INTEGER count;
  12968. (void)reset;
  12969. if (!init) {
  12970. QueryPerformanceFrequency(&freq);
  12971. init = 1;
  12972. }
  12973. QueryPerformanceCounter(&count);
  12974. #ifdef BENCH_MICROSECOND
  12975. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12976. #else
  12977. return (double)count.QuadPart / freq.QuadPart;
  12978. #endif
  12979. }
  12980. #elif defined MICROCHIP_PIC32
  12981. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12982. #define CLOCK 80000000.0
  12983. #else
  12984. #define CLOCK 40000000.0
  12985. #endif
  12986. extern void WriteCoreTimer(word32 t);
  12987. extern word32 ReadCoreTimer(void);
  12988. double current_time(int reset)
  12989. {
  12990. unsigned int ns;
  12991. if (reset) {
  12992. WriteCoreTimer(0);
  12993. }
  12994. /* get timer in ns */
  12995. ns = ReadCoreTimer();
  12996. /* return seconds as a double */
  12997. return ( ns / CLOCK * 2.0);
  12998. }
  12999. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  13000. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  13001. /* declared above at line 239 */
  13002. /* extern double current_time(int reset); */
  13003. #elif defined(FREERTOS)
  13004. #ifdef PLATFORMIO
  13005. #include <freertos/FreeRTOS.h>
  13006. #include <freertos/task.h>
  13007. #else
  13008. #include "task.h"
  13009. #endif
  13010. #if defined(WOLFSSL_ESPIDF)
  13011. /* prototype definition */
  13012. int construct_argv();
  13013. extern char* __argv[22];
  13014. /* current_time(reset)
  13015. *
  13016. * Benchmark passage of time, in fractional seconds.
  13017. * [reset] is non zero to adjust timer or counter to zero
  13018. *
  13019. * Use care when repeatedly calling calling. See implementation. */
  13020. double current_time(int reset)
  13021. {
  13022. double ret;
  13023. #if ESP_IDF_VERSION_MAJOR >= 4
  13024. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  13025. #else
  13026. portTickType tickCount;
  13027. #endif
  13028. #if defined(__XTENSA__)
  13029. (void)reset;
  13030. if (reset) {
  13031. /* TODO: Determine a mechanism for reset that does not interfere
  13032. * with freeRTOS tick. Using this code for Xtensa appears to cause
  13033. * RTOS tick timer to stick. See "last_tickCount unchanged".
  13034. ESP_LOGW(TAG, "Current_time() reset!");
  13035. portTICK_TYPE_ENTER_CRITICAL();
  13036. {
  13037. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  13038. _esp_cpu_count_last = xthal_get_ccount();
  13039. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  13040. }
  13041. portTICK_TYPE_EXIT_CRITICAL();
  13042. */
  13043. }
  13044. #else
  13045. /* Only reset the CPU counter for RISC-V */
  13046. if (reset) {
  13047. ESP_LOGV(TAG, "current_time() reset!");
  13048. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  13049. * unexpected rollovers in return values for Xtensa but not RISC-V?
  13050. * See also esp_get_cycle_count_ex() */
  13051. #ifdef __XTENSA__
  13052. _esp_cpu_count_last = xthal_get_ccount();
  13053. #else
  13054. #if ESP_IDF_VERSION_MAJOR >= 5
  13055. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  13056. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  13057. #else
  13058. cpu_hal_set_cycle_count((uint32_t)0);
  13059. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  13060. #endif
  13061. #endif
  13062. }
  13063. #endif
  13064. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  13065. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  13066. The count of ticks since vTaskStartScheduler was called,
  13067. typiclly in app_startup.c */
  13068. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13069. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  13070. if (tickCount == last_tickCount) {
  13071. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  13072. }
  13073. if (tickCount < last_tickCount) {
  13074. ESP_LOGW(TAG, "last_tickCount overflow?");
  13075. }
  13076. #endif
  13077. if (reset) {
  13078. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13079. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  13080. #endif
  13081. last_tickCount = tickCount;
  13082. }
  13083. else {
  13084. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13085. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  13086. #endif
  13087. }
  13088. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  13089. ret = (double)tickCount / configTICK_RATE_HZ;
  13090. #else
  13091. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  13092. "assuming 1000 Hz.");
  13093. ret = (double)(tickCount / 1000.0);
  13094. #endif /* configTICK_RATE_HZ */
  13095. return ret;
  13096. } /* current_time */
  13097. #else
  13098. /* current_time(reset)
  13099. *
  13100. * Benchmark passage of time, in fractional seconds.
  13101. * [reset] is non zero to adjust timer or counter to zero
  13102. *
  13103. * Use care when repeatedly calling calling. See implementation. */
  13104. double current_time(int reset)
  13105. {
  13106. portTickType tickCount = xTaskGetTickCount();
  13107. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13108. #ifdef configTICK_RATE_HZ
  13109. return (double)tickCount / configTICK_RATE_HZ;
  13110. #else
  13111. return (double)tickCount / 1000;
  13112. #endif
  13113. }
  13114. #endif
  13115. #elif defined (WOLFSSL_TIRTOS)
  13116. extern double current_time(int reset);
  13117. #elif defined(FREESCALE_MQX)
  13118. double current_time(int reset)
  13119. {
  13120. TIME_STRUCT tv;
  13121. _time_get(&tv);
  13122. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13123. }
  13124. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13125. && defined(MAX3266X_RTC)
  13126. double current_time(int reset)
  13127. {
  13128. (void)reset;
  13129. return wc_MXC_RTC_Time();
  13130. }
  13131. #elif defined(FREESCALE_KSDK_BM)
  13132. double current_time(int reset)
  13133. {
  13134. return (double)OSA_TimeGetMsec() / 1000;
  13135. }
  13136. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13137. double current_time(int reset)
  13138. {
  13139. (void)reset;
  13140. return (double)osKernelGetTickCount() / 1000.0;
  13141. }
  13142. #elif defined(WOLFSSL_EMBOS)
  13143. #include "RTOS.h"
  13144. double current_time(int reset)
  13145. {
  13146. double time_now;
  13147. double current_s = OS_GetTime() / 1000.0;
  13148. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13149. time_now = (double)( current_s + current_us);
  13150. (void) reset;
  13151. return time_now;
  13152. }
  13153. #elif defined(WOLFSSL_SGX)
  13154. double current_time(int reset);
  13155. #elif defined(WOLFSSL_DEOS)
  13156. double current_time(int reset)
  13157. {
  13158. const uint32_t systemTickTimeInHz
  13159. = 1000000 / systemTickInMicroseconds();
  13160. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13161. (void)reset;
  13162. return (double) *systemTickPtr/systemTickTimeInHz;
  13163. }
  13164. #elif defined(MICRIUM)
  13165. double current_time(int reset)
  13166. {
  13167. #if (OS_VERSION < 50000)
  13168. CPU_ERR err;
  13169. (void)reset;
  13170. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13171. #else
  13172. RTOS_ERR err;
  13173. double ret = 0;
  13174. OS_TICK tick = OSTimeGet(&err);
  13175. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13176. (void)reset;
  13177. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13178. ret = ((double)tick)/rate;
  13179. }
  13180. return ret;
  13181. #endif
  13182. }
  13183. #elif defined(WOLFSSL_ZEPHYR)
  13184. #include <time.h>
  13185. double current_time(int reset)
  13186. {
  13187. int64_t t;
  13188. (void)reset;
  13189. #if defined(CONFIG_ARCH_POSIX)
  13190. k_cpu_idle();
  13191. #endif
  13192. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13193. return (double)(t / 1000);
  13194. }
  13195. #elif defined(WOLFSSL_NETBURNER)
  13196. #include <predef.h>
  13197. #include <utils.h>
  13198. #include <constants.h>
  13199. double current_time(int reset)
  13200. {
  13201. DWORD ticks = TimeTick; /* ticks since system start */
  13202. (void)reset;
  13203. return (double) ticks/TICKS_PER_SECOND;
  13204. }
  13205. #elif defined(WOLFSSL_RPIPICO)
  13206. #include "pico/stdlib.h"
  13207. double current_time(int reset)
  13208. {
  13209. (void)reset;
  13210. return (double) time_us_64() / 1000000;
  13211. }
  13212. #elif defined(THREADX)
  13213. #include "tx_api.h"
  13214. double current_time(int reset)
  13215. {
  13216. (void)reset;
  13217. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13218. }
  13219. #elif defined(WOLFSSL_XILINX)
  13220. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13221. #define COUNTS_PER_SECOND \
  13222. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13223. #else
  13224. #define COUNTS_PER_SECOND \
  13225. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13226. #endif
  13227. double current_time(int reset)
  13228. {
  13229. double timer;
  13230. uint64_t cntPct = 0;
  13231. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13232. /* Convert to milliseconds */
  13233. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13234. /* Convert to seconds.millisecond */
  13235. timer /= 1000;
  13236. return timer;
  13237. }
  13238. #elif defined(LINUX_RUSAGE_UTIME)
  13239. #include <sys/time.h>
  13240. #include <sys/resource.h>
  13241. static struct rusage base_rusage;
  13242. static struct rusage cur_rusage;
  13243. double current_time(int reset)
  13244. {
  13245. struct rusage rusage;
  13246. (void)reset;
  13247. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13248. if (reset)
  13249. base_rusage = rusage;
  13250. else
  13251. cur_rusage = rusage;
  13252. /* only consider user time, as system time is host-related overhead
  13253. * outside wolfcrypt.
  13254. */
  13255. return (double)rusage.ru_utime.tv_sec +
  13256. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13257. }
  13258. static void check_for_excessive_stime(const char *desc,
  13259. const char *desc_extra)
  13260. {
  13261. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13262. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13263. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13264. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13265. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13266. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13267. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13268. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13269. double stime_utime_ratio =
  13270. (cur_stime - start_stime) / (cur_utime - start_utime);
  13271. if (stime_utime_ratio > .1)
  13272. printf("%swarning, "
  13273. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13274. err_prefix, desc, desc_extra,
  13275. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13276. }
  13277. #elif defined(WOLFSSL_LINUXKM)
  13278. double current_time(int reset)
  13279. {
  13280. (void)reset;
  13281. u64 ns = ktime_get_ns();
  13282. return (double)ns / 1000000000.0;
  13283. }
  13284. #elif defined(WOLFSSL_GAISLER_BCC)
  13285. #include <bcc/bcc.h>
  13286. double current_time(int reset)
  13287. {
  13288. (void)reset;
  13289. uint32_t us = bcc_timer_get_us();
  13290. return (double)us / 1000000.0;
  13291. }
  13292. #else
  13293. #include <time.h>
  13294. #include <sys/time.h>
  13295. double current_time(int reset)
  13296. {
  13297. struct timespec tv;
  13298. (void)reset;
  13299. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13300. #ifdef BENCH_MICROSECOND
  13301. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13302. #else
  13303. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13304. #endif
  13305. }
  13306. #endif /* _WIN32 */
  13307. #if defined(HAVE_GET_CYCLES)
  13308. #if defined(WOLFSSL_ESPIDF)
  13309. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13310. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13311. {
  13312. /* Reminder for long duration between calls with
  13313. * multiple overflows will not be detected. */
  13314. return esp_get_cycle_count_ex();
  13315. }
  13316. /* implement other architectures here */
  13317. #else
  13318. static WC_INLINE word64 get_intel_cycles(void)
  13319. {
  13320. unsigned int lo_c, hi_c;
  13321. __asm__ __volatile__ (
  13322. "cpuid\n\t"
  13323. "rdtsc"
  13324. : "=a"(lo_c), "=d"(hi_c) /* out */
  13325. : "a"(0) /* in */
  13326. : "%ebx", "%ecx"); /* clobber */
  13327. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13328. }
  13329. #endif
  13330. #endif /* HAVE_GET_CYCLES */
  13331. void benchmark_configure(word32 block_size)
  13332. {
  13333. /* must be greater than 0 */
  13334. if (block_size > 0) {
  13335. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13336. bench_size = block_size;
  13337. }
  13338. }
  13339. #ifndef NO_MAIN_DRIVER
  13340. #ifndef MAIN_NO_ARGS
  13341. #ifndef WOLFSSL_BENCHMARK_ALL
  13342. /* Display the algorithm string and keep to 80 characters per line.
  13343. *
  13344. * str Algorithm string to print.
  13345. * line Length of line used so far.
  13346. */
  13347. #ifndef BENCH_MAX_LINE
  13348. #define BENCH_MAX_LINE 80
  13349. #endif
  13350. static void print_alg(const char* str, int* line)
  13351. {
  13352. const char* const ident = " ";
  13353. if (*line == 0) {
  13354. printf("%s", ident);
  13355. *line = (int)XSTRLEN(ident);
  13356. }
  13357. printf(" %s", str);
  13358. *line += (int)XSTRLEN(str) + 1;
  13359. if (*line > BENCH_MAX_LINE) {
  13360. printf("\n");
  13361. *line = 0;
  13362. }
  13363. }
  13364. #endif /* WOLFSSL_BENCHMARK_ALL */
  13365. /* Display the usage options of the benchmark program. */
  13366. static void Usage(void)
  13367. {
  13368. int e = 0;
  13369. #ifndef WOLFSSL_BENCHMARK_ALL
  13370. int i;
  13371. int line;
  13372. #endif
  13373. printf("benchmark\n");
  13374. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13375. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13376. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13377. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13378. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13379. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13380. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13381. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13382. #else
  13383. e += 3;
  13384. #endif
  13385. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13386. #ifndef NO_RSA
  13387. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13388. #ifdef WOLFSSL_KEY_GEN
  13389. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13390. #endif
  13391. e++;
  13392. #else
  13393. e += 2;
  13394. #endif
  13395. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13396. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13397. #endif
  13398. e++;
  13399. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13400. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13401. #endif
  13402. e++;
  13403. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13404. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13405. #endif
  13406. e++;
  13407. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13408. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13409. #endif
  13410. e++;
  13411. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13412. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13413. #endif
  13414. e++;
  13415. #if defined(HAVE_ECC)
  13416. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13417. #endif
  13418. e++;
  13419. #ifndef WOLFSSL_BENCHMARK_ALL
  13420. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13421. line = 0;
  13422. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13423. print_alg(bench_cipher_opt[i].str, &line);
  13424. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13425. print_alg(bench_digest_opt[i].str, &line);
  13426. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13427. print_alg(bench_mac_opt[i].str, &line);
  13428. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13429. print_alg(bench_kdf_opt[i].str, &line);
  13430. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13431. print_alg(bench_asym_opt[i].str, &line);
  13432. for (i=0; bench_other_opt[i].str != NULL; i++)
  13433. print_alg(bench_other_opt[i].str, &line);
  13434. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13435. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13436. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13437. print_alg(bench_pq_asym_opt[i].str, &line);
  13438. #if defined(HAVE_SPHINCS)
  13439. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13440. print_alg(bench_pq_asym_opt2[i].str, &line);
  13441. #endif /* HAVE_SPHINCS */
  13442. #endif
  13443. #if defined(BENCH_PQ_STATEFUL_HBS)
  13444. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13445. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13446. #endif /* BENCH_PQ_STATEFUL_HBS */
  13447. printf("\n");
  13448. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13449. e++;
  13450. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13451. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13452. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13453. #ifdef WC_ENABLE_BENCH_THREADING
  13454. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13455. #endif
  13456. e++;
  13457. #ifdef WC_BENCH_TRACK_STATS
  13458. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13459. #endif
  13460. e++;
  13461. #ifndef NO_FILESYSTEM
  13462. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13463. #endif
  13464. e++;
  13465. #ifndef NO_FILESYSTEM
  13466. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13467. #endif
  13468. #ifdef MULTI_VALUE_STATISTICS
  13469. e++;
  13470. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13471. #endif
  13472. }
  13473. /* Match the command line argument with the string.
  13474. *
  13475. * arg Command line argument.
  13476. * str String to check for.
  13477. * return 1 if the command line argument matches the string, 0 otherwise.
  13478. */
  13479. static int string_matches(const char* arg, const char* str)
  13480. {
  13481. return XSTRCMP(arg, str) == 0;
  13482. }
  13483. #endif /* MAIN_NO_ARGS */
  13484. /*
  13485. ** ----------------------------------------------------------------------------
  13486. ** determine how the benchmarks are called, the function name varies:
  13487. ** ----------------------------------------------------------------------------
  13488. */
  13489. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13490. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13491. /* for some environments, we'll call a function wolf_benchmark_task: */
  13492. int wolf_benchmark_task(void)
  13493. #elif defined(MAIN_NO_ARGS)
  13494. /* otherwise we'll use main() with no arguments as desired: */
  13495. int main()
  13496. #else
  13497. /* else we'll be calling main with default arg parameters */
  13498. int main(int argc, char** argv)
  13499. #endif
  13500. {
  13501. /* Code for main() or wolf_benchmark_task() */
  13502. #ifdef WOLFSSL_ESPIDF
  13503. int argc = construct_argv();
  13504. char** argv = (char**)__argv;
  13505. #elif defined(MAIN_NO_ARGS)
  13506. int argc = 0;
  13507. char** argv = NULL;
  13508. #endif
  13509. return wolfcrypt_benchmark_main(argc, argv);
  13510. }
  13511. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13512. int wolfcrypt_benchmark_main(int argc, char** argv)
  13513. {
  13514. int ret = 0;
  13515. #ifndef MAIN_NO_ARGS
  13516. int optMatched;
  13517. #ifndef WOLFSSL_BENCHMARK_ALL
  13518. int i;
  13519. #endif
  13520. #endif
  13521. benchmark_static_init(1);
  13522. printf("%s------------------------------------------------------------------------------\n",
  13523. info_prefix);
  13524. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13525. printf("%s------------------------------------------------------------------------------\n",
  13526. info_prefix);
  13527. #ifndef MAIN_NO_ARGS
  13528. while (argc > 1) {
  13529. if (string_matches(argv[1], "-?")) {
  13530. if (--argc > 1) {
  13531. lng_index = XATOI((++argv)[1]);
  13532. if (lng_index<0 || lng_index>1) {
  13533. lng_index = 0;
  13534. }
  13535. }
  13536. Usage();
  13537. return 0;
  13538. }
  13539. else if (string_matches(argv[1], "-lng")) {
  13540. argc--;
  13541. argv++;
  13542. if (argc > 1) {
  13543. lng_index = XATOI(argv[1]);
  13544. if (lng_index<0 || lng_index>1) {
  13545. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13546. lng_index);
  13547. lng_index = 0;
  13548. }
  13549. }
  13550. }
  13551. else if (string_matches(argv[1], "-base10"))
  13552. base2 = 0;
  13553. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13554. else if (string_matches(argv[1], "-no_aad"))
  13555. aes_aad_options = AAD_SIZE_ZERO;
  13556. else if (string_matches(argv[1], "-all_aad"))
  13557. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13558. else if (string_matches(argv[1], "-aad_size")) {
  13559. argc--;
  13560. argv++;
  13561. if (argc > 1) {
  13562. aes_aad_size = (word32)XATOI(argv[1]);
  13563. aes_aad_options |= AAD_SIZE_CUSTOM;
  13564. }
  13565. }
  13566. #endif
  13567. else if (string_matches(argv[1], "-dgst_full"))
  13568. digest_stream = 0;
  13569. #ifdef HAVE_CHACHA
  13570. else if (string_matches(argv[1], "-enc_only"))
  13571. encrypt_only = 1;
  13572. #endif
  13573. #ifndef NO_RSA
  13574. else if (string_matches(argv[1], "-rsa_sign"))
  13575. rsa_sign_verify = 1;
  13576. #endif
  13577. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13578. else if (string_matches(argv[1], "-ffdhe2048"))
  13579. use_ffdhe = 2048;
  13580. #endif
  13581. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13582. else if (string_matches(argv[1], "-ffdhe3072"))
  13583. use_ffdhe = 3072;
  13584. #endif
  13585. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13586. else if (string_matches(argv[1], "-ffdhe4096"))
  13587. use_ffdhe = 4096;
  13588. #endif
  13589. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13590. else if (string_matches(argv[1], "-p256"))
  13591. bench_asym_algs |= BENCH_ECC_P256;
  13592. #endif
  13593. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13594. else if (string_matches(argv[1], "-p384"))
  13595. bench_asym_algs |= BENCH_ECC_P384;
  13596. #endif
  13597. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13598. else if (string_matches(argv[1], "-p521"))
  13599. bench_asym_algs |= BENCH_ECC_P521;
  13600. #endif
  13601. #ifdef BENCH_ASYM
  13602. else if (string_matches(argv[1], "-csv")) {
  13603. csv_format = 1;
  13604. }
  13605. #endif
  13606. #ifdef WC_ENABLE_BENCH_THREADING
  13607. else if (string_matches(argv[1], "-threads")) {
  13608. argc--;
  13609. argv++;
  13610. if (argc > 1) {
  13611. g_threadCount = XATOI(argv[1]);
  13612. if (g_threadCount < 1 || lng_index > 128){
  13613. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13614. g_threadCount);
  13615. g_threadCount = 0;
  13616. }
  13617. }
  13618. }
  13619. #endif
  13620. #ifdef WC_BENCH_TRACK_STATS
  13621. else if (string_matches(argv[1], "-print")) {
  13622. gPrintStats = 1;
  13623. }
  13624. #endif
  13625. else if (string_matches(argv[1], "-blocks")) {
  13626. argc--;
  13627. argv++;
  13628. if (argc > 1)
  13629. numBlocks = XATOI(argv[1]);
  13630. }
  13631. #ifndef NO_FILESYSTEM
  13632. else if (string_matches(argv[1], "-hash_input")) {
  13633. argc--;
  13634. argv++;
  13635. if (argc > 1)
  13636. hash_input = argv[1];
  13637. }
  13638. else if (string_matches(argv[1], "-cipher_input")) {
  13639. argc--;
  13640. argv++;
  13641. if (argc > 1)
  13642. cipher_input = argv[1];
  13643. }
  13644. #endif
  13645. #ifdef MULTI_VALUE_STATISTICS
  13646. else if (string_matches(argv[1], "-min_runs")) {
  13647. argc--;
  13648. argv++;
  13649. if (argc > 1) {
  13650. minimum_runs = XATOI(argv[1]);
  13651. }
  13652. }
  13653. #endif
  13654. else if (argv[1][0] == '-') {
  13655. optMatched = 0;
  13656. #ifndef WOLFSSL_BENCHMARK_ALL
  13657. /* Check known algorithm choosing command line options. */
  13658. /* Known cipher algorithms */
  13659. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13660. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13661. bench_cipher_algs |= bench_cipher_opt[i].val;
  13662. bench_all = 0;
  13663. optMatched = 1;
  13664. }
  13665. }
  13666. /* Known digest algorithms */
  13667. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13668. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13669. bench_digest_algs |= bench_digest_opt[i].val;
  13670. bench_all = 0;
  13671. optMatched = 1;
  13672. }
  13673. }
  13674. /* Known MAC algorithms */
  13675. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13676. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13677. bench_mac_algs |= bench_mac_opt[i].val;
  13678. bench_all = 0;
  13679. optMatched = 1;
  13680. }
  13681. }
  13682. /* Known KDF algorithms */
  13683. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13684. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13685. bench_kdf_algs |= bench_kdf_opt[i].val;
  13686. bench_all = 0;
  13687. optMatched = 1;
  13688. }
  13689. }
  13690. /* Known asymmetric algorithms */
  13691. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13692. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13693. bench_asym_algs |= bench_asym_opt[i].val;
  13694. bench_all = 0;
  13695. optMatched = 1;
  13696. }
  13697. }
  13698. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13699. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13700. /* Known asymmetric post-quantum algorithms */
  13701. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13702. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13703. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13704. bench_all = 0;
  13705. optMatched = 1;
  13706. }
  13707. }
  13708. #ifdef HAVE_SPHINCS
  13709. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13710. * -pq, so we need to do a special case for -pq since optMatched
  13711. * was set to 1 just above. */
  13712. if ((bench_pq_asym_opt[0].str != NULL) &&
  13713. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13714. {
  13715. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13716. bench_all = 0;
  13717. optMatched = 1;
  13718. }
  13719. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13720. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13721. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13722. bench_all = 0;
  13723. optMatched = 1;
  13724. }
  13725. }
  13726. #endif
  13727. #endif
  13728. /* Other known cryptographic algorithms */
  13729. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13730. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13731. bench_other_algs |= bench_other_opt[i].val;
  13732. bench_all = 0;
  13733. optMatched = 1;
  13734. }
  13735. }
  13736. #if defined(BENCH_PQ_STATEFUL_HBS)
  13737. /* post-quantum stateful hash-based signatures */
  13738. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13739. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13740. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13741. bench_all = 0;
  13742. optMatched = 1;
  13743. }
  13744. }
  13745. #endif /* BENCH_PQ_STATEFUL_HBS */
  13746. #endif
  13747. if (!optMatched) {
  13748. printf("Option not recognized: %s\n", argv[1]);
  13749. Usage();
  13750. return 1;
  13751. }
  13752. }
  13753. else {
  13754. /* parse for block size */
  13755. benchmark_configure((word32)XATOI(argv[1]));
  13756. }
  13757. argc--;
  13758. argv++;
  13759. }
  13760. #endif /* MAIN_NO_ARGS */
  13761. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13762. /* when defined, we'll always output CSV regardless of params.
  13763. ** this is typically convenient in embedded environments.
  13764. */
  13765. csv_format = 1;
  13766. #endif
  13767. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13768. if (g_threadCount > 1) {
  13769. ret = benchmark_test_threaded(NULL);
  13770. }
  13771. else
  13772. #endif
  13773. {
  13774. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13775. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13776. defined(CONFIG_IDF_TARGET_ESP32C6)
  13777. {
  13778. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13779. if (esp_gptimer == NULL) {
  13780. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13781. &esp_gptimer) );
  13782. }
  13783. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13784. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13785. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13786. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13787. }
  13788. #endif
  13789. #ifdef HAVE_STACK_SIZE
  13790. ret = StackSizeCheck(NULL, benchmark_test);
  13791. #else
  13792. ret = benchmark_test(NULL);
  13793. #endif
  13794. }
  13795. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13796. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13797. defined(CONFIG_IDF_TARGET_ESP32C6)
  13798. {
  13799. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13800. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13801. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13802. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13803. }
  13804. #endif
  13805. return ret;
  13806. }
  13807. #endif /* !NO_MAIN_DRIVER */
  13808. #else
  13809. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13810. int main(void) { return 0; }
  13811. #endif
  13812. #endif /* !NO_CRYPT_BENCHMARK */