1
0

benchmark.c 516 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217
  1. /* benchmark.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS)
  166. #include <wolfssl/wolfcrypt/ext_kyber.h>
  167. #endif
  168. #endif
  169. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  170. #include <wolfssl/wolfcrypt/lms.h>
  171. #ifdef HAVE_LIBLMS
  172. #include <wolfssl/wolfcrypt/ext_lms.h>
  173. #else
  174. #include <wolfssl/wolfcrypt/wc_lms.h>
  175. #endif
  176. #endif
  177. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  178. #include <wolfssl/wolfcrypt/xmss.h>
  179. #ifdef HAVE_LIBXMSS
  180. #include <wolfssl/wolfcrypt/ext_xmss.h>
  181. #else
  182. #include <wolfssl/wolfcrypt/wc_xmss.h>
  183. #endif
  184. #endif
  185. #ifdef WOLFCRYPT_HAVE_ECCSI
  186. #include <wolfssl/wolfcrypt/eccsi.h>
  187. #endif
  188. #ifdef WOLFCRYPT_HAVE_SAKKE
  189. #include <wolfssl/wolfcrypt/sakke.h>
  190. #endif
  191. #if defined(HAVE_FALCON)
  192. #include <wolfssl/wolfcrypt/falcon.h>
  193. #endif
  194. #if defined(HAVE_DILITHIUM)
  195. #include <wolfssl/wolfcrypt/dilithium.h>
  196. #endif
  197. #if defined(HAVE_SPHINCS)
  198. #include <wolfssl/wolfcrypt/sphincs.h>
  199. #endif
  200. #ifdef WOLF_CRYPTO_CB
  201. #include <wolfssl/wolfcrypt/cryptocb.h>
  202. #ifdef HAVE_INTEL_QA_SYNC
  203. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  204. #endif
  205. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  206. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  207. #endif
  208. #ifdef HAVE_RENESAS_SYNC
  209. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  210. #endif
  211. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  212. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  213. #endif
  214. #endif
  215. #ifdef WOLFSSL_ASYNC_CRYPT
  216. #include <wolfssl/wolfcrypt/async.h>
  217. #endif
  218. #ifdef USE_FLAT_BENCHMARK_H
  219. #include "benchmark.h"
  220. #else
  221. #include "wolfcrypt/benchmark/benchmark.h"
  222. #endif
  223. /* define the max length for each string of metric reported */
  224. #ifndef WC_BENCH_MAX_LINE_LEN
  225. #define WC_BENCH_MAX_LINE_LEN 150
  226. #endif
  227. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  228. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  229. #define MILLION_VALUE 1000000.0
  230. #ifdef BENCH_MICROSECOND
  231. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  232. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  233. #else
  234. #define WOLFSSL_FIXED_TIME_UNIT "s"
  235. #endif
  236. #ifdef MULTI_VALUE_STATISTICS
  237. #define STATS_CLAUSE_SEPARATOR ""
  238. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  239. squareSum = 0, prev = 0, delta;\
  240. int runs = 0;
  241. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  242. delta = current_time(0) - start;\
  243. min = delta;\
  244. max = delta;\
  245. }\
  246. else {\
  247. delta = current_time(0) - prev;\
  248. }\
  249. if (max < delta)\
  250. max = delta;\
  251. else if (min > delta)\
  252. min = delta;\
  253. sum += delta;\
  254. squareSum += delta * delta;\
  255. runs++;\
  256. prev = current_time(0)
  257. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  258. runs = 0;\
  259. sum = 0;\
  260. squareSum = 0
  261. #else
  262. #define STATS_CLAUSE_SEPARATOR "\n"
  263. #define DECLARE_MULTI_VALUE_STATS_VARS()
  264. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  265. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  266. #endif
  267. #ifdef WOLFSSL_NO_FLOAT_FMT
  268. #define FLT_FMT "%0ld,%09lu"
  269. #define FLT_FMT_PREC "%0ld.%0*lu"
  270. #define FLT_FMT_PREC2 FLT_FMT_PREC
  271. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  272. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  273. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  274. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  275. 10000.0, 100000.0, 1000000.0, \
  276. 10000000.0, 100000000.0, \
  277. 1000000000.0 };
  278. #define FLT_FMT_PREC_ARGS(p, x) \
  279. (long)(x), \
  280. p, \
  281. (x) >= 0.0 ? \
  282. (unsigned long int)((((x) - (double)(long)(x)) * \
  283. pow_10_array[(p)+1]) + 0.5) : \
  284. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  285. pow_10_array[(p)+1]) + 0.5)
  286. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  287. #else
  288. #define FLT_FMT "%f"
  289. #define FLT_FMT_PREC "%.*f"
  290. #define FLT_FMT_PREC2 "%*.*f"
  291. #define FLT_FMT_ARGS(x) x
  292. #define FLT_FMT_PREC_ARGS(p, x) p, x
  293. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  294. #endif /* WOLFSSL_NO_FLOAT_FMT */
  295. #ifdef WOLFSSL_ESPIDF
  296. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  297. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  298. * enabled, all if the values in report are blank. */
  299. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  300. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  301. #error "Nano newlib formatting must not be enabled for benchmark"
  302. #endif
  303. #endif
  304. #if ESP_IDF_VERSION_MAJOR >= 5
  305. #define TFMT "%lu"
  306. #else
  307. #define TFMT "%d"
  308. #endif
  309. #ifdef configTICK_RATE_HZ
  310. /* Define CPU clock cycles per tick of FreeRTOS clock
  311. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  312. * configTICK_RATE_HZ is typically 100 or 1000.
  313. **/
  314. #if defined(CONFIG_IDF_TARGET_ESP8266)
  315. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  316. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  317. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  318. #endif
  319. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  320. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  321. #endif
  322. #endif
  323. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  324. /* This section is for pre-v5 ESP-IDF */
  325. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  326. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  327. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  328. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  329. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  330. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  331. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  332. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  333. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  334. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  335. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  336. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  337. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  338. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  339. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  340. #else
  341. /* TODO unsupported */
  342. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  343. #endif
  344. #define CPU_TICK_CYCLES ( \
  345. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  346. / configTICK_RATE_HZ \
  347. )
  348. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  349. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  350. #include "driver/gptimer.h"
  351. static gptimer_handle_t esp_gptimer = NULL;
  352. static gptimer_config_t esp_timer_config = {
  353. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  354. .direction = GPTIMER_COUNT_UP,
  355. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  356. };
  357. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  358. defined(CONFIG_IDF_TARGET_ESP32C6)
  359. #include <esp_cpu.h>
  360. #if ESP_IDF_VERSION_MAJOR >= 5
  361. #include <driver/gptimer.h>
  362. #endif
  363. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  364. #define RESOLUTION_SCALE 100
  365. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  366. static gptimer_handle_t esp_gptimer = NULL;
  367. static gptimer_config_t esp_timer_config = {
  368. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  369. .direction = GPTIMER_COUNT_UP,
  370. /* CONFIG_XTAL_FREQ = 40,
  371. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  372. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  373. (MILLION_VALUE / RESOLUTION_SCALE),
  374. };
  375. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  376. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  377. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S3)
  379. #include <xtensa/hal.h>
  380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  381. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  382. #include <FreeRTOS.h>
  383. #include <esp_system.h>
  384. #include <esp_timer.h>
  385. #include <xtensa/hal.h>
  386. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  387. /* TODO add ESP32-H2 benchmark support */
  388. #else
  389. /* Other platform */
  390. #endif
  391. #include <esp_log.h>
  392. #endif /* WOLFSSL_ESPIDF */
  393. #if defined(HAVE_PTHREAD) || \
  394. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  395. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  396. !defined(BENCH_EMBEDDED))
  397. #include <errno.h>
  398. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  399. #include <unistd.h>
  400. #endif
  401. #endif
  402. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  403. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  404. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  405. #undef XFFLUSH
  406. #define XFFLUSH(...) WC_DO_NOTHING
  407. #endif
  408. /* only for stack size check */
  409. #include <wolfssl/wolfcrypt/mem_track.h>
  410. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  411. #define WC_ENABLE_BENCH_THREADING
  412. #endif
  413. /* enable tracking of stats for threaded benchmark */
  414. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  415. #define WC_BENCH_TRACK_STATS
  416. #endif
  417. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  418. static const char info_prefix[] = "###, ";
  419. static const char err_prefix[] = "!!!, ";
  420. #else
  421. static const char info_prefix[] = "";
  422. static const char err_prefix[] = "";
  423. #endif
  424. /* printf mappings */
  425. #ifdef FREESCALE_MQX
  426. #include <mqx.h>
  427. /* see wc_port.h for fio.h and nio.h includes */
  428. #elif defined(FREESCALE_KSDK_1_3)
  429. #include "fsl_debug_console.h"
  430. #include "fsl_os_abstraction.h"
  431. #undef printf
  432. #define printf PRINTF
  433. #elif defined(WOLFSSL_DEOS)
  434. #include <deos.h>
  435. #include <printx.h>
  436. #undef printf
  437. #define printf printx
  438. #elif defined(MICRIUM)
  439. #if (OS_VERSION < 50000)
  440. #include <bsp_ser.h>
  441. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  442. #undef printf
  443. #define printf BSP_Ser_Printf
  444. #endif
  445. #elif defined(WOLFSSL_ZEPHYR)
  446. #include <stdio.h>
  447. #include <stdarg.h>
  448. #define BENCH_EMBEDDED
  449. #define printf printfk
  450. static int printfk(const char *fmt, ...)
  451. {
  452. int ret;
  453. char line[WC_BENCH_MAX_LINE_LEN];
  454. va_list ap;
  455. va_start(ap, fmt);
  456. ret = vsnprintf(line, sizeof(line), fmt, ap);
  457. line[sizeof(line)-1] = '\0';
  458. printk("%s", line);
  459. va_end(ap);
  460. return ret;
  461. }
  462. #elif defined(WOLFSSL_TELIT_M2MB)
  463. #include <stdarg.h>
  464. #include <stdio.h>
  465. #include <string.h>
  466. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  467. /* remap printf */
  468. #undef printf
  469. #define printf M2M_LOG_INFO
  470. /* OS requires occasional sleep() */
  471. #ifndef TEST_SLEEP_MS
  472. #define TEST_SLEEP_MS 50
  473. #endif
  474. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  475. /* don't use file system for these tests, since ./certs dir isn't loaded */
  476. #undef NO_FILESYSTEM
  477. #define NO_FILESYSTEM
  478. /* ANDROID_V454 (for android studio) displays information in a textview
  479. * and redirects printf to the textview output instead of using
  480. * __android_log_print() */
  481. #elif defined(ANDROID) && !defined(ANDROID_V454)
  482. #ifdef XMALLOC_USER
  483. #include <stdlib.h> /* we're using malloc / free direct here */
  484. #endif
  485. #ifndef STRING_USER
  486. #include <stdio.h>
  487. #endif
  488. #include <android/log.h>
  489. #define printf(...) \
  490. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  491. #define fprintf(fp, ...) \
  492. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  493. #else
  494. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  495. /* MQX classic needs for EXIT_FAILURE */
  496. #include <stdlib.h> /* we're using malloc / free direct here */
  497. #endif
  498. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  499. #include <string.h>
  500. #include <stdio.h>
  501. #endif
  502. /* enable way for customer to override test/bench printf */
  503. #ifdef XPRINTF
  504. #undef printf
  505. #define printf XPRINTF
  506. #elif defined(NETOS)
  507. #undef printf
  508. #define printf dc_log_printf
  509. #endif
  510. #endif
  511. #ifdef HAVE_FIPS
  512. #include <wolfssl/wolfcrypt/fips_test.h>
  513. static void myFipsCb(int ok, int err, const char* hash)
  514. {
  515. printf("%sin my Fips callback, ok = %d, err = %d\n",
  516. ok ? info_prefix : err_prefix, ok, err);
  517. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  518. wc_GetErrorString(err));
  519. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  520. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  521. printf("%sIn core integrity hash check failure, copy above hash\n",
  522. err_prefix);
  523. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  524. err_prefix);
  525. }
  526. }
  527. #endif
  528. #ifdef WOLFSSL_STATIC_MEMORY
  529. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  530. #else
  531. #define HEAP_HINT NULL
  532. #endif /* WOLFSSL_STATIC_MEMORY */
  533. #ifndef EXIT_FAILURE
  534. #define EXIT_FAILURE 1
  535. #endif
  536. #undef LIBCALL_CHECK_RET
  537. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  538. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  539. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  540. #else
  541. #define LIBCALL_CHECK_RET(...) do { \
  542. int _libcall_ret = (__VA_ARGS__); \
  543. if (_libcall_ret < 0) { \
  544. printf("%s%s L%d error %d for \"%s\"\n", \
  545. err_prefix, __FILE__, __LINE__, \
  546. errno, #__VA_ARGS__); \
  547. XFFLUSH(stdout); \
  548. _exit(1); \
  549. } \
  550. } while(0)
  551. #endif
  552. #undef THREAD_CHECK_RET
  553. #define THREAD_CHECK_RET(...) do { \
  554. int _thread_ret = (__VA_ARGS__); \
  555. if (_thread_ret != 0) { \
  556. errno = _thread_ret; \
  557. printf("%s%s L%d error %d for \"%s\"\n", \
  558. err_prefix, __FILE__, __LINE__, \
  559. _thread_ret, #__VA_ARGS__); \
  560. XFFLUSH(stdout); \
  561. _exit(1); \
  562. } \
  563. } while(0)
  564. /* optional macro to add sleep between tests */
  565. #ifndef TEST_SLEEP
  566. /* stub the sleep macro */
  567. #define TEST_SLEEP() WC_DO_NOTHING
  568. #endif
  569. #define TEST_STRING "Everyone gets Friday off."
  570. #define TEST_STRING_SZ 25
  571. /* Bit values for each algorithm that is able to be benchmarked.
  572. * Common grouping of algorithms also.
  573. * Each algorithm has a unique value for its type e.g. cipher.
  574. */
  575. /* Cipher algorithms. */
  576. #define BENCH_AES_CBC 0x00000001
  577. #define BENCH_AES_GCM 0x00000002
  578. #define BENCH_AES_ECB 0x00000004
  579. #define BENCH_AES_XTS 0x00000008
  580. #define BENCH_AES_CTR 0x00000010
  581. #define BENCH_AES_CCM 0x00000020
  582. #define BENCH_CAMELLIA 0x00000100
  583. #define BENCH_ARC4 0x00000200
  584. #define BENCH_CHACHA20 0x00001000
  585. #define BENCH_CHACHA20_POLY1305 0x00002000
  586. #define BENCH_DES 0x00004000
  587. #define BENCH_AES_CFB 0x00010000
  588. #define BENCH_AES_OFB 0x00020000
  589. #define BENCH_AES_SIV 0x00040000
  590. #define BENCH_SM4_CBC 0x00080000
  591. #define BENCH_SM4_GCM 0x00100000
  592. #define BENCH_SM4_CCM 0x00200000
  593. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  594. /* Digest algorithms. */
  595. #define BENCH_MD5 0x00000001
  596. #define BENCH_POLY1305 0x00000002
  597. #define BENCH_SHA 0x00000004
  598. #define BENCH_SHA224 0x00000010
  599. #define BENCH_SHA256 0x00000020
  600. #define BENCH_SHA384 0x00000040
  601. #define BENCH_SHA512 0x00000080
  602. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  603. BENCH_SHA384 | BENCH_SHA512)
  604. #define BENCH_SHA3_224 0x00000100
  605. #define BENCH_SHA3_256 0x00000200
  606. #define BENCH_SHA3_384 0x00000400
  607. #define BENCH_SHA3_512 0x00000800
  608. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  609. BENCH_SHA3_384 | BENCH_SHA3_512)
  610. #define BENCH_SHAKE128 0x00001000
  611. #define BENCH_SHAKE256 0x00002000
  612. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  613. #define BENCH_RIPEMD 0x00004000
  614. #define BENCH_BLAKE2B 0x00008000
  615. #define BENCH_BLAKE2S 0x00010000
  616. #define BENCH_SM3 0x00020000
  617. /* MAC algorithms. */
  618. #define BENCH_CMAC 0x00000001
  619. #define BENCH_HMAC_MD5 0x00000002
  620. #define BENCH_HMAC_SHA 0x00000004
  621. #define BENCH_HMAC_SHA224 0x00000010
  622. #define BENCH_HMAC_SHA256 0x00000020
  623. #define BENCH_HMAC_SHA384 0x00000040
  624. #define BENCH_HMAC_SHA512 0x00000080
  625. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  626. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  627. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  628. #define BENCH_PBKDF2 0x00000100
  629. #define BENCH_SIPHASH 0x00000200
  630. /* KDF algorithms */
  631. #define BENCH_SRTP_KDF 0x00000001
  632. /* Asymmetric algorithms. */
  633. #define BENCH_RSA_KEYGEN 0x00000001
  634. #define BENCH_RSA 0x00000002
  635. #define BENCH_RSA_SZ 0x00000004
  636. #define BENCH_DH 0x00000010
  637. #define BENCH_ECC_MAKEKEY 0x00001000
  638. #define BENCH_ECC 0x00002000
  639. #define BENCH_ECC_ENCRYPT 0x00004000
  640. #define BENCH_ECC_ALL 0x00008000
  641. #define BENCH_CURVE25519_KEYGEN 0x00010000
  642. #define BENCH_CURVE25519_KA 0x00020000
  643. #define BENCH_ED25519_KEYGEN 0x00040000
  644. #define BENCH_ED25519_SIGN 0x00080000
  645. #define BENCH_CURVE448_KEYGEN 0x00100000
  646. #define BENCH_CURVE448_KA 0x00200000
  647. #define BENCH_ED448_KEYGEN 0x00400000
  648. #define BENCH_ED448_SIGN 0x00800000
  649. #define BENCH_ECC_P256 0x01000000
  650. #define BENCH_ECC_P384 0x02000000
  651. #define BENCH_ECC_P521 0x04000000
  652. #define BENCH_SM2 0x08000000
  653. #define BENCH_ECCSI_KEYGEN 0x00000020
  654. #define BENCH_ECCSI_PAIRGEN 0x00000040
  655. #define BENCH_ECCSI_VALIDATE 0x00000080
  656. #define BENCH_ECCSI 0x00000400
  657. #define BENCH_SAKKE_KEYGEN 0x10000000
  658. #define BENCH_SAKKE_RSKGEN 0x20000000
  659. #define BENCH_SAKKE_VALIDATE 0x40000000
  660. #define BENCH_SAKKE 0x80000000
  661. /* Post-Quantum Asymmetric algorithms. */
  662. #define BENCH_KYBER512 0x00000020
  663. #define BENCH_KYBER768 0x00000040
  664. #define BENCH_KYBER1024 0x00000080
  665. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  666. BENCH_KYBER1024)
  667. #define BENCH_ML_KEM_512 0x00000020
  668. #define BENCH_ML_KEM_768 0x00000040
  669. #define BENCH_ML_KEM_1024 0x00000080
  670. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  671. BENCH_ML_KEM_1024)
  672. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  673. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  674. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  675. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  676. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  677. #define BENCH_ML_DSA_44_SIGN 0x04000000
  678. #define BENCH_ML_DSA_65_SIGN 0x08000000
  679. #define BENCH_ML_DSA_87_SIGN 0x10000000
  680. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  681. BENCH_ML_DSA_65_SIGN | \
  682. BENCH_ML_DSA_87_SIGN)
  683. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  684. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  685. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  686. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  687. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  688. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  689. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  690. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  691. #define BENCH_LMS_HSS 0x00000001
  692. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  693. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  694. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  695. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  696. #ifndef NO_SHA256
  697. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  698. #elif defined(WOLFSSL_SHA512)
  699. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  700. #elif defined(WOLFSSL_SHAKE128)
  701. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  702. #elif defined(WOLFSSL_SHAKE256)
  703. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  704. #else
  705. #define BENCH_XMSS_XMSSMT 0x00000000
  706. #endif
  707. /* Other */
  708. #define BENCH_RNG 0x00000001
  709. #define BENCH_SCRYPT 0x00000002
  710. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  711. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  712. * static declaration of `bench_Usage_msg1`. */
  713. #if !defined(AES_AUTH_ADD_SZ) && \
  714. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  715. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  716. /* For STM32 use multiple of 4 to leverage crypto hardware
  717. * Xilinx Versal requires to use multiples of 16 bytes */
  718. #define AES_AUTH_ADD_SZ 16
  719. #endif
  720. #ifndef AES_AUTH_ADD_SZ
  721. #define AES_AUTH_ADD_SZ 13
  722. #endif
  723. #endif
  724. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  725. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  726. #define BENCH_PQ_STATEFUL_HBS
  727. #endif
  728. /* Benchmark all compiled in algorithms.
  729. * When 1, ignore other benchmark algorithm values.
  730. * 0, only benchmark algorithm values set.
  731. */
  732. static int bench_all = 1;
  733. /* Cipher algorithms to benchmark. */
  734. static word32 bench_cipher_algs = 0;
  735. /* Digest algorithms to benchmark. */
  736. static word32 bench_digest_algs = 0;
  737. /* MAC algorithms to benchmark. */
  738. static word32 bench_mac_algs = 0;
  739. /* KDF algorithms to benchmark. */
  740. static word32 bench_kdf_algs = 0;
  741. /* Asymmetric algorithms to benchmark. */
  742. static word32 bench_asym_algs = 0;
  743. /* Post-Quantum Asymmetric algorithms to benchmark. */
  744. static word32 bench_pq_asym_algs = 0;
  745. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  746. static word32 bench_pq_asym_algs2 = 0;
  747. /* Other cryptographic algorithms to benchmark. */
  748. static word32 bench_other_algs = 0;
  749. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  750. static word32 bench_pq_hash_sig_algs = 0;
  751. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  752. /* The mapping of command line option to bit values. */
  753. typedef struct bench_alg {
  754. /* Command line option string. */
  755. const char* str;
  756. /* Bit values to set. */
  757. word32 val;
  758. } bench_alg;
  759. #ifndef MAIN_NO_ARGS
  760. /* All recognized cipher algorithm choosing command line options. */
  761. static const bench_alg bench_cipher_opt[] = {
  762. { "-cipher", 0xffffffff },
  763. #ifdef HAVE_AES_CBC
  764. { "-aes-cbc", BENCH_AES_CBC },
  765. #endif
  766. #ifdef HAVE_AESGCM
  767. { "-aes-gcm", BENCH_AES_GCM },
  768. #endif
  769. #ifdef WOLFSSL_AES_DIRECT
  770. { "-aes-ecb", BENCH_AES_ECB },
  771. #endif
  772. #ifdef WOLFSSL_AES_XTS
  773. { "-aes-xts", BENCH_AES_XTS },
  774. #endif
  775. #ifdef WOLFSSL_AES_CFB
  776. { "-aes-cfb", BENCH_AES_CFB },
  777. #endif
  778. #ifdef WOLFSSL_AES_OFB
  779. { "-aes-ofb", BENCH_AES_OFB },
  780. #endif
  781. #ifdef WOLFSSL_AES_COUNTER
  782. { "-aes-ctr", BENCH_AES_CTR },
  783. #endif
  784. #ifdef HAVE_AESCCM
  785. { "-aes-ccm", BENCH_AES_CCM },
  786. #endif
  787. #ifdef WOLFSSL_AES_SIV
  788. { "-aes-siv", BENCH_AES_SIV },
  789. #endif
  790. #ifdef HAVE_CAMELLIA
  791. { "-camellia", BENCH_CAMELLIA },
  792. #endif
  793. #ifndef NO_RC4
  794. { "-arc4", BENCH_ARC4 },
  795. #endif
  796. #ifdef HAVE_CHACHA
  797. { "-chacha20", BENCH_CHACHA20 },
  798. #endif
  799. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  800. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  801. #endif
  802. #ifdef WOLFSSL_SM4_CBC
  803. { "-sm4-cbc", BENCH_SM4_CBC },
  804. #endif
  805. #ifdef WOLFSSL_SM4_GCM
  806. { "-sm4-gcm", BENCH_SM4_GCM },
  807. #endif
  808. #ifdef WOLFSSL_SM4_CCM
  809. { "-sm4-ccm", BENCH_SM4_CCM },
  810. #endif
  811. #ifdef WOLFSSL_SM4
  812. { "-sm4", BENCH_SM4 },
  813. #endif
  814. #ifndef NO_DES3
  815. { "-des", BENCH_DES },
  816. #endif
  817. { NULL, 0 }
  818. };
  819. /* All recognized digest algorithm choosing command line options. */
  820. static const bench_alg bench_digest_opt[] = {
  821. { "-digest", 0xffffffff },
  822. #ifndef NO_MD5
  823. { "-md5", BENCH_MD5 },
  824. #endif
  825. #ifdef HAVE_POLY1305
  826. { "-poly1305", BENCH_POLY1305 },
  827. #endif
  828. #ifndef NO_SHA
  829. { "-sha", BENCH_SHA },
  830. #endif
  831. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  832. || defined(WOLFSSL_SHA512)
  833. { "-sha2", BENCH_SHA2 },
  834. #endif
  835. #ifdef WOLFSSL_SHA224
  836. { "-sha224", BENCH_SHA224 },
  837. #endif
  838. #ifndef NO_SHA256
  839. { "-sha256", BENCH_SHA256 },
  840. #endif
  841. #ifdef WOLFSSL_SHA384
  842. { "-sha384", BENCH_SHA384 },
  843. #endif
  844. #ifdef WOLFSSL_SHA512
  845. { "-sha512", BENCH_SHA512 },
  846. #endif
  847. #ifdef WOLFSSL_SHA3
  848. { "-sha3", BENCH_SHA3 },
  849. #ifndef WOLFSSL_NOSHA3_224
  850. { "-sha3-224", BENCH_SHA3_224 },
  851. #endif
  852. #ifndef WOLFSSL_NOSHA3_256
  853. { "-sha3-256", BENCH_SHA3_256 },
  854. #endif
  855. #ifndef WOLFSSL_NOSHA3_384
  856. { "-sha3-384", BENCH_SHA3_384 },
  857. #endif
  858. #ifndef WOLFSSL_NOSHA3_512
  859. { "-sha3-512", BENCH_SHA3_512 },
  860. #endif
  861. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  862. { "-shake", BENCH_SHAKE },
  863. #endif
  864. #ifdef WOLFSSL_SHAKE128
  865. { "-shake128", BENCH_SHAKE128 },
  866. #endif
  867. #ifdef WOLFSSL_SHAKE256
  868. { "-shake256", BENCH_SHAKE256 },
  869. #endif
  870. #endif
  871. #ifdef WOLFSSL_SM3
  872. { "-sm3", BENCH_SM3 },
  873. #endif
  874. #ifdef WOLFSSL_RIPEMD
  875. { "-ripemd", BENCH_RIPEMD },
  876. #endif
  877. #ifdef HAVE_BLAKE2
  878. { "-blake2b", BENCH_BLAKE2B },
  879. #endif
  880. #ifdef HAVE_BLAKE2S
  881. { "-blake2s", BENCH_BLAKE2S },
  882. #endif
  883. { NULL, 0 }
  884. };
  885. /* All recognized MAC algorithm choosing command line options. */
  886. static const bench_alg bench_mac_opt[] = {
  887. { "-mac", 0xffffffff },
  888. #ifdef WOLFSSL_CMAC
  889. { "-cmac", BENCH_CMAC },
  890. #endif
  891. #ifndef NO_HMAC
  892. { "-hmac", BENCH_HMAC },
  893. #ifndef NO_MD5
  894. { "-hmac-md5", BENCH_HMAC_MD5 },
  895. #endif
  896. #ifndef NO_SHA
  897. { "-hmac-sha", BENCH_HMAC_SHA },
  898. #endif
  899. #ifdef WOLFSSL_SHA224
  900. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  901. #endif
  902. #ifndef NO_SHA256
  903. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  904. #endif
  905. #ifdef WOLFSSL_SHA384
  906. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  907. #endif
  908. #ifdef WOLFSSL_SHA512
  909. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  910. #endif
  911. #ifndef NO_PWDBASED
  912. { "-pbkdf2", BENCH_PBKDF2 },
  913. #endif
  914. #endif
  915. #ifdef WOLFSSL_SIPHASH
  916. { "-siphash", BENCH_SIPHASH },
  917. #endif
  918. { NULL, 0 }
  919. };
  920. /* All recognized KDF algorithm choosing command line options. */
  921. static const bench_alg bench_kdf_opt[] = {
  922. { "-kdf", 0xffffffff },
  923. #ifdef WC_SRTP_KDF
  924. { "-srtp-kdf", BENCH_SRTP_KDF },
  925. #endif
  926. { NULL, 0 }
  927. };
  928. /* All recognized asymmetric algorithm choosing command line options. */
  929. static const bench_alg bench_asym_opt[] = {
  930. { "-asym", 0xffffffff },
  931. #ifndef NO_RSA
  932. #ifdef WOLFSSL_KEY_GEN
  933. { "-rsa-kg", BENCH_RSA_KEYGEN },
  934. #endif
  935. { "-rsa", BENCH_RSA },
  936. #ifdef WOLFSSL_KEY_GEN
  937. { "-rsa-sz", BENCH_RSA_SZ },
  938. #endif
  939. #endif
  940. #ifndef NO_DH
  941. { "-dh", BENCH_DH },
  942. #endif
  943. #ifdef HAVE_ECC
  944. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  945. { "-ecc", BENCH_ECC },
  946. #ifdef HAVE_ECC_ENCRYPT
  947. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  948. #endif
  949. { "-ecc-all", BENCH_ECC_ALL },
  950. #endif
  951. #ifdef WOLFSSL_SM2
  952. { "-sm2", BENCH_SM2 },
  953. #endif
  954. #ifdef HAVE_CURVE25519
  955. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  956. #ifdef HAVE_CURVE25519_SHARED_SECRET
  957. { "-x25519", BENCH_CURVE25519_KA },
  958. #endif
  959. #endif
  960. #ifdef HAVE_ED25519
  961. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  962. { "-ed25519", BENCH_ED25519_SIGN },
  963. #endif
  964. #ifdef HAVE_CURVE448
  965. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  966. #ifdef HAVE_CURVE448_SHARED_SECRET
  967. { "-x448", BENCH_CURVE448_KA },
  968. #endif
  969. #endif
  970. #ifdef HAVE_ED448
  971. { "-ed448-kg", BENCH_ED448_KEYGEN },
  972. { "-ed448", BENCH_ED448_SIGN },
  973. #endif
  974. #ifdef WOLFCRYPT_HAVE_ECCSI
  975. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  976. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  977. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  978. { "-eccsi", BENCH_ECCSI },
  979. #endif
  980. #ifdef WOLFCRYPT_HAVE_SAKKE
  981. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  982. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  983. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  984. { "-sakke", BENCH_SAKKE },
  985. #endif
  986. { NULL, 0 }
  987. };
  988. /* All recognized other cryptographic algorithm choosing command line options.
  989. */
  990. static const bench_alg bench_other_opt[] = {
  991. { "-other", 0xffffffff },
  992. #ifndef WC_NO_RNG
  993. { "-rng", BENCH_RNG },
  994. #endif
  995. #ifdef HAVE_SCRYPT
  996. { "-scrypt", BENCH_SCRYPT },
  997. #endif
  998. { NULL, 0}
  999. };
  1000. #endif /* MAIN_NO_ARGS */
  1001. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1002. #if defined(BENCH_PQ_STATEFUL_HBS)
  1003. typedef struct bench_pq_hash_sig_alg {
  1004. /* Command line option string. */
  1005. const char* str;
  1006. /* Bit values to set. */
  1007. word32 val;
  1008. } bench_pq_hash_sig_alg;
  1009. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1010. { "-pq_hash_sig", 0xffffffff},
  1011. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1012. { "-lms_hss", BENCH_LMS_HSS},
  1013. #endif
  1014. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1015. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1016. #ifdef WC_XMSS_SHA256
  1017. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1018. #endif
  1019. #ifdef WC_XMSS_SHA512
  1020. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1021. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1022. #endif
  1023. #endif
  1024. #ifdef WC_XMSS_SHAKE128
  1025. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1026. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1027. #endif
  1028. #endif
  1029. #ifdef WC_XMSS_SHAKE256
  1030. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1031. #endif
  1032. #endif
  1033. { NULL, 0}
  1034. };
  1035. #endif /* BENCH_PQ_STATEFUL_HBS */
  1036. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1037. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1038. /* The post-quantum-specific mapping of command line option to bit values and
  1039. * OQS name. */
  1040. typedef struct bench_pq_alg {
  1041. /* Command line option string. */
  1042. const char* str;
  1043. /* Bit values to set. */
  1044. word32 val;
  1045. } bench_pq_alg;
  1046. /* All recognized post-quantum asymmetric algorithm choosing command line
  1047. * options. */
  1048. static const bench_pq_alg bench_pq_asym_opt[] = {
  1049. { "-pq", 0xffffffff },
  1050. #ifdef WOLFSSL_HAVE_KYBER
  1051. { "-kyber", BENCH_KYBER },
  1052. { "-kyber512", BENCH_KYBER512 },
  1053. { "-kyber768", BENCH_KYBER768 },
  1054. { "-kyber1024", BENCH_KYBER1024 },
  1055. { "-ml-kem", BENCH_ML_KEM },
  1056. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1057. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1058. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1059. #endif
  1060. #if defined(HAVE_FALCON)
  1061. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1062. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1063. #endif
  1064. #if defined(HAVE_DILITHIUM)
  1065. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1066. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1067. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1068. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1069. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1070. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1071. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1072. #endif
  1073. { NULL, 0 }
  1074. };
  1075. #if defined(HAVE_SPHINCS)
  1076. /* All recognized post-quantum asymmetric algorithm choosing command line
  1077. * options. (Part 2) */
  1078. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1079. { "-pq", 0xffffffff },
  1080. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1081. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1082. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1083. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1084. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1085. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1086. { NULL, 0, }
  1087. };
  1088. #endif /* HAVE_SPHINCS */
  1089. #endif
  1090. #ifdef HAVE_WNR
  1091. const char* wnrConfigFile = "wnr-example.conf";
  1092. #endif
  1093. #if defined(WOLFSSL_MDK_ARM)
  1094. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1095. #define fopen wolfSSL_fopen
  1096. #endif
  1097. static int lng_index = 0;
  1098. #ifndef NO_MAIN_DRIVER
  1099. #ifndef MAIN_NO_ARGS
  1100. static const char* bench_Usage_msg1[][25] = {
  1101. /* 0 English */
  1102. { "-? <num> Help, print this usage\n",
  1103. " 0: English, 1: Japanese\n",
  1104. "-csv Print terminal output in csv format\n",
  1105. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1106. "-no_aad No additional authentication data passed.\n",
  1107. "-aad_size <num> With <num> bytes of AAD.\n",
  1108. ("-all_aad With AAD length of 0, "
  1109. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1110. " and\n"
  1111. " (if set via -aad_size) <aad_size> bytes.\n"
  1112. ),
  1113. "-dgst_full Full digest operation performed.\n",
  1114. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1115. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1116. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1117. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1118. "-p256 Measure ECC using P-256 curve.\n",
  1119. "-p384 Measure ECC using P-384 curve.\n",
  1120. "-p521 Measure ECC using P-521 curve.\n",
  1121. "-ecc-all Bench all enabled ECC curves.\n",
  1122. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1123. ("-lng <num> Display benchmark result by specified language.\n"
  1124. " 0: English, 1: Japanese\n"
  1125. ),
  1126. "<num> Size of block in bytes\n",
  1127. ("-blocks <num> Number of blocks. Can be used together with the "
  1128. "'Size of block'\n"
  1129. " option, but must be used after that one.\n"
  1130. ),
  1131. "-threads <num> Number of threads to run\n",
  1132. "-print Show benchmark stats summary\n",
  1133. "-hash_input <file> Input data to use for hash benchmarking\n",
  1134. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1135. "-min_runs <num> Specify minimum number of operation runs\n"
  1136. },
  1137. #ifndef NO_MULTIBYTE_PRINT
  1138. /* 1 Japanese */
  1139. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1140. " 0: 英語、 1: 日本語\n",
  1141. "-csv csv 形式で端末に出力します。\n",
  1142. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1143. "-no_aad 追加の認証データを使用しません.\n",
  1144. "-aad_size <num> TBD.\n",
  1145. "-all_aad TBD.\n",
  1146. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1147. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1148. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1149. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1150. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1151. "-p256 Measure ECC using P-256 curve.\n",
  1152. "-p384 Measure ECC using P-384 curve.\n",
  1153. "-p521 Measure ECC using P-521 curve.\n",
  1154. "-ecc-all Bench all enabled ECC curves.\n",
  1155. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1156. " 利用可能なアルゴリズムは下記を含みます:\n"
  1157. ),
  1158. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1159. " 0: 英語、 1: 日本語\n"
  1160. ),
  1161. "<num> ブロックサイズをバイト単位で指定します。\n",
  1162. "-blocks <num> TBD.\n",
  1163. "-threads <num> 実行するスレッド数\n",
  1164. "-print ベンチマーク統計の要約を表示する\n",
  1165. /* TODO: translate below */
  1166. "-hash_input <file> Input data to use for hash benchmarking\n",
  1167. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1168. "-min_runs <num> Specify minimum number of operation runs\n"
  1169. },
  1170. #endif
  1171. };
  1172. #endif /* MAIN_NO_ARGS */
  1173. #endif
  1174. static const char* bench_result_words1[][4] = {
  1175. { "took",
  1176. #ifdef BENCH_MICROSECOND
  1177. "microseconds"
  1178. #else
  1179. "seconds"
  1180. #endif
  1181. , "Cycles per byte", NULL }, /* 0 English */
  1182. #ifndef NO_MULTIBYTE_PRINT
  1183. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1184. #endif
  1185. };
  1186. #if !defined(NO_RSA) || \
  1187. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1188. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1189. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1190. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1191. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1192. static const char* bench_desc_words[][15] = {
  1193. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1194. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1195. #ifndef NO_MULTIBYTE_PRINT
  1196. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1197. #endif
  1198. };
  1199. #endif
  1200. #ifdef MULTI_VALUE_STATISTICS
  1201. static const char* bench_result_words3[][5] = {
  1202. /* 0 English */
  1203. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1204. /* TODO: Add japenese version */
  1205. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1206. };
  1207. #endif
  1208. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1209. #define HAVE_GET_CYCLES
  1210. static WC_INLINE word64 get_intel_cycles(void);
  1211. static THREAD_LS_T word64 total_cycles;
  1212. #define INIT_CYCLE_COUNTER
  1213. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1214. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1215. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1216. #define SHOW_INTEL_CYCLES(b, n, s) \
  1217. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1218. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1219. bench_result_words1[lng_index][2], \
  1220. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1221. (double)total_cycles / ((word64)count*(s))))
  1222. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1223. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1224. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1225. (double)total_cycles / ((word64)count*(s))))
  1226. #elif defined(LINUX_CYCLE_COUNT)
  1227. #include <linux/perf_event.h>
  1228. #include <sys/syscall.h>
  1229. #include <unistd.h>
  1230. static THREAD_LS_T word64 begin_cycles;
  1231. static THREAD_LS_T word64 total_cycles;
  1232. static THREAD_LS_T int cycles = -1;
  1233. static THREAD_LS_T struct perf_event_attr atr;
  1234. #define INIT_CYCLE_COUNTER do { \
  1235. atr.type = PERF_TYPE_HARDWARE; \
  1236. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1237. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1238. } while (0);
  1239. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1240. #define END_INTEL_CYCLES do { \
  1241. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1242. total_cycles = total_cycles - begin_cycles; \
  1243. } while (0);
  1244. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1245. #define SHOW_INTEL_CYCLES(b, n, s) \
  1246. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1247. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1248. bench_result_words1[lng_index][2], \
  1249. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1250. (count*s)))
  1251. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1252. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1253. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1254. / (count*s)))
  1255. #elif defined(SYNERGY_CYCLE_COUNT)
  1256. #include "hal_data.h"
  1257. static THREAD_LS_T word64 begin_cycles;
  1258. static THREAD_LS_T word64 total_cycles;
  1259. #define INIT_CYCLE_COUNTER
  1260. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1261. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1262. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1263. #define SHOW_INTEL_CYCLES(b, n, s) \
  1264. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1265. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1266. bench_result_words1[lng_index][2], \
  1267. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1268. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1269. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1270. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1271. #elif defined(WOLFSSL_ESPIDF)
  1272. /* TAG for ESP_LOGx() */
  1273. static const char* TAG = "wolfssl_benchmark";
  1274. static THREAD_LS_T word64 begin_cycles = 0;
  1275. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1276. static THREAD_LS_T word64 end_cycles = 0;
  1277. static THREAD_LS_T word64 total_cycles = 0;
  1278. /* the return value, as a global var */
  1279. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1280. /* the last value seen, adjusted for an overflow, as a global var */
  1281. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1282. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1283. /* esp_get_cpu_benchmark_cycles(void):
  1284. *
  1285. * Architecture-independant CPU clock counter.
  1286. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1287. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1288. /* Some vars for debugging, compare ticks to cycles */
  1289. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1290. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1291. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1292. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1293. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1294. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1295. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1296. #if ESP_IDF_VERSION_MAJOR >= 5
  1297. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1298. #define HAVE_GET_CYCLES
  1299. #define INIT_CYCLE_COUNTER do { \
  1300. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1301. esp_cpu_set_cycle_count(0); \
  1302. } while (0);
  1303. #else
  1304. #define HAVE_GET_CYCLES
  1305. #define INIT_CYCLE_COUNTER do { \
  1306. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1307. } while (0);
  1308. #endif
  1309. #define BEGIN_ESP_CYCLES do { \
  1310. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1311. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1312. begin_cycles_ticks = xTaskGetTickCount(); \
  1313. } while (0);
  1314. /* since it rolls over, we have something that will tolerate one */
  1315. #define END_ESP_CYCLES \
  1316. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1317. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1318. end_cycles, \
  1319. begin_cycles \
  1320. ); \
  1321. total_cycles = (end_cycles - begin_cycles);
  1322. #define SHOW_ESP_CYCLES(b, n, s) \
  1323. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1324. " %s = " FLT_FMT_PREC2 "\n", \
  1325. bench_result_words1[lng_index][2], \
  1326. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1327. )
  1328. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1329. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1330. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1331. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1332. /* 64 bit, unisgned, absolute difference
  1333. * used in CPU cycle counter debug calcs. */
  1334. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1335. {
  1336. uint64_t ret;
  1337. ret = (x > y) ? (x - y) : (y - x);
  1338. return ret;
  1339. }
  1340. #endif
  1341. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1342. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1343. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1344. ** at least once during full benchmark tests.
  1345. **
  1346. ** To test timing overflow, add a delay longer than max cycles:
  1347. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1348. */
  1349. uint64_t esp_get_cycle_count_ex()
  1350. {
  1351. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1352. /* unsigned int max = 4,294,967,295 */
  1353. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1354. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1355. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1356. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1357. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1358. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1359. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1360. #endif
  1361. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1362. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1363. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1364. * (current - last) */
  1365. #endif
  1366. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1367. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1368. defined(CONFIG_IDF_TARGET_ESP32C6)
  1369. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1370. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1371. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1372. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1373. #if ESP_IDF_VERSION_MAJOR >= 5
  1374. thisVal = esp_cpu_get_cycle_count();
  1375. #else
  1376. thisVal = cpu_hal_get_cycle_count();
  1377. #endif
  1378. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1379. thisVal = esp_cpu_get_cycle_count();
  1380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1381. thisVal = esp_timer_get_time();
  1382. #else
  1383. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1384. * Calling current_time(1) to reset time causes thisVal overflow,
  1385. * on Xtensa, but not on RISC-V architecture. See also, below */
  1386. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1387. #ifndef configCPU_CLOCK_HZ
  1388. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1389. #define configCPU_CLOCK_HZ \
  1390. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1391. #endif
  1392. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1393. thisVal = (uint64_t)xTaskGetTickCount() *
  1394. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1395. #elif defined(__XTENSA__)
  1396. thisVal = esp_cpu_get_cycle_count();
  1397. #else
  1398. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1399. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1400. #endif
  1401. #endif
  1402. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1403. {
  1404. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1405. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1406. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1407. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1408. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1409. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1410. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1411. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1412. }
  1413. #endif
  1414. /* If either thisVal is smaller than last (overflow), and/or the
  1415. * expected value calculated from FreeRTOS tick difference that would
  1416. * have never fit into an unsigned 32 bit integer anyhow... then we
  1417. * need to adjust thisVal to save. */
  1418. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1419. {
  1420. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1421. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1422. **
  1423. ** NOTE for long duration between calls with multiple overflows:
  1424. **
  1425. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1426. **
  1427. ** At this time no single test overflows. This is currently only a
  1428. ** concern for cumulative counts over multiple tests. As long
  1429. ** as well call xthal_get_ccount_ex() with no more than one
  1430. ** overflow CPU tick count, all will be well.
  1431. */
  1432. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1433. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1434. "(%llu < %llu) adding UINT_MAX = %llu.",
  1435. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1436. #endif
  1437. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1438. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1439. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1440. #endif
  1441. /* double check expected diff calc */
  1442. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1443. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1444. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1445. * MILLION_VALUE)
  1446. * tickDiff / configTICK_RATE_HZ;
  1447. #else
  1448. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1449. * tickDiff / configTICK_RATE_HZ;
  1450. #endif
  1451. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1452. #endif
  1453. if (expected_diff > UINT_MAX) {
  1454. /* The number of cycles expected from FreeRTOS ticks is
  1455. * greater than the maximum size of an unsigned 32-bit
  1456. * integer, meaning multiple overflows occurred. */
  1457. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1458. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1459. #endif
  1460. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1461. }
  1462. else {
  1463. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1464. }
  1465. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1466. {
  1467. tickBeginDiff = tickCount - begin_cycles_ticks;
  1468. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1469. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1470. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1471. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1472. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1473. }
  1474. #endif
  1475. }
  1476. else {
  1477. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1478. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1479. #endif
  1480. } /* if thisVal adjustment check */
  1481. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1482. if (thisTimerVal < _esp_cpu_timer_last)
  1483. {
  1484. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1485. "adding %ull", UINT_MAX);
  1486. thisTimerVal += (word64)UINT_MAX;
  1487. }
  1488. /* Check an alternate counter using a timer */
  1489. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1490. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1491. /* Adjust our actual returned value that takes into account overflow,
  1492. * increment 64 bit extended total by this 32 bit differential: */
  1493. thisIncrement = (thisVal - _esp_cpu_count_last);
  1494. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1495. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1496. #endif
  1497. /* Add our adjustment, taking into account overflows (see above) */
  1498. _esp_get_cycle_count_ex += thisIncrement;
  1499. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1500. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1501. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1502. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1503. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1504. /* all of this took some time, so reset the "last seen" value
  1505. * for the next measurement. */
  1506. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1507. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1508. defined(CONFIG_IDF_TARGET_ESP32C6)
  1509. {
  1510. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1511. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1512. &_esp_cpu_timer_last));
  1513. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1514. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1515. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1516. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1517. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1518. #if ESP_IDF_VERSION_MAJOR >= 5
  1519. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1520. #else
  1521. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1522. #endif
  1523. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1524. }
  1525. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1526. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1527. #else
  1528. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1529. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1530. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1531. * or thisVal = xthal_get_ccount(); */
  1532. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1533. /* There's no CPU counter on the ESP8266, so we'll estimate
  1534. * cycles based on defined CPU frequency from sdkconfig and
  1535. * the RTOS tick frequency */
  1536. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1537. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1538. #elif ESP_IDF_VERSION_MAJOR < 5
  1539. _esp_cpu_count_last = xthal_get_ccount();
  1540. #else
  1541. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1542. #endif
  1543. #endif
  1544. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1545. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1546. #endif
  1547. /* Return the 64 bit extended total from 32 bit counter. */
  1548. return _esp_get_cycle_count_ex;
  1549. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1550. /* implement other architecture cycle counters here */
  1551. #else
  1552. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1553. #undef HAVE_GET_CYCLES
  1554. #define INIT_CYCLE_COUNTER
  1555. #define BEGIN_INTEL_CYCLES
  1556. #define END_INTEL_CYCLES
  1557. #ifdef MULTI_VALUE_STATISTICS
  1558. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1559. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1560. #else
  1561. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1562. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1563. #endif
  1564. #endif
  1565. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1566. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1567. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1568. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1569. #endif
  1570. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1571. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1572. !defined(NO_DH)
  1573. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1574. #include <wolfssl/certs_test.h>
  1575. #endif
  1576. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1577. #include <wolfssl/wolfcrypt/blake2.h>
  1578. #endif
  1579. #ifdef _MSC_VER
  1580. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1581. #pragma warning(disable: 4996)
  1582. #endif
  1583. #ifdef WOLFSSL_CURRTIME_REMAP
  1584. #define current_time WOLFSSL_CURRTIME_REMAP
  1585. #else
  1586. double current_time(int reset);
  1587. #endif
  1588. #ifdef LINUX_RUSAGE_UTIME
  1589. static void check_for_excessive_stime(const char *desc,
  1590. const char *desc_extra);
  1591. #endif
  1592. #if !defined(WC_NO_RNG) && \
  1593. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1594. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1595. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1596. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1597. || defined(WOLFSSL_HAVE_KYBER))
  1598. #define HAVE_LOCAL_RNG
  1599. static THREAD_LS_T WC_RNG gRng;
  1600. #define GLOBAL_RNG &gRng
  1601. #else
  1602. #define GLOBAL_RNG NULL
  1603. #endif
  1604. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1605. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1606. defined(HAVE_ECC) || !defined(NO_DH) || \
  1607. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1608. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1609. defined(WOLFSSL_HAVE_LMS)
  1610. #define BENCH_ASYM
  1611. #endif
  1612. #if defined(BENCH_ASYM)
  1613. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1614. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1615. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1616. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1617. defined(WOLFSSL_HAVE_LMS)
  1618. static const char* bench_result_words2[][5] = {
  1619. #ifdef BENCH_MICROSECOND
  1620. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1621. for μsec */
  1622. #else
  1623. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1624. #endif
  1625. #ifndef NO_MULTIBYTE_PRINT
  1626. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1627. #endif
  1628. };
  1629. #endif
  1630. #endif
  1631. #ifdef WOLFSSL_CAAM
  1632. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1633. #ifdef WOLFSSL_SECO_CAAM
  1634. #define SECO_MAX_UPDATES 10000
  1635. #define SECO_BENCHMARK_NONCE 0x7777
  1636. #define SECO_KEY_STORE_ID 1
  1637. #endif
  1638. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1639. #else
  1640. #ifdef WC_USE_DEVID
  1641. static THREAD_LS_T int devId = WC_USE_DEVID;
  1642. #else
  1643. static THREAD_LS_T int devId = INVALID_DEVID;
  1644. #endif
  1645. #endif
  1646. /* Asynchronous helper macros */
  1647. #ifdef WC_ENABLE_BENCH_THREADING
  1648. typedef struct ThreadData {
  1649. pthread_t thread_id;
  1650. } ThreadData;
  1651. static ThreadData* g_threadData;
  1652. static volatile int g_threadCount;
  1653. #endif
  1654. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1655. #ifndef NO_HW_BENCH
  1656. #define BENCH_DEVID
  1657. #endif
  1658. #ifndef HAVE_RENESAS_SYNC
  1659. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1660. #else
  1661. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1662. #endif
  1663. #else
  1664. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1665. #endif
  1666. #ifdef WOLFSSL_ASYNC_CRYPT
  1667. static WOLF_EVENT_QUEUE eventQueue;
  1668. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1669. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1670. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1671. int callAgain, int* times, int limit, int* pending)
  1672. {
  1673. int allowNext = 0;
  1674. /* this state can be set from a different thread */
  1675. WOLF_EVENT_STATE state = asyncDev->event.state;
  1676. /* if algo doesn't require calling again then use this flow */
  1677. if (state == WOLF_EVENT_STATE_DONE) {
  1678. if (callAgain) {
  1679. /* needs called again, so allow it and handle completion in
  1680. * bench_async_handle */
  1681. allowNext = 1;
  1682. }
  1683. else {
  1684. *ret = asyncDev->event.ret;
  1685. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1686. (*times)++;
  1687. if (*pending > 0) /* to support case where async blocks */
  1688. (*pending)--;
  1689. if ((*times + *pending) < limit)
  1690. allowNext = 1;
  1691. }
  1692. }
  1693. /* if slot is available and we haven't reached limit, start another */
  1694. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1695. allowNext = 1;
  1696. }
  1697. return allowNext;
  1698. }
  1699. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1700. int callAgain, int* times, int* pending)
  1701. {
  1702. WOLF_EVENT_STATE state = asyncDev->event.state;
  1703. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1704. if (state == WOLF_EVENT_STATE_DONE) {
  1705. *ret = asyncDev->event.ret;
  1706. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1707. (*times)++;
  1708. (*pending)--;
  1709. }
  1710. else {
  1711. (*pending)++;
  1712. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1713. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1714. }
  1715. }
  1716. else if (*ret >= 0) {
  1717. *ret = asyncDev->event.ret;
  1718. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1719. (*times)++;
  1720. if (*pending > 0) /* to support case where async blocks */
  1721. (*pending)--;
  1722. }
  1723. return (*ret >= 0) ? 1 : 0;
  1724. }
  1725. static WC_INLINE int bench_async_poll(int* pending)
  1726. {
  1727. int ret, asyncDone = 0;
  1728. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1729. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1730. if (ret != 0) {
  1731. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1732. return ret;
  1733. }
  1734. if (asyncDone == 0) {
  1735. #ifndef WC_NO_ASYNC_THREADING
  1736. /* give time to other threads */
  1737. wc_AsyncThreadYield();
  1738. #endif
  1739. }
  1740. (void)pending;
  1741. return asyncDone;
  1742. }
  1743. #else
  1744. #define BENCH_MAX_PENDING 1
  1745. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1746. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1747. int callAgain, int* times, int limit, int* pending)
  1748. {
  1749. (void)ret;
  1750. (void)asyncDev;
  1751. (void)callAgain;
  1752. (void)times;
  1753. (void)limit;
  1754. (void)pending;
  1755. return 1;
  1756. }
  1757. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1758. int callAgain, int* times, int* pending)
  1759. {
  1760. (void)asyncDev;
  1761. (void)callAgain;
  1762. (void)pending;
  1763. if (*ret >= 0) {
  1764. /* operation completed */
  1765. (*times)++;
  1766. return 1;
  1767. }
  1768. return 0;
  1769. }
  1770. #define bench_async_poll(p) WC_DO_NOTHING
  1771. #endif /* WOLFSSL_ASYNC_CRYPT */
  1772. /* maximum runtime for each benchmark */
  1773. #ifndef BENCH_MIN_RUNTIME_SEC
  1774. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1775. #endif
  1776. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1777. #define AES_AUTH_TAG_SZ 16
  1778. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1779. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1780. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1781. #if !defined(NO_MAIN_DRIVER)
  1782. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1783. #else
  1784. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1785. #endif
  1786. #endif
  1787. #define AES_AAD_STRING(s) \
  1788. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1789. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1790. enum en_aad_options {
  1791. AAD_SIZE_DEFAULT = 0x1U,
  1792. AAD_SIZE_ZERO = 0x2U,
  1793. AAD_SIZE_CUSTOM = 0x4U,
  1794. };
  1795. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1796. static word32 aes_aad_size = 0;
  1797. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1798. {
  1799. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1800. word32 options = aes_aad_options;
  1801. while(options) {
  1802. if (options & AAD_SIZE_DEFAULT) {
  1803. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1804. options &= ~(word32)AAD_SIZE_DEFAULT;
  1805. }
  1806. else if (options & AAD_SIZE_ZERO) {
  1807. aesAuthAddSz = 0;
  1808. options &= ~(word32)AAD_SIZE_ZERO;
  1809. }
  1810. else if (options & AAD_SIZE_CUSTOM) {
  1811. aesAuthAddSz = aes_aad_size;
  1812. options &= ~(word32)AAD_SIZE_CUSTOM;
  1813. }
  1814. fn(i);
  1815. aesAuthAddSz = aesAuthAddSz_orig;
  1816. }
  1817. }
  1818. #endif
  1819. #ifndef BENCH_CIPHER_ADD
  1820. #define BENCH_CIPHER_ADD 0
  1821. #endif
  1822. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  1823. #warning Large/Unalligned AuthSz could result in errors with /dev/crypto
  1824. #endif
  1825. /* use kB instead of mB for embedded benchmarking */
  1826. #ifdef BENCH_EMBEDDED
  1827. #ifndef BENCH_NTIMES
  1828. #define BENCH_NTIMES 2
  1829. #endif
  1830. #ifndef BENCH_AGREETIMES
  1831. #define BENCH_AGREETIMES 2
  1832. #endif
  1833. enum BenchmarkBounds {
  1834. scryptCnt = 1,
  1835. ntimes = BENCH_NTIMES,
  1836. genTimes = BENCH_MAX_PENDING,
  1837. agreeTimes = BENCH_AGREETIMES
  1838. };
  1839. /* how many kB to test (en/de)cryption */
  1840. #define NUM_BLOCKS 25
  1841. #define BENCH_SIZE (1024uL)
  1842. #else
  1843. #ifndef BENCH_NTIMES
  1844. #define BENCH_NTIMES 100
  1845. #endif
  1846. #ifndef BENCH_AGREETIMES
  1847. #define BENCH_AGREETIMES 100
  1848. #endif
  1849. enum BenchmarkBounds {
  1850. scryptCnt = 10,
  1851. ntimes = BENCH_NTIMES,
  1852. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1853. agreeTimes = BENCH_AGREETIMES
  1854. };
  1855. /* how many megs to test (en/de)cryption */
  1856. #define NUM_BLOCKS 5
  1857. #define BENCH_SIZE (1024*1024uL)
  1858. #endif
  1859. static int numBlocks = NUM_BLOCKS;
  1860. static word32 bench_size = BENCH_SIZE;
  1861. static int base2 = 1;
  1862. static int digest_stream = 1;
  1863. #ifdef HAVE_CHACHA
  1864. static int encrypt_only = 0;
  1865. #endif
  1866. #ifdef HAVE_AES_CBC
  1867. static int cipher_same_buffer = 0;
  1868. #endif
  1869. #ifdef MULTI_VALUE_STATISTICS
  1870. static int minimum_runs = 0;
  1871. #endif
  1872. #ifndef NO_RSA
  1873. /* Don't measure RSA sign/verify by default */
  1874. static int rsa_sign_verify = 0;
  1875. #endif
  1876. #ifndef NO_DH
  1877. /* Use the FFDHE parameters */
  1878. static int use_ffdhe = 0;
  1879. #endif
  1880. /* Don't print out in CSV format by default */
  1881. static int csv_format = 0;
  1882. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1883. /* Versal PLM maybe prints an error message to the same console.
  1884. * In order to not mix those outputs up, sleep a little while
  1885. * before erroring out.
  1886. */
  1887. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1888. #else
  1889. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1890. #endif
  1891. /* globals for cipher tests */
  1892. static THREAD_LS_T byte* bench_plain = NULL;
  1893. static THREAD_LS_T byte* bench_cipher = NULL;
  1894. #ifndef NO_FILESYSTEM
  1895. static THREAD_LS_T char* hash_input = NULL;
  1896. static THREAD_LS_T char* cipher_input = NULL;
  1897. #endif
  1898. static const XGEN_ALIGN byte bench_key_buf[] =
  1899. {
  1900. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1901. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1902. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1903. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1904. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1905. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1906. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1907. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1908. };
  1909. static const XGEN_ALIGN byte bench_iv_buf[] =
  1910. {
  1911. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1912. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1913. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1914. };
  1915. static THREAD_LS_T byte* bench_key = NULL;
  1916. static THREAD_LS_T byte* bench_iv = NULL;
  1917. #ifdef HAVE_RENESAS_SYNC
  1918. static THREAD_LS_T byte* bench_key1 = NULL;
  1919. static THREAD_LS_T byte* bench_key2 = NULL;
  1920. #endif
  1921. #ifdef WOLFSSL_STATIC_MEMORY
  1922. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1923. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1924. #elif defined(BENCH_EMBEDDED)
  1925. static byte gBenchMemory[50000];
  1926. #else
  1927. static byte gBenchMemory[400000];
  1928. #endif
  1929. #endif
  1930. /* This code handles cases with systems where static (non cost) ram variables
  1931. aren't properly initialized with data */
  1932. static void benchmark_static_init(int force)
  1933. {
  1934. static int gBenchStaticInit = 0;
  1935. if (gBenchStaticInit == 0 || force) {
  1936. gBenchStaticInit = 1;
  1937. /* Init static variables */
  1938. numBlocks = NUM_BLOCKS;
  1939. bench_size = BENCH_SIZE;
  1940. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1941. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1942. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1943. aes_aad_size = 0;
  1944. #endif
  1945. base2 = 1;
  1946. digest_stream = 1;
  1947. #ifdef MULTI_VALUE_STATISTICS
  1948. minimum_runs = 0;
  1949. #endif
  1950. bench_all = 1;
  1951. bench_cipher_algs = 0;
  1952. bench_digest_algs = 0;
  1953. bench_mac_algs = 0;
  1954. bench_kdf_algs = 0;
  1955. bench_asym_algs = 0;
  1956. bench_pq_asym_algs = 0;
  1957. bench_other_algs = 0;
  1958. bench_pq_hash_sig_algs = 0;
  1959. csv_format = 0;
  1960. }
  1961. }
  1962. /*****************************************************************************/
  1963. /* Begin Stats Functions */
  1964. /*****************************************************************************/
  1965. typedef enum bench_stat_type {
  1966. BENCH_STAT_ASYM,
  1967. BENCH_STAT_SYM,
  1968. BENCH_STAT_IGNORE,
  1969. } bench_stat_type_t;
  1970. #ifdef WC_BENCH_TRACK_STATS
  1971. static int gPrintStats = 0;
  1972. #ifdef WC_ENABLE_BENCH_THREADING
  1973. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1974. #endif
  1975. #ifndef BENCH_MAX_NAME_SZ
  1976. #define BENCH_MAX_NAME_SZ 24
  1977. #endif
  1978. typedef struct bench_stats {
  1979. struct bench_stats* next;
  1980. struct bench_stats* prev;
  1981. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1982. const char* desc;
  1983. double perfsec;
  1984. int strength;
  1985. int useDeviceID;
  1986. int finishCount;
  1987. bench_stat_type_t type;
  1988. int lastRet;
  1989. const char* perftype;
  1990. } bench_stats_t;
  1991. static bench_stats_t* bench_stats_head;
  1992. static bench_stats_t* bench_stats_tail;
  1993. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1994. const char* algo, int strength, const char* desc, int useDeviceID,
  1995. double perfsec, const char* perftype, int ret)
  1996. {
  1997. bench_stats_t* bstat = NULL;
  1998. #ifdef WC_ENABLE_BENCH_THREADING
  1999. /* protect bench_stats_head and bench_stats_tail access */
  2000. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2001. #endif
  2002. if (algo != NULL) {
  2003. /* locate existing in list */
  2004. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  2005. /* match based on algo, strength and desc */
  2006. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2007. bstat->strength == strength &&
  2008. bstat->desc == desc &&
  2009. bstat->useDeviceID == useDeviceID) {
  2010. break;
  2011. }
  2012. }
  2013. }
  2014. if (bstat == NULL) {
  2015. /* allocate new and put on list */
  2016. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2017. DYNAMIC_TYPE_INFO);
  2018. if (bstat) {
  2019. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2020. /* add to list */
  2021. bstat->next = NULL;
  2022. if (bench_stats_tail == NULL) {
  2023. bench_stats_head = bstat;
  2024. }
  2025. else {
  2026. bench_stats_tail->next = bstat;
  2027. bstat->prev = bench_stats_tail;
  2028. }
  2029. bench_stats_tail = bstat; /* add to the end either way */
  2030. }
  2031. }
  2032. if (bstat) {
  2033. bstat->type = type;
  2034. if (algo != NULL)
  2035. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2036. bstat->strength = strength;
  2037. bstat->desc = desc;
  2038. bstat->useDeviceID = useDeviceID;
  2039. bstat->perfsec += perfsec;
  2040. bstat->finishCount++;
  2041. bstat->perftype = perftype;
  2042. if (bstat->lastRet > ret)
  2043. bstat->lastRet = ret; /* track last error */
  2044. }
  2045. #ifdef WC_ENABLE_BENCH_THREADING
  2046. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2047. #endif
  2048. return bstat;
  2049. }
  2050. void bench_stats_print(void)
  2051. {
  2052. bench_stats_t* bstat;
  2053. int digits;
  2054. #ifdef WC_ENABLE_BENCH_THREADING
  2055. /* protect bench_stats_head and bench_stats_tail access */
  2056. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2057. #endif
  2058. #ifdef BENCH_MICROSECOND
  2059. digits = 5;
  2060. #else
  2061. digits = 3;
  2062. #endif
  2063. for (bstat = bench_stats_head; bstat != NULL; ) {
  2064. if (bstat->type == BENCH_STAT_SYM) {
  2065. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2066. "\n", bstat->desc,
  2067. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2068. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2069. base2 ? "MB" : "mB");
  2070. }
  2071. else {
  2072. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2073. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2074. bstat->algo, bstat->strength, bstat->desc,
  2075. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2076. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2077. }
  2078. bstat = bstat->next;
  2079. }
  2080. #ifdef WC_ENABLE_BENCH_THREADING
  2081. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2082. #endif
  2083. }
  2084. #endif /* WC_BENCH_TRACK_STATS */
  2085. static WC_INLINE void bench_stats_init(void)
  2086. {
  2087. #ifdef WC_BENCH_TRACK_STATS
  2088. bench_stats_head = NULL;
  2089. bench_stats_tail = NULL;
  2090. #endif
  2091. INIT_CYCLE_COUNTER
  2092. }
  2093. static WC_INLINE void bench_stats_start(int* count, double* start)
  2094. {
  2095. *count = 0;
  2096. *start = current_time(1);
  2097. #ifdef WOLFSSL_ESPIDF
  2098. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2099. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2100. ", start=" FLT_FMT,
  2101. total_cycles, FLT_FMT_ARGS(*start) );
  2102. #endif
  2103. BEGIN_ESP_CYCLES
  2104. #else
  2105. BEGIN_INTEL_CYCLES
  2106. #endif
  2107. }
  2108. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2109. #define bench_stats_start(count, start) do { \
  2110. SAVE_VECTOR_REGISTERS(pr_err( \
  2111. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2112. return; ); \
  2113. bench_stats_start(count, start); \
  2114. } while (0)
  2115. #endif
  2116. static WC_INLINE int bench_stats_check(double start)
  2117. {
  2118. int ret = 0;
  2119. double this_current_time = 0.0;
  2120. this_current_time = current_time(0); /* get the timestamp, no reset */
  2121. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2122. #if defined(WOLFSSL_ESPIDF)
  2123. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2124. this_current_time, start );
  2125. #endif
  2126. #endif
  2127. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2128. #ifdef BENCH_MICROSECOND
  2129. * 1000000
  2130. #endif
  2131. );
  2132. return ret;
  2133. }
  2134. /* return text for units and scale the value of blocks as needed */
  2135. static const char* get_blocktype(double* blocks)
  2136. {
  2137. const char* rt;
  2138. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2139. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2140. #undef WOLFSSL_FIXED_UNIT
  2141. #define WOLFSSL_FIXED_UNIT "GB"
  2142. *blocks /= (1024UL * 1024UL * 1024UL);
  2143. rt = "GiB";
  2144. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2145. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2146. #undef WOLFSSL_FIXED_UNIT
  2147. #define WOLFSSL_FIXED_UNIT "MB"
  2148. *blocks /= (1024UL * 1024UL);
  2149. rt = "MiB";
  2150. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2151. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2152. #undef WOLFSSL_FIXED_UNIT
  2153. #define WOLFSSL_FIXED_UNIT "KB"
  2154. *blocks /= 1024;
  2155. rt = "KiB";
  2156. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2157. #undef WOLFSSL_FIXED_UNIT
  2158. #define WOLFSSL_FIXED_UNIT "bytes"
  2159. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2160. rt = "bytes";
  2161. #else
  2162. /* If no user-specified, auto-scale each metric (results vary).
  2163. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2164. if (*blocks > (1024UL * 1024UL)) {
  2165. *blocks /= (1024UL * 1024UL);
  2166. rt = "MiB";
  2167. }
  2168. else if (*blocks > 1024) {
  2169. *blocks /= 1024;
  2170. rt = "KiB";
  2171. }
  2172. else {
  2173. rt = "bytes";
  2174. }
  2175. #endif
  2176. return rt;
  2177. }
  2178. /* return text for units and scale the value of blocks as needed for base2 */
  2179. static const char* get_blocktype_base10(double* blocks)
  2180. {
  2181. const char* rt;
  2182. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2183. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2184. *blocks /= (1000UL * 1000UL * 1000UL);
  2185. rt = "GB";
  2186. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2187. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2188. *blocks /= (1000UL * 1000UL);
  2189. rt = "MB";
  2190. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2191. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2192. *blocks /= (1000UL);
  2193. rt = "KB";
  2194. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2195. (void)(*blocks); /* no adjustment, just appease compiler */
  2196. rt = "bytes";
  2197. #else
  2198. /* If not user-specified, auto-scale each metric (results vary).
  2199. * Determine if we should show as KB or MB or bytes */
  2200. if (*blocks > (1000UL * 1000UL)) {
  2201. *blocks /= (1000UL * 1000UL);
  2202. rt = "MB";
  2203. }
  2204. else if (*blocks > 1000) {
  2205. *blocks /= 1000; /* make KB */
  2206. rt = "KB";
  2207. }
  2208. else {
  2209. rt = "bytes";
  2210. }
  2211. #endif
  2212. return rt;
  2213. }
  2214. #ifdef MULTI_VALUE_STATISTICS
  2215. static double wc_sqroot(double in)
  2216. {
  2217. /* do 32 iterations for the sqroot */
  2218. int iter = 32;
  2219. double root = in/3.0;
  2220. if (in < 0.0)
  2221. return -1;
  2222. for (int i=0; i < iter; i++)
  2223. root = (root + in / root) / 2.0;
  2224. return root;
  2225. }
  2226. static void bench_multi_value_stats(double max, double min, double sum,
  2227. double squareSum, int runs)
  2228. {
  2229. double mean = 0;
  2230. double sd = 0;
  2231. char msg[WC_BENCH_MAX_LINE_LEN];
  2232. const char** word = bench_result_words3[lng_index];
  2233. XMEMSET(msg, 0, sizeof(msg));
  2234. mean = sum / runs;
  2235. /* Calculating standard deviation */
  2236. sd = (squareSum / runs) - (mean * mean);
  2237. sd = wc_sqroot(sd);
  2238. if (csv_format == 1) {
  2239. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2240. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2241. FLT_FMT_PREC2_ARGS(3, 3, max),
  2242. FLT_FMT_PREC2_ARGS(3, 3, min),
  2243. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2244. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2245. }
  2246. else{
  2247. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2248. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2249. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2250. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2251. WOLFSSL_FIXED_TIME_UNIT "\n",
  2252. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2253. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2254. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2255. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2256. }
  2257. printf("%s", msg);
  2258. #ifndef WOLFSSL_SGX
  2259. XFFLUSH(stdout);
  2260. #endif
  2261. }
  2262. #endif
  2263. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2264. * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */
  2265. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2266. int count, word32 countSz,
  2267. double start, int ret)
  2268. {
  2269. double total, persec = 0, blocks = (double)count;
  2270. const char* blockType;
  2271. char msg[WC_BENCH_MAX_LINE_LEN];
  2272. const char** word = bench_result_words1[lng_index];
  2273. static int sym_header_printed = 0;
  2274. XMEMSET(msg, 0, sizeof(msg));
  2275. #ifdef WOLFSSL_ESPIDF
  2276. END_ESP_CYCLES
  2277. #else
  2278. END_INTEL_CYCLES
  2279. #endif
  2280. total = current_time(0) - start;
  2281. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2282. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2283. #endif
  2284. #ifdef LINUX_RUSAGE_UTIME
  2285. check_for_excessive_stime(desc, "");
  2286. #endif
  2287. /* calculate actual bytes */
  2288. blocks *= countSz;
  2289. if (csv_format == 1) {
  2290. /* only print out header once */
  2291. if (sym_header_printed == 0) {
  2292. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2293. /* machine parseable CSV */
  2294. #ifdef HAVE_GET_CYCLES
  2295. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2296. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2297. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2298. ",cycles_total,Cycles per byte,");
  2299. #else
  2300. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2301. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2302. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2303. ",cycles_total,");
  2304. #endif
  2305. #else
  2306. /* normal CSV */
  2307. #ifdef BENCH_DEVID
  2308. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2309. #else
  2310. #define BENCH_DEVID_COLUMN_HEADER
  2311. #endif
  2312. #ifdef HAVE_GET_CYCLES
  2313. printf("\n\nSymmetric Ciphers:\n\n");
  2314. printf("Algorithm,"
  2315. BENCH_DEVID_COLUMN_HEADER
  2316. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2317. ",Cycles per byte,");
  2318. #else
  2319. printf("\n\nSymmetric Ciphers:\n\n");
  2320. printf("Algorithm,"
  2321. BENCH_DEVID_COLUMN_HEADER
  2322. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2323. #endif
  2324. #endif
  2325. #ifdef MULTI_VALUE_STATISTICS
  2326. printf("max duration,min duration,mean duration,sd,\n");
  2327. #else
  2328. printf("\n");
  2329. #endif
  2330. sym_header_printed = 1;
  2331. }
  2332. }
  2333. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2334. * note that the blockType text is assigned AND the blocks param is scaled.
  2335. */
  2336. if (base2) {
  2337. blockType = get_blocktype(&blocks);
  2338. }
  2339. else {
  2340. blockType = get_blocktype_base10(&blocks);
  2341. }
  2342. /* calculate blocks per second */
  2343. if (total > 0) {
  2344. persec = (1 / total) * blocks;
  2345. }
  2346. SLEEP_ON_ERROR(ret);
  2347. /* format and print to terminal */
  2348. if (csv_format == 1) {
  2349. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2350. #ifdef WOLFSSL_ESPIDF
  2351. unsigned long bytes_processed =
  2352. (unsigned long)count * (unsigned long)countSz;
  2353. #else
  2354. word64 bytes_processed = (word64)count * (word64)countSz;
  2355. #endif
  2356. /* note this codepath brings in all the fields from the non-CSV case. */
  2357. #ifdef WOLFSSL_ESPIDF
  2358. #ifdef HAVE_GET_CYCLES
  2359. (void)XSNPRINTF(msg, sizeof(msg),
  2360. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2361. BENCH_DEVID_GET_NAME(useDeviceID),
  2362. bytes_processed, FLT_FMT_ARGS(total),
  2363. FLT_FMT_ARGS(persec),
  2364. (long unsigned int) total_cycles);
  2365. #else
  2366. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2367. #endif
  2368. /* implement other architectures here */
  2369. #else
  2370. #ifdef HAVE_GET_CYCLES
  2371. (void)XSNPRINTF(msg, sizeof(msg),
  2372. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2373. BENCH_DEVID_GET_NAME(useDeviceID),
  2374. bytes_processed, FLT_FMT_ARGS(total),
  2375. FLT_FMT_ARGS(persec), total_cycles);
  2376. #else
  2377. (void)XSNPRINTF(msg, sizeof(msg),
  2378. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2379. BENCH_DEVID_GET_NAME(useDeviceID),
  2380. bytes_processed, FLT_FMT_ARGS(total),
  2381. FLT_FMT_ARGS(persec));
  2382. #endif
  2383. #endif
  2384. #elif defined(BENCH_DEVID)
  2385. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2386. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2387. #else
  2388. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2389. FLT_FMT_ARGS(persec));
  2390. #endif
  2391. #ifdef WOLFSSL_ESPIDF
  2392. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2393. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2394. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2395. total_cycles);
  2396. #endif
  2397. /* implement other cycle counters here */
  2398. #else
  2399. /* the default cycle counter is Intel */
  2400. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2401. #endif
  2402. } /* if (csv_format == 1) */
  2403. else {
  2404. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2405. #ifdef HAVE_GET_CYCLES
  2406. (void)XSNPRINTF(msg, sizeof(msg),
  2407. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2408. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2409. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2410. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2411. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2412. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2413. (unsigned long) total_cycles);
  2414. #else
  2415. (void)XSNPRINTF(msg, sizeof(msg),
  2416. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2417. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2418. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2419. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2420. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2421. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2422. #endif /* HAVE_GET_CYCLES */
  2423. #else
  2424. (void)XSNPRINTF(msg, sizeof(msg),
  2425. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2426. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2427. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2428. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2429. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2430. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2431. #endif
  2432. #ifdef WOLFSSL_ESPIDF
  2433. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2434. /* implement other architecture cycle counters here */
  2435. #else
  2436. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2437. #endif
  2438. } /* not CSV format */
  2439. printf("%s", msg);
  2440. /* show errors */
  2441. if (ret < 0) {
  2442. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2443. }
  2444. #ifndef WOLFSSL_SGX
  2445. XFFLUSH(stdout);
  2446. #endif
  2447. #ifdef WC_BENCH_TRACK_STATS
  2448. /* Add to thread stats */
  2449. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2450. blockType, ret);
  2451. #endif
  2452. (void)useDeviceID;
  2453. (void)ret;
  2454. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2455. RESTORE_VECTOR_REGISTERS();
  2456. #endif
  2457. TEST_SLEEP();
  2458. } /* bench_stats_sym_finish */
  2459. #ifdef BENCH_ASYM
  2460. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2461. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2462. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2463. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  2464. defined(WOLFSSL_HAVE_LMS)
  2465. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2466. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2467. double start, int ret)
  2468. {
  2469. double total, each = 0, opsSec, milliEach;
  2470. const char **word = bench_result_words2[lng_index];
  2471. #ifdef WC_BENCH_TRACK_STATS
  2472. const char* kOpsSec = "Ops/Sec";
  2473. #endif
  2474. char msg[256];
  2475. static int asym_header_printed = 0;
  2476. #ifdef BENCH_MICROSECOND
  2477. const int digits = 5;
  2478. #else
  2479. const int digits = 3;
  2480. #endif
  2481. XMEMSET(msg, 0, sizeof(msg));
  2482. total = current_time(0) - start;
  2483. #ifdef LINUX_RUSAGE_UTIME
  2484. check_for_excessive_stime(desc, desc_extra);
  2485. #endif
  2486. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2487. #ifdef WOLFSSL_ESPIDF
  2488. END_ESP_CYCLES
  2489. #else
  2490. END_INTEL_CYCLES
  2491. #endif
  2492. #endif
  2493. /* some sanity checks on the final numbers */
  2494. if (count > 0) {
  2495. each = total / count; /* per second */
  2496. }
  2497. else {
  2498. count = 0;
  2499. each = 0;
  2500. }
  2501. if (total > 0) {
  2502. opsSec = count / total; /* ops second */
  2503. }
  2504. else {
  2505. opsSec = 0;
  2506. }
  2507. #ifdef BENCH_MICROSECOND
  2508. milliEach = each / 1000; /* milliseconds */
  2509. #else
  2510. milliEach = each * 1000; /* milliseconds */
  2511. #endif
  2512. SLEEP_ON_ERROR(ret);
  2513. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2514. (void)milliEach;
  2515. /* format and print to terminal */
  2516. if (csv_format == 1) {
  2517. /* only print out header once */
  2518. if (asym_header_printed == 0) {
  2519. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2520. #ifdef HAVE_GET_CYCLES
  2521. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2522. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2523. "ecs,cycles,cycles/op,");
  2524. #else
  2525. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2526. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2527. "ecs,");
  2528. #endif
  2529. #else
  2530. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2531. printf("%sAlgorithm,key size,operation,ops/"
  2532. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2533. #endif
  2534. printf("max duration,min duration,mean duration,sd,\n");
  2535. asym_header_printed = 1;
  2536. }
  2537. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2538. #ifdef HAVE_GET_CYCLES
  2539. (void)XSNPRINTF(msg, sizeof(msg),
  2540. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2541. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2542. algo, strength, desc, desc_extra,
  2543. FLT_FMT_PREC_ARGS(digits, opsSec),
  2544. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2545. FLT_FMT_PREC_ARGS(6,
  2546. (double)total_cycles / (double)count));
  2547. #else
  2548. (void)XSNPRINTF(msg, sizeof(msg),
  2549. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2550. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2551. algo, strength, desc, desc_extra,
  2552. FLT_FMT_PREC_ARGS(digits, opsSec),
  2553. count, FLT_FMT_ARGS(total));
  2554. #endif
  2555. #else
  2556. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2557. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2558. algo, strength, desc, desc_extra,
  2559. FLT_FMT_PREC_ARGS(digits, opsSec));
  2560. #endif
  2561. } /* if (csv_format == 1) */
  2562. else {
  2563. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2564. #ifdef HAVE_GET_CYCLES
  2565. (void)XSNPRINTF(msg, sizeof(msg),
  2566. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2567. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2568. algo, strength, desc, desc_extra,
  2569. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2570. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2571. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2572. (unsigned long)total_cycles);
  2573. #else
  2574. (void)XSNPRINTF(msg, sizeof(msg),
  2575. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2576. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2577. algo, strength, desc, desc_extra,
  2578. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2579. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2580. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2581. #endif /* HAVE_GET_CYCLES */
  2582. #else
  2583. (void)XSNPRINTF(msg, sizeof(msg),
  2584. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2585. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2586. algo, strength, desc, desc_extra,
  2587. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2588. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2589. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2590. #endif
  2591. }
  2592. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2593. /* format and print to terminal */
  2594. if (csv_format == 1) {
  2595. /* only print out header once */
  2596. if (asym_header_printed == 0) {
  2597. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2598. #ifdef HAVE_GET_CYCLES
  2599. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2600. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2601. "ecs,cycles,cycles/op,");
  2602. #else
  2603. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2604. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2605. "ecs,");
  2606. #endif
  2607. #else
  2608. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2609. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2610. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2611. #endif
  2612. printf("\n");
  2613. asym_header_printed = 1;
  2614. }
  2615. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2616. #ifdef HAVE_GET_CYCLES
  2617. (void)XSNPRINTF(msg, sizeof(msg),
  2618. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2619. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2620. algo, strength, desc, desc_extra,
  2621. FLT_FMT_PREC_ARGS(3, milliEach),
  2622. FLT_FMT_PREC_ARGS(digits, opsSec),
  2623. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2624. FLT_FMT_PREC_ARGS(6,
  2625. (double)total_cycles / (double)count));
  2626. #else
  2627. (void)XSNPRINTF(msg, sizeof(msg),
  2628. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2629. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2630. algo, strength, desc, desc_extra,
  2631. FLT_FMT_PREC_ARGS(3, milliEach),
  2632. FLT_FMT_PREC_ARGS(digits, opsSec),
  2633. count, FLT_FMT_ARGS(total));
  2634. #endif
  2635. #else
  2636. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2637. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2638. algo, strength, desc, desc_extra,
  2639. FLT_FMT_PREC_ARGS(3, milliEach),
  2640. FLT_FMT_PREC_ARGS(digits, opsSec));
  2641. #endif
  2642. } /* if (csv_format == 1) */
  2643. else {
  2644. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2645. #ifdef HAVE_GET_CYCLES
  2646. (void)XSNPRINTF(msg, sizeof(msg),
  2647. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2648. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2649. STATS_CLAUSE_SEPARATOR,
  2650. algo, strength, desc, desc_extra,
  2651. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2652. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2653. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2654. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2655. (unsigned long)total_cycles);
  2656. #else
  2657. (void)XSNPRINTF(msg, sizeof(msg),
  2658. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2659. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2660. STATS_CLAUSE_SEPARATOR,
  2661. algo, strength, desc, desc_extra,
  2662. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2663. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2664. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2665. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2666. #endif /* HAVE_GET_CYCLES */
  2667. #else
  2668. (void)XSNPRINTF(msg, sizeof(msg),
  2669. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2670. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2671. STATS_CLAUSE_SEPARATOR,
  2672. algo, strength, desc, desc_extra,
  2673. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2674. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2675. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2676. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2677. #endif
  2678. }
  2679. #endif /* MULTI_VALUE_STATISTICS */
  2680. printf("%s", msg);
  2681. /* show errors */
  2682. if (ret < 0) {
  2683. printf("%sBenchmark %s %s %d failed: %d\n",
  2684. err_prefix, algo, desc, strength, ret);
  2685. }
  2686. #ifndef WOLFSSL_SGX
  2687. XFFLUSH(stdout);
  2688. #endif
  2689. #ifdef WC_BENCH_TRACK_STATS
  2690. /* Add to thread stats */
  2691. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2692. kOpsSec, ret);
  2693. #endif
  2694. (void)useDeviceID;
  2695. (void)ret;
  2696. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2697. RESTORE_VECTOR_REGISTERS();
  2698. #endif
  2699. TEST_SLEEP();
  2700. } /* bench_stats_asym_finish_ex */
  2701. static void bench_stats_asym_finish(const char* algo, int strength,
  2702. const char* desc, int useDeviceID, int count, double start, int ret)
  2703. {
  2704. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2705. start, ret);
  2706. }
  2707. #endif
  2708. #endif /* BENCH_ASYM */
  2709. static WC_INLINE void bench_stats_free(void)
  2710. {
  2711. #ifdef WC_BENCH_TRACK_STATS
  2712. bench_stats_t* bstat;
  2713. for (bstat = bench_stats_head; bstat != NULL; ) {
  2714. bench_stats_t* next = bstat->next;
  2715. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2716. bstat = next;
  2717. }
  2718. bench_stats_head = NULL;
  2719. bench_stats_tail = NULL;
  2720. #endif
  2721. }
  2722. /*****************************************************************************/
  2723. /* End Stats Functions */
  2724. /*****************************************************************************/
  2725. static void* benchmarks_do(void* args)
  2726. {
  2727. long bench_buf_size;
  2728. #ifdef WOLFSSL_ASYNC_CRYPT
  2729. #ifndef WC_NO_ASYNC_THREADING
  2730. ThreadData* threadData = (ThreadData*)args;
  2731. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2732. #else
  2733. if (wolfAsync_DevOpen(&devId) < 0)
  2734. #endif
  2735. {
  2736. printf("%sAsync device open failed\n%sRunning without async\n",
  2737. err_prefix, err_prefix);
  2738. }
  2739. #endif /* WOLFSSL_ASYNC_CRYPT */
  2740. (void)args;
  2741. #ifdef WOLFSSL_ASYNC_CRYPT
  2742. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2743. printf("%sAsync event queue init failure!\n", err_prefix);
  2744. }
  2745. #endif
  2746. #ifdef WOLF_CRYPTO_CB
  2747. #ifdef HAVE_INTEL_QA_SYNC
  2748. devId = wc_CryptoCb_InitIntelQa();
  2749. if (devId == INVALID_DEVID) {
  2750. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2751. }
  2752. #endif
  2753. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2754. devId = wc_CryptoCb_InitOcteon();
  2755. if (devId == INVALID_DEVID) {
  2756. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2757. }
  2758. #endif
  2759. #ifdef HAVE_RENESAS_SYNC
  2760. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2761. if (devId == INVALID_DEVID) {
  2762. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2763. }
  2764. #endif
  2765. #endif
  2766. #if defined(HAVE_LOCAL_RNG)
  2767. {
  2768. int rngRet;
  2769. #ifndef HAVE_FIPS
  2770. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2771. #else
  2772. rngRet = wc_InitRng(&gRng);
  2773. #endif
  2774. if (rngRet < 0) {
  2775. printf("%sInitRNG failed\n", err_prefix);
  2776. return NULL;
  2777. }
  2778. }
  2779. #endif
  2780. /* setup bench plain, cipher, key and iv globals */
  2781. /* make sure bench buffer is multiple of 16 (AES block size) */
  2782. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2783. if (bench_buf_size % 16)
  2784. bench_buf_size += 16 - (bench_buf_size % 16);
  2785. #ifdef WOLFSSL_AFALG_XILINX_AES
  2786. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2787. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2788. #else
  2789. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2790. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2791. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2792. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2793. #endif
  2794. if (bench_plain == NULL || bench_cipher == NULL) {
  2795. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2796. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2797. bench_plain = bench_cipher = NULL;
  2798. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2799. goto exit;
  2800. }
  2801. #ifndef NO_FILESYSTEM
  2802. if (hash_input) {
  2803. size_t rawSz;
  2804. XFILE file;
  2805. file = XFOPEN(hash_input, "rb");
  2806. if (file == XBADFILE)
  2807. goto exit;
  2808. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2809. XFCLOSE(file);
  2810. goto exit;
  2811. }
  2812. bench_buf_size = XFTELL(file);
  2813. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2814. XFCLOSE(file);
  2815. goto exit;
  2816. }
  2817. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2818. rawSz = (size_t)bench_buf_size;
  2819. if (bench_buf_size % 16)
  2820. bench_buf_size += 16 - (bench_buf_size % 16);
  2821. bench_size = (word32)bench_buf_size;
  2822. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2823. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2824. if (bench_plain == NULL) {
  2825. XFCLOSE(file);
  2826. goto exit;
  2827. }
  2828. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2829. != rawSz) {
  2830. XFCLOSE(file);
  2831. goto exit;
  2832. }
  2833. XFCLOSE(file);
  2834. }
  2835. else {
  2836. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2837. }
  2838. if (cipher_input) {
  2839. size_t rawSz;
  2840. XFILE file;
  2841. file = XFOPEN(cipher_input, "rb");
  2842. if (file == XBADFILE)
  2843. goto exit;
  2844. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2845. XFCLOSE(file);
  2846. goto exit;
  2847. }
  2848. bench_buf_size = XFTELL(file);
  2849. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2850. XFCLOSE(file);
  2851. goto exit;
  2852. }
  2853. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2854. rawSz = (size_t)bench_buf_size;
  2855. if (bench_buf_size % 16)
  2856. bench_buf_size += 16 - (bench_buf_size % 16);
  2857. if (bench_size > (word32)bench_buf_size)
  2858. bench_size = (word32)bench_buf_size;
  2859. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2860. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2861. if (bench_cipher == NULL) {
  2862. XFCLOSE(file);
  2863. goto exit;
  2864. }
  2865. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2866. != rawSz) {
  2867. XFCLOSE(file);
  2868. goto exit;
  2869. }
  2870. XFCLOSE(file);
  2871. }
  2872. else {
  2873. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2874. }
  2875. #endif
  2876. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2877. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2878. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2879. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2880. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2881. if (bench_key == NULL || bench_iv == NULL) {
  2882. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2883. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2884. bench_key = bench_iv = NULL;
  2885. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2886. goto exit;
  2887. }
  2888. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2889. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2890. #elif defined(HAVE_RENESAS_SYNC)
  2891. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2892. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2893. bench_key = (byte*)bench_key_buf;
  2894. bench_iv = (byte*)bench_iv_buf;
  2895. #else
  2896. bench_key = (byte*)bench_key_buf;
  2897. bench_iv = (byte*)bench_iv_buf;
  2898. #endif
  2899. #ifndef WC_NO_RNG
  2900. if (bench_all || (bench_other_algs & BENCH_RNG))
  2901. bench_rng();
  2902. #endif /* WC_NO_RNG */
  2903. #ifndef NO_AES
  2904. #ifdef HAVE_AES_CBC
  2905. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2906. #ifndef NO_SW_BENCH
  2907. bench_aescbc(0);
  2908. #endif
  2909. #if defined(BENCH_DEVID)
  2910. bench_aescbc(1);
  2911. #endif
  2912. }
  2913. #endif
  2914. #ifdef HAVE_AESGCM
  2915. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2916. #ifndef NO_SW_BENCH
  2917. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2918. #endif
  2919. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2920. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2921. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2922. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2923. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2924. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2925. #endif
  2926. #ifndef NO_SW_BENCH
  2927. bench_gmac(0);
  2928. #endif
  2929. #if defined(BENCH_DEVID)
  2930. bench_gmac(1);
  2931. #endif
  2932. }
  2933. #endif
  2934. #ifdef HAVE_AES_ECB
  2935. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2936. #ifndef NO_SW_BENCH
  2937. bench_aesecb(0);
  2938. #endif
  2939. #ifdef BENCH_DEVID
  2940. bench_aesecb(1);
  2941. #endif
  2942. }
  2943. #endif
  2944. #ifdef WOLFSSL_AES_XTS
  2945. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2946. bench_aesxts();
  2947. #endif
  2948. #ifdef WOLFSSL_AES_CFB
  2949. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2950. bench_aescfb();
  2951. #endif
  2952. #ifdef WOLFSSL_AES_OFB
  2953. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2954. bench_aesofb();
  2955. #endif
  2956. #ifdef WOLFSSL_AES_COUNTER
  2957. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2958. bench_aesctr(0);
  2959. #ifdef BENCH_DEVID
  2960. bench_aesctr(1);
  2961. #endif
  2962. }
  2963. #endif
  2964. #ifdef HAVE_AESCCM
  2965. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2966. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2967. #ifdef BENCH_DEVID
  2968. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2969. #endif
  2970. }
  2971. #endif
  2972. #ifdef WOLFSSL_AES_SIV
  2973. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2974. bench_aessiv();
  2975. #endif
  2976. #endif /* !NO_AES */
  2977. #ifdef HAVE_CAMELLIA
  2978. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2979. bench_camellia();
  2980. #endif
  2981. #ifdef WOLFSSL_SM4_CBC
  2982. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2983. bench_sm4_cbc();
  2984. #endif
  2985. #ifdef WOLFSSL_SM4_GCM
  2986. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2987. bench_sm4_gcm();
  2988. #endif
  2989. #ifdef WOLFSSL_SM4_CCM
  2990. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2991. bench_sm4_ccm();
  2992. #endif
  2993. #ifndef NO_RC4
  2994. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2995. #ifndef NO_SW_BENCH
  2996. bench_arc4(0);
  2997. #endif
  2998. #ifdef BENCH_DEVID
  2999. bench_arc4(1);
  3000. #endif
  3001. }
  3002. #endif
  3003. #ifdef HAVE_CHACHA
  3004. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  3005. bench_chacha();
  3006. #endif
  3007. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3008. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3009. bench_chacha20_poly1305_aead();
  3010. #endif
  3011. #ifndef NO_DES3
  3012. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3013. #ifndef NO_SW_BENCH
  3014. bench_des(0);
  3015. #endif
  3016. #ifdef BENCH_DEVID
  3017. bench_des(1);
  3018. #endif
  3019. }
  3020. #endif
  3021. #ifndef NO_MD5
  3022. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3023. #ifndef NO_SW_BENCH
  3024. bench_md5(0);
  3025. #endif
  3026. #ifdef BENCH_DEVID
  3027. bench_md5(1);
  3028. #endif
  3029. }
  3030. #endif
  3031. #ifdef HAVE_POLY1305
  3032. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3033. bench_poly1305();
  3034. #endif
  3035. #ifndef NO_SHA
  3036. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3037. #ifndef NO_SW_BENCH
  3038. bench_sha(0);
  3039. #endif
  3040. #ifdef BENCH_DEVID
  3041. bench_sha(1);
  3042. #endif
  3043. }
  3044. #endif
  3045. #ifdef WOLFSSL_SHA224
  3046. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3047. #ifndef NO_SW_BENCH
  3048. bench_sha224(0);
  3049. #endif
  3050. #ifdef BENCH_DEVID
  3051. bench_sha224(1);
  3052. #endif
  3053. }
  3054. #endif
  3055. #ifndef NO_SHA256
  3056. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3057. #ifndef NO_SW_BENCH
  3058. bench_sha256(0);
  3059. #endif
  3060. #ifdef BENCH_DEVID
  3061. bench_sha256(1);
  3062. #endif
  3063. }
  3064. #endif
  3065. #ifdef WOLFSSL_SHA384
  3066. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3067. #ifndef NO_SW_BENCH
  3068. bench_sha384(0);
  3069. #endif
  3070. #ifdef BENCH_DEVID
  3071. bench_sha384(1);
  3072. #endif
  3073. }
  3074. #endif
  3075. #ifdef WOLFSSL_SHA512
  3076. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3077. #ifndef NO_SW_BENCH
  3078. bench_sha512(0);
  3079. #endif
  3080. #ifdef BENCH_DEVID
  3081. bench_sha512(1);
  3082. #endif
  3083. }
  3084. #if !defined(WOLFSSL_NOSHA512_224) && \
  3085. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3086. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3087. #ifndef NO_SW_BENCH
  3088. bench_sha512_224(0);
  3089. #endif
  3090. #ifdef BENCH_DEVID
  3091. bench_sha512_224(1);
  3092. #endif
  3093. }
  3094. #endif /* WOLFSSL_NOSHA512_224 */
  3095. #if !defined(WOLFSSL_NOSHA512_256) && \
  3096. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3097. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3098. #ifndef NO_SW_BENCH
  3099. bench_sha512_256(0);
  3100. #endif
  3101. #ifdef BENCH_DEVID
  3102. bench_sha512_256(1);
  3103. #endif
  3104. }
  3105. #endif /* WOLFSSL_NOSHA512_256 */
  3106. #endif /* WOLFSSL_SHA512 */
  3107. #ifdef WOLFSSL_SHA3
  3108. #ifndef WOLFSSL_NOSHA3_224
  3109. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3110. #ifndef NO_SW_BENCH
  3111. bench_sha3_224(0);
  3112. #endif
  3113. #ifdef BENCH_DEVID
  3114. bench_sha3_224(1);
  3115. #endif
  3116. }
  3117. #endif /* WOLFSSL_NOSHA3_224 */
  3118. #ifndef WOLFSSL_NOSHA3_256
  3119. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3120. #ifndef NO_SW_BENCH
  3121. bench_sha3_256(0);
  3122. #endif
  3123. #ifdef BENCH_DEVID
  3124. bench_sha3_256(1);
  3125. #endif
  3126. }
  3127. #endif /* WOLFSSL_NOSHA3_256 */
  3128. #ifndef WOLFSSL_NOSHA3_384
  3129. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3130. #ifndef NO_SW_BENCH
  3131. bench_sha3_384(0);
  3132. #endif
  3133. #ifdef BENCH_DEVID
  3134. bench_sha3_384(1);
  3135. #endif
  3136. }
  3137. #endif /* WOLFSSL_NOSHA3_384 */
  3138. #ifndef WOLFSSL_NOSHA3_512
  3139. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3140. #ifndef NO_SW_BENCH
  3141. bench_sha3_512(0);
  3142. #endif
  3143. #ifdef BENCH_DEVID
  3144. bench_sha3_512(1);
  3145. #endif
  3146. }
  3147. #endif /* WOLFSSL_NOSHA3_512 */
  3148. #ifdef WOLFSSL_SHAKE128
  3149. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3150. #ifndef NO_SW_BENCH
  3151. bench_shake128(0);
  3152. #endif
  3153. #ifdef BENCH_DEVID
  3154. bench_shake128(1);
  3155. #endif
  3156. }
  3157. #endif /* WOLFSSL_SHAKE128 */
  3158. #ifdef WOLFSSL_SHAKE256
  3159. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3160. #ifndef NO_SW_BENCH
  3161. bench_shake256(0);
  3162. #endif
  3163. #ifdef BENCH_DEVID
  3164. bench_shake256(1);
  3165. #endif
  3166. }
  3167. #endif /* WOLFSSL_SHAKE256 */
  3168. #endif
  3169. #ifdef WOLFSSL_SM3
  3170. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3171. #ifndef NO_SW_BENCH
  3172. bench_sm3(0);
  3173. #endif
  3174. #ifdef BENCH_DEVID
  3175. bench_sm3(1);
  3176. #endif
  3177. }
  3178. #endif
  3179. #ifdef WOLFSSL_RIPEMD
  3180. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3181. bench_ripemd();
  3182. #endif
  3183. #ifdef HAVE_BLAKE2
  3184. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3185. bench_blake2b();
  3186. #endif
  3187. #ifdef HAVE_BLAKE2S
  3188. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3189. bench_blake2s();
  3190. #endif
  3191. #ifdef WOLFSSL_CMAC
  3192. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3193. bench_cmac(0);
  3194. #ifdef BENCH_DEVID
  3195. bench_cmac(1);
  3196. #endif
  3197. }
  3198. #endif
  3199. #ifndef NO_HMAC
  3200. #ifndef NO_MD5
  3201. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3202. #ifndef NO_SW_BENCH
  3203. bench_hmac_md5(0);
  3204. #endif
  3205. #ifdef BENCH_DEVID
  3206. bench_hmac_md5(1);
  3207. #endif
  3208. }
  3209. #endif
  3210. #ifndef NO_SHA
  3211. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3212. #ifndef NO_SW_BENCH
  3213. bench_hmac_sha(0);
  3214. #endif
  3215. #ifdef BENCH_DEVID
  3216. bench_hmac_sha(1);
  3217. #endif
  3218. }
  3219. #endif
  3220. #ifdef WOLFSSL_SHA224
  3221. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3222. #ifndef NO_SW_BENCH
  3223. bench_hmac_sha224(0);
  3224. #endif
  3225. #ifdef BENCH_DEVID
  3226. bench_hmac_sha224(1);
  3227. #endif
  3228. }
  3229. #endif
  3230. #ifndef NO_SHA256
  3231. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3232. #ifndef NO_SW_BENCH
  3233. bench_hmac_sha256(0);
  3234. #endif
  3235. #ifdef BENCH_DEVID
  3236. bench_hmac_sha256(1);
  3237. #endif
  3238. }
  3239. #endif
  3240. #ifdef WOLFSSL_SHA384
  3241. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3242. #ifndef NO_SW_BENCH
  3243. bench_hmac_sha384(0);
  3244. #endif
  3245. #ifdef BENCH_DEVID
  3246. bench_hmac_sha384(1);
  3247. #endif
  3248. }
  3249. #endif
  3250. #ifdef WOLFSSL_SHA512
  3251. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3252. #ifndef NO_SW_BENCH
  3253. bench_hmac_sha512(0);
  3254. #endif
  3255. #ifdef BENCH_DEVID
  3256. bench_hmac_sha512(1);
  3257. #endif
  3258. }
  3259. #endif
  3260. #ifndef NO_PWDBASED
  3261. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3262. bench_pbkdf2();
  3263. }
  3264. #endif
  3265. #endif /* NO_HMAC */
  3266. #ifdef WOLFSSL_SIPHASH
  3267. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3268. bench_siphash();
  3269. }
  3270. #endif
  3271. #ifdef WC_SRTP_KDF
  3272. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3273. bench_srtpkdf();
  3274. }
  3275. #endif
  3276. #ifdef HAVE_SCRYPT
  3277. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3278. bench_scrypt();
  3279. #endif
  3280. #ifndef NO_RSA
  3281. #ifndef HAVE_RENESAS_SYNC
  3282. #ifdef WOLFSSL_KEY_GEN
  3283. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3284. #ifndef NO_SW_BENCH
  3285. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3286. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3287. bench_rsaKeyGen(0);
  3288. }
  3289. else {
  3290. bench_rsaKeyGen_size(0, bench_size);
  3291. }
  3292. #endif
  3293. #ifdef BENCH_DEVID
  3294. if (bench_asym_algs & BENCH_RSA_SZ) {
  3295. bench_rsaKeyGen_size(1, bench_size);
  3296. }
  3297. else {
  3298. bench_rsaKeyGen(1);
  3299. }
  3300. #endif
  3301. }
  3302. #endif
  3303. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3304. #ifndef NO_SW_BENCH
  3305. bench_rsa(0);
  3306. #endif
  3307. #ifdef BENCH_DEVID
  3308. bench_rsa(1);
  3309. #endif
  3310. }
  3311. #ifdef WOLFSSL_KEY_GEN
  3312. if (bench_asym_algs & BENCH_RSA_SZ) {
  3313. #ifndef NO_SW_BENCH
  3314. bench_rsa_key(0, bench_size);
  3315. #endif
  3316. #ifdef BENCH_DEVID
  3317. bench_rsa_key(1, bench_size);
  3318. #endif
  3319. }
  3320. #endif
  3321. #endif
  3322. #endif
  3323. #ifndef NO_DH
  3324. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3325. #ifndef NO_SW_BENCH
  3326. bench_dh(0);
  3327. #endif
  3328. #ifdef BENCH_DEVID
  3329. bench_dh(1);
  3330. #endif
  3331. }
  3332. #endif
  3333. #ifdef WOLFSSL_HAVE_KYBER
  3334. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3335. #ifndef WOLFSSL_NO_ML_KEM
  3336. #ifdef WOLFSSL_KYBER512
  3337. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3338. bench_kyber(WC_ML_KEM_512);
  3339. }
  3340. #endif
  3341. #ifdef WOLFSSL_KYBER768
  3342. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3343. bench_kyber(WC_ML_KEM_768);
  3344. }
  3345. #endif
  3346. #ifdef WOLFSSL_KYBER1024
  3347. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3348. bench_kyber(WC_ML_KEM_1024);
  3349. }
  3350. #endif
  3351. #endif
  3352. #ifdef WOLFSSL_KYBER_ORIGINAL
  3353. #ifdef WOLFSSL_KYBER512
  3354. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3355. bench_kyber(KYBER512);
  3356. }
  3357. #endif
  3358. #ifdef WOLFSSL_KYBER768
  3359. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3360. bench_kyber(KYBER768);
  3361. }
  3362. #endif
  3363. #ifdef WOLFSSL_KYBER1024
  3364. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3365. bench_kyber(KYBER1024);
  3366. }
  3367. #endif
  3368. #endif
  3369. }
  3370. #endif
  3371. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3372. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3373. bench_lms();
  3374. }
  3375. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3376. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3377. if (bench_all) {
  3378. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3379. }
  3380. #ifndef NO_SHA256
  3381. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3382. bench_xmss(WC_HASH_TYPE_SHA256);
  3383. }
  3384. #endif
  3385. #ifdef WOLFSSL_SHA512
  3386. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3387. bench_xmss(WC_HASH_TYPE_SHA512);
  3388. }
  3389. #endif
  3390. #ifdef WOLFSSL_SHAKE128
  3391. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3392. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3393. }
  3394. #endif
  3395. #ifdef WOLFSSL_SHAKE256
  3396. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3397. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3398. }
  3399. #endif
  3400. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3401. #ifdef HAVE_ECC
  3402. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3403. (bench_asym_algs & BENCH_ECC) ||
  3404. (bench_asym_algs & BENCH_ECC_ALL) ||
  3405. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3406. if (bench_asym_algs & BENCH_ECC_ALL) {
  3407. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3408. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3409. err_prefix);
  3410. #else
  3411. int curveId = (int)ECC_SECP192R1;
  3412. /* set make key and encrypt */
  3413. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3414. BENCH_ECC_ENCRYPT;
  3415. if (csv_format != 1) {
  3416. printf("\n%sECC Benchmarks:\n", info_prefix);
  3417. }
  3418. do {
  3419. #ifdef WOLFCRYPT_HAVE_SAKKE
  3420. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3421. if (curveId == ECC_SAKKE_1) {
  3422. curveId++;
  3423. continue;
  3424. }
  3425. #endif
  3426. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3427. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3428. bench_ecc_curve(curveId);
  3429. if (csv_format != 1) {
  3430. printf("\n");
  3431. }
  3432. }
  3433. curveId++;
  3434. } while (curveId != (int)ECC_CURVE_MAX);
  3435. #endif
  3436. }
  3437. else if (bench_asym_algs & BENCH_ECC_P256) {
  3438. bench_ecc_curve((int)ECC_SECP256R1);
  3439. }
  3440. else if (bench_asym_algs & BENCH_ECC_P384) {
  3441. bench_ecc_curve((int)ECC_SECP384R1);
  3442. }
  3443. else if (bench_asym_algs & BENCH_ECC_P521) {
  3444. bench_ecc_curve((int)ECC_SECP521R1);
  3445. }
  3446. else {
  3447. #ifndef NO_ECC256
  3448. bench_ecc_curve((int)ECC_SECP256R1);
  3449. #elif defined(HAVE_ECC384)
  3450. bench_ecc_curve((int)ECC_SECP384R1);
  3451. #elif defined(HAVE_ECC521)
  3452. bench_ecc_curve((int)ECC_SECP521R1);
  3453. #endif
  3454. #ifdef HAVE_ECC_BRAINPOOL
  3455. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3456. #endif
  3457. }
  3458. }
  3459. #endif
  3460. #ifdef WOLFSSL_SM2
  3461. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3462. bench_sm2(0);
  3463. }
  3464. #endif
  3465. #ifdef HAVE_CURVE25519
  3466. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3467. bench_curve25519KeyGen(0);
  3468. #ifdef BENCH_DEVID
  3469. bench_curve25519KeyGen(1);
  3470. #endif
  3471. }
  3472. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3473. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3474. bench_curve25519KeyAgree(0);
  3475. #ifdef BENCH_DEVID
  3476. bench_curve25519KeyAgree(1);
  3477. #endif
  3478. }
  3479. #endif
  3480. #endif
  3481. #ifdef HAVE_ED25519
  3482. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3483. bench_ed25519KeyGen();
  3484. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3485. bench_ed25519KeySign();
  3486. #endif
  3487. #ifdef HAVE_CURVE448
  3488. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3489. bench_curve448KeyGen();
  3490. #ifdef HAVE_CURVE448_SHARED_SECRET
  3491. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3492. bench_curve448KeyAgree();
  3493. #endif
  3494. #endif
  3495. #ifdef HAVE_ED448
  3496. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3497. bench_ed448KeyGen();
  3498. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3499. bench_ed448KeySign();
  3500. #endif
  3501. #ifdef WOLFCRYPT_HAVE_ECCSI
  3502. #ifdef WOLFCRYPT_ECCSI_KMS
  3503. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3504. bench_eccsiKeyGen();
  3505. }
  3506. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3507. bench_eccsiPairGen();
  3508. }
  3509. #endif
  3510. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3511. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3512. bench_eccsiValidate();
  3513. }
  3514. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3515. bench_eccsi();
  3516. }
  3517. #endif
  3518. #endif
  3519. #ifdef WOLFCRYPT_HAVE_SAKKE
  3520. #ifdef WOLFCRYPT_SAKKE_KMS
  3521. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3522. bench_sakkeKeyGen();
  3523. }
  3524. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3525. bench_sakkeRskGen();
  3526. }
  3527. #endif
  3528. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3529. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3530. bench_sakkeValidate();
  3531. }
  3532. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3533. bench_sakke();
  3534. }
  3535. #endif
  3536. #endif
  3537. #ifdef HAVE_FALCON
  3538. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3539. bench_falconKeySign(1);
  3540. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3541. bench_falconKeySign(5);
  3542. #endif
  3543. #ifdef HAVE_DILITHIUM
  3544. #ifndef WOLFSSL_NO_ML_DSA_44
  3545. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3546. bench_dilithiumKeySign(2);
  3547. #endif
  3548. #ifndef WOLFSSL_NO_ML_DSA_65
  3549. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3550. bench_dilithiumKeySign(3);
  3551. #endif
  3552. #ifndef WOLFSSL_NO_ML_DSA_87
  3553. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3554. bench_dilithiumKeySign(5);
  3555. #endif
  3556. #endif
  3557. #ifdef HAVE_SPHINCS
  3558. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3559. bench_sphincsKeySign(1, FAST_VARIANT);
  3560. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3561. bench_sphincsKeySign(3, FAST_VARIANT);
  3562. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3563. bench_sphincsKeySign(5, FAST_VARIANT);
  3564. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3565. bench_sphincsKeySign(1, SMALL_VARIANT);
  3566. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3567. bench_sphincsKeySign(3, SMALL_VARIANT);
  3568. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3569. bench_sphincsKeySign(5, SMALL_VARIANT);
  3570. #endif
  3571. exit:
  3572. /* free benchmark buffers */
  3573. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3574. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3575. #ifdef WOLFSSL_ASYNC_CRYPT
  3576. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3577. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3578. #endif
  3579. #if defined(HAVE_LOCAL_RNG)
  3580. wc_FreeRng(&gRng);
  3581. #endif
  3582. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3583. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3584. wc_ecc_fp_free();
  3585. #endif
  3586. (void)bench_cipher_algs;
  3587. (void)bench_digest_algs;
  3588. (void)bench_mac_algs;
  3589. (void)bench_asym_algs;
  3590. (void)bench_other_algs;
  3591. (void)bench_pq_asym_algs;
  3592. (void)bench_pq_asym_algs2;
  3593. return NULL;
  3594. }
  3595. int benchmark_init(void)
  3596. {
  3597. int ret = 0;
  3598. benchmark_static_init(0);
  3599. #ifdef WOLFSSL_STATIC_MEMORY
  3600. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3601. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3602. if (ret != 0) {
  3603. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3604. }
  3605. #endif /* WOLFSSL_STATIC_MEMORY */
  3606. if ((ret = wolfCrypt_Init()) != 0) {
  3607. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3608. return EXIT_FAILURE;
  3609. }
  3610. #ifdef HAVE_WC_INTROSPECTION
  3611. printf("Math: %s\n", wc_GetMathInfo());
  3612. #endif
  3613. #ifdef WOLFSSL_SECO_CAAM
  3614. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3615. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3616. != 0) {
  3617. printf("%sunable to open HSM\n", err_prefix);
  3618. wolfCrypt_Cleanup();
  3619. return EXIT_FAILURE;
  3620. }
  3621. #endif
  3622. #ifdef WC_RNG_SEED_CB
  3623. wc_SetSeed_Cb(wc_GenerateSeed);
  3624. #endif
  3625. bench_stats_init();
  3626. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3627. wolfSSL_Debugging_ON();
  3628. #endif
  3629. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3630. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3631. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3632. if (csv_format == 1) {
  3633. printf("This format allows you to easily copy "
  3634. "the output to a csv file.");
  3635. }
  3636. #endif
  3637. #ifdef HAVE_WNR
  3638. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3639. if (ret != 0) {
  3640. printf("%sWhitewood netRandom config init failed %d\n",
  3641. err_prefix, ret);
  3642. }
  3643. #endif /* HAVE_WNR */
  3644. return ret;
  3645. }
  3646. int benchmark_free(void)
  3647. {
  3648. int ret;
  3649. #ifdef WC_BENCH_TRACK_STATS
  3650. if (gPrintStats || devId != INVALID_DEVID) {
  3651. bench_stats_print();
  3652. }
  3653. #endif
  3654. bench_stats_free();
  3655. #ifdef WOLF_CRYPTO_CB
  3656. #ifdef HAVE_INTEL_QA_SYNC
  3657. wc_CryptoCb_CleanupIntelQa(&devId);
  3658. #endif
  3659. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3660. wc_CryptoCb_CleanupOcteon(&devId);
  3661. #endif
  3662. #ifdef HAVE_RENESAS_SYNC
  3663. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3664. #endif
  3665. #endif
  3666. #ifdef WOLFSSL_ASYNC_CRYPT
  3667. /* free event queue */
  3668. wolfEventQueue_Free(&eventQueue);
  3669. /* close device */
  3670. wolfAsync_DevClose(&devId);
  3671. #endif
  3672. #ifdef HAVE_WNR
  3673. ret = wc_FreeNetRandom();
  3674. if (ret < 0) {
  3675. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3676. }
  3677. #endif
  3678. #ifdef WOLFSSL_SECO_CAAM
  3679. if (wc_SECO_CloseHSM() != 0) {
  3680. printf("%sError closing down the key store\n", err_prefix);
  3681. }
  3682. #endif
  3683. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3684. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3685. }
  3686. return ret;
  3687. }
  3688. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3689. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3690. {
  3691. benchmark_test(args);
  3692. EXIT_TEST(0);
  3693. }
  3694. static int benchmark_test_threaded(void* args)
  3695. {
  3696. int i;
  3697. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3698. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3699. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3700. if (g_threadData == NULL) {
  3701. printf("%sThread data alloc failed!\n", err_prefix);
  3702. return EXIT_FAILURE;
  3703. }
  3704. for (i = 0; i < g_threadCount; i++) {
  3705. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3706. NULL, run_bench, args));
  3707. }
  3708. for (i = 0; i < g_threadCount; i++) {
  3709. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3710. }
  3711. printf("\n");
  3712. bench_stats_print();
  3713. return 0;
  3714. }
  3715. #endif
  3716. /* so embedded projects can pull in tests on their own */
  3717. #ifdef HAVE_STACK_SIZE
  3718. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3719. #else
  3720. int benchmark_test(void *args)
  3721. #endif
  3722. {
  3723. int ret;
  3724. (void)args;
  3725. #ifdef HAVE_FIPS
  3726. wolfCrypt_SetCb_fips(myFipsCb);
  3727. #endif
  3728. ret = benchmark_init();
  3729. if (ret != 0)
  3730. EXIT_TEST(ret);
  3731. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3732. {
  3733. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3734. **
  3735. ** Chapter Two, Build Options:
  3736. **
  3737. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3738. **
  3739. ** asynchronous cryptography using hardware based adapters such as
  3740. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3741. */
  3742. int i;
  3743. if (g_threadCount == 0) {
  3744. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3745. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3746. #else
  3747. g_threadCount = wc_AsyncGetNumberOfCpus();
  3748. if (g_threadCount > 0) {
  3749. g_threadCount /= 2; /* use physical core count */
  3750. }
  3751. #endif
  3752. }
  3753. if (g_threadCount <= 0) {
  3754. g_threadCount = 1;
  3755. }
  3756. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3757. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3758. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3759. if (g_threadData == NULL) {
  3760. printf("%sThread data alloc failed!\n", err_prefix);
  3761. EXIT_TEST(EXIT_FAILURE);
  3762. }
  3763. /* Create threads */
  3764. for (i = 0; i < g_threadCount; i++) {
  3765. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3766. benchmarks_do, &g_threadData[i]);
  3767. if (ret != 0) {
  3768. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3769. EXIT_TEST(EXIT_FAILURE);
  3770. }
  3771. }
  3772. /* Start threads */
  3773. for (i = 0; i < g_threadCount; i++) {
  3774. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3775. }
  3776. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3777. }
  3778. #else
  3779. benchmarks_do(NULL);
  3780. #endif
  3781. SLEEP_ON_ERROR(1);
  3782. printf("%sBenchmark complete\n", info_prefix);
  3783. ret = benchmark_free();
  3784. EXIT_TEST(ret);
  3785. }
  3786. #ifndef WC_NO_RNG
  3787. void bench_rng(void)
  3788. {
  3789. int ret, i, count;
  3790. double start;
  3791. long pos, len, remain;
  3792. WC_RNG myrng;
  3793. DECLARE_MULTI_VALUE_STATS_VARS()
  3794. #ifndef HAVE_FIPS
  3795. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3796. #else
  3797. ret = wc_InitRng(&myrng);
  3798. #endif
  3799. if (ret < 0) {
  3800. printf("InitRNG failed %d\n", ret);
  3801. return;
  3802. }
  3803. bench_stats_start(&count, &start);
  3804. do {
  3805. for (i = 0; i < numBlocks; i++) {
  3806. /* Split request to handle large RNG request */
  3807. pos = 0;
  3808. remain = (int)bench_size;
  3809. while (remain > 0) {
  3810. len = remain;
  3811. if (len > RNG_MAX_BLOCK_LEN)
  3812. len = RNG_MAX_BLOCK_LEN;
  3813. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3814. (word32)len);
  3815. if (ret < 0)
  3816. goto exit_rng;
  3817. remain -= len;
  3818. pos += len;
  3819. }
  3820. RECORD_MULTI_VALUE_STATS();
  3821. }
  3822. count += i;
  3823. } while (bench_stats_check(start)
  3824. #ifdef MULTI_VALUE_STATISTICS
  3825. || runs < minimum_runs
  3826. #endif
  3827. );
  3828. exit_rng:
  3829. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3830. #ifdef MULTI_VALUE_STATISTICS
  3831. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3832. #endif
  3833. wc_FreeRng(&myrng);
  3834. }
  3835. #endif /* WC_NO_RNG */
  3836. #ifndef NO_AES
  3837. #ifdef HAVE_AES_CBC
  3838. static void bench_aescbc_internal(int useDeviceID,
  3839. const byte* key, word32 keySz,
  3840. const byte* iv, const char* encLabel,
  3841. const char* decLabel)
  3842. {
  3843. const byte* in = bench_cipher;
  3844. byte* out = bench_plain;
  3845. int ret = 0, i, count = 0, times, pending = 0;
  3846. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3847. sizeof(Aes), HEAP_HINT);
  3848. double start;
  3849. DECLARE_MULTI_VALUE_STATS_VARS()
  3850. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3851. sizeof(Aes), HEAP_HINT);
  3852. /* init keys */
  3853. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3854. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3855. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3856. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3857. goto exit;
  3858. }
  3859. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3860. if (ret != 0) {
  3861. printf("AesSetKey failed, ret = %d\n", ret);
  3862. goto exit;
  3863. }
  3864. }
  3865. if (cipher_same_buffer) {
  3866. in = bench_plain;
  3867. }
  3868. bench_stats_start(&count, &start);
  3869. do {
  3870. for (times = 0; times < numBlocks || pending > 0; ) {
  3871. bench_async_poll(&pending);
  3872. /* while free pending slots in queue, submit ops */
  3873. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3874. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3875. &times, numBlocks, &pending)) {
  3876. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3877. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3878. 0, &times, &pending)) {
  3879. goto exit_aes_enc;
  3880. }
  3881. }
  3882. } /* for i */
  3883. RECORD_MULTI_VALUE_STATS();
  3884. } /* for times */
  3885. count += times;
  3886. } while (bench_stats_check(start)
  3887. #ifdef MULTI_VALUE_STATISTICS
  3888. || runs < minimum_runs
  3889. #endif
  3890. );
  3891. exit_aes_enc:
  3892. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3893. bench_size, start, ret);
  3894. #ifdef MULTI_VALUE_STATISTICS
  3895. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3896. #endif
  3897. if (ret < 0) {
  3898. goto exit;
  3899. }
  3900. #ifdef HAVE_AES_DECRYPT
  3901. /* init keys */
  3902. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3903. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3904. if (ret != 0) {
  3905. printf("AesSetKey failed, ret = %d\n", ret);
  3906. goto exit;
  3907. }
  3908. }
  3909. RESET_MULTI_VALUE_STATS_VARS();
  3910. bench_stats_start(&count, &start);
  3911. do {
  3912. for (times = 0; times < numBlocks || pending > 0; ) {
  3913. bench_async_poll(&pending);
  3914. /* while free pending slots in queue, submit ops */
  3915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3917. &times, numBlocks, &pending)) {
  3918. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3919. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3920. 0, &times, &pending)) {
  3921. goto exit_aes_dec;
  3922. }
  3923. }
  3924. } /* for i */
  3925. RECORD_MULTI_VALUE_STATS();
  3926. } /* for times */
  3927. count += times;
  3928. } while (bench_stats_check(start)
  3929. #ifdef MULTI_VALUE_STATISTICS
  3930. || runs < minimum_runs
  3931. #endif
  3932. );
  3933. exit_aes_dec:
  3934. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3935. start, ret);
  3936. #ifdef MULTI_VALUE_STATISTICS
  3937. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3938. #endif
  3939. #endif /* HAVE_AES_DECRYPT */
  3940. (void)decLabel;
  3941. exit:
  3942. if (WC_ARRAY_OK(enc)) {
  3943. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3944. wc_AesFree(enc[i]);
  3945. }
  3946. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3947. }
  3948. }
  3949. void bench_aescbc(int useDeviceID)
  3950. {
  3951. #ifdef WOLFSSL_AES_128
  3952. #ifdef HAVE_RENESAS_SYNC
  3953. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3954. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3955. #else
  3956. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3957. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3958. #endif
  3959. #endif
  3960. #ifdef WOLFSSL_AES_192
  3961. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3962. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3963. #endif
  3964. #ifdef WOLFSSL_AES_256
  3965. #ifdef HAVE_RENESAS_SYNC
  3966. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3967. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3968. #else
  3969. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3970. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3971. #endif
  3972. #endif
  3973. }
  3974. #endif /* HAVE_AES_CBC */
  3975. #ifdef HAVE_AESGCM
  3976. static void bench_aesgcm_internal(int useDeviceID,
  3977. const byte* key, word32 keySz,
  3978. const byte* iv, word32 ivSz,
  3979. const char* encLabel, const char* decLabel)
  3980. {
  3981. int ret = 0, i, count = 0, times, pending = 0;
  3982. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3983. sizeof(Aes), HEAP_HINT);
  3984. #ifdef HAVE_AES_DECRYPT
  3985. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3986. sizeof(Aes), HEAP_HINT);
  3987. #endif
  3988. double start;
  3989. DECLARE_MULTI_VALUE_STATS_VARS()
  3990. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3991. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3992. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3993. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3994. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3995. sizeof(Aes), HEAP_HINT);
  3996. #ifdef HAVE_AES_DECRYPT
  3997. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3998. sizeof(Aes), HEAP_HINT);
  3999. #endif
  4000. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4001. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4002. /* init keys */
  4003. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4004. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4005. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4006. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4007. goto exit;
  4008. }
  4009. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4010. if (ret != 0) {
  4011. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4012. goto exit;
  4013. }
  4014. }
  4015. /* GCM uses same routine in backend for both encrypt and decrypt */
  4016. bench_stats_start(&count, &start);
  4017. do {
  4018. for (times = 0; times < numBlocks || pending > 0; ) {
  4019. bench_async_poll(&pending);
  4020. /* while free pending slots in queue, submit ops */
  4021. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4022. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4023. &times, numBlocks, &pending)) {
  4024. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4025. bench_plain, bench_size,
  4026. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4027. bench_additional, aesAuthAddSz);
  4028. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4029. 0, &times, &pending)) {
  4030. goto exit_aes_gcm;
  4031. }
  4032. }
  4033. } /* for i */
  4034. RECORD_MULTI_VALUE_STATS();
  4035. } /* for times */
  4036. count += times;
  4037. } while (bench_stats_check(start)
  4038. #ifdef MULTI_VALUE_STATISTICS
  4039. || runs < minimum_runs
  4040. #endif
  4041. );
  4042. exit_aes_gcm:
  4043. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4044. start, ret);
  4045. #ifdef MULTI_VALUE_STATISTICS
  4046. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4047. #endif
  4048. #ifdef HAVE_AES_DECRYPT
  4049. RESET_MULTI_VALUE_STATS_VARS();
  4050. /* init keys */
  4051. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4052. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4053. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4054. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4055. goto exit;
  4056. }
  4057. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4058. if (ret != 0) {
  4059. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4060. goto exit;
  4061. }
  4062. }
  4063. bench_stats_start(&count, &start);
  4064. do {
  4065. for (times = 0; times < numBlocks || pending > 0; ) {
  4066. bench_async_poll(&pending);
  4067. /* while free pending slots in queue, submit ops */
  4068. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4069. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4070. &times, numBlocks, &pending)) {
  4071. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4072. bench_cipher, bench_size,
  4073. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4074. bench_additional, aesAuthAddSz);
  4075. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4076. 0, &times, &pending)) {
  4077. goto exit_aes_gcm_dec;
  4078. }
  4079. }
  4080. } /* for i */
  4081. RECORD_MULTI_VALUE_STATS();
  4082. } /* for times */
  4083. count += times;
  4084. } while (bench_stats_check(start)
  4085. #ifdef MULTI_VALUE_STATISTICS
  4086. || runs < minimum_runs
  4087. #endif
  4088. );
  4089. exit_aes_gcm_dec:
  4090. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4091. start, ret);
  4092. #ifdef MULTI_VALUE_STATISTICS
  4093. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4094. #endif
  4095. #endif /* HAVE_AES_DECRYPT */
  4096. (void)decLabel;
  4097. exit:
  4098. if (ret < 0) {
  4099. printf("bench_aesgcm failed: %d\n", ret);
  4100. }
  4101. #ifdef HAVE_AES_DECRYPT
  4102. if (WC_ARRAY_OK(dec)) {
  4103. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4104. wc_AesFree(dec[i]);
  4105. }
  4106. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4107. }
  4108. #endif
  4109. if (WC_ARRAY_OK(enc)) {
  4110. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4111. wc_AesFree(enc[i]);
  4112. }
  4113. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4114. }
  4115. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4116. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4117. }
  4118. #ifdef WOLFSSL_AESGCM_STREAM
  4119. static void bench_aesgcm_stream_internal(int useDeviceID,
  4120. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4121. const char* encLabel, const char* decLabel)
  4122. {
  4123. int ret = 0, i, count = 0, times, pending = 0;
  4124. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4125. sizeof(Aes), HEAP_HINT);
  4126. #ifdef HAVE_AES_DECRYPT
  4127. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4128. sizeof(Aes), HEAP_HINT);
  4129. #endif
  4130. double start;
  4131. DECLARE_MULTI_VALUE_STATS_VARS()
  4132. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4133. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4134. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4135. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4136. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4137. sizeof(Aes), HEAP_HINT);
  4138. #ifdef HAVE_AES_DECRYPT
  4139. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4140. sizeof(Aes), HEAP_HINT);
  4141. #endif
  4142. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4143. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4144. /* init keys */
  4145. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4146. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4147. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4148. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4149. goto exit;
  4150. }
  4151. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4152. if (ret != 0) {
  4153. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4154. goto exit;
  4155. }
  4156. }
  4157. /* GCM uses same routine in backend for both encrypt and decrypt */
  4158. bench_stats_start(&count, &start);
  4159. do {
  4160. for (times = 0; times < numBlocks || pending > 0; ) {
  4161. bench_async_poll(&pending);
  4162. /* while free pending slots in queue, submit ops */
  4163. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4164. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4165. &times, numBlocks, &pending)) {
  4166. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4167. if (ret == 0) {
  4168. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4169. bench_plain, bench_size, bench_additional,
  4170. aesAuthAddSz);
  4171. }
  4172. if (ret == 0) {
  4173. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4174. AES_AUTH_TAG_SZ);
  4175. }
  4176. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4177. 0, &times, &pending)) {
  4178. goto exit_aes_gcm;
  4179. }
  4180. }
  4181. } /* for i */
  4182. RECORD_MULTI_VALUE_STATS();
  4183. } /* for times */
  4184. count += times;
  4185. } while (bench_stats_check(start)
  4186. #ifdef MULTI_VALUE_STATISTICS
  4187. || runs < minimum_runs
  4188. #endif
  4189. );
  4190. exit_aes_gcm:
  4191. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4192. start, ret);
  4193. #ifdef MULTI_VALUE_STATISTICS
  4194. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4195. #endif
  4196. #ifdef HAVE_AES_DECRYPT
  4197. /* init keys */
  4198. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4199. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4200. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4201. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4202. goto exit;
  4203. }
  4204. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4205. if (ret != 0) {
  4206. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4207. goto exit;
  4208. }
  4209. }
  4210. RESET_MULTI_VALUE_STATS_VARS();
  4211. bench_stats_start(&count, &start);
  4212. do {
  4213. for (times = 0; times < numBlocks || pending > 0; ) {
  4214. bench_async_poll(&pending);
  4215. /* while free pending slots in queue, submit ops */
  4216. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4217. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4218. &times, numBlocks, &pending)) {
  4219. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4220. if (ret == 0) {
  4221. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4222. bench_cipher, bench_size, bench_additional,
  4223. aesAuthAddSz);
  4224. }
  4225. if (ret == 0) {
  4226. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4227. AES_AUTH_TAG_SZ);
  4228. }
  4229. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4230. 0, &times, &pending)) {
  4231. goto exit_aes_gcm_dec;
  4232. }
  4233. }
  4234. } /* for i */
  4235. RECORD_MULTI_VALUE_STATS();
  4236. } /* for times */
  4237. count += times;
  4238. } while (bench_stats_check(start)
  4239. #ifdef MULTI_VALUE_STATISTICS
  4240. || runs < minimum_runs
  4241. #endif
  4242. );
  4243. exit_aes_gcm_dec:
  4244. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4245. start, ret);
  4246. #ifdef MULTI_VALUE_STATISTICS
  4247. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4248. #endif
  4249. #endif /* HAVE_AES_DECRYPT */
  4250. (void)decLabel;
  4251. exit:
  4252. if (ret < 0) {
  4253. printf("bench_aesgcm failed: %d\n", ret);
  4254. }
  4255. #ifdef HAVE_AES_DECRYPT
  4256. if (WC_ARRAY_OK(dec)) {
  4257. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4258. wc_AesFree(dec[i]);
  4259. }
  4260. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4261. }
  4262. #endif
  4263. if (WC_ARRAY_OK(enc)) {
  4264. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4265. wc_AesFree(enc[i]);
  4266. }
  4267. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4268. }
  4269. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4270. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4271. }
  4272. #endif
  4273. void bench_aesgcm(int useDeviceID)
  4274. {
  4275. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4276. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4277. && !defined(WOLFSSL_XILINX_CRYPT) \
  4278. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4279. #ifdef HAVE_RENESAS_SYNC
  4280. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4281. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4282. #else
  4283. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4284. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4285. #endif
  4286. #endif
  4287. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4288. && !defined(WOLFSSL_XILINX_CRYPT)
  4289. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4290. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4291. #endif
  4292. #ifdef WOLFSSL_AES_256
  4293. #ifdef HAVE_RENESAS_SYNC
  4294. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4295. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4296. #else
  4297. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4298. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4299. #endif
  4300. #endif
  4301. #ifdef WOLFSSL_AESGCM_STREAM
  4302. #undef AES_GCM_STRING
  4303. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4304. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4305. && !defined(WOLFSSL_XILINX_CRYPT) \
  4306. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4307. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4308. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4309. #endif
  4310. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4311. && !defined(WOLFSSL_XILINX_CRYPT)
  4312. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4313. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4314. #endif
  4315. #ifdef WOLFSSL_AES_256
  4316. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4317. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4318. #endif
  4319. #endif /* WOLFSSL_AESGCM_STREAM */
  4320. #undef AES_GCM_STRING
  4321. }
  4322. /* GMAC */
  4323. void bench_gmac(int useDeviceID)
  4324. {
  4325. int ret, count = 0;
  4326. Gmac gmac;
  4327. double start;
  4328. byte tag[AES_AUTH_TAG_SZ];
  4329. DECLARE_MULTI_VALUE_STATS_VARS()
  4330. /* determine GCM GHASH method */
  4331. #ifdef GCM_SMALL
  4332. const char* gmacStr = "GMAC Small";
  4333. #elif defined(GCM_TABLE)
  4334. const char* gmacStr = "GMAC Table";
  4335. #elif defined(GCM_TABLE_4BIT)
  4336. const char* gmacStr = "GMAC Table 4-bit";
  4337. #elif defined(GCM_WORD32)
  4338. const char* gmacStr = "GMAC Word32";
  4339. #else
  4340. const char* gmacStr = "GMAC Default";
  4341. #endif
  4342. /* Implementations of /Dev/Crypto will error out if the size of Auth in is */
  4343. /* greater than the system's page size */
  4344. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  4345. bench_size = WOLFSSL_AUTHSZ_BENCH;
  4346. #elif defined(WOLFSSL_DEVCRYPTO)
  4347. bench_size = sysconf(_SC_PAGESIZE);
  4348. #endif
  4349. /* init keys */
  4350. XMEMSET(bench_plain, 0, bench_size);
  4351. XMEMSET(tag, 0, sizeof(tag));
  4352. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4353. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4354. useDeviceID ? devId: INVALID_DEVID);
  4355. #ifdef HAVE_RENESAS_SYNC
  4356. wc_GmacSetKey(&gmac, bench_key1, 16);
  4357. #else
  4358. wc_GmacSetKey(&gmac, bench_key, 16);
  4359. #endif
  4360. bench_stats_start(&count, &start);
  4361. do {
  4362. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4363. tag, sizeof(tag));
  4364. count++;
  4365. RECORD_MULTI_VALUE_STATS();
  4366. } while (bench_stats_check(start)
  4367. #ifdef MULTI_VALUE_STATISTICS
  4368. || runs < minimum_runs
  4369. #endif
  4370. );
  4371. wc_AesFree((Aes*)&gmac);
  4372. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4373. #ifdef MULTI_VALUE_STATISTICS
  4374. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4375. #endif
  4376. #if defined(WOLFSSL_DEVCRYPTO)
  4377. if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) {
  4378. printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n",
  4379. bench_size, sysconf(_SC_PAGESIZE));
  4380. }
  4381. bench_size = BENCH_SIZE;
  4382. #endif
  4383. }
  4384. #endif /* HAVE_AESGCM */
  4385. #ifdef HAVE_AES_ECB
  4386. static void bench_aesecb_internal(int useDeviceID,
  4387. const byte* key, word32 keySz,
  4388. const char* encLabel, const char* decLabel)
  4389. {
  4390. int ret = 0, i, count = 0, times, pending = 0;
  4391. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4392. sizeof(Aes), HEAP_HINT);
  4393. double start;
  4394. DECLARE_MULTI_VALUE_STATS_VARS()
  4395. #ifdef HAVE_FIPS
  4396. const word32 benchSz = WC_AES_BLOCK_SIZE;
  4397. #else
  4398. const word32 benchSz = bench_size;
  4399. #endif
  4400. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4401. sizeof(Aes), HEAP_HINT);
  4402. /* init keys */
  4403. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4404. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4405. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4406. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4407. goto exit;
  4408. }
  4409. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4410. if (ret != 0) {
  4411. printf("AesSetKey failed, ret = %d\n", ret);
  4412. goto exit;
  4413. }
  4414. }
  4415. bench_stats_start(&count, &start);
  4416. do {
  4417. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4418. for (times = 0;
  4419. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4420. ) {
  4421. bench_async_poll(&pending);
  4422. /* while free pending slots in queue, submit ops */
  4423. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4424. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4425. &times, outer_loop_limit, &pending)) {
  4426. #ifdef HAVE_FIPS
  4427. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4428. #else
  4429. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4430. benchSz);
  4431. #endif
  4432. ret = 0;
  4433. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4434. 0, &times, &pending)) {
  4435. goto exit_aes_enc;
  4436. }
  4437. }
  4438. } /* for i */
  4439. RECORD_MULTI_VALUE_STATS();
  4440. } /* for times */
  4441. count += times;
  4442. } while (bench_stats_check(start)
  4443. #ifdef MULTI_VALUE_STATISTICS
  4444. || runs < minimum_runs
  4445. #endif
  4446. );
  4447. exit_aes_enc:
  4448. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4449. start, ret);
  4450. #ifdef MULTI_VALUE_STATISTICS
  4451. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4452. #endif
  4453. #ifdef HAVE_AES_DECRYPT
  4454. /* init keys */
  4455. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4456. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4457. if (ret != 0) {
  4458. printf("AesSetKey failed, ret = %d\n", ret);
  4459. goto exit;
  4460. }
  4461. }
  4462. RESET_MULTI_VALUE_STATS_VARS();
  4463. bench_stats_start(&count, &start);
  4464. do {
  4465. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4466. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4467. bench_async_poll(&pending);
  4468. /* while free pending slots in queue, submit ops */
  4469. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4470. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4471. &times, outer_loop_limit, &pending)) {
  4472. #ifdef HAVE_FIPS
  4473. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4474. #else
  4475. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4476. benchSz);
  4477. #endif
  4478. ret = 0;
  4479. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4480. 0, &times, &pending)) {
  4481. goto exit_aes_dec;
  4482. }
  4483. }
  4484. } /* for i */
  4485. RECORD_MULTI_VALUE_STATS();
  4486. } /* for times */
  4487. count += times;
  4488. } while (bench_stats_check(start)
  4489. #ifdef MULTI_VALUE_STATISTICS
  4490. || runs < minimum_runs
  4491. #endif
  4492. );
  4493. exit_aes_dec:
  4494. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4495. start, ret);
  4496. #ifdef MULTI_VALUE_STATISTICS
  4497. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4498. #endif
  4499. #endif /* HAVE_AES_DECRYPT */
  4500. (void)decLabel;
  4501. exit:
  4502. if (WC_ARRAY_OK(enc)) {
  4503. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4504. wc_AesFree(enc[i]);
  4505. }
  4506. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4507. }
  4508. }
  4509. void bench_aesecb(int useDeviceID)
  4510. {
  4511. #ifdef WOLFSSL_AES_128
  4512. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4513. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4514. #endif
  4515. #ifdef WOLFSSL_AES_192
  4516. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4517. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4518. #endif
  4519. #ifdef WOLFSSL_AES_256
  4520. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4521. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4522. #endif
  4523. }
  4524. #endif /* HAVE_AES_ECB */
  4525. #ifdef WOLFSSL_AES_CFB
  4526. static void bench_aescfb_internal(const byte* key,
  4527. word32 keySz, const byte* iv,
  4528. const char* label)
  4529. {
  4530. Aes enc;
  4531. double start;
  4532. int i, ret, count;
  4533. DECLARE_MULTI_VALUE_STATS_VARS()
  4534. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4535. if (ret != 0) {
  4536. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4537. return;
  4538. }
  4539. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4540. if (ret != 0) {
  4541. printf("AesSetKey failed, ret = %d\n", ret);
  4542. goto out;
  4543. }
  4544. bench_stats_start(&count, &start);
  4545. do {
  4546. for (i = 0; i < numBlocks; i++) {
  4547. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4548. bench_size)) != 0) {
  4549. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4550. goto out;
  4551. }
  4552. RECORD_MULTI_VALUE_STATS();
  4553. }
  4554. count += i;
  4555. } while (bench_stats_check(start)
  4556. #ifdef MULTI_VALUE_STATISTICS
  4557. || runs < minimum_runs
  4558. #endif
  4559. );
  4560. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4561. #ifdef MULTI_VALUE_STATISTICS
  4562. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4563. #endif
  4564. out:
  4565. wc_AesFree(&enc);
  4566. return;
  4567. }
  4568. void bench_aescfb(void)
  4569. {
  4570. #ifdef WOLFSSL_AES_128
  4571. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4572. #endif
  4573. #ifdef WOLFSSL_AES_192
  4574. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4575. #endif
  4576. #ifdef WOLFSSL_AES_256
  4577. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4578. #endif
  4579. }
  4580. #endif /* WOLFSSL_AES_CFB */
  4581. #ifdef WOLFSSL_AES_OFB
  4582. static void bench_aesofb_internal(const byte* key,
  4583. word32 keySz, const byte* iv,
  4584. const char* label)
  4585. {
  4586. Aes enc;
  4587. double start;
  4588. int i, ret, count;
  4589. DECLARE_MULTI_VALUE_STATS_VARS()
  4590. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4591. if (ret != 0) {
  4592. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4593. return;
  4594. }
  4595. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4596. if (ret != 0) {
  4597. printf("AesSetKey failed, ret = %d\n", ret);
  4598. return;
  4599. }
  4600. bench_stats_start(&count, &start);
  4601. do {
  4602. for (i = 0; i < numBlocks; i++) {
  4603. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4604. bench_size)) != 0) {
  4605. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4606. return;
  4607. }
  4608. RECORD_MULTI_VALUE_STATS();
  4609. }
  4610. count += i;
  4611. } while (bench_stats_check(start)
  4612. #ifdef MULTI_VALUE_STATISTICS
  4613. || runs < minimum_runs
  4614. #endif
  4615. );
  4616. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4617. #ifdef MULTI_VALUE_STATISTICS
  4618. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4619. #endif
  4620. wc_AesFree(&enc);
  4621. }
  4622. void bench_aesofb(void)
  4623. {
  4624. #ifdef WOLFSSL_AES_128
  4625. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4626. #endif
  4627. #ifdef WOLFSSL_AES_192
  4628. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4629. #endif
  4630. #ifdef WOLFSSL_AES_256
  4631. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4632. #endif
  4633. }
  4634. #endif /* WOLFSSL_AES_CFB */
  4635. #ifdef WOLFSSL_AES_XTS
  4636. void bench_aesxts(void)
  4637. {
  4638. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4639. double start;
  4640. int i, count, ret;
  4641. DECLARE_MULTI_VALUE_STATS_VARS()
  4642. static const unsigned char k1[] = {
  4643. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4644. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4645. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4646. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4647. };
  4648. static const unsigned char i1[] = {
  4649. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4650. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4651. };
  4652. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4653. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4654. HEAP_HINT, devId);
  4655. if (ret != 0) {
  4656. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4657. goto exit;
  4658. }
  4659. bench_stats_start(&count, &start);
  4660. do {
  4661. for (i = 0; i < numBlocks; i++) {
  4662. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4663. bench_size, i1, sizeof(i1))) != 0) {
  4664. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4665. goto exit;
  4666. }
  4667. RECORD_MULTI_VALUE_STATS();
  4668. }
  4669. count += i;
  4670. } while (bench_stats_check(start)
  4671. #ifdef MULTI_VALUE_STATISTICS
  4672. || runs < minimum_runs
  4673. #endif
  4674. );
  4675. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4676. #ifdef MULTI_VALUE_STATISTICS
  4677. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4678. #endif
  4679. wc_AesXtsFree(aes);
  4680. /* decryption benchmark */
  4681. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4682. HEAP_HINT, devId);
  4683. if (ret != 0) {
  4684. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4685. goto exit;
  4686. }
  4687. RESET_MULTI_VALUE_STATS_VARS();
  4688. bench_stats_start(&count, &start);
  4689. do {
  4690. for (i = 0; i < numBlocks; i++) {
  4691. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4692. bench_size, i1, sizeof(i1))) != 0) {
  4693. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4694. goto exit;
  4695. }
  4696. RECORD_MULTI_VALUE_STATS();
  4697. }
  4698. count += i;
  4699. } while (bench_stats_check(start)
  4700. #ifdef MULTI_VALUE_STATISTICS
  4701. || runs < minimum_runs
  4702. #endif
  4703. );
  4704. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4705. #ifdef MULTI_VALUE_STATISTICS
  4706. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4707. #endif
  4708. exit:
  4709. wc_AesXtsFree(aes);
  4710. WC_FREE_VAR(aes, HEAP_HINT);
  4711. }
  4712. #endif /* WOLFSSL_AES_XTS */
  4713. #ifdef WOLFSSL_AES_COUNTER
  4714. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4715. const byte* iv, const char* label,
  4716. int useDeviceID)
  4717. {
  4718. Aes enc;
  4719. double start;
  4720. int i, count, ret = 0;
  4721. DECLARE_MULTI_VALUE_STATS_VARS()
  4722. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4723. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4724. printf("wc_AesInit failed, ret = %d\n", ret);
  4725. }
  4726. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4727. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4728. return;
  4729. }
  4730. bench_stats_start(&count, &start);
  4731. do {
  4732. for (i = 0; i < numBlocks; i++) {
  4733. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4734. bench_size)) != 0) {
  4735. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4736. return;
  4737. }
  4738. RECORD_MULTI_VALUE_STATS();
  4739. }
  4740. count += i;
  4741. } while (bench_stats_check(start)
  4742. #ifdef MULTI_VALUE_STATISTICS
  4743. || runs < minimum_runs
  4744. #endif
  4745. );
  4746. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4747. #ifdef MULTI_VALUE_STATISTICS
  4748. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4749. #endif
  4750. wc_AesFree(&enc);
  4751. }
  4752. void bench_aesctr(int useDeviceID)
  4753. {
  4754. #ifdef WOLFSSL_AES_128
  4755. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4756. #endif
  4757. #ifdef WOLFSSL_AES_192
  4758. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4759. #endif
  4760. #ifdef WOLFSSL_AES_256
  4761. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4762. #endif
  4763. }
  4764. #endif /* WOLFSSL_AES_COUNTER */
  4765. #ifdef HAVE_AESCCM
  4766. void bench_aesccm(int useDeviceID)
  4767. {
  4768. Aes enc;
  4769. int enc_inited = 0;
  4770. double start;
  4771. int ret, i, count;
  4772. DECLARE_MULTI_VALUE_STATS_VARS()
  4773. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4774. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4775. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4776. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4777. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4778. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4779. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4780. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4781. {
  4782. printf("wc_AesInit failed, ret = %d\n", ret);
  4783. goto exit;
  4784. }
  4785. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4786. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4787. goto exit;
  4788. }
  4789. enc_inited = 1;
  4790. bench_stats_start(&count, &start);
  4791. do {
  4792. for (i = 0; i < numBlocks; i++) {
  4793. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4794. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4795. bench_additional, 0);
  4796. RECORD_MULTI_VALUE_STATS();
  4797. }
  4798. count += i;
  4799. } while (bench_stats_check(start)
  4800. #ifdef MULTI_VALUE_STATISTICS
  4801. || runs < minimum_runs
  4802. #endif
  4803. );
  4804. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4805. bench_size, start, ret);
  4806. #ifdef MULTI_VALUE_STATISTICS
  4807. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4808. #endif
  4809. if (ret != 0) {
  4810. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4811. goto exit;
  4812. }
  4813. #ifdef HAVE_AES_DECRYPT
  4814. RESET_MULTI_VALUE_STATS_VARS();
  4815. bench_stats_start(&count, &start);
  4816. do {
  4817. for (i = 0; i < numBlocks; i++) {
  4818. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4819. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4820. bench_additional, 0);
  4821. RECORD_MULTI_VALUE_STATS();
  4822. }
  4823. count += i;
  4824. } while (bench_stats_check(start)
  4825. #ifdef MULTI_VALUE_STATISTICS
  4826. || runs < minimum_runs
  4827. #endif
  4828. );
  4829. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4830. bench_size, start, ret);
  4831. #ifdef MULTI_VALUE_STATISTICS
  4832. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4833. #endif
  4834. if (ret != 0) {
  4835. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4836. goto exit;
  4837. }
  4838. #endif
  4839. exit:
  4840. if (enc_inited)
  4841. wc_AesFree(&enc);
  4842. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4843. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4844. }
  4845. #endif /* HAVE_AESCCM */
  4846. #ifdef WOLFSSL_AES_SIV
  4847. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4848. encLabel, const char* decLabel)
  4849. {
  4850. int i;
  4851. int ret = 0;
  4852. byte assoc[WC_AES_BLOCK_SIZE];
  4853. byte nonce[WC_AES_BLOCK_SIZE];
  4854. byte siv[WC_AES_BLOCK_SIZE];
  4855. int count = 0;
  4856. double start;
  4857. DECLARE_MULTI_VALUE_STATS_VARS()
  4858. bench_stats_start(&count, &start);
  4859. do {
  4860. for (i = 0; i < numBlocks; i++) {
  4861. ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4862. WC_AES_BLOCK_SIZE, bench_plain, bench_size,
  4863. siv, bench_cipher);
  4864. if (ret != 0) {
  4865. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4866. return;
  4867. }
  4868. RECORD_MULTI_VALUE_STATS();
  4869. }
  4870. count += i;
  4871. } while (bench_stats_check(start)
  4872. #ifdef MULTI_VALUE_STATISTICS
  4873. || runs < minimum_runs
  4874. #endif
  4875. );
  4876. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4877. #ifdef MULTI_VALUE_STATISTICS
  4878. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4879. #endif
  4880. RESET_MULTI_VALUE_STATS_VARS();
  4881. bench_stats_start(&count, &start);
  4882. do {
  4883. for (i = 0; i < numBlocks; i++) {
  4884. ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4885. WC_AES_BLOCK_SIZE, bench_cipher, bench_size,
  4886. siv, bench_plain);
  4887. if (ret != 0) {
  4888. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4889. return;
  4890. }
  4891. RECORD_MULTI_VALUE_STATS();
  4892. }
  4893. count += i;
  4894. } while (bench_stats_check(start)
  4895. #ifdef MULTI_VALUE_STATISTICS
  4896. || runs < minimum_runs
  4897. #endif
  4898. );
  4899. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4900. #ifdef MULTI_VALUE_STATISTICS
  4901. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4902. #endif
  4903. }
  4904. void bench_aessiv(void)
  4905. {
  4906. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4907. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4908. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4909. }
  4910. #endif /* WOLFSSL_AES_SIV */
  4911. #endif /* !NO_AES */
  4912. #ifdef HAVE_POLY1305
  4913. void bench_poly1305(void)
  4914. {
  4915. Poly1305 enc;
  4916. byte mac[16];
  4917. double start;
  4918. int ret = 0, i, count;
  4919. DECLARE_MULTI_VALUE_STATS_VARS()
  4920. if (digest_stream) {
  4921. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4922. if (ret != 0) {
  4923. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4924. return;
  4925. }
  4926. bench_stats_start(&count, &start);
  4927. do {
  4928. for (i = 0; i < numBlocks; i++) {
  4929. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4930. if (ret != 0) {
  4931. printf("Poly1305Update failed: %d\n", ret);
  4932. break;
  4933. }
  4934. RECORD_MULTI_VALUE_STATS();
  4935. }
  4936. wc_Poly1305Final(&enc, mac);
  4937. count += i;
  4938. } while (bench_stats_check(start)
  4939. #ifdef MULTI_VALUE_STATISTICS
  4940. || runs < minimum_runs
  4941. #endif
  4942. );
  4943. }
  4944. else {
  4945. bench_stats_start(&count, &start);
  4946. do {
  4947. for (i = 0; i < numBlocks; i++) {
  4948. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4949. if (ret != 0) {
  4950. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4951. return;
  4952. }
  4953. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4954. if (ret != 0) {
  4955. printf("Poly1305Update failed: %d\n", ret);
  4956. break;
  4957. }
  4958. wc_Poly1305Final(&enc, mac);
  4959. RECORD_MULTI_VALUE_STATS();
  4960. }
  4961. count += i;
  4962. } while (bench_stats_check(start)
  4963. #ifdef MULTI_VALUE_STATISTICS
  4964. || runs < minimum_runs
  4965. #endif
  4966. );
  4967. }
  4968. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4969. #ifdef MULTI_VALUE_STATISTICS
  4970. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4971. #endif
  4972. }
  4973. #endif /* HAVE_POLY1305 */
  4974. #ifdef HAVE_CAMELLIA
  4975. void bench_camellia(void)
  4976. {
  4977. wc_Camellia cam;
  4978. double start;
  4979. int ret, i, count;
  4980. DECLARE_MULTI_VALUE_STATS_VARS()
  4981. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4982. if (ret != 0) {
  4983. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4984. return;
  4985. }
  4986. bench_stats_start(&count, &start);
  4987. do {
  4988. for (i = 0; i < numBlocks; i++) {
  4989. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4990. bench_size);
  4991. if (ret < 0) {
  4992. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4993. return;
  4994. }
  4995. RECORD_MULTI_VALUE_STATS();
  4996. }
  4997. count += i;
  4998. } while (bench_stats_check(start)
  4999. #ifdef MULTI_VALUE_STATISTICS
  5000. || runs < minimum_runs
  5001. #endif
  5002. );
  5003. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  5004. #ifdef MULTI_VALUE_STATISTICS
  5005. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5006. #endif
  5007. }
  5008. #endif
  5009. #ifdef WOLFSSL_SM4_CBC
  5010. void bench_sm4_cbc(void)
  5011. {
  5012. wc_Sm4 sm4;
  5013. double start;
  5014. int ret;
  5015. int i;
  5016. int count;
  5017. DECLARE_MULTI_VALUE_STATS_VARS()
  5018. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5019. if (ret != 0) {
  5020. printf("Sm4SetKey failed, ret = %d\n", ret);
  5021. return;
  5022. }
  5023. ret = wc_Sm4SetIV(&sm4, bench_iv);
  5024. if (ret != 0) {
  5025. printf("Sm4SetIV failed, ret = %d\n", ret);
  5026. return;
  5027. }
  5028. bench_stats_start(&count, &start);
  5029. do {
  5030. for (i = 0; i < numBlocks; i++) {
  5031. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  5032. if (ret < 0) {
  5033. printf("Sm4CbcEncrypt failed: %d\n", ret);
  5034. return;
  5035. }
  5036. RECORD_MULTI_VALUE_STATS();
  5037. }
  5038. count += i;
  5039. } while (bench_stats_check(start)
  5040. #ifdef MULTI_VALUE_STATISTICS
  5041. || runs < minimum_runs
  5042. #endif
  5043. );
  5044. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5045. #ifdef MULTI_VALUE_STATISTICS
  5046. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5047. #endif
  5048. RESET_MULTI_VALUE_STATS_VARS();
  5049. bench_stats_start(&count, &start);
  5050. do {
  5051. for (i = 0; i < numBlocks; i++) {
  5052. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5053. if (ret < 0) {
  5054. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5055. return;
  5056. }
  5057. RECORD_MULTI_VALUE_STATS();
  5058. }
  5059. count += i;
  5060. } while (bench_stats_check(start)
  5061. #ifdef MULTI_VALUE_STATISTICS
  5062. || runs < minimum_runs
  5063. #endif
  5064. );
  5065. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5066. #ifdef MULTI_VALUE_STATISTICS
  5067. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5068. #endif
  5069. }
  5070. #endif
  5071. #ifdef WOLFSSL_SM4_GCM
  5072. void bench_sm4_gcm(void)
  5073. {
  5074. wc_Sm4 sm4;
  5075. double start;
  5076. int ret;
  5077. int i;
  5078. int count;
  5079. DECLARE_MULTI_VALUE_STATS_VARS()
  5080. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5081. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5082. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5083. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5084. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5085. if (ret != 0) {
  5086. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5087. goto exit;
  5088. }
  5089. bench_stats_start(&count, &start);
  5090. do {
  5091. for (i = 0; i < numBlocks; i++) {
  5092. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5093. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5094. bench_additional, aesAuthAddSz);
  5095. if (ret < 0) {
  5096. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5097. goto exit;
  5098. }
  5099. RECORD_MULTI_VALUE_STATS();
  5100. }
  5101. count += i;
  5102. } while (bench_stats_check(start)
  5103. #ifdef MULTI_VALUE_STATISTICS
  5104. || runs < minimum_runs
  5105. #endif
  5106. );
  5107. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5108. #ifdef MULTI_VALUE_STATISTICS
  5109. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5110. #endif
  5111. RESET_MULTI_VALUE_STATS_VARS();
  5112. bench_stats_start(&count, &start);
  5113. do {
  5114. for (i = 0; i < numBlocks; i++) {
  5115. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5116. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5117. bench_additional, aesAuthAddSz);
  5118. if (ret < 0) {
  5119. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5120. goto exit;
  5121. }
  5122. RECORD_MULTI_VALUE_STATS();
  5123. }
  5124. count += i;
  5125. } while (bench_stats_check(start)
  5126. #ifdef MULTI_VALUE_STATISTICS
  5127. || runs < minimum_runs
  5128. #endif
  5129. );
  5130. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5131. #ifdef MULTI_VALUE_STATISTICS
  5132. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5133. #endif
  5134. exit:
  5135. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5136. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5137. }
  5138. #endif
  5139. #ifdef WOLFSSL_SM4_CCM
  5140. void bench_sm4_ccm(void)
  5141. {
  5142. wc_Sm4 enc;
  5143. double start;
  5144. int ret, i, count;
  5145. DECLARE_MULTI_VALUE_STATS_VARS()
  5146. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5147. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5148. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5149. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5150. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5151. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5152. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5153. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5154. goto exit;
  5155. }
  5156. bench_stats_start(&count, &start);
  5157. do {
  5158. for (i = 0; i < numBlocks; i++) {
  5159. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5160. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5161. bench_additional, 0);
  5162. RECORD_MULTI_VALUE_STATS();
  5163. }
  5164. count += i;
  5165. } while (bench_stats_check(start)
  5166. #ifdef MULTI_VALUE_STATISTICS
  5167. || runs < minimum_runs
  5168. #endif
  5169. );
  5170. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5171. #ifdef MULTI_VALUE_STATISTICS
  5172. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5173. #endif
  5174. if (ret != 0) {
  5175. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5176. goto exit;
  5177. }
  5178. RESET_MULTI_VALUE_STATS_VARS();
  5179. bench_stats_start(&count, &start);
  5180. do {
  5181. for (i = 0; i < numBlocks; i++) {
  5182. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5183. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5184. bench_additional, 0);
  5185. RECORD_MULTI_VALUE_STATS();
  5186. }
  5187. count += i;
  5188. } while (bench_stats_check(start)
  5189. #ifdef MULTI_VALUE_STATISTICS
  5190. || runs < minimum_runs
  5191. #endif
  5192. );
  5193. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5194. #ifdef MULTI_VALUE_STATISTICS
  5195. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5196. #endif
  5197. if (ret != 0) {
  5198. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5199. goto exit;
  5200. }
  5201. exit:
  5202. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5203. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5204. }
  5205. #endif /* HAVE_AESCCM */
  5206. #ifndef NO_DES3
  5207. void bench_des(int useDeviceID)
  5208. {
  5209. int ret = 0, i, count = 0, times, pending = 0;
  5210. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5211. sizeof(Des3), HEAP_HINT);
  5212. double start;
  5213. DECLARE_MULTI_VALUE_STATS_VARS()
  5214. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5215. sizeof(Des3), HEAP_HINT);
  5216. /* init keys */
  5217. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5218. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5219. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5220. printf("Des3Init failed, ret = %d\n", ret);
  5221. goto exit;
  5222. }
  5223. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5224. if (ret != 0) {
  5225. printf("Des3_SetKey failed, ret = %d\n", ret);
  5226. goto exit;
  5227. }
  5228. }
  5229. bench_stats_start(&count, &start);
  5230. do {
  5231. for (times = 0; times < numBlocks || pending > 0; ) {
  5232. bench_async_poll(&pending);
  5233. /* while free pending slots in queue, submit ops */
  5234. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5235. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5236. &times, numBlocks, &pending)) {
  5237. ret = wc_Des3_CbcEncrypt(enc[i],
  5238. bench_cipher,
  5239. bench_plain, bench_size);
  5240. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5241. 0, &times, &pending)) {
  5242. goto exit_3des;
  5243. }
  5244. }
  5245. } /* for i */
  5246. RECORD_MULTI_VALUE_STATS();
  5247. } /* for times */
  5248. count += times;
  5249. } while (bench_stats_check(start)
  5250. #ifdef MULTI_VALUE_STATISTICS
  5251. || runs < minimum_runs
  5252. #endif
  5253. );
  5254. exit_3des:
  5255. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5256. #ifdef MULTI_VALUE_STATISTICS
  5257. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5258. #endif
  5259. exit:
  5260. if (WC_ARRAY_OK(enc)) {
  5261. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5262. wc_Des3Free(enc[i]);
  5263. }
  5264. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5265. }
  5266. }
  5267. #endif /* !NO_DES3 */
  5268. #ifndef NO_RC4
  5269. void bench_arc4(int useDeviceID)
  5270. {
  5271. int ret = 0, i, count = 0, times, pending = 0;
  5272. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5273. sizeof(Arc4), HEAP_HINT);
  5274. double start;
  5275. DECLARE_MULTI_VALUE_STATS_VARS()
  5276. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5277. sizeof(Arc4), HEAP_HINT);
  5278. /* init keys */
  5279. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5280. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5281. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5282. printf("Arc4Init failed, ret = %d\n", ret);
  5283. goto exit;
  5284. }
  5285. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5286. if (ret != 0) {
  5287. printf("Arc4SetKey failed, ret = %d\n", ret);
  5288. goto exit;
  5289. }
  5290. }
  5291. bench_stats_start(&count, &start);
  5292. do {
  5293. for (times = 0; times < numBlocks || pending > 0; ) {
  5294. bench_async_poll(&pending);
  5295. /* while free pending slots in queue, submit ops */
  5296. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5297. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5298. &times, numBlocks, &pending)) {
  5299. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5300. bench_size);
  5301. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5302. 0, &times, &pending)) {
  5303. goto exit_arc4;
  5304. }
  5305. }
  5306. } /* for i */
  5307. RECORD_MULTI_VALUE_STATS();
  5308. } /* for times */
  5309. count += times;
  5310. } while (bench_stats_check(start)
  5311. #ifdef MULTI_VALUE_STATISTICS
  5312. || runs < minimum_runs
  5313. #endif
  5314. );
  5315. exit_arc4:
  5316. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5317. #ifdef MULTI_VALUE_STATISTICS
  5318. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5319. #endif
  5320. exit:
  5321. if (WC_ARRAY_OK(enc)) {
  5322. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5323. wc_Arc4Free(enc[i]);
  5324. }
  5325. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5326. }
  5327. }
  5328. #endif /* !NO_RC4 */
  5329. #ifdef HAVE_CHACHA
  5330. void bench_chacha(void)
  5331. {
  5332. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5333. double start;
  5334. int ret, i, count;
  5335. DECLARE_MULTI_VALUE_STATS_VARS()
  5336. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5337. XMEMSET(enc, 0, sizeof(ChaCha));
  5338. wc_Chacha_SetKey(enc, bench_key, 16);
  5339. if (encrypt_only) {
  5340. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5341. if (ret < 0) {
  5342. printf("wc_Chacha_SetIV error: %d\n", ret);
  5343. goto exit;
  5344. }
  5345. bench_stats_start(&count, &start);
  5346. do {
  5347. for (i = 0; i < numBlocks; i++) {
  5348. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5349. bench_size);
  5350. if (ret < 0) {
  5351. printf("wc_Chacha_Process error: %d\n", ret);
  5352. goto exit;
  5353. }
  5354. RECORD_MULTI_VALUE_STATS();
  5355. }
  5356. count += i;
  5357. } while (bench_stats_check(start)
  5358. #ifdef MULTI_VALUE_STATISTICS
  5359. || runs < minimum_runs
  5360. #endif
  5361. );
  5362. }
  5363. else {
  5364. bench_stats_start(&count, &start);
  5365. do {
  5366. for (i = 0; i < numBlocks; i++) {
  5367. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5368. if (ret < 0) {
  5369. printf("wc_Chacha_SetIV error: %d\n", ret);
  5370. goto exit;
  5371. }
  5372. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5373. bench_size);
  5374. if (ret < 0) {
  5375. printf("wc_Chacha_Process error: %d\n", ret);
  5376. goto exit;
  5377. }
  5378. RECORD_MULTI_VALUE_STATS();
  5379. }
  5380. count += i;
  5381. } while (bench_stats_check(start)
  5382. #ifdef MULTI_VALUE_STATISTICS
  5383. || runs < minimum_runs
  5384. #endif
  5385. );
  5386. }
  5387. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5388. #ifdef MULTI_VALUE_STATISTICS
  5389. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5390. #endif
  5391. exit:
  5392. WC_FREE_VAR(enc, HEAP_HINT);
  5393. }
  5394. #endif /* HAVE_CHACHA*/
  5395. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5396. void bench_chacha20_poly1305_aead(void)
  5397. {
  5398. double start;
  5399. int ret = 0, i, count;
  5400. DECLARE_MULTI_VALUE_STATS_VARS()
  5401. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5402. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5403. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5404. bench_stats_start(&count, &start);
  5405. do {
  5406. for (i = 0; i < numBlocks; i++) {
  5407. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5408. bench_plain, bench_size, bench_cipher, authTag);
  5409. if (ret < 0) {
  5410. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5411. goto exit;
  5412. }
  5413. RECORD_MULTI_VALUE_STATS();
  5414. }
  5415. count += i;
  5416. } while (bench_stats_check(start)
  5417. #ifdef MULTI_VALUE_STATISTICS
  5418. || runs < minimum_runs
  5419. #endif
  5420. );
  5421. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5422. #ifdef MULTI_VALUE_STATISTICS
  5423. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5424. #endif
  5425. exit:
  5426. WC_FREE_VAR(authTag, HEAP_HINT);
  5427. }
  5428. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5429. #ifndef NO_MD5
  5430. void bench_md5(int useDeviceID)
  5431. {
  5432. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5433. sizeof(wc_Md5), HEAP_HINT);
  5434. double start = 0;
  5435. int ret = 0, i, count = 0, times, pending = 0;
  5436. DECLARE_MULTI_VALUE_STATS_VARS()
  5437. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5438. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5439. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5440. sizeof(wc_Md5), HEAP_HINT);
  5441. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5442. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5443. if (digest_stream) {
  5444. /* init keys */
  5445. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5446. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5447. useDeviceID ? devId : INVALID_DEVID);
  5448. if (ret != 0) {
  5449. printf("InitMd5_ex failed, ret = %d\n", ret);
  5450. goto exit;
  5451. }
  5452. #ifdef WOLFSSL_PIC32MZ_HASH
  5453. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5454. #endif
  5455. }
  5456. bench_stats_start(&count, &start);
  5457. do {
  5458. for (times = 0; times < numBlocks || pending > 0; ) {
  5459. bench_async_poll(&pending);
  5460. /* while free pending slots in queue, submit ops */
  5461. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5462. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5463. 0, &times, numBlocks, &pending)) {
  5464. ret = wc_Md5Update(hash[i], bench_plain,
  5465. bench_size);
  5466. if (!bench_async_handle(&ret,
  5467. BENCH_ASYNC_GET_DEV(hash[i]),
  5468. 0, &times, &pending)) {
  5469. goto exit_md5;
  5470. }
  5471. }
  5472. } /* for i */
  5473. RECORD_MULTI_VALUE_STATS();
  5474. } /* for times */
  5475. count += times;
  5476. times = 0;
  5477. do {
  5478. bench_async_poll(&pending);
  5479. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5480. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5481. 0, &times, numBlocks, &pending)) {
  5482. ret = wc_Md5Final(hash[i], digest[i]);
  5483. if (!bench_async_handle(&ret,
  5484. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5485. &times, &pending)) {
  5486. goto exit_md5;
  5487. }
  5488. }
  5489. } /* for i */
  5490. } while (pending > 0);
  5491. } while (bench_stats_check(start)
  5492. #ifdef MULTI_VALUE_STATISTICS
  5493. || runs < minimum_runs
  5494. #endif
  5495. );
  5496. }
  5497. else {
  5498. bench_stats_start(&count, &start);
  5499. do {
  5500. for (times = 0; times < numBlocks; times++) {
  5501. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5502. if (ret == 0)
  5503. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5504. if (ret == 0)
  5505. ret = wc_Md5Final(hash[0], digest[0]);
  5506. if (ret != 0)
  5507. goto exit_md5;
  5508. RECORD_MULTI_VALUE_STATS();
  5509. } /* for times */
  5510. count += times;
  5511. } while (bench_stats_check(start)
  5512. #ifdef MULTI_VALUE_STATISTICS
  5513. || runs < minimum_runs
  5514. #endif
  5515. );
  5516. }
  5517. exit_md5:
  5518. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5519. #ifdef MULTI_VALUE_STATISTICS
  5520. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5521. #endif
  5522. exit:
  5523. #ifdef WOLFSSL_ASYNC_CRYPT
  5524. if (WC_ARRAY_OK(hash)) {
  5525. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5526. wc_Md5Free(hash[i]);
  5527. }
  5528. }
  5529. #endif
  5530. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5531. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5532. }
  5533. #endif /* !NO_MD5 */
  5534. #ifndef NO_SHA
  5535. void bench_sha(int useDeviceID)
  5536. {
  5537. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5538. sizeof(wc_Sha), HEAP_HINT);
  5539. double start;
  5540. int ret = 0, i, count = 0, times, pending = 0;
  5541. DECLARE_MULTI_VALUE_STATS_VARS()
  5542. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5543. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5544. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5545. sizeof(wc_Sha), HEAP_HINT);
  5546. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5547. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5548. if (digest_stream) {
  5549. /* init keys */
  5550. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5551. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5552. useDeviceID ? devId : INVALID_DEVID);
  5553. if (ret != 0) {
  5554. printf("InitSha failed, ret = %d\n", ret);
  5555. goto exit;
  5556. }
  5557. #ifdef WOLFSSL_PIC32MZ_HASH
  5558. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5559. #endif
  5560. }
  5561. bench_stats_start(&count, &start);
  5562. do {
  5563. for (times = 0; times < numBlocks || pending > 0; ) {
  5564. bench_async_poll(&pending);
  5565. /* while free pending slots in queue, submit ops */
  5566. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5567. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5568. 0, &times, numBlocks, &pending)) {
  5569. ret = wc_ShaUpdate(hash[i], bench_plain,
  5570. bench_size);
  5571. if (!bench_async_handle(&ret,
  5572. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5573. &times, &pending)) {
  5574. goto exit_sha;
  5575. }
  5576. }
  5577. } /* for i */
  5578. RECORD_MULTI_VALUE_STATS();
  5579. } /* for times */
  5580. count += times;
  5581. times = 0;
  5582. do {
  5583. bench_async_poll(&pending);
  5584. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5585. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5586. 0, &times, numBlocks, &pending)) {
  5587. ret = wc_ShaFinal(hash[i], digest[i]);
  5588. if (!bench_async_handle(&ret,
  5589. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5590. &times, &pending)) {
  5591. goto exit_sha;
  5592. }
  5593. }
  5594. } /* for i */
  5595. } while (pending > 0);
  5596. } while (bench_stats_check(start)
  5597. #ifdef MULTI_VALUE_STATISTICS
  5598. || runs < minimum_runs
  5599. #endif
  5600. );
  5601. }
  5602. else {
  5603. bench_stats_start(&count, &start);
  5604. do {
  5605. for (times = 0; times < numBlocks; times++) {
  5606. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5607. useDeviceID ? devId : INVALID_DEVID);
  5608. if (ret == 0)
  5609. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5610. if (ret == 0)
  5611. ret = wc_ShaFinal(hash[0], digest[0]);
  5612. if (ret != 0)
  5613. goto exit_sha;
  5614. RECORD_MULTI_VALUE_STATS();
  5615. } /* for times */
  5616. count += times;
  5617. } while (bench_stats_check(start)
  5618. #ifdef MULTI_VALUE_STATISTICS
  5619. || runs < minimum_runs
  5620. #endif
  5621. );
  5622. }
  5623. exit_sha:
  5624. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5625. #ifdef MULTI_VALUE_STATISTICS
  5626. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5627. #endif
  5628. exit:
  5629. if (WC_ARRAY_OK(hash)) {
  5630. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5631. wc_ShaFree(hash[i]);
  5632. }
  5633. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5634. }
  5635. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5636. }
  5637. #endif /* NO_SHA */
  5638. #ifdef WOLFSSL_SHA224
  5639. void bench_sha224(int useDeviceID)
  5640. {
  5641. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5642. sizeof(wc_Sha224), HEAP_HINT);
  5643. double start;
  5644. int ret = 0, i, count = 0, times, pending = 0;
  5645. DECLARE_MULTI_VALUE_STATS_VARS()
  5646. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5647. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5648. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5649. sizeof(wc_Sha224), HEAP_HINT);
  5650. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5651. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5652. if (digest_stream) {
  5653. /* init keys */
  5654. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5655. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5656. useDeviceID ? devId : INVALID_DEVID);
  5657. if (ret != 0) {
  5658. printf("InitSha224_ex failed, ret = %d\n", ret);
  5659. goto exit;
  5660. }
  5661. }
  5662. bench_stats_start(&count, &start);
  5663. do {
  5664. for (times = 0; times < numBlocks || pending > 0; ) {
  5665. bench_async_poll(&pending);
  5666. /* while free pending slots in queue, submit ops */
  5667. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5668. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5669. 0, &times, numBlocks, &pending)) {
  5670. ret = wc_Sha224Update(hash[i], bench_plain,
  5671. bench_size);
  5672. if (!bench_async_handle(&ret,
  5673. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5674. &times, &pending)) {
  5675. goto exit_sha224;
  5676. }
  5677. }
  5678. } /* for i */
  5679. RECORD_MULTI_VALUE_STATS();
  5680. } /* for times */
  5681. count += times;
  5682. times = 0;
  5683. do {
  5684. bench_async_poll(&pending);
  5685. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5686. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5687. 0, &times, numBlocks, &pending)) {
  5688. ret = wc_Sha224Final(hash[i], digest[i]);
  5689. if (!bench_async_handle(&ret,
  5690. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5691. &times, &pending)) {
  5692. goto exit_sha224;
  5693. }
  5694. }
  5695. } /* for i */
  5696. } while (pending > 0);
  5697. } while (bench_stats_check(start)
  5698. #ifdef MULTI_VALUE_STATISTICS
  5699. || runs < minimum_runs
  5700. #endif
  5701. );
  5702. }
  5703. else {
  5704. bench_stats_start(&count, &start);
  5705. do {
  5706. for (times = 0; times < numBlocks; times++) {
  5707. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5708. useDeviceID ? devId : INVALID_DEVID);
  5709. if (ret == 0)
  5710. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5711. if (ret == 0)
  5712. ret = wc_Sha224Final(hash[0], digest[0]);
  5713. if (ret != 0)
  5714. goto exit_sha224;
  5715. } /* for times */
  5716. count += times;
  5717. } while (bench_stats_check(start)
  5718. #ifdef MULTI_VALUE_STATISTICS
  5719. || runs < minimum_runs
  5720. #endif
  5721. );
  5722. }
  5723. exit_sha224:
  5724. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5725. bench_size, start, ret);
  5726. #ifdef MULTI_VALUE_STATISTICS
  5727. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5728. #endif
  5729. exit:
  5730. if (WC_ARRAY_OK(hash)) {
  5731. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5732. wc_Sha224Free(hash[i]);
  5733. }
  5734. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5735. }
  5736. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5737. }
  5738. #endif
  5739. #ifndef NO_SHA256
  5740. void bench_sha256(int useDeviceID)
  5741. {
  5742. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5743. sizeof(wc_Sha256), HEAP_HINT);
  5744. double start;
  5745. int ret = 0, i, count = 0, times, pending = 0;
  5746. DECLARE_MULTI_VALUE_STATS_VARS()
  5747. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5748. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5749. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5750. sizeof(wc_Sha256), HEAP_HINT);
  5751. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5752. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5753. if (digest_stream) {
  5754. /* init keys */
  5755. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5756. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5757. useDeviceID ? devId: INVALID_DEVID);
  5758. if (ret != 0) {
  5759. printf("InitSha256_ex failed, ret = %d\n", ret);
  5760. goto exit;
  5761. }
  5762. #ifdef WOLFSSL_PIC32MZ_HASH
  5763. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5764. #endif
  5765. }
  5766. bench_stats_start(&count, &start);
  5767. do {
  5768. for (times = 0; times < numBlocks || pending > 0; ) {
  5769. bench_async_poll(&pending);
  5770. /* while free pending slots in queue, submit ops */
  5771. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5772. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5773. 0, &times, numBlocks, &pending)) {
  5774. ret = wc_Sha256Update(hash[i], bench_plain,
  5775. bench_size);
  5776. if (!bench_async_handle(&ret,
  5777. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5778. &times, &pending)) {
  5779. goto exit_sha256;
  5780. }
  5781. }
  5782. } /* for i */
  5783. RECORD_MULTI_VALUE_STATS();
  5784. } /* for times */
  5785. count += times;
  5786. times = 0;
  5787. do {
  5788. bench_async_poll(&pending);
  5789. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5790. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5791. 0, &times, numBlocks, &pending)) {
  5792. ret = wc_Sha256Final(hash[i], digest[i]);
  5793. if (!bench_async_handle(&ret,
  5794. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5795. &times, &pending)) {
  5796. goto exit_sha256;
  5797. }
  5798. }
  5799. } /* for i */
  5800. } while (pending > 0);
  5801. } while (bench_stats_check(start)
  5802. #ifdef MULTI_VALUE_STATISTICS
  5803. || runs < minimum_runs
  5804. #endif
  5805. );
  5806. }
  5807. else {
  5808. bench_stats_start(&count, &start);
  5809. do {
  5810. for (times = 0; times < numBlocks; times++) {
  5811. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5812. useDeviceID ? devId: INVALID_DEVID);
  5813. if (ret == 0)
  5814. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5815. if (ret == 0)
  5816. ret = wc_Sha256Final(hash[0], digest[0]);
  5817. if (ret != 0)
  5818. goto exit_sha256;
  5819. RECORD_MULTI_VALUE_STATS();
  5820. } /* for times */
  5821. count += times;
  5822. } while (bench_stats_check(start)
  5823. #ifdef MULTI_VALUE_STATISTICS
  5824. || runs < minimum_runs
  5825. #endif
  5826. );
  5827. }
  5828. exit_sha256:
  5829. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5830. start, ret);
  5831. #ifdef MULTI_VALUE_STATISTICS
  5832. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5833. #endif
  5834. exit:
  5835. if (WC_ARRAY_OK(hash)) {
  5836. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5837. wc_Sha256Free(hash[i]);
  5838. }
  5839. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5840. }
  5841. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5842. }
  5843. #endif
  5844. #ifdef WOLFSSL_SHA384
  5845. void bench_sha384(int useDeviceID)
  5846. {
  5847. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5848. sizeof(wc_Sha384), HEAP_HINT);
  5849. double start;
  5850. int ret = 0, i, count = 0, times, pending = 0;
  5851. DECLARE_MULTI_VALUE_STATS_VARS()
  5852. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5853. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5854. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5855. sizeof(wc_Sha384), HEAP_HINT);
  5856. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5857. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5858. if (digest_stream) {
  5859. /* init keys */
  5860. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5861. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5862. useDeviceID ? devId : INVALID_DEVID);
  5863. if (ret != 0) {
  5864. printf("InitSha384_ex failed, ret = %d\n", ret);
  5865. goto exit;
  5866. }
  5867. }
  5868. bench_stats_start(&count, &start);
  5869. do {
  5870. for (times = 0; times < numBlocks || pending > 0; ) {
  5871. bench_async_poll(&pending);
  5872. /* while free pending slots in queue, submit ops */
  5873. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5874. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5875. 0, &times, numBlocks, &pending)) {
  5876. ret = wc_Sha384Update(hash[i], bench_plain,
  5877. bench_size);
  5878. if (!bench_async_handle(&ret,
  5879. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5880. &times, &pending)) {
  5881. goto exit_sha384;
  5882. }
  5883. }
  5884. } /* for i */
  5885. RECORD_MULTI_VALUE_STATS();
  5886. } /* for times */
  5887. count += times;
  5888. times = 0;
  5889. do {
  5890. bench_async_poll(&pending);
  5891. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5892. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5893. 0, &times, numBlocks, &pending)) {
  5894. ret = wc_Sha384Final(hash[i], digest[i]);
  5895. if (!bench_async_handle(&ret,
  5896. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5897. &times, &pending)) {
  5898. goto exit_sha384;
  5899. }
  5900. }
  5901. } /* for i */
  5902. } while (pending > 0);
  5903. } while (bench_stats_check(start)
  5904. #ifdef MULTI_VALUE_STATISTICS
  5905. || runs < minimum_runs
  5906. #endif
  5907. );
  5908. }
  5909. else {
  5910. bench_stats_start(&count, &start);
  5911. do {
  5912. for (times = 0; times < numBlocks; times++) {
  5913. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5914. useDeviceID ? devId : INVALID_DEVID);
  5915. if (ret == 0)
  5916. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5917. if (ret == 0)
  5918. ret = wc_Sha384Final(hash[0], digest[0]);
  5919. if (ret != 0)
  5920. goto exit_sha384;
  5921. RECORD_MULTI_VALUE_STATS();
  5922. } /* for times */
  5923. count += times;
  5924. } while (bench_stats_check(start)
  5925. #ifdef MULTI_VALUE_STATISTICS
  5926. || runs < minimum_runs
  5927. #endif
  5928. );
  5929. }
  5930. exit_sha384:
  5931. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5932. start, ret);
  5933. #ifdef MULTI_VALUE_STATISTICS
  5934. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5935. #endif
  5936. exit:
  5937. if (WC_ARRAY_OK(hash)) {
  5938. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5939. wc_Sha384Free(hash[i]);
  5940. }
  5941. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5942. }
  5943. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5944. }
  5945. #endif
  5946. #ifdef WOLFSSL_SHA512
  5947. void bench_sha512(int useDeviceID)
  5948. {
  5949. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5950. sizeof(wc_Sha512), HEAP_HINT);
  5951. double start;
  5952. int ret = 0, i, count = 0, times, pending = 0;
  5953. DECLARE_MULTI_VALUE_STATS_VARS()
  5954. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5955. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5956. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5957. sizeof(wc_Sha512), HEAP_HINT);
  5958. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5959. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5960. if (digest_stream) {
  5961. /* init keys */
  5962. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5963. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5964. useDeviceID ? devId : INVALID_DEVID);
  5965. if (ret != 0) {
  5966. printf("InitSha512_ex failed, ret = %d\n", ret);
  5967. goto exit;
  5968. }
  5969. }
  5970. bench_stats_start(&count, &start);
  5971. do {
  5972. for (times = 0; times < numBlocks || pending > 0; ) {
  5973. bench_async_poll(&pending);
  5974. /* while free pending slots in queue, submit ops */
  5975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5976. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5977. 0, &times, numBlocks, &pending)) {
  5978. ret = wc_Sha512Update(hash[i], bench_plain,
  5979. bench_size);
  5980. if (!bench_async_handle(&ret,
  5981. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5982. &times, &pending)) {
  5983. goto exit_sha512;
  5984. }
  5985. }
  5986. } /* for i */
  5987. RECORD_MULTI_VALUE_STATS();
  5988. } /* for times */
  5989. count += times;
  5990. times = 0;
  5991. do {
  5992. bench_async_poll(&pending);
  5993. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5994. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5995. 0, &times, numBlocks, &pending)) {
  5996. ret = wc_Sha512Final(hash[i], digest[i]);
  5997. if (!bench_async_handle(&ret,
  5998. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5999. &times, &pending)) {
  6000. goto exit_sha512;
  6001. }
  6002. }
  6003. } /* for i */
  6004. } while (pending > 0);
  6005. } while (bench_stats_check(start)
  6006. #ifdef MULTI_VALUE_STATISTICS
  6007. || runs < minimum_runs
  6008. #endif
  6009. );
  6010. }
  6011. else {
  6012. bench_stats_start(&count, &start);
  6013. do {
  6014. for (times = 0; times < numBlocks; times++) {
  6015. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  6016. useDeviceID ? devId : INVALID_DEVID);
  6017. if (ret == 0)
  6018. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  6019. if (ret == 0)
  6020. ret = wc_Sha512Final(hash[0], digest[0]);
  6021. if (ret != 0)
  6022. goto exit_sha512;
  6023. RECORD_MULTI_VALUE_STATS();
  6024. } /* for times */
  6025. count += times;
  6026. } while (bench_stats_check(start)
  6027. #ifdef MULTI_VALUE_STATISTICS
  6028. || runs < minimum_runs
  6029. #endif
  6030. );
  6031. }
  6032. exit_sha512:
  6033. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  6034. start, ret);
  6035. #ifdef MULTI_VALUE_STATISTICS
  6036. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6037. #endif
  6038. exit:
  6039. if (WC_ARRAY_OK(hash)) {
  6040. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6041. wc_Sha512Free(hash[i]);
  6042. }
  6043. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6044. }
  6045. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6046. }
  6047. #if !defined(WOLFSSL_NOSHA512_224) && \
  6048. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6049. void bench_sha512_224(int useDeviceID)
  6050. {
  6051. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6052. sizeof(wc_Sha512_224), HEAP_HINT);
  6053. double start;
  6054. int ret = 0, i, count = 0, times, pending = 0;
  6055. DECLARE_MULTI_VALUE_STATS_VARS()
  6056. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6057. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6058. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6059. sizeof(wc_Sha512_224), HEAP_HINT);
  6060. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6061. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6062. if (digest_stream) {
  6063. /* init keys */
  6064. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6065. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6066. useDeviceID ? devId : INVALID_DEVID);
  6067. if (ret != 0) {
  6068. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6069. goto exit;
  6070. }
  6071. }
  6072. bench_stats_start(&count, &start);
  6073. do {
  6074. for (times = 0; times < numBlocks || pending > 0; ) {
  6075. bench_async_poll(&pending);
  6076. /* while free pending slots in queue, submit ops */
  6077. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6078. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6079. 0, &times, numBlocks, &pending)) {
  6080. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6081. bench_size);
  6082. if (!bench_async_handle(&ret,
  6083. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6084. &times, &pending)) {
  6085. goto exit_sha512_224;
  6086. }
  6087. }
  6088. } /* for i */
  6089. RECORD_MULTI_VALUE_STATS();
  6090. } /* for times */
  6091. count += times;
  6092. times = 0;
  6093. do {
  6094. bench_async_poll(&pending);
  6095. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6096. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6097. 0, &times, numBlocks, &pending)) {
  6098. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6099. if (!bench_async_handle(&ret,
  6100. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6101. &times, &pending)) {
  6102. goto exit_sha512_224;
  6103. }
  6104. }
  6105. } /* for i */
  6106. } while (pending > 0);
  6107. } while (bench_stats_check(start)
  6108. #ifdef MULTI_VALUE_STATISTICS
  6109. || runs < minimum_runs
  6110. #endif
  6111. );
  6112. }
  6113. else {
  6114. bench_stats_start(&count, &start);
  6115. do {
  6116. for (times = 0; times < numBlocks; times++) {
  6117. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6118. useDeviceID ? devId : INVALID_DEVID);
  6119. if (ret == 0)
  6120. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6121. if (ret == 0)
  6122. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6123. if (ret != 0)
  6124. goto exit_sha512_224;
  6125. RECORD_MULTI_VALUE_STATS();
  6126. } /* for times */
  6127. count += times;
  6128. } while (bench_stats_check(start)
  6129. #ifdef MULTI_VALUE_STATISTICS
  6130. || runs < minimum_runs
  6131. #endif
  6132. );
  6133. }
  6134. exit_sha512_224:
  6135. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6136. start, ret);
  6137. #ifdef MULTI_VALUE_STATISTICS
  6138. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6139. #endif
  6140. exit:
  6141. if (WC_ARRAY_OK(hash)) {
  6142. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6143. wc_Sha512_224Free(hash[i]);
  6144. }
  6145. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6146. }
  6147. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6148. }
  6149. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6150. #if !defined(WOLFSSL_NOSHA512_256) && \
  6151. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6152. void bench_sha512_256(int useDeviceID)
  6153. {
  6154. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6155. sizeof(wc_Sha512_256), HEAP_HINT);
  6156. double start;
  6157. int ret = 0, i, count = 0, times, pending = 0;
  6158. DECLARE_MULTI_VALUE_STATS_VARS()
  6159. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6160. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6161. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6162. sizeof(wc_Sha512_256), HEAP_HINT);
  6163. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6164. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6165. if (digest_stream) {
  6166. /* init keys */
  6167. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6168. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6169. useDeviceID ? devId : INVALID_DEVID);
  6170. if (ret != 0) {
  6171. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6172. goto exit;
  6173. }
  6174. }
  6175. bench_stats_start(&count, &start);
  6176. do {
  6177. for (times = 0; times < numBlocks || pending > 0; ) {
  6178. bench_async_poll(&pending);
  6179. /* while free pending slots in queue, submit ops */
  6180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6181. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6182. 0, &times, numBlocks, &pending)) {
  6183. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6184. bench_size);
  6185. if (!bench_async_handle(&ret,
  6186. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6187. &times, &pending)) {
  6188. goto exit_sha512_256;
  6189. }
  6190. }
  6191. } /* for i */
  6192. RECORD_MULTI_VALUE_STATS();
  6193. } /* for times */
  6194. count += times;
  6195. times = 0;
  6196. do {
  6197. bench_async_poll(&pending);
  6198. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6199. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6200. 0, &times, numBlocks, &pending)) {
  6201. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6202. if (!bench_async_handle(&ret,
  6203. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6204. &times, &pending)) {
  6205. goto exit_sha512_256;
  6206. }
  6207. }
  6208. } /* for i */
  6209. } while (pending > 0);
  6210. } while (bench_stats_check(start)
  6211. #ifdef MULTI_VALUE_STATISTICS
  6212. || runs < minimum_runs
  6213. #endif
  6214. );
  6215. }
  6216. else {
  6217. bench_stats_start(&count, &start);
  6218. do {
  6219. for (times = 0; times < numBlocks; times++) {
  6220. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6221. useDeviceID ? devId : INVALID_DEVID);
  6222. if (ret == 0)
  6223. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6224. if (ret == 0)
  6225. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6226. if (ret != 0)
  6227. goto exit_sha512_256;
  6228. RECORD_MULTI_VALUE_STATS();
  6229. } /* for times */
  6230. count += times;
  6231. } while (bench_stats_check(start)
  6232. #ifdef MULTI_VALUE_STATISTICS
  6233. || runs < minimum_runs
  6234. #endif
  6235. );
  6236. }
  6237. exit_sha512_256:
  6238. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6239. start, ret);
  6240. #ifdef MULTI_VALUE_STATISTICS
  6241. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6242. #endif
  6243. exit:
  6244. if (WC_ARRAY_OK(hash)) {
  6245. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6246. wc_Sha512_256Free(hash[i]);
  6247. }
  6248. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6249. }
  6250. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6251. }
  6252. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6253. #endif /* WOLFSSL_SHA512 */
  6254. #ifdef WOLFSSL_SHA3
  6255. #ifndef WOLFSSL_NOSHA3_224
  6256. void bench_sha3_224(int useDeviceID)
  6257. {
  6258. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6259. sizeof(wc_Sha3), HEAP_HINT);
  6260. double start;
  6261. int ret = 0, i, count = 0, times, pending = 0;
  6262. DECLARE_MULTI_VALUE_STATS_VARS()
  6263. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6264. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6265. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6266. sizeof(wc_Sha3), HEAP_HINT);
  6267. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6268. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6269. if (digest_stream) {
  6270. /* init keys */
  6271. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6272. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6273. useDeviceID ? devId : INVALID_DEVID);
  6274. if (ret != 0) {
  6275. printf("InitSha3_224 failed, ret = %d\n", ret);
  6276. goto exit;
  6277. }
  6278. }
  6279. bench_stats_start(&count, &start);
  6280. do {
  6281. for (times = 0; times < numBlocks || pending > 0; ) {
  6282. bench_async_poll(&pending);
  6283. /* while free pending slots in queue, submit ops */
  6284. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6285. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6286. 0, &times, numBlocks, &pending)) {
  6287. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6288. bench_size);
  6289. if (!bench_async_handle(&ret,
  6290. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6291. &times, &pending)) {
  6292. goto exit_sha3_224;
  6293. }
  6294. }
  6295. } /* for i */
  6296. RECORD_MULTI_VALUE_STATS();
  6297. } /* for times */
  6298. count += times;
  6299. times = 0;
  6300. do {
  6301. bench_async_poll(&pending);
  6302. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6303. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6304. 0, &times, numBlocks, &pending)) {
  6305. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6306. if (!bench_async_handle(&ret,
  6307. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6308. &times, &pending)) {
  6309. goto exit_sha3_224;
  6310. }
  6311. }
  6312. } /* for i */
  6313. } while (pending > 0);
  6314. } while (bench_stats_check(start)
  6315. #ifdef MULTI_VALUE_STATISTICS
  6316. || runs < minimum_runs
  6317. #endif
  6318. );
  6319. }
  6320. else {
  6321. bench_stats_start(&count, &start);
  6322. do {
  6323. for (times = 0; times < numBlocks; times++) {
  6324. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6325. useDeviceID ? devId : INVALID_DEVID);
  6326. if (ret == 0)
  6327. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6328. if (ret == 0)
  6329. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6330. if (ret != 0)
  6331. goto exit_sha3_224;
  6332. RECORD_MULTI_VALUE_STATS();
  6333. } /* for times */
  6334. count += times;
  6335. } while (bench_stats_check(start)
  6336. #ifdef MULTI_VALUE_STATISTICS
  6337. || runs < minimum_runs
  6338. #endif
  6339. );
  6340. }
  6341. exit_sha3_224:
  6342. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6343. start, ret);
  6344. #ifdef MULTI_VALUE_STATISTICS
  6345. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6346. #endif
  6347. exit:
  6348. if (WC_ARRAY_OK(hash)) {
  6349. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6350. wc_Sha3_224_Free(hash[i]);
  6351. }
  6352. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6353. }
  6354. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6355. }
  6356. #endif /* WOLFSSL_NOSHA3_224 */
  6357. #ifndef WOLFSSL_NOSHA3_256
  6358. void bench_sha3_256(int useDeviceID)
  6359. {
  6360. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6361. sizeof(wc_Sha3), HEAP_HINT);
  6362. double start;
  6363. DECLARE_MULTI_VALUE_STATS_VARS()
  6364. int ret = 0, i, count = 0, times, pending = 0;
  6365. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6366. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6367. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6368. sizeof(wc_Sha3), HEAP_HINT);
  6369. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6370. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6371. if (digest_stream) {
  6372. /* init keys */
  6373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6374. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6375. useDeviceID ? devId : INVALID_DEVID);
  6376. if (ret != 0) {
  6377. printf("InitSha3_256 failed, ret = %d\n", ret);
  6378. goto exit;
  6379. }
  6380. }
  6381. bench_stats_start(&count, &start);
  6382. do {
  6383. for (times = 0; times < numBlocks || pending > 0; ) {
  6384. bench_async_poll(&pending);
  6385. /* while free pending slots in queue, submit ops */
  6386. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6387. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6388. 0, &times, numBlocks, &pending)) {
  6389. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6390. bench_size);
  6391. if (!bench_async_handle(&ret,
  6392. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6393. &times, &pending)) {
  6394. goto exit_sha3_256;
  6395. }
  6396. }
  6397. } /* for i */
  6398. RECORD_MULTI_VALUE_STATS();
  6399. } /* for times */
  6400. count += times;
  6401. times = 0;
  6402. do {
  6403. bench_async_poll(&pending);
  6404. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6405. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6406. 0, &times, numBlocks, &pending)) {
  6407. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6408. if (!bench_async_handle(&ret,
  6409. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6410. &times, &pending)) {
  6411. goto exit_sha3_256;
  6412. }
  6413. }
  6414. } /* for i */
  6415. } while (pending > 0);
  6416. } while (bench_stats_check(start)
  6417. #ifdef MULTI_VALUE_STATISTICS
  6418. || runs < minimum_runs
  6419. #endif
  6420. );
  6421. }
  6422. else {
  6423. bench_stats_start(&count, &start);
  6424. do {
  6425. for (times = 0; times < numBlocks; times++) {
  6426. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6427. useDeviceID ? devId : INVALID_DEVID);
  6428. if (ret == 0)
  6429. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6430. if (ret == 0)
  6431. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6432. if (ret != 0)
  6433. goto exit_sha3_256;
  6434. RECORD_MULTI_VALUE_STATS();
  6435. } /* for times */
  6436. count += times;
  6437. } while (bench_stats_check(start)
  6438. #ifdef MULTI_VALUE_STATISTICS
  6439. || runs < minimum_runs
  6440. #endif
  6441. );
  6442. }
  6443. exit_sha3_256:
  6444. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6445. start, ret);
  6446. #ifdef MULTI_VALUE_STATISTICS
  6447. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6448. #endif
  6449. exit:
  6450. if (WC_ARRAY_OK(hash)) {
  6451. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6452. wc_Sha3_256_Free(hash[i]);
  6453. }
  6454. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6455. }
  6456. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6457. }
  6458. #endif /* WOLFSSL_NOSHA3_256 */
  6459. #ifndef WOLFSSL_NOSHA3_384
  6460. void bench_sha3_384(int useDeviceID)
  6461. {
  6462. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6463. sizeof(wc_Sha3), HEAP_HINT);
  6464. double start;
  6465. int ret = 0, i, count = 0, times, pending = 0;
  6466. DECLARE_MULTI_VALUE_STATS_VARS()
  6467. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6468. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6469. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6470. sizeof(wc_Sha3), HEAP_HINT);
  6471. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6472. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6473. if (digest_stream) {
  6474. /* init keys */
  6475. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6476. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6477. useDeviceID ? devId : INVALID_DEVID);
  6478. if (ret != 0) {
  6479. printf("InitSha3_384 failed, ret = %d\n", ret);
  6480. goto exit;
  6481. }
  6482. }
  6483. bench_stats_start(&count, &start);
  6484. do {
  6485. for (times = 0; times < numBlocks || pending > 0; ) {
  6486. bench_async_poll(&pending);
  6487. /* while free pending slots in queue, submit ops */
  6488. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6489. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6490. 0, &times, numBlocks, &pending)) {
  6491. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6492. bench_size);
  6493. if (!bench_async_handle(&ret,
  6494. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6495. &times, &pending)) {
  6496. goto exit_sha3_384;
  6497. }
  6498. }
  6499. } /* for i */
  6500. RECORD_MULTI_VALUE_STATS();
  6501. } /* for times */
  6502. count += times;
  6503. times = 0;
  6504. do {
  6505. bench_async_poll(&pending);
  6506. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6507. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6508. 0, &times, numBlocks, &pending)) {
  6509. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6510. if (!bench_async_handle(&ret,
  6511. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6512. &times, &pending)) {
  6513. goto exit_sha3_384;
  6514. }
  6515. }
  6516. } /* for i */
  6517. } while (pending > 0);
  6518. } while (bench_stats_check(start)
  6519. #ifdef MULTI_VALUE_STATISTICS
  6520. || runs < minimum_runs
  6521. #endif
  6522. );
  6523. }
  6524. else {
  6525. bench_stats_start(&count, &start);
  6526. do {
  6527. for (times = 0; times < numBlocks; times++) {
  6528. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6529. useDeviceID ? devId : INVALID_DEVID);
  6530. if (ret == 0)
  6531. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6532. if (ret == 0)
  6533. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6534. if (ret != 0)
  6535. goto exit_sha3_384;
  6536. RECORD_MULTI_VALUE_STATS();
  6537. } /* for times */
  6538. count += times;
  6539. } while (bench_stats_check(start)
  6540. #ifdef MULTI_VALUE_STATISTICS
  6541. || runs < minimum_runs
  6542. #endif
  6543. );
  6544. }
  6545. exit_sha3_384:
  6546. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6547. start, ret);
  6548. #ifdef MULTI_VALUE_STATISTICS
  6549. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6550. #endif
  6551. exit:
  6552. if (WC_ARRAY_OK(hash)) {
  6553. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6554. wc_Sha3_384_Free(hash[i]);
  6555. }
  6556. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6557. }
  6558. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6559. }
  6560. #endif /* WOLFSSL_NOSHA3_384 */
  6561. #ifndef WOLFSSL_NOSHA3_512
  6562. void bench_sha3_512(int useDeviceID)
  6563. {
  6564. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6565. sizeof(wc_Sha3), HEAP_HINT);
  6566. double start;
  6567. int ret = 0, i, count = 0, times, pending = 0;
  6568. DECLARE_MULTI_VALUE_STATS_VARS()
  6569. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6570. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6571. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6572. sizeof(wc_Sha3), HEAP_HINT);
  6573. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6574. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6575. if (digest_stream) {
  6576. /* init keys */
  6577. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6578. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6579. useDeviceID ? devId : INVALID_DEVID);
  6580. if (ret != 0) {
  6581. printf("InitSha3_512 failed, ret = %d\n", ret);
  6582. goto exit;
  6583. }
  6584. }
  6585. bench_stats_start(&count, &start);
  6586. do {
  6587. for (times = 0; times < numBlocks || pending > 0; ) {
  6588. bench_async_poll(&pending);
  6589. /* while free pending slots in queue, submit ops */
  6590. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6591. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6592. 0, &times, numBlocks, &pending)) {
  6593. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6594. bench_size);
  6595. if (!bench_async_handle(&ret,
  6596. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6597. &times, &pending)) {
  6598. goto exit_sha3_512;
  6599. }
  6600. }
  6601. } /* for i */
  6602. RECORD_MULTI_VALUE_STATS();
  6603. } /* for times */
  6604. count += times;
  6605. times = 0;
  6606. do {
  6607. bench_async_poll(&pending);
  6608. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6609. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6610. 0, &times, numBlocks, &pending)) {
  6611. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6612. if (!bench_async_handle(&ret,
  6613. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6614. &times, &pending)) {
  6615. goto exit_sha3_512;
  6616. }
  6617. }
  6618. } /* for i */
  6619. } while (pending > 0);
  6620. } while (bench_stats_check(start)
  6621. #ifdef MULTI_VALUE_STATISTICS
  6622. || runs < minimum_runs
  6623. #endif
  6624. );
  6625. }
  6626. else {
  6627. bench_stats_start(&count, &start);
  6628. do {
  6629. for (times = 0; times < numBlocks; times++) {
  6630. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6631. useDeviceID ? devId : INVALID_DEVID);
  6632. if (ret == 0)
  6633. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6634. if (ret == 0)
  6635. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6636. if (ret != 0)
  6637. goto exit_sha3_512;
  6638. RECORD_MULTI_VALUE_STATS();
  6639. } /* for times */
  6640. count += times;
  6641. } while (bench_stats_check(start)
  6642. #ifdef MULTI_VALUE_STATISTICS
  6643. || runs < minimum_runs
  6644. #endif
  6645. );
  6646. }
  6647. exit_sha3_512:
  6648. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6649. start, ret);
  6650. #ifdef MULTI_VALUE_STATISTICS
  6651. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6652. #endif
  6653. exit:
  6654. if (WC_ARRAY_OK(hash)) {
  6655. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6656. wc_Sha3_512_Free(hash[i]);
  6657. }
  6658. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6659. }
  6660. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6661. }
  6662. #endif /* WOLFSSL_NOSHA3_512 */
  6663. #ifdef WOLFSSL_SHAKE128
  6664. void bench_shake128(int useDeviceID)
  6665. {
  6666. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6667. sizeof(wc_Shake), HEAP_HINT);
  6668. double start;
  6669. int ret = 0, i, count = 0, times, pending = 0;
  6670. DECLARE_MULTI_VALUE_STATS_VARS()
  6671. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6672. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6673. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6674. sizeof(wc_Shake), HEAP_HINT);
  6675. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6676. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6677. if (digest_stream) {
  6678. /* init keys */
  6679. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6680. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6681. useDeviceID ? devId : INVALID_DEVID);
  6682. if (ret != 0) {
  6683. printf("InitShake128 failed, ret = %d\n", ret);
  6684. goto exit;
  6685. }
  6686. }
  6687. bench_stats_start(&count, &start);
  6688. do {
  6689. for (times = 0; times < numBlocks || pending > 0; ) {
  6690. bench_async_poll(&pending);
  6691. /* while free pending slots in queue, submit ops */
  6692. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6693. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6694. 0, &times, numBlocks, &pending)) {
  6695. ret = wc_Shake128_Update(hash[i], bench_plain,
  6696. bench_size);
  6697. if (!bench_async_handle(&ret,
  6698. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6699. &times, &pending)) {
  6700. goto exit_shake128;
  6701. }
  6702. }
  6703. } /* for i */
  6704. RECORD_MULTI_VALUE_STATS();
  6705. } /* for times */
  6706. count += times;
  6707. times = 0;
  6708. do {
  6709. bench_async_poll(&pending);
  6710. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6711. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6712. 0, &times, numBlocks, &pending)) {
  6713. ret = wc_Shake128_Final(hash[i], digest[i],
  6714. WC_SHA3_128_BLOCK_SIZE);
  6715. if (!bench_async_handle(&ret,
  6716. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6717. &times, &pending)) {
  6718. goto exit_shake128;
  6719. }
  6720. }
  6721. } /* for i */
  6722. } while (pending > 0);
  6723. } while (bench_stats_check(start)
  6724. #ifdef MULTI_VALUE_STATISTICS
  6725. || runs < minimum_runs
  6726. #endif
  6727. );
  6728. }
  6729. else {
  6730. bench_stats_start(&count, &start);
  6731. do {
  6732. for (times = 0; times < numBlocks; times++) {
  6733. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6734. useDeviceID ? devId : INVALID_DEVID);
  6735. if (ret == 0)
  6736. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6737. if (ret == 0)
  6738. ret = wc_Shake128_Final(hash[0], digest[0],
  6739. WC_SHA3_128_BLOCK_SIZE);
  6740. if (ret != 0)
  6741. goto exit_shake128;
  6742. RECORD_MULTI_VALUE_STATS();
  6743. } /* for times */
  6744. count += times;
  6745. } while (bench_stats_check(start)
  6746. #ifdef MULTI_VALUE_STATISTICS
  6747. || runs < minimum_runs
  6748. #endif
  6749. );
  6750. }
  6751. exit_shake128:
  6752. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6753. start, ret);
  6754. #ifdef MULTI_VALUE_STATISTICS
  6755. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6756. #endif
  6757. exit:
  6758. if (WC_ARRAY_OK(hash)) {
  6759. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6760. wc_Shake128_Free(hash[i]);
  6761. }
  6762. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6763. }
  6764. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6765. }
  6766. #endif /* WOLFSSL_SHAKE128 */
  6767. #ifdef WOLFSSL_SHAKE256
  6768. void bench_shake256(int useDeviceID)
  6769. {
  6770. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6771. sizeof(wc_Shake), HEAP_HINT);
  6772. double start;
  6773. int ret = 0, i, count = 0, times, pending = 0;
  6774. DECLARE_MULTI_VALUE_STATS_VARS()
  6775. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6776. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6777. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6778. sizeof(wc_Shake), HEAP_HINT);
  6779. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6780. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6781. if (digest_stream) {
  6782. /* init keys */
  6783. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6784. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6785. useDeviceID ? devId : INVALID_DEVID);
  6786. if (ret != 0) {
  6787. printf("InitShake256 failed, ret = %d\n", ret);
  6788. goto exit;
  6789. }
  6790. }
  6791. bench_stats_start(&count, &start);
  6792. do {
  6793. for (times = 0; times < numBlocks || pending > 0; ) {
  6794. bench_async_poll(&pending);
  6795. /* while free pending slots in queue, submit ops */
  6796. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6797. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6798. 0, &times, numBlocks, &pending)) {
  6799. ret = wc_Shake256_Update(hash[i], bench_plain,
  6800. bench_size);
  6801. if (!bench_async_handle(&ret,
  6802. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6803. &times, &pending)) {
  6804. goto exit_shake256;
  6805. }
  6806. }
  6807. } /* for i */
  6808. RECORD_MULTI_VALUE_STATS();
  6809. } /* for times */
  6810. count += times;
  6811. times = 0;
  6812. do {
  6813. bench_async_poll(&pending);
  6814. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6815. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6816. 0, &times, numBlocks, &pending)) {
  6817. ret = wc_Shake256_Final(hash[i], digest[i],
  6818. WC_SHA3_256_BLOCK_SIZE);
  6819. if (!bench_async_handle(&ret,
  6820. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6821. &times, &pending)) {
  6822. goto exit_shake256;
  6823. }
  6824. }
  6825. } /* for i */
  6826. } while (pending > 0);
  6827. } while (bench_stats_check(start)
  6828. #ifdef MULTI_VALUE_STATISTICS
  6829. || runs < minimum_runs
  6830. #endif
  6831. );
  6832. }
  6833. else {
  6834. bench_stats_start(&count, &start);
  6835. do {
  6836. for (times = 0; times < numBlocks; times++) {
  6837. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6838. useDeviceID ? devId : INVALID_DEVID);
  6839. if (ret == 0)
  6840. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6841. if (ret == 0)
  6842. ret = wc_Shake256_Final(hash[0], digest[0],
  6843. WC_SHA3_256_BLOCK_SIZE);
  6844. if (ret != 0)
  6845. goto exit_shake256;
  6846. RECORD_MULTI_VALUE_STATS();
  6847. } /* for times */
  6848. count += times;
  6849. } while (bench_stats_check(start)
  6850. #ifdef MULTI_VALUE_STATISTICS
  6851. || runs < minimum_runs
  6852. #endif
  6853. );
  6854. }
  6855. exit_shake256:
  6856. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6857. start, ret);
  6858. #ifdef MULTI_VALUE_STATISTICS
  6859. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6860. #endif
  6861. exit:
  6862. if (WC_ARRAY_OK(hash)) {
  6863. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6864. wc_Shake256_Free(hash[i]);
  6865. }
  6866. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6867. }
  6868. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6869. }
  6870. #endif /* WOLFSSL_SHAKE256 */
  6871. #endif
  6872. #ifdef WOLFSSL_SM3
  6873. void bench_sm3(int useDeviceID)
  6874. {
  6875. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6876. sizeof(wc_Sm3), HEAP_HINT);
  6877. double start;
  6878. int ret = 0, i, count = 0, times, pending = 0;
  6879. DECLARE_MULTI_VALUE_STATS_VARS()
  6880. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6881. HEAP_HINT);
  6882. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6883. sizeof(wc_Sm3), HEAP_HINT);
  6884. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6885. HEAP_HINT);
  6886. if (digest_stream) {
  6887. /* init keys */
  6888. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6889. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6890. useDeviceID ? devId: INVALID_DEVID);
  6891. if (ret != 0) {
  6892. printf("InitSm3 failed, ret = %d\n", ret);
  6893. goto exit;
  6894. }
  6895. }
  6896. bench_stats_start(&count, &start);
  6897. do {
  6898. for (times = 0; times < numBlocks || pending > 0; ) {
  6899. bench_async_poll(&pending);
  6900. /* while free pending slots in queue, submit ops */
  6901. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6902. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6903. 0, &times, numBlocks, &pending)) {
  6904. ret = wc_Sm3Update(hash[i], bench_plain,
  6905. bench_size);
  6906. if (!bench_async_handle(&ret,
  6907. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6908. goto exit_sm3;
  6909. }
  6910. }
  6911. } /* for i */
  6912. RECORD_MULTI_VALUE_STATS();
  6913. } /* for times */
  6914. count += times;
  6915. times = 0;
  6916. do {
  6917. bench_async_poll(&pending);
  6918. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6919. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6920. 0, &times, numBlocks, &pending)) {
  6921. ret = wc_Sm3Final(hash[i], digest[i]);
  6922. if (!bench_async_handle(&ret,
  6923. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6924. goto exit_sm3;
  6925. }
  6926. }
  6927. } /* for i */
  6928. } while (pending > 0);
  6929. } while (bench_stats_check(start)
  6930. #ifdef MULTI_VALUE_STATISTICS
  6931. || runs < minimum_runs
  6932. #endif
  6933. );
  6934. }
  6935. else {
  6936. bench_stats_start(&count, &start);
  6937. do {
  6938. for (times = 0; times < numBlocks; times++) {
  6939. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6940. useDeviceID ? devId: INVALID_DEVID);
  6941. if (ret == 0)
  6942. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6943. if (ret == 0)
  6944. ret = wc_Sm3Final(hash[0], digest[0]);
  6945. if (ret != 0)
  6946. goto exit_sm3;
  6947. RECORD_MULTI_VALUE_STATS();
  6948. } /* for times */
  6949. count += times;
  6950. } while (bench_stats_check(start)
  6951. #ifdef MULTI_VALUE_STATISTICS
  6952. || runs < minimum_runs
  6953. #endif
  6954. );
  6955. }
  6956. exit_sm3:
  6957. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6958. #ifdef MULTI_VALUE_STATISTICS
  6959. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6960. #endif
  6961. exit:
  6962. if (WC_ARRAY_OK(hash)) {
  6963. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6964. wc_Sm3Free(hash[i]);
  6965. }
  6966. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6967. }
  6968. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6969. }
  6970. #endif
  6971. #ifdef WOLFSSL_RIPEMD
  6972. void bench_ripemd(void)
  6973. {
  6974. RipeMd hash;
  6975. byte digest[RIPEMD_DIGEST_SIZE];
  6976. double start;
  6977. int i, count, ret = 0;
  6978. DECLARE_MULTI_VALUE_STATS_VARS()
  6979. if (digest_stream) {
  6980. ret = wc_InitRipeMd(&hash);
  6981. if (ret != 0) {
  6982. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6983. return;
  6984. }
  6985. bench_stats_start(&count, &start);
  6986. do {
  6987. for (i = 0; i < numBlocks; i++) {
  6988. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6989. if (ret != 0) {
  6990. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6991. return;
  6992. }
  6993. RECORD_MULTI_VALUE_STATS();
  6994. }
  6995. ret = wc_RipeMdFinal(&hash, digest);
  6996. if (ret != 0) {
  6997. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6998. return;
  6999. }
  7000. count += i;
  7001. } while (bench_stats_check(start)
  7002. #ifdef MULTI_VALUE_STATISTICS
  7003. || runs < minimum_runs
  7004. #endif
  7005. );
  7006. }
  7007. else {
  7008. bench_stats_start(&count, &start);
  7009. do {
  7010. for (i = 0; i < numBlocks; i++) {
  7011. ret = wc_InitRipeMd(&hash);
  7012. if (ret != 0) {
  7013. printf("wc_InitRipeMd failed, retval %d\n", ret);
  7014. return;
  7015. }
  7016. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7017. if (ret != 0) {
  7018. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7019. return;
  7020. }
  7021. ret = wc_RipeMdFinal(&hash, digest);
  7022. if (ret != 0) {
  7023. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7024. return;
  7025. }
  7026. RECORD_MULTI_VALUE_STATS();
  7027. }
  7028. count += i;
  7029. } while (bench_stats_check(start)
  7030. #ifdef MULTI_VALUE_STATISTICS
  7031. || runs < minimum_runs
  7032. #endif
  7033. );
  7034. }
  7035. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  7036. #ifdef MULTI_VALUE_STATISTICS
  7037. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7038. #endif
  7039. return;
  7040. }
  7041. #endif
  7042. #ifdef HAVE_BLAKE2
  7043. void bench_blake2b(void)
  7044. {
  7045. Blake2b b2b;
  7046. byte digest[64];
  7047. double start;
  7048. int ret = 0, i, count;
  7049. DECLARE_MULTI_VALUE_STATS_VARS()
  7050. if (digest_stream) {
  7051. ret = wc_InitBlake2b(&b2b, 64);
  7052. if (ret != 0) {
  7053. printf("InitBlake2b failed, ret = %d\n", ret);
  7054. return;
  7055. }
  7056. bench_stats_start(&count, &start);
  7057. do {
  7058. for (i = 0; i < numBlocks; i++) {
  7059. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7060. if (ret != 0) {
  7061. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7062. return;
  7063. }
  7064. RECORD_MULTI_VALUE_STATS();
  7065. }
  7066. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7067. if (ret != 0) {
  7068. printf("Blake2bFinal failed, ret = %d\n", ret);
  7069. return;
  7070. }
  7071. count += i;
  7072. } while (bench_stats_check(start)
  7073. #ifdef MULTI_VALUE_STATISTICS
  7074. || runs < minimum_runs
  7075. #endif
  7076. );
  7077. }
  7078. else {
  7079. bench_stats_start(&count, &start);
  7080. do {
  7081. for (i = 0; i < numBlocks; i++) {
  7082. ret = wc_InitBlake2b(&b2b, 64);
  7083. if (ret != 0) {
  7084. printf("InitBlake2b failed, ret = %d\n", ret);
  7085. return;
  7086. }
  7087. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7088. if (ret != 0) {
  7089. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7090. return;
  7091. }
  7092. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7093. if (ret != 0) {
  7094. printf("Blake2bFinal failed, ret = %d\n", ret);
  7095. return;
  7096. }
  7097. RECORD_MULTI_VALUE_STATS();
  7098. }
  7099. count += i;
  7100. } while (bench_stats_check(start)
  7101. #ifdef MULTI_VALUE_STATISTICS
  7102. || runs < minimum_runs
  7103. #endif
  7104. );
  7105. }
  7106. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7107. #ifdef MULTI_VALUE_STATISTICS
  7108. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7109. #endif
  7110. }
  7111. #endif
  7112. #if defined(HAVE_BLAKE2S)
  7113. void bench_blake2s(void)
  7114. {
  7115. Blake2s b2s;
  7116. byte digest[32];
  7117. double start;
  7118. int ret = 0, i, count;
  7119. DECLARE_MULTI_VALUE_STATS_VARS()
  7120. if (digest_stream) {
  7121. ret = wc_InitBlake2s(&b2s, 32);
  7122. if (ret != 0) {
  7123. printf("InitBlake2s failed, ret = %d\n", ret);
  7124. return;
  7125. }
  7126. bench_stats_start(&count, &start);
  7127. do {
  7128. for (i = 0; i < numBlocks; i++) {
  7129. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7130. if (ret != 0) {
  7131. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7132. return;
  7133. }
  7134. RECORD_MULTI_VALUE_STATS();
  7135. }
  7136. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7137. if (ret != 0) {
  7138. printf("Blake2sFinal failed, ret = %d\n", ret);
  7139. return;
  7140. }
  7141. count += i;
  7142. } while (bench_stats_check(start)
  7143. #ifdef MULTI_VALUE_STATISTICS
  7144. || runs < minimum_runs
  7145. #endif
  7146. );
  7147. }
  7148. else {
  7149. bench_stats_start(&count, &start);
  7150. do {
  7151. for (i = 0; i < numBlocks; i++) {
  7152. ret = wc_InitBlake2s(&b2s, 32);
  7153. if (ret != 0) {
  7154. printf("InitBlake2b failed, ret = %d\n", ret);
  7155. return;
  7156. }
  7157. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7158. if (ret != 0) {
  7159. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7160. return;
  7161. }
  7162. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7163. if (ret != 0) {
  7164. printf("Blake2sFinal failed, ret = %d\n", ret);
  7165. return;
  7166. }
  7167. RECORD_MULTI_VALUE_STATS();
  7168. }
  7169. count += i;
  7170. } while (bench_stats_check(start)
  7171. #ifdef MULTI_VALUE_STATISTICS
  7172. || runs < minimum_runs
  7173. #endif
  7174. );
  7175. }
  7176. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7177. #ifdef MULTI_VALUE_STATISTICS
  7178. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7179. #endif
  7180. }
  7181. #endif
  7182. #ifdef WOLFSSL_CMAC
  7183. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7184. {
  7185. Cmac cmac;
  7186. byte digest[WC_AES_BLOCK_SIZE];
  7187. word32 digestSz = sizeof(digest);
  7188. double start;
  7189. int ret, i, count;
  7190. DECLARE_MULTI_VALUE_STATS_VARS()
  7191. #ifdef WOLFSSL_SECO_CAAM
  7192. unsigned int keyID;
  7193. int keyGroup = 1; /* group one was chosen arbitrarily */
  7194. int keyInfo = CAAM_KEY_TRANSIENT;
  7195. int keyType = CAAM_KEYTYPE_AES128;
  7196. byte pubKey[AES_256_KEY_SIZE];
  7197. if (keySz == AES_256_KEY_SIZE) {
  7198. keyType = CAAM_KEYTYPE_AES256;
  7199. }
  7200. if (useDeviceID &&
  7201. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7202. keyInfo, &keyID) != 0) {
  7203. printf("Error generating key in hsm\n");
  7204. return;
  7205. }
  7206. #endif
  7207. (void)useDeviceID;
  7208. bench_stats_start(&count, &start);
  7209. do {
  7210. #ifdef HAVE_FIPS
  7211. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7212. #else
  7213. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7214. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7215. #endif
  7216. if (ret != 0) {
  7217. printf("InitCmac failed, ret = %d\n", ret);
  7218. return;
  7219. }
  7220. #ifdef WOLFSSL_SECO_CAAM
  7221. if (useDeviceID) {
  7222. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7223. }
  7224. #endif
  7225. for (i = 0; i < numBlocks; i++) {
  7226. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7227. if (ret != 0) {
  7228. printf("CmacUpdate failed, ret = %d\n", ret);
  7229. return;
  7230. }
  7231. RECORD_MULTI_VALUE_STATS();
  7232. }
  7233. /* Note: final force zero's the Cmac struct */
  7234. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7235. if (ret != 0) {
  7236. printf("CmacFinal failed, ret = %d\n", ret);
  7237. return;
  7238. }
  7239. count += i;
  7240. } while (bench_stats_check(start)
  7241. #ifdef MULTI_VALUE_STATISTICS
  7242. || runs < minimum_runs
  7243. #endif
  7244. );
  7245. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7246. #ifdef MULTI_VALUE_STATISTICS
  7247. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7248. #endif
  7249. }
  7250. void bench_cmac(int useDeviceID)
  7251. {
  7252. #ifdef WOLFSSL_AES_128
  7253. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7254. #endif
  7255. #ifdef WOLFSSL_AES_256
  7256. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7257. #endif
  7258. }
  7259. #endif /* WOLFSSL_CMAC */
  7260. #ifdef HAVE_SCRYPT
  7261. void bench_scrypt(void)
  7262. {
  7263. byte derived[64];
  7264. double start;
  7265. int ret, i, count;
  7266. DECLARE_MULTI_VALUE_STATS_VARS()
  7267. bench_stats_start(&count, &start);
  7268. do {
  7269. for (i = 0; i < scryptCnt; i++) {
  7270. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7271. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7272. sizeof(derived));
  7273. if (ret != 0) {
  7274. printf("scrypt failed, ret = %d\n", ret);
  7275. goto exit;
  7276. }
  7277. RECORD_MULTI_VALUE_STATS();
  7278. }
  7279. count += i;
  7280. } while (bench_stats_check(start)
  7281. #ifdef MULTI_VALUE_STATISTICS
  7282. || runs < minimum_runs
  7283. #endif
  7284. );
  7285. exit:
  7286. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7287. #ifdef MULTI_VALUE_STATISTICS
  7288. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7289. #endif
  7290. }
  7291. #endif /* HAVE_SCRYPT */
  7292. #ifndef NO_HMAC
  7293. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7294. const byte* key, word32 keySz, const char* label)
  7295. {
  7296. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7297. sizeof(Hmac), HEAP_HINT);
  7298. double start;
  7299. int ret = 0, i, count = 0, times, pending = 0;
  7300. DECLARE_MULTI_VALUE_STATS_VARS()
  7301. #ifdef WOLFSSL_ASYNC_CRYPT
  7302. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7303. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7304. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7305. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7306. #else
  7307. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7308. #endif
  7309. (void)digestSz;
  7310. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7311. sizeof(Hmac), HEAP_HINT);
  7312. /* init keys */
  7313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7314. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7315. useDeviceID ? devId : INVALID_DEVID);
  7316. if (ret != 0) {
  7317. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7318. goto exit;
  7319. }
  7320. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7321. if (ret != 0) {
  7322. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7323. goto exit;
  7324. }
  7325. }
  7326. bench_stats_start(&count, &start);
  7327. do {
  7328. for (times = 0; times < numBlocks || pending > 0; ) {
  7329. bench_async_poll(&pending);
  7330. /* while free pending slots in queue, submit ops */
  7331. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7332. if (bench_async_check(&ret,
  7333. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7334. &times, numBlocks, &pending)) {
  7335. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7336. if (!bench_async_handle(&ret,
  7337. BENCH_ASYNC_GET_DEV(hmac[i]),
  7338. 0, &times, &pending)) {
  7339. goto exit_hmac;
  7340. }
  7341. }
  7342. } /* for i */
  7343. } /* for times */
  7344. count += times;
  7345. times = 0;
  7346. do {
  7347. bench_async_poll(&pending);
  7348. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7349. if (bench_async_check(&ret,
  7350. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7351. &times, numBlocks, &pending)) {
  7352. ret = wc_HmacFinal(hmac[i], digest[i]);
  7353. if (!bench_async_handle(&ret,
  7354. BENCH_ASYNC_GET_DEV(hmac[i]),
  7355. 0, &times, &pending)) {
  7356. goto exit_hmac;
  7357. }
  7358. }
  7359. RECORD_MULTI_VALUE_STATS();
  7360. } /* for i */
  7361. } while (pending > 0);
  7362. } while (bench_stats_check(start)
  7363. #ifdef MULTI_VALUE_STATISTICS
  7364. || runs < minimum_runs
  7365. #endif
  7366. );
  7367. exit_hmac:
  7368. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7369. #ifdef MULTI_VALUE_STATISTICS
  7370. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7371. #endif
  7372. exit:
  7373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7374. wc_HmacFree(hmac[i]);
  7375. }
  7376. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7377. #ifdef WOLFSSL_ASYNC_CRYPT
  7378. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7379. #endif
  7380. }
  7381. #ifndef NO_MD5
  7382. void bench_hmac_md5(int useDeviceID)
  7383. {
  7384. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7385. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7386. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7387. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7388. "HMAC-MD5");
  7389. }
  7390. #endif /* NO_MD5 */
  7391. #ifndef NO_SHA
  7392. void bench_hmac_sha(int useDeviceID)
  7393. {
  7394. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7395. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7396. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7397. 0x0b, 0x0b, 0x0b, 0x0b };
  7398. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7399. "HMAC-SHA");
  7400. }
  7401. #endif /* NO_SHA */
  7402. #ifdef WOLFSSL_SHA224
  7403. void bench_hmac_sha224(int useDeviceID)
  7404. {
  7405. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7406. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7407. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7408. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7409. 0x0b, 0x0b, 0x0b, 0x0b };
  7410. bench_hmac(useDeviceID, WC_SHA224,
  7411. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7412. "HMAC-SHA224");
  7413. }
  7414. #endif /* WOLFSSL_SHA224 */
  7415. #ifndef NO_SHA256
  7416. void bench_hmac_sha256(int useDeviceID)
  7417. {
  7418. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7419. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7420. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7421. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7422. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7423. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7424. "HMAC-SHA256");
  7425. }
  7426. #endif /* NO_SHA256 */
  7427. #ifdef WOLFSSL_SHA384
  7428. void bench_hmac_sha384(int useDeviceID)
  7429. {
  7430. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7431. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7432. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7433. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7434. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7435. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7436. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7437. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7438. "HMAC-SHA384");
  7439. }
  7440. #endif /* WOLFSSL_SHA384 */
  7441. #ifdef WOLFSSL_SHA512
  7442. void bench_hmac_sha512(int useDeviceID)
  7443. {
  7444. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7445. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7446. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7447. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7448. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7449. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7450. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7451. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7452. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7453. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7454. "HMAC-SHA512");
  7455. }
  7456. #endif /* WOLFSSL_SHA512 */
  7457. #ifndef NO_PWDBASED
  7458. void bench_pbkdf2(void)
  7459. {
  7460. double start;
  7461. int ret = 0, count = 0;
  7462. const char* passwd32 = "passwordpasswordpasswordpassword";
  7463. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7464. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7465. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7466. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7467. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7468. byte derived[32];
  7469. DECLARE_MULTI_VALUE_STATS_VARS()
  7470. bench_stats_start(&count, &start);
  7471. PRIVATE_KEY_UNLOCK();
  7472. do {
  7473. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7474. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7475. count++;
  7476. RECORD_MULTI_VALUE_STATS();
  7477. } while (bench_stats_check(start)
  7478. #ifdef MULTI_VALUE_STATISTICS
  7479. || runs < minimum_runs
  7480. #endif
  7481. );
  7482. PRIVATE_KEY_LOCK();
  7483. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7484. #ifdef MULTI_VALUE_STATISTICS
  7485. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7486. #endif
  7487. }
  7488. #endif /* !NO_PWDBASED */
  7489. #endif /* NO_HMAC */
  7490. #ifdef WOLFSSL_SIPHASH
  7491. void bench_siphash(void)
  7492. {
  7493. double start;
  7494. int ret = 0, count;
  7495. const char* passwd16 = "passwordpassword";
  7496. byte out[16];
  7497. int i;
  7498. DECLARE_MULTI_VALUE_STATS_VARS()
  7499. bench_stats_start(&count, &start);
  7500. do {
  7501. for (i = 0; i < numBlocks; i++) {
  7502. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7503. out, 8);
  7504. RECORD_MULTI_VALUE_STATS();
  7505. }
  7506. count += i;
  7507. } while (bench_stats_check(start)
  7508. #ifdef MULTI_VALUE_STATISTICS
  7509. || runs < minimum_runs
  7510. #endif
  7511. );
  7512. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7513. #ifdef MULTI_VALUE_STATISTICS
  7514. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7515. #endif
  7516. RESET_MULTI_VALUE_STATS_VARS();
  7517. bench_stats_start(&count, &start);
  7518. do {
  7519. for (i = 0; i < numBlocks; i++) {
  7520. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7521. out, 16);
  7522. RECORD_MULTI_VALUE_STATS();
  7523. }
  7524. count += i;
  7525. } while (bench_stats_check(start)
  7526. #ifdef MULTI_VALUE_STATISTICS
  7527. || runs < minimum_runs
  7528. #endif
  7529. );
  7530. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7531. #ifdef MULTI_VALUE_STATISTICS
  7532. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7533. #endif
  7534. }
  7535. #endif
  7536. #ifdef WC_SRTP_KDF
  7537. void bench_srtpkdf(void)
  7538. {
  7539. double start;
  7540. int count;
  7541. int ret = 0;
  7542. byte keyE[32];
  7543. byte keyA[20];
  7544. byte keyS[14];
  7545. const byte *key = bench_key_buf;
  7546. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7547. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7548. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7549. int kdrIdx = 0;
  7550. int i;
  7551. DECLARE_MULTI_VALUE_STATS_VARS()
  7552. bench_stats_start(&count, &start);
  7553. PRIVATE_KEY_UNLOCK();
  7554. do {
  7555. for (i = 0; i < numBlocks; i++) {
  7556. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7557. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7558. keyS, sizeof(keyS));
  7559. RECORD_MULTI_VALUE_STATS();
  7560. }
  7561. count += i;
  7562. } while (bench_stats_check(start)
  7563. #ifdef MULTI_VALUE_STATISTICS
  7564. || runs < minimum_runs
  7565. #endif
  7566. );
  7567. PRIVATE_KEY_LOCK();
  7568. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7569. #ifdef MULTI_VALUE_STATISTICS
  7570. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7571. #endif
  7572. RESET_MULTI_VALUE_STATS_VARS();
  7573. bench_stats_start(&count, &start);
  7574. PRIVATE_KEY_UNLOCK();
  7575. do {
  7576. for (i = 0; i < numBlocks; i++) {
  7577. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7578. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7579. keyS, sizeof(keyS));
  7580. RECORD_MULTI_VALUE_STATS();
  7581. }
  7582. count += i;
  7583. } while (bench_stats_check(start)
  7584. #ifdef MULTI_VALUE_STATISTICS
  7585. || runs < minimum_runs
  7586. #endif
  7587. );
  7588. PRIVATE_KEY_LOCK();
  7589. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7590. #ifdef MULTI_VALUE_STATISTICS
  7591. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7592. #endif
  7593. RESET_MULTI_VALUE_STATS_VARS();
  7594. bench_stats_start(&count, &start);
  7595. PRIVATE_KEY_UNLOCK();
  7596. do {
  7597. for (i = 0; i < numBlocks; i++) {
  7598. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7599. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7600. keyS, sizeof(keyS));
  7601. RECORD_MULTI_VALUE_STATS();
  7602. }
  7603. count += i;
  7604. } while (bench_stats_check(start)
  7605. #ifdef MULTI_VALUE_STATISTICS
  7606. || runs < minimum_runs
  7607. #endif
  7608. );
  7609. PRIVATE_KEY_LOCK();
  7610. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7611. #ifdef MULTI_VALUE_STATISTICS
  7612. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7613. #endif
  7614. RESET_MULTI_VALUE_STATS_VARS();
  7615. bench_stats_start(&count, &start);
  7616. PRIVATE_KEY_UNLOCK();
  7617. do {
  7618. for (i = 0; i < numBlocks; i++) {
  7619. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7620. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7621. keyS, sizeof(keyS));
  7622. RECORD_MULTI_VALUE_STATS();
  7623. }
  7624. count += i;
  7625. } while (bench_stats_check(start)
  7626. #ifdef MULTI_VALUE_STATISTICS
  7627. || runs < minimum_runs
  7628. #endif
  7629. );
  7630. PRIVATE_KEY_LOCK();
  7631. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7632. #ifdef MULTI_VALUE_STATISTICS
  7633. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7634. #endif
  7635. }
  7636. #endif
  7637. #ifndef NO_RSA
  7638. #if defined(WOLFSSL_KEY_GEN)
  7639. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7640. {
  7641. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7642. sizeof(RsaKey), HEAP_HINT);
  7643. double start = 0;
  7644. int ret = 0, i, count = 0, times, pending = 0;
  7645. const long rsa_e_val = WC_RSA_EXPONENT;
  7646. const char**desc = bench_desc_words[lng_index];
  7647. DECLARE_MULTI_VALUE_STATS_VARS()
  7648. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7649. sizeof(RsaKey), HEAP_HINT);
  7650. bench_stats_start(&count, &start);
  7651. do {
  7652. /* while free pending slots in queue, submit ops */
  7653. for (times = 0; times < genTimes || pending > 0; ) {
  7654. bench_async_poll(&pending);
  7655. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7656. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7657. 0, &times, genTimes, &pending)) {
  7658. wc_FreeRsaKey(genKey[i]);
  7659. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7660. if (ret < 0) {
  7661. goto exit;
  7662. }
  7663. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7664. &gRng);
  7665. if (!bench_async_handle(&ret,
  7666. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7667. &times, &pending)) {
  7668. goto exit;
  7669. }
  7670. }
  7671. } /* for i */
  7672. RECORD_MULTI_VALUE_STATS();
  7673. } /* for times */
  7674. count += times;
  7675. } while (bench_stats_check(start)
  7676. #ifdef MULTI_VALUE_STATISTICS
  7677. || runs < minimum_runs
  7678. #endif
  7679. );
  7680. exit:
  7681. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7682. start, ret);
  7683. #ifdef MULTI_VALUE_STATISTICS
  7684. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7685. #endif
  7686. /* cleanup */
  7687. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7688. wc_FreeRsaKey(genKey[i]);
  7689. }
  7690. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7691. }
  7692. void bench_rsaKeyGen(int useDeviceID)
  7693. {
  7694. int k;
  7695. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7696. static const word32 keySizes[2] = {1024, 2048 };
  7697. #elif RSA_MAX_SIZE >= 4096
  7698. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7699. (RSA_MIN_SIZE <= 1024)
  7700. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7701. #else
  7702. static const word32 keySizes[3] = {2048, 3072, 4096};
  7703. #endif
  7704. #elif RSA_MAX_SIZE >= 3072
  7705. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7706. (RSA_MIN_SIZE <= 1024)
  7707. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7708. #else
  7709. static const word32 keySizes[2] = {2048, 3072 };
  7710. #endif
  7711. #elif RSA_MAX_SIZE >= 2048
  7712. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7713. (RSA_MIN_SIZE <= 1024)
  7714. static const word32 keySizes[2] = {1024, 2048 };
  7715. #else
  7716. static const word32 keySizes[1] = {2048};
  7717. #endif
  7718. #else
  7719. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7720. (RSA_MIN_SIZE <= 1024)
  7721. static const word32 keySizes[1] = {1024 };
  7722. #else
  7723. #error No candidate RSA key sizes to benchmark.
  7724. #endif
  7725. #endif
  7726. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7727. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7728. }
  7729. }
  7730. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7731. {
  7732. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7733. }
  7734. #endif /* WOLFSSL_KEY_GEN */
  7735. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7736. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7737. #if defined(WOLFSSL_MDK_SHELL)
  7738. static char *certRSAname = "certs/rsa2048.der";
  7739. /* set by shell command */
  7740. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7741. #elif defined(FREESCALE_MQX)
  7742. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7743. #else
  7744. static const char *certRSAname = "certs/rsa2048.der";
  7745. #endif
  7746. #endif
  7747. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7748. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7749. #if defined(USE_CERT_BUFFERS_2048)
  7750. static const unsigned char rsa_2048_sig[] = {
  7751. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7752. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7753. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7754. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7755. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7756. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7757. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7758. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7759. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7760. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7761. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7762. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7763. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7764. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7765. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7766. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7767. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7768. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7769. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7770. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7771. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7772. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7773. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7774. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7775. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7776. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7777. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7778. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7779. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7780. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7781. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7782. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7783. };
  7784. #elif defined(USE_CERT_BUFFERS_3072)
  7785. static const unsigned char rsa_3072_sig[] = {
  7786. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7787. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7788. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7789. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7790. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7791. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7792. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7793. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7794. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7795. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7796. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7797. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7798. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7799. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7800. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7801. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7802. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7803. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7804. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7805. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7806. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7807. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7808. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7809. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7810. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7811. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7812. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7813. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7814. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7815. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7816. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7817. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7818. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7819. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7820. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7821. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7822. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7823. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7824. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7825. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7826. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7827. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7828. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7829. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7830. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7831. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7832. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7833. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7834. };
  7835. #else
  7836. #error Not Supported Yet!
  7837. #endif
  7838. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7839. static void bench_rsa_helper(int useDeviceID,
  7840. WC_ARRAY_ARG(rsaKey,
  7841. RsaKey,
  7842. BENCH_MAX_PENDING,
  7843. sizeof(RsaKey)),
  7844. word32 rsaKeySz)
  7845. {
  7846. int ret = 0, i, times, count = 0, pending = 0;
  7847. word32 idx = 0;
  7848. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7849. const char* messageStr = TEST_STRING;
  7850. const int len = (int)TEST_STRING_SZ;
  7851. #endif
  7852. double start = 0.0F;
  7853. const char**desc = bench_desc_words[lng_index];
  7854. DECLARE_MULTI_VALUE_STATS_VARS()
  7855. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7856. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7857. #endif
  7858. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7859. rsaKeySz, HEAP_HINT);
  7860. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7861. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7862. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7863. rsaKeySz, HEAP_HINT);
  7864. #else
  7865. byte* out[BENCH_MAX_PENDING];
  7866. #endif
  7867. XMEMSET(out, 0, sizeof(out));
  7868. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7869. rsaKeySz, HEAP_HINT);
  7870. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7871. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7872. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7873. rsaKeySz, HEAP_HINT);
  7874. if (out[0] == NULL) {
  7875. ret = MEMORY_E;
  7876. goto exit;
  7877. }
  7878. #endif
  7879. if (enc[0] == NULL) {
  7880. ret = MEMORY_E;
  7881. goto exit;
  7882. }
  7883. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7884. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7885. XMEMCPY(message, messageStr, len);
  7886. #endif
  7887. if (!rsa_sign_verify) {
  7888. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7889. /* begin public RSA */
  7890. bench_stats_start(&count, &start);
  7891. do {
  7892. for (times = 0; times < ntimes || pending > 0; ) {
  7893. bench_async_poll(&pending);
  7894. /* while free pending slots in queue, submit ops */
  7895. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7896. if (bench_async_check(&ret,
  7897. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7898. 1, &times, ntimes, &pending)) {
  7899. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7900. rsaKeySz/8, rsaKey[i],
  7901. GLOBAL_RNG);
  7902. if (!bench_async_handle(&ret,
  7903. BENCH_ASYNC_GET_DEV(
  7904. rsaKey[i]), 1, &times,
  7905. &pending)) {
  7906. goto exit_rsa_verify;
  7907. }
  7908. }
  7909. } /* for i */
  7910. RECORD_MULTI_VALUE_STATS();
  7911. } /* for times */
  7912. count += times;
  7913. } while (bench_stats_check(start)
  7914. #ifdef MULTI_VALUE_STATISTICS
  7915. || runs < minimum_runs
  7916. #endif
  7917. );
  7918. exit_rsa_verify:
  7919. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7920. useDeviceID, count, start, ret);
  7921. #ifdef MULTI_VALUE_STATISTICS
  7922. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7923. #endif
  7924. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7925. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7926. if (ret < 0) {
  7927. goto exit;
  7928. }
  7929. RESET_MULTI_VALUE_STATS_VARS();
  7930. /* capture resulting encrypt length */
  7931. idx = (word32)(rsaKeySz/8);
  7932. /* begin private async RSA */
  7933. bench_stats_start(&count, &start);
  7934. do {
  7935. for (times = 0; times < ntimes || pending > 0; ) {
  7936. bench_async_poll(&pending);
  7937. /* while free pending slots in queue, submit ops */
  7938. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7939. if (bench_async_check(&ret,
  7940. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7941. 1, &times, ntimes, &pending)) {
  7942. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7943. rsaKeySz/8, rsaKey[i]);
  7944. if (!bench_async_handle(&ret,
  7945. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7946. 1, &times, &pending)) {
  7947. goto exit_rsa_pub;
  7948. }
  7949. }
  7950. } /* for i */
  7951. RECORD_MULTI_VALUE_STATS();
  7952. } /* for times */
  7953. count += times;
  7954. } while (bench_stats_check(start)
  7955. #ifdef MULTI_VALUE_STATISTICS
  7956. || runs < minimum_runs
  7957. #endif
  7958. );
  7959. exit_rsa_pub:
  7960. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7961. useDeviceID, count, start, ret);
  7962. #ifdef MULTI_VALUE_STATISTICS
  7963. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7964. #endif
  7965. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7966. }
  7967. else {
  7968. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7969. /* begin RSA sign */
  7970. bench_stats_start(&count, &start);
  7971. do {
  7972. for (times = 0; times < ntimes || pending > 0; ) {
  7973. bench_async_poll(&pending);
  7974. /* while free pending slots in queue, submit ops */
  7975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7976. if (bench_async_check(&ret,
  7977. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7978. 1, &times, ntimes, &pending)) {
  7979. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7980. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7981. if (!bench_async_handle(&ret,
  7982. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7983. 1, &times, &pending)) {
  7984. goto exit_rsa_sign;
  7985. }
  7986. }
  7987. } /* for i */
  7988. RECORD_MULTI_VALUE_STATS();
  7989. } /* for times */
  7990. count += times;
  7991. } while (bench_stats_check(start)
  7992. #ifdef MULTI_VALUE_STATISTICS
  7993. || runs < minimum_runs
  7994. #endif
  7995. );
  7996. exit_rsa_sign:
  7997. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7998. count, start, ret);
  7999. #ifdef MULTI_VALUE_STATISTICS
  8000. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8001. #endif
  8002. if (ret < 0) {
  8003. goto exit;
  8004. }
  8005. RESET_MULTI_VALUE_STATS_VARS();
  8006. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  8007. /* capture resulting encrypt length */
  8008. idx = rsaKeySz/8;
  8009. /* begin RSA verify */
  8010. bench_stats_start(&count, &start);
  8011. do {
  8012. for (times = 0; times < ntimes || pending > 0; ) {
  8013. bench_async_poll(&pending);
  8014. /* while free pending slots in queue, submit ops */
  8015. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8016. if (bench_async_check(&ret,
  8017. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8018. 1, &times, ntimes, &pending)) {
  8019. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  8020. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8021. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  8022. rsaKeySz/8, rsaKey[i]);
  8023. #elif defined(USE_CERT_BUFFERS_2048)
  8024. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  8025. idx = sizeof(rsa_2048_sig);
  8026. out[i] = NULL;
  8027. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8028. &out[i], rsaKey[i]);
  8029. if (ret > 0) {
  8030. ret = 0;
  8031. }
  8032. #elif defined(USE_CERT_BUFFERS_3072)
  8033. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  8034. idx = sizeof(rsa_3072_sig);
  8035. out[i] = NULL;
  8036. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8037. &out[i], rsaKey[i]);
  8038. if (ret > 0)
  8039. ret = 0;
  8040. #endif
  8041. if (!bench_async_handle(&ret,
  8042. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8043. 1, &times, &pending)) {
  8044. goto exit_rsa_verifyinline;
  8045. }
  8046. }
  8047. } /* for i */
  8048. RECORD_MULTI_VALUE_STATS();
  8049. } /* for times */
  8050. count += times;
  8051. } while (bench_stats_check(start)
  8052. #ifdef MULTI_VALUE_STATISTICS
  8053. || runs < minimum_runs
  8054. #endif
  8055. );
  8056. exit_rsa_verifyinline:
  8057. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8058. useDeviceID, count, start, ret);
  8059. #ifdef MULTI_VALUE_STATISTICS
  8060. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8061. #endif
  8062. }
  8063. exit:
  8064. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8065. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8066. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8067. #endif
  8068. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8069. WC_FREE_VAR(message, HEAP_HINT);
  8070. #endif
  8071. }
  8072. void bench_rsa(int useDeviceID)
  8073. {
  8074. int i;
  8075. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8076. sizeof(RsaKey), HEAP_HINT);
  8077. int ret = 0;
  8078. word32 rsaKeySz = 0;
  8079. const byte* tmp;
  8080. size_t bytes;
  8081. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8082. word32 idx;
  8083. #endif
  8084. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8085. sizeof(RsaKey), HEAP_HINT);
  8086. #ifdef USE_CERT_BUFFERS_1024
  8087. tmp = rsa_key_der_1024;
  8088. bytes = (size_t)sizeof_rsa_key_der_1024;
  8089. rsaKeySz = 1024;
  8090. #elif defined(USE_CERT_BUFFERS_2048)
  8091. tmp = rsa_key_der_2048;
  8092. bytes = (size_t)sizeof_rsa_key_der_2048;
  8093. rsaKeySz = 2048;
  8094. #elif defined(USE_CERT_BUFFERS_3072)
  8095. tmp = rsa_key_der_3072;
  8096. bytes = (size_t)sizeof_rsa_key_der_3072;
  8097. rsaKeySz = 3072;
  8098. #elif defined(USE_CERT_BUFFERS_4096)
  8099. tmp = client_key_der_4096;
  8100. bytes = (size_t)sizeof_client_key_der_4096;
  8101. rsaKeySz = 4096;
  8102. #else
  8103. #error "need a cert buffer size"
  8104. #endif /* USE_CERT_BUFFERS */
  8105. /* init keys */
  8106. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8107. /* setup an async context for each key */
  8108. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8109. useDeviceID ? devId : INVALID_DEVID);
  8110. if (ret < 0) {
  8111. goto exit;
  8112. }
  8113. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8114. #ifdef WC_RSA_BLINDING
  8115. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8116. if (ret != 0)
  8117. goto exit;
  8118. #endif
  8119. #endif
  8120. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8121. /* decode the private key */
  8122. idx = 0;
  8123. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8124. rsaKey[i], (word32)bytes)) != 0) {
  8125. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8126. goto exit;
  8127. }
  8128. #elif defined(WOLFSSL_PUBLIC_MP)
  8129. /* get offset to public portion of the RSA key */
  8130. #ifdef USE_CERT_BUFFERS_1024
  8131. bytes = 11;
  8132. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8133. bytes = 12;
  8134. #endif
  8135. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8136. if (ret != 0) {
  8137. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8138. goto exit;
  8139. }
  8140. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8141. if (ret != 0) {
  8142. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8143. goto exit;
  8144. }
  8145. #else
  8146. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8147. rsaKeySz = 0;
  8148. #endif
  8149. }
  8150. if (rsaKeySz > 0) {
  8151. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8152. }
  8153. (void)bytes;
  8154. (void)tmp;
  8155. exit:
  8156. /* cleanup */
  8157. if (WC_ARRAY_OK(rsaKey)) {
  8158. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8159. wc_FreeRsaKey(rsaKey[i]);
  8160. }
  8161. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8162. }
  8163. }
  8164. #ifdef WOLFSSL_KEY_GEN
  8165. /* bench any size of RSA key */
  8166. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8167. {
  8168. int ret = 0, i, pending = 0;
  8169. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8170. sizeof(RsaKey), HEAP_HINT);
  8171. int isPending[BENCH_MAX_PENDING];
  8172. long exp = 65537L;
  8173. /* clear for done cleanup */
  8174. XMEMSET(isPending, 0, sizeof(isPending));
  8175. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8176. sizeof(RsaKey), HEAP_HINT);
  8177. /* init keys */
  8178. do {
  8179. pending = 0;
  8180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8181. if (!isPending[i]) { /* if making the key is pending then just call
  8182. * wc_MakeRsaKey again */
  8183. /* setup an async context for each key */
  8184. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8185. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8186. goto exit;
  8187. }
  8188. #ifdef WC_RSA_BLINDING
  8189. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8190. if (ret != 0)
  8191. goto exit;
  8192. #endif
  8193. }
  8194. /* create the RSA key */
  8195. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8196. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8197. isPending[i] = 1;
  8198. pending = 1;
  8199. }
  8200. else if (ret != 0) {
  8201. printf("wc_MakeRsaKey failed! %d\n", ret);
  8202. goto exit;
  8203. }
  8204. } /* for i */
  8205. } while (pending > 0);
  8206. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8207. exit:
  8208. /* cleanup */
  8209. if (WC_ARRAY_OK(rsaKey)) {
  8210. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8211. wc_FreeRsaKey(rsaKey[i]);
  8212. }
  8213. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8214. }
  8215. }
  8216. #endif /* WOLFSSL_KEY_GEN */
  8217. #endif /* !NO_RSA */
  8218. #ifndef NO_DH
  8219. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8220. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8221. #if defined(WOLFSSL_MDK_SHELL)
  8222. static char *certDHname = "certs/dh2048.der";
  8223. /* set by shell command */
  8224. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8225. #elif defined(FREESCALE_MQX)
  8226. static char *certDHname = "a:\\certs\\dh2048.der";
  8227. #elif defined(NO_ASN)
  8228. /* do nothing, but don't need a file */
  8229. #else
  8230. static const char *certDHname = "certs/dh2048.der";
  8231. #endif
  8232. #endif
  8233. #ifdef HAVE_FFDHE_4096
  8234. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8235. #else
  8236. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8237. #endif
  8238. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8239. void bench_dh(int useDeviceID)
  8240. {
  8241. int ret = 0, i;
  8242. int count = 0, times, pending = 0;
  8243. const byte* tmp = NULL;
  8244. double start = 0.0F;
  8245. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8246. sizeof(DhKey), HEAP_HINT);
  8247. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8248. const char**desc = bench_desc_words[lng_index];
  8249. #ifndef NO_ASN
  8250. size_t bytes = 0;
  8251. word32 idx;
  8252. #endif
  8253. word32 pubSz[BENCH_MAX_PENDING];
  8254. word32 privSz[BENCH_MAX_PENDING];
  8255. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8256. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8257. word32 agreeSz[BENCH_MAX_PENDING];
  8258. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8259. #ifdef HAVE_PUBLIC_FFDHE
  8260. const DhParams *params = NULL;
  8261. #else
  8262. int paramName = 0;
  8263. #endif
  8264. #endif
  8265. DECLARE_MULTI_VALUE_STATS_VARS()
  8266. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8267. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8268. WC_DECLARE_VAR(pub2, byte,
  8269. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8270. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8271. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8272. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8273. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8274. WC_DECLARE_VAR(priv2, byte,
  8275. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8276. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8277. XMEMSET(pub, 0, sizeof(pub));
  8278. XMEMSET(agree, 0, sizeof(agree));
  8279. XMEMSET(priv, 0, sizeof(priv));
  8280. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8281. sizeof(DhKey), HEAP_HINT);
  8282. WC_ALLOC_ARRAY(pub, byte,
  8283. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8284. WC_ALLOC_ARRAY(agree, byte,
  8285. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8286. WC_ALLOC_ARRAY(priv, byte,
  8287. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8288. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8289. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8290. (void)tmp;
  8291. if (!use_ffdhe) {
  8292. #if defined(NO_ASN)
  8293. dhKeySz = 1024;
  8294. /* do nothing, but don't use default FILE */
  8295. #elif defined(USE_CERT_BUFFERS_1024)
  8296. tmp = dh_key_der_1024;
  8297. bytes = (size_t)sizeof_dh_key_der_1024;
  8298. dhKeySz = 1024;
  8299. #elif defined(USE_CERT_BUFFERS_2048)
  8300. tmp = dh_key_der_2048;
  8301. bytes = (size_t)sizeof_dh_key_der_2048;
  8302. dhKeySz = 2048;
  8303. #elif defined(USE_CERT_BUFFERS_3072)
  8304. tmp = dh_key_der_3072;
  8305. bytes = (size_t)sizeof_dh_key_der_3072;
  8306. dhKeySz = 3072;
  8307. #elif defined(USE_CERT_BUFFERS_4096)
  8308. tmp = dh_key_der_4096;
  8309. bytes = (size_t)sizeof_dh_key_der_4096;
  8310. dhKeySz = 4096;
  8311. #else
  8312. #error "need to define a cert buffer size"
  8313. #endif /* USE_CERT_BUFFERS */
  8314. }
  8315. #ifdef HAVE_FFDHE_2048
  8316. else if (use_ffdhe == 2048) {
  8317. #ifdef HAVE_PUBLIC_FFDHE
  8318. params = wc_Dh_ffdhe2048_Get();
  8319. #else
  8320. paramName = WC_FFDHE_2048;
  8321. #endif
  8322. dhKeySz = 2048;
  8323. }
  8324. #endif
  8325. #ifdef HAVE_FFDHE_3072
  8326. else if (use_ffdhe == 3072) {
  8327. #ifdef HAVE_PUBLIC_FFDHE
  8328. params = wc_Dh_ffdhe3072_Get();
  8329. #else
  8330. paramName = WC_FFDHE_3072;
  8331. #endif
  8332. dhKeySz = 3072;
  8333. }
  8334. #endif
  8335. #ifdef HAVE_FFDHE_4096
  8336. else if (use_ffdhe == 4096) {
  8337. #ifdef HAVE_PUBLIC_FFDHE
  8338. params = wc_Dh_ffdhe4096_Get();
  8339. #else
  8340. paramName = WC_FFDHE_4096;
  8341. #endif
  8342. dhKeySz = 4096;
  8343. }
  8344. #endif
  8345. /* init keys */
  8346. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8347. /* setup an async context for each key */
  8348. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8349. useDeviceID ? devId : INVALID_DEVID);
  8350. if (ret != 0)
  8351. goto exit;
  8352. /* setup key */
  8353. if (!use_ffdhe) {
  8354. #ifdef NO_ASN
  8355. ret = wc_DhSetKey(dhKey[i], dh_p,
  8356. sizeof(dh_p), dh_g, sizeof(dh_g));
  8357. #else
  8358. idx = 0;
  8359. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8360. #endif
  8361. }
  8362. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8363. #ifdef HAVE_PUBLIC_FFDHE
  8364. else if (params != NULL) {
  8365. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8366. params->g, params->g_len);
  8367. }
  8368. #else
  8369. else if (paramName != 0) {
  8370. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8371. }
  8372. #endif
  8373. #endif
  8374. if (ret != 0) {
  8375. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8376. goto exit;
  8377. }
  8378. }
  8379. /* Key Gen */
  8380. bench_stats_start(&count, &start);
  8381. PRIVATE_KEY_UNLOCK();
  8382. do {
  8383. /* while free pending slots in queue, submit ops */
  8384. for (times = 0; times < genTimes || pending > 0; ) {
  8385. bench_async_poll(&pending);
  8386. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8387. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8388. 0, &times, genTimes, &pending)) {
  8389. privSz[i] = BENCH_DH_PRIV_SIZE;
  8390. pubSz[i] = BENCH_DH_KEY_SIZE;
  8391. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8392. priv[i], &privSz[i],
  8393. pub[i], &pubSz[i]);
  8394. if (!bench_async_handle(&ret,
  8395. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8396. 0, &times, &pending)) {
  8397. goto exit_dh_gen;
  8398. }
  8399. }
  8400. } /* for i */
  8401. RECORD_MULTI_VALUE_STATS();
  8402. } /* for times */
  8403. count += times;
  8404. } while (bench_stats_check(start)
  8405. #ifdef MULTI_VALUE_STATISTICS
  8406. || runs < minimum_runs
  8407. #endif
  8408. );
  8409. PRIVATE_KEY_LOCK();
  8410. exit_dh_gen:
  8411. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8412. useDeviceID, count, start, ret);
  8413. #ifdef MULTI_VALUE_STATISTICS
  8414. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8415. #endif
  8416. if (ret < 0) {
  8417. goto exit;
  8418. }
  8419. RESET_MULTI_VALUE_STATS_VARS();
  8420. /* Generate key to use as other public */
  8421. PRIVATE_KEY_UNLOCK();
  8422. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8423. priv2, &privSz2, pub2, &pubSz2);
  8424. PRIVATE_KEY_LOCK();
  8425. #ifdef WOLFSSL_ASYNC_CRYPT
  8426. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8427. #endif
  8428. /* Key Agree */
  8429. bench_stats_start(&count, &start);
  8430. PRIVATE_KEY_UNLOCK();
  8431. do {
  8432. for (times = 0; times < agreeTimes || pending > 0; ) {
  8433. bench_async_poll(&pending);
  8434. /* while free pending slots in queue, submit ops */
  8435. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8436. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8437. 0, &times, agreeTimes, &pending)) {
  8438. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8439. privSz[i], pub2, pubSz2);
  8440. if (!bench_async_handle(&ret,
  8441. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8442. goto exit;
  8443. }
  8444. }
  8445. } /* for i */
  8446. RECORD_MULTI_VALUE_STATS();
  8447. } /* for times */
  8448. count += times;
  8449. } while (bench_stats_check(start)
  8450. #ifdef MULTI_VALUE_STATISTICS
  8451. || runs < minimum_runs
  8452. #endif
  8453. );
  8454. PRIVATE_KEY_LOCK();
  8455. exit:
  8456. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8457. useDeviceID, count, start, ret);
  8458. #ifdef MULTI_VALUE_STATISTICS
  8459. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8460. #endif
  8461. /* cleanup */
  8462. if (WC_ARRAY_OK(dhKey)) {
  8463. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8464. wc_FreeDhKey(dhKey[i]);
  8465. }
  8466. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8467. }
  8468. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8469. WC_FREE_VAR(pub2, HEAP_HINT);
  8470. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8471. WC_FREE_VAR(priv2, HEAP_HINT);
  8472. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8473. }
  8474. #endif /* !NO_DH */
  8475. #ifdef WOLFSSL_HAVE_KYBER
  8476. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8477. KyberKey* key)
  8478. {
  8479. int ret = 0, times, count, pending = 0;
  8480. double start;
  8481. const char**desc = bench_desc_words[lng_index];
  8482. DECLARE_MULTI_VALUE_STATS_VARS()
  8483. /* KYBER Make Key */
  8484. bench_stats_start(&count, &start);
  8485. do {
  8486. /* while free pending slots in queue, submit ops */
  8487. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8488. wc_KyberKey_Free(key);
  8489. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8490. if (ret != 0)
  8491. goto exit;
  8492. #ifdef KYBER_NONDETERMINISTIC
  8493. ret = wc_KyberKey_MakeKey(key, &gRng);
  8494. #else
  8495. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8496. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8497. #endif
  8498. if (ret != 0)
  8499. goto exit;
  8500. RECORD_MULTI_VALUE_STATS();
  8501. } /* for times */
  8502. count += times;
  8503. } while (bench_stats_check(start)
  8504. #ifdef MULTI_VALUE_STATISTICS
  8505. || runs < minimum_runs
  8506. #endif
  8507. );
  8508. exit:
  8509. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8510. #ifdef MULTI_VALUE_STATISTICS
  8511. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8512. #endif
  8513. }
  8514. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8515. {
  8516. int ret = 0, times, count, pending = 0;
  8517. double start;
  8518. const char**desc = bench_desc_words[lng_index];
  8519. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8520. byte ss[KYBER_SS_SZ];
  8521. word32 ctSz;
  8522. DECLARE_MULTI_VALUE_STATS_VARS()
  8523. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8524. if (ret != 0) {
  8525. return;
  8526. }
  8527. /* KYBER Encapsulate */
  8528. bench_stats_start(&count, &start);
  8529. do {
  8530. /* while free pending slots in queue, submit ops */
  8531. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8532. #ifdef KYBER_NONDETERMINISTIC
  8533. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8534. #else
  8535. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8536. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8537. sizeof(rand));
  8538. #endif
  8539. if (ret != 0)
  8540. goto exit_encap;
  8541. RECORD_MULTI_VALUE_STATS();
  8542. } /* for times */
  8543. count += times;
  8544. } while (bench_stats_check(start)
  8545. #ifdef MULTI_VALUE_STATISTICS
  8546. || runs < minimum_runs
  8547. #endif
  8548. );
  8549. exit_encap:
  8550. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8551. #ifdef MULTI_VALUE_STATISTICS
  8552. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8553. #endif
  8554. RESET_MULTI_VALUE_STATS_VARS();
  8555. /* KYBER Decapsulate */
  8556. bench_stats_start(&count, &start);
  8557. do {
  8558. /* while free pending slots in queue, submit ops */
  8559. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8560. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8561. if (ret != 0)
  8562. goto exit_decap;
  8563. RECORD_MULTI_VALUE_STATS();
  8564. } /* for times */
  8565. count += times;
  8566. } while (bench_stats_check(start)
  8567. #ifdef MULTI_VALUE_STATISTICS
  8568. || runs < minimum_runs
  8569. #endif
  8570. );
  8571. exit_decap:
  8572. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8573. #ifdef MULTI_VALUE_STATISTICS
  8574. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8575. #endif
  8576. }
  8577. void bench_kyber(int type)
  8578. {
  8579. KyberKey key;
  8580. const char* name = NULL;
  8581. int keySize = 0;
  8582. switch (type) {
  8583. #ifndef WOLFSSL_NO_ML_KEM
  8584. #ifdef WOLFSSL_WC_ML_KEM_512
  8585. case WC_ML_KEM_512:
  8586. name = "ML-KEM 512 ";
  8587. keySize = 128;
  8588. break;
  8589. #endif
  8590. #ifdef WOLFSSL_WC_ML_KEM_768
  8591. case WC_ML_KEM_768:
  8592. name = "ML-KEM 768 ";
  8593. keySize = 192;
  8594. break;
  8595. #endif
  8596. #ifdef WOLFSSL_WC_ML_KEM_1024
  8597. case WC_ML_KEM_1024:
  8598. name = "ML-KEM 1024 ";
  8599. keySize = 256;
  8600. break;
  8601. #endif
  8602. #endif
  8603. #ifdef WOLFSSL_KYBER_ORIGINAL
  8604. #ifdef WOLFSSL_KYBER512
  8605. case KYBER512:
  8606. name = "KYBER512 ";
  8607. keySize = 128;
  8608. break;
  8609. #endif
  8610. #ifdef WOLFSSL_KYBER768
  8611. case KYBER768:
  8612. name = "KYBER768 ";
  8613. keySize = 192;
  8614. break;
  8615. #endif
  8616. #ifdef WOLFSSL_KYBER1024
  8617. case KYBER1024:
  8618. name = "KYBER1024";
  8619. keySize = 256;
  8620. break;
  8621. #endif
  8622. #endif
  8623. }
  8624. bench_kyber_keygen(type, name, keySize, &key);
  8625. bench_kyber_encap(name, keySize, &key);
  8626. wc_KyberKey_Free(&key);
  8627. }
  8628. #endif
  8629. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8630. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8631. /* WC_LMS_PARM_L2_H10_W2
  8632. * signature length: 9300 */
  8633. static const byte lms_priv_L2_H10_W2[64] =
  8634. {
  8635. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8636. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8637. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8638. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8639. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8640. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8641. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8642. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8643. };
  8644. static const byte lms_pub_L2_H10_W2[60] =
  8645. {
  8646. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8647. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8648. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8649. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8650. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8651. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8652. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8653. 0x7F,0xC8,0x91,0xB0
  8654. };
  8655. /* WC_LMS_PARM_L2_H10_W4
  8656. * signature length: 5076 */
  8657. static const byte lms_priv_L2_H10_W4[64] =
  8658. {
  8659. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8660. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8661. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8662. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8663. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8664. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8665. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8666. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8667. };
  8668. static const byte lms_pub_L2_H10_W4[60] =
  8669. {
  8670. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8671. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8672. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8673. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8674. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8675. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8676. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8677. 0x6B,0x9A,0xD3,0x14
  8678. };
  8679. /* WC_LMS_PARM_L3_H5_W4
  8680. * signature length: 7160 */
  8681. static const byte lms_priv_L3_H5_W4[64] =
  8682. {
  8683. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8684. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8685. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8686. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8687. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8688. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8689. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8690. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8691. };
  8692. static const byte lms_pub_L3_H5_W4[60] =
  8693. {
  8694. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8695. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8696. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8697. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8698. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8699. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8700. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8701. 0xAB,0x4B,0x51,0x39
  8702. };
  8703. /* WC_LMS_PARM_L3_H5_W8
  8704. * signature length: 3992 */
  8705. static const byte lms_priv_L3_H5_W8[64] =
  8706. {
  8707. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8708. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8709. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8710. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8711. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8712. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8713. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8714. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8715. };
  8716. static const byte lms_pub_L3_H5_W8[60] =
  8717. {
  8718. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8719. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8720. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8721. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8722. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8723. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8724. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8725. 0x83,0xAB,0x43,0xAF
  8726. };
  8727. /* WC_LMS_PARM_L3_H10_W4
  8728. * signature length: 7640 */
  8729. static const byte lms_priv_L3_H10_W4[64] =
  8730. {
  8731. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8732. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8733. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8734. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8735. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8736. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8737. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8738. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8739. };
  8740. static const byte lms_pub_L3_H10_W4[60] =
  8741. {
  8742. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8743. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8744. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8745. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8746. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8747. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8748. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8749. 0x8D,0x78,0xD5,0xA8
  8750. };
  8751. /* WC_LMS_PARM_L4_H5_W8
  8752. * signature length: 5340 */
  8753. static const byte lms_priv_L4_H5_W8[64] =
  8754. {
  8755. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8756. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8757. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8758. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8759. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8760. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8761. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8762. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8763. };
  8764. static const byte lms_pub_L4_H5_W8[60] =
  8765. {
  8766. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8767. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8768. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8769. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8770. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8771. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8772. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8773. 0x74,0x24,0x12,0xC8
  8774. };
  8775. #endif
  8776. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8777. {
  8778. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8779. * BE USED FOR TESTING PURPOSES! Production applications should
  8780. * write only to non-volatile storage. */
  8781. XMEMCPY(context, priv, privSz);
  8782. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8783. }
  8784. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8785. {
  8786. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8787. * BE USED FOR TESTING PURPOSES! */
  8788. XMEMCPY(priv, context, privSz);
  8789. return WC_LMS_RC_READ_TO_MEMORY;
  8790. }
  8791. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8792. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8793. {
  8794. WC_RNG rng;
  8795. LmsKey key;
  8796. int ret;
  8797. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8798. int times = 0;
  8799. int count = 0;
  8800. double start = 0.0F;
  8801. int levels;
  8802. int height;
  8803. int winternitz;
  8804. const char* str = wc_LmsKey_ParmToStr(parm);
  8805. DECLARE_MULTI_VALUE_STATS_VARS()
  8806. #ifndef HAVE_FIPS
  8807. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8808. #else
  8809. ret = wc_InitRng(&rng);
  8810. #endif
  8811. if (ret != 0) {
  8812. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8813. return;
  8814. }
  8815. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8816. if (ret) {
  8817. printf("wc_LmsKey_Init failed: %d\n", ret);
  8818. wc_FreeRng(&rng);
  8819. return;
  8820. }
  8821. count = 0;
  8822. bench_stats_start(&count, &start);
  8823. do {
  8824. /* LMS is stateful. Async queuing not practical. */
  8825. for (times = 0; times < 1; ++times) {
  8826. wc_LmsKey_Free(&key);
  8827. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8828. if (ret) {
  8829. printf("wc_LmsKey_Init failed: %d\n", ret);
  8830. goto exit_lms_keygen;
  8831. }
  8832. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8833. if (ret) {
  8834. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8835. goto exit_lms_keygen;
  8836. }
  8837. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8838. if (ret) {
  8839. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8840. ret);
  8841. goto exit_lms_keygen;
  8842. }
  8843. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8844. if (ret) {
  8845. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8846. ret);
  8847. goto exit_lms_keygen;
  8848. }
  8849. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8850. if (ret) {
  8851. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8852. goto exit_lms_keygen;
  8853. }
  8854. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8855. if (ret) {
  8856. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8857. ret);
  8858. goto exit_lms_keygen;
  8859. }
  8860. ret = wc_LmsKey_MakeKey(&key, &rng);
  8861. if (ret) {
  8862. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8863. goto exit_lms_keygen;
  8864. }
  8865. RECORD_MULTI_VALUE_STATS();
  8866. }
  8867. count += times;
  8868. } while (bench_stats_check(start)
  8869. #ifdef MULTI_VALUE_STATISTICS
  8870. || runs < minimum_runs
  8871. #endif
  8872. );
  8873. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8874. count, start, ret);
  8875. #ifdef MULTI_VALUE_STATISTICS
  8876. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8877. #endif
  8878. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8879. if (ret) {
  8880. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8881. }
  8882. exit_lms_keygen:
  8883. wc_LmsKey_Free(&key);
  8884. wc_FreeRng(&rng);
  8885. }
  8886. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8887. {
  8888. LmsKey key;
  8889. int ret = 0;
  8890. const char * msg = TEST_STRING;
  8891. word32 msgSz = TEST_STRING_SZ;
  8892. byte * sig = NULL;
  8893. word32 sigSz = 0;
  8894. word32 privLen = 0;
  8895. int loaded = 0;
  8896. int times = 0;
  8897. int count = 0;
  8898. double start = 0.0F;
  8899. const char * str = wc_LmsKey_ParmToStr(parm);
  8900. DECLARE_MULTI_VALUE_STATS_VARS()
  8901. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8902. if (ret) {
  8903. printf("wc_LmsKey_Init failed: %d\n", ret);
  8904. goto exit_lms_sign_verify;
  8905. }
  8906. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8907. if (ret) {
  8908. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8909. goto exit_lms_sign_verify;
  8910. }
  8911. switch (parm) {
  8912. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8913. case WC_LMS_PARM_L2_H10_W2:
  8914. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8915. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8916. break;
  8917. case WC_LMS_PARM_L2_H10_W4:
  8918. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8919. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8920. break;
  8921. case WC_LMS_PARM_L3_H5_W4:
  8922. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8923. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8924. break;
  8925. case WC_LMS_PARM_L3_H5_W8:
  8926. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8927. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8928. break;
  8929. case WC_LMS_PARM_L3_H10_W4:
  8930. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8931. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8932. break;
  8933. case WC_LMS_PARM_L4_H5_W8:
  8934. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8935. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8936. break;
  8937. case WC_LMS_PARM_NONE:
  8938. case WC_LMS_PARM_L1_H15_W2:
  8939. case WC_LMS_PARM_L1_H15_W4:
  8940. case WC_LMS_PARM_L2_H10_W8:
  8941. case WC_LMS_PARM_L3_H5_W2:
  8942. case WC_LMS_PARM_L1_H5_W1:
  8943. case WC_LMS_PARM_L1_H5_W2:
  8944. case WC_LMS_PARM_L1_H5_W4:
  8945. case WC_LMS_PARM_L1_H5_W8:
  8946. case WC_LMS_PARM_L1_H10_W2:
  8947. case WC_LMS_PARM_L1_H10_W4:
  8948. case WC_LMS_PARM_L1_H10_W8:
  8949. case WC_LMS_PARM_L1_H15_W8:
  8950. case WC_LMS_PARM_L1_H20_W2:
  8951. case WC_LMS_PARM_L1_H20_W4:
  8952. case WC_LMS_PARM_L1_H20_W8:
  8953. case WC_LMS_PARM_L2_H5_W2:
  8954. case WC_LMS_PARM_L2_H5_W4:
  8955. case WC_LMS_PARM_L2_H5_W8:
  8956. case WC_LMS_PARM_L2_H15_W2:
  8957. case WC_LMS_PARM_L2_H15_W4:
  8958. case WC_LMS_PARM_L2_H15_W8:
  8959. case WC_LMS_PARM_L2_H20_W2:
  8960. case WC_LMS_PARM_L2_H20_W4:
  8961. case WC_LMS_PARM_L2_H20_W8:
  8962. case WC_LMS_PARM_L3_H10_W8:
  8963. case WC_LMS_PARM_L4_H5_W2:
  8964. case WC_LMS_PARM_L4_H5_W4:
  8965. case WC_LMS_PARM_L4_H10_W4:
  8966. case WC_LMS_PARM_L4_H10_W8:
  8967. #endif
  8968. #ifdef WOLFSSL_LMS_SHA256_192
  8969. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  8970. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  8971. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  8972. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  8973. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  8974. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  8975. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  8976. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  8977. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  8978. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  8979. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  8980. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  8981. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  8982. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  8983. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  8984. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  8985. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  8986. #endif
  8987. default:
  8988. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8989. break;
  8990. }
  8991. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8992. if (ret) {
  8993. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8994. goto exit_lms_sign_verify;
  8995. }
  8996. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8997. if (ret) {
  8998. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8999. goto exit_lms_sign_verify;
  9000. }
  9001. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  9002. if (ret) {
  9003. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  9004. goto exit_lms_sign_verify;
  9005. }
  9006. /* Even with saved priv/pub keys, we must still reload the private
  9007. * key before using it. Reloading the private key is the bottleneck
  9008. * for larger heights. Only print load time in debug builds. */
  9009. count = 0;
  9010. bench_stats_start(&count, &start);
  9011. #ifndef WOLFSSL_WC_LMS_SMALL
  9012. do {
  9013. #ifdef WOLFSSL_WC_LMS
  9014. key.priv.inited = 0;
  9015. key.state = WC_LMS_STATE_PARMSET;
  9016. #endif
  9017. ret = wc_LmsKey_Reload(&key);
  9018. if (ret) {
  9019. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9020. goto exit_lms_sign_verify;
  9021. }
  9022. RECORD_MULTI_VALUE_STATS();
  9023. count++;
  9024. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9025. if (ret) {
  9026. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9027. goto exit_lms_sign_verify;
  9028. }
  9029. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9030. if (ret) {
  9031. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9032. goto exit_lms_sign_verify;
  9033. }
  9034. #ifdef HAVE_LIBLMS
  9035. break;
  9036. #endif
  9037. } while (bench_stats_check(start)
  9038. #ifdef MULTI_VALUE_STATISTICS
  9039. || runs < minimum_runs
  9040. #endif
  9041. );
  9042. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  9043. count, start, ret);
  9044. #ifdef MULTI_VALUE_STATISTICS
  9045. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9046. #endif
  9047. RESET_MULTI_VALUE_STATS_VARS();
  9048. #else
  9049. ret = wc_LmsKey_Reload(&key);
  9050. if (ret) {
  9051. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9052. goto exit_lms_sign_verify;
  9053. }
  9054. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9055. if (ret) {
  9056. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9057. goto exit_lms_sign_verify;
  9058. }
  9059. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9060. if (ret) {
  9061. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9062. goto exit_lms_sign_verify;
  9063. }
  9064. #endif
  9065. loaded = 1;
  9066. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9067. if (sig == NULL) {
  9068. printf("bench_lms_sign_verify malloc failed\n");
  9069. goto exit_lms_sign_verify;
  9070. }
  9071. count = 0;
  9072. bench_stats_start(&count, &start);
  9073. do {
  9074. /* LMS is stateful. Async queuing not practical. */
  9075. #ifndef WOLFSSL_WC_LMS_SMALL
  9076. for (times = 0; times < ntimes; ++times)
  9077. #else
  9078. for (times = 0; times < 1; ++times)
  9079. #endif
  9080. {
  9081. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9082. if (ret) {
  9083. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9084. goto exit_lms_sign_verify;
  9085. }
  9086. RECORD_MULTI_VALUE_STATS();
  9087. if (!wc_LmsKey_SigsLeft(&key)) {
  9088. break;
  9089. }
  9090. }
  9091. count += times;
  9092. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9093. #ifdef MULTI_VALUE_STATISTICS
  9094. || runs < minimum_runs
  9095. #endif
  9096. ));
  9097. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9098. count, start, ret);
  9099. #ifdef MULTI_VALUE_STATISTICS
  9100. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9101. #endif
  9102. RESET_MULTI_VALUE_STATS_VARS();
  9103. count = 0;
  9104. bench_stats_start(&count, &start);
  9105. do {
  9106. /* LMS is stateful. Async queuing not practical. */
  9107. for (times = 0; times < ntimes; ++times) {
  9108. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9109. if (ret) {
  9110. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9111. goto exit_lms_sign_verify;
  9112. }
  9113. RECORD_MULTI_VALUE_STATS();
  9114. }
  9115. count += times;
  9116. } while (bench_stats_check(start)
  9117. #ifdef MULTI_VALUE_STATISTICS
  9118. || runs < minimum_runs
  9119. #endif
  9120. );
  9121. exit_lms_sign_verify:
  9122. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9123. count, start, ret);
  9124. #ifdef MULTI_VALUE_STATISTICS
  9125. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9126. #endif
  9127. if (loaded) {
  9128. wc_LmsKey_Free(&key);
  9129. }
  9130. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9131. return;
  9132. }
  9133. void bench_lms(void)
  9134. {
  9135. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9136. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9137. #ifdef BENCH_LMS_SLOW_KEYGEN
  9138. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9139. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9140. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9141. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9142. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9143. #undef LMS_PARAMS_BENCHED
  9144. #define LMS_PARAMS_BENCHED
  9145. #endif
  9146. #endif
  9147. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9148. (LMS_MAX_HEIGHT >= 10))
  9149. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9150. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9151. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9152. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9153. #undef LMS_PARAMS_BENCHED
  9154. #define LMS_PARAMS_BENCHED
  9155. #ifdef BENCH_LMS_SLOW_KEYGEN
  9156. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9157. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9158. #endif
  9159. #endif
  9160. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9161. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9162. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9163. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9164. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9165. #undef LMS_PARAMS_BENCHED
  9166. #define LMS_PARAMS_BENCHED
  9167. #endif
  9168. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9169. (LMS_MAX_HEIGHT >= 10))
  9170. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9171. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9172. #endif
  9173. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9174. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9175. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9176. #endif
  9177. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9178. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9179. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9180. #endif
  9181. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9182. #ifdef WOLFSSL_LMS_SHA256_192
  9183. #ifdef BENCH_LMS_SLOW_KEYGEN
  9184. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9185. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9186. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9187. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9188. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9189. #undef LMS_PARAMS_BENCHED
  9190. #define LMS_PARAMS_BENCHED
  9191. #endif
  9192. #endif
  9193. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9194. (LMS_MAX_HEIGHT >= 10))
  9195. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9196. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9197. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9198. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9199. #undef LMS_PARAMS_BENCHED
  9200. #define LMS_PARAMS_BENCHED
  9201. #ifdef BENCH_LMS_SLOW_KEYGEN
  9202. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9203. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9204. #endif
  9205. #endif
  9206. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9207. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9208. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9209. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9210. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9211. #undef LMS_PARAMS_BENCHED
  9212. #define LMS_PARAMS_BENCHED
  9213. #endif
  9214. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9215. (LMS_MAX_HEIGHT >= 10))
  9216. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9217. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9218. #endif
  9219. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9220. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9221. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9222. #endif
  9223. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9224. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9225. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9226. #endif
  9227. #endif /* WOLFSSL_LMS_SHA256_192 */
  9228. return;
  9229. }
  9230. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9231. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9232. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9233. void *context)
  9234. {
  9235. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9236. * BE USED FOR TESTING PURPOSES! Production applications should
  9237. * write only to non-volatile storage. */
  9238. XMEMCPY(context, priv, privSz);
  9239. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9240. }
  9241. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9242. void *context)
  9243. {
  9244. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9245. * BE USED FOR TESTING PURPOSES! */
  9246. XMEMCPY(priv, context, privSz);
  9247. return WC_XMSS_RC_READ_TO_MEMORY;
  9248. }
  9249. static void bench_xmss_sign_verify(const char * params)
  9250. {
  9251. WC_RNG rng;
  9252. XmssKey key;
  9253. word32 pkSz = 0;
  9254. word32 skSz = 0;
  9255. int freeRng = 0;
  9256. int freeKey = 0;
  9257. unsigned char * sk = NULL;
  9258. const char * msg = "XMSS post quantum signature test";
  9259. word32 msgSz = (word32) XSTRLEN(msg);
  9260. int ret = 0;
  9261. byte * sig = NULL;
  9262. word32 sigSz = 0;
  9263. int times = 0;
  9264. int count = 0;
  9265. double start = 0.0F;
  9266. #ifndef HAVE_FIPS
  9267. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9268. #else
  9269. ret = wc_InitRng(&rng);
  9270. #endif
  9271. if (ret != 0) {
  9272. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9273. goto exit_xmss_sign_verify;
  9274. }
  9275. freeRng = 1;
  9276. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9277. if (ret != 0) {
  9278. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9279. goto exit_xmss_sign_verify;
  9280. }
  9281. ret = wc_XmssKey_SetParamStr(&key, params);
  9282. if (ret != 0) {
  9283. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9284. goto exit_xmss_sign_verify;
  9285. }
  9286. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9287. if (ret != 0) {
  9288. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9289. goto exit_xmss_sign_verify;
  9290. }
  9291. #ifndef WOLFSSL_WC_XMSS
  9292. if (pkSz != XMSS_SHA256_PUBLEN) {
  9293. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9294. XMSS_SHA256_PUBLEN);
  9295. goto exit_xmss_sign_verify;
  9296. }
  9297. #endif
  9298. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9299. if (ret != 0 || skSz <= 0) {
  9300. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9301. goto exit_xmss_sign_verify;
  9302. }
  9303. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9304. if (ret != 0 || sigSz <= 0) {
  9305. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9306. goto exit_xmss_sign_verify;
  9307. }
  9308. /* Allocate secret keys.*/
  9309. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9310. if (sk == NULL) {
  9311. fprintf(stderr, "error: allocate xmss sk failed\n");
  9312. goto exit_xmss_sign_verify;
  9313. }
  9314. /* Allocate signature array. */
  9315. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9316. if (sig == NULL) {
  9317. fprintf(stderr, "error: allocate xmss sig failed\n");
  9318. goto exit_xmss_sign_verify;
  9319. }
  9320. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9321. if (ret != 0) {
  9322. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9323. goto exit_xmss_sign_verify;
  9324. }
  9325. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9326. if (ret != 0) {
  9327. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9328. goto exit_xmss_sign_verify;
  9329. }
  9330. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9331. if (ret != 0) {
  9332. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9333. goto exit_xmss_sign_verify;
  9334. }
  9335. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9336. fprintf(stderr, "params: %s\n", params);
  9337. fprintf(stderr, "pkSz: %d\n", pkSz);
  9338. fprintf(stderr, "skSz: %d\n", skSz);
  9339. fprintf(stderr, "sigSz: %d\n", sigSz);
  9340. #endif
  9341. /* Making the private key is the bottleneck for larger heights. */
  9342. count = 0;
  9343. bench_stats_start(&count, &start);
  9344. ret = wc_XmssKey_MakeKey(&key, &rng);
  9345. if (ret != 0) {
  9346. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9347. goto exit_xmss_sign_verify;
  9348. }
  9349. /* Can only do one at a time - state changes after make key. */
  9350. count +=1;
  9351. bench_stats_check(start);
  9352. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9353. freeKey = 1;
  9354. count = 0;
  9355. bench_stats_start(&count, &start);
  9356. do {
  9357. /* XMSS is stateful. Async queuing not practical. */
  9358. #ifndef WOLFSSL_WC_XMSS_SMALL
  9359. for (times = 0; times < ntimes; ++times)
  9360. #else
  9361. for (times = 0; times < 1; ++times)
  9362. #endif
  9363. {
  9364. if (!wc_XmssKey_SigsLeft(&key))
  9365. break;
  9366. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9367. if (ret) {
  9368. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9369. goto exit_xmss_sign_verify;
  9370. }
  9371. }
  9372. count += times;
  9373. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9374. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9375. count = 0;
  9376. bench_stats_start(&count, &start);
  9377. do {
  9378. /* XMSS is stateful. Async queuing not practical. */
  9379. for (times = 0; times < ntimes; ++times) {
  9380. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9381. if (ret) {
  9382. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9383. goto exit_xmss_sign_verify;
  9384. }
  9385. }
  9386. count += times;
  9387. } while (bench_stats_check(start));
  9388. exit_xmss_sign_verify:
  9389. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9390. /* Cleanup everything. */
  9391. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9392. sig = NULL;
  9393. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9394. sk = NULL;
  9395. if (freeRng) {
  9396. wc_FreeRng(&rng);
  9397. }
  9398. if (freeKey) {
  9399. wc_XmssKey_Free(&key);
  9400. }
  9401. return;
  9402. }
  9403. void bench_xmss(int hash)
  9404. {
  9405. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9406. * sets.
  9407. *
  9408. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9409. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9410. * very slow, their signatures and private keys quite large,
  9411. * and xmss private keys are not portable across different
  9412. * XMSS/XMSS^MT implementations.
  9413. *
  9414. * The bottleneck in key generation is the height of the first
  9415. * level tree (or h/d).
  9416. *
  9417. * h is the total height of the hyper tree, and d the number of
  9418. * trees.
  9419. */
  9420. /* h/d h d */
  9421. #ifdef WC_XMSS_SHA256
  9422. if (hash == WC_HASH_TYPE_SHA256) {
  9423. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9424. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9425. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9426. #endif
  9427. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9428. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9429. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9430. #endif
  9431. #endif
  9432. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9433. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9434. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9435. #endif
  9436. #endif
  9437. #endif /* HASH_SIZE 256 */
  9438. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9439. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9440. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9441. #endif
  9442. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9443. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9444. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9445. #endif
  9446. #endif
  9447. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9448. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9449. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9450. #endif
  9451. #endif
  9452. #endif /* HASH_SIZE 192 */
  9453. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9454. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9455. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9456. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9457. #endif
  9458. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9459. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9460. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9461. #endif
  9462. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9463. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9464. #endif
  9465. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9466. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9467. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9468. #endif
  9469. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9470. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9471. #endif
  9472. #endif /* HASH_SIZE 256 */
  9473. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9474. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9475. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9476. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9477. #endif
  9478. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9479. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9480. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9481. #endif
  9482. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9483. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9484. #endif
  9485. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9486. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9487. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9488. #endif
  9489. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9490. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9491. #endif
  9492. #endif /* HASH_SIZE 192 */
  9493. }
  9494. #endif
  9495. #ifdef WC_XMSS_SHA512
  9496. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9497. if (hash == WC_HASH_TYPE_SHA512) {
  9498. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9499. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9500. #endif
  9501. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9502. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9503. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9504. #endif
  9505. #endif
  9506. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9507. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9508. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9509. #endif
  9510. #endif
  9511. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9512. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9513. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9514. #endif
  9515. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9516. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9517. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9518. #endif
  9519. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9520. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9521. #endif
  9522. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9523. #endif
  9524. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9525. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9526. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9527. #endif
  9528. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9529. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9530. #endif
  9531. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9532. #endif
  9533. }
  9534. #endif /* HASH_SIZE 512 */
  9535. #endif
  9536. #ifdef WC_XMSS_SHAKE128
  9537. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9538. if (hash == WC_HASH_TYPE_SHAKE128) {
  9539. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9540. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9541. #endif
  9542. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9543. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9544. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9545. #endif
  9546. #endif
  9547. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9548. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9549. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9550. #endif
  9551. #endif
  9552. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9553. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9554. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9555. #endif
  9556. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9557. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9558. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9559. #endif
  9560. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9561. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9562. #endif
  9563. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9564. #endif
  9565. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9566. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9567. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9568. #endif
  9569. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9570. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9571. #endif
  9572. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9573. #endif
  9574. }
  9575. #endif /* HASH_SIZE 256 */
  9576. #endif
  9577. #ifdef WC_XMSS_SHAKE256
  9578. if (hash == WC_HASH_TYPE_SHAKE256) {
  9579. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9580. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9581. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9582. #endif
  9583. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9584. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9585. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9586. #endif
  9587. #endif
  9588. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9589. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9590. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9591. #endif
  9592. #endif
  9593. #endif /* HASH_SIZE 512 */
  9594. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9595. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9596. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9597. #endif
  9598. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9599. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9600. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9601. #endif
  9602. #endif
  9603. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9604. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9605. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9606. #endif
  9607. #endif
  9608. #endif /* HASH_SIZE 256 */
  9609. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9610. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9611. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9612. #endif
  9613. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9614. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9615. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9616. #endif
  9617. #endif
  9618. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9619. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9620. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9621. #endif
  9622. #endif
  9623. #endif /* HASH_SIZE 192 */
  9624. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9625. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9626. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9627. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9628. #endif
  9629. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9630. #endif
  9631. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9632. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9633. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9634. #endif
  9635. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9636. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9637. #endif
  9638. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9639. #endif
  9640. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9641. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9642. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9643. #endif
  9644. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9645. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9646. #endif
  9647. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9648. #endif
  9649. #endif /* HASH_SIZE 512 */
  9650. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9651. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9652. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9653. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9654. #endif
  9655. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9656. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9657. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9658. #endif
  9659. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9660. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9661. #endif
  9662. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9663. #endif
  9664. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9665. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9666. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9667. #endif
  9668. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9669. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9670. #endif
  9671. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9672. #endif
  9673. #endif /* HASH_SIZE 256 */
  9674. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9675. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9676. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9677. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9678. #endif
  9679. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9680. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9681. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9682. #endif
  9683. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9684. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9685. #endif
  9686. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9687. #endif
  9688. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9689. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9690. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9691. #endif
  9692. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9693. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9694. #endif
  9695. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9696. #endif
  9697. #endif /* HASH_SIZE 192 */
  9698. }
  9699. #endif
  9700. return;
  9701. }
  9702. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9703. #ifdef HAVE_ECC
  9704. /* Maximum ECC name plus null terminator:
  9705. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9706. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9707. /* run all benchmarks on a curve */
  9708. void bench_ecc_curve(int curveId)
  9709. {
  9710. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9711. #ifndef NO_SW_BENCH
  9712. bench_eccMakeKey(0, curveId);
  9713. #endif
  9714. #if defined(BENCH_DEVID)
  9715. bench_eccMakeKey(1, curveId);
  9716. #endif
  9717. }
  9718. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9719. #ifndef NO_SW_BENCH
  9720. bench_ecc(0, curveId);
  9721. #endif
  9722. #if defined(BENCH_DEVID)
  9723. bench_ecc(1, curveId);
  9724. #endif
  9725. }
  9726. #ifdef HAVE_ECC_ENCRYPT
  9727. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9728. bench_eccEncrypt(curveId);
  9729. #endif
  9730. }
  9731. void bench_eccMakeKey(int useDeviceID, int curveId)
  9732. {
  9733. int ret = 0, i, times, count = 0, pending = 0;
  9734. int deviceID;
  9735. int keySize = 0;
  9736. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9737. sizeof(ecc_key), HEAP_HINT);
  9738. char name[BENCH_ECC_NAME_SZ];
  9739. double start = 0;
  9740. const char**desc = bench_desc_words[lng_index];
  9741. DECLARE_MULTI_VALUE_STATS_VARS()
  9742. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9743. sizeof(ecc_key), HEAP_HINT);
  9744. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9745. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9746. /* ECC Make Key */
  9747. bench_stats_start(&count, &start);
  9748. do {
  9749. /* while free pending slots in queue, submit ops */
  9750. for (times = 0; times < agreeTimes || pending > 0; ) {
  9751. bench_async_poll(&pending);
  9752. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9753. if (bench_async_check(&ret,
  9754. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9755. &times, agreeTimes, &pending)) {
  9756. wc_ecc_free(genKey[i]);
  9757. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9758. if (ret < 0) {
  9759. goto exit;
  9760. }
  9761. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9762. curveId);
  9763. if (!bench_async_handle(&ret,
  9764. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9765. &pending)) {
  9766. goto exit;
  9767. }
  9768. }
  9769. } /* for i */
  9770. RECORD_MULTI_VALUE_STATS();
  9771. } /* for times */
  9772. count += times;
  9773. } while (bench_stats_check(start)
  9774. #ifdef MULTI_VALUE_STATISTICS
  9775. || runs < minimum_runs
  9776. #endif
  9777. );
  9778. exit:
  9779. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9780. wc_ecc_get_name(curveId));
  9781. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9782. useDeviceID, count, start, ret);
  9783. #ifdef MULTI_VALUE_STATISTICS
  9784. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9785. #endif
  9786. /* cleanup */
  9787. if (WC_ARRAY_OK(genKey)) {
  9788. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9789. wc_ecc_free(genKey[i]);
  9790. }
  9791. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9792. }
  9793. }
  9794. void bench_ecc(int useDeviceID, int curveId)
  9795. {
  9796. int ret = 0, i, times, count, pending = 0;
  9797. int deviceID;
  9798. int keySize;
  9799. char name[BENCH_ECC_NAME_SZ];
  9800. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9801. sizeof(ecc_key), HEAP_HINT);
  9802. #ifdef HAVE_ECC_DHE
  9803. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9804. sizeof(ecc_key), HEAP_HINT);
  9805. #endif
  9806. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9807. #ifdef HAVE_ECC_VERIFY
  9808. int verify[BENCH_MAX_PENDING];
  9809. #endif
  9810. #endif
  9811. word32 x[BENCH_MAX_PENDING];
  9812. double start = 0;
  9813. const char**desc = bench_desc_words[lng_index];
  9814. DECLARE_MULTI_VALUE_STATS_VARS()
  9815. #ifdef HAVE_ECC_DHE
  9816. WC_DECLARE_ARRAY(shared, byte,
  9817. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9818. #endif
  9819. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9820. WC_DECLARE_ARRAY(sig, byte,
  9821. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9822. WC_DECLARE_ARRAY(digest, byte,
  9823. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9824. #endif
  9825. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9826. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9827. XMEMSET(sig, 0, sizeof(sig));
  9828. XMEMSET(digest, 0, sizeof(digest));
  9829. #endif
  9830. #ifdef HAVE_ECC_DHE
  9831. XMEMSET(shared, 0, sizeof(shared));
  9832. #endif
  9833. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9834. sizeof(ecc_key), HEAP_HINT);
  9835. #ifdef HAVE_ECC_DHE
  9836. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9837. sizeof(ecc_key), HEAP_HINT);
  9838. WC_ALLOC_ARRAY(shared, byte,
  9839. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9840. #endif
  9841. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9842. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9843. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9844. #endif
  9845. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9846. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9847. /* init keys */
  9848. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9849. /* setup an context for each key */
  9850. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9851. goto exit;
  9852. }
  9853. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9854. #ifdef WOLFSSL_ASYNC_CRYPT
  9855. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9856. #endif
  9857. if (ret < 0) {
  9858. goto exit;
  9859. }
  9860. #ifdef HAVE_ECC_DHE
  9861. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9862. goto exit;
  9863. }
  9864. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9865. curveId)) > 0) {
  9866. goto exit;
  9867. }
  9868. #endif
  9869. }
  9870. #ifdef HAVE_ECC_DHE
  9871. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9872. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9873. !defined(HAVE_SELFTEST)
  9874. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9875. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9876. }
  9877. #endif
  9878. /* ECC Shared Secret */
  9879. bench_stats_start(&count, &start);
  9880. PRIVATE_KEY_UNLOCK();
  9881. do {
  9882. for (times = 0; times < agreeTimes || pending > 0; ) {
  9883. bench_async_poll(&pending);
  9884. /* while free pending slots in queue, submit ops */
  9885. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9886. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9887. &times, agreeTimes, &pending)) {
  9888. x[i] = (word32)keySize;
  9889. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9890. shared[i], &x[i]);
  9891. if (!bench_async_handle(&ret,
  9892. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9893. &pending)) {
  9894. goto exit_ecdhe;
  9895. }
  9896. }
  9897. } /* for i */
  9898. RECORD_MULTI_VALUE_STATS();
  9899. } /* for times */
  9900. count += times;
  9901. } while (bench_stats_check(start)
  9902. #ifdef MULTI_VALUE_STATISTICS
  9903. || runs < minimum_runs
  9904. #endif
  9905. );
  9906. PRIVATE_KEY_UNLOCK();
  9907. exit_ecdhe:
  9908. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9909. wc_ecc_get_name(curveId));
  9910. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9911. useDeviceID, count, start, ret);
  9912. #ifdef MULTI_VALUE_STATISTICS
  9913. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9914. #endif
  9915. RESET_MULTI_VALUE_STATS_VARS();
  9916. if (ret < 0) {
  9917. goto exit;
  9918. }
  9919. #endif /* HAVE_ECC_DHE */
  9920. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9921. /* Init digest to sign */
  9922. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9923. for (count = 0; count < keySize; count++) {
  9924. digest[i][count] = (byte)count;
  9925. }
  9926. }
  9927. /* ECC Sign */
  9928. bench_stats_start(&count, &start);
  9929. do {
  9930. for (times = 0; times < agreeTimes || pending > 0; ) {
  9931. bench_async_poll(&pending);
  9932. /* while free pending slots in queue, submit ops */
  9933. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9934. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9935. &times, agreeTimes, &pending)) {
  9936. if (genKey[i]->state == 0) {
  9937. x[i] = ECC_MAX_SIG_SIZE;
  9938. }
  9939. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9940. &x[i], GLOBAL_RNG, genKey[i]);
  9941. if (!bench_async_handle(&ret,
  9942. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9943. &pending)) {
  9944. goto exit_ecdsa_sign;
  9945. }
  9946. } /* bench_async_check */
  9947. } /* for i */
  9948. RECORD_MULTI_VALUE_STATS();
  9949. } /* for times */
  9950. count += times;
  9951. } while (bench_stats_check(start)
  9952. #ifdef MULTI_VALUE_STATISTICS
  9953. || runs < minimum_runs
  9954. #endif
  9955. );
  9956. exit_ecdsa_sign:
  9957. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9958. wc_ecc_get_name(curveId));
  9959. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9960. useDeviceID, count, start, ret);
  9961. #ifdef MULTI_VALUE_STATISTICS
  9962. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9963. #endif
  9964. RESET_MULTI_VALUE_STATS_VARS();
  9965. if (ret < 0) {
  9966. goto exit;
  9967. }
  9968. #ifdef HAVE_ECC_VERIFY
  9969. /* ECC Verify */
  9970. bench_stats_start(&count, &start);
  9971. do {
  9972. for (times = 0; times < agreeTimes || pending > 0; ) {
  9973. bench_async_poll(&pending);
  9974. /* while free pending slots in queue, submit ops */
  9975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9976. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9977. &times, agreeTimes, &pending)) {
  9978. if (genKey[i]->state == 0) {
  9979. verify[i] = 0;
  9980. }
  9981. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9982. (word32)keySize, &verify[i],
  9983. genKey[i]);
  9984. if (!bench_async_handle(&ret,
  9985. BENCH_ASYNC_GET_DEV(genKey[i]),
  9986. 1, &times,
  9987. &pending)) {
  9988. goto exit_ecdsa_verify;
  9989. }
  9990. } /* if bench_async_check */
  9991. } /* for i */
  9992. RECORD_MULTI_VALUE_STATS();
  9993. } /* for times */
  9994. count += times;
  9995. } while (bench_stats_check(start)
  9996. #ifdef MULTI_VALUE_STATISTICS
  9997. || runs < minimum_runs
  9998. #endif
  9999. );
  10000. exit_ecdsa_verify:
  10001. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10002. wc_ecc_get_name(curveId));
  10003. bench_stats_asym_finish(name, keySize * 8, desc[5],
  10004. useDeviceID, count, start, ret);
  10005. #ifdef MULTI_VALUE_STATISTICS
  10006. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10007. #endif
  10008. #endif /* HAVE_ECC_VERIFY */
  10009. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10010. exit:
  10011. /* cleanup */
  10012. if (WC_ARRAY_OK(genKey)) {
  10013. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10014. wc_ecc_free(genKey[i]);
  10015. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10016. }
  10017. #ifdef HAVE_ECC_DHE
  10018. if (WC_ARRAY_OK(genKey2)) {
  10019. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10020. wc_ecc_free(genKey2[i]);
  10021. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10022. }
  10023. #endif
  10024. #ifdef HAVE_ECC_DHE
  10025. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10026. #endif
  10027. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10028. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10029. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10030. #endif
  10031. (void)useDeviceID;
  10032. (void)pending;
  10033. (void)x;
  10034. (void)count;
  10035. (void)times;
  10036. (void)desc;
  10037. (void)start;
  10038. (void)name;
  10039. }
  10040. #ifdef HAVE_ECC_ENCRYPT
  10041. void bench_eccEncrypt(int curveId)
  10042. {
  10043. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  10044. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  10045. WC_SHA256_DIGEST_SIZE + \
  10046. (MAX_ECC_BITS+3)/4 + 2)
  10047. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  10048. #ifdef WOLFSSL_SMALL_STACK
  10049. ecc_key *userA = NULL, *userB = NULL;
  10050. byte *msg = NULL;
  10051. byte *out = NULL;
  10052. #else
  10053. ecc_key userA[1], userB[1];
  10054. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  10055. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  10056. #endif
  10057. char name[BENCH_ECC_NAME_SZ];
  10058. int keySize;
  10059. word32 bench_plainSz = bench_size;
  10060. int ret, i, count;
  10061. double start;
  10062. const char**desc = bench_desc_words[lng_index];
  10063. DECLARE_MULTI_VALUE_STATS_VARS()
  10064. #ifdef WOLFSSL_SMALL_STACK
  10065. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10066. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10067. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10068. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10069. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10070. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10071. out = (byte *)XMALLOC(outSz,
  10072. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10073. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10074. printf("bench_eccEncrypt malloc failed\n");
  10075. goto exit;
  10076. }
  10077. #endif
  10078. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10079. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10080. if (ret != 0) {
  10081. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10082. goto exit;
  10083. }
  10084. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10085. if (ret != 0) {
  10086. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10087. goto exit;
  10088. }
  10089. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10090. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10091. !defined(HAVE_SELFTEST)
  10092. ret = wc_ecc_set_rng(userA, &gRng);
  10093. if (ret != 0) {
  10094. goto exit;
  10095. }
  10096. ret = wc_ecc_set_rng(userB, &gRng);
  10097. if (ret != 0) {
  10098. goto exit;
  10099. }
  10100. #endif
  10101. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10102. #ifdef WOLFSSL_ASYNC_CRYPT
  10103. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10104. #endif
  10105. if (ret != 0)
  10106. goto exit;
  10107. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10108. #ifdef WOLFSSL_ASYNC_CRYPT
  10109. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10110. #endif
  10111. if (ret != 0)
  10112. goto exit;
  10113. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10114. msg[i] = (byte)i;
  10115. }
  10116. bench_stats_start(&count, &start);
  10117. do {
  10118. for (i = 0; i < ntimes; i++) {
  10119. /* encrypt msg to B */
  10120. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10121. out, &outSz, NULL);
  10122. if (ret != 0) {
  10123. printf("wc_ecc_encrypt failed! %d\n", ret);
  10124. goto exit_enc;
  10125. }
  10126. RECORD_MULTI_VALUE_STATS();
  10127. }
  10128. count += i;
  10129. } while (bench_stats_check(start)
  10130. #ifdef MULTI_VALUE_STATISTICS
  10131. || runs < minimum_runs
  10132. #endif
  10133. );
  10134. exit_enc:
  10135. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10136. wc_ecc_get_name(curveId));
  10137. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10138. #ifdef MULTI_VALUE_STATISTICS
  10139. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10140. #endif
  10141. RESET_MULTI_VALUE_STATS_VARS();
  10142. if (ret != 0)
  10143. goto exit;
  10144. bench_stats_start(&count, &start);
  10145. do {
  10146. for (i = 0; i < ntimes; i++) {
  10147. /* decrypt msg from A */
  10148. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10149. &bench_plainSz, NULL);
  10150. if (ret != 0) {
  10151. printf("wc_ecc_decrypt failed! %d\n", ret);
  10152. goto exit_dec;
  10153. }
  10154. RECORD_MULTI_VALUE_STATS();
  10155. }
  10156. count += i;
  10157. } while (bench_stats_check(start)
  10158. #ifdef MULTI_VALUE_STATISTICS
  10159. || runs < minimum_runs
  10160. #endif
  10161. );
  10162. exit_dec:
  10163. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10164. #ifdef MULTI_VALUE_STATISTICS
  10165. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10166. #endif
  10167. exit:
  10168. /* cleanup */
  10169. #ifdef WOLFSSL_SMALL_STACK
  10170. if (userA) {
  10171. wc_ecc_free(userA);
  10172. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10173. }
  10174. if (userB) {
  10175. wc_ecc_free(userB);
  10176. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10177. }
  10178. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10179. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10180. #else
  10181. wc_ecc_free(userB);
  10182. wc_ecc_free(userA);
  10183. #endif
  10184. }
  10185. #endif
  10186. #ifdef WOLFSSL_SM2
  10187. static void bench_sm2_MakeKey(int useDeviceID)
  10188. {
  10189. int ret = 0, i, times, count = 0, pending = 0;
  10190. int deviceID;
  10191. int keySize;
  10192. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10193. sizeof(ecc_key), HEAP_HINT);
  10194. char name[BENCH_ECC_NAME_SZ];
  10195. double start = 0;
  10196. const char**desc = bench_desc_words[lng_index];
  10197. DECLARE_MULTI_VALUE_STATS_VARS()
  10198. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10199. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10200. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10201. sizeof(ecc_key), HEAP_HINT);
  10202. /* ECC Make Key */
  10203. bench_stats_start(&count, &start);
  10204. do {
  10205. /* while free pending slots in queue, submit ops */
  10206. for (times = 0; times < agreeTimes || pending > 0; ) {
  10207. bench_async_poll(&pending);
  10208. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10209. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10210. &times, agreeTimes, &pending)) {
  10211. wc_ecc_free(genKey[i]);
  10212. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10213. if (ret < 0) {
  10214. goto exit;
  10215. }
  10216. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10217. WC_ECC_FLAG_NONE);
  10218. if (!bench_async_handle(&ret,
  10219. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10220. &pending)) {
  10221. goto exit;
  10222. }
  10223. }
  10224. } /* for i */
  10225. RECORD_MULTI_VALUE_STATS();
  10226. } /* for times */
  10227. count += times;
  10228. } while (bench_stats_check(start)
  10229. #ifdef MULTI_VALUE_STATISTICS
  10230. || runs < minimum_runs
  10231. #endif
  10232. );
  10233. exit:
  10234. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10235. wc_ecc_get_name(ECC_SM2P256V1));
  10236. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10237. start, ret);
  10238. #ifdef MULTI_VALUE_STATISTICS
  10239. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10240. #endif
  10241. /* cleanup */
  10242. if (WC_ARRAY_OK(genKey)) {
  10243. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10244. wc_ecc_free(genKey[i]);
  10245. }
  10246. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10247. }
  10248. }
  10249. void bench_sm2(int useDeviceID)
  10250. {
  10251. int ret = 0, i, times, count, pending = 0;
  10252. int deviceID;
  10253. int keySize;
  10254. char name[BENCH_ECC_NAME_SZ];
  10255. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10256. sizeof(ecc_key), HEAP_HINT);
  10257. #ifdef HAVE_ECC_DHE
  10258. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10259. sizeof(ecc_key), HEAP_HINT);
  10260. #endif
  10261. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10262. #ifdef HAVE_ECC_VERIFY
  10263. int verify[BENCH_MAX_PENDING];
  10264. #endif
  10265. #endif
  10266. word32 x[BENCH_MAX_PENDING];
  10267. double start = 0;
  10268. const char**desc = bench_desc_words[lng_index];
  10269. DECLARE_MULTI_VALUE_STATS_VARS()
  10270. #ifdef HAVE_ECC_DHE
  10271. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10272. #endif
  10273. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10274. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10275. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10276. #endif
  10277. #ifdef HAVE_ECC_DHE
  10278. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10279. #endif
  10280. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10281. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10282. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10283. #endif
  10284. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10285. bench_sm2_MakeKey(useDeviceID);
  10286. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10287. sizeof(ecc_key), HEAP_HINT);
  10288. #ifdef HAVE_ECC_DHE
  10289. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10290. sizeof(ecc_key), HEAP_HINT);
  10291. #endif
  10292. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10293. /* init keys */
  10294. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10295. /* setup an context for each key */
  10296. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10297. goto exit;
  10298. }
  10299. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10300. #ifdef WOLFSSL_ASYNC_CRYPT
  10301. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10302. #endif
  10303. if (ret < 0) {
  10304. goto exit;
  10305. }
  10306. #ifdef HAVE_ECC_DHE
  10307. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10308. goto exit;
  10309. }
  10310. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10311. WC_ECC_FLAG_NONE)) > 0) {
  10312. goto exit;
  10313. }
  10314. #endif
  10315. }
  10316. #ifdef HAVE_ECC_DHE
  10317. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10318. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10319. !defined(HAVE_SELFTEST)
  10320. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10321. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10322. }
  10323. #endif
  10324. /* ECC Shared Secret */
  10325. bench_stats_start(&count, &start);
  10326. PRIVATE_KEY_UNLOCK();
  10327. do {
  10328. for (times = 0; times < agreeTimes || pending > 0; ) {
  10329. bench_async_poll(&pending);
  10330. /* while free pending slots in queue, submit ops */
  10331. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10332. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10333. &times, agreeTimes, &pending)) {
  10334. x[i] = (word32)keySize;
  10335. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10336. shared[i], &x[i]);
  10337. if (!bench_async_handle(&ret,
  10338. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10339. &pending)) {
  10340. goto exit_ecdhe;
  10341. }
  10342. }
  10343. } /* for i */
  10344. RECORD_MULTI_VALUE_STATS();
  10345. } /* for times */
  10346. count += times;
  10347. } while (bench_stats_check(start)
  10348. #ifdef MULTI_VALUE_STATISTICS
  10349. || runs < minimum_runs
  10350. #endif
  10351. );
  10352. PRIVATE_KEY_UNLOCK();
  10353. exit_ecdhe:
  10354. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10355. wc_ecc_get_name(ECC_SM2P256V1));
  10356. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10357. start, ret);
  10358. #ifdef MULTI_VALUE_STATISTICS
  10359. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10360. #endif
  10361. if (ret < 0) {
  10362. goto exit;
  10363. }
  10364. #endif /* HAVE_ECC_DHE */
  10365. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10366. /* Init digest to sign */
  10367. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10368. for (count = 0; count < keySize; count++) {
  10369. digest[i][count] = (byte)count;
  10370. }
  10371. }
  10372. RESET_MULTI_VALUE_STATS_VARS();
  10373. /* ECC Sign */
  10374. bench_stats_start(&count, &start);
  10375. do {
  10376. for (times = 0; times < agreeTimes || pending > 0; ) {
  10377. bench_async_poll(&pending);
  10378. /* while free pending slots in queue, submit ops */
  10379. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10380. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10381. &times, agreeTimes, &pending)) {
  10382. if (genKey[i]->state == 0)
  10383. x[i] = ECC_MAX_SIG_SIZE;
  10384. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10385. sig[i], &x[i], &gRng, genKey[i]);
  10386. if (!bench_async_handle(&ret,
  10387. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10388. &pending)) {
  10389. goto exit_ecdsa_sign;
  10390. }
  10391. }
  10392. } /* for i */
  10393. RECORD_MULTI_VALUE_STATS();
  10394. } /* for times */
  10395. count += times;
  10396. } while (bench_stats_check(start)
  10397. #ifdef MULTI_VALUE_STATISTICS
  10398. || runs < minimum_runs
  10399. #endif
  10400. );
  10401. exit_ecdsa_sign:
  10402. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10403. wc_ecc_get_name(ECC_SM2P256V1));
  10404. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10405. start, ret);
  10406. #ifdef MULTI_VALUE_STATISTICS
  10407. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10408. #endif
  10409. if (ret < 0) {
  10410. goto exit;
  10411. }
  10412. #ifdef HAVE_ECC_VERIFY
  10413. /* ECC Verify */
  10414. bench_stats_start(&count, &start);
  10415. do {
  10416. for (times = 0; times < agreeTimes || pending > 0; ) {
  10417. bench_async_poll(&pending);
  10418. /* while free pending slots in queue, submit ops */
  10419. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10420. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10421. &times, agreeTimes, &pending)) {
  10422. if (genKey[i]->state == 0)
  10423. verify[i] = 0;
  10424. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10425. (word32)keySize, &verify[i], genKey[i]);
  10426. if (!bench_async_handle(&ret,
  10427. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10428. &pending)) {
  10429. goto exit_ecdsa_verify;
  10430. }
  10431. }
  10432. } /* for i */
  10433. RECORD_MULTI_VALUE_STATS();
  10434. } /* for times */
  10435. count += times;
  10436. } while (bench_stats_check(start)
  10437. #ifdef MULTI_VALUE_STATISTICS
  10438. || runs < minimum_runs
  10439. #endif
  10440. );
  10441. exit_ecdsa_verify:
  10442. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10443. wc_ecc_get_name(ECC_SM2P256V1));
  10444. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10445. start, ret);
  10446. #ifdef MULTI_VALUE_STATISTICS
  10447. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10448. #endif
  10449. #endif /* HAVE_ECC_VERIFY */
  10450. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10451. exit:
  10452. /* cleanup */
  10453. if (WC_ARRAY_OK(genKey)) {
  10454. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10455. wc_ecc_free(genKey[i]);
  10456. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10457. }
  10458. #ifdef HAVE_ECC_DHE
  10459. if (WC_ARRAY_OK(genKey2)) {
  10460. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10461. wc_ecc_free(genKey2[i]);
  10462. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10463. }
  10464. #endif
  10465. #ifdef HAVE_ECC_DHE
  10466. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10467. #endif
  10468. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10469. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10470. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10471. #endif
  10472. (void)useDeviceID;
  10473. (void)pending;
  10474. (void)x;
  10475. (void)count;
  10476. (void)times;
  10477. (void)desc;
  10478. (void)start;
  10479. (void)name;
  10480. }
  10481. #endif /* WOLFSSL_SM2 */
  10482. #endif /* HAVE_ECC */
  10483. #ifdef HAVE_CURVE25519
  10484. void bench_curve25519KeyGen(int useDeviceID)
  10485. {
  10486. curve25519_key genKey;
  10487. double start;
  10488. int ret = 0, i, count;
  10489. const char**desc = bench_desc_words[lng_index];
  10490. DECLARE_MULTI_VALUE_STATS_VARS()
  10491. /* Key Gen */
  10492. bench_stats_start(&count, &start);
  10493. do {
  10494. for (i = 0; i < genTimes; i++) {
  10495. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10496. useDeviceID ? devId : INVALID_DEVID);
  10497. if (ret != 0) {
  10498. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10499. break;
  10500. }
  10501. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10502. wc_curve25519_free(&genKey);
  10503. if (ret != 0) {
  10504. printf("wc_curve25519_make_key failed: %d\n", ret);
  10505. break;
  10506. }
  10507. RECORD_MULTI_VALUE_STATS();
  10508. }
  10509. count += i;
  10510. } while (bench_stats_check(start)
  10511. #ifdef MULTI_VALUE_STATISTICS
  10512. || runs < minimum_runs
  10513. #endif
  10514. );
  10515. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10516. ret);
  10517. #ifdef MULTI_VALUE_STATISTICS
  10518. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10519. #endif
  10520. }
  10521. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10522. void bench_curve25519KeyAgree(int useDeviceID)
  10523. {
  10524. curve25519_key genKey, genKey2;
  10525. double start;
  10526. int ret, i, count;
  10527. byte shared[32];
  10528. const char**desc = bench_desc_words[lng_index];
  10529. word32 x = 0;
  10530. DECLARE_MULTI_VALUE_STATS_VARS()
  10531. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10532. useDeviceID ? devId : INVALID_DEVID);
  10533. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10534. useDeviceID ? devId : INVALID_DEVID);
  10535. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10536. if (ret != 0) {
  10537. printf("curve25519_make_key failed\n");
  10538. return;
  10539. }
  10540. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10541. if (ret != 0) {
  10542. printf("curve25519_make_key failed: %d\n", ret);
  10543. wc_curve25519_free(&genKey);
  10544. return;
  10545. }
  10546. /* Shared secret */
  10547. bench_stats_start(&count, &start);
  10548. do {
  10549. for (i = 0; i < agreeTimes; i++) {
  10550. x = sizeof(shared);
  10551. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10552. if (ret != 0) {
  10553. printf("curve25519_shared_secret failed: %d\n", ret);
  10554. goto exit;
  10555. }
  10556. RECORD_MULTI_VALUE_STATS();
  10557. }
  10558. count += i;
  10559. } while (bench_stats_check(start)
  10560. #ifdef MULTI_VALUE_STATISTICS
  10561. || runs < minimum_runs
  10562. #endif
  10563. );
  10564. exit:
  10565. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10566. ret);
  10567. #ifdef MULTI_VALUE_STATISTICS
  10568. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10569. #endif
  10570. wc_curve25519_free(&genKey2);
  10571. wc_curve25519_free(&genKey);
  10572. }
  10573. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10574. #endif /* HAVE_CURVE25519 */
  10575. #ifdef HAVE_ED25519
  10576. void bench_ed25519KeyGen(void)
  10577. {
  10578. #ifdef HAVE_ED25519_MAKE_KEY
  10579. ed25519_key genKey;
  10580. double start;
  10581. int i, count;
  10582. const char**desc = bench_desc_words[lng_index];
  10583. DECLARE_MULTI_VALUE_STATS_VARS()
  10584. /* Key Gen */
  10585. bench_stats_start(&count, &start);
  10586. do {
  10587. for (i = 0; i < genTimes; i++) {
  10588. wc_ed25519_init(&genKey);
  10589. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10590. wc_ed25519_free(&genKey);
  10591. RECORD_MULTI_VALUE_STATS();
  10592. }
  10593. count += i;
  10594. } while (bench_stats_check(start)
  10595. #ifdef MULTI_VALUE_STATISTICS
  10596. || runs < minimum_runs
  10597. #endif
  10598. );
  10599. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10600. #ifdef MULTI_VALUE_STATISTICS
  10601. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10602. #endif
  10603. #endif /* HAVE_ED25519_MAKE_KEY */
  10604. }
  10605. void bench_ed25519KeySign(void)
  10606. {
  10607. #ifdef HAVE_ED25519_MAKE_KEY
  10608. int ret;
  10609. #endif
  10610. ed25519_key genKey;
  10611. #ifdef HAVE_ED25519_SIGN
  10612. double start;
  10613. int i, count;
  10614. byte sig[ED25519_SIG_SIZE];
  10615. byte msg[512];
  10616. word32 x = 0;
  10617. const char**desc = bench_desc_words[lng_index];
  10618. DECLARE_MULTI_VALUE_STATS_VARS()
  10619. #endif
  10620. wc_ed25519_init(&genKey);
  10621. #ifdef HAVE_ED25519_MAKE_KEY
  10622. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10623. if (ret != 0) {
  10624. printf("ed25519_make_key failed\n");
  10625. return;
  10626. }
  10627. #endif
  10628. #ifdef HAVE_ED25519_SIGN
  10629. /* make dummy msg */
  10630. for (i = 0; i < (int)sizeof(msg); i++)
  10631. msg[i] = (byte)i;
  10632. bench_stats_start(&count, &start);
  10633. do {
  10634. for (i = 0; i < agreeTimes; i++) {
  10635. x = sizeof(sig);
  10636. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10637. if (ret != 0) {
  10638. printf("ed25519_sign_msg failed\n");
  10639. goto exit_ed_sign;
  10640. }
  10641. RECORD_MULTI_VALUE_STATS();
  10642. }
  10643. count += i;
  10644. } while (bench_stats_check(start)
  10645. #ifdef MULTI_VALUE_STATISTICS
  10646. || runs < minimum_runs
  10647. #endif
  10648. );
  10649. exit_ed_sign:
  10650. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10651. #ifdef MULTI_VALUE_STATISTICS
  10652. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10653. #endif
  10654. RESET_MULTI_VALUE_STATS_VARS();
  10655. #ifdef HAVE_ED25519_VERIFY
  10656. bench_stats_start(&count, &start);
  10657. do {
  10658. for (i = 0; i < agreeTimes; i++) {
  10659. int verify = 0;
  10660. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10661. &genKey);
  10662. if (ret != 0 || verify != 1) {
  10663. printf("ed25519_verify_msg failed\n");
  10664. goto exit_ed_verify;
  10665. }
  10666. RECORD_MULTI_VALUE_STATS();
  10667. }
  10668. count += i;
  10669. } while (bench_stats_check(start)
  10670. #ifdef MULTI_VALUE_STATISTICS
  10671. || runs < minimum_runs
  10672. #endif
  10673. );
  10674. exit_ed_verify:
  10675. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10676. #ifdef MULTI_VALUE_STATISTICS
  10677. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10678. #endif
  10679. #endif /* HAVE_ED25519_VERIFY */
  10680. #endif /* HAVE_ED25519_SIGN */
  10681. wc_ed25519_free(&genKey);
  10682. }
  10683. #endif /* HAVE_ED25519 */
  10684. #ifdef HAVE_CURVE448
  10685. void bench_curve448KeyGen(void)
  10686. {
  10687. curve448_key genKey;
  10688. double start;
  10689. int ret = 0, i, count;
  10690. const char**desc = bench_desc_words[lng_index];
  10691. DECLARE_MULTI_VALUE_STATS_VARS()
  10692. /* Key Gen */
  10693. bench_stats_start(&count, &start);
  10694. do {
  10695. for (i = 0; i < genTimes; i++) {
  10696. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10697. wc_curve448_free(&genKey);
  10698. if (ret != 0) {
  10699. printf("wc_curve448_make_key failed: %d\n", ret);
  10700. break;
  10701. }
  10702. RECORD_MULTI_VALUE_STATS();
  10703. }
  10704. count += i;
  10705. } while (bench_stats_check(start)
  10706. #ifdef MULTI_VALUE_STATISTICS
  10707. || runs < minimum_runs
  10708. #endif
  10709. );
  10710. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10711. #ifdef MULTI_VALUE_STATISTICS
  10712. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10713. #endif
  10714. }
  10715. #ifdef HAVE_CURVE448_SHARED_SECRET
  10716. void bench_curve448KeyAgree(void)
  10717. {
  10718. curve448_key genKey, genKey2;
  10719. double start;
  10720. int ret, i, count;
  10721. byte shared[56];
  10722. const char**desc = bench_desc_words[lng_index];
  10723. word32 x = 0;
  10724. DECLARE_MULTI_VALUE_STATS_VARS()
  10725. wc_curve448_init(&genKey);
  10726. wc_curve448_init(&genKey2);
  10727. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10728. if (ret != 0) {
  10729. printf("curve448_make_key failed\n");
  10730. return;
  10731. }
  10732. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10733. if (ret != 0) {
  10734. printf("curve448_make_key failed: %d\n", ret);
  10735. wc_curve448_free(&genKey);
  10736. return;
  10737. }
  10738. /* Shared secret */
  10739. bench_stats_start(&count, &start);
  10740. do {
  10741. for (i = 0; i < agreeTimes; i++) {
  10742. x = sizeof(shared);
  10743. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10744. if (ret != 0) {
  10745. printf("curve448_shared_secret failed: %d\n", ret);
  10746. goto exit;
  10747. }
  10748. RECORD_MULTI_VALUE_STATS();
  10749. }
  10750. count += i;
  10751. } while (bench_stats_check(start)
  10752. #ifdef MULTI_VALUE_STATISTICS
  10753. || runs < minimum_runs
  10754. #endif
  10755. );
  10756. exit:
  10757. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10758. #ifdef MULTI_VALUE_STATISTICS
  10759. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10760. #endif
  10761. wc_curve448_free(&genKey2);
  10762. wc_curve448_free(&genKey);
  10763. }
  10764. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10765. #endif /* HAVE_CURVE448 */
  10766. #ifdef HAVE_ED448
  10767. void bench_ed448KeyGen(void)
  10768. {
  10769. ed448_key genKey;
  10770. double start;
  10771. int i, count;
  10772. const char**desc = bench_desc_words[lng_index];
  10773. DECLARE_MULTI_VALUE_STATS_VARS()
  10774. /* Key Gen */
  10775. bench_stats_start(&count, &start);
  10776. do {
  10777. for (i = 0; i < genTimes; i++) {
  10778. wc_ed448_init(&genKey);
  10779. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10780. wc_ed448_free(&genKey);
  10781. RECORD_MULTI_VALUE_STATS();
  10782. }
  10783. count += i;
  10784. } while (bench_stats_check(start)
  10785. #ifdef MULTI_VALUE_STATISTICS
  10786. || runs < minimum_runs
  10787. #endif
  10788. );
  10789. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10790. #ifdef MULTI_VALUE_STATISTICS
  10791. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10792. #endif
  10793. }
  10794. void bench_ed448KeySign(void)
  10795. {
  10796. int ret;
  10797. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10798. #ifdef HAVE_ED448_SIGN
  10799. double start;
  10800. int i, count;
  10801. byte sig[ED448_SIG_SIZE];
  10802. byte msg[512];
  10803. word32 x = 0;
  10804. const char**desc = bench_desc_words[lng_index];
  10805. DECLARE_MULTI_VALUE_STATS_VARS()
  10806. #endif
  10807. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10808. wc_ed448_init(genKey);
  10809. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10810. if (ret != 0) {
  10811. printf("ed448_make_key failed\n");
  10812. goto exit;
  10813. }
  10814. #ifdef HAVE_ED448_SIGN
  10815. /* make dummy msg */
  10816. for (i = 0; i < (int)sizeof(msg); i++)
  10817. msg[i] = (byte)i;
  10818. bench_stats_start(&count, &start);
  10819. do {
  10820. for (i = 0; i < agreeTimes; i++) {
  10821. x = sizeof(sig);
  10822. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10823. NULL, 0);
  10824. if (ret != 0) {
  10825. printf("ed448_sign_msg failed\n");
  10826. goto exit;
  10827. }
  10828. RECORD_MULTI_VALUE_STATS();
  10829. }
  10830. count += i;
  10831. } while (bench_stats_check(start)
  10832. #ifdef MULTI_VALUE_STATISTICS
  10833. || runs < minimum_runs
  10834. #endif
  10835. );
  10836. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10837. #ifdef MULTI_VALUE_STATISTICS
  10838. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10839. #endif
  10840. RESET_MULTI_VALUE_STATS_VARS();
  10841. #ifdef HAVE_ED448_VERIFY
  10842. bench_stats_start(&count, &start);
  10843. do {
  10844. for (i = 0; i < agreeTimes; i++) {
  10845. int verify = 0;
  10846. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10847. genKey, NULL, 0);
  10848. if (ret != 0 || verify != 1) {
  10849. printf("ed448_verify_msg failed\n");
  10850. goto exit;
  10851. }
  10852. RECORD_MULTI_VALUE_STATS();
  10853. }
  10854. count += i;
  10855. } while (bench_stats_check(start)
  10856. #ifdef MULTI_VALUE_STATISTICS
  10857. || runs < minimum_runs
  10858. #endif
  10859. );
  10860. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10861. #ifdef MULTI_VALUE_STATISTICS
  10862. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10863. #endif
  10864. #endif /* HAVE_ED448_VERIFY */
  10865. #endif /* HAVE_ED448_SIGN */
  10866. exit:
  10867. wc_ed448_free(genKey);
  10868. WC_FREE_VAR(genKey, HEAP_HINT);
  10869. }
  10870. #endif /* HAVE_ED448 */
  10871. #ifdef WOLFCRYPT_HAVE_ECCSI
  10872. #ifdef WOLFCRYPT_ECCSI_KMS
  10873. void bench_eccsiKeyGen(void)
  10874. {
  10875. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10876. double start;
  10877. int i, count;
  10878. const char**desc = bench_desc_words[lng_index];
  10879. int ret;
  10880. DECLARE_MULTI_VALUE_STATS_VARS()
  10881. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10882. /* Key Gen */
  10883. bench_stats_start(&count, &start);
  10884. do {
  10885. for (i = 0; i < genTimes; i++) {
  10886. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10887. ret = wc_MakeEccsiKey(genKey, &gRng);
  10888. wc_FreeEccsiKey(genKey);
  10889. if (ret != 0) {
  10890. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10891. goto exit;
  10892. }
  10893. RECORD_MULTI_VALUE_STATS();
  10894. }
  10895. count += i;
  10896. } while (bench_stats_check(start)
  10897. #ifdef MULTI_VALUE_STATISTICS
  10898. || runs < minimum_runs
  10899. #endif
  10900. );
  10901. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10902. #ifdef MULTI_VALUE_STATISTICS
  10903. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10904. #endif
  10905. exit:
  10906. WC_FREE_VAR(genKey, HEAP_HINT);
  10907. }
  10908. void bench_eccsiPairGen(void)
  10909. {
  10910. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10911. double start;
  10912. int i, count;
  10913. const char**desc = bench_desc_words[lng_index];
  10914. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10915. ecc_point* pvt;
  10916. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10917. int ret;
  10918. DECLARE_MULTI_VALUE_STATS_VARS()
  10919. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10920. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10921. (void)mp_init(ssk);
  10922. pvt = wc_ecc_new_point();
  10923. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10924. (void)wc_MakeEccsiKey(genKey, &gRng);
  10925. /* RSK Gen */
  10926. bench_stats_start(&count, &start);
  10927. do {
  10928. for (i = 0; i < genTimes; i++) {
  10929. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10930. sizeof(id), ssk, pvt);
  10931. if (ret != 0) {
  10932. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10933. goto exit;
  10934. }
  10935. RECORD_MULTI_VALUE_STATS();
  10936. }
  10937. count += i;
  10938. } while (bench_stats_check(start)
  10939. #ifdef MULTI_VALUE_STATISTICS
  10940. || runs < minimum_runs
  10941. #endif
  10942. );
  10943. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10944. #ifdef MULTI_VALUE_STATISTICS
  10945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10946. #endif
  10947. wc_FreeEccsiKey(genKey);
  10948. wc_ecc_del_point(pvt);
  10949. mp_free(ssk);
  10950. exit:
  10951. WC_FREE_VAR(genKey, HEAP_HINT);
  10952. WC_FREE_VAR(ssk, HEAP_HINT);
  10953. }
  10954. #endif
  10955. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10956. void bench_eccsiValidate(void)
  10957. {
  10958. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10959. double start;
  10960. int i, count;
  10961. const char**desc = bench_desc_words[lng_index];
  10962. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10963. ecc_point* pvt;
  10964. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10965. int valid;
  10966. int ret;
  10967. DECLARE_MULTI_VALUE_STATS_VARS()
  10968. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10969. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10970. (void)mp_init(ssk);
  10971. pvt = wc_ecc_new_point();
  10972. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10973. (void)wc_MakeEccsiKey(genKey, &gRng);
  10974. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10975. ssk, pvt);
  10976. /* Validation of RSK */
  10977. bench_stats_start(&count, &start);
  10978. do {
  10979. for (i = 0; i < genTimes; i++) {
  10980. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10981. sizeof(id), ssk, pvt, &valid);
  10982. if (ret != 0 || !valid) {
  10983. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10984. valid);
  10985. goto exit;
  10986. }
  10987. RECORD_MULTI_VALUE_STATS();
  10988. }
  10989. count += i;
  10990. } while (bench_stats_check(start)
  10991. #ifdef MULTI_VALUE_STATISTICS
  10992. || runs < minimum_runs
  10993. #endif
  10994. );
  10995. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10996. #ifdef MULTI_VALUE_STATISTICS
  10997. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10998. #endif
  10999. wc_FreeEccsiKey(genKey);
  11000. wc_ecc_del_point(pvt);
  11001. mp_free(ssk);
  11002. exit:
  11003. WC_FREE_VAR(genKey, HEAP_HINT);
  11004. WC_FREE_VAR(ssk, HEAP_HINT);
  11005. }
  11006. void bench_eccsi(void)
  11007. {
  11008. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11009. double start;
  11010. int i, count;
  11011. const char**desc = bench_desc_words[lng_index];
  11012. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  11013. ecc_point* pvt;
  11014. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11015. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  11016. byte hash[WC_SHA256_DIGEST_SIZE];
  11017. byte hashSz = (byte)sizeof(hash);
  11018. byte sig[257];
  11019. word32 sigSz = sizeof(sig);
  11020. int ret;
  11021. int verified;
  11022. DECLARE_MULTI_VALUE_STATS_VARS()
  11023. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11024. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11025. (void)mp_init(ssk);
  11026. pvt = wc_ecc_new_point();
  11027. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11028. (void)wc_MakeEccsiKey(genKey, &gRng);
  11029. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11030. ssk, pvt);
  11031. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  11032. hash, &hashSz);
  11033. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  11034. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  11035. /* Encapsulate */
  11036. bench_stats_start(&count, &start);
  11037. do {
  11038. for (i = 0; i < genTimes; i++) {
  11039. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  11040. sizeof(msg), sig, &sigSz);
  11041. if (ret != 0) {
  11042. printf("wc_SignEccsiHash failed: %d\n", ret);
  11043. break;
  11044. }
  11045. RECORD_MULTI_VALUE_STATS();
  11046. }
  11047. count += i;
  11048. } while (bench_stats_check(start)
  11049. #ifdef MULTI_VALUE_STATISTICS
  11050. || runs < minimum_runs
  11051. #endif
  11052. );
  11053. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  11054. #ifdef MULTI_VALUE_STATISTICS
  11055. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11056. #endif
  11057. RESET_MULTI_VALUE_STATS_VARS();
  11058. /* Derive */
  11059. bench_stats_start(&count, &start);
  11060. do {
  11061. for (i = 0; i < genTimes; i++) {
  11062. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11063. sizeof(msg), sig, sigSz, &verified);
  11064. if (ret != 0 || !verified) {
  11065. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11066. verified);
  11067. goto exit;
  11068. }
  11069. RECORD_MULTI_VALUE_STATS();
  11070. }
  11071. count += i;
  11072. } while (bench_stats_check(start)
  11073. #ifdef MULTI_VALUE_STATISTICS
  11074. || runs < minimum_runs
  11075. #endif
  11076. );
  11077. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11078. #ifdef MULTI_VALUE_STATISTICS
  11079. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11080. #endif
  11081. wc_FreeEccsiKey(genKey);
  11082. wc_ecc_del_point(pvt);
  11083. exit:
  11084. WC_FREE_VAR(genKey, HEAP_HINT);
  11085. WC_FREE_VAR(ssk, HEAP_HINT);
  11086. }
  11087. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11088. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11089. #ifdef WOLFCRYPT_HAVE_SAKKE
  11090. #ifdef WOLFCRYPT_SAKKE_KMS
  11091. void bench_sakkeKeyGen(void)
  11092. {
  11093. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11094. double start;
  11095. int i, count;
  11096. const char**desc = bench_desc_words[lng_index];
  11097. int ret;
  11098. DECLARE_MULTI_VALUE_STATS_VARS()
  11099. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11100. /* Key Gen */
  11101. bench_stats_start(&count, &start);
  11102. do {
  11103. for (i = 0; i < genTimes; i++) {
  11104. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11105. ret = wc_MakeSakkeKey(genKey, &gRng);
  11106. if (ret != 0) {
  11107. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11108. goto exit;
  11109. }
  11110. wc_FreeSakkeKey(genKey);
  11111. RECORD_MULTI_VALUE_STATS();
  11112. }
  11113. count += i;
  11114. } while (bench_stats_check(start)
  11115. #ifdef MULTI_VALUE_STATISTICS
  11116. || runs < minimum_runs
  11117. #endif
  11118. );
  11119. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  11120. #ifdef MULTI_VALUE_STATISTICS
  11121. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11122. #endif
  11123. exit:
  11124. WC_FREE_VAR(genKey, HEAP_HINT);
  11125. }
  11126. void bench_sakkeRskGen(void)
  11127. {
  11128. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11129. double start;
  11130. int i, count;
  11131. const char**desc = bench_desc_words[lng_index];
  11132. ecc_point* rsk;
  11133. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11134. int ret;
  11135. DECLARE_MULTI_VALUE_STATS_VARS()
  11136. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11137. rsk = wc_ecc_new_point();
  11138. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11139. (void)wc_MakeSakkeKey(genKey, &gRng);
  11140. /* RSK Gen */
  11141. bench_stats_start(&count, &start);
  11142. do {
  11143. for (i = 0; i < genTimes; i++) {
  11144. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11145. if (ret != 0) {
  11146. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11147. goto exit;
  11148. }
  11149. RECORD_MULTI_VALUE_STATS();
  11150. }
  11151. count += i;
  11152. } while (bench_stats_check(start)
  11153. #ifdef MULTI_VALUE_STATISTICS
  11154. || runs < minimum_runs
  11155. #endif
  11156. );
  11157. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11158. #ifdef MULTI_VALUE_STATISTICS
  11159. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11160. #endif
  11161. wc_FreeSakkeKey(genKey);
  11162. wc_ecc_del_point(rsk);
  11163. exit:
  11164. WC_FREE_VAR(genKey, HEAP_HINT);
  11165. }
  11166. #endif
  11167. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11168. void bench_sakkeValidate(void)
  11169. {
  11170. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11171. double start;
  11172. int i, count;
  11173. const char**desc = bench_desc_words[lng_index];
  11174. ecc_point* rsk;
  11175. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11176. int valid;
  11177. int ret;
  11178. DECLARE_MULTI_VALUE_STATS_VARS()
  11179. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11180. rsk = wc_ecc_new_point();
  11181. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11182. (void)wc_MakeSakkeKey(genKey, &gRng);
  11183. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11184. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11185. /* Validation of RSK */
  11186. bench_stats_start(&count, &start);
  11187. do {
  11188. for (i = 0; i < genTimes; i++) {
  11189. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11190. if (ret != 0 || !valid) {
  11191. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11192. valid);
  11193. goto exit;
  11194. }
  11195. RECORD_MULTI_VALUE_STATS();
  11196. }
  11197. count += i;
  11198. } while (bench_stats_check(start)
  11199. #ifdef MULTI_VALUE_STATISTICS
  11200. || runs < minimum_runs
  11201. #endif
  11202. );
  11203. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11204. #ifdef MULTI_VALUE_STATISTICS
  11205. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11206. #endif
  11207. wc_FreeSakkeKey(genKey);
  11208. wc_ecc_del_point(rsk);
  11209. exit:
  11210. WC_FREE_VAR(genKey, HEAP_HINT);
  11211. }
  11212. void bench_sakke(void)
  11213. {
  11214. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11215. double start;
  11216. int i, count;
  11217. const char**desc = bench_desc_words[lng_index];
  11218. ecc_point* rsk;
  11219. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11220. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11221. byte ssv[sizeof(ssv_init)];
  11222. byte derSSV[sizeof(ssv)];
  11223. byte auth[257];
  11224. word16 authSz = sizeof(auth);
  11225. int ret = 0;
  11226. byte* table = NULL;
  11227. word32 len = 0;
  11228. byte* iTable = NULL;
  11229. word32 iTableLen = 0;
  11230. DECLARE_MULTI_VALUE_STATS_VARS()
  11231. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11232. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11233. rsk = wc_ecc_new_point();
  11234. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11235. (void)wc_MakeSakkeKey(genKey, &gRng);
  11236. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11237. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11238. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11239. /* Encapsulate */
  11240. bench_stats_start(&count, &start);
  11241. do {
  11242. for (i = 0; i < genTimes; i++) {
  11243. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11244. WC_HASH_TYPE_SHA256,
  11245. ssv, sizeof(ssv), auth, &authSz);
  11246. if (ret != 0) {
  11247. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11248. break;
  11249. }
  11250. RECORD_MULTI_VALUE_STATS();
  11251. } /* for */
  11252. count += i;
  11253. } while (bench_stats_check(start)
  11254. #ifdef MULTI_VALUE_STATISTICS
  11255. || runs < minimum_runs
  11256. #endif
  11257. );
  11258. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11259. 0, count, start, 0);
  11260. #ifdef MULTI_VALUE_STATISTICS
  11261. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11262. #endif
  11263. RESET_MULTI_VALUE_STATS_VARS();
  11264. /* Derive */
  11265. bench_stats_start(&count, &start);
  11266. do {
  11267. for (i = 0; i < genTimes; i++) {
  11268. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11269. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11270. sizeof(derSSV), auth, authSz);
  11271. if (ret != 0) {
  11272. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11273. break;
  11274. }
  11275. RECORD_MULTI_VALUE_STATS();
  11276. }
  11277. if (ret != 0) break;
  11278. count += i;
  11279. } while (bench_stats_check(start)
  11280. #ifdef MULTI_VALUE_STATISTICS
  11281. || runs < minimum_runs
  11282. #endif
  11283. );
  11284. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11285. 0, count, start, 0);
  11286. #ifdef MULTI_VALUE_STATISTICS
  11287. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11288. #endif
  11289. /* Calculate Point I and generate table. */
  11290. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11291. iTableLen = 0;
  11292. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11293. if (iTableLen != 0) {
  11294. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11295. if (iTable == NULL)
  11296. WC_ALLOC_DO_ON_FAILURE();
  11297. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11298. }
  11299. /* Encapsulate with Point I table */
  11300. bench_stats_start(&count, &start);
  11301. do {
  11302. for (i = 0; i < genTimes; i++) {
  11303. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11304. WC_HASH_TYPE_SHA256, ssv,
  11305. sizeof(ssv), auth, &authSz);
  11306. if (ret != 0) {
  11307. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11308. break;
  11309. }
  11310. RECORD_MULTI_VALUE_STATS();
  11311. }
  11312. count += i;
  11313. } while (bench_stats_check(start)
  11314. #ifdef MULTI_VALUE_STATISTICS
  11315. || runs < minimum_runs
  11316. #endif
  11317. );
  11318. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11319. count, start, 0);
  11320. #ifdef MULTI_VALUE_STATISTICS
  11321. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11322. #endif
  11323. RESET_MULTI_VALUE_STATS_VARS();
  11324. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11325. /* Derive with Point I table */
  11326. bench_stats_start(&count, &start);
  11327. do {
  11328. for (i = 0; i < genTimes; i++) {
  11329. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11330. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11331. sizeof(derSSV), auth, authSz);
  11332. if (ret != 0) {
  11333. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11334. break;
  11335. }
  11336. RECORD_MULTI_VALUE_STATS();
  11337. }
  11338. if (ret != 0) break;
  11339. count += i;
  11340. } while (bench_stats_check(start)
  11341. #ifdef MULTI_VALUE_STATISTICS
  11342. || runs < minimum_runs
  11343. #endif
  11344. );
  11345. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11346. count, start, 0);
  11347. #ifdef MULTI_VALUE_STATISTICS
  11348. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11349. #endif
  11350. RESET_MULTI_VALUE_STATS_VARS();
  11351. len = 0;
  11352. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11353. if (len > 0) {
  11354. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11355. if (table == NULL)
  11356. WC_ALLOC_DO_ON_FAILURE();
  11357. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11358. }
  11359. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11360. /* Derive with Point I table and RSK table */
  11361. bench_stats_start(&count, &start);
  11362. do {
  11363. for (i = 0; i < genTimes; i++) {
  11364. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11365. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11366. sizeof(derSSV), auth, authSz);
  11367. if (ret != 0) {
  11368. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11369. break;
  11370. }
  11371. RECORD_MULTI_VALUE_STATS();
  11372. }
  11373. if (ret != 0) break;
  11374. count += i;
  11375. } while (bench_stats_check(start)
  11376. #ifdef MULTI_VALUE_STATISTICS
  11377. || runs < minimum_runs
  11378. #endif
  11379. );
  11380. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11381. 0, count, start, 0);
  11382. #ifdef MULTI_VALUE_STATISTICS
  11383. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11384. #endif
  11385. RESET_MULTI_VALUE_STATS_VARS();
  11386. wc_ClearSakkePointITable(genKey);
  11387. /* Derive with RSK table */
  11388. bench_stats_start(&count, &start);
  11389. do {
  11390. for (i = 0; i < genTimes; i++) {
  11391. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11392. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11393. sizeof(derSSV), auth, authSz);
  11394. if (ret != 0) {
  11395. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11396. break;
  11397. }
  11398. RECORD_MULTI_VALUE_STATS();
  11399. }
  11400. if (ret != 0) break;
  11401. count += i;
  11402. } while (bench_stats_check(start)
  11403. #ifdef MULTI_VALUE_STATISTICS
  11404. || runs < minimum_runs
  11405. #endif
  11406. );
  11407. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11408. count, start, 0);
  11409. #ifdef MULTI_VALUE_STATISTICS
  11410. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11411. #endif
  11412. wc_FreeSakkeKey(genKey);
  11413. wc_ecc_del_point(rsk);
  11414. exit:
  11415. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11416. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11417. WC_FREE_VAR(genKey, HEAP_HINT);
  11418. }
  11419. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11420. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11421. #ifdef HAVE_FALCON
  11422. void bench_falconKeySign(byte level)
  11423. {
  11424. int ret = 0;
  11425. falcon_key key;
  11426. double start;
  11427. int i, count;
  11428. byte sig[FALCON_MAX_SIG_SIZE];
  11429. byte msg[512];
  11430. word32 x = 0;
  11431. const char**desc = bench_desc_words[lng_index];
  11432. DECLARE_MULTI_VALUE_STATS_VARS()
  11433. ret = wc_falcon_init(&key);
  11434. if (ret != 0) {
  11435. printf("wc_falcon_init failed %d\n", ret);
  11436. return;
  11437. }
  11438. ret = wc_falcon_set_level(&key, level);
  11439. if (ret != 0) {
  11440. printf("wc_falcon_set_level failed %d\n", ret);
  11441. }
  11442. if (ret == 0) {
  11443. if (level == 1) {
  11444. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11445. sizeof_bench_falcon_level1_key,
  11446. NULL, 0, &key);
  11447. }
  11448. else {
  11449. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11450. sizeof_bench_falcon_level5_key,
  11451. NULL, 0, &key);
  11452. }
  11453. if (ret != 0) {
  11454. printf("wc_falcon_import_private_key failed %d\n", ret);
  11455. }
  11456. }
  11457. /* make dummy msg */
  11458. for (i = 0; i < (int)sizeof(msg); i++) {
  11459. msg[i] = (byte)i;
  11460. }
  11461. bench_stats_start(&count, &start);
  11462. do {
  11463. for (i = 0; i < agreeTimes; i++) {
  11464. if (ret == 0) {
  11465. if (level == 1) {
  11466. x = FALCON_LEVEL1_SIG_SIZE;
  11467. }
  11468. else {
  11469. x = FALCON_LEVEL5_SIG_SIZE;
  11470. }
  11471. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11472. if (ret != 0) {
  11473. printf("wc_falcon_sign_msg failed\n");
  11474. }
  11475. }
  11476. RECORD_MULTI_VALUE_STATS();
  11477. }
  11478. count += i;
  11479. } while (bench_stats_check(start)
  11480. #ifdef MULTI_VALUE_STATISTICS
  11481. || runs < minimum_runs
  11482. #endif
  11483. );
  11484. if (ret == 0) {
  11485. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11486. count, start, ret);
  11487. #ifdef MULTI_VALUE_STATISTICS
  11488. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11489. #endif
  11490. }
  11491. RESET_MULTI_VALUE_STATS_VARS();
  11492. bench_stats_start(&count, &start);
  11493. do {
  11494. for (i = 0; i < agreeTimes; i++) {
  11495. if (ret == 0) {
  11496. int verify = 0;
  11497. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11498. &key);
  11499. if (ret != 0 || verify != 1) {
  11500. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11501. ret, verify);
  11502. ret = -1;
  11503. }
  11504. }
  11505. RECORD_MULTI_VALUE_STATS();
  11506. }
  11507. count += i;
  11508. } while (bench_stats_check(start)
  11509. #ifdef MULTI_VALUE_STATISTICS
  11510. || runs < minimum_runs
  11511. #endif
  11512. );
  11513. if (ret == 0) {
  11514. bench_stats_asym_finish("FALCON", level, desc[5],
  11515. 0, count, start, ret);
  11516. #ifdef MULTI_VALUE_STATISTICS
  11517. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11518. #endif
  11519. }
  11520. wc_falcon_free(&key);
  11521. }
  11522. #endif /* HAVE_FALCON */
  11523. #ifdef HAVE_DILITHIUM
  11524. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11525. #ifndef WOLFSSL_NO_ML_DSA_44
  11526. static const unsigned char bench_dilithium_level2_sig[] = {
  11527. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11528. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11529. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11530. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11531. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11532. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11533. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11534. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11535. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11536. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11537. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11538. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11539. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11540. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11541. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11542. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11543. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11544. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11545. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11546. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11547. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11548. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11549. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11550. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11551. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11552. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11553. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11554. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11555. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11556. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11557. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11558. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11559. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11560. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11561. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11562. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11563. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11564. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11565. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11566. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11567. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11568. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11569. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11570. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11571. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11572. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11573. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11574. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11575. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11576. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11577. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11578. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11579. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11580. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11581. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11582. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11583. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11584. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11585. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11586. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11587. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11588. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11589. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11590. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11591. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11592. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11593. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11594. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11595. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11596. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11597. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11598. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11599. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11600. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11601. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11602. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11603. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11604. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11605. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11606. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11607. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11608. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11609. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11610. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11611. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11612. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11613. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11614. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11615. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11616. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11617. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11618. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11619. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11620. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11621. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11622. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11623. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11624. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11625. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11626. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11627. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11628. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11629. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11630. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11631. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11632. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11633. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11634. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11635. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11636. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11637. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11638. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11639. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11640. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11641. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11642. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11643. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11644. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11645. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11646. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11647. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11648. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11649. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11650. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11651. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11652. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11653. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11654. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11655. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11656. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11657. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11658. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11659. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11660. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11661. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11662. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11663. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11664. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11665. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11666. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11667. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11668. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11669. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11670. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11671. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11672. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11673. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11674. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11675. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11676. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11677. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11678. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11679. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11680. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11681. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11682. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11683. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11684. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11685. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11686. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11687. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11688. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11689. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11690. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11691. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11692. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11693. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11694. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11695. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11696. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11697. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11698. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11699. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11700. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11701. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11702. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11703. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11704. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11705. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11706. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11707. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11708. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11709. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11710. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11711. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11712. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11713. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11714. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11715. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11716. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11717. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11718. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11719. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11720. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11721. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11722. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11723. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11724. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11725. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11726. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11727. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11728. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11729. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11730. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11731. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11732. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11733. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11734. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11735. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11736. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11737. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11738. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11739. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11740. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11741. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11742. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11743. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11744. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11745. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11746. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11747. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11748. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11749. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11750. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11751. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11752. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11753. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11754. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11755. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11756. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11757. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11758. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11759. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11760. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11761. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11762. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11763. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11764. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11765. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11766. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11767. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11768. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11769. };
  11770. static const int sizeof_bench_dilithium_level2_sig =
  11771. sizeof(bench_dilithium_level2_sig);
  11772. #endif
  11773. #ifndef WOLFSSL_NO_ML_DSA_65
  11774. static const unsigned char bench_dilithium_level3_sig[] = {
  11775. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11776. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11777. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11778. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11779. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11780. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11781. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11782. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11783. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11784. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11785. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11786. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11787. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11788. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11789. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11790. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11791. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11792. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11793. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11794. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11795. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11796. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11797. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11798. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11799. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11800. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11801. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11802. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11803. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11804. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11805. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11806. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11807. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11808. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11809. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11810. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11811. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11812. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11813. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11814. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11815. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11816. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11817. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11818. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11819. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11820. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11821. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11822. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11823. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11824. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11825. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11826. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11827. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11828. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11829. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11830. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11831. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11832. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11833. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11834. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11835. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11836. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11837. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11838. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11839. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11840. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11841. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11842. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11843. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11844. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11845. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11846. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11847. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11848. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11849. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11850. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11851. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11852. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11853. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11854. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11855. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11856. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11857. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11858. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11859. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11860. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11861. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11862. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11863. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11864. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11865. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11866. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11867. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11868. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11869. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11870. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11871. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11872. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11873. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11874. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11875. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11876. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11877. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11878. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11879. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11880. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11881. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11882. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11883. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11884. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11885. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11886. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11887. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11888. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11889. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11890. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11891. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11892. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11893. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11894. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11895. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11896. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11897. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11898. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11899. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11900. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11901. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11902. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11903. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11904. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11905. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11906. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11907. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11908. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11909. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11910. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11911. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11912. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11913. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11914. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11915. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11916. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11917. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11918. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11919. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11920. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11921. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11922. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11923. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11924. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11925. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11926. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11927. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11928. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11929. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11930. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11931. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11932. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11933. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11934. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11935. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11936. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11937. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11938. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11939. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11940. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11941. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11942. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11943. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11944. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11945. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11946. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11947. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11948. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11949. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11950. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11951. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11952. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11953. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11954. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11955. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11956. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11957. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11958. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11959. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11960. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11961. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11962. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11963. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11964. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11965. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11966. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11967. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11968. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11969. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11970. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11971. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11972. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11973. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11974. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11975. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11976. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11977. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11978. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11979. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11980. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11981. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11982. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11983. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11984. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11985. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11986. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11987. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11988. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11989. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11990. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11991. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11992. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11993. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11994. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11995. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11996. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11997. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11998. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11999. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  12000. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  12001. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  12002. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  12003. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  12004. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  12005. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  12006. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  12007. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  12008. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  12009. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  12010. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  12011. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  12012. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  12013. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  12014. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  12015. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  12016. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  12017. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  12018. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  12019. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  12020. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  12021. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  12022. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  12023. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  12024. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  12025. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  12026. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  12027. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  12028. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  12029. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  12030. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  12031. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  12032. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  12033. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  12034. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  12035. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  12036. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  12037. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  12038. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  12039. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  12040. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  12041. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  12042. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  12043. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  12044. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  12045. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  12046. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  12047. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  12048. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  12049. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  12050. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  12051. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  12052. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  12053. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  12054. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  12055. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  12056. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  12057. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  12058. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12059. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12060. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12061. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12062. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12063. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12064. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12065. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12066. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12067. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12068. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12069. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12070. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12071. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12072. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12073. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12074. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12075. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12076. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12077. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12078. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12079. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12080. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12081. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12082. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12083. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12084. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12085. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12086. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12087. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12088. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12089. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12090. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12091. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12092. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12093. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12094. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12095. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12096. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12097. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12098. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12099. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12100. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12101. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12102. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12103. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12105. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12106. };
  12107. static const int sizeof_bench_dilithium_level3_sig =
  12108. sizeof(bench_dilithium_level3_sig);
  12109. #endif
  12110. #ifndef WOLFSSL_NO_ML_DSA_87
  12111. static const unsigned char bench_dilithium_level5_sig[] = {
  12112. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12113. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12114. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12115. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12116. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12117. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12118. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12119. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12120. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12121. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12122. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12123. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12124. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12125. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12126. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12127. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12128. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12129. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12130. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12131. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12132. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12133. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12134. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12135. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12136. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12137. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12138. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12139. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12140. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12141. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12142. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12143. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12144. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12145. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12146. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12147. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12148. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12149. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12150. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12151. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12152. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12153. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12154. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12155. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12156. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12157. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12158. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12159. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12160. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12161. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12162. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12163. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12164. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12165. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12166. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12167. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12168. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12169. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12170. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12171. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12172. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12173. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12174. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12175. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12176. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12177. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12178. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12179. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12180. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12181. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12182. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12183. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12184. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12185. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12186. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12187. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12188. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12189. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12190. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12191. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12192. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12193. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12194. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12195. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12196. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12197. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12198. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12199. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12200. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12201. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12202. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12203. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12204. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12205. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12206. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12207. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12208. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12209. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12210. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12211. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12212. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12213. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12214. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12215. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12216. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12217. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12218. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12219. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12220. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12221. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12222. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12223. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12224. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12225. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12226. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12227. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12228. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12229. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12230. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12231. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12232. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12233. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12234. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12235. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12236. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12237. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12238. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12239. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12240. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12241. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12242. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12243. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12244. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12245. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12246. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12247. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12248. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12249. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12250. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12251. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12252. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12253. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12254. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12255. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12256. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12257. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12258. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12259. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12260. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12261. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12262. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12263. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12264. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12265. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12266. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12267. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12268. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12269. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12270. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12271. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12272. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12273. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12274. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12275. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12276. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12277. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12278. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12279. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12280. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12281. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12282. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12283. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12284. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12285. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12286. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12287. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12288. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12289. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12290. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12291. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12292. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12293. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12294. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12295. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12296. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12297. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12298. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12299. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12300. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12301. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12302. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12303. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12304. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12305. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12306. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12307. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12308. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12309. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12310. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12311. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12312. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12313. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12314. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12315. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12316. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12317. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12318. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12319. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12320. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12321. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12322. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12323. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12324. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12325. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12326. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12327. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12328. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12329. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12330. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12331. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12332. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12333. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12334. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12335. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12336. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12337. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12338. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12339. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12340. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12341. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12342. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12343. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12344. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12345. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12346. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12347. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12348. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12349. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12350. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12351. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12352. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12353. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12354. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12355. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12356. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12357. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12358. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12359. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12360. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12361. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12362. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12363. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12364. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12365. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12366. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12367. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12368. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12369. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12370. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12371. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12372. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12373. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12374. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12375. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12376. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12377. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12378. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12379. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12380. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12381. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12382. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12383. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12384. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12385. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12386. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12387. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12388. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12389. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12390. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12391. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12392. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12393. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12394. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12395. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12396. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12397. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12398. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12399. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12400. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12401. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12402. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12403. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12404. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12405. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12406. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12407. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12408. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12409. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12410. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12411. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12412. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12413. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12414. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12415. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12416. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12417. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12418. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12419. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12420. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12421. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12422. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12423. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12424. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12425. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12426. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12427. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12428. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12429. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12430. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12431. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12432. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12433. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12434. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12435. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12436. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12437. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12438. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12439. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12440. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12441. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12442. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12443. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12444. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12445. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12446. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12447. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12448. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12449. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12450. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12451. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12452. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12453. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12454. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12455. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12456. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12457. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12458. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12459. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12460. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12461. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12462. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12463. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12464. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12465. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12466. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12467. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12468. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12469. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12470. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12471. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12472. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12473. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12474. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12475. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12476. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12477. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12478. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12479. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12480. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12481. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12482. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12483. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12484. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12485. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12486. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12487. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12488. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12489. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12490. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12491. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12492. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12493. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12494. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12495. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12496. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12497. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12498. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12499. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12500. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12501. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12502. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12503. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12504. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12505. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12506. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12507. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12508. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12509. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12510. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12511. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12512. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12513. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12514. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12515. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12516. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12517. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12518. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12519. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12520. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12521. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12522. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12523. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12524. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12525. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12526. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12527. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12528. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12529. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12530. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12531. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12532. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12533. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12534. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12535. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12536. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12537. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12538. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12539. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12540. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12541. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12542. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12543. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12544. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12545. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12546. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12547. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12548. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12549. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12550. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12551. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12552. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12553. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12554. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12555. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12556. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12557. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12558. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12559. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12560. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12561. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12562. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12563. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12564. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12565. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12566. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12567. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12568. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12569. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12570. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12571. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12572. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12573. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12574. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12575. };
  12576. static const int sizeof_bench_dilithium_level5_sig =
  12577. sizeof(bench_dilithium_level5_sig);
  12578. #endif
  12579. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12580. void bench_dilithiumKeySign(byte level)
  12581. {
  12582. int ret = 0;
  12583. dilithium_key key;
  12584. double start;
  12585. int i, count;
  12586. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12587. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12588. byte msg[512];
  12589. word32 x = 0;
  12590. #endif
  12591. const char**desc = bench_desc_words[lng_index];
  12592. DECLARE_MULTI_VALUE_STATS_VARS()
  12593. byte params = 0;
  12594. if (level == 2) {
  12595. params = 44;
  12596. }
  12597. else if (level == 3) {
  12598. params = 65;
  12599. }
  12600. else if (level == 5) {
  12601. params = 87;
  12602. }
  12603. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12604. /* make dummy msg */
  12605. for (i = 0; i < (int)sizeof(msg); i++) {
  12606. msg[i] = (byte)i;
  12607. }
  12608. #endif
  12609. ret = wc_dilithium_init(&key);
  12610. if (ret != 0) {
  12611. printf("wc_dilithium_init failed %d\n", ret);
  12612. return;
  12613. }
  12614. ret = wc_dilithium_set_level(&key, level);
  12615. if (ret != 0) {
  12616. printf("wc_dilithium_set_level() failed %d\n", ret);
  12617. }
  12618. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12619. bench_stats_start(&count, &start);
  12620. do {
  12621. for (i = 0; i < agreeTimes; i++) {
  12622. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12623. if (ret != 0) {
  12624. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12625. return;
  12626. }
  12627. }
  12628. count += i;
  12629. } while (bench_stats_check(start)
  12630. #ifdef MULTI_VALUE_STATISTICS
  12631. || runs < minimum_runs
  12632. #endif
  12633. );
  12634. if (ret == 0) {
  12635. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12636. start, ret);
  12637. #ifdef MULTI_VALUE_STATISTICS
  12638. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12639. #endif
  12640. }
  12641. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12642. #ifndef WOLFSSL_NO_ML_DSA_44
  12643. if (level == 2) {
  12644. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12645. sizeof_bench_dilithium_level2_key, &key);
  12646. }
  12647. #endif
  12648. #ifndef WOLFSSL_NO_ML_DSA_65
  12649. if (level == 3) {
  12650. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12651. sizeof_bench_dilithium_level3_key, &key);
  12652. }
  12653. #endif
  12654. #ifndef WOLFSSL_NO_ML_DSA_87
  12655. if (level == 5) {
  12656. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12657. sizeof_bench_dilithium_level5_key, &key);
  12658. }
  12659. #endif
  12660. if (ret != 0) {
  12661. printf("Failed to load private key\n");
  12662. return;
  12663. }
  12664. #endif
  12665. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12666. if (level == 2) {
  12667. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12668. }
  12669. else if (level == 3) {
  12670. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12671. }
  12672. else {
  12673. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12674. }
  12675. RESET_MULTI_VALUE_STATS_VARS();
  12676. bench_stats_start(&count, &start);
  12677. do {
  12678. for (i = 0; i < agreeTimes; i++) {
  12679. if (ret == 0) {
  12680. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12681. GLOBAL_RNG);
  12682. if (ret != 0) {
  12683. printf("wc_dilithium_sign_msg failed\n");
  12684. }
  12685. }
  12686. RECORD_MULTI_VALUE_STATS();
  12687. }
  12688. count += i;
  12689. } while (bench_stats_check(start)
  12690. #ifdef MULTI_VALUE_STATISTICS
  12691. || runs < minimum_runs
  12692. #endif
  12693. );
  12694. if (ret == 0) {
  12695. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12696. ret);
  12697. #ifdef MULTI_VALUE_STATISTICS
  12698. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12699. #endif
  12700. }
  12701. #endif
  12702. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12703. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12704. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12705. #ifndef WOLFSSL_NO_ML_DSA_44
  12706. if (level == 2) {
  12707. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12708. x = sizeof_bench_dilithium_level2_sig;
  12709. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12710. #endif
  12711. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12712. sizeof_bench_dilithium_level2_pubkey, &key);
  12713. }
  12714. #endif
  12715. #ifndef WOLFSSL_NO_ML_DSA_65
  12716. if (level == 3) {
  12717. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12718. x = sizeof_bench_dilithium_level3_sig;
  12719. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12720. #endif
  12721. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12722. sizeof_bench_dilithium_level3_pubkey, &key);
  12723. }
  12724. #endif
  12725. #ifndef WOLFSSL_NO_ML_DSA_87
  12726. if (level == 5) {
  12727. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12728. x = sizeof_bench_dilithium_level5_sig;
  12729. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12730. #endif
  12731. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12732. sizeof_bench_dilithium_level5_pubkey, &key);
  12733. }
  12734. #endif
  12735. if (ret != 0) {
  12736. printf("Failed to load public key\n");
  12737. return;
  12738. }
  12739. #endif
  12740. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12741. RESET_MULTI_VALUE_STATS_VARS();
  12742. bench_stats_start(&count, &start);
  12743. do {
  12744. for (i = 0; i < agreeTimes; i++) {
  12745. if (ret == 0) {
  12746. int verify = 0;
  12747. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12748. &verify, &key);
  12749. if (ret != 0 || verify != 1) {
  12750. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12751. ret, verify);
  12752. ret = -1;
  12753. }
  12754. }
  12755. RECORD_MULTI_VALUE_STATS();
  12756. }
  12757. count += i;
  12758. } while (bench_stats_check(start)
  12759. #ifdef MULTI_VALUE_STATISTICS
  12760. || runs < minimum_runs
  12761. #endif
  12762. );
  12763. if (ret == 0) {
  12764. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12765. ret);
  12766. #ifdef MULTI_VALUE_STATISTICS
  12767. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12768. #endif
  12769. }
  12770. #endif
  12771. wc_dilithium_free(&key);
  12772. }
  12773. #endif /* HAVE_DILITHIUM */
  12774. #ifdef HAVE_SPHINCS
  12775. void bench_sphincsKeySign(byte level, byte optim)
  12776. {
  12777. int ret = 0;
  12778. sphincs_key key;
  12779. double start;
  12780. int i, count;
  12781. byte sig[SPHINCS_MAX_SIG_SIZE];
  12782. byte msg[512];
  12783. word32 x = 0;
  12784. const char**desc = bench_desc_words[lng_index];
  12785. DECLARE_MULTI_VALUE_STATS_VARS()
  12786. ret = wc_sphincs_init(&key);
  12787. if (ret != 0) {
  12788. printf("wc_sphincs_init failed %d\n", ret);
  12789. return;
  12790. }
  12791. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12792. if (ret != 0) {
  12793. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12794. }
  12795. if (ret == 0) {
  12796. ret = -1;
  12797. if ((level == 1) && (optim == FAST_VARIANT)) {
  12798. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12799. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12800. }
  12801. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12802. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12803. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12804. }
  12805. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12806. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12807. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12808. }
  12809. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12810. ret = wc_sphincs_import_private_key(
  12811. bench_sphincs_small_level1_key,
  12812. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12813. }
  12814. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12815. ret = wc_sphincs_import_private_key(
  12816. bench_sphincs_small_level3_key,
  12817. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12818. }
  12819. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12820. ret = wc_sphincs_import_private_key(
  12821. bench_sphincs_small_level5_key,
  12822. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12823. }
  12824. if (ret != 0) {
  12825. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12826. }
  12827. }
  12828. /* make dummy msg */
  12829. for (i = 0; i < (int)sizeof(msg); i++) {
  12830. msg[i] = (byte)i;
  12831. }
  12832. bench_stats_start(&count, &start);
  12833. do {
  12834. for (i = 0; i < agreeTimes; i++) {
  12835. if (ret == 0) {
  12836. if ((level == 1) && (optim == FAST_VARIANT)) {
  12837. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12838. }
  12839. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12840. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12841. }
  12842. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12843. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12844. }
  12845. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12846. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12847. }
  12848. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12849. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12850. }
  12851. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12852. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12853. }
  12854. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12855. if (ret != 0) {
  12856. printf("wc_sphincs_sign_msg failed\n");
  12857. }
  12858. }
  12859. RECORD_MULTI_VALUE_STATS();
  12860. }
  12861. count += i;
  12862. } while (bench_stats_check(start)
  12863. #ifdef MULTI_VALUE_STATISTICS
  12864. || runs < minimum_runs
  12865. #endif
  12866. );
  12867. if (ret == 0) {
  12868. if (optim == FAST_VARIANT) {
  12869. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12870. start, ret);
  12871. }
  12872. else {
  12873. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12874. start, ret);
  12875. }
  12876. #ifdef MULTI_VALUE_STATISTICS
  12877. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12878. #endif
  12879. }
  12880. RESET_MULTI_VALUE_STATS_VARS();
  12881. bench_stats_start(&count, &start);
  12882. do {
  12883. for (i = 0; i < agreeTimes; i++) {
  12884. if (ret == 0) {
  12885. int verify = 0;
  12886. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12887. &key);
  12888. if (ret != 0 || verify != 1) {
  12889. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12890. ret, verify);
  12891. ret = -1;
  12892. }
  12893. }
  12894. RECORD_MULTI_VALUE_STATS();
  12895. }
  12896. count += i;
  12897. } while (bench_stats_check(start)
  12898. #ifdef MULTI_VALUE_STATISTICS
  12899. || runs < minimum_runs
  12900. #endif
  12901. );
  12902. if (ret == 0) {
  12903. if (optim == FAST_VARIANT) {
  12904. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12905. start, ret);
  12906. }
  12907. else {
  12908. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12909. start, ret);
  12910. }
  12911. #ifdef MULTI_VALUE_STATISTICS
  12912. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12913. #endif
  12914. }
  12915. wc_sphincs_free(&key);
  12916. }
  12917. #endif /* HAVE_SPHINCS */
  12918. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12919. #define WIN32_LEAN_AND_MEAN
  12920. #include <windows.h>
  12921. double current_time(int reset)
  12922. {
  12923. static int init = 0;
  12924. static LARGE_INTEGER freq;
  12925. LARGE_INTEGER count;
  12926. (void)reset;
  12927. if (!init) {
  12928. QueryPerformanceFrequency(&freq);
  12929. init = 1;
  12930. }
  12931. QueryPerformanceCounter(&count);
  12932. #ifdef BENCH_MICROSECOND
  12933. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12934. #else
  12935. return (double)count.QuadPart / freq.QuadPart;
  12936. #endif
  12937. }
  12938. #elif defined MICROCHIP_PIC32
  12939. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12940. #define CLOCK 80000000.0
  12941. #else
  12942. #define CLOCK 40000000.0
  12943. #endif
  12944. extern void WriteCoreTimer(word32 t);
  12945. extern word32 ReadCoreTimer(void);
  12946. double current_time(int reset)
  12947. {
  12948. unsigned int ns;
  12949. if (reset) {
  12950. WriteCoreTimer(0);
  12951. }
  12952. /* get timer in ns */
  12953. ns = ReadCoreTimer();
  12954. /* return seconds as a double */
  12955. return ( ns / CLOCK * 2.0);
  12956. }
  12957. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12958. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12959. /* declared above at line 239 */
  12960. /* extern double current_time(int reset); */
  12961. #elif defined(FREERTOS)
  12962. #ifdef PLATFORMIO
  12963. #include <freertos/FreeRTOS.h>
  12964. #include <freertos/task.h>
  12965. #else
  12966. #include "task.h"
  12967. #endif
  12968. #if defined(WOLFSSL_ESPIDF)
  12969. /* prototype definition */
  12970. int construct_argv();
  12971. extern char* __argv[22];
  12972. /* current_time(reset)
  12973. *
  12974. * Benchmark passage of time, in fractional seconds.
  12975. * [reset] is non zero to adjust timer or counter to zero
  12976. *
  12977. * Use care when repeatedly calling calling. See implementation. */
  12978. double current_time(int reset)
  12979. {
  12980. double ret;
  12981. #if ESP_IDF_VERSION_MAJOR >= 4
  12982. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12983. #else
  12984. portTickType tickCount;
  12985. #endif
  12986. #if defined(__XTENSA__)
  12987. (void)reset;
  12988. if (reset) {
  12989. /* TODO: Determine a mechanism for reset that does not interfere
  12990. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12991. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12992. ESP_LOGW(TAG, "Current_time() reset!");
  12993. portTICK_TYPE_ENTER_CRITICAL();
  12994. {
  12995. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12996. _esp_cpu_count_last = xthal_get_ccount();
  12997. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12998. }
  12999. portTICK_TYPE_EXIT_CRITICAL();
  13000. */
  13001. }
  13002. #else
  13003. /* Only reset the CPU counter for RISC-V */
  13004. if (reset) {
  13005. ESP_LOGV(TAG, "current_time() reset!");
  13006. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  13007. * unexpected rollovers in return values for Xtensa but not RISC-V?
  13008. * See also esp_get_cycle_count_ex() */
  13009. #ifdef __XTENSA__
  13010. _esp_cpu_count_last = xthal_get_ccount();
  13011. #else
  13012. #if ESP_IDF_VERSION_MAJOR >= 5
  13013. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  13014. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  13015. #else
  13016. cpu_hal_set_cycle_count((uint32_t)0);
  13017. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  13018. #endif
  13019. #endif
  13020. }
  13021. #endif
  13022. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  13023. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  13024. The count of ticks since vTaskStartScheduler was called,
  13025. typiclly in app_startup.c */
  13026. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13027. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  13028. if (tickCount == last_tickCount) {
  13029. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  13030. }
  13031. if (tickCount < last_tickCount) {
  13032. ESP_LOGW(TAG, "last_tickCount overflow?");
  13033. }
  13034. #endif
  13035. if (reset) {
  13036. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13037. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  13038. #endif
  13039. last_tickCount = tickCount;
  13040. }
  13041. else {
  13042. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13043. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  13044. #endif
  13045. }
  13046. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  13047. ret = (double)tickCount / configTICK_RATE_HZ;
  13048. #else
  13049. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  13050. "assuming 1000 Hz.");
  13051. ret = (double)(tickCount / 1000.0);
  13052. #endif /* configTICK_RATE_HZ */
  13053. return ret;
  13054. } /* current_time */
  13055. #else
  13056. /* current_time(reset)
  13057. *
  13058. * Benchmark passage of time, in fractional seconds.
  13059. * [reset] is non zero to adjust timer or counter to zero
  13060. *
  13061. * Use care when repeatedly calling calling. See implementation. */
  13062. double current_time(int reset)
  13063. {
  13064. portTickType tickCount = xTaskGetTickCount();
  13065. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13066. #ifdef configTICK_RATE_HZ
  13067. return (double)tickCount / configTICK_RATE_HZ;
  13068. #else
  13069. return (double)tickCount / 1000;
  13070. #endif
  13071. }
  13072. #endif
  13073. #elif defined (WOLFSSL_TIRTOS)
  13074. extern double current_time(int reset);
  13075. #elif defined(FREESCALE_MQX)
  13076. double current_time(int reset)
  13077. {
  13078. TIME_STRUCT tv;
  13079. _time_get(&tv);
  13080. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13081. }
  13082. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13083. && defined(MAX3266X_RTC)
  13084. double current_time(int reset)
  13085. {
  13086. (void)reset;
  13087. return wc_MXC_RTC_Time();
  13088. }
  13089. #elif defined(FREESCALE_KSDK_BM)
  13090. double current_time(int reset)
  13091. {
  13092. return (double)OSA_TimeGetMsec() / 1000;
  13093. }
  13094. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13095. double current_time(int reset)
  13096. {
  13097. (void)reset;
  13098. return (double)osKernelGetTickCount() / 1000.0;
  13099. }
  13100. #elif defined(WOLFSSL_EMBOS)
  13101. #include "RTOS.h"
  13102. double current_time(int reset)
  13103. {
  13104. double time_now;
  13105. double current_s = OS_GetTime() / 1000.0;
  13106. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13107. time_now = (double)( current_s + current_us);
  13108. (void) reset;
  13109. return time_now;
  13110. }
  13111. #elif defined(WOLFSSL_SGX)
  13112. double current_time(int reset);
  13113. #elif defined(WOLFSSL_DEOS)
  13114. double current_time(int reset)
  13115. {
  13116. const uint32_t systemTickTimeInHz
  13117. = 1000000 / systemTickInMicroseconds();
  13118. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13119. (void)reset;
  13120. return (double) *systemTickPtr/systemTickTimeInHz;
  13121. }
  13122. #elif defined(MICRIUM)
  13123. double current_time(int reset)
  13124. {
  13125. #if (OS_VERSION < 50000)
  13126. CPU_ERR err;
  13127. (void)reset;
  13128. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13129. #else
  13130. RTOS_ERR err;
  13131. double ret = 0;
  13132. OS_TICK tick = OSTimeGet(&err);
  13133. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13134. (void)reset;
  13135. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13136. ret = ((double)tick)/rate;
  13137. }
  13138. return ret;
  13139. #endif
  13140. }
  13141. #elif defined(WOLFSSL_ZEPHYR)
  13142. #include <time.h>
  13143. double current_time(int reset)
  13144. {
  13145. int64_t t;
  13146. (void)reset;
  13147. #if defined(CONFIG_ARCH_POSIX)
  13148. k_cpu_idle();
  13149. #endif
  13150. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13151. return (double)(t / 1000);
  13152. }
  13153. #elif defined(WOLFSSL_NETBURNER)
  13154. #include <predef.h>
  13155. #include <utils.h>
  13156. #include <constants.h>
  13157. double current_time(int reset)
  13158. {
  13159. DWORD ticks = TimeTick; /* ticks since system start */
  13160. (void)reset;
  13161. return (double) ticks/TICKS_PER_SECOND;
  13162. }
  13163. #elif defined(WOLFSSL_RPIPICO)
  13164. #include "pico/stdlib.h"
  13165. double current_time(int reset)
  13166. {
  13167. (void)reset;
  13168. return (double) time_us_64() / 1000000;
  13169. }
  13170. #elif defined(THREADX)
  13171. #include "tx_api.h"
  13172. double current_time(int reset)
  13173. {
  13174. (void)reset;
  13175. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13176. }
  13177. #elif defined(WOLFSSL_XILINX)
  13178. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13179. #define COUNTS_PER_SECOND \
  13180. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13181. #else
  13182. #define COUNTS_PER_SECOND \
  13183. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13184. #endif
  13185. double current_time(int reset)
  13186. {
  13187. double timer;
  13188. uint64_t cntPct = 0;
  13189. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13190. /* Convert to milliseconds */
  13191. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13192. /* Convert to seconds.millisecond */
  13193. timer /= 1000;
  13194. return timer;
  13195. }
  13196. #elif defined(LINUX_RUSAGE_UTIME)
  13197. #include <sys/time.h>
  13198. #include <sys/resource.h>
  13199. static struct rusage base_rusage;
  13200. static struct rusage cur_rusage;
  13201. double current_time(int reset)
  13202. {
  13203. struct rusage rusage;
  13204. (void)reset;
  13205. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13206. if (reset)
  13207. base_rusage = rusage;
  13208. else
  13209. cur_rusage = rusage;
  13210. /* only consider user time, as system time is host-related overhead
  13211. * outside wolfcrypt.
  13212. */
  13213. return (double)rusage.ru_utime.tv_sec +
  13214. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13215. }
  13216. static void check_for_excessive_stime(const char *desc,
  13217. const char *desc_extra)
  13218. {
  13219. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13220. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13221. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13222. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13223. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13224. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13225. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13226. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13227. double stime_utime_ratio =
  13228. (cur_stime - start_stime) / (cur_utime - start_utime);
  13229. if (stime_utime_ratio > .1)
  13230. printf("%swarning, "
  13231. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13232. err_prefix, desc, desc_extra,
  13233. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13234. }
  13235. #elif defined(WOLFSSL_LINUXKM)
  13236. double current_time(int reset)
  13237. {
  13238. (void)reset;
  13239. u64 ns = ktime_get_ns();
  13240. return (double)ns / 1000000000.0;
  13241. }
  13242. #else
  13243. #include <time.h>
  13244. #include <sys/time.h>
  13245. double current_time(int reset)
  13246. {
  13247. struct timespec tv;
  13248. (void)reset;
  13249. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13250. #ifdef BENCH_MICROSECOND
  13251. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13252. #else
  13253. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13254. #endif
  13255. }
  13256. #endif /* _WIN32 */
  13257. #if defined(HAVE_GET_CYCLES)
  13258. #if defined(WOLFSSL_ESPIDF)
  13259. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13260. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13261. {
  13262. /* Reminder for long duration between calls with
  13263. * multiple overflows will not be detected. */
  13264. return esp_get_cycle_count_ex();
  13265. }
  13266. /* implement other architectures here */
  13267. #else
  13268. static WC_INLINE word64 get_intel_cycles(void)
  13269. {
  13270. unsigned int lo_c, hi_c;
  13271. __asm__ __volatile__ (
  13272. "cpuid\n\t"
  13273. "rdtsc"
  13274. : "=a"(lo_c), "=d"(hi_c) /* out */
  13275. : "a"(0) /* in */
  13276. : "%ebx", "%ecx"); /* clobber */
  13277. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13278. }
  13279. #endif
  13280. #endif /* HAVE_GET_CYCLES */
  13281. void benchmark_configure(word32 block_size)
  13282. {
  13283. /* must be greater than 0 */
  13284. if (block_size > 0) {
  13285. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13286. bench_size = block_size;
  13287. }
  13288. }
  13289. #ifndef NO_MAIN_DRIVER
  13290. #ifndef MAIN_NO_ARGS
  13291. #ifndef WOLFSSL_BENCHMARK_ALL
  13292. /* Display the algorithm string and keep to 80 characters per line.
  13293. *
  13294. * str Algorithm string to print.
  13295. * line Length of line used so far.
  13296. */
  13297. #ifndef BENCH_MAX_LINE
  13298. #define BENCH_MAX_LINE 80
  13299. #endif
  13300. static void print_alg(const char* str, int* line)
  13301. {
  13302. const char* const ident = " ";
  13303. if (*line == 0) {
  13304. printf("%s", ident);
  13305. *line = (int)XSTRLEN(ident);
  13306. }
  13307. printf(" %s", str);
  13308. *line += (int)XSTRLEN(str) + 1;
  13309. if (*line > BENCH_MAX_LINE) {
  13310. printf("\n");
  13311. *line = 0;
  13312. }
  13313. }
  13314. #endif /* WOLFSSL_BENCHMARK_ALL */
  13315. /* Display the usage options of the benchmark program. */
  13316. static void Usage(void)
  13317. {
  13318. int e = 0;
  13319. #ifndef WOLFSSL_BENCHMARK_ALL
  13320. int i;
  13321. int line;
  13322. #endif
  13323. printf("benchmark\n");
  13324. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13325. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13326. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13327. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13328. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13329. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13330. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13331. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13332. #else
  13333. e += 3;
  13334. #endif
  13335. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13336. #ifndef NO_RSA
  13337. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13338. #ifdef WOLFSSL_KEY_GEN
  13339. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13340. #endif
  13341. e++;
  13342. #else
  13343. e += 2;
  13344. #endif
  13345. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13346. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13347. #endif
  13348. e++;
  13349. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13350. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13351. #endif
  13352. e++;
  13353. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13354. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13355. #endif
  13356. e++;
  13357. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13358. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13359. #endif
  13360. e++;
  13361. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13362. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13363. #endif
  13364. e++;
  13365. #if defined(HAVE_ECC)
  13366. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13367. #endif
  13368. e++;
  13369. #ifndef WOLFSSL_BENCHMARK_ALL
  13370. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13371. line = 0;
  13372. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13373. print_alg(bench_cipher_opt[i].str, &line);
  13374. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13375. print_alg(bench_digest_opt[i].str, &line);
  13376. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13377. print_alg(bench_mac_opt[i].str, &line);
  13378. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13379. print_alg(bench_kdf_opt[i].str, &line);
  13380. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13381. print_alg(bench_asym_opt[i].str, &line);
  13382. for (i=0; bench_other_opt[i].str != NULL; i++)
  13383. print_alg(bench_other_opt[i].str, &line);
  13384. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13385. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13386. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13387. print_alg(bench_pq_asym_opt[i].str, &line);
  13388. #if defined(HAVE_SPHINCS)
  13389. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13390. print_alg(bench_pq_asym_opt2[i].str, &line);
  13391. #endif /* HAVE_SPHINCS */
  13392. #endif
  13393. #if defined(BENCH_PQ_STATEFUL_HBS)
  13394. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13395. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13396. #endif /* BENCH_PQ_STATEFUL_HBS */
  13397. printf("\n");
  13398. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13399. e++;
  13400. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13401. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13402. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13403. #ifdef WC_ENABLE_BENCH_THREADING
  13404. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13405. #endif
  13406. e++;
  13407. #ifdef WC_BENCH_TRACK_STATS
  13408. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13409. #endif
  13410. e++;
  13411. #ifndef NO_FILESYSTEM
  13412. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13413. #endif
  13414. e++;
  13415. #ifndef NO_FILESYSTEM
  13416. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13417. #endif
  13418. #ifdef MULTI_VALUE_STATISTICS
  13419. e++;
  13420. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13421. #endif
  13422. }
  13423. /* Match the command line argument with the string.
  13424. *
  13425. * arg Command line argument.
  13426. * str String to check for.
  13427. * return 1 if the command line argument matches the string, 0 otherwise.
  13428. */
  13429. static int string_matches(const char* arg, const char* str)
  13430. {
  13431. return XSTRCMP(arg, str) == 0;
  13432. }
  13433. #endif /* MAIN_NO_ARGS */
  13434. /*
  13435. ** ----------------------------------------------------------------------------
  13436. ** determine how the benchmarks are called, the function name varies:
  13437. ** ----------------------------------------------------------------------------
  13438. */
  13439. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13440. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13441. /* for some environments, we'll call a function wolf_benchmark_task: */
  13442. int wolf_benchmark_task(void)
  13443. #elif defined(MAIN_NO_ARGS)
  13444. /* otherwise we'll use main() with no arguments as desired: */
  13445. int main()
  13446. #else
  13447. /* else we'll be calling main with default arg parameters */
  13448. int main(int argc, char** argv)
  13449. #endif
  13450. {
  13451. /* Code for main() or wolf_benchmark_task() */
  13452. #ifdef WOLFSSL_ESPIDF
  13453. int argc = construct_argv();
  13454. char** argv = (char**)__argv;
  13455. #elif defined(MAIN_NO_ARGS)
  13456. int argc = 0;
  13457. char** argv = NULL;
  13458. #endif
  13459. return wolfcrypt_benchmark_main(argc, argv);
  13460. }
  13461. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13462. int wolfcrypt_benchmark_main(int argc, char** argv)
  13463. {
  13464. int ret = 0;
  13465. #ifndef MAIN_NO_ARGS
  13466. int optMatched;
  13467. #ifndef WOLFSSL_BENCHMARK_ALL
  13468. int i;
  13469. #endif
  13470. #endif
  13471. benchmark_static_init(1);
  13472. printf("%s------------------------------------------------------------------------------\n",
  13473. info_prefix);
  13474. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13475. printf("%s------------------------------------------------------------------------------\n",
  13476. info_prefix);
  13477. #ifndef MAIN_NO_ARGS
  13478. while (argc > 1) {
  13479. if (string_matches(argv[1], "-?")) {
  13480. if (--argc > 1) {
  13481. lng_index = XATOI((++argv)[1]);
  13482. if (lng_index<0 || lng_index>1) {
  13483. lng_index = 0;
  13484. }
  13485. }
  13486. Usage();
  13487. return 0;
  13488. }
  13489. else if (string_matches(argv[1], "-lng")) {
  13490. argc--;
  13491. argv++;
  13492. if (argc > 1) {
  13493. lng_index = XATOI(argv[1]);
  13494. if (lng_index<0 || lng_index>1) {
  13495. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13496. lng_index);
  13497. lng_index = 0;
  13498. }
  13499. }
  13500. }
  13501. else if (string_matches(argv[1], "-base10"))
  13502. base2 = 0;
  13503. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13504. else if (string_matches(argv[1], "-no_aad"))
  13505. aes_aad_options = AAD_SIZE_ZERO;
  13506. else if (string_matches(argv[1], "-all_aad"))
  13507. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13508. else if (string_matches(argv[1], "-aad_size")) {
  13509. argc--;
  13510. argv++;
  13511. if (argc > 1) {
  13512. aes_aad_size = (word32)XATOI(argv[1]);
  13513. aes_aad_options |= AAD_SIZE_CUSTOM;
  13514. }
  13515. }
  13516. #endif
  13517. else if (string_matches(argv[1], "-dgst_full"))
  13518. digest_stream = 0;
  13519. #ifdef HAVE_CHACHA
  13520. else if (string_matches(argv[1], "-enc_only"))
  13521. encrypt_only = 1;
  13522. #endif
  13523. #ifndef NO_RSA
  13524. else if (string_matches(argv[1], "-rsa_sign"))
  13525. rsa_sign_verify = 1;
  13526. #endif
  13527. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13528. else if (string_matches(argv[1], "-ffdhe2048"))
  13529. use_ffdhe = 2048;
  13530. #endif
  13531. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13532. else if (string_matches(argv[1], "-ffdhe3072"))
  13533. use_ffdhe = 3072;
  13534. #endif
  13535. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13536. else if (string_matches(argv[1], "-ffdhe4096"))
  13537. use_ffdhe = 4096;
  13538. #endif
  13539. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13540. else if (string_matches(argv[1], "-p256"))
  13541. bench_asym_algs |= BENCH_ECC_P256;
  13542. #endif
  13543. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13544. else if (string_matches(argv[1], "-p384"))
  13545. bench_asym_algs |= BENCH_ECC_P384;
  13546. #endif
  13547. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13548. else if (string_matches(argv[1], "-p521"))
  13549. bench_asym_algs |= BENCH_ECC_P521;
  13550. #endif
  13551. #ifdef BENCH_ASYM
  13552. else if (string_matches(argv[1], "-csv")) {
  13553. csv_format = 1;
  13554. }
  13555. #endif
  13556. #ifdef WC_ENABLE_BENCH_THREADING
  13557. else if (string_matches(argv[1], "-threads")) {
  13558. argc--;
  13559. argv++;
  13560. if (argc > 1) {
  13561. g_threadCount = XATOI(argv[1]);
  13562. if (g_threadCount < 1 || lng_index > 128){
  13563. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13564. g_threadCount);
  13565. g_threadCount = 0;
  13566. }
  13567. }
  13568. }
  13569. #endif
  13570. #ifdef WC_BENCH_TRACK_STATS
  13571. else if (string_matches(argv[1], "-print")) {
  13572. gPrintStats = 1;
  13573. }
  13574. #endif
  13575. else if (string_matches(argv[1], "-blocks")) {
  13576. argc--;
  13577. argv++;
  13578. if (argc > 1)
  13579. numBlocks = XATOI(argv[1]);
  13580. }
  13581. #ifndef NO_FILESYSTEM
  13582. else if (string_matches(argv[1], "-hash_input")) {
  13583. argc--;
  13584. argv++;
  13585. if (argc > 1)
  13586. hash_input = argv[1];
  13587. }
  13588. else if (string_matches(argv[1], "-cipher_input")) {
  13589. argc--;
  13590. argv++;
  13591. if (argc > 1)
  13592. cipher_input = argv[1];
  13593. }
  13594. #endif
  13595. #ifdef MULTI_VALUE_STATISTICS
  13596. else if (string_matches(argv[1], "-min_runs")) {
  13597. argc--;
  13598. argv++;
  13599. if (argc > 1) {
  13600. minimum_runs = XATOI(argv[1]);
  13601. }
  13602. }
  13603. #endif
  13604. else if (argv[1][0] == '-') {
  13605. optMatched = 0;
  13606. #ifndef WOLFSSL_BENCHMARK_ALL
  13607. /* Check known algorithm choosing command line options. */
  13608. /* Known cipher algorithms */
  13609. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13610. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13611. bench_cipher_algs |= bench_cipher_opt[i].val;
  13612. bench_all = 0;
  13613. optMatched = 1;
  13614. }
  13615. }
  13616. /* Known digest algorithms */
  13617. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13618. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13619. bench_digest_algs |= bench_digest_opt[i].val;
  13620. bench_all = 0;
  13621. optMatched = 1;
  13622. }
  13623. }
  13624. /* Known MAC algorithms */
  13625. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13626. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13627. bench_mac_algs |= bench_mac_opt[i].val;
  13628. bench_all = 0;
  13629. optMatched = 1;
  13630. }
  13631. }
  13632. /* Known KDF algorithms */
  13633. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13634. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13635. bench_kdf_algs |= bench_kdf_opt[i].val;
  13636. bench_all = 0;
  13637. optMatched = 1;
  13638. }
  13639. }
  13640. /* Known asymmetric algorithms */
  13641. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13642. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13643. bench_asym_algs |= bench_asym_opt[i].val;
  13644. bench_all = 0;
  13645. optMatched = 1;
  13646. }
  13647. }
  13648. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13649. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13650. /* Known asymmetric post-quantum algorithms */
  13651. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13652. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13653. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13654. bench_all = 0;
  13655. optMatched = 1;
  13656. }
  13657. }
  13658. #ifdef HAVE_SPHINCS
  13659. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13660. * -pq, so we need to do a special case for -pq since optMatched
  13661. * was set to 1 just above. */
  13662. if ((bench_pq_asym_opt[0].str != NULL) &&
  13663. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13664. {
  13665. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13666. bench_all = 0;
  13667. optMatched = 1;
  13668. }
  13669. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13670. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13671. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13672. bench_all = 0;
  13673. optMatched = 1;
  13674. }
  13675. }
  13676. #endif
  13677. #endif
  13678. /* Other known cryptographic algorithms */
  13679. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13680. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13681. bench_other_algs |= bench_other_opt[i].val;
  13682. bench_all = 0;
  13683. optMatched = 1;
  13684. }
  13685. }
  13686. #if defined(BENCH_PQ_STATEFUL_HBS)
  13687. /* post-quantum stateful hash-based signatures */
  13688. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13689. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13690. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13691. bench_all = 0;
  13692. optMatched = 1;
  13693. }
  13694. }
  13695. #endif /* BENCH_PQ_STATEFUL_HBS */
  13696. #endif
  13697. if (!optMatched) {
  13698. printf("Option not recognized: %s\n", argv[1]);
  13699. Usage();
  13700. return 1;
  13701. }
  13702. }
  13703. else {
  13704. /* parse for block size */
  13705. benchmark_configure((word32)XATOI(argv[1]));
  13706. }
  13707. argc--;
  13708. argv++;
  13709. }
  13710. #endif /* MAIN_NO_ARGS */
  13711. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13712. /* when defined, we'll always output CSV regardless of params.
  13713. ** this is typically convenient in embedded environments.
  13714. */
  13715. csv_format = 1;
  13716. #endif
  13717. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13718. if (g_threadCount > 1) {
  13719. ret = benchmark_test_threaded(NULL);
  13720. }
  13721. else
  13722. #endif
  13723. {
  13724. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13725. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13726. defined(CONFIG_IDF_TARGET_ESP32C6)
  13727. {
  13728. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13729. if (esp_gptimer == NULL) {
  13730. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13731. &esp_gptimer) );
  13732. }
  13733. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13734. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13735. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13736. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13737. }
  13738. #endif
  13739. #ifdef HAVE_STACK_SIZE
  13740. ret = StackSizeCheck(NULL, benchmark_test);
  13741. #else
  13742. ret = benchmark_test(NULL);
  13743. #endif
  13744. }
  13745. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13746. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13747. defined(CONFIG_IDF_TARGET_ESP32C6)
  13748. {
  13749. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13750. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13751. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13752. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13753. }
  13754. #endif
  13755. return ret;
  13756. }
  13757. #endif /* !NO_MAIN_DRIVER */
  13758. #else
  13759. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13760. int main(void) { return 0; }
  13761. #endif
  13762. #endif /* !NO_CRYPT_BENCHMARK */