benchmark.c 506 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945
  1. /* benchmark.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #ifndef WOLFSSL_USER_SETTINGS
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS) || defined(HAVE_PQM4)
  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. #endif
  212. #ifdef WOLFSSL_ASYNC_CRYPT
  213. #include <wolfssl/wolfcrypt/async.h>
  214. #endif
  215. #ifdef USE_FLAT_BENCHMARK_H
  216. #include "benchmark.h"
  217. #else
  218. #include "wolfcrypt/benchmark/benchmark.h"
  219. #endif
  220. /* define the max length for each string of metric reported */
  221. #ifndef WC_BENCH_MAX_LINE_LEN
  222. #define WC_BENCH_MAX_LINE_LEN 150
  223. #endif
  224. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  225. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  226. #define MILLION_VALUE 1000000.0
  227. #ifdef BENCH_MICROSECOND
  228. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  229. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  230. #else
  231. #define WOLFSSL_FIXED_TIME_UNIT "s"
  232. #endif
  233. #ifdef MULTI_VALUE_STATISTICS
  234. #define STATS_CLAUSE_SEPARATOR ""
  235. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  236. squareSum = 0, prev = 0, delta;\
  237. int runs = 0;
  238. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  239. delta = current_time(0) - start;\
  240. min = delta;\
  241. max = delta;\
  242. }\
  243. else {\
  244. delta = current_time(0) - prev;\
  245. }\
  246. if (max < delta)\
  247. max = delta;\
  248. else if (min > delta)\
  249. min = delta;\
  250. sum += delta;\
  251. squareSum += delta * delta;\
  252. runs++;\
  253. prev = current_time(0)
  254. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  255. runs = 0;\
  256. sum = 0;\
  257. squareSum = 0
  258. #else
  259. #define STATS_CLAUSE_SEPARATOR "\n"
  260. #define DECLARE_MULTI_VALUE_STATS_VARS()
  261. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  262. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  263. #endif
  264. #ifdef WOLFSSL_NO_FLOAT_FMT
  265. #define FLT_FMT "%0ld,%09lu"
  266. #define FLT_FMT_PREC "%0ld.%0*lu"
  267. #define FLT_FMT_PREC2 FLT_FMT_PREC
  268. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  269. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  270. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  271. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  272. 10000.0, 100000.0, 1000000.0, \
  273. 10000000.0, 100000000.0, \
  274. 1000000000.0 };
  275. #define FLT_FMT_PREC_ARGS(p, x) \
  276. (long)(x), \
  277. p, \
  278. (x) >= 0.0 ? \
  279. (unsigned long int)((((x) - (double)(long)(x)) * \
  280. pow_10_array[(p)+1]) + 0.5) : \
  281. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  282. pow_10_array[(p)+1]) + 0.5)
  283. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  284. #else
  285. #define FLT_FMT "%f"
  286. #define FLT_FMT_PREC "%.*f"
  287. #define FLT_FMT_PREC2 "%*.*f"
  288. #define FLT_FMT_ARGS(x) x
  289. #define FLT_FMT_PREC_ARGS(p, x) p, x
  290. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  291. #endif /* WOLFSSL_NO_FLOAT_FMT */
  292. #ifdef WOLFSSL_ESPIDF
  293. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  294. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  295. * enabled, all if the values in report are blank. */
  296. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  297. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  298. #error "Nano newlib formatting must not be enabled for benchmark"
  299. #endif
  300. #endif
  301. #ifdef configTICK_RATE_HZ
  302. /* Define CPU clock cycles per tick of FreeRTOS clock
  303. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  304. * configTICK_RATE_HZ is typically 100 or 1000.
  305. **/
  306. #if defined(CONFIG_IDF_TARGET_ESP8266)
  307. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  308. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  309. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  310. #endif
  311. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  312. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  313. #endif
  314. #endif
  315. #define CPU_TICK_CYCLES ( \
  316. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  317. / configTICK_RATE_HZ \
  318. )
  319. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  320. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  321. #include "driver/gptimer.h"
  322. static gptimer_handle_t esp_gptimer = NULL;
  323. static gptimer_config_t esp_timer_config = {
  324. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  325. .direction = GPTIMER_COUNT_UP,
  326. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  327. };
  328. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  329. defined(CONFIG_IDF_TARGET_ESP32C6)
  330. #include <esp_cpu.h>
  331. #include "driver/gptimer.h"
  332. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  333. #define RESOLUTION_SCALE 100
  334. static gptimer_handle_t esp_gptimer = NULL;
  335. static gptimer_config_t esp_timer_config = {
  336. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  337. .direction = GPTIMER_COUNT_UP,
  338. /* CONFIG_XTAL_FREQ = 40,
  339. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  340. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  341. (MILLION_VALUE / RESOLUTION_SCALE),
  342. };
  343. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  344. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  345. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  346. defined(CONFIG_IDF_TARGET_ESP32S3)
  347. #include <xtensa/hal.h>
  348. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  349. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  350. #include <FreeRTOS.h>
  351. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  352. /* TODO add ESP32-H2 benchmark support */
  353. #else
  354. /* Other platform */
  355. #endif
  356. #include <esp_log.h>
  357. #endif /* WOLFSSL_ESPIDF */
  358. #if defined(HAVE_PTHREAD) || \
  359. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  360. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  361. !defined(BENCH_EMBEDDED))
  362. #include <errno.h>
  363. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  364. #include <unistd.h>
  365. #endif
  366. #endif
  367. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  368. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  369. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  370. #undef XFFLUSH
  371. #define XFFLUSH(...) WC_DO_NOTHING
  372. #endif
  373. /* only for stack size check */
  374. #include <wolfssl/wolfcrypt/mem_track.h>
  375. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  376. #define WC_ENABLE_BENCH_THREADING
  377. #endif
  378. /* enable tracking of stats for threaded benchmark */
  379. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  380. #define WC_BENCH_TRACK_STATS
  381. #endif
  382. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  383. static const char info_prefix[] = "###, ";
  384. static const char err_prefix[] = "!!!, ";
  385. #else
  386. static const char info_prefix[] = "";
  387. static const char err_prefix[] = "";
  388. #endif
  389. /* printf mappings */
  390. #ifdef FREESCALE_MQX
  391. #include <mqx.h>
  392. /* see wc_port.h for fio.h and nio.h includes */
  393. #elif defined(FREESCALE_KSDK_1_3)
  394. #include "fsl_debug_console.h"
  395. #include "fsl_os_abstraction.h"
  396. #undef printf
  397. #define printf PRINTF
  398. #elif defined(WOLFSSL_DEOS)
  399. #include <deos.h>
  400. #include <printx.h>
  401. #undef printf
  402. #define printf printx
  403. #elif defined(MICRIUM)
  404. #if (OS_VERSION < 50000)
  405. #include <bsp_ser.h>
  406. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  407. #undef printf
  408. #define printf BSP_Ser_Printf
  409. #endif
  410. #elif defined(WOLFSSL_ZEPHYR)
  411. #include <stdio.h>
  412. #define BENCH_EMBEDDED
  413. #define printf printfk
  414. static int printfk(const char *fmt, ...)
  415. {
  416. int ret;
  417. char line[WC_BENCH_MAX_LINE_LEN];
  418. va_list ap;
  419. va_start(ap, fmt);
  420. ret = vsnprintf(line, sizeof(line), fmt, ap);
  421. line[sizeof(line)-1] = '\0';
  422. printk("%s", line);
  423. va_end(ap);
  424. return ret;
  425. }
  426. #elif defined(WOLFSSL_TELIT_M2MB)
  427. #include <stdarg.h>
  428. #include <stdio.h>
  429. #include <string.h>
  430. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  431. /* remap printf */
  432. #undef printf
  433. #define printf M2M_LOG_INFO
  434. /* OS requires occasional sleep() */
  435. #ifndef TEST_SLEEP_MS
  436. #define TEST_SLEEP_MS 50
  437. #endif
  438. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  439. /* don't use file system for these tests, since ./certs dir isn't loaded */
  440. #undef NO_FILESYSTEM
  441. #define NO_FILESYSTEM
  442. /* ANDROID_V454 (for android studio) displays information in a textview
  443. * and redirects printf to the textview output instead of using
  444. * __android_log_print() */
  445. #elif defined(ANDROID) && !defined(ANDROID_V454)
  446. #ifdef XMALLOC_USER
  447. #include <stdlib.h> /* we're using malloc / free direct here */
  448. #endif
  449. #ifndef STRING_USER
  450. #include <stdio.h>
  451. #endif
  452. #include <android/log.h>
  453. #define printf(...) \
  454. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  455. #define fprintf(fp, ...) \
  456. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  457. #else
  458. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  459. /* MQX classic needs for EXIT_FAILURE */
  460. #include <stdlib.h> /* we're using malloc / free direct here */
  461. #endif
  462. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  463. #include <string.h>
  464. #include <stdio.h>
  465. #endif
  466. /* enable way for customer to override test/bench printf */
  467. #ifdef XPRINTF
  468. #undef printf
  469. #define printf XPRINTF
  470. #elif defined(NETOS)
  471. #undef printf
  472. #define printf dc_log_printf
  473. #endif
  474. #endif
  475. #ifdef HAVE_FIPS
  476. #include <wolfssl/wolfcrypt/fips_test.h>
  477. static void myFipsCb(int ok, int err, const char* hash)
  478. {
  479. printf("%sin my Fips callback, ok = %d, err = %d\n",
  480. ok ? info_prefix : err_prefix, ok, err);
  481. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  482. wc_GetErrorString(err));
  483. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  484. if (err == IN_CORE_FIPS_E) {
  485. printf("%sIn core integrity hash check failure, copy above hash\n",
  486. err_prefix);
  487. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  488. err_prefix);
  489. }
  490. }
  491. #endif
  492. #ifdef WOLFSSL_STATIC_MEMORY
  493. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  494. #else
  495. #define HEAP_HINT NULL
  496. #endif /* WOLFSSL_STATIC_MEMORY */
  497. #ifndef EXIT_FAILURE
  498. #define EXIT_FAILURE 1
  499. #endif
  500. #undef LIBCALL_CHECK_RET
  501. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  502. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  503. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  504. #else
  505. #define LIBCALL_CHECK_RET(...) do { \
  506. int _libcall_ret = (__VA_ARGS__); \
  507. if (_libcall_ret < 0) { \
  508. printf("%s%s L%d error %d for \"%s\"\n", \
  509. err_prefix, __FILE__, __LINE__, \
  510. errno, #__VA_ARGS__); \
  511. XFFLUSH(stdout); \
  512. _exit(1); \
  513. } \
  514. } while(0)
  515. #endif
  516. #undef THREAD_CHECK_RET
  517. #define THREAD_CHECK_RET(...) do { \
  518. int _thread_ret = (__VA_ARGS__); \
  519. if (_thread_ret != 0) { \
  520. errno = _thread_ret; \
  521. printf("%s%s L%d error %d for \"%s\"\n", \
  522. err_prefix, __FILE__, __LINE__, \
  523. _thread_ret, #__VA_ARGS__); \
  524. XFFLUSH(stdout); \
  525. _exit(1); \
  526. } \
  527. } while(0)
  528. /* optional macro to add sleep between tests */
  529. #ifndef TEST_SLEEP
  530. /* stub the sleep macro */
  531. #define TEST_SLEEP() WC_DO_NOTHING
  532. #endif
  533. #define TEST_STRING "Everyone gets Friday off."
  534. #define TEST_STRING_SZ 25
  535. /* Bit values for each algorithm that is able to be benchmarked.
  536. * Common grouping of algorithms also.
  537. * Each algorithm has a unique value for its type e.g. cipher.
  538. */
  539. /* Cipher algorithms. */
  540. #define BENCH_AES_CBC 0x00000001
  541. #define BENCH_AES_GCM 0x00000002
  542. #define BENCH_AES_ECB 0x00000004
  543. #define BENCH_AES_XTS 0x00000008
  544. #define BENCH_AES_CTR 0x00000010
  545. #define BENCH_AES_CCM 0x00000020
  546. #define BENCH_CAMELLIA 0x00000100
  547. #define BENCH_ARC4 0x00000200
  548. #define BENCH_CHACHA20 0x00001000
  549. #define BENCH_CHACHA20_POLY1305 0x00002000
  550. #define BENCH_DES 0x00004000
  551. #define BENCH_AES_CFB 0x00010000
  552. #define BENCH_AES_OFB 0x00020000
  553. #define BENCH_AES_SIV 0x00040000
  554. #define BENCH_SM4_CBC 0x00080000
  555. #define BENCH_SM4_GCM 0x00100000
  556. #define BENCH_SM4_CCM 0x00200000
  557. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  558. /* Digest algorithms. */
  559. #define BENCH_MD5 0x00000001
  560. #define BENCH_POLY1305 0x00000002
  561. #define BENCH_SHA 0x00000004
  562. #define BENCH_SHA224 0x00000010
  563. #define BENCH_SHA256 0x00000020
  564. #define BENCH_SHA384 0x00000040
  565. #define BENCH_SHA512 0x00000080
  566. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  567. BENCH_SHA384 | BENCH_SHA512)
  568. #define BENCH_SHA3_224 0x00000100
  569. #define BENCH_SHA3_256 0x00000200
  570. #define BENCH_SHA3_384 0x00000400
  571. #define BENCH_SHA3_512 0x00000800
  572. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  573. BENCH_SHA3_384 | BENCH_SHA3_512)
  574. #define BENCH_SHAKE128 0x00001000
  575. #define BENCH_SHAKE256 0x00002000
  576. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  577. #define BENCH_RIPEMD 0x00004000
  578. #define BENCH_BLAKE2B 0x00008000
  579. #define BENCH_BLAKE2S 0x00010000
  580. #define BENCH_SM3 0x00020000
  581. /* MAC algorithms. */
  582. #define BENCH_CMAC 0x00000001
  583. #define BENCH_HMAC_MD5 0x00000002
  584. #define BENCH_HMAC_SHA 0x00000004
  585. #define BENCH_HMAC_SHA224 0x00000010
  586. #define BENCH_HMAC_SHA256 0x00000020
  587. #define BENCH_HMAC_SHA384 0x00000040
  588. #define BENCH_HMAC_SHA512 0x00000080
  589. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  590. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  591. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  592. #define BENCH_PBKDF2 0x00000100
  593. #define BENCH_SIPHASH 0x00000200
  594. /* KDF algorithms */
  595. #define BENCH_SRTP_KDF 0x00000001
  596. /* Asymmetric algorithms. */
  597. #define BENCH_RSA_KEYGEN 0x00000001
  598. #define BENCH_RSA 0x00000002
  599. #define BENCH_RSA_SZ 0x00000004
  600. #define BENCH_DH 0x00000010
  601. #define BENCH_ECC_MAKEKEY 0x00001000
  602. #define BENCH_ECC 0x00002000
  603. #define BENCH_ECC_ENCRYPT 0x00004000
  604. #define BENCH_ECC_ALL 0x00008000
  605. #define BENCH_CURVE25519_KEYGEN 0x00010000
  606. #define BENCH_CURVE25519_KA 0x00020000
  607. #define BENCH_ED25519_KEYGEN 0x00040000
  608. #define BENCH_ED25519_SIGN 0x00080000
  609. #define BENCH_CURVE448_KEYGEN 0x00100000
  610. #define BENCH_CURVE448_KA 0x00200000
  611. #define BENCH_ED448_KEYGEN 0x00400000
  612. #define BENCH_ED448_SIGN 0x00800000
  613. #define BENCH_ECC_P256 0x01000000
  614. #define BENCH_ECC_P384 0x02000000
  615. #define BENCH_ECC_P521 0x04000000
  616. #define BENCH_SM2 0x08000000
  617. #define BENCH_ECCSI_KEYGEN 0x00000020
  618. #define BENCH_ECCSI_PAIRGEN 0x00000040
  619. #define BENCH_ECCSI_VALIDATE 0x00000080
  620. #define BENCH_ECCSI 0x00000400
  621. #define BENCH_SAKKE_KEYGEN 0x10000000
  622. #define BENCH_SAKKE_RSKGEN 0x20000000
  623. #define BENCH_SAKKE_VALIDATE 0x40000000
  624. #define BENCH_SAKKE 0x80000000
  625. /* Post-Quantum Asymmetric algorithms. */
  626. #define BENCH_KYBER512 0x00000020
  627. #define BENCH_KYBER768 0x00000040
  628. #define BENCH_KYBER1024 0x00000080
  629. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  630. BENCH_KYBER1024)
  631. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  632. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  633. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  634. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  635. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  636. #define BENCH_ML_DSA_44_SIGN 0x04000000
  637. #define BENCH_ML_DSA_65_SIGN 0x08000000
  638. #define BENCH_ML_DSA_87_SIGN 0x10000000
  639. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  640. BENCH_ML_DSA_65_SIGN | \
  641. BENCH_ML_DSA_87_SIGN)
  642. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  643. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  644. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  645. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  646. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  647. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  648. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  649. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  650. #define BENCH_LMS_HSS 0x00000001
  651. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  652. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  653. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  654. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  655. #ifndef NO_SHA256
  656. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  657. #elif defined(WOLFSSL_SHA512)
  658. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  659. #elif defined(WOLFSSL_SHAKE128)
  660. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  661. #elif defined(WOLFSSL_SHAKE256)
  662. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  663. #else
  664. #define BENCH_XMSS_XMSSMT 0x00000000
  665. #endif
  666. /* Other */
  667. #define BENCH_RNG 0x00000001
  668. #define BENCH_SCRYPT 0x00000002
  669. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  670. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  671. * static declaration of `bench_Usage_msg1`. */
  672. #if !defined(AES_AUTH_ADD_SZ) && \
  673. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  674. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  675. /* For STM32 use multiple of 4 to leverage crypto hardware
  676. * Xilinx Versal requires to use multiples of 16 bytes */
  677. #define AES_AUTH_ADD_SZ 16
  678. #endif
  679. #ifndef AES_AUTH_ADD_SZ
  680. #define AES_AUTH_ADD_SZ 13
  681. #endif
  682. #endif
  683. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  684. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  685. #define BENCH_PQ_STATEFUL_HBS
  686. #endif
  687. /* Benchmark all compiled in algorithms.
  688. * When 1, ignore other benchmark algorithm values.
  689. * 0, only benchmark algorithm values set.
  690. */
  691. static int bench_all = 1;
  692. /* Cipher algorithms to benchmark. */
  693. static word32 bench_cipher_algs = 0;
  694. /* Digest algorithms to benchmark. */
  695. static word32 bench_digest_algs = 0;
  696. /* MAC algorithms to benchmark. */
  697. static word32 bench_mac_algs = 0;
  698. /* KDF algorithms to benchmark. */
  699. static word32 bench_kdf_algs = 0;
  700. /* Asymmetric algorithms to benchmark. */
  701. static word32 bench_asym_algs = 0;
  702. /* Post-Quantum Asymmetric algorithms to benchmark. */
  703. static word32 bench_pq_asym_algs = 0;
  704. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  705. static word32 bench_pq_asym_algs2 = 0;
  706. /* Other cryptographic algorithms to benchmark. */
  707. static word32 bench_other_algs = 0;
  708. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  709. static word32 bench_pq_hash_sig_algs = 0;
  710. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  711. /* The mapping of command line option to bit values. */
  712. typedef struct bench_alg {
  713. /* Command line option string. */
  714. const char* str;
  715. /* Bit values to set. */
  716. word32 val;
  717. } bench_alg;
  718. #ifndef MAIN_NO_ARGS
  719. /* All recognized cipher algorithm choosing command line options. */
  720. static const bench_alg bench_cipher_opt[] = {
  721. { "-cipher", 0xffffffff },
  722. #ifdef HAVE_AES_CBC
  723. { "-aes-cbc", BENCH_AES_CBC },
  724. #endif
  725. #ifdef HAVE_AESGCM
  726. { "-aes-gcm", BENCH_AES_GCM },
  727. #endif
  728. #ifdef WOLFSSL_AES_DIRECT
  729. { "-aes-ecb", BENCH_AES_ECB },
  730. #endif
  731. #ifdef WOLFSSL_AES_XTS
  732. { "-aes-xts", BENCH_AES_XTS },
  733. #endif
  734. #ifdef WOLFSSL_AES_CFB
  735. { "-aes-cfb", BENCH_AES_CFB },
  736. #endif
  737. #ifdef WOLFSSL_AES_OFB
  738. { "-aes-ofb", BENCH_AES_OFB },
  739. #endif
  740. #ifdef WOLFSSL_AES_COUNTER
  741. { "-aes-ctr", BENCH_AES_CTR },
  742. #endif
  743. #ifdef HAVE_AESCCM
  744. { "-aes-ccm", BENCH_AES_CCM },
  745. #endif
  746. #ifdef WOLFSSL_AES_SIV
  747. { "-aes-siv", BENCH_AES_SIV },
  748. #endif
  749. #ifdef HAVE_CAMELLIA
  750. { "-camellia", BENCH_CAMELLIA },
  751. #endif
  752. #ifndef NO_RC4
  753. { "-arc4", BENCH_ARC4 },
  754. #endif
  755. #ifdef HAVE_CHACHA
  756. { "-chacha20", BENCH_CHACHA20 },
  757. #endif
  758. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  759. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  760. #endif
  761. #ifdef WOLFSSL_SM4_CBC
  762. { "-sm4-cbc", BENCH_SM4_CBC },
  763. #endif
  764. #ifdef WOLFSSL_SM4_GCM
  765. { "-sm4-gcm", BENCH_SM4_GCM },
  766. #endif
  767. #ifdef WOLFSSL_SM4_CCM
  768. { "-sm4-ccm", BENCH_SM4_CCM },
  769. #endif
  770. #ifdef WOLFSSL_SM4
  771. { "-sm4", BENCH_SM4 },
  772. #endif
  773. #ifndef NO_DES3
  774. { "-des", BENCH_DES },
  775. #endif
  776. { NULL, 0 }
  777. };
  778. /* All recognized digest algorithm choosing command line options. */
  779. static const bench_alg bench_digest_opt[] = {
  780. { "-digest", 0xffffffff },
  781. #ifndef NO_MD5
  782. { "-md5", BENCH_MD5 },
  783. #endif
  784. #ifdef HAVE_POLY1305
  785. { "-poly1305", BENCH_POLY1305 },
  786. #endif
  787. #ifndef NO_SHA
  788. { "-sha", BENCH_SHA },
  789. #endif
  790. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  791. || defined(WOLFSSL_SHA512)
  792. { "-sha2", BENCH_SHA2 },
  793. #endif
  794. #ifdef WOLFSSL_SHA224
  795. { "-sha224", BENCH_SHA224 },
  796. #endif
  797. #ifndef NO_SHA256
  798. { "-sha256", BENCH_SHA256 },
  799. #endif
  800. #ifdef WOLFSSL_SHA384
  801. { "-sha384", BENCH_SHA384 },
  802. #endif
  803. #ifdef WOLFSSL_SHA512
  804. { "-sha512", BENCH_SHA512 },
  805. #endif
  806. #ifdef WOLFSSL_SHA3
  807. { "-sha3", BENCH_SHA3 },
  808. #ifndef WOLFSSL_NOSHA3_224
  809. { "-sha3-224", BENCH_SHA3_224 },
  810. #endif
  811. #ifndef WOLFSSL_NOSHA3_256
  812. { "-sha3-256", BENCH_SHA3_256 },
  813. #endif
  814. #ifndef WOLFSSL_NOSHA3_384
  815. { "-sha3-384", BENCH_SHA3_384 },
  816. #endif
  817. #ifndef WOLFSSL_NOSHA3_512
  818. { "-sha3-512", BENCH_SHA3_512 },
  819. #endif
  820. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  821. { "-shake", BENCH_SHAKE },
  822. #endif
  823. #ifdef WOLFSSL_SHAKE128
  824. { "-shake128", BENCH_SHAKE128 },
  825. #endif
  826. #ifdef WOLFSSL_SHAKE256
  827. { "-shake256", BENCH_SHAKE256 },
  828. #endif
  829. #endif
  830. #ifdef WOLFSSL_SM3
  831. { "-sm3", BENCH_SM3 },
  832. #endif
  833. #ifdef WOLFSSL_RIPEMD
  834. { "-ripemd", BENCH_RIPEMD },
  835. #endif
  836. #ifdef HAVE_BLAKE2
  837. { "-blake2b", BENCH_BLAKE2B },
  838. #endif
  839. #ifdef HAVE_BLAKE2S
  840. { "-blake2s", BENCH_BLAKE2S },
  841. #endif
  842. { NULL, 0 }
  843. };
  844. /* All recognized MAC algorithm choosing command line options. */
  845. static const bench_alg bench_mac_opt[] = {
  846. { "-mac", 0xffffffff },
  847. #ifdef WOLFSSL_CMAC
  848. { "-cmac", BENCH_CMAC },
  849. #endif
  850. #ifndef NO_HMAC
  851. { "-hmac", BENCH_HMAC },
  852. #ifndef NO_MD5
  853. { "-hmac-md5", BENCH_HMAC_MD5 },
  854. #endif
  855. #ifndef NO_SHA
  856. { "-hmac-sha", BENCH_HMAC_SHA },
  857. #endif
  858. #ifdef WOLFSSL_SHA224
  859. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  860. #endif
  861. #ifndef NO_SHA256
  862. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  863. #endif
  864. #ifdef WOLFSSL_SHA384
  865. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  866. #endif
  867. #ifdef WOLFSSL_SHA512
  868. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  869. #endif
  870. #ifndef NO_PWDBASED
  871. { "-pbkdf2", BENCH_PBKDF2 },
  872. #endif
  873. #endif
  874. #ifdef WOLFSSL_SIPHASH
  875. { "-siphash", BENCH_SIPHASH },
  876. #endif
  877. { NULL, 0 }
  878. };
  879. /* All recognized KDF algorithm choosing command line options. */
  880. static const bench_alg bench_kdf_opt[] = {
  881. { "-kdf", 0xffffffff },
  882. #ifdef WC_SRTP_KDF
  883. { "-srtp-kdf", BENCH_SRTP_KDF },
  884. #endif
  885. { NULL, 0 }
  886. };
  887. /* All recognized asymmetric algorithm choosing command line options. */
  888. static const bench_alg bench_asym_opt[] = {
  889. { "-asym", 0xffffffff },
  890. #ifndef NO_RSA
  891. #ifdef WOLFSSL_KEY_GEN
  892. { "-rsa-kg", BENCH_RSA_KEYGEN },
  893. #endif
  894. { "-rsa", BENCH_RSA },
  895. #ifdef WOLFSSL_KEY_GEN
  896. { "-rsa-sz", BENCH_RSA_SZ },
  897. #endif
  898. #endif
  899. #ifndef NO_DH
  900. { "-dh", BENCH_DH },
  901. #endif
  902. #ifdef HAVE_ECC
  903. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  904. { "-ecc", BENCH_ECC },
  905. #ifdef HAVE_ECC_ENCRYPT
  906. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  907. #endif
  908. { "-ecc-all", BENCH_ECC_ALL },
  909. #endif
  910. #ifdef WOLFSSL_SM2
  911. { "-sm2", BENCH_SM2 },
  912. #endif
  913. #ifdef HAVE_CURVE25519
  914. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  915. #ifdef HAVE_CURVE25519_SHARED_SECRET
  916. { "-x25519", BENCH_CURVE25519_KA },
  917. #endif
  918. #endif
  919. #ifdef HAVE_ED25519
  920. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  921. { "-ed25519", BENCH_ED25519_SIGN },
  922. #endif
  923. #ifdef HAVE_CURVE448
  924. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  925. #ifdef HAVE_CURVE448_SHARED_SECRET
  926. { "-x448", BENCH_CURVE448_KA },
  927. #endif
  928. #endif
  929. #ifdef HAVE_ED448
  930. { "-ed448-kg", BENCH_ED448_KEYGEN },
  931. { "-ed448", BENCH_ED448_SIGN },
  932. #endif
  933. #ifdef WOLFCRYPT_HAVE_ECCSI
  934. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  935. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  936. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  937. { "-eccsi", BENCH_ECCSI },
  938. #endif
  939. #ifdef WOLFCRYPT_HAVE_SAKKE
  940. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  941. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  942. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  943. { "-sakke", BENCH_SAKKE },
  944. #endif
  945. { NULL, 0 }
  946. };
  947. /* All recognized other cryptographic algorithm choosing command line options.
  948. */
  949. static const bench_alg bench_other_opt[] = {
  950. { "-other", 0xffffffff },
  951. #ifndef WC_NO_RNG
  952. { "-rng", BENCH_RNG },
  953. #endif
  954. #ifdef HAVE_SCRYPT
  955. { "-scrypt", BENCH_SCRYPT },
  956. #endif
  957. { NULL, 0}
  958. };
  959. #endif /* MAIN_NO_ARGS */
  960. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  961. #if defined(BENCH_PQ_STATEFUL_HBS)
  962. typedef struct bench_pq_hash_sig_alg {
  963. /* Command line option string. */
  964. const char* str;
  965. /* Bit values to set. */
  966. word32 val;
  967. } bench_pq_hash_sig_alg;
  968. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  969. { "-pq_hash_sig", 0xffffffff},
  970. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  971. { "-lms_hss", BENCH_LMS_HSS},
  972. #endif
  973. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  974. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  975. #ifdef WC_XMSS_SHA256
  976. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  977. #endif
  978. #ifdef WC_XMSS_SHA512
  979. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  980. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  981. #endif
  982. #endif
  983. #ifdef WC_XMSS_SHAKE128
  984. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  985. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  986. #endif
  987. #endif
  988. #ifdef WC_XMSS_SHAKE256
  989. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  990. #endif
  991. #endif
  992. { NULL, 0}
  993. };
  994. #endif /* BENCH_PQ_STATEFUL_HBS */
  995. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  996. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  997. /* The post-quantum-specific mapping of command line option to bit values and
  998. * OQS name. */
  999. typedef struct bench_pq_alg {
  1000. /* Command line option string. */
  1001. const char* str;
  1002. /* Bit values to set. */
  1003. word32 val;
  1004. } bench_pq_alg;
  1005. /* All recognized post-quantum asymmetric algorithm choosing command line
  1006. * options. */
  1007. static const bench_pq_alg bench_pq_asym_opt[] = {
  1008. { "-pq", 0xffffffff },
  1009. #ifdef WOLFSSL_HAVE_KYBER
  1010. { "-kyber", BENCH_KYBER },
  1011. { "-kyber512", BENCH_KYBER512 },
  1012. { "-kyber768", BENCH_KYBER768 },
  1013. { "-kyber1024", BENCH_KYBER1024 },
  1014. #endif
  1015. #if defined(HAVE_FALCON)
  1016. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1017. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1018. #endif
  1019. #if defined(HAVE_DILITHIUM)
  1020. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1021. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1022. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1023. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1024. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1025. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1026. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1027. #endif
  1028. { NULL, 0 }
  1029. };
  1030. #if defined(HAVE_SPHINCS)
  1031. /* All recognized post-quantum asymmetric algorithm choosing command line
  1032. * options. (Part 2) */
  1033. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1034. { "-pq", 0xffffffff },
  1035. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1036. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1037. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1038. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1039. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1040. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1041. { NULL, 0, }
  1042. };
  1043. #endif /* HAVE_SPHINCS */
  1044. #endif
  1045. #ifdef HAVE_WNR
  1046. const char* wnrConfigFile = "wnr-example.conf";
  1047. #endif
  1048. #if defined(WOLFSSL_MDK_ARM)
  1049. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1050. #define fopen wolfSSL_fopen
  1051. #endif
  1052. static int lng_index = 0;
  1053. #ifndef NO_MAIN_DRIVER
  1054. #ifndef MAIN_NO_ARGS
  1055. static const char* bench_Usage_msg1[][25] = {
  1056. /* 0 English */
  1057. { "-? <num> Help, print this usage\n",
  1058. " 0: English, 1: Japanese\n",
  1059. "-csv Print terminal output in csv format\n",
  1060. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1061. "-no_aad No additional authentication data passed.\n",
  1062. "-aad_size <num> With <num> bytes of AAD.\n",
  1063. ("-all_aad With AAD length of 0, "
  1064. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1065. " and\n"
  1066. " (if set via -aad_size) <aad_size> bytes.\n"
  1067. ),
  1068. "-dgst_full Full digest operation performed.\n",
  1069. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1070. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1071. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1072. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1073. "-p256 Measure ECC using P-256 curve.\n",
  1074. "-p384 Measure ECC using P-384 curve.\n",
  1075. "-p521 Measure ECC using P-521 curve.\n",
  1076. "-ecc-all Bench all enabled ECC curves.\n",
  1077. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1078. ("-lng <num> Display benchmark result by specified language.\n"
  1079. " 0: English, 1: Japanese\n"
  1080. ),
  1081. "<num> Size of block in bytes\n",
  1082. ("-blocks <num> Number of blocks. Can be used together with the "
  1083. "'Size of block'\n"
  1084. " option, but must be used after that one.\n"
  1085. ),
  1086. "-threads <num> Number of threads to run\n",
  1087. "-print Show benchmark stats summary\n",
  1088. "-hash_input <file> Input data to use for hash benchmarking\n",
  1089. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1090. "-min_runs <num> Specify minimum number of operation runs\n"
  1091. },
  1092. #ifndef NO_MULTIBYTE_PRINT
  1093. /* 1 Japanese */
  1094. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1095. " 0: 英語、 1: 日本語\n",
  1096. "-csv csv 形式で端末に出力します。\n",
  1097. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1098. "-no_aad 追加の認証データを使用しません.\n",
  1099. "-aad_size <num> TBD.\n",
  1100. "-all_aad TBD.\n",
  1101. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1102. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1103. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1104. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1105. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1106. "-p256 Measure ECC using P-256 curve.\n",
  1107. "-p384 Measure ECC using P-384 curve.\n",
  1108. "-p521 Measure ECC using P-521 curve.\n",
  1109. "-ecc-all Bench all enabled ECC curves.\n",
  1110. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1111. " 利用可能なアルゴリズムは下記を含みます:\n"
  1112. ),
  1113. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1114. " 0: 英語、 1: 日本語\n"
  1115. ),
  1116. "<num> ブロックサイズをバイト単位で指定します。\n",
  1117. "-blocks <num> TBD.\n",
  1118. "-threads <num> 実行するスレッド数\n",
  1119. "-print ベンチマーク統計の要約を表示する\n",
  1120. /* TODO: translate below */
  1121. "-hash_input <file> Input data to use for hash benchmarking\n",
  1122. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1123. "-min_runs <num> Specify minimum number of operation runs\n"
  1124. },
  1125. #endif
  1126. };
  1127. #endif /* MAIN_NO_ARGS */
  1128. #endif
  1129. static const char* bench_result_words1[][4] = {
  1130. { "took",
  1131. #ifdef BENCH_MICROSECOND
  1132. "microseconds"
  1133. #else
  1134. "seconds"
  1135. #endif
  1136. , "Cycles per byte", NULL }, /* 0 English */
  1137. #ifndef NO_MULTIBYTE_PRINT
  1138. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1139. #endif
  1140. };
  1141. #if !defined(NO_RSA) || \
  1142. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1143. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1144. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1145. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1146. defined(WOLFSSL_HAVE_KYBER)
  1147. static const char* bench_desc_words[][15] = {
  1148. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1149. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1150. #ifndef NO_MULTIBYTE_PRINT
  1151. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1152. #endif
  1153. };
  1154. #endif
  1155. #ifdef MULTI_VALUE_STATISTICS
  1156. static const char* bench_result_words3[][5] = {
  1157. /* 0 English */
  1158. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1159. /* TODO: Add japenese version */
  1160. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1161. };
  1162. #endif
  1163. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1164. #define HAVE_GET_CYCLES
  1165. static WC_INLINE word64 get_intel_cycles(void);
  1166. static THREAD_LS_T word64 total_cycles;
  1167. #define INIT_CYCLE_COUNTER
  1168. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1169. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1170. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1171. #define SHOW_INTEL_CYCLES(b, n, s) \
  1172. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1173. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1174. bench_result_words1[lng_index][2], \
  1175. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1176. (double)total_cycles / ((word64)count*(s))))
  1177. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1178. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1179. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1180. (double)total_cycles / ((word64)count*(s))))
  1181. #elif defined(LINUX_CYCLE_COUNT)
  1182. #include <linux/perf_event.h>
  1183. #include <sys/syscall.h>
  1184. #include <unistd.h>
  1185. static THREAD_LS_T word64 begin_cycles;
  1186. static THREAD_LS_T word64 total_cycles;
  1187. static THREAD_LS_T int cycles = -1;
  1188. static THREAD_LS_T struct perf_event_attr atr;
  1189. #define INIT_CYCLE_COUNTER do { \
  1190. atr.type = PERF_TYPE_HARDWARE; \
  1191. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1192. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1193. } while (0);
  1194. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1195. #define END_INTEL_CYCLES do { \
  1196. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1197. total_cycles = total_cycles - begin_cycles; \
  1198. } while (0);
  1199. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1200. #define SHOW_INTEL_CYCLES(b, n, s) \
  1201. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1202. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1203. bench_result_words1[lng_index][2], \
  1204. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1205. (count*s)))
  1206. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1207. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1208. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1209. / (count*s)))
  1210. #elif defined(SYNERGY_CYCLE_COUNT)
  1211. #include "hal_data.h"
  1212. static THREAD_LS_T word64 begin_cycles;
  1213. static THREAD_LS_T word64 total_cycles;
  1214. #define INIT_CYCLE_COUNTER
  1215. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1216. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1217. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1218. #define SHOW_INTEL_CYCLES(b, n, s) \
  1219. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1220. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1221. bench_result_words1[lng_index][2], \
  1222. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1223. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1224. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1225. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1226. #elif defined(WOLFSSL_ESPIDF)
  1227. /* TAG for ESP_LOGx() */
  1228. static const char* TAG = "wolfssl_benchmark";
  1229. static THREAD_LS_T word64 begin_cycles = 0;
  1230. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1231. static THREAD_LS_T word64 end_cycles = 0;
  1232. static THREAD_LS_T word64 total_cycles = 0;
  1233. /* the return value, as a global var */
  1234. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1235. /* the last value seen, adjusted for an overflow, as a global var */
  1236. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1237. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1238. /* esp_get_cpu_benchmark_cycles(void):
  1239. *
  1240. * Architecture-independant CPU clock counter.
  1241. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1242. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1243. /* Some vars for debugging, compare ticks to cycles */
  1244. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1245. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1246. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1247. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1248. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1249. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1250. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1251. #if ESP_IDF_VERSION_MAJOR >= 5
  1252. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1253. #define HAVE_GET_CYCLES
  1254. #define INIT_CYCLE_COUNTER do { \
  1255. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1256. esp_cpu_set_cycle_count(0); \
  1257. } while (0);
  1258. #else
  1259. #define HAVE_GET_CYCLES
  1260. #define INIT_CYCLE_COUNTER do { \
  1261. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1262. } while (0);
  1263. #endif
  1264. #define BEGIN_ESP_CYCLES do { \
  1265. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1266. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1267. begin_cycles_ticks = xTaskGetTickCount(); \
  1268. } while (0);
  1269. /* since it rolls over, we have something that will tolerate one */
  1270. #define END_ESP_CYCLES \
  1271. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1272. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1273. end_cycles, \
  1274. begin_cycles \
  1275. ); \
  1276. total_cycles = (end_cycles - begin_cycles);
  1277. #define SHOW_ESP_CYCLES(b, n, s) \
  1278. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1279. " %s = " FLT_FMT_PREC2 "\n", \
  1280. bench_result_words1[lng_index][2], \
  1281. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1282. )
  1283. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1284. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1285. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1286. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1287. /* 64 bit, unisgned, absolute difference
  1288. * used in CPU cycle counter debug calcs. */
  1289. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1290. {
  1291. uint64_t ret;
  1292. ret = (x > y) ? (x - y) : (y - x);
  1293. return ret;
  1294. }
  1295. #endif
  1296. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1297. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1298. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1299. ** at least once during full benchmark tests.
  1300. **
  1301. ** To test timing overflow, add a delay longer than max cycles:
  1302. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1303. */
  1304. uint64_t esp_get_cycle_count_ex()
  1305. {
  1306. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1307. /* unsigned int max = 4,294,967,295 */
  1308. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1309. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1310. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1311. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1312. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1313. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1314. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1315. #endif
  1316. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1317. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1318. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1319. * (current - last) */
  1320. #endif
  1321. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1322. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1323. defined(CONFIG_IDF_TARGET_ESP32C6)
  1324. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1325. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1326. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1327. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1328. thisVal = esp_cpu_get_cycle_count();
  1329. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1330. thisVal = esp_cpu_get_cycle_count();
  1331. #else
  1332. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1333. * Calling current_time(1) to reset time causes thisVal overflow,
  1334. * on Xtensa, but not on RISC-V architecture. See also, below */
  1335. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1336. #ifndef configCPU_CLOCK_HZ
  1337. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1338. #define configCPU_CLOCK_HZ \
  1339. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1340. #endif
  1341. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1342. thisVal = (uint64_t)xTaskGetTickCount() *
  1343. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1344. #elif defined(__XTENSA__)
  1345. thisVal = esp_cpu_get_cycle_count();
  1346. #else
  1347. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1348. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1349. #endif
  1350. #endif
  1351. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1352. {
  1353. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1354. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1355. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1356. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1357. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1358. ESP_LOGV(TAG, "last_tickCount = %u", last_tickCount);
  1359. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1360. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1361. }
  1362. #endif
  1363. /* If either thisVal is smaller than last (overflow), and/or the
  1364. * expected value calculated from FreeRTOS tick difference that would
  1365. * have never fit into an unsigned 32 bit integer anyhow... then we
  1366. * need to adjust thisVal to save. */
  1367. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1368. {
  1369. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1370. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1371. **
  1372. ** NOTE for long duration between calls with multiple overflows:
  1373. **
  1374. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1375. **
  1376. ** At this time no single test overflows. This is currently only a
  1377. ** concern for cumulative counts over multiple tests. As long
  1378. ** as well call xthal_get_ccount_ex() with no more than one
  1379. ** overflow CPU tick count, all will be well.
  1380. */
  1381. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1382. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1383. "(%llu < %llu) adding UINT_MAX = %llu.",
  1384. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1385. #endif
  1386. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1387. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1388. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1389. #endif
  1390. /* double check expected diff calc */
  1391. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1392. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1393. * tickDiff / configTICK_RATE_HZ;
  1394. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1395. #endif
  1396. if (expected_diff > UINT_MAX) {
  1397. /* The number of cycles expected from FreeRTOS ticks is
  1398. * greater than the maximum size of an unsigned 32-bit
  1399. * integer, meaning multiple overflows occurred. */
  1400. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1401. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1402. #endif
  1403. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1404. }
  1405. else {
  1406. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1407. }
  1408. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1409. {
  1410. tickBeginDiff = tickCount - begin_cycles_ticks;
  1411. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1412. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1413. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1414. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1415. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1416. }
  1417. #endif
  1418. }
  1419. else {
  1420. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1421. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1422. #endif
  1423. } /* if thisVal adjustment check */
  1424. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1425. if (thisTimerVal < _esp_cpu_timer_last)
  1426. {
  1427. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1428. "adding %ull", UINT_MAX);
  1429. thisTimerVal += (word64)UINT_MAX;
  1430. }
  1431. /* Check an alternate counter using a timer */
  1432. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1433. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1434. /* Adjust our actual returned value that takes into account overflow,
  1435. * increment 64 bit extended total by this 32 bit differential: */
  1436. thisIncrement = (thisVal - _esp_cpu_count_last);
  1437. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1438. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1439. #endif
  1440. /* Add our adjustment, taking into account overflows (see above) */
  1441. _esp_get_cycle_count_ex += thisIncrement;
  1442. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1443. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1444. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1445. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1446. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1447. /* all of this took some time, so reset the "last seen" value
  1448. * for the next measurement. */
  1449. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1450. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1451. defined(CONFIG_IDF_TARGET_ESP32C6)
  1452. {
  1453. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1454. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1455. &_esp_cpu_timer_last));
  1456. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1457. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1458. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1459. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1460. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1461. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1462. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1463. }
  1464. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1465. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1466. #else
  1467. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1468. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1469. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1470. * or thisVal = xthal_get_ccount(); */
  1471. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1472. /* There's no CPU counter on the ESP8266, so we'll estimate
  1473. * cycles based on defined CPU frequency from sdkconfig and
  1474. * the RTOS tick frequency */
  1475. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1476. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1477. #elif ESP_IDF_VERSION_MAJOR < 5
  1478. _esp_cpu_count_last = xthal_get_ccount();
  1479. #else
  1480. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1481. #endif
  1482. #endif
  1483. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1484. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1485. #endif
  1486. /* Return the 64 bit extended total from 32 bit counter. */
  1487. return _esp_get_cycle_count_ex;
  1488. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1489. /* implement other architecture cycle counters here */
  1490. #else
  1491. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1492. #undef HAVE_GET_CYCLES
  1493. #define INIT_CYCLE_COUNTER
  1494. #define BEGIN_INTEL_CYCLES
  1495. #define END_INTEL_CYCLES
  1496. #ifdef MULTI_VALUE_STATISTICS
  1497. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1498. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1499. #else
  1500. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1501. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1502. #endif
  1503. #endif
  1504. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1505. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1506. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1507. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1508. #endif
  1509. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1510. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1511. !defined(NO_DH)
  1512. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1513. #include <wolfssl/certs_test.h>
  1514. #endif
  1515. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1516. #include <wolfssl/wolfcrypt/blake2.h>
  1517. #endif
  1518. #ifdef _MSC_VER
  1519. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1520. #pragma warning(disable: 4996)
  1521. #endif
  1522. #ifdef WOLFSSL_CURRTIME_REMAP
  1523. #define current_time WOLFSSL_CURRTIME_REMAP
  1524. #else
  1525. double current_time(int reset);
  1526. #endif
  1527. #ifdef LINUX_RUSAGE_UTIME
  1528. static void check_for_excessive_stime(const char *desc,
  1529. const char *desc_extra);
  1530. #endif
  1531. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND) && \
  1532. !defined(HAVE_STACK_SIZE)
  1533. #ifdef __cplusplus
  1534. extern "C" {
  1535. #endif
  1536. WOLFSSL_API int wolfSSL_Debugging_ON(void);
  1537. WOLFSSL_API void wolfSSL_Debugging_OFF(void);
  1538. #ifdef __cplusplus
  1539. } /* extern "C" */
  1540. #endif
  1541. #endif
  1542. #if !defined(WC_NO_RNG) && \
  1543. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1544. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1545. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1546. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1547. || defined(WOLFSSL_HAVE_KYBER))
  1548. #define HAVE_LOCAL_RNG
  1549. static THREAD_LS_T WC_RNG gRng;
  1550. #define GLOBAL_RNG &gRng
  1551. #else
  1552. #define GLOBAL_RNG NULL
  1553. #endif
  1554. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1555. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1556. defined(HAVE_ECC) || !defined(NO_DH) || \
  1557. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1558. defined(WOLFSSL_HAVE_KYBER)
  1559. #define BENCH_ASYM
  1560. #endif
  1561. #if defined(BENCH_ASYM)
  1562. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1563. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1564. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1565. defined(WOLFSSL_HAVE_KYBER)
  1566. static const char* bench_result_words2[][5] = {
  1567. #ifdef BENCH_MICROSECOND
  1568. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1569. for μsec */
  1570. #else
  1571. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1572. #endif
  1573. #ifndef NO_MULTIBYTE_PRINT
  1574. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1575. #endif
  1576. };
  1577. #endif
  1578. #endif
  1579. #ifdef WOLFSSL_CAAM
  1580. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1581. #ifdef WOLFSSL_SECO_CAAM
  1582. #define SECO_MAX_UPDATES 10000
  1583. #define SECO_BENCHMARK_NONCE 0x7777
  1584. #define SECO_KEY_STORE_ID 1
  1585. #endif
  1586. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1587. #else
  1588. #ifdef WC_USE_DEVID
  1589. static THREAD_LS_T int devId = WC_USE_DEVID;
  1590. #else
  1591. static THREAD_LS_T int devId = INVALID_DEVID;
  1592. #endif
  1593. #endif
  1594. /* Asynchronous helper macros */
  1595. #ifdef WC_ENABLE_BENCH_THREADING
  1596. typedef struct ThreadData {
  1597. pthread_t thread_id;
  1598. } ThreadData;
  1599. static ThreadData* g_threadData;
  1600. static volatile int g_threadCount;
  1601. #endif
  1602. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1603. #ifndef NO_HW_BENCH
  1604. #define BENCH_DEVID
  1605. #endif
  1606. #ifndef HAVE_RENESAS_SYNC
  1607. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1608. #else
  1609. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1610. #endif
  1611. #else
  1612. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1613. #endif
  1614. #ifdef WOLFSSL_ASYNC_CRYPT
  1615. static WOLF_EVENT_QUEUE eventQueue;
  1616. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1617. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1618. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1619. int callAgain, int* times, int limit, int* pending)
  1620. {
  1621. int allowNext = 0;
  1622. /* this state can be set from a different thread */
  1623. WOLF_EVENT_STATE state = asyncDev->event.state;
  1624. /* if algo doesn't require calling again then use this flow */
  1625. if (state == WOLF_EVENT_STATE_DONE) {
  1626. if (callAgain) {
  1627. /* needs called again, so allow it and handle completion in
  1628. * bench_async_handle */
  1629. allowNext = 1;
  1630. }
  1631. else {
  1632. *ret = asyncDev->event.ret;
  1633. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1634. (*times)++;
  1635. if (*pending > 0) /* to support case where async blocks */
  1636. (*pending)--;
  1637. if ((*times + *pending) < limit)
  1638. allowNext = 1;
  1639. }
  1640. }
  1641. /* if slot is available and we haven't reached limit, start another */
  1642. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1643. allowNext = 1;
  1644. }
  1645. return allowNext;
  1646. }
  1647. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1648. int callAgain, int* times, int* pending)
  1649. {
  1650. WOLF_EVENT_STATE state = asyncDev->event.state;
  1651. if (*ret == WC_PENDING_E) {
  1652. if (state == WOLF_EVENT_STATE_DONE) {
  1653. *ret = asyncDev->event.ret;
  1654. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1655. (*times)++;
  1656. (*pending)--;
  1657. }
  1658. else {
  1659. (*pending)++;
  1660. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1661. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1662. }
  1663. }
  1664. else if (*ret >= 0) {
  1665. *ret = asyncDev->event.ret;
  1666. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1667. (*times)++;
  1668. if (*pending > 0) /* to support case where async blocks */
  1669. (*pending)--;
  1670. }
  1671. return (*ret >= 0) ? 1 : 0;
  1672. }
  1673. static WC_INLINE int bench_async_poll(int* pending)
  1674. {
  1675. int ret, asyncDone = 0;
  1676. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1677. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1678. if (ret != 0) {
  1679. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1680. return ret;
  1681. }
  1682. if (asyncDone == 0) {
  1683. #ifndef WC_NO_ASYNC_THREADING
  1684. /* give time to other threads */
  1685. wc_AsyncThreadYield();
  1686. #endif
  1687. }
  1688. (void)pending;
  1689. return asyncDone;
  1690. }
  1691. #else
  1692. #define BENCH_MAX_PENDING 1
  1693. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1694. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1695. int callAgain, int* times, int limit, int* pending)
  1696. {
  1697. (void)ret;
  1698. (void)asyncDev;
  1699. (void)callAgain;
  1700. (void)times;
  1701. (void)limit;
  1702. (void)pending;
  1703. return 1;
  1704. }
  1705. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1706. int callAgain, int* times, int* pending)
  1707. {
  1708. (void)asyncDev;
  1709. (void)callAgain;
  1710. (void)pending;
  1711. if (*ret >= 0) {
  1712. /* operation completed */
  1713. (*times)++;
  1714. return 1;
  1715. }
  1716. return 0;
  1717. }
  1718. #define bench_async_poll(p) WC_DO_NOTHING
  1719. #endif /* WOLFSSL_ASYNC_CRYPT */
  1720. /* maximum runtime for each benchmark */
  1721. #ifndef BENCH_MIN_RUNTIME_SEC
  1722. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1723. #endif
  1724. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1725. #define AES_AUTH_TAG_SZ 16
  1726. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1727. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1728. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1729. #if !defined(NO_MAIN_DRIVER)
  1730. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1731. #else
  1732. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1733. #endif
  1734. #endif
  1735. #define AES_AAD_STRING(s) \
  1736. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1737. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1738. enum en_aad_options {
  1739. AAD_SIZE_DEFAULT = 0x1U,
  1740. AAD_SIZE_ZERO = 0x2U,
  1741. AAD_SIZE_CUSTOM = 0x4U,
  1742. };
  1743. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1744. static word32 aes_aad_size = 0;
  1745. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1746. {
  1747. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1748. word32 options = aes_aad_options;
  1749. while(options) {
  1750. if (options & AAD_SIZE_DEFAULT) {
  1751. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1752. options &= ~(word32)AAD_SIZE_DEFAULT;
  1753. }
  1754. else if (options & AAD_SIZE_ZERO) {
  1755. aesAuthAddSz = 0;
  1756. options &= ~(word32)AAD_SIZE_ZERO;
  1757. }
  1758. else if (options & AAD_SIZE_CUSTOM) {
  1759. aesAuthAddSz = aes_aad_size;
  1760. options &= ~(word32)AAD_SIZE_CUSTOM;
  1761. }
  1762. fn(i);
  1763. aesAuthAddSz = aesAuthAddSz_orig;
  1764. }
  1765. }
  1766. #endif
  1767. #ifndef BENCH_CIPHER_ADD
  1768. #define BENCH_CIPHER_ADD 0
  1769. #endif
  1770. /* use kB instead of mB for embedded benchmarking */
  1771. #ifdef BENCH_EMBEDDED
  1772. #ifndef BENCH_NTIMES
  1773. #define BENCH_NTIMES 2
  1774. #endif
  1775. #ifndef BENCH_AGREETIMES
  1776. #define BENCH_AGREETIMES 2
  1777. #endif
  1778. enum BenchmarkBounds {
  1779. scryptCnt = 1,
  1780. ntimes = BENCH_NTIMES,
  1781. genTimes = BENCH_MAX_PENDING,
  1782. agreeTimes = BENCH_AGREETIMES
  1783. };
  1784. /* how many kB to test (en/de)cryption */
  1785. #define NUM_BLOCKS 25
  1786. #define BENCH_SIZE (1024uL)
  1787. #else
  1788. #ifndef BENCH_NTIMES
  1789. #define BENCH_NTIMES 100
  1790. #endif
  1791. #ifndef BENCH_AGREETIMES
  1792. #define BENCH_AGREETIMES 100
  1793. #endif
  1794. enum BenchmarkBounds {
  1795. scryptCnt = 10,
  1796. ntimes = BENCH_NTIMES,
  1797. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1798. agreeTimes = BENCH_AGREETIMES
  1799. };
  1800. /* how many megs to test (en/de)cryption */
  1801. #define NUM_BLOCKS 5
  1802. #define BENCH_SIZE (1024*1024uL)
  1803. #endif
  1804. static int numBlocks = NUM_BLOCKS;
  1805. static word32 bench_size = BENCH_SIZE;
  1806. static int base2 = 1;
  1807. static int digest_stream = 1;
  1808. static int encrypt_only = 0;
  1809. #ifdef HAVE_AES_CBC
  1810. static int cipher_same_buffer = 0;
  1811. #endif
  1812. #ifdef MULTI_VALUE_STATISTICS
  1813. static int minimum_runs = 0;
  1814. #endif
  1815. #ifndef NO_RSA
  1816. /* Don't measure RSA sign/verify by default */
  1817. static int rsa_sign_verify = 0;
  1818. #endif
  1819. #ifndef NO_DH
  1820. /* Use the FFDHE parameters */
  1821. static int use_ffdhe = 0;
  1822. #endif
  1823. /* Don't print out in CSV format by default */
  1824. static int csv_format = 0;
  1825. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1826. /* Versal PLM maybe prints an error message to the same console.
  1827. * In order to not mix those outputs up, sleep a little while
  1828. * before erroring out.
  1829. */
  1830. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1831. #else
  1832. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1833. #endif
  1834. /* globals for cipher tests */
  1835. static THREAD_LS_T byte* bench_plain = NULL;
  1836. static THREAD_LS_T byte* bench_cipher = NULL;
  1837. #ifndef NO_FILESYSTEM
  1838. static THREAD_LS_T char* hash_input = NULL;
  1839. static THREAD_LS_T char* cipher_input = NULL;
  1840. #endif
  1841. static const XGEN_ALIGN byte bench_key_buf[] =
  1842. {
  1843. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1844. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1845. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1846. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1847. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1848. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1849. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1850. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1851. };
  1852. static const XGEN_ALIGN byte bench_iv_buf[] =
  1853. {
  1854. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1855. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1856. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1857. };
  1858. static THREAD_LS_T byte* bench_key = NULL;
  1859. static THREAD_LS_T byte* bench_iv = NULL;
  1860. #ifdef HAVE_RENESAS_SYNC
  1861. static THREAD_LS_T byte* bench_key1 = NULL;
  1862. static THREAD_LS_T byte* bench_key2 = NULL;
  1863. #endif
  1864. #ifdef WOLFSSL_STATIC_MEMORY
  1865. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1866. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1867. #elif defined(BENCH_EMBEDDED)
  1868. static byte gBenchMemory[50000];
  1869. #else
  1870. static byte gBenchMemory[400000];
  1871. #endif
  1872. #endif
  1873. /* This code handles cases with systems where static (non cost) ram variables
  1874. aren't properly initialized with data */
  1875. static void benchmark_static_init(int force)
  1876. {
  1877. static int gBenchStaticInit = 0;
  1878. if (gBenchStaticInit == 0 || force) {
  1879. gBenchStaticInit = 1;
  1880. /* Init static variables */
  1881. numBlocks = NUM_BLOCKS;
  1882. bench_size = BENCH_SIZE;
  1883. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1884. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1885. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1886. aes_aad_size = 0;
  1887. #endif
  1888. base2 = 1;
  1889. digest_stream = 1;
  1890. #ifdef MULTI_VALUE_STATISTICS
  1891. minimum_runs = 0;
  1892. #endif
  1893. bench_all = 1;
  1894. bench_cipher_algs = 0;
  1895. bench_digest_algs = 0;
  1896. bench_mac_algs = 0;
  1897. bench_kdf_algs = 0;
  1898. bench_asym_algs = 0;
  1899. bench_pq_asym_algs = 0;
  1900. bench_other_algs = 0;
  1901. bench_pq_hash_sig_algs = 0;
  1902. csv_format = 0;
  1903. }
  1904. }
  1905. /*****************************************************************************/
  1906. /* Begin Stats Functions */
  1907. /*****************************************************************************/
  1908. typedef enum bench_stat_type {
  1909. BENCH_STAT_ASYM,
  1910. BENCH_STAT_SYM,
  1911. BENCH_STAT_IGNORE,
  1912. } bench_stat_type_t;
  1913. #ifdef WC_BENCH_TRACK_STATS
  1914. static int gPrintStats = 0;
  1915. #ifdef WC_ENABLE_BENCH_THREADING
  1916. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1917. #endif
  1918. #ifndef BENCH_MAX_NAME_SZ
  1919. #define BENCH_MAX_NAME_SZ 24
  1920. #endif
  1921. typedef struct bench_stats {
  1922. struct bench_stats* next;
  1923. struct bench_stats* prev;
  1924. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1925. const char* desc;
  1926. double perfsec;
  1927. int strength;
  1928. int useDeviceID;
  1929. int finishCount;
  1930. bench_stat_type_t type;
  1931. int lastRet;
  1932. const char* perftype;
  1933. } bench_stats_t;
  1934. static bench_stats_t* bench_stats_head;
  1935. static bench_stats_t* bench_stats_tail;
  1936. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1937. const char* algo, int strength, const char* desc, int useDeviceID,
  1938. double perfsec, const char* perftype, int ret)
  1939. {
  1940. bench_stats_t* bstat = NULL;
  1941. #ifdef WC_ENABLE_BENCH_THREADING
  1942. /* protect bench_stats_head and bench_stats_tail access */
  1943. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  1944. #endif
  1945. if (algo != NULL) {
  1946. /* locate existing in list */
  1947. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  1948. /* match based on algo, strength and desc */
  1949. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  1950. bstat->strength == strength &&
  1951. bstat->desc == desc &&
  1952. bstat->useDeviceID == useDeviceID) {
  1953. break;
  1954. }
  1955. }
  1956. }
  1957. if (bstat == NULL) {
  1958. /* allocate new and put on list */
  1959. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  1960. DYNAMIC_TYPE_INFO);
  1961. if (bstat) {
  1962. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  1963. /* add to list */
  1964. bstat->next = NULL;
  1965. if (bench_stats_tail == NULL) {
  1966. bench_stats_head = bstat;
  1967. }
  1968. else {
  1969. bench_stats_tail->next = bstat;
  1970. bstat->prev = bench_stats_tail;
  1971. }
  1972. bench_stats_tail = bstat; /* add to the end either way */
  1973. }
  1974. }
  1975. if (bstat) {
  1976. bstat->type = type;
  1977. if (algo != NULL)
  1978. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  1979. bstat->strength = strength;
  1980. bstat->desc = desc;
  1981. bstat->useDeviceID = useDeviceID;
  1982. bstat->perfsec += perfsec;
  1983. bstat->finishCount++;
  1984. bstat->perftype = perftype;
  1985. if (bstat->lastRet > ret)
  1986. bstat->lastRet = ret; /* track last error */
  1987. }
  1988. #ifdef WC_ENABLE_BENCH_THREADING
  1989. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  1990. #endif
  1991. return bstat;
  1992. }
  1993. void bench_stats_print(void)
  1994. {
  1995. bench_stats_t* bstat;
  1996. int digits;
  1997. #ifdef WC_ENABLE_BENCH_THREADING
  1998. /* protect bench_stats_head and bench_stats_tail access */
  1999. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2000. #endif
  2001. #ifdef BENCH_MICROSECOND
  2002. digits = 5;
  2003. #else
  2004. digits = 3;
  2005. #endif
  2006. for (bstat = bench_stats_head; bstat != NULL; ) {
  2007. if (bstat->type == BENCH_STAT_SYM) {
  2008. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2009. "\n", bstat->desc,
  2010. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2011. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2012. base2 ? "MB" : "mB");
  2013. }
  2014. else {
  2015. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2016. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2017. bstat->algo, bstat->strength, bstat->desc,
  2018. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2019. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2020. }
  2021. bstat = bstat->next;
  2022. }
  2023. #ifdef WC_ENABLE_BENCH_THREADING
  2024. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2025. #endif
  2026. }
  2027. #endif /* WC_BENCH_TRACK_STATS */
  2028. static WC_INLINE void bench_stats_init(void)
  2029. {
  2030. #ifdef WC_BENCH_TRACK_STATS
  2031. bench_stats_head = NULL;
  2032. bench_stats_tail = NULL;
  2033. #endif
  2034. INIT_CYCLE_COUNTER
  2035. }
  2036. static WC_INLINE void bench_stats_start(int* count, double* start)
  2037. {
  2038. *count = 0;
  2039. *start = current_time(1);
  2040. #ifdef WOLFSSL_ESPIDF
  2041. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2042. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu, start=" FLT_FMT,
  2043. total_cycles, FLT_FMT_ARGS(*start) );
  2044. #endif
  2045. BEGIN_ESP_CYCLES
  2046. #else
  2047. BEGIN_INTEL_CYCLES
  2048. #endif
  2049. }
  2050. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2051. #define bench_stats_start(count, start) do { \
  2052. SAVE_VECTOR_REGISTERS(pr_err( \
  2053. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2054. return; ); \
  2055. bench_stats_start(count, start); \
  2056. } while (0)
  2057. #endif
  2058. static WC_INLINE int bench_stats_check(double start)
  2059. {
  2060. int ret = 0;
  2061. double this_current_time;
  2062. this_current_time = current_time(0); /* get the timestamp, no reset */
  2063. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2064. ESP_LOGV(TAG, "bench_stats_check: Current time %f, start %f",
  2065. this_current_time, start );
  2066. #endif
  2067. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2068. #ifdef BENCH_MICROSECOND
  2069. * 1000000
  2070. #endif
  2071. );
  2072. return ret;
  2073. }
  2074. /* return text for units and scale the value of blocks as needed */
  2075. static const char* get_blocktype(double* blocks)
  2076. {
  2077. const char* rt;
  2078. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2079. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2080. #undef WOLFSSL_FIXED_UNIT
  2081. #define WOLFSSL_FIXED_UNIT "GB"
  2082. *blocks /= (1024UL * 1024UL * 1024UL);
  2083. rt = "GiB";
  2084. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2085. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2086. #undef WOLFSSL_FIXED_UNIT
  2087. #define WOLFSSL_FIXED_UNIT "MB"
  2088. *blocks /= (1024UL * 1024UL);
  2089. rt = "MiB";
  2090. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2091. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2092. #undef WOLFSSL_FIXED_UNIT
  2093. #define WOLFSSL_FIXED_UNIT "KB"
  2094. *blocks /= 1024;
  2095. rt = "KiB";
  2096. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2097. #undef WOLFSSL_FIXED_UNIT
  2098. #define WOLFSSL_FIXED_UNIT "bytes"
  2099. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2100. rt = "bytes";
  2101. #else
  2102. /* If no user-specified, auto-scale each metric (results vary).
  2103. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2104. if (*blocks > (1024UL * 1024UL)) {
  2105. *blocks /= (1024UL * 1024UL);
  2106. rt = "MiB";
  2107. }
  2108. else if (*blocks > 1024) {
  2109. *blocks /= 1024;
  2110. rt = "KiB";
  2111. }
  2112. else {
  2113. rt = "bytes";
  2114. }
  2115. #endif
  2116. return rt;
  2117. }
  2118. /* return text for units and scale the value of blocks as needed for base2 */
  2119. static const char* get_blocktype_base10(double* blocks)
  2120. {
  2121. const char* rt;
  2122. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2123. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2124. *blocks /= (1000UL * 1000UL * 1000UL);
  2125. rt = "GB";
  2126. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2127. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2128. *blocks /= (1000UL * 1000UL);
  2129. rt = "MB";
  2130. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2131. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2132. *blocks /= (1000UL);
  2133. rt = "KB";
  2134. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2135. (void)(*blocks); /* no adjustment, just appease compiler */
  2136. rt = "bytes";
  2137. #else
  2138. /* If not user-specified, auto-scale each metric (results vary).
  2139. * Determine if we should show as KB or MB or bytes */
  2140. if (*blocks > (1000UL * 1000UL)) {
  2141. *blocks /= (1000UL * 1000UL);
  2142. rt = "MB";
  2143. }
  2144. else if (*blocks > 1000) {
  2145. *blocks /= 1000; /* make KB */
  2146. rt = "KB";
  2147. }
  2148. else {
  2149. rt = "bytes";
  2150. }
  2151. #endif
  2152. return rt;
  2153. }
  2154. #ifdef MULTI_VALUE_STATISTICS
  2155. static double wc_sqroot(double in)
  2156. {
  2157. /* do 32 iterations for the sqroot */
  2158. int iter = 32;
  2159. double root = in/3.0;
  2160. if (in < 0.0)
  2161. return -1;
  2162. for (int i=0; i < iter; i++)
  2163. root = (root + in / root) / 2.0;
  2164. return root;
  2165. }
  2166. static void bench_multi_value_stats(double max, double min, double sum,
  2167. double squareSum, int runs)
  2168. {
  2169. double mean = 0;
  2170. double sd = 0;
  2171. char msg[WC_BENCH_MAX_LINE_LEN];
  2172. const char** word = bench_result_words3[lng_index];
  2173. XMEMSET(msg, 0, sizeof(msg));
  2174. mean = sum / runs;
  2175. /* Calculating standard deviation */
  2176. sd = (squareSum / runs) - (mean * mean);
  2177. sd = wc_sqroot(sd);
  2178. if (csv_format == 1) {
  2179. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2180. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2181. FLT_FMT_PREC2_ARGS(3, 3, max),
  2182. FLT_FMT_PREC2_ARGS(3, 3, min),
  2183. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2184. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2185. }
  2186. else{
  2187. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2188. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2189. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2190. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2191. WOLFSSL_FIXED_TIME_UNIT "\n",
  2192. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2193. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2194. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2195. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2196. }
  2197. printf("%s", msg);
  2198. #ifndef WOLFSSL_SGX
  2199. XFFLUSH(stdout);
  2200. #endif
  2201. }
  2202. #endif
  2203. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2204. * except for AES direct that operates on AES_BLOCK_SIZE blocks */
  2205. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2206. int count, word32 countSz,
  2207. double start, int ret)
  2208. {
  2209. double total, persec = 0, blocks = (double)count;
  2210. const char* blockType;
  2211. char msg[WC_BENCH_MAX_LINE_LEN];
  2212. const char** word = bench_result_words1[lng_index];
  2213. static int sym_header_printed = 0;
  2214. XMEMSET(msg, 0, sizeof(msg));
  2215. #ifdef WOLFSSL_ESPIDF
  2216. END_ESP_CYCLES
  2217. #else
  2218. END_INTEL_CYCLES
  2219. #endif
  2220. total = current_time(0) - start;
  2221. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2222. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2223. #endif
  2224. #ifdef LINUX_RUSAGE_UTIME
  2225. check_for_excessive_stime(desc, "");
  2226. #endif
  2227. /* calculate actual bytes */
  2228. blocks *= countSz;
  2229. if (csv_format == 1) {
  2230. /* only print out header once */
  2231. if (sym_header_printed == 0) {
  2232. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2233. /* machine parseable CSV */
  2234. #ifdef HAVE_GET_CYCLES
  2235. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2236. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2237. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2238. ",cycles_total,Cycles per byte,");
  2239. #else
  2240. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2241. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2242. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2243. ",cycles_total,");
  2244. #endif
  2245. #else
  2246. /* normal CSV */
  2247. #ifdef BENCH_DEVID
  2248. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2249. #else
  2250. #define BENCH_DEVID_COLUMN_HEADER
  2251. #endif
  2252. #ifdef HAVE_GET_CYCLES
  2253. printf("\n\nSymmetric Ciphers:\n\n");
  2254. printf("Algorithm,"
  2255. BENCH_DEVID_COLUMN_HEADER
  2256. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2257. ",Cycles per byte,");
  2258. #else
  2259. printf("\n\nSymmetric Ciphers:\n\n");
  2260. printf("Algorithm,"
  2261. BENCH_DEVID_COLUMN_HEADER
  2262. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2263. #endif
  2264. #endif
  2265. #ifdef MULTI_VALUE_STATISTICS
  2266. printf("max duration,min duration,mean duration,sd,\n");
  2267. #else
  2268. printf("\n");
  2269. #endif
  2270. sym_header_printed = 1;
  2271. }
  2272. }
  2273. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2274. * note that the blockType text is assigned AND the blocks param is scaled.
  2275. */
  2276. if (base2) {
  2277. blockType = get_blocktype(&blocks);
  2278. }
  2279. else {
  2280. blockType = get_blocktype_base10(&blocks);
  2281. }
  2282. /* calculate blocks per second */
  2283. if (total > 0) {
  2284. persec = (1 / total) * blocks;
  2285. }
  2286. SLEEP_ON_ERROR(ret);
  2287. /* format and print to terminal */
  2288. if (csv_format == 1) {
  2289. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2290. #ifdef WOLFSSL_ESPIDF
  2291. unsigned long bytes_processed =
  2292. (unsigned long)count * (unsigned long)countSz;
  2293. #else
  2294. word64 bytes_processed = (word64)count * (word64)countSz;
  2295. #endif
  2296. /* note this codepath brings in all the fields from the non-CSV case. */
  2297. #ifdef WOLFSSL_ESPIDF
  2298. #ifdef HAVE_GET_CYCLES
  2299. (void)XSNPRINTF(msg, sizeof(msg),
  2300. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2301. BENCH_DEVID_GET_NAME(useDeviceID),
  2302. bytes_processed, FLT_FMT_ARGS(total),
  2303. FLT_FMT_ARGS(persec),
  2304. (long unsigned int) total_cycles);
  2305. #else
  2306. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2307. #endif
  2308. /* implement other architectures here */
  2309. #else
  2310. #ifdef HAVE_GET_CYCLES
  2311. (void)XSNPRINTF(msg, sizeof(msg),
  2312. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2313. BENCH_DEVID_GET_NAME(useDeviceID),
  2314. bytes_processed, FLT_FMT_ARGS(total),
  2315. FLT_FMT_ARGS(persec), total_cycles);
  2316. #else
  2317. (void)XSNPRINTF(msg, sizeof(msg),
  2318. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2319. BENCH_DEVID_GET_NAME(useDeviceID),
  2320. bytes_processed, FLT_FMT_ARGS(total),
  2321. FLT_FMT_ARGS(persec));
  2322. #endif
  2323. #endif
  2324. #elif defined(BENCH_DEVID)
  2325. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2326. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2327. #else
  2328. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2329. FLT_FMT_ARGS(persec));
  2330. #endif
  2331. #ifdef WOLFSSL_ESPIDF
  2332. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2333. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2334. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2335. total_cycles);
  2336. #endif
  2337. /* implement other cycle counters here */
  2338. #else
  2339. /* the default cycle counter is Intel */
  2340. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2341. #endif
  2342. } /* if (csv_format == 1) */
  2343. else {
  2344. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2345. #ifdef HAVE_GET_CYCLES
  2346. (void)XSNPRINTF(msg, sizeof(msg),
  2347. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2348. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2349. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2350. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2351. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2352. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2353. (unsigned long) total_cycles);
  2354. #else
  2355. (void)XSNPRINTF(msg, sizeof(msg),
  2356. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2357. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2358. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2359. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2360. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2361. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2362. #endif /* HAVE_GET_CYCLES */
  2363. #else
  2364. (void)XSNPRINTF(msg, sizeof(msg),
  2365. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2366. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2367. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2368. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2369. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2370. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2371. #endif
  2372. #ifdef WOLFSSL_ESPIDF
  2373. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2374. /* implement other architecture cycle counters here */
  2375. #else
  2376. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2377. #endif
  2378. } /* not CSV format */
  2379. printf("%s", msg);
  2380. /* show errors */
  2381. if (ret < 0) {
  2382. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2383. }
  2384. #ifndef WOLFSSL_SGX
  2385. XFFLUSH(stdout);
  2386. #endif
  2387. #ifdef WC_BENCH_TRACK_STATS
  2388. /* Add to thread stats */
  2389. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2390. blockType, ret);
  2391. #endif
  2392. (void)useDeviceID;
  2393. (void)ret;
  2394. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2395. RESTORE_VECTOR_REGISTERS();
  2396. #endif
  2397. TEST_SLEEP();
  2398. } /* bench_stats_sym_finish */
  2399. #ifdef BENCH_ASYM
  2400. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2401. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2402. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2403. defined(WOLFSSL_HAVE_KYBER)
  2404. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2405. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2406. double start, int ret)
  2407. {
  2408. double total, each = 0, opsSec, milliEach;
  2409. const char **word = bench_result_words2[lng_index];
  2410. #ifdef WC_BENCH_TRACK_STATS
  2411. const char* kOpsSec = "Ops/Sec";
  2412. #endif
  2413. char msg[256];
  2414. static int asym_header_printed = 0;
  2415. #ifdef BENCH_MICROSECOND
  2416. const int digits = 5;
  2417. #else
  2418. const int digits = 3;
  2419. #endif
  2420. XMEMSET(msg, 0, sizeof(msg));
  2421. total = current_time(0) - start;
  2422. #ifdef LINUX_RUSAGE_UTIME
  2423. check_for_excessive_stime(desc, desc_extra);
  2424. #endif
  2425. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2426. #ifdef WOLFSSL_ESPIDF
  2427. END_ESP_CYCLES
  2428. #else
  2429. END_INTEL_CYCLES
  2430. #endif
  2431. #endif
  2432. /* some sanity checks on the final numbers */
  2433. if (count > 0) {
  2434. each = total / count; /* per second */
  2435. }
  2436. else {
  2437. count = 0;
  2438. each = 0;
  2439. }
  2440. if (total > 0) {
  2441. opsSec = count / total; /* ops second */
  2442. }
  2443. else {
  2444. opsSec = 0;
  2445. }
  2446. #ifdef BENCH_MICROSECOND
  2447. milliEach = each / 1000; /* milliseconds */
  2448. #else
  2449. milliEach = each * 1000; /* milliseconds */
  2450. #endif
  2451. SLEEP_ON_ERROR(ret);
  2452. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2453. (void)milliEach;
  2454. /* format and print to terminal */
  2455. if (csv_format == 1) {
  2456. /* only print out header once */
  2457. if (asym_header_printed == 0) {
  2458. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2459. #ifdef HAVE_GET_CYCLES
  2460. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2461. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2462. "ecs,cycles,cycles/op,");
  2463. #else
  2464. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2465. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2466. "ecs,");
  2467. #endif
  2468. #else
  2469. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2470. printf("%sAlgorithm,key size,operation,ops/"
  2471. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2472. #endif
  2473. printf("max duration,min duration,mean duration,sd,\n");
  2474. asym_header_printed = 1;
  2475. }
  2476. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2477. #ifdef HAVE_GET_CYCLES
  2478. (void)XSNPRINTF(msg, sizeof(msg),
  2479. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2480. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2481. algo, strength, desc, desc_extra,
  2482. FLT_FMT_PREC_ARGS(digits, opsSec),
  2483. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2484. FLT_FMT_PREC_ARGS(6,
  2485. (double)total_cycles / (double)count));
  2486. #else
  2487. (void)XSNPRINTF(msg, sizeof(msg),
  2488. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2489. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2490. algo, strength, desc, desc_extra,
  2491. FLT_FMT_PREC_ARGS(digits, opsSec),
  2492. count, FLT_FMT_ARGS(total));
  2493. #endif
  2494. #else
  2495. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2496. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2497. algo, strength, desc, desc_extra,
  2498. FLT_FMT_PREC_ARGS(digits, opsSec));
  2499. #endif
  2500. } /* if (csv_format == 1) */
  2501. else {
  2502. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2503. #ifdef HAVE_GET_CYCLES
  2504. (void)XSNPRINTF(msg, sizeof(msg),
  2505. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2506. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2507. algo, strength, desc, desc_extra,
  2508. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2509. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2510. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2511. (unsigned long)total_cycles);
  2512. #else
  2513. (void)XSNPRINTF(msg, sizeof(msg),
  2514. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2515. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2516. algo, strength, desc, desc_extra,
  2517. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2518. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2519. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2520. #endif /* HAVE_GET_CYCLES */
  2521. #else
  2522. (void)XSNPRINTF(msg, sizeof(msg),
  2523. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2524. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2525. algo, strength, desc, desc_extra,
  2526. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2527. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2528. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2529. #endif
  2530. }
  2531. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2532. /* format and print to terminal */
  2533. if (csv_format == 1) {
  2534. /* only print out header once */
  2535. if (asym_header_printed == 0) {
  2536. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2537. #ifdef HAVE_GET_CYCLES
  2538. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2539. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2540. "ecs,cycles,cycles/op,");
  2541. #else
  2542. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2543. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2544. "ecs,");
  2545. #endif
  2546. #else
  2547. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2548. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2549. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2550. #endif
  2551. printf("\n");
  2552. asym_header_printed = 1;
  2553. }
  2554. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2555. #ifdef HAVE_GET_CYCLES
  2556. (void)XSNPRINTF(msg, sizeof(msg),
  2557. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2558. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2559. algo, strength, desc, desc_extra,
  2560. FLT_FMT_PREC_ARGS(3, milliEach),
  2561. FLT_FMT_PREC_ARGS(digits, opsSec),
  2562. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2563. FLT_FMT_PREC_ARGS(6,
  2564. (double)total_cycles / (double)count));
  2565. #else
  2566. (void)XSNPRINTF(msg, sizeof(msg),
  2567. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2568. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2569. algo, strength, desc, desc_extra,
  2570. FLT_FMT_PREC_ARGS(3, milliEach),
  2571. FLT_FMT_PREC_ARGS(digits, opsSec),
  2572. count, FLT_FMT_ARGS(total));
  2573. #endif
  2574. #else
  2575. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2576. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2577. algo, strength, desc, desc_extra,
  2578. FLT_FMT_PREC_ARGS(3, milliEach),
  2579. FLT_FMT_PREC_ARGS(digits, opsSec));
  2580. #endif
  2581. } /* if (csv_format == 1) */
  2582. else {
  2583. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2584. #ifdef HAVE_GET_CYCLES
  2585. (void)XSNPRINTF(msg, sizeof(msg),
  2586. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2587. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2588. STATS_CLAUSE_SEPARATOR,
  2589. algo, strength, desc, desc_extra,
  2590. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2591. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2592. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2593. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2594. (unsigned long)total_cycles);
  2595. #else
  2596. (void)XSNPRINTF(msg, sizeof(msg),
  2597. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2598. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2599. STATS_CLAUSE_SEPARATOR,
  2600. algo, strength, desc, desc_extra,
  2601. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2602. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2603. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2604. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2605. #endif /* HAVE_GET_CYCLES */
  2606. #else
  2607. (void)XSNPRINTF(msg, sizeof(msg),
  2608. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2609. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2610. STATS_CLAUSE_SEPARATOR,
  2611. algo, strength, desc, desc_extra,
  2612. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2613. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2614. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2615. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2616. #endif
  2617. }
  2618. #endif /* MULTI_VALUE_STATISTICS */
  2619. printf("%s", msg);
  2620. /* show errors */
  2621. if (ret < 0) {
  2622. printf("%sBenchmark %s %s %d failed: %d\n",
  2623. err_prefix, algo, desc, strength, ret);
  2624. }
  2625. #ifndef WOLFSSL_SGX
  2626. XFFLUSH(stdout);
  2627. #endif
  2628. #ifdef WC_BENCH_TRACK_STATS
  2629. /* Add to thread stats */
  2630. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2631. kOpsSec, ret);
  2632. #endif
  2633. (void)useDeviceID;
  2634. (void)ret;
  2635. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2636. RESTORE_VECTOR_REGISTERS();
  2637. #endif
  2638. TEST_SLEEP();
  2639. } /* bench_stats_asym_finish_ex */
  2640. static void bench_stats_asym_finish(const char* algo, int strength,
  2641. const char* desc, int useDeviceID, int count, double start, int ret)
  2642. {
  2643. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2644. start, ret);
  2645. }
  2646. #endif
  2647. #endif /* BENCH_ASYM */
  2648. static WC_INLINE void bench_stats_free(void)
  2649. {
  2650. #ifdef WC_BENCH_TRACK_STATS
  2651. bench_stats_t* bstat;
  2652. for (bstat = bench_stats_head; bstat != NULL; ) {
  2653. bench_stats_t* next = bstat->next;
  2654. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2655. bstat = next;
  2656. }
  2657. bench_stats_head = NULL;
  2658. bench_stats_tail = NULL;
  2659. #endif
  2660. }
  2661. /*****************************************************************************/
  2662. /* End Stats Functions */
  2663. /*****************************************************************************/
  2664. static void* benchmarks_do(void* args)
  2665. {
  2666. long bench_buf_size;
  2667. #ifdef WOLFSSL_ASYNC_CRYPT
  2668. #ifndef WC_NO_ASYNC_THREADING
  2669. ThreadData* threadData = (ThreadData*)args;
  2670. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2671. #else
  2672. if (wolfAsync_DevOpen(&devId) < 0)
  2673. #endif
  2674. {
  2675. printf("%sAsync device open failed\n%sRunning without async\n",
  2676. err_prefix, err_prefix);
  2677. }
  2678. #endif /* WOLFSSL_ASYNC_CRYPT */
  2679. (void)args;
  2680. #ifdef WOLFSSL_ASYNC_CRYPT
  2681. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2682. printf("%sAsync event queue init failure!\n", err_prefix);
  2683. }
  2684. #endif
  2685. #ifdef WOLF_CRYPTO_CB
  2686. #ifdef HAVE_INTEL_QA_SYNC
  2687. devId = wc_CryptoCb_InitIntelQa();
  2688. if (devId == INVALID_DEVID) {
  2689. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2690. }
  2691. #endif
  2692. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2693. devId = wc_CryptoCb_InitOcteon();
  2694. if (devId == INVALID_DEVID) {
  2695. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2696. }
  2697. #endif
  2698. #ifdef HAVE_RENESAS_SYNC
  2699. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2700. if (devId == INVALID_DEVID) {
  2701. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2702. }
  2703. #endif
  2704. #endif
  2705. #if defined(HAVE_LOCAL_RNG)
  2706. {
  2707. int rngRet;
  2708. #ifndef HAVE_FIPS
  2709. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2710. #else
  2711. rngRet = wc_InitRng(&gRng);
  2712. #endif
  2713. if (rngRet < 0) {
  2714. printf("%sInitRNG failed\n", err_prefix);
  2715. return NULL;
  2716. }
  2717. }
  2718. #endif
  2719. /* setup bench plain, cipher, key and iv globals */
  2720. /* make sure bench buffer is multiple of 16 (AES block size) */
  2721. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2722. if (bench_buf_size % 16)
  2723. bench_buf_size += 16 - (bench_buf_size % 16);
  2724. #ifdef WOLFSSL_AFALG_XILINX_AES
  2725. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2726. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2727. #else
  2728. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2729. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2730. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2731. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2732. #endif
  2733. if (bench_plain == NULL || bench_cipher == NULL) {
  2734. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2735. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2736. bench_plain = bench_cipher = NULL;
  2737. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2738. goto exit;
  2739. }
  2740. #ifndef NO_FILESYSTEM
  2741. if (hash_input) {
  2742. size_t rawSz;
  2743. XFILE file;
  2744. file = XFOPEN(hash_input, "rb");
  2745. if (file == XBADFILE)
  2746. goto exit;
  2747. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2748. XFCLOSE(file);
  2749. goto exit;
  2750. }
  2751. bench_buf_size = XFTELL(file);
  2752. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2753. XFCLOSE(file);
  2754. goto exit;
  2755. }
  2756. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2757. rawSz = (size_t)bench_buf_size;
  2758. if (bench_buf_size % 16)
  2759. bench_buf_size += 16 - (bench_buf_size % 16);
  2760. bench_size = (word32)bench_buf_size;
  2761. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2762. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2763. if (bench_plain == NULL) {
  2764. XFCLOSE(file);
  2765. goto exit;
  2766. }
  2767. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2768. != rawSz) {
  2769. XFCLOSE(file);
  2770. goto exit;
  2771. }
  2772. XFCLOSE(file);
  2773. }
  2774. else {
  2775. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2776. }
  2777. if (cipher_input) {
  2778. size_t rawSz;
  2779. XFILE file;
  2780. file = XFOPEN(cipher_input, "rb");
  2781. if (file == XBADFILE)
  2782. goto exit;
  2783. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2784. XFCLOSE(file);
  2785. goto exit;
  2786. }
  2787. bench_buf_size = XFTELL(file);
  2788. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2789. XFCLOSE(file);
  2790. goto exit;
  2791. }
  2792. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2793. rawSz = (size_t)bench_buf_size;
  2794. if (bench_buf_size % 16)
  2795. bench_buf_size += 16 - (bench_buf_size % 16);
  2796. if (bench_size > (word32)bench_buf_size)
  2797. bench_size = (word32)bench_buf_size;
  2798. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2799. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2800. if (bench_cipher == NULL) {
  2801. XFCLOSE(file);
  2802. goto exit;
  2803. }
  2804. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2805. != rawSz) {
  2806. XFCLOSE(file);
  2807. goto exit;
  2808. }
  2809. XFCLOSE(file);
  2810. }
  2811. else {
  2812. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2813. }
  2814. #endif
  2815. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2816. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2817. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2818. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2819. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2820. if (bench_key == NULL || bench_iv == NULL) {
  2821. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2822. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2823. bench_key = bench_iv = NULL;
  2824. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2825. goto exit;
  2826. }
  2827. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2828. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2829. #elif defined(HAVE_RENESAS_SYNC)
  2830. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2831. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2832. bench_key = (byte*)bench_key_buf;
  2833. bench_iv = (byte*)bench_iv_buf;
  2834. #else
  2835. bench_key = (byte*)bench_key_buf;
  2836. bench_iv = (byte*)bench_iv_buf;
  2837. #endif
  2838. #ifndef WC_NO_RNG
  2839. if (bench_all || (bench_other_algs & BENCH_RNG))
  2840. bench_rng();
  2841. #endif /* WC_NO_RNG */
  2842. #ifndef NO_AES
  2843. #ifdef HAVE_AES_CBC
  2844. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2845. #ifndef NO_SW_BENCH
  2846. bench_aescbc(0);
  2847. #endif
  2848. #if defined(BENCH_DEVID)
  2849. bench_aescbc(1);
  2850. #endif
  2851. }
  2852. #endif
  2853. #ifdef HAVE_AESGCM
  2854. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2855. #ifndef NO_SW_BENCH
  2856. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2857. #endif
  2858. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2859. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2860. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) && \
  2861. !defined(NO_HW_BENCH)
  2862. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2863. #endif
  2864. #ifndef NO_SW_BENCH
  2865. bench_gmac(0);
  2866. #endif
  2867. #if defined(BENCH_DEVID)
  2868. bench_gmac(1);
  2869. #endif
  2870. }
  2871. #endif
  2872. #ifdef HAVE_AES_ECB
  2873. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2874. #ifndef NO_SW_BENCH
  2875. bench_aesecb(0);
  2876. #endif
  2877. #ifdef BENCH_DEVID
  2878. bench_aesecb(1);
  2879. #endif
  2880. }
  2881. #endif
  2882. #ifdef WOLFSSL_AES_XTS
  2883. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2884. bench_aesxts();
  2885. #endif
  2886. #ifdef WOLFSSL_AES_CFB
  2887. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2888. bench_aescfb();
  2889. #endif
  2890. #ifdef WOLFSSL_AES_OFB
  2891. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2892. bench_aesofb();
  2893. #endif
  2894. #ifdef WOLFSSL_AES_COUNTER
  2895. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2896. bench_aesctr(0);
  2897. #ifdef BENCH_DEVID
  2898. bench_aesctr(1);
  2899. #endif
  2900. }
  2901. #endif
  2902. #ifdef HAVE_AESCCM
  2903. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2904. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2905. #ifdef BENCH_DEVID
  2906. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2907. #endif
  2908. }
  2909. #endif
  2910. #ifdef WOLFSSL_AES_SIV
  2911. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2912. bench_aessiv();
  2913. #endif
  2914. #endif /* !NO_AES */
  2915. #ifdef HAVE_CAMELLIA
  2916. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2917. bench_camellia();
  2918. #endif
  2919. #ifdef WOLFSSL_SM4_CBC
  2920. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2921. bench_sm4_cbc();
  2922. #endif
  2923. #ifdef WOLFSSL_SM4_GCM
  2924. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2925. bench_sm4_gcm();
  2926. #endif
  2927. #ifdef WOLFSSL_SM4_CCM
  2928. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2929. bench_sm4_ccm();
  2930. #endif
  2931. #ifndef NO_RC4
  2932. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2933. #ifndef NO_SW_BENCH
  2934. bench_arc4(0);
  2935. #endif
  2936. #ifdef BENCH_DEVID
  2937. bench_arc4(1);
  2938. #endif
  2939. }
  2940. #endif
  2941. #ifdef HAVE_CHACHA
  2942. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  2943. bench_chacha();
  2944. #endif
  2945. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  2946. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  2947. bench_chacha20_poly1305_aead();
  2948. #endif
  2949. #ifndef NO_DES3
  2950. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  2951. #ifndef NO_SW_BENCH
  2952. bench_des(0);
  2953. #endif
  2954. #ifdef BENCH_DEVID
  2955. bench_des(1);
  2956. #endif
  2957. }
  2958. #endif
  2959. #ifndef NO_MD5
  2960. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  2961. #ifndef NO_SW_BENCH
  2962. bench_md5(0);
  2963. #endif
  2964. #ifdef BENCH_DEVID
  2965. bench_md5(1);
  2966. #endif
  2967. }
  2968. #endif
  2969. #ifdef HAVE_POLY1305
  2970. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  2971. bench_poly1305();
  2972. #endif
  2973. #ifndef NO_SHA
  2974. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  2975. #ifndef NO_SW_BENCH
  2976. bench_sha(0);
  2977. #endif
  2978. #ifdef BENCH_DEVID
  2979. bench_sha(1);
  2980. #endif
  2981. }
  2982. #endif
  2983. #ifdef WOLFSSL_SHA224
  2984. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  2985. #ifndef NO_SW_BENCH
  2986. bench_sha224(0);
  2987. #endif
  2988. #ifdef BENCH_DEVID
  2989. bench_sha224(1);
  2990. #endif
  2991. }
  2992. #endif
  2993. #ifndef NO_SHA256
  2994. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  2995. #ifndef NO_SW_BENCH
  2996. bench_sha256(0);
  2997. #endif
  2998. #ifdef BENCH_DEVID
  2999. bench_sha256(1);
  3000. #endif
  3001. }
  3002. #endif
  3003. #ifdef WOLFSSL_SHA384
  3004. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3005. #ifndef NO_SW_BENCH
  3006. bench_sha384(0);
  3007. #endif
  3008. #ifdef BENCH_DEVID
  3009. bench_sha384(1);
  3010. #endif
  3011. }
  3012. #endif
  3013. #ifdef WOLFSSL_SHA512
  3014. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3015. #ifndef NO_SW_BENCH
  3016. bench_sha512(0);
  3017. #endif
  3018. #ifdef BENCH_DEVID
  3019. bench_sha512(1);
  3020. #endif
  3021. }
  3022. #if !defined(WOLFSSL_NOSHA512_224) && \
  3023. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3024. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3025. #ifndef NO_SW_BENCH
  3026. bench_sha512_224(0);
  3027. #endif
  3028. #ifdef BENCH_DEVID
  3029. bench_sha512_224(1);
  3030. #endif
  3031. }
  3032. #endif /* WOLFSSL_NOSHA512_224 */
  3033. #if !defined(WOLFSSL_NOSHA512_256) && \
  3034. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3035. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3036. #ifndef NO_SW_BENCH
  3037. bench_sha512_256(0);
  3038. #endif
  3039. #ifdef BENCH_DEVID
  3040. bench_sha512_256(1);
  3041. #endif
  3042. }
  3043. #endif /* WOLFSSL_NOSHA512_256 */
  3044. #endif /* WOLFSSL_SHA512 */
  3045. #ifdef WOLFSSL_SHA3
  3046. #ifndef WOLFSSL_NOSHA3_224
  3047. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3048. #ifndef NO_SW_BENCH
  3049. bench_sha3_224(0);
  3050. #endif
  3051. #ifdef BENCH_DEVID
  3052. bench_sha3_224(1);
  3053. #endif
  3054. }
  3055. #endif /* WOLFSSL_NOSHA3_224 */
  3056. #ifndef WOLFSSL_NOSHA3_256
  3057. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3058. #ifndef NO_SW_BENCH
  3059. bench_sha3_256(0);
  3060. #endif
  3061. #ifdef BENCH_DEVID
  3062. bench_sha3_256(1);
  3063. #endif
  3064. }
  3065. #endif /* WOLFSSL_NOSHA3_256 */
  3066. #ifndef WOLFSSL_NOSHA3_384
  3067. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3068. #ifndef NO_SW_BENCH
  3069. bench_sha3_384(0);
  3070. #endif
  3071. #ifdef BENCH_DEVID
  3072. bench_sha3_384(1);
  3073. #endif
  3074. }
  3075. #endif /* WOLFSSL_NOSHA3_384 */
  3076. #ifndef WOLFSSL_NOSHA3_512
  3077. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3078. #ifndef NO_SW_BENCH
  3079. bench_sha3_512(0);
  3080. #endif
  3081. #ifdef BENCH_DEVID
  3082. bench_sha3_512(1);
  3083. #endif
  3084. }
  3085. #endif /* WOLFSSL_NOSHA3_512 */
  3086. #ifdef WOLFSSL_SHAKE128
  3087. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3088. #ifndef NO_SW_BENCH
  3089. bench_shake128(0);
  3090. #endif
  3091. #ifdef BENCH_DEVID
  3092. bench_shake128(1);
  3093. #endif
  3094. }
  3095. #endif /* WOLFSSL_SHAKE128 */
  3096. #ifdef WOLFSSL_SHAKE256
  3097. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3098. #ifndef NO_SW_BENCH
  3099. bench_shake256(0);
  3100. #endif
  3101. #ifdef BENCH_DEVID
  3102. bench_shake256(1);
  3103. #endif
  3104. }
  3105. #endif /* WOLFSSL_SHAKE256 */
  3106. #endif
  3107. #ifdef WOLFSSL_SM3
  3108. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3109. #ifndef NO_SW_BENCH
  3110. bench_sm3(0);
  3111. #endif
  3112. #ifdef BENCH_DEVID
  3113. bench_sm3(1);
  3114. #endif
  3115. }
  3116. #endif
  3117. #ifdef WOLFSSL_RIPEMD
  3118. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3119. bench_ripemd();
  3120. #endif
  3121. #ifdef HAVE_BLAKE2
  3122. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3123. bench_blake2b();
  3124. #endif
  3125. #ifdef HAVE_BLAKE2S
  3126. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3127. bench_blake2s();
  3128. #endif
  3129. #ifdef WOLFSSL_CMAC
  3130. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3131. bench_cmac(0);
  3132. #ifdef BENCH_DEVID
  3133. bench_cmac(1);
  3134. #endif
  3135. }
  3136. #endif
  3137. #ifndef NO_HMAC
  3138. #ifndef NO_MD5
  3139. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3140. #ifndef NO_SW_BENCH
  3141. bench_hmac_md5(0);
  3142. #endif
  3143. #ifdef BENCH_DEVID
  3144. bench_hmac_md5(1);
  3145. #endif
  3146. }
  3147. #endif
  3148. #ifndef NO_SHA
  3149. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3150. #ifndef NO_SW_BENCH
  3151. bench_hmac_sha(0);
  3152. #endif
  3153. #ifdef BENCH_DEVID
  3154. bench_hmac_sha(1);
  3155. #endif
  3156. }
  3157. #endif
  3158. #ifdef WOLFSSL_SHA224
  3159. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3160. #ifndef NO_SW_BENCH
  3161. bench_hmac_sha224(0);
  3162. #endif
  3163. #ifdef BENCH_DEVID
  3164. bench_hmac_sha224(1);
  3165. #endif
  3166. }
  3167. #endif
  3168. #ifndef NO_SHA256
  3169. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3170. #ifndef NO_SW_BENCH
  3171. bench_hmac_sha256(0);
  3172. #endif
  3173. #ifdef BENCH_DEVID
  3174. bench_hmac_sha256(1);
  3175. #endif
  3176. }
  3177. #endif
  3178. #ifdef WOLFSSL_SHA384
  3179. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3180. #ifndef NO_SW_BENCH
  3181. bench_hmac_sha384(0);
  3182. #endif
  3183. #ifdef BENCH_DEVID
  3184. bench_hmac_sha384(1);
  3185. #endif
  3186. }
  3187. #endif
  3188. #ifdef WOLFSSL_SHA512
  3189. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3190. #ifndef NO_SW_BENCH
  3191. bench_hmac_sha512(0);
  3192. #endif
  3193. #ifdef BENCH_DEVID
  3194. bench_hmac_sha512(1);
  3195. #endif
  3196. }
  3197. #endif
  3198. #ifndef NO_PWDBASED
  3199. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3200. bench_pbkdf2();
  3201. }
  3202. #endif
  3203. #endif /* NO_HMAC */
  3204. #ifdef WOLFSSL_SIPHASH
  3205. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3206. bench_siphash();
  3207. }
  3208. #endif
  3209. #ifdef WC_SRTP_KDF
  3210. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3211. bench_srtpkdf();
  3212. }
  3213. #endif
  3214. #ifdef HAVE_SCRYPT
  3215. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3216. bench_scrypt();
  3217. #endif
  3218. #ifndef NO_RSA
  3219. #ifndef HAVE_RENESAS_SYNC
  3220. #ifdef WOLFSSL_KEY_GEN
  3221. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3222. #ifndef NO_SW_BENCH
  3223. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3224. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3225. bench_rsaKeyGen(0);
  3226. }
  3227. else {
  3228. bench_rsaKeyGen_size(0, bench_size);
  3229. }
  3230. #endif
  3231. #ifdef BENCH_DEVID
  3232. if (bench_asym_algs & BENCH_RSA_SZ) {
  3233. bench_rsaKeyGen_size(1, bench_size);
  3234. }
  3235. else {
  3236. bench_rsaKeyGen(1);
  3237. }
  3238. #endif
  3239. }
  3240. #endif
  3241. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3242. #ifndef NO_SW_BENCH
  3243. bench_rsa(0);
  3244. #endif
  3245. #ifdef BENCH_DEVID
  3246. bench_rsa(1);
  3247. #endif
  3248. }
  3249. #ifdef WOLFSSL_KEY_GEN
  3250. if (bench_asym_algs & BENCH_RSA_SZ) {
  3251. #ifndef NO_SW_BENCH
  3252. bench_rsa_key(0, bench_size);
  3253. #endif
  3254. #ifdef BENCH_DEVID
  3255. bench_rsa_key(1, bench_size);
  3256. #endif
  3257. }
  3258. #endif
  3259. #endif
  3260. #endif
  3261. #ifndef NO_DH
  3262. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3263. #ifndef NO_SW_BENCH
  3264. bench_dh(0);
  3265. #endif
  3266. #ifdef BENCH_DEVID
  3267. bench_dh(1);
  3268. #endif
  3269. }
  3270. #endif
  3271. #ifdef WOLFSSL_HAVE_KYBER
  3272. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3273. #ifdef WOLFSSL_KYBER512
  3274. if (bench_pq_asym_algs & BENCH_KYBER512) {
  3275. bench_kyber(KYBER512);
  3276. }
  3277. #endif
  3278. #ifdef WOLFSSL_KYBER768
  3279. if (bench_pq_asym_algs & BENCH_KYBER768) {
  3280. bench_kyber(KYBER768);
  3281. }
  3282. #endif
  3283. #ifdef WOLFSSL_KYBER1024
  3284. if (bench_pq_asym_algs & BENCH_KYBER1024) {
  3285. bench_kyber(KYBER1024);
  3286. }
  3287. #endif
  3288. }
  3289. #endif
  3290. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3291. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3292. bench_lms();
  3293. }
  3294. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3295. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3296. if (bench_all) {
  3297. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3298. }
  3299. #ifndef NO_SHA256
  3300. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3301. bench_xmss(WC_HASH_TYPE_SHA256);
  3302. }
  3303. #endif
  3304. #ifdef WOLFSSL_SHA512
  3305. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3306. bench_xmss(WC_HASH_TYPE_SHA512);
  3307. }
  3308. #endif
  3309. #ifdef WOLFSSL_SHAKE128
  3310. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3311. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3312. }
  3313. #endif
  3314. #ifdef WOLFSSL_SHAKE256
  3315. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3316. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3317. }
  3318. #endif
  3319. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3320. #ifdef HAVE_ECC
  3321. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3322. (bench_asym_algs & BENCH_ECC) ||
  3323. (bench_asym_algs & BENCH_ECC_ALL) ||
  3324. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3325. if (bench_asym_algs & BENCH_ECC_ALL) {
  3326. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3327. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3328. err_prefix);
  3329. #else
  3330. int curveId = (int)ECC_SECP192R1;
  3331. /* set make key and encrypt */
  3332. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3333. BENCH_ECC_ENCRYPT;
  3334. if (csv_format != 1) {
  3335. printf("\n%sECC Benchmarks:\n", info_prefix);
  3336. }
  3337. do {
  3338. #ifdef WOLFCRYPT_HAVE_SAKKE
  3339. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3340. if (curveId == ECC_SAKKE_1) {
  3341. curveId++;
  3342. continue;
  3343. }
  3344. #endif
  3345. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3346. ECC_BAD_ARG_E) {
  3347. bench_ecc_curve(curveId);
  3348. if (csv_format != 1) {
  3349. printf("\n");
  3350. }
  3351. }
  3352. curveId++;
  3353. } while (curveId != (int)ECC_CURVE_MAX);
  3354. #endif
  3355. }
  3356. else if (bench_asym_algs & BENCH_ECC_P256) {
  3357. bench_ecc_curve((int)ECC_SECP256R1);
  3358. }
  3359. else if (bench_asym_algs & BENCH_ECC_P384) {
  3360. bench_ecc_curve((int)ECC_SECP384R1);
  3361. }
  3362. else if (bench_asym_algs & BENCH_ECC_P521) {
  3363. bench_ecc_curve((int)ECC_SECP521R1);
  3364. }
  3365. else {
  3366. #ifndef NO_ECC256
  3367. bench_ecc_curve((int)ECC_SECP256R1);
  3368. #elif defined(HAVE_ECC384)
  3369. bench_ecc_curve((int)ECC_SECP384R1);
  3370. #elif defined(HAVE_ECC521)
  3371. bench_ecc_curve((int)ECC_SECP521R1);
  3372. #endif
  3373. #ifdef HAVE_ECC_BRAINPOOL
  3374. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3375. #endif
  3376. }
  3377. }
  3378. #endif
  3379. #ifdef WOLFSSL_SM2
  3380. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3381. bench_sm2(0);
  3382. }
  3383. #endif
  3384. #ifdef HAVE_CURVE25519
  3385. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3386. bench_curve25519KeyGen(0);
  3387. #ifdef BENCH_DEVID
  3388. bench_curve25519KeyGen(1);
  3389. #endif
  3390. }
  3391. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3392. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3393. bench_curve25519KeyAgree(0);
  3394. #ifdef BENCH_DEVID
  3395. bench_curve25519KeyAgree(1);
  3396. #endif
  3397. }
  3398. #endif
  3399. #endif
  3400. #ifdef HAVE_ED25519
  3401. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3402. bench_ed25519KeyGen();
  3403. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3404. bench_ed25519KeySign();
  3405. #endif
  3406. #ifdef HAVE_CURVE448
  3407. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3408. bench_curve448KeyGen();
  3409. #ifdef HAVE_CURVE448_SHARED_SECRET
  3410. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3411. bench_curve448KeyAgree();
  3412. #endif
  3413. #endif
  3414. #ifdef HAVE_ED448
  3415. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3416. bench_ed448KeyGen();
  3417. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3418. bench_ed448KeySign();
  3419. #endif
  3420. #ifdef WOLFCRYPT_HAVE_ECCSI
  3421. #ifdef WOLFCRYPT_ECCSI_KMS
  3422. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3423. bench_eccsiKeyGen();
  3424. }
  3425. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3426. bench_eccsiPairGen();
  3427. }
  3428. #endif
  3429. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3430. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3431. bench_eccsiValidate();
  3432. }
  3433. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3434. bench_eccsi();
  3435. }
  3436. #endif
  3437. #endif
  3438. #ifdef WOLFCRYPT_HAVE_SAKKE
  3439. #ifdef WOLFCRYPT_SAKKE_KMS
  3440. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3441. bench_sakkeKeyGen();
  3442. }
  3443. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3444. bench_sakkeRskGen();
  3445. }
  3446. #endif
  3447. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3448. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3449. bench_sakkeValidate();
  3450. }
  3451. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3452. bench_sakke();
  3453. }
  3454. #endif
  3455. #endif
  3456. #ifdef HAVE_FALCON
  3457. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3458. bench_falconKeySign(1);
  3459. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3460. bench_falconKeySign(5);
  3461. #endif
  3462. #ifdef HAVE_DILITHIUM
  3463. #ifndef WOLFSSL_NO_ML_DSA_44
  3464. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3465. bench_dilithiumKeySign(2);
  3466. #endif
  3467. #ifndef WOLFSSL_NO_ML_DSA_65
  3468. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3469. bench_dilithiumKeySign(3);
  3470. #endif
  3471. #ifndef WOLFSSL_NO_ML_DSA_87
  3472. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3473. bench_dilithiumKeySign(5);
  3474. #endif
  3475. #endif
  3476. #ifdef HAVE_SPHINCS
  3477. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3478. bench_sphincsKeySign(1, FAST_VARIANT);
  3479. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3480. bench_sphincsKeySign(3, FAST_VARIANT);
  3481. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3482. bench_sphincsKeySign(5, FAST_VARIANT);
  3483. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3484. bench_sphincsKeySign(1, SMALL_VARIANT);
  3485. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3486. bench_sphincsKeySign(3, SMALL_VARIANT);
  3487. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3488. bench_sphincsKeySign(5, SMALL_VARIANT);
  3489. #endif
  3490. exit:
  3491. /* free benchmark buffers */
  3492. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3493. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3494. #ifdef WOLFSSL_ASYNC_CRYPT
  3495. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3496. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3497. #endif
  3498. #if defined(HAVE_LOCAL_RNG)
  3499. wc_FreeRng(&gRng);
  3500. #endif
  3501. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3502. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3503. wc_ecc_fp_free();
  3504. #endif
  3505. (void)bench_cipher_algs;
  3506. (void)bench_digest_algs;
  3507. (void)bench_mac_algs;
  3508. (void)bench_asym_algs;
  3509. (void)bench_other_algs;
  3510. (void)bench_pq_asym_algs;
  3511. (void)bench_pq_asym_algs2;
  3512. return NULL;
  3513. }
  3514. int benchmark_init(void)
  3515. {
  3516. int ret = 0;
  3517. benchmark_static_init(0);
  3518. #ifdef WOLFSSL_STATIC_MEMORY
  3519. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3520. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3521. if (ret != 0) {
  3522. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3523. }
  3524. #endif /* WOLFSSL_STATIC_MEMORY */
  3525. if ((ret = wolfCrypt_Init()) != 0) {
  3526. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3527. return EXIT_FAILURE;
  3528. }
  3529. #ifdef HAVE_WC_INTROSPECTION
  3530. printf("Math: %s\n", wc_GetMathInfo());
  3531. #endif
  3532. #ifdef WOLFSSL_SECO_CAAM
  3533. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3534. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3535. != 0) {
  3536. printf("%sunable to open HSM\n", err_prefix);
  3537. wolfCrypt_Cleanup();
  3538. return EXIT_FAILURE;
  3539. }
  3540. #endif
  3541. #ifdef WC_RNG_SEED_CB
  3542. wc_SetSeed_Cb(wc_GenerateSeed);
  3543. #endif
  3544. bench_stats_init();
  3545. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3546. wolfSSL_Debugging_ON();
  3547. #endif
  3548. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3549. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3550. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3551. if (csv_format == 1) {
  3552. printf("This format allows you to easily copy "
  3553. "the output to a csv file.");
  3554. }
  3555. #endif
  3556. #ifdef HAVE_WNR
  3557. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3558. if (ret != 0) {
  3559. printf("%sWhitewood netRandom config init failed %d\n",
  3560. err_prefix, ret);
  3561. }
  3562. #endif /* HAVE_WNR */
  3563. return ret;
  3564. }
  3565. int benchmark_free(void)
  3566. {
  3567. int ret;
  3568. #ifdef WC_BENCH_TRACK_STATS
  3569. if (gPrintStats || devId != INVALID_DEVID) {
  3570. bench_stats_print();
  3571. }
  3572. #endif
  3573. bench_stats_free();
  3574. #ifdef WOLF_CRYPTO_CB
  3575. #ifdef HAVE_INTEL_QA_SYNC
  3576. wc_CryptoCb_CleanupIntelQa(&devId);
  3577. #endif
  3578. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3579. wc_CryptoCb_CleanupOcteon(&devId);
  3580. #endif
  3581. #ifdef HAVE_RENESAS_SYNC
  3582. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3583. #endif
  3584. #endif
  3585. #ifdef WOLFSSL_ASYNC_CRYPT
  3586. /* free event queue */
  3587. wolfEventQueue_Free(&eventQueue);
  3588. /* close device */
  3589. wolfAsync_DevClose(&devId);
  3590. #endif
  3591. #ifdef HAVE_WNR
  3592. ret = wc_FreeNetRandom();
  3593. if (ret < 0) {
  3594. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3595. }
  3596. #endif
  3597. #ifdef WOLFSSL_SECO_CAAM
  3598. if (wc_SECO_CloseHSM() != 0) {
  3599. printf("%sError closing down the key store\n", err_prefix);
  3600. }
  3601. #endif
  3602. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3603. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3604. }
  3605. return ret;
  3606. }
  3607. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3608. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3609. {
  3610. benchmark_test(args);
  3611. EXIT_TEST(0);
  3612. }
  3613. static int benchmark_test_threaded(void* args)
  3614. {
  3615. int i;
  3616. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3617. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3618. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3619. if (g_threadData == NULL) {
  3620. printf("%sThread data alloc failed!\n", err_prefix);
  3621. return EXIT_FAILURE;
  3622. }
  3623. for (i = 0; i < g_threadCount; i++) {
  3624. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3625. NULL, run_bench, args));
  3626. }
  3627. for (i = 0; i < g_threadCount; i++) {
  3628. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3629. }
  3630. printf("\n");
  3631. bench_stats_print();
  3632. return 0;
  3633. }
  3634. #endif
  3635. /* so embedded projects can pull in tests on their own */
  3636. #ifdef HAVE_STACK_SIZE
  3637. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3638. #else
  3639. int benchmark_test(void *args)
  3640. #endif
  3641. {
  3642. int ret;
  3643. (void)args;
  3644. #ifdef HAVE_FIPS
  3645. wolfCrypt_SetCb_fips(myFipsCb);
  3646. #endif
  3647. ret = benchmark_init();
  3648. if (ret != 0)
  3649. EXIT_TEST(ret);
  3650. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3651. {
  3652. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3653. **
  3654. ** Chapter Two, Build Options:
  3655. **
  3656. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3657. **
  3658. ** asynchronous cryptography using hardware based adapters such as
  3659. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3660. */
  3661. int i;
  3662. if (g_threadCount == 0) {
  3663. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3664. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3665. #else
  3666. g_threadCount = wc_AsyncGetNumberOfCpus();
  3667. if (g_threadCount > 0) {
  3668. g_threadCount /= 2; /* use physical core count */
  3669. }
  3670. #endif
  3671. }
  3672. if (g_threadCount <= 0) {
  3673. g_threadCount = 1;
  3674. }
  3675. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3676. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3677. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3678. if (g_threadData == NULL) {
  3679. printf("%sThread data alloc failed!\n", err_prefix);
  3680. EXIT_TEST(EXIT_FAILURE);
  3681. }
  3682. /* Create threads */
  3683. for (i = 0; i < g_threadCount; i++) {
  3684. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3685. benchmarks_do, &g_threadData[i]);
  3686. if (ret != 0) {
  3687. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3688. EXIT_TEST(EXIT_FAILURE);
  3689. }
  3690. }
  3691. /* Start threads */
  3692. for (i = 0; i < g_threadCount; i++) {
  3693. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3694. }
  3695. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3696. }
  3697. #else
  3698. benchmarks_do(NULL);
  3699. #endif
  3700. SLEEP_ON_ERROR(1);
  3701. printf("%sBenchmark complete\n", info_prefix);
  3702. ret = benchmark_free();
  3703. EXIT_TEST(ret);
  3704. }
  3705. #ifndef WC_NO_RNG
  3706. void bench_rng(void)
  3707. {
  3708. int ret, i, count;
  3709. double start;
  3710. long pos, len, remain;
  3711. WC_RNG myrng;
  3712. DECLARE_MULTI_VALUE_STATS_VARS()
  3713. #ifndef HAVE_FIPS
  3714. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3715. #else
  3716. ret = wc_InitRng(&myrng);
  3717. #endif
  3718. if (ret < 0) {
  3719. printf("InitRNG failed %d\n", ret);
  3720. return;
  3721. }
  3722. bench_stats_start(&count, &start);
  3723. do {
  3724. for (i = 0; i < numBlocks; i++) {
  3725. /* Split request to handle large RNG request */
  3726. pos = 0;
  3727. remain = (int)bench_size;
  3728. while (remain > 0) {
  3729. len = remain;
  3730. if (len > RNG_MAX_BLOCK_LEN)
  3731. len = RNG_MAX_BLOCK_LEN;
  3732. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3733. (word32)len);
  3734. if (ret < 0)
  3735. goto exit_rng;
  3736. remain -= len;
  3737. pos += len;
  3738. }
  3739. RECORD_MULTI_VALUE_STATS();
  3740. }
  3741. count += i;
  3742. } while (bench_stats_check(start)
  3743. #ifdef MULTI_VALUE_STATISTICS
  3744. || runs < minimum_runs
  3745. #endif
  3746. );
  3747. exit_rng:
  3748. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3749. #ifdef MULTI_VALUE_STATISTICS
  3750. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3751. #endif
  3752. wc_FreeRng(&myrng);
  3753. }
  3754. #endif /* WC_NO_RNG */
  3755. #ifndef NO_AES
  3756. #ifdef HAVE_AES_CBC
  3757. static void bench_aescbc_internal(int useDeviceID,
  3758. const byte* key, word32 keySz,
  3759. const byte* iv, const char* encLabel,
  3760. const char* decLabel)
  3761. {
  3762. const byte* in = bench_cipher;
  3763. byte* out = bench_plain;
  3764. int ret = 0, i, count = 0, times, pending = 0;
  3765. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3766. sizeof(Aes), HEAP_HINT);
  3767. double start;
  3768. DECLARE_MULTI_VALUE_STATS_VARS()
  3769. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3770. sizeof(Aes), HEAP_HINT);
  3771. /* init keys */
  3772. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3773. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3774. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3775. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3776. goto exit;
  3777. }
  3778. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3779. if (ret != 0) {
  3780. printf("AesSetKey failed, ret = %d\n", ret);
  3781. goto exit;
  3782. }
  3783. }
  3784. if (cipher_same_buffer) {
  3785. in = bench_plain;
  3786. }
  3787. bench_stats_start(&count, &start);
  3788. do {
  3789. for (times = 0; times < numBlocks || pending > 0; ) {
  3790. bench_async_poll(&pending);
  3791. /* while free pending slots in queue, submit ops */
  3792. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3793. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3794. &times, numBlocks, &pending)) {
  3795. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3796. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3797. 0, &times, &pending)) {
  3798. goto exit_aes_enc;
  3799. }
  3800. }
  3801. } /* for i */
  3802. RECORD_MULTI_VALUE_STATS();
  3803. } /* for times */
  3804. count += times;
  3805. } while (bench_stats_check(start)
  3806. #ifdef MULTI_VALUE_STATISTICS
  3807. || runs < minimum_runs
  3808. #endif
  3809. );
  3810. exit_aes_enc:
  3811. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3812. bench_size, start, ret);
  3813. #ifdef MULTI_VALUE_STATISTICS
  3814. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3815. #endif
  3816. if (ret < 0) {
  3817. goto exit;
  3818. }
  3819. #ifdef HAVE_AES_DECRYPT
  3820. /* init keys */
  3821. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3822. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3823. if (ret != 0) {
  3824. printf("AesSetKey failed, ret = %d\n", ret);
  3825. goto exit;
  3826. }
  3827. }
  3828. RESET_MULTI_VALUE_STATS_VARS();
  3829. bench_stats_start(&count, &start);
  3830. do {
  3831. for (times = 0; times < numBlocks || pending > 0; ) {
  3832. bench_async_poll(&pending);
  3833. /* while free pending slots in queue, submit ops */
  3834. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3835. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3836. &times, numBlocks, &pending)) {
  3837. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3838. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3839. 0, &times, &pending)) {
  3840. goto exit_aes_dec;
  3841. }
  3842. }
  3843. } /* for i */
  3844. RECORD_MULTI_VALUE_STATS();
  3845. } /* for times */
  3846. count += times;
  3847. } while (bench_stats_check(start)
  3848. #ifdef MULTI_VALUE_STATISTICS
  3849. || runs < minimum_runs
  3850. #endif
  3851. );
  3852. exit_aes_dec:
  3853. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3854. start, ret);
  3855. #ifdef MULTI_VALUE_STATISTICS
  3856. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3857. #endif
  3858. #endif /* HAVE_AES_DECRYPT */
  3859. (void)decLabel;
  3860. exit:
  3861. if (WC_ARRAY_OK(enc)) {
  3862. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3863. wc_AesFree(enc[i]);
  3864. }
  3865. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3866. }
  3867. }
  3868. void bench_aescbc(int useDeviceID)
  3869. {
  3870. #ifdef WOLFSSL_AES_128
  3871. #ifdef HAVE_RENESAS_SYNC
  3872. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3873. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3874. #else
  3875. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3876. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3877. #endif
  3878. #endif
  3879. #ifdef WOLFSSL_AES_192
  3880. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3881. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3882. #endif
  3883. #ifdef WOLFSSL_AES_256
  3884. #ifdef HAVE_RENESAS_SYNC
  3885. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3886. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3887. #else
  3888. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3889. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3890. #endif
  3891. #endif
  3892. }
  3893. #endif /* HAVE_AES_CBC */
  3894. #ifdef HAVE_AESGCM
  3895. static void bench_aesgcm_internal(int useDeviceID,
  3896. const byte* key, word32 keySz,
  3897. const byte* iv, word32 ivSz,
  3898. const char* encLabel, const char* decLabel)
  3899. {
  3900. int ret = 0, i, count = 0, times, pending = 0;
  3901. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3902. sizeof(Aes), HEAP_HINT);
  3903. #ifdef HAVE_AES_DECRYPT
  3904. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3905. sizeof(Aes), HEAP_HINT);
  3906. #endif
  3907. double start;
  3908. DECLARE_MULTI_VALUE_STATS_VARS()
  3909. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3910. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3911. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3912. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3913. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3914. sizeof(Aes), HEAP_HINT);
  3915. #ifdef HAVE_AES_DECRYPT
  3916. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3917. sizeof(Aes), HEAP_HINT);
  3918. #endif
  3919. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3920. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3921. /* init keys */
  3922. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3923. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3924. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3925. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3926. goto exit;
  3927. }
  3928. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  3929. if (ret != 0) {
  3930. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3931. goto exit;
  3932. }
  3933. }
  3934. /* GCM uses same routine in backend for both encrypt and decrypt */
  3935. bench_stats_start(&count, &start);
  3936. do {
  3937. for (times = 0; times < numBlocks || pending > 0; ) {
  3938. bench_async_poll(&pending);
  3939. /* while free pending slots in queue, submit ops */
  3940. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3941. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3942. &times, numBlocks, &pending)) {
  3943. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  3944. bench_plain, bench_size,
  3945. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  3946. bench_additional, aesAuthAddSz);
  3947. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3948. 0, &times, &pending)) {
  3949. goto exit_aes_gcm;
  3950. }
  3951. }
  3952. } /* for i */
  3953. RECORD_MULTI_VALUE_STATS();
  3954. } /* for times */
  3955. count += times;
  3956. } while (bench_stats_check(start)
  3957. #ifdef MULTI_VALUE_STATISTICS
  3958. || runs < minimum_runs
  3959. #endif
  3960. );
  3961. exit_aes_gcm:
  3962. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  3963. start, ret);
  3964. #ifdef MULTI_VALUE_STATISTICS
  3965. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3966. #endif
  3967. #ifdef HAVE_AES_DECRYPT
  3968. RESET_MULTI_VALUE_STATS_VARS();
  3969. /* init keys */
  3970. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3971. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  3972. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3973. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3974. goto exit;
  3975. }
  3976. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  3977. if (ret != 0) {
  3978. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3979. goto exit;
  3980. }
  3981. }
  3982. bench_stats_start(&count, &start);
  3983. do {
  3984. for (times = 0; times < numBlocks || pending > 0; ) {
  3985. bench_async_poll(&pending);
  3986. /* while free pending slots in queue, submit ops */
  3987. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3988. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  3989. &times, numBlocks, &pending)) {
  3990. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  3991. bench_cipher, bench_size,
  3992. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  3993. bench_additional, aesAuthAddSz);
  3994. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  3995. 0, &times, &pending)) {
  3996. goto exit_aes_gcm_dec;
  3997. }
  3998. }
  3999. } /* for i */
  4000. RECORD_MULTI_VALUE_STATS();
  4001. } /* for times */
  4002. count += times;
  4003. } while (bench_stats_check(start)
  4004. #ifdef MULTI_VALUE_STATISTICS
  4005. || runs < minimum_runs
  4006. #endif
  4007. );
  4008. exit_aes_gcm_dec:
  4009. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4010. start, ret);
  4011. #ifdef MULTI_VALUE_STATISTICS
  4012. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4013. #endif
  4014. #endif /* HAVE_AES_DECRYPT */
  4015. (void)decLabel;
  4016. exit:
  4017. if (ret < 0) {
  4018. printf("bench_aesgcm failed: %d\n", ret);
  4019. }
  4020. #ifdef HAVE_AES_DECRYPT
  4021. if (WC_ARRAY_OK(dec)) {
  4022. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4023. wc_AesFree(dec[i]);
  4024. }
  4025. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4026. }
  4027. #endif
  4028. if (WC_ARRAY_OK(enc)) {
  4029. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4030. wc_AesFree(enc[i]);
  4031. }
  4032. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4033. }
  4034. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4035. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4036. }
  4037. #ifdef WOLFSSL_AESGCM_STREAM
  4038. static void bench_aesgcm_stream_internal(int useDeviceID,
  4039. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4040. const char* encLabel, const char* decLabel)
  4041. {
  4042. int ret = 0, i, count = 0, times, pending = 0;
  4043. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4044. sizeof(Aes), HEAP_HINT);
  4045. #ifdef HAVE_AES_DECRYPT
  4046. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4047. sizeof(Aes), HEAP_HINT);
  4048. #endif
  4049. double start;
  4050. DECLARE_MULTI_VALUE_STATS_VARS()
  4051. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4052. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4053. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4054. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4055. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4056. sizeof(Aes), HEAP_HINT);
  4057. #ifdef HAVE_AES_DECRYPT
  4058. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4059. sizeof(Aes), HEAP_HINT);
  4060. #endif
  4061. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4062. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4063. /* init keys */
  4064. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4065. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4066. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4067. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4068. goto exit;
  4069. }
  4070. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4071. if (ret != 0) {
  4072. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4073. goto exit;
  4074. }
  4075. }
  4076. /* GCM uses same routine in backend for both encrypt and decrypt */
  4077. bench_stats_start(&count, &start);
  4078. do {
  4079. for (times = 0; times < numBlocks || pending > 0; ) {
  4080. bench_async_poll(&pending);
  4081. /* while free pending slots in queue, submit ops */
  4082. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4083. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4084. &times, numBlocks, &pending)) {
  4085. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4086. if (ret == 0) {
  4087. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4088. bench_plain, bench_size, bench_additional,
  4089. aesAuthAddSz);
  4090. }
  4091. if (ret == 0) {
  4092. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4093. AES_AUTH_TAG_SZ);
  4094. }
  4095. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4096. 0, &times, &pending)) {
  4097. goto exit_aes_gcm;
  4098. }
  4099. }
  4100. } /* for i */
  4101. RECORD_MULTI_VALUE_STATS();
  4102. } /* for times */
  4103. count += times;
  4104. } while (bench_stats_check(start)
  4105. #ifdef MULTI_VALUE_STATISTICS
  4106. || runs < minimum_runs
  4107. #endif
  4108. );
  4109. exit_aes_gcm:
  4110. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4111. start, ret);
  4112. #ifdef MULTI_VALUE_STATISTICS
  4113. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4114. #endif
  4115. #ifdef HAVE_AES_DECRYPT
  4116. /* init keys */
  4117. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4118. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4119. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4120. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4121. goto exit;
  4122. }
  4123. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4124. if (ret != 0) {
  4125. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4126. goto exit;
  4127. }
  4128. }
  4129. RESET_MULTI_VALUE_STATS_VARS();
  4130. bench_stats_start(&count, &start);
  4131. do {
  4132. for (times = 0; times < numBlocks || pending > 0; ) {
  4133. bench_async_poll(&pending);
  4134. /* while free pending slots in queue, submit ops */
  4135. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4136. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4137. &times, numBlocks, &pending)) {
  4138. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4139. if (ret == 0) {
  4140. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4141. bench_cipher, bench_size, bench_additional,
  4142. aesAuthAddSz);
  4143. }
  4144. if (ret == 0) {
  4145. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4146. AES_AUTH_TAG_SZ);
  4147. }
  4148. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4149. 0, &times, &pending)) {
  4150. goto exit_aes_gcm_dec;
  4151. }
  4152. }
  4153. } /* for i */
  4154. RECORD_MULTI_VALUE_STATS();
  4155. } /* for times */
  4156. count += times;
  4157. } while (bench_stats_check(start)
  4158. #ifdef MULTI_VALUE_STATISTICS
  4159. || runs < minimum_runs
  4160. #endif
  4161. );
  4162. exit_aes_gcm_dec:
  4163. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4164. start, ret);
  4165. #ifdef MULTI_VALUE_STATISTICS
  4166. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4167. #endif
  4168. #endif /* HAVE_AES_DECRYPT */
  4169. (void)decLabel;
  4170. exit:
  4171. if (ret < 0) {
  4172. printf("bench_aesgcm failed: %d\n", ret);
  4173. }
  4174. #ifdef HAVE_AES_DECRYPT
  4175. if (WC_ARRAY_OK(dec)) {
  4176. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4177. wc_AesFree(dec[i]);
  4178. }
  4179. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4180. }
  4181. #endif
  4182. if (WC_ARRAY_OK(enc)) {
  4183. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4184. wc_AesFree(enc[i]);
  4185. }
  4186. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4187. }
  4188. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4189. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4190. }
  4191. #endif
  4192. void bench_aesgcm(int useDeviceID)
  4193. {
  4194. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4195. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4196. && !defined(WOLFSSL_XILINX_CRYPT) \
  4197. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4198. #ifdef HAVE_RENESAS_SYNC
  4199. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4200. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4201. #else
  4202. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4203. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4204. #endif
  4205. #endif
  4206. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4207. && !defined(WOLFSSL_XILINX_CRYPT)
  4208. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4209. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4210. #endif
  4211. #ifdef WOLFSSL_AES_256
  4212. #ifdef HAVE_RENESAS_SYNC
  4213. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4214. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4215. #else
  4216. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4217. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4218. #endif
  4219. #endif
  4220. #ifdef WOLFSSL_AESGCM_STREAM
  4221. #undef AES_GCM_STRING
  4222. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4223. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4224. && !defined(WOLFSSL_XILINX_CRYPT) \
  4225. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4226. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4227. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4228. #endif
  4229. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4230. && !defined(WOLFSSL_XILINX_CRYPT)
  4231. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4232. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4233. #endif
  4234. #ifdef WOLFSSL_AES_256
  4235. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4236. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4237. #endif
  4238. #endif /* WOLFSSL_AESGCM_STREAM */
  4239. #undef AES_GCM_STRING
  4240. }
  4241. /* GMAC */
  4242. void bench_gmac(int useDeviceID)
  4243. {
  4244. int ret, count = 0;
  4245. Gmac gmac;
  4246. double start;
  4247. byte tag[AES_AUTH_TAG_SZ];
  4248. DECLARE_MULTI_VALUE_STATS_VARS()
  4249. /* determine GCM GHASH method */
  4250. #ifdef GCM_SMALL
  4251. const char* gmacStr = "GMAC Small";
  4252. #elif defined(GCM_TABLE)
  4253. const char* gmacStr = "GMAC Table";
  4254. #elif defined(GCM_TABLE_4BIT)
  4255. const char* gmacStr = "GMAC Table 4-bit";
  4256. #elif defined(GCM_WORD32)
  4257. const char* gmacStr = "GMAC Word32";
  4258. #else
  4259. const char* gmacStr = "GMAC Default";
  4260. #endif
  4261. /* init keys */
  4262. XMEMSET(bench_plain, 0, bench_size);
  4263. XMEMSET(tag, 0, sizeof(tag));
  4264. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4265. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4266. useDeviceID ? devId: INVALID_DEVID);
  4267. #ifdef HAVE_RENESAS_SYNC
  4268. wc_GmacSetKey(&gmac, bench_key1, 16);
  4269. #else
  4270. wc_GmacSetKey(&gmac, bench_key, 16);
  4271. #endif
  4272. bench_stats_start(&count, &start);
  4273. do {
  4274. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4275. tag, sizeof(tag));
  4276. count++;
  4277. RECORD_MULTI_VALUE_STATS();
  4278. } while (bench_stats_check(start)
  4279. #ifdef MULTI_VALUE_STATISTICS
  4280. || runs < minimum_runs
  4281. #endif
  4282. );
  4283. wc_AesFree((Aes*)&gmac);
  4284. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4285. #ifdef MULTI_VALUE_STATISTICS
  4286. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4287. #endif
  4288. }
  4289. #endif /* HAVE_AESGCM */
  4290. #ifdef HAVE_AES_ECB
  4291. static void bench_aesecb_internal(int useDeviceID,
  4292. const byte* key, word32 keySz,
  4293. const char* encLabel, const char* decLabel)
  4294. {
  4295. int ret = 0, i, count = 0, times, pending = 0;
  4296. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4297. sizeof(Aes), HEAP_HINT);
  4298. double start;
  4299. DECLARE_MULTI_VALUE_STATS_VARS()
  4300. #ifdef HAVE_FIPS
  4301. const word32 benchSz = AES_BLOCK_SIZE;
  4302. #else
  4303. const word32 benchSz = bench_size;
  4304. #endif
  4305. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4306. sizeof(Aes), HEAP_HINT);
  4307. /* init keys */
  4308. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4309. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4310. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4311. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4312. goto exit;
  4313. }
  4314. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4315. if (ret != 0) {
  4316. printf("AesSetKey failed, ret = %d\n", ret);
  4317. goto exit;
  4318. }
  4319. }
  4320. bench_stats_start(&count, &start);
  4321. do {
  4322. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4323. for (times = 0;
  4324. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4325. ) {
  4326. bench_async_poll(&pending);
  4327. /* while free pending slots in queue, submit ops */
  4328. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4329. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4330. &times, outer_loop_limit, &pending)) {
  4331. #ifdef HAVE_FIPS
  4332. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4333. #else
  4334. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4335. benchSz);
  4336. #endif
  4337. ret = 0;
  4338. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4339. 0, &times, &pending)) {
  4340. goto exit_aes_enc;
  4341. }
  4342. }
  4343. } /* for i */
  4344. RECORD_MULTI_VALUE_STATS();
  4345. } /* for times */
  4346. count += times;
  4347. } while (bench_stats_check(start)
  4348. #ifdef MULTI_VALUE_STATISTICS
  4349. || runs < minimum_runs
  4350. #endif
  4351. );
  4352. exit_aes_enc:
  4353. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4354. start, ret);
  4355. #ifdef MULTI_VALUE_STATISTICS
  4356. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4357. #endif
  4358. #ifdef HAVE_AES_DECRYPT
  4359. /* init keys */
  4360. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4361. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4362. if (ret != 0) {
  4363. printf("AesSetKey failed, ret = %d\n", ret);
  4364. goto exit;
  4365. }
  4366. }
  4367. RESET_MULTI_VALUE_STATS_VARS();
  4368. bench_stats_start(&count, &start);
  4369. do {
  4370. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4371. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4372. bench_async_poll(&pending);
  4373. /* while free pending slots in queue, submit ops */
  4374. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4375. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4376. &times, outer_loop_limit, &pending)) {
  4377. #ifdef HAVE_FIPS
  4378. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4379. #else
  4380. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4381. benchSz);
  4382. #endif
  4383. ret = 0;
  4384. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4385. 0, &times, &pending)) {
  4386. goto exit_aes_dec;
  4387. }
  4388. }
  4389. } /* for i */
  4390. RECORD_MULTI_VALUE_STATS();
  4391. } /* for times */
  4392. count += times;
  4393. } while (bench_stats_check(start)
  4394. #ifdef MULTI_VALUE_STATISTICS
  4395. || runs < minimum_runs
  4396. #endif
  4397. );
  4398. exit_aes_dec:
  4399. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4400. start, ret);
  4401. #ifdef MULTI_VALUE_STATISTICS
  4402. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4403. #endif
  4404. #endif /* HAVE_AES_DECRYPT */
  4405. (void)decLabel;
  4406. exit:
  4407. if (WC_ARRAY_OK(enc)) {
  4408. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4409. wc_AesFree(enc[i]);
  4410. }
  4411. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4412. }
  4413. }
  4414. void bench_aesecb(int useDeviceID)
  4415. {
  4416. #ifdef WOLFSSL_AES_128
  4417. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4418. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4419. #endif
  4420. #ifdef WOLFSSL_AES_192
  4421. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4422. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4423. #endif
  4424. #ifdef WOLFSSL_AES_256
  4425. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4426. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4427. #endif
  4428. }
  4429. #endif /* HAVE_AES_ECB */
  4430. #ifdef WOLFSSL_AES_CFB
  4431. static void bench_aescfb_internal(const byte* key,
  4432. word32 keySz, const byte* iv,
  4433. const char* label)
  4434. {
  4435. Aes enc;
  4436. double start;
  4437. int i, ret, count;
  4438. DECLARE_MULTI_VALUE_STATS_VARS()
  4439. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4440. if (ret != 0) {
  4441. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4442. return;
  4443. }
  4444. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4445. if (ret != 0) {
  4446. printf("AesSetKey failed, ret = %d\n", ret);
  4447. goto out;
  4448. }
  4449. bench_stats_start(&count, &start);
  4450. do {
  4451. for (i = 0; i < numBlocks; i++) {
  4452. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4453. bench_size)) != 0) {
  4454. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4455. goto out;
  4456. }
  4457. RECORD_MULTI_VALUE_STATS();
  4458. }
  4459. count += i;
  4460. } while (bench_stats_check(start)
  4461. #ifdef MULTI_VALUE_STATISTICS
  4462. || runs < minimum_runs
  4463. #endif
  4464. );
  4465. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4466. #ifdef MULTI_VALUE_STATISTICS
  4467. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4468. #endif
  4469. out:
  4470. wc_AesFree(&enc);
  4471. return;
  4472. }
  4473. void bench_aescfb(void)
  4474. {
  4475. #ifdef WOLFSSL_AES_128
  4476. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4477. #endif
  4478. #ifdef WOLFSSL_AES_192
  4479. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4480. #endif
  4481. #ifdef WOLFSSL_AES_256
  4482. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4483. #endif
  4484. }
  4485. #endif /* WOLFSSL_AES_CFB */
  4486. #ifdef WOLFSSL_AES_OFB
  4487. static void bench_aesofb_internal(const byte* key,
  4488. word32 keySz, const byte* iv,
  4489. const char* label)
  4490. {
  4491. Aes enc;
  4492. double start;
  4493. int i, ret, count;
  4494. DECLARE_MULTI_VALUE_STATS_VARS()
  4495. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4496. if (ret != 0) {
  4497. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4498. return;
  4499. }
  4500. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4501. if (ret != 0) {
  4502. printf("AesSetKey failed, ret = %d\n", ret);
  4503. return;
  4504. }
  4505. bench_stats_start(&count, &start);
  4506. do {
  4507. for (i = 0; i < numBlocks; i++) {
  4508. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4509. bench_size)) != 0) {
  4510. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4511. return;
  4512. }
  4513. RECORD_MULTI_VALUE_STATS();
  4514. }
  4515. count += i;
  4516. } while (bench_stats_check(start)
  4517. #ifdef MULTI_VALUE_STATISTICS
  4518. || runs < minimum_runs
  4519. #endif
  4520. );
  4521. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4522. #ifdef MULTI_VALUE_STATISTICS
  4523. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4524. #endif
  4525. wc_AesFree(&enc);
  4526. }
  4527. void bench_aesofb(void)
  4528. {
  4529. #ifdef WOLFSSL_AES_128
  4530. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4531. #endif
  4532. #ifdef WOLFSSL_AES_192
  4533. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4534. #endif
  4535. #ifdef WOLFSSL_AES_256
  4536. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4537. #endif
  4538. }
  4539. #endif /* WOLFSSL_AES_CFB */
  4540. #ifdef WOLFSSL_AES_XTS
  4541. void bench_aesxts(void)
  4542. {
  4543. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4544. double start;
  4545. int i, count, ret;
  4546. DECLARE_MULTI_VALUE_STATS_VARS()
  4547. static const unsigned char k1[] = {
  4548. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4549. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4550. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4551. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4552. };
  4553. static const unsigned char i1[] = {
  4554. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4555. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4556. };
  4557. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4558. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4559. HEAP_HINT, devId);
  4560. if (ret != 0) {
  4561. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4562. goto exit;
  4563. }
  4564. bench_stats_start(&count, &start);
  4565. do {
  4566. for (i = 0; i < numBlocks; i++) {
  4567. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4568. bench_size, i1, sizeof(i1))) != 0) {
  4569. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4570. goto exit;
  4571. }
  4572. RECORD_MULTI_VALUE_STATS();
  4573. }
  4574. count += i;
  4575. } while (bench_stats_check(start)
  4576. #ifdef MULTI_VALUE_STATISTICS
  4577. || runs < minimum_runs
  4578. #endif
  4579. );
  4580. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4581. #ifdef MULTI_VALUE_STATISTICS
  4582. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4583. #endif
  4584. wc_AesXtsFree(aes);
  4585. /* decryption benchmark */
  4586. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4587. HEAP_HINT, devId);
  4588. if (ret != 0) {
  4589. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4590. goto exit;
  4591. }
  4592. RESET_MULTI_VALUE_STATS_VARS();
  4593. bench_stats_start(&count, &start);
  4594. do {
  4595. for (i = 0; i < numBlocks; i++) {
  4596. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4597. bench_size, i1, sizeof(i1))) != 0) {
  4598. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4599. goto exit;
  4600. }
  4601. RECORD_MULTI_VALUE_STATS();
  4602. }
  4603. count += i;
  4604. } while (bench_stats_check(start)
  4605. #ifdef MULTI_VALUE_STATISTICS
  4606. || runs < minimum_runs
  4607. #endif
  4608. );
  4609. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4610. #ifdef MULTI_VALUE_STATISTICS
  4611. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4612. #endif
  4613. exit:
  4614. wc_AesXtsFree(aes);
  4615. WC_FREE_VAR(aes, HEAP_HINT);
  4616. }
  4617. #endif /* WOLFSSL_AES_XTS */
  4618. #ifdef WOLFSSL_AES_COUNTER
  4619. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4620. const byte* iv, const char* label,
  4621. int useDeviceID)
  4622. {
  4623. Aes enc;
  4624. double start;
  4625. int i, count, ret = 0;
  4626. DECLARE_MULTI_VALUE_STATS_VARS()
  4627. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4628. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4629. printf("wc_AesInit failed, ret = %d\n", ret);
  4630. }
  4631. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4632. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4633. return;
  4634. }
  4635. bench_stats_start(&count, &start);
  4636. do {
  4637. for (i = 0; i < numBlocks; i++) {
  4638. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4639. bench_size)) != 0) {
  4640. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4641. return;
  4642. }
  4643. RECORD_MULTI_VALUE_STATS();
  4644. }
  4645. count += i;
  4646. } while (bench_stats_check(start)
  4647. #ifdef MULTI_VALUE_STATISTICS
  4648. || runs < minimum_runs
  4649. #endif
  4650. );
  4651. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4652. #ifdef MULTI_VALUE_STATISTICS
  4653. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4654. #endif
  4655. wc_AesFree(&enc);
  4656. }
  4657. void bench_aesctr(int useDeviceID)
  4658. {
  4659. #ifdef WOLFSSL_AES_128
  4660. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4661. #endif
  4662. #ifdef WOLFSSL_AES_192
  4663. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4664. #endif
  4665. #ifdef WOLFSSL_AES_256
  4666. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4667. #endif
  4668. }
  4669. #endif /* WOLFSSL_AES_COUNTER */
  4670. #ifdef HAVE_AESCCM
  4671. void bench_aesccm(int useDeviceID)
  4672. {
  4673. Aes enc;
  4674. int enc_inited = 0;
  4675. double start;
  4676. int ret, i, count;
  4677. DECLARE_MULTI_VALUE_STATS_VARS()
  4678. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4679. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4680. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4681. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4682. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4683. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4684. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4685. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4686. {
  4687. printf("wc_AesInit failed, ret = %d\n", ret);
  4688. goto exit;
  4689. }
  4690. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4691. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4692. goto exit;
  4693. }
  4694. enc_inited = 1;
  4695. bench_stats_start(&count, &start);
  4696. do {
  4697. for (i = 0; i < numBlocks; i++) {
  4698. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4699. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4700. bench_additional, 0);
  4701. RECORD_MULTI_VALUE_STATS();
  4702. }
  4703. count += i;
  4704. } while (bench_stats_check(start)
  4705. #ifdef MULTI_VALUE_STATISTICS
  4706. || runs < minimum_runs
  4707. #endif
  4708. );
  4709. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4710. bench_size, start, ret);
  4711. #ifdef MULTI_VALUE_STATISTICS
  4712. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4713. #endif
  4714. if (ret != 0) {
  4715. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4716. goto exit;
  4717. }
  4718. #ifdef HAVE_AES_DECRYPT
  4719. RESET_MULTI_VALUE_STATS_VARS();
  4720. bench_stats_start(&count, &start);
  4721. do {
  4722. for (i = 0; i < numBlocks; i++) {
  4723. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4724. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4725. bench_additional, 0);
  4726. RECORD_MULTI_VALUE_STATS();
  4727. }
  4728. count += i;
  4729. } while (bench_stats_check(start)
  4730. #ifdef MULTI_VALUE_STATISTICS
  4731. || runs < minimum_runs
  4732. #endif
  4733. );
  4734. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4735. bench_size, start, ret);
  4736. #ifdef MULTI_VALUE_STATISTICS
  4737. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4738. #endif
  4739. if (ret != 0) {
  4740. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4741. goto exit;
  4742. }
  4743. #endif
  4744. exit:
  4745. if (enc_inited)
  4746. wc_AesFree(&enc);
  4747. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4748. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4749. }
  4750. #endif /* HAVE_AESCCM */
  4751. #ifdef WOLFSSL_AES_SIV
  4752. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4753. encLabel, const char* decLabel)
  4754. {
  4755. int i;
  4756. int ret = 0;
  4757. byte assoc[AES_BLOCK_SIZE];
  4758. byte nonce[AES_BLOCK_SIZE];
  4759. byte siv[AES_BLOCK_SIZE];
  4760. int count = 0;
  4761. double start;
  4762. DECLARE_MULTI_VALUE_STATS_VARS()
  4763. bench_stats_start(&count, &start);
  4764. do {
  4765. for (i = 0; i < numBlocks; i++) {
  4766. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4767. AES_BLOCK_SIZE, bench_plain, bench_size,
  4768. siv, bench_cipher);
  4769. if (ret != 0) {
  4770. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4771. return;
  4772. }
  4773. RECORD_MULTI_VALUE_STATS();
  4774. }
  4775. count += i;
  4776. } while (bench_stats_check(start)
  4777. #ifdef MULTI_VALUE_STATISTICS
  4778. || runs < minimum_runs
  4779. #endif
  4780. );
  4781. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4782. #ifdef MULTI_VALUE_STATISTICS
  4783. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4784. #endif
  4785. RESET_MULTI_VALUE_STATS_VARS();
  4786. bench_stats_start(&count, &start);
  4787. do {
  4788. for (i = 0; i < numBlocks; i++) {
  4789. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4790. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4791. siv, bench_plain);
  4792. if (ret != 0) {
  4793. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4794. return;
  4795. }
  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(decLabel, 0, count, bench_size, start, ret);
  4805. #ifdef MULTI_VALUE_STATISTICS
  4806. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4807. #endif
  4808. }
  4809. void bench_aessiv(void)
  4810. {
  4811. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4812. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4813. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4814. }
  4815. #endif /* WOLFSSL_AES_SIV */
  4816. #endif /* !NO_AES */
  4817. #ifdef HAVE_POLY1305
  4818. void bench_poly1305(void)
  4819. {
  4820. Poly1305 enc;
  4821. byte mac[16];
  4822. double start;
  4823. int ret = 0, i, count;
  4824. DECLARE_MULTI_VALUE_STATS_VARS()
  4825. if (digest_stream) {
  4826. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4827. if (ret != 0) {
  4828. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4829. return;
  4830. }
  4831. bench_stats_start(&count, &start);
  4832. do {
  4833. for (i = 0; i < numBlocks; i++) {
  4834. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4835. if (ret != 0) {
  4836. printf("Poly1305Update failed: %d\n", ret);
  4837. break;
  4838. }
  4839. RECORD_MULTI_VALUE_STATS();
  4840. }
  4841. wc_Poly1305Final(&enc, mac);
  4842. count += i;
  4843. } while (bench_stats_check(start)
  4844. #ifdef MULTI_VALUE_STATISTICS
  4845. || runs < minimum_runs
  4846. #endif
  4847. );
  4848. }
  4849. else {
  4850. bench_stats_start(&count, &start);
  4851. do {
  4852. for (i = 0; i < numBlocks; i++) {
  4853. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4854. if (ret != 0) {
  4855. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4856. return;
  4857. }
  4858. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4859. if (ret != 0) {
  4860. printf("Poly1305Update failed: %d\n", ret);
  4861. break;
  4862. }
  4863. wc_Poly1305Final(&enc, mac);
  4864. RECORD_MULTI_VALUE_STATS();
  4865. }
  4866. count += i;
  4867. } while (bench_stats_check(start)
  4868. #ifdef MULTI_VALUE_STATISTICS
  4869. || runs < minimum_runs
  4870. #endif
  4871. );
  4872. }
  4873. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4874. #ifdef MULTI_VALUE_STATISTICS
  4875. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4876. #endif
  4877. }
  4878. #endif /* HAVE_POLY1305 */
  4879. #ifdef HAVE_CAMELLIA
  4880. void bench_camellia(void)
  4881. {
  4882. Camellia cam;
  4883. double start;
  4884. int ret, i, count;
  4885. DECLARE_MULTI_VALUE_STATS_VARS()
  4886. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4887. if (ret != 0) {
  4888. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4889. return;
  4890. }
  4891. bench_stats_start(&count, &start);
  4892. do {
  4893. for (i = 0; i < numBlocks; i++) {
  4894. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4895. bench_size);
  4896. if (ret < 0) {
  4897. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4898. return;
  4899. }
  4900. RECORD_MULTI_VALUE_STATS();
  4901. }
  4902. count += i;
  4903. } while (bench_stats_check(start)
  4904. #ifdef MULTI_VALUE_STATISTICS
  4905. || runs < minimum_runs
  4906. #endif
  4907. );
  4908. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4909. #ifdef MULTI_VALUE_STATISTICS
  4910. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4911. #endif
  4912. }
  4913. #endif
  4914. #ifdef WOLFSSL_SM4_CBC
  4915. void bench_sm4_cbc(void)
  4916. {
  4917. wc_Sm4 sm4;
  4918. double start;
  4919. int ret;
  4920. int i;
  4921. int count;
  4922. DECLARE_MULTI_VALUE_STATS_VARS()
  4923. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4924. if (ret != 0) {
  4925. printf("Sm4SetKey failed, ret = %d\n", ret);
  4926. return;
  4927. }
  4928. ret = wc_Sm4SetIV(&sm4, bench_iv);
  4929. if (ret != 0) {
  4930. printf("Sm4SetIV failed, ret = %d\n", ret);
  4931. return;
  4932. }
  4933. bench_stats_start(&count, &start);
  4934. do {
  4935. for (i = 0; i < numBlocks; i++) {
  4936. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  4937. if (ret < 0) {
  4938. printf("Sm4CbcEncrypt failed: %d\n", ret);
  4939. return;
  4940. }
  4941. RECORD_MULTI_VALUE_STATS();
  4942. }
  4943. count += i;
  4944. } while (bench_stats_check(start)
  4945. #ifdef MULTI_VALUE_STATISTICS
  4946. || runs < minimum_runs
  4947. #endif
  4948. );
  4949. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  4950. #ifdef MULTI_VALUE_STATISTICS
  4951. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4952. #endif
  4953. RESET_MULTI_VALUE_STATS_VARS();
  4954. bench_stats_start(&count, &start);
  4955. do {
  4956. for (i = 0; i < numBlocks; i++) {
  4957. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  4958. if (ret < 0) {
  4959. printf("Sm4CbcDecrypt failed: %d\n", ret);
  4960. return;
  4961. }
  4962. RECORD_MULTI_VALUE_STATS();
  4963. }
  4964. count += i;
  4965. } while (bench_stats_check(start)
  4966. #ifdef MULTI_VALUE_STATISTICS
  4967. || runs < minimum_runs
  4968. #endif
  4969. );
  4970. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  4971. #ifdef MULTI_VALUE_STATISTICS
  4972. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4973. #endif
  4974. }
  4975. #endif
  4976. #ifdef WOLFSSL_SM4_GCM
  4977. void bench_sm4_gcm(void)
  4978. {
  4979. wc_Sm4 sm4;
  4980. double start;
  4981. int ret;
  4982. int i;
  4983. int count;
  4984. DECLARE_MULTI_VALUE_STATS_VARS()
  4985. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4986. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4987. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4988. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4989. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4990. if (ret != 0) {
  4991. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  4992. goto exit;
  4993. }
  4994. bench_stats_start(&count, &start);
  4995. do {
  4996. for (i = 0; i < numBlocks; i++) {
  4997. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  4998. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  4999. bench_additional, aesAuthAddSz);
  5000. if (ret < 0) {
  5001. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5002. goto exit;
  5003. }
  5004. RECORD_MULTI_VALUE_STATS();
  5005. }
  5006. count += i;
  5007. } while (bench_stats_check(start)
  5008. #ifdef MULTI_VALUE_STATISTICS
  5009. || runs < minimum_runs
  5010. #endif
  5011. );
  5012. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5013. #ifdef MULTI_VALUE_STATISTICS
  5014. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5015. #endif
  5016. RESET_MULTI_VALUE_STATS_VARS();
  5017. bench_stats_start(&count, &start);
  5018. do {
  5019. for (i = 0; i < numBlocks; i++) {
  5020. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5021. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5022. bench_additional, aesAuthAddSz);
  5023. if (ret < 0) {
  5024. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5025. goto exit;
  5026. }
  5027. RECORD_MULTI_VALUE_STATS();
  5028. }
  5029. count += i;
  5030. } while (bench_stats_check(start)
  5031. #ifdef MULTI_VALUE_STATISTICS
  5032. || runs < minimum_runs
  5033. #endif
  5034. );
  5035. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5036. #ifdef MULTI_VALUE_STATISTICS
  5037. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5038. #endif
  5039. exit:
  5040. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5041. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5042. }
  5043. #endif
  5044. #ifdef WOLFSSL_SM4_CCM
  5045. void bench_sm4_ccm(void)
  5046. {
  5047. wc_Sm4 enc;
  5048. double start;
  5049. int ret, i, count;
  5050. DECLARE_MULTI_VALUE_STATS_VARS()
  5051. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5052. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5053. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5054. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5055. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5056. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5057. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5058. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5059. goto exit;
  5060. }
  5061. bench_stats_start(&count, &start);
  5062. do {
  5063. for (i = 0; i < numBlocks; i++) {
  5064. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5065. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5066. bench_additional, 0);
  5067. RECORD_MULTI_VALUE_STATS();
  5068. }
  5069. count += i;
  5070. } while (bench_stats_check(start)
  5071. #ifdef MULTI_VALUE_STATISTICS
  5072. || runs < minimum_runs
  5073. #endif
  5074. );
  5075. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5076. #ifdef MULTI_VALUE_STATISTICS
  5077. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5078. #endif
  5079. if (ret != 0) {
  5080. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5081. goto exit;
  5082. }
  5083. RESET_MULTI_VALUE_STATS_VARS();
  5084. bench_stats_start(&count, &start);
  5085. do {
  5086. for (i = 0; i < numBlocks; i++) {
  5087. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5088. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5089. bench_additional, 0);
  5090. RECORD_MULTI_VALUE_STATS();
  5091. }
  5092. count += i;
  5093. } while (bench_stats_check(start)
  5094. #ifdef MULTI_VALUE_STATISTICS
  5095. || runs < minimum_runs
  5096. #endif
  5097. );
  5098. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5099. #ifdef MULTI_VALUE_STATISTICS
  5100. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5101. #endif
  5102. if (ret != 0) {
  5103. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5104. goto exit;
  5105. }
  5106. exit:
  5107. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5108. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5109. }
  5110. #endif /* HAVE_AESCCM */
  5111. #ifndef NO_DES3
  5112. void bench_des(int useDeviceID)
  5113. {
  5114. int ret = 0, i, count = 0, times, pending = 0;
  5115. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5116. sizeof(Des3), HEAP_HINT);
  5117. double start;
  5118. DECLARE_MULTI_VALUE_STATS_VARS()
  5119. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5120. sizeof(Des3), HEAP_HINT);
  5121. /* init keys */
  5122. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5123. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5124. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5125. printf("Des3Init failed, ret = %d\n", ret);
  5126. goto exit;
  5127. }
  5128. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5129. if (ret != 0) {
  5130. printf("Des3_SetKey failed, ret = %d\n", ret);
  5131. goto exit;
  5132. }
  5133. }
  5134. bench_stats_start(&count, &start);
  5135. do {
  5136. for (times = 0; times < numBlocks || pending > 0; ) {
  5137. bench_async_poll(&pending);
  5138. /* while free pending slots in queue, submit ops */
  5139. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5140. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5141. &times, numBlocks, &pending)) {
  5142. ret = wc_Des3_CbcEncrypt(enc[i],
  5143. bench_cipher,
  5144. bench_plain, bench_size);
  5145. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5146. 0, &times, &pending)) {
  5147. goto exit_3des;
  5148. }
  5149. }
  5150. } /* for i */
  5151. RECORD_MULTI_VALUE_STATS();
  5152. } /* for times */
  5153. count += times;
  5154. } while (bench_stats_check(start)
  5155. #ifdef MULTI_VALUE_STATISTICS
  5156. || runs < minimum_runs
  5157. #endif
  5158. );
  5159. exit_3des:
  5160. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5161. #ifdef MULTI_VALUE_STATISTICS
  5162. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5163. #endif
  5164. exit:
  5165. if (WC_ARRAY_OK(enc)) {
  5166. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5167. wc_Des3Free(enc[i]);
  5168. }
  5169. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5170. }
  5171. }
  5172. #endif /* !NO_DES3 */
  5173. #ifndef NO_RC4
  5174. void bench_arc4(int useDeviceID)
  5175. {
  5176. int ret = 0, i, count = 0, times, pending = 0;
  5177. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5178. sizeof(Arc4), HEAP_HINT);
  5179. double start;
  5180. DECLARE_MULTI_VALUE_STATS_VARS()
  5181. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5182. sizeof(Arc4), HEAP_HINT);
  5183. /* init keys */
  5184. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5185. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5186. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5187. printf("Arc4Init failed, ret = %d\n", ret);
  5188. goto exit;
  5189. }
  5190. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5191. if (ret != 0) {
  5192. printf("Arc4SetKey failed, ret = %d\n", ret);
  5193. goto exit;
  5194. }
  5195. }
  5196. bench_stats_start(&count, &start);
  5197. do {
  5198. for (times = 0; times < numBlocks || pending > 0; ) {
  5199. bench_async_poll(&pending);
  5200. /* while free pending slots in queue, submit ops */
  5201. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5202. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5203. &times, numBlocks, &pending)) {
  5204. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5205. bench_size);
  5206. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5207. 0, &times, &pending)) {
  5208. goto exit_arc4;
  5209. }
  5210. }
  5211. } /* for i */
  5212. RECORD_MULTI_VALUE_STATS();
  5213. } /* for times */
  5214. count += times;
  5215. } while (bench_stats_check(start)
  5216. #ifdef MULTI_VALUE_STATISTICS
  5217. || runs < minimum_runs
  5218. #endif
  5219. );
  5220. exit_arc4:
  5221. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5222. #ifdef MULTI_VALUE_STATISTICS
  5223. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5224. #endif
  5225. exit:
  5226. if (WC_ARRAY_OK(enc)) {
  5227. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5228. wc_Arc4Free(enc[i]);
  5229. }
  5230. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5231. }
  5232. }
  5233. #endif /* !NO_RC4 */
  5234. #ifdef HAVE_CHACHA
  5235. void bench_chacha(void)
  5236. {
  5237. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5238. double start;
  5239. int ret, i, count;
  5240. DECLARE_MULTI_VALUE_STATS_VARS()
  5241. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5242. XMEMSET(enc, 0, sizeof(ChaCha));
  5243. wc_Chacha_SetKey(enc, bench_key, 16);
  5244. if (encrypt_only) {
  5245. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5246. if (ret < 0) {
  5247. printf("wc_Chacha_SetIV error: %d\n", ret);
  5248. goto exit;
  5249. }
  5250. bench_stats_start(&count, &start);
  5251. do {
  5252. for (i = 0; i < numBlocks; i++) {
  5253. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5254. bench_size);
  5255. if (ret < 0) {
  5256. printf("wc_Chacha_Process error: %d\n", ret);
  5257. goto exit;
  5258. }
  5259. RECORD_MULTI_VALUE_STATS();
  5260. }
  5261. count += i;
  5262. } while (bench_stats_check(start)
  5263. #ifdef MULTI_VALUE_STATISTICS
  5264. || runs < minimum_runs
  5265. #endif
  5266. );
  5267. }
  5268. else {
  5269. bench_stats_start(&count, &start);
  5270. do {
  5271. for (i = 0; i < numBlocks; i++) {
  5272. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5273. if (ret < 0) {
  5274. printf("wc_Chacha_SetIV error: %d\n", ret);
  5275. goto exit;
  5276. }
  5277. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5278. bench_size);
  5279. if (ret < 0) {
  5280. printf("wc_Chacha_Process error: %d\n", ret);
  5281. goto exit;
  5282. }
  5283. RECORD_MULTI_VALUE_STATS();
  5284. }
  5285. count += i;
  5286. } while (bench_stats_check(start)
  5287. #ifdef MULTI_VALUE_STATISTICS
  5288. || runs < minimum_runs
  5289. #endif
  5290. );
  5291. }
  5292. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5293. #ifdef MULTI_VALUE_STATISTICS
  5294. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5295. #endif
  5296. exit:
  5297. WC_FREE_VAR(enc, HEAP_HINT);
  5298. }
  5299. #endif /* HAVE_CHACHA*/
  5300. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5301. void bench_chacha20_poly1305_aead(void)
  5302. {
  5303. double start;
  5304. int ret = 0, i, count;
  5305. DECLARE_MULTI_VALUE_STATS_VARS()
  5306. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5307. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5308. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5309. bench_stats_start(&count, &start);
  5310. do {
  5311. for (i = 0; i < numBlocks; i++) {
  5312. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5313. bench_plain, bench_size, bench_cipher, authTag);
  5314. if (ret < 0) {
  5315. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5316. goto exit;
  5317. }
  5318. RECORD_MULTI_VALUE_STATS();
  5319. }
  5320. count += i;
  5321. } while (bench_stats_check(start)
  5322. #ifdef MULTI_VALUE_STATISTICS
  5323. || runs < minimum_runs
  5324. #endif
  5325. );
  5326. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5327. #ifdef MULTI_VALUE_STATISTICS
  5328. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5329. #endif
  5330. exit:
  5331. WC_FREE_VAR(authTag, HEAP_HINT);
  5332. }
  5333. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5334. #ifndef NO_MD5
  5335. void bench_md5(int useDeviceID)
  5336. {
  5337. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5338. sizeof(wc_Md5), HEAP_HINT);
  5339. double start = 0;
  5340. int ret = 0, i, count = 0, times, pending = 0;
  5341. DECLARE_MULTI_VALUE_STATS_VARS()
  5342. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5343. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5344. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5345. sizeof(wc_Md5), HEAP_HINT);
  5346. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5347. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5348. if (digest_stream) {
  5349. /* init keys */
  5350. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5351. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5352. useDeviceID ? devId : INVALID_DEVID);
  5353. if (ret != 0) {
  5354. printf("InitMd5_ex failed, ret = %d\n", ret);
  5355. goto exit;
  5356. }
  5357. #ifdef WOLFSSL_PIC32MZ_HASH
  5358. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5359. #endif
  5360. }
  5361. bench_stats_start(&count, &start);
  5362. do {
  5363. for (times = 0; times < numBlocks || pending > 0; ) {
  5364. bench_async_poll(&pending);
  5365. /* while free pending slots in queue, submit ops */
  5366. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5367. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5368. 0, &times, numBlocks, &pending)) {
  5369. ret = wc_Md5Update(hash[i], bench_plain,
  5370. bench_size);
  5371. if (!bench_async_handle(&ret,
  5372. BENCH_ASYNC_GET_DEV(hash[i]),
  5373. 0, &times, &pending)) {
  5374. goto exit_md5;
  5375. }
  5376. }
  5377. } /* for i */
  5378. RECORD_MULTI_VALUE_STATS();
  5379. } /* for times */
  5380. count += times;
  5381. times = 0;
  5382. do {
  5383. bench_async_poll(&pending);
  5384. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5385. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5386. 0, &times, numBlocks, &pending)) {
  5387. ret = wc_Md5Final(hash[i], digest[i]);
  5388. if (!bench_async_handle(&ret,
  5389. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5390. &times, &pending)) {
  5391. goto exit_md5;
  5392. }
  5393. }
  5394. } /* for i */
  5395. } while (pending > 0);
  5396. } while (bench_stats_check(start)
  5397. #ifdef MULTI_VALUE_STATISTICS
  5398. || runs < minimum_runs
  5399. #endif
  5400. );
  5401. }
  5402. else {
  5403. bench_stats_start(&count, &start);
  5404. do {
  5405. for (times = 0; times < numBlocks; times++) {
  5406. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5407. if (ret == 0)
  5408. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5409. if (ret == 0)
  5410. ret = wc_Md5Final(hash[0], digest[0]);
  5411. if (ret != 0)
  5412. goto exit_md5;
  5413. RECORD_MULTI_VALUE_STATS();
  5414. } /* for times */
  5415. count += times;
  5416. } while (bench_stats_check(start)
  5417. #ifdef MULTI_VALUE_STATISTICS
  5418. || runs < minimum_runs
  5419. #endif
  5420. );
  5421. }
  5422. exit_md5:
  5423. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5424. #ifdef MULTI_VALUE_STATISTICS
  5425. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5426. #endif
  5427. exit:
  5428. #ifdef WOLFSSL_ASYNC_CRYPT
  5429. if (WC_ARRAY_OK(hash)) {
  5430. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5431. wc_Md5Free(hash[i]);
  5432. }
  5433. }
  5434. #endif
  5435. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5436. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5437. }
  5438. #endif /* !NO_MD5 */
  5439. #ifndef NO_SHA
  5440. void bench_sha(int useDeviceID)
  5441. {
  5442. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5443. sizeof(wc_Sha), HEAP_HINT);
  5444. double start;
  5445. int ret = 0, i, count = 0, times, pending = 0;
  5446. DECLARE_MULTI_VALUE_STATS_VARS()
  5447. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5448. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5449. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5450. sizeof(wc_Sha), HEAP_HINT);
  5451. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5452. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5453. if (digest_stream) {
  5454. /* init keys */
  5455. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5456. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5457. useDeviceID ? devId : INVALID_DEVID);
  5458. if (ret != 0) {
  5459. printf("InitSha failed, ret = %d\n", ret);
  5460. goto exit;
  5461. }
  5462. #ifdef WOLFSSL_PIC32MZ_HASH
  5463. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5464. #endif
  5465. }
  5466. bench_stats_start(&count, &start);
  5467. do {
  5468. for (times = 0; times < numBlocks || pending > 0; ) {
  5469. bench_async_poll(&pending);
  5470. /* while free pending slots in queue, submit ops */
  5471. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5472. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5473. 0, &times, numBlocks, &pending)) {
  5474. ret = wc_ShaUpdate(hash[i], bench_plain,
  5475. bench_size);
  5476. if (!bench_async_handle(&ret,
  5477. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5478. &times, &pending)) {
  5479. goto exit_sha;
  5480. }
  5481. }
  5482. } /* for i */
  5483. RECORD_MULTI_VALUE_STATS();
  5484. } /* for times */
  5485. count += times;
  5486. times = 0;
  5487. do {
  5488. bench_async_poll(&pending);
  5489. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5490. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5491. 0, &times, numBlocks, &pending)) {
  5492. ret = wc_ShaFinal(hash[i], digest[i]);
  5493. if (!bench_async_handle(&ret,
  5494. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5495. &times, &pending)) {
  5496. goto exit_sha;
  5497. }
  5498. }
  5499. } /* for i */
  5500. } while (pending > 0);
  5501. } while (bench_stats_check(start)
  5502. #ifdef MULTI_VALUE_STATISTICS
  5503. || runs < minimum_runs
  5504. #endif
  5505. );
  5506. }
  5507. else {
  5508. bench_stats_start(&count, &start);
  5509. do {
  5510. for (times = 0; times < numBlocks; times++) {
  5511. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5512. useDeviceID ? devId : INVALID_DEVID);
  5513. if (ret == 0)
  5514. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5515. if (ret == 0)
  5516. ret = wc_ShaFinal(hash[0], digest[0]);
  5517. if (ret != 0)
  5518. goto exit_sha;
  5519. RECORD_MULTI_VALUE_STATS();
  5520. } /* for times */
  5521. count += times;
  5522. } while (bench_stats_check(start)
  5523. #ifdef MULTI_VALUE_STATISTICS
  5524. || runs < minimum_runs
  5525. #endif
  5526. );
  5527. }
  5528. exit_sha:
  5529. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5530. #ifdef MULTI_VALUE_STATISTICS
  5531. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5532. #endif
  5533. exit:
  5534. if (WC_ARRAY_OK(hash)) {
  5535. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5536. wc_ShaFree(hash[i]);
  5537. }
  5538. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5539. }
  5540. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5541. }
  5542. #endif /* NO_SHA */
  5543. #ifdef WOLFSSL_SHA224
  5544. void bench_sha224(int useDeviceID)
  5545. {
  5546. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5547. sizeof(wc_Sha224), HEAP_HINT);
  5548. double start;
  5549. int ret = 0, i, count = 0, times, pending = 0;
  5550. DECLARE_MULTI_VALUE_STATS_VARS()
  5551. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5552. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5553. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5554. sizeof(wc_Sha224), HEAP_HINT);
  5555. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5556. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5557. if (digest_stream) {
  5558. /* init keys */
  5559. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5560. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5561. useDeviceID ? devId : INVALID_DEVID);
  5562. if (ret != 0) {
  5563. printf("InitSha224_ex failed, ret = %d\n", ret);
  5564. goto exit;
  5565. }
  5566. }
  5567. bench_stats_start(&count, &start);
  5568. do {
  5569. for (times = 0; times < numBlocks || pending > 0; ) {
  5570. bench_async_poll(&pending);
  5571. /* while free pending slots in queue, submit ops */
  5572. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5573. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5574. 0, &times, numBlocks, &pending)) {
  5575. ret = wc_Sha224Update(hash[i], bench_plain,
  5576. bench_size);
  5577. if (!bench_async_handle(&ret,
  5578. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5579. &times, &pending)) {
  5580. goto exit_sha224;
  5581. }
  5582. }
  5583. } /* for i */
  5584. RECORD_MULTI_VALUE_STATS();
  5585. } /* for times */
  5586. count += times;
  5587. times = 0;
  5588. do {
  5589. bench_async_poll(&pending);
  5590. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5591. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5592. 0, &times, numBlocks, &pending)) {
  5593. ret = wc_Sha224Final(hash[i], digest[i]);
  5594. if (!bench_async_handle(&ret,
  5595. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5596. &times, &pending)) {
  5597. goto exit_sha224;
  5598. }
  5599. }
  5600. } /* for i */
  5601. } while (pending > 0);
  5602. } while (bench_stats_check(start)
  5603. #ifdef MULTI_VALUE_STATISTICS
  5604. || runs < minimum_runs
  5605. #endif
  5606. );
  5607. }
  5608. else {
  5609. bench_stats_start(&count, &start);
  5610. do {
  5611. for (times = 0; times < numBlocks; times++) {
  5612. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5613. useDeviceID ? devId : INVALID_DEVID);
  5614. if (ret == 0)
  5615. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5616. if (ret == 0)
  5617. ret = wc_Sha224Final(hash[0], digest[0]);
  5618. if (ret != 0)
  5619. goto exit_sha224;
  5620. } /* for times */
  5621. count += times;
  5622. } while (bench_stats_check(start)
  5623. #ifdef MULTI_VALUE_STATISTICS
  5624. || runs < minimum_runs
  5625. #endif
  5626. );
  5627. }
  5628. exit_sha224:
  5629. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5630. bench_size, start, ret);
  5631. #ifdef MULTI_VALUE_STATISTICS
  5632. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5633. #endif
  5634. exit:
  5635. if (WC_ARRAY_OK(hash)) {
  5636. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5637. wc_Sha224Free(hash[i]);
  5638. }
  5639. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5640. }
  5641. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5642. }
  5643. #endif
  5644. #ifndef NO_SHA256
  5645. void bench_sha256(int useDeviceID)
  5646. {
  5647. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5648. sizeof(wc_Sha256), HEAP_HINT);
  5649. double start;
  5650. int ret = 0, i, count = 0, times, pending = 0;
  5651. DECLARE_MULTI_VALUE_STATS_VARS()
  5652. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5653. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5654. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5655. sizeof(wc_Sha256), HEAP_HINT);
  5656. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5657. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5658. if (digest_stream) {
  5659. /* init keys */
  5660. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5661. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5662. useDeviceID ? devId: INVALID_DEVID);
  5663. if (ret != 0) {
  5664. printf("InitSha256_ex failed, ret = %d\n", ret);
  5665. goto exit;
  5666. }
  5667. #ifdef WOLFSSL_PIC32MZ_HASH
  5668. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5669. #endif
  5670. }
  5671. bench_stats_start(&count, &start);
  5672. do {
  5673. for (times = 0; times < numBlocks || pending > 0; ) {
  5674. bench_async_poll(&pending);
  5675. /* while free pending slots in queue, submit ops */
  5676. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5677. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5678. 0, &times, numBlocks, &pending)) {
  5679. ret = wc_Sha256Update(hash[i], bench_plain,
  5680. bench_size);
  5681. if (!bench_async_handle(&ret,
  5682. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5683. &times, &pending)) {
  5684. goto exit_sha256;
  5685. }
  5686. }
  5687. } /* for i */
  5688. RECORD_MULTI_VALUE_STATS();
  5689. } /* for times */
  5690. count += times;
  5691. times = 0;
  5692. do {
  5693. bench_async_poll(&pending);
  5694. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5695. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5696. 0, &times, numBlocks, &pending)) {
  5697. ret = wc_Sha256Final(hash[i], digest[i]);
  5698. if (!bench_async_handle(&ret,
  5699. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5700. &times, &pending)) {
  5701. goto exit_sha256;
  5702. }
  5703. }
  5704. } /* for i */
  5705. } while (pending > 0);
  5706. } while (bench_stats_check(start)
  5707. #ifdef MULTI_VALUE_STATISTICS
  5708. || runs < minimum_runs
  5709. #endif
  5710. );
  5711. }
  5712. else {
  5713. bench_stats_start(&count, &start);
  5714. do {
  5715. for (times = 0; times < numBlocks; times++) {
  5716. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5717. useDeviceID ? devId: INVALID_DEVID);
  5718. if (ret == 0)
  5719. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5720. if (ret == 0)
  5721. ret = wc_Sha256Final(hash[0], digest[0]);
  5722. if (ret != 0)
  5723. goto exit_sha256;
  5724. RECORD_MULTI_VALUE_STATS();
  5725. } /* for times */
  5726. count += times;
  5727. } while (bench_stats_check(start)
  5728. #ifdef MULTI_VALUE_STATISTICS
  5729. || runs < minimum_runs
  5730. #endif
  5731. );
  5732. }
  5733. exit_sha256:
  5734. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5735. start, ret);
  5736. #ifdef MULTI_VALUE_STATISTICS
  5737. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5738. #endif
  5739. exit:
  5740. if (WC_ARRAY_OK(hash)) {
  5741. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5742. wc_Sha256Free(hash[i]);
  5743. }
  5744. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5745. }
  5746. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5747. }
  5748. #endif
  5749. #ifdef WOLFSSL_SHA384
  5750. void bench_sha384(int useDeviceID)
  5751. {
  5752. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5753. sizeof(wc_Sha384), HEAP_HINT);
  5754. double start;
  5755. int ret = 0, i, count = 0, times, pending = 0;
  5756. DECLARE_MULTI_VALUE_STATS_VARS()
  5757. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5758. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5759. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5760. sizeof(wc_Sha384), HEAP_HINT);
  5761. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5762. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5763. if (digest_stream) {
  5764. /* init keys */
  5765. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5766. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5767. useDeviceID ? devId : INVALID_DEVID);
  5768. if (ret != 0) {
  5769. printf("InitSha384_ex failed, ret = %d\n", ret);
  5770. goto exit;
  5771. }
  5772. }
  5773. bench_stats_start(&count, &start);
  5774. do {
  5775. for (times = 0; times < numBlocks || pending > 0; ) {
  5776. bench_async_poll(&pending);
  5777. /* while free pending slots in queue, submit ops */
  5778. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5779. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5780. 0, &times, numBlocks, &pending)) {
  5781. ret = wc_Sha384Update(hash[i], bench_plain,
  5782. bench_size);
  5783. if (!bench_async_handle(&ret,
  5784. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5785. &times, &pending)) {
  5786. goto exit_sha384;
  5787. }
  5788. }
  5789. } /* for i */
  5790. RECORD_MULTI_VALUE_STATS();
  5791. } /* for times */
  5792. count += times;
  5793. times = 0;
  5794. do {
  5795. bench_async_poll(&pending);
  5796. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5797. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5798. 0, &times, numBlocks, &pending)) {
  5799. ret = wc_Sha384Final(hash[i], digest[i]);
  5800. if (!bench_async_handle(&ret,
  5801. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5802. &times, &pending)) {
  5803. goto exit_sha384;
  5804. }
  5805. }
  5806. } /* for i */
  5807. } while (pending > 0);
  5808. } while (bench_stats_check(start)
  5809. #ifdef MULTI_VALUE_STATISTICS
  5810. || runs < minimum_runs
  5811. #endif
  5812. );
  5813. }
  5814. else {
  5815. bench_stats_start(&count, &start);
  5816. do {
  5817. for (times = 0; times < numBlocks; times++) {
  5818. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5819. useDeviceID ? devId : INVALID_DEVID);
  5820. if (ret == 0)
  5821. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5822. if (ret == 0)
  5823. ret = wc_Sha384Final(hash[0], digest[0]);
  5824. if (ret != 0)
  5825. goto exit_sha384;
  5826. RECORD_MULTI_VALUE_STATS();
  5827. } /* for times */
  5828. count += times;
  5829. } while (bench_stats_check(start)
  5830. #ifdef MULTI_VALUE_STATISTICS
  5831. || runs < minimum_runs
  5832. #endif
  5833. );
  5834. }
  5835. exit_sha384:
  5836. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5837. start, ret);
  5838. #ifdef MULTI_VALUE_STATISTICS
  5839. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5840. #endif
  5841. exit:
  5842. if (WC_ARRAY_OK(hash)) {
  5843. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5844. wc_Sha384Free(hash[i]);
  5845. }
  5846. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5847. }
  5848. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5849. }
  5850. #endif
  5851. #ifdef WOLFSSL_SHA512
  5852. void bench_sha512(int useDeviceID)
  5853. {
  5854. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5855. sizeof(wc_Sha512), HEAP_HINT);
  5856. double start;
  5857. int ret = 0, i, count = 0, times, pending = 0;
  5858. DECLARE_MULTI_VALUE_STATS_VARS()
  5859. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5860. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5861. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5862. sizeof(wc_Sha512), HEAP_HINT);
  5863. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5864. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5865. if (digest_stream) {
  5866. /* init keys */
  5867. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5868. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5869. useDeviceID ? devId : INVALID_DEVID);
  5870. if (ret != 0) {
  5871. printf("InitSha512_ex failed, ret = %d\n", ret);
  5872. goto exit;
  5873. }
  5874. }
  5875. bench_stats_start(&count, &start);
  5876. do {
  5877. for (times = 0; times < numBlocks || pending > 0; ) {
  5878. bench_async_poll(&pending);
  5879. /* while free pending slots in queue, submit ops */
  5880. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5881. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5882. 0, &times, numBlocks, &pending)) {
  5883. ret = wc_Sha512Update(hash[i], bench_plain,
  5884. bench_size);
  5885. if (!bench_async_handle(&ret,
  5886. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5887. &times, &pending)) {
  5888. goto exit_sha512;
  5889. }
  5890. }
  5891. } /* for i */
  5892. RECORD_MULTI_VALUE_STATS();
  5893. } /* for times */
  5894. count += times;
  5895. times = 0;
  5896. do {
  5897. bench_async_poll(&pending);
  5898. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5899. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5900. 0, &times, numBlocks, &pending)) {
  5901. ret = wc_Sha512Final(hash[i], digest[i]);
  5902. if (!bench_async_handle(&ret,
  5903. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5904. &times, &pending)) {
  5905. goto exit_sha512;
  5906. }
  5907. }
  5908. } /* for i */
  5909. } while (pending > 0);
  5910. } while (bench_stats_check(start)
  5911. #ifdef MULTI_VALUE_STATISTICS
  5912. || runs < minimum_runs
  5913. #endif
  5914. );
  5915. }
  5916. else {
  5917. bench_stats_start(&count, &start);
  5918. do {
  5919. for (times = 0; times < numBlocks; times++) {
  5920. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5921. useDeviceID ? devId : INVALID_DEVID);
  5922. if (ret == 0)
  5923. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  5924. if (ret == 0)
  5925. ret = wc_Sha512Final(hash[0], digest[0]);
  5926. if (ret != 0)
  5927. goto exit_sha512;
  5928. RECORD_MULTI_VALUE_STATS();
  5929. } /* for times */
  5930. count += times;
  5931. } while (bench_stats_check(start)
  5932. #ifdef MULTI_VALUE_STATISTICS
  5933. || runs < minimum_runs
  5934. #endif
  5935. );
  5936. }
  5937. exit_sha512:
  5938. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  5939. start, ret);
  5940. #ifdef MULTI_VALUE_STATISTICS
  5941. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5942. #endif
  5943. exit:
  5944. if (WC_ARRAY_OK(hash)) {
  5945. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5946. wc_Sha512Free(hash[i]);
  5947. }
  5948. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5949. }
  5950. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5951. }
  5952. #if !defined(WOLFSSL_NOSHA512_224) && \
  5953. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  5954. void bench_sha512_224(int useDeviceID)
  5955. {
  5956. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  5957. sizeof(wc_Sha512_224), HEAP_HINT);
  5958. double start;
  5959. int ret = 0, i, count = 0, times, pending = 0;
  5960. DECLARE_MULTI_VALUE_STATS_VARS()
  5961. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5962. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  5963. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  5964. sizeof(wc_Sha512_224), HEAP_HINT);
  5965. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5966. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  5967. if (digest_stream) {
  5968. /* init keys */
  5969. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5970. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  5971. useDeviceID ? devId : INVALID_DEVID);
  5972. if (ret != 0) {
  5973. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  5974. goto exit;
  5975. }
  5976. }
  5977. bench_stats_start(&count, &start);
  5978. do {
  5979. for (times = 0; times < numBlocks || pending > 0; ) {
  5980. bench_async_poll(&pending);
  5981. /* while free pending slots in queue, submit ops */
  5982. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5983. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5984. 0, &times, numBlocks, &pending)) {
  5985. ret = wc_Sha512_224Update(hash[i], bench_plain,
  5986. bench_size);
  5987. if (!bench_async_handle(&ret,
  5988. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5989. &times, &pending)) {
  5990. goto exit_sha512_224;
  5991. }
  5992. }
  5993. } /* for i */
  5994. RECORD_MULTI_VALUE_STATS();
  5995. } /* for times */
  5996. count += times;
  5997. times = 0;
  5998. do {
  5999. bench_async_poll(&pending);
  6000. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6001. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6002. 0, &times, numBlocks, &pending)) {
  6003. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6004. if (!bench_async_handle(&ret,
  6005. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6006. &times, &pending)) {
  6007. goto exit_sha512_224;
  6008. }
  6009. }
  6010. } /* for i */
  6011. } while (pending > 0);
  6012. } while (bench_stats_check(start)
  6013. #ifdef MULTI_VALUE_STATISTICS
  6014. || runs < minimum_runs
  6015. #endif
  6016. );
  6017. }
  6018. else {
  6019. bench_stats_start(&count, &start);
  6020. do {
  6021. for (times = 0; times < numBlocks; times++) {
  6022. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6023. useDeviceID ? devId : INVALID_DEVID);
  6024. if (ret == 0)
  6025. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6026. if (ret == 0)
  6027. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6028. if (ret != 0)
  6029. goto exit_sha512_224;
  6030. RECORD_MULTI_VALUE_STATS();
  6031. } /* for times */
  6032. count += times;
  6033. } while (bench_stats_check(start)
  6034. #ifdef MULTI_VALUE_STATISTICS
  6035. || runs < minimum_runs
  6036. #endif
  6037. );
  6038. }
  6039. exit_sha512_224:
  6040. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6041. start, ret);
  6042. #ifdef MULTI_VALUE_STATISTICS
  6043. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6044. #endif
  6045. exit:
  6046. if (WC_ARRAY_OK(hash)) {
  6047. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6048. wc_Sha512_224Free(hash[i]);
  6049. }
  6050. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6051. }
  6052. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6053. }
  6054. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6055. #if !defined(WOLFSSL_NOSHA512_256) && \
  6056. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6057. void bench_sha512_256(int useDeviceID)
  6058. {
  6059. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6060. sizeof(wc_Sha512_256), HEAP_HINT);
  6061. double start;
  6062. int ret = 0, i, count = 0, times, pending = 0;
  6063. DECLARE_MULTI_VALUE_STATS_VARS()
  6064. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6065. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6066. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6067. sizeof(wc_Sha512_256), HEAP_HINT);
  6068. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6069. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6070. if (digest_stream) {
  6071. /* init keys */
  6072. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6073. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6074. useDeviceID ? devId : INVALID_DEVID);
  6075. if (ret != 0) {
  6076. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6077. goto exit;
  6078. }
  6079. }
  6080. bench_stats_start(&count, &start);
  6081. do {
  6082. for (times = 0; times < numBlocks || pending > 0; ) {
  6083. bench_async_poll(&pending);
  6084. /* while free pending slots in queue, submit ops */
  6085. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6086. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6087. 0, &times, numBlocks, &pending)) {
  6088. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6089. bench_size);
  6090. if (!bench_async_handle(&ret,
  6091. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6092. &times, &pending)) {
  6093. goto exit_sha512_256;
  6094. }
  6095. }
  6096. } /* for i */
  6097. RECORD_MULTI_VALUE_STATS();
  6098. } /* for times */
  6099. count += times;
  6100. times = 0;
  6101. do {
  6102. bench_async_poll(&pending);
  6103. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6104. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6105. 0, &times, numBlocks, &pending)) {
  6106. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6107. if (!bench_async_handle(&ret,
  6108. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6109. &times, &pending)) {
  6110. goto exit_sha512_256;
  6111. }
  6112. }
  6113. } /* for i */
  6114. } while (pending > 0);
  6115. } while (bench_stats_check(start)
  6116. #ifdef MULTI_VALUE_STATISTICS
  6117. || runs < minimum_runs
  6118. #endif
  6119. );
  6120. }
  6121. else {
  6122. bench_stats_start(&count, &start);
  6123. do {
  6124. for (times = 0; times < numBlocks; times++) {
  6125. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6126. useDeviceID ? devId : INVALID_DEVID);
  6127. if (ret == 0)
  6128. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6129. if (ret == 0)
  6130. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6131. if (ret != 0)
  6132. goto exit_sha512_256;
  6133. RECORD_MULTI_VALUE_STATS();
  6134. } /* for times */
  6135. count += times;
  6136. } while (bench_stats_check(start)
  6137. #ifdef MULTI_VALUE_STATISTICS
  6138. || runs < minimum_runs
  6139. #endif
  6140. );
  6141. }
  6142. exit_sha512_256:
  6143. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6144. start, ret);
  6145. #ifdef MULTI_VALUE_STATISTICS
  6146. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6147. #endif
  6148. exit:
  6149. if (WC_ARRAY_OK(hash)) {
  6150. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6151. wc_Sha512_256Free(hash[i]);
  6152. }
  6153. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6154. }
  6155. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6156. }
  6157. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6158. #endif /* WOLFSSL_SHA512 */
  6159. #ifdef WOLFSSL_SHA3
  6160. #ifndef WOLFSSL_NOSHA3_224
  6161. void bench_sha3_224(int useDeviceID)
  6162. {
  6163. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6164. sizeof(wc_Sha3), HEAP_HINT);
  6165. double start;
  6166. int ret = 0, i, count = 0, times, pending = 0;
  6167. DECLARE_MULTI_VALUE_STATS_VARS()
  6168. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6169. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6170. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6171. sizeof(wc_Sha3), HEAP_HINT);
  6172. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6173. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6174. if (digest_stream) {
  6175. /* init keys */
  6176. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6177. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6178. useDeviceID ? devId : INVALID_DEVID);
  6179. if (ret != 0) {
  6180. printf("InitSha3_224 failed, ret = %d\n", ret);
  6181. goto exit;
  6182. }
  6183. }
  6184. bench_stats_start(&count, &start);
  6185. do {
  6186. for (times = 0; times < numBlocks || pending > 0; ) {
  6187. bench_async_poll(&pending);
  6188. /* while free pending slots in queue, submit ops */
  6189. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6190. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6191. 0, &times, numBlocks, &pending)) {
  6192. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6193. bench_size);
  6194. if (!bench_async_handle(&ret,
  6195. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6196. &times, &pending)) {
  6197. goto exit_sha3_224;
  6198. }
  6199. }
  6200. } /* for i */
  6201. RECORD_MULTI_VALUE_STATS();
  6202. } /* for times */
  6203. count += times;
  6204. times = 0;
  6205. do {
  6206. bench_async_poll(&pending);
  6207. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6208. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6209. 0, &times, numBlocks, &pending)) {
  6210. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6211. if (!bench_async_handle(&ret,
  6212. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6213. &times, &pending)) {
  6214. goto exit_sha3_224;
  6215. }
  6216. }
  6217. } /* for i */
  6218. } while (pending > 0);
  6219. } while (bench_stats_check(start)
  6220. #ifdef MULTI_VALUE_STATISTICS
  6221. || runs < minimum_runs
  6222. #endif
  6223. );
  6224. }
  6225. else {
  6226. bench_stats_start(&count, &start);
  6227. do {
  6228. for (times = 0; times < numBlocks; times++) {
  6229. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6230. useDeviceID ? devId : INVALID_DEVID);
  6231. if (ret == 0)
  6232. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6233. if (ret == 0)
  6234. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6235. if (ret != 0)
  6236. goto exit_sha3_224;
  6237. RECORD_MULTI_VALUE_STATS();
  6238. } /* for times */
  6239. count += times;
  6240. } while (bench_stats_check(start)
  6241. #ifdef MULTI_VALUE_STATISTICS
  6242. || runs < minimum_runs
  6243. #endif
  6244. );
  6245. }
  6246. exit_sha3_224:
  6247. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6248. start, ret);
  6249. #ifdef MULTI_VALUE_STATISTICS
  6250. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6251. #endif
  6252. exit:
  6253. if (WC_ARRAY_OK(hash)) {
  6254. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6255. wc_Sha3_224_Free(hash[i]);
  6256. }
  6257. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6258. }
  6259. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6260. }
  6261. #endif /* WOLFSSL_NOSHA3_224 */
  6262. #ifndef WOLFSSL_NOSHA3_256
  6263. void bench_sha3_256(int useDeviceID)
  6264. {
  6265. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6266. sizeof(wc_Sha3), HEAP_HINT);
  6267. double start;
  6268. DECLARE_MULTI_VALUE_STATS_VARS()
  6269. int ret = 0, i, count = 0, times, pending = 0;
  6270. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6271. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6272. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6273. sizeof(wc_Sha3), HEAP_HINT);
  6274. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6275. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6276. if (digest_stream) {
  6277. /* init keys */
  6278. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6279. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6280. useDeviceID ? devId : INVALID_DEVID);
  6281. if (ret != 0) {
  6282. printf("InitSha3_256 failed, ret = %d\n", ret);
  6283. goto exit;
  6284. }
  6285. }
  6286. bench_stats_start(&count, &start);
  6287. do {
  6288. for (times = 0; times < numBlocks || pending > 0; ) {
  6289. bench_async_poll(&pending);
  6290. /* while free pending slots in queue, submit ops */
  6291. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6292. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6293. 0, &times, numBlocks, &pending)) {
  6294. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6295. bench_size);
  6296. if (!bench_async_handle(&ret,
  6297. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6298. &times, &pending)) {
  6299. goto exit_sha3_256;
  6300. }
  6301. }
  6302. } /* for i */
  6303. RECORD_MULTI_VALUE_STATS();
  6304. } /* for times */
  6305. count += times;
  6306. times = 0;
  6307. do {
  6308. bench_async_poll(&pending);
  6309. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6310. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6311. 0, &times, numBlocks, &pending)) {
  6312. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6313. if (!bench_async_handle(&ret,
  6314. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6315. &times, &pending)) {
  6316. goto exit_sha3_256;
  6317. }
  6318. }
  6319. } /* for i */
  6320. } while (pending > 0);
  6321. } while (bench_stats_check(start)
  6322. #ifdef MULTI_VALUE_STATISTICS
  6323. || runs < minimum_runs
  6324. #endif
  6325. );
  6326. }
  6327. else {
  6328. bench_stats_start(&count, &start);
  6329. do {
  6330. for (times = 0; times < numBlocks; times++) {
  6331. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6332. useDeviceID ? devId : INVALID_DEVID);
  6333. if (ret == 0)
  6334. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6335. if (ret == 0)
  6336. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6337. if (ret != 0)
  6338. goto exit_sha3_256;
  6339. RECORD_MULTI_VALUE_STATS();
  6340. } /* for times */
  6341. count += times;
  6342. } while (bench_stats_check(start)
  6343. #ifdef MULTI_VALUE_STATISTICS
  6344. || runs < minimum_runs
  6345. #endif
  6346. );
  6347. }
  6348. exit_sha3_256:
  6349. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6350. start, ret);
  6351. #ifdef MULTI_VALUE_STATISTICS
  6352. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6353. #endif
  6354. exit:
  6355. if (WC_ARRAY_OK(hash)) {
  6356. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6357. wc_Sha3_256_Free(hash[i]);
  6358. }
  6359. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6360. }
  6361. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6362. }
  6363. #endif /* WOLFSSL_NOSHA3_256 */
  6364. #ifndef WOLFSSL_NOSHA3_384
  6365. void bench_sha3_384(int useDeviceID)
  6366. {
  6367. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6368. sizeof(wc_Sha3), HEAP_HINT);
  6369. double start;
  6370. int ret = 0, i, count = 0, times, pending = 0;
  6371. DECLARE_MULTI_VALUE_STATS_VARS()
  6372. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6373. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6374. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6375. sizeof(wc_Sha3), HEAP_HINT);
  6376. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6377. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6378. if (digest_stream) {
  6379. /* init keys */
  6380. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6381. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6382. useDeviceID ? devId : INVALID_DEVID);
  6383. if (ret != 0) {
  6384. printf("InitSha3_384 failed, ret = %d\n", ret);
  6385. goto exit;
  6386. }
  6387. }
  6388. bench_stats_start(&count, &start);
  6389. do {
  6390. for (times = 0; times < numBlocks || pending > 0; ) {
  6391. bench_async_poll(&pending);
  6392. /* while free pending slots in queue, submit ops */
  6393. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6394. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6395. 0, &times, numBlocks, &pending)) {
  6396. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6397. bench_size);
  6398. if (!bench_async_handle(&ret,
  6399. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6400. &times, &pending)) {
  6401. goto exit_sha3_384;
  6402. }
  6403. }
  6404. } /* for i */
  6405. RECORD_MULTI_VALUE_STATS();
  6406. } /* for times */
  6407. count += times;
  6408. times = 0;
  6409. do {
  6410. bench_async_poll(&pending);
  6411. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6412. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6413. 0, &times, numBlocks, &pending)) {
  6414. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6415. if (!bench_async_handle(&ret,
  6416. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6417. &times, &pending)) {
  6418. goto exit_sha3_384;
  6419. }
  6420. }
  6421. } /* for i */
  6422. } while (pending > 0);
  6423. } while (bench_stats_check(start)
  6424. #ifdef MULTI_VALUE_STATISTICS
  6425. || runs < minimum_runs
  6426. #endif
  6427. );
  6428. }
  6429. else {
  6430. bench_stats_start(&count, &start);
  6431. do {
  6432. for (times = 0; times < numBlocks; times++) {
  6433. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6434. useDeviceID ? devId : INVALID_DEVID);
  6435. if (ret == 0)
  6436. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6437. if (ret == 0)
  6438. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6439. if (ret != 0)
  6440. goto exit_sha3_384;
  6441. RECORD_MULTI_VALUE_STATS();
  6442. } /* for times */
  6443. count += times;
  6444. } while (bench_stats_check(start)
  6445. #ifdef MULTI_VALUE_STATISTICS
  6446. || runs < minimum_runs
  6447. #endif
  6448. );
  6449. }
  6450. exit_sha3_384:
  6451. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6452. start, ret);
  6453. #ifdef MULTI_VALUE_STATISTICS
  6454. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6455. #endif
  6456. exit:
  6457. if (WC_ARRAY_OK(hash)) {
  6458. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6459. wc_Sha3_384_Free(hash[i]);
  6460. }
  6461. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6462. }
  6463. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6464. }
  6465. #endif /* WOLFSSL_NOSHA3_384 */
  6466. #ifndef WOLFSSL_NOSHA3_512
  6467. void bench_sha3_512(int useDeviceID)
  6468. {
  6469. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6470. sizeof(wc_Sha3), HEAP_HINT);
  6471. double start;
  6472. int ret = 0, i, count = 0, times, pending = 0;
  6473. DECLARE_MULTI_VALUE_STATS_VARS()
  6474. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6475. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6476. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6477. sizeof(wc_Sha3), HEAP_HINT);
  6478. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6479. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6480. if (digest_stream) {
  6481. /* init keys */
  6482. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6483. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6484. useDeviceID ? devId : INVALID_DEVID);
  6485. if (ret != 0) {
  6486. printf("InitSha3_512 failed, ret = %d\n", ret);
  6487. goto exit;
  6488. }
  6489. }
  6490. bench_stats_start(&count, &start);
  6491. do {
  6492. for (times = 0; times < numBlocks || pending > 0; ) {
  6493. bench_async_poll(&pending);
  6494. /* while free pending slots in queue, submit ops */
  6495. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6496. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6497. 0, &times, numBlocks, &pending)) {
  6498. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6499. bench_size);
  6500. if (!bench_async_handle(&ret,
  6501. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6502. &times, &pending)) {
  6503. goto exit_sha3_512;
  6504. }
  6505. }
  6506. } /* for i */
  6507. RECORD_MULTI_VALUE_STATS();
  6508. } /* for times */
  6509. count += times;
  6510. times = 0;
  6511. do {
  6512. bench_async_poll(&pending);
  6513. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6514. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6515. 0, &times, numBlocks, &pending)) {
  6516. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6517. if (!bench_async_handle(&ret,
  6518. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6519. &times, &pending)) {
  6520. goto exit_sha3_512;
  6521. }
  6522. }
  6523. } /* for i */
  6524. } while (pending > 0);
  6525. } while (bench_stats_check(start)
  6526. #ifdef MULTI_VALUE_STATISTICS
  6527. || runs < minimum_runs
  6528. #endif
  6529. );
  6530. }
  6531. else {
  6532. bench_stats_start(&count, &start);
  6533. do {
  6534. for (times = 0; times < numBlocks; times++) {
  6535. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6536. useDeviceID ? devId : INVALID_DEVID);
  6537. if (ret == 0)
  6538. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6539. if (ret == 0)
  6540. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6541. if (ret != 0)
  6542. goto exit_sha3_512;
  6543. RECORD_MULTI_VALUE_STATS();
  6544. } /* for times */
  6545. count += times;
  6546. } while (bench_stats_check(start)
  6547. #ifdef MULTI_VALUE_STATISTICS
  6548. || runs < minimum_runs
  6549. #endif
  6550. );
  6551. }
  6552. exit_sha3_512:
  6553. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6554. start, ret);
  6555. #ifdef MULTI_VALUE_STATISTICS
  6556. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6557. #endif
  6558. exit:
  6559. if (WC_ARRAY_OK(hash)) {
  6560. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6561. wc_Sha3_512_Free(hash[i]);
  6562. }
  6563. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6564. }
  6565. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6566. }
  6567. #endif /* WOLFSSL_NOSHA3_512 */
  6568. #ifdef WOLFSSL_SHAKE128
  6569. void bench_shake128(int useDeviceID)
  6570. {
  6571. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6572. sizeof(wc_Shake), HEAP_HINT);
  6573. double start;
  6574. int ret = 0, i, count = 0, times, pending = 0;
  6575. DECLARE_MULTI_VALUE_STATS_VARS()
  6576. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6577. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6578. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6579. sizeof(wc_Shake), HEAP_HINT);
  6580. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6581. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6582. if (digest_stream) {
  6583. /* init keys */
  6584. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6585. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6586. useDeviceID ? devId : INVALID_DEVID);
  6587. if (ret != 0) {
  6588. printf("InitShake128 failed, ret = %d\n", ret);
  6589. goto exit;
  6590. }
  6591. }
  6592. bench_stats_start(&count, &start);
  6593. do {
  6594. for (times = 0; times < numBlocks || pending > 0; ) {
  6595. bench_async_poll(&pending);
  6596. /* while free pending slots in queue, submit ops */
  6597. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6598. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6599. 0, &times, numBlocks, &pending)) {
  6600. ret = wc_Shake128_Update(hash[i], bench_plain,
  6601. bench_size);
  6602. if (!bench_async_handle(&ret,
  6603. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6604. &times, &pending)) {
  6605. goto exit_shake128;
  6606. }
  6607. }
  6608. } /* for i */
  6609. RECORD_MULTI_VALUE_STATS();
  6610. } /* for times */
  6611. count += times;
  6612. times = 0;
  6613. do {
  6614. bench_async_poll(&pending);
  6615. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6616. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6617. 0, &times, numBlocks, &pending)) {
  6618. ret = wc_Shake128_Final(hash[i], digest[i],
  6619. WC_SHA3_128_BLOCK_SIZE);
  6620. if (!bench_async_handle(&ret,
  6621. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6622. &times, &pending)) {
  6623. goto exit_shake128;
  6624. }
  6625. }
  6626. } /* for i */
  6627. } while (pending > 0);
  6628. } while (bench_stats_check(start)
  6629. #ifdef MULTI_VALUE_STATISTICS
  6630. || runs < minimum_runs
  6631. #endif
  6632. );
  6633. }
  6634. else {
  6635. bench_stats_start(&count, &start);
  6636. do {
  6637. for (times = 0; times < numBlocks; times++) {
  6638. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6639. useDeviceID ? devId : INVALID_DEVID);
  6640. if (ret == 0)
  6641. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6642. if (ret == 0)
  6643. ret = wc_Shake128_Final(hash[0], digest[0],
  6644. WC_SHA3_128_BLOCK_SIZE);
  6645. if (ret != 0)
  6646. goto exit_shake128;
  6647. RECORD_MULTI_VALUE_STATS();
  6648. } /* for times */
  6649. count += times;
  6650. } while (bench_stats_check(start)
  6651. #ifdef MULTI_VALUE_STATISTICS
  6652. || runs < minimum_runs
  6653. #endif
  6654. );
  6655. }
  6656. exit_shake128:
  6657. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6658. start, ret);
  6659. #ifdef MULTI_VALUE_STATISTICS
  6660. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6661. #endif
  6662. exit:
  6663. if (WC_ARRAY_OK(hash)) {
  6664. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6665. wc_Shake128_Free(hash[i]);
  6666. }
  6667. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6668. }
  6669. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6670. }
  6671. #endif /* WOLFSSL_SHAKE128 */
  6672. #ifdef WOLFSSL_SHAKE256
  6673. void bench_shake256(int useDeviceID)
  6674. {
  6675. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6676. sizeof(wc_Shake), HEAP_HINT);
  6677. double start;
  6678. int ret = 0, i, count = 0, times, pending = 0;
  6679. DECLARE_MULTI_VALUE_STATS_VARS()
  6680. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6681. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6682. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6683. sizeof(wc_Shake), HEAP_HINT);
  6684. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6685. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6686. if (digest_stream) {
  6687. /* init keys */
  6688. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6689. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6690. useDeviceID ? devId : INVALID_DEVID);
  6691. if (ret != 0) {
  6692. printf("InitShake256 failed, ret = %d\n", ret);
  6693. goto exit;
  6694. }
  6695. }
  6696. bench_stats_start(&count, &start);
  6697. do {
  6698. for (times = 0; times < numBlocks || pending > 0; ) {
  6699. bench_async_poll(&pending);
  6700. /* while free pending slots in queue, submit ops */
  6701. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6702. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6703. 0, &times, numBlocks, &pending)) {
  6704. ret = wc_Shake256_Update(hash[i], bench_plain,
  6705. bench_size);
  6706. if (!bench_async_handle(&ret,
  6707. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6708. &times, &pending)) {
  6709. goto exit_shake256;
  6710. }
  6711. }
  6712. } /* for i */
  6713. RECORD_MULTI_VALUE_STATS();
  6714. } /* for times */
  6715. count += times;
  6716. times = 0;
  6717. do {
  6718. bench_async_poll(&pending);
  6719. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6720. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6721. 0, &times, numBlocks, &pending)) {
  6722. ret = wc_Shake256_Final(hash[i], digest[i],
  6723. WC_SHA3_256_BLOCK_SIZE);
  6724. if (!bench_async_handle(&ret,
  6725. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6726. &times, &pending)) {
  6727. goto exit_shake256;
  6728. }
  6729. }
  6730. } /* for i */
  6731. } while (pending > 0);
  6732. } while (bench_stats_check(start)
  6733. #ifdef MULTI_VALUE_STATISTICS
  6734. || runs < minimum_runs
  6735. #endif
  6736. );
  6737. }
  6738. else {
  6739. bench_stats_start(&count, &start);
  6740. do {
  6741. for (times = 0; times < numBlocks; times++) {
  6742. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6743. useDeviceID ? devId : INVALID_DEVID);
  6744. if (ret == 0)
  6745. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6746. if (ret == 0)
  6747. ret = wc_Shake256_Final(hash[0], digest[0],
  6748. WC_SHA3_256_BLOCK_SIZE);
  6749. if (ret != 0)
  6750. goto exit_shake256;
  6751. RECORD_MULTI_VALUE_STATS();
  6752. } /* for times */
  6753. count += times;
  6754. } while (bench_stats_check(start)
  6755. #ifdef MULTI_VALUE_STATISTICS
  6756. || runs < minimum_runs
  6757. #endif
  6758. );
  6759. }
  6760. exit_shake256:
  6761. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6762. start, ret);
  6763. #ifdef MULTI_VALUE_STATISTICS
  6764. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6765. #endif
  6766. exit:
  6767. if (WC_ARRAY_OK(hash)) {
  6768. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6769. wc_Shake256_Free(hash[i]);
  6770. }
  6771. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6772. }
  6773. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6774. }
  6775. #endif /* WOLFSSL_SHAKE256 */
  6776. #endif
  6777. #ifdef WOLFSSL_SM3
  6778. void bench_sm3(int useDeviceID)
  6779. {
  6780. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6781. sizeof(wc_Sm3), HEAP_HINT);
  6782. double start;
  6783. int ret = 0, i, count = 0, times, pending = 0;
  6784. DECLARE_MULTI_VALUE_STATS_VARS()
  6785. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6786. HEAP_HINT);
  6787. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6788. sizeof(wc_Sm3), HEAP_HINT);
  6789. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6790. HEAP_HINT);
  6791. if (digest_stream) {
  6792. /* init keys */
  6793. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6794. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6795. useDeviceID ? devId: INVALID_DEVID);
  6796. if (ret != 0) {
  6797. printf("InitSm3 failed, ret = %d\n", ret);
  6798. goto exit;
  6799. }
  6800. }
  6801. bench_stats_start(&count, &start);
  6802. do {
  6803. for (times = 0; times < numBlocks || pending > 0; ) {
  6804. bench_async_poll(&pending);
  6805. /* while free pending slots in queue, submit ops */
  6806. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6807. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6808. 0, &times, numBlocks, &pending)) {
  6809. ret = wc_Sm3Update(hash[i], bench_plain,
  6810. bench_size);
  6811. if (!bench_async_handle(&ret,
  6812. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6813. goto exit_sm3;
  6814. }
  6815. }
  6816. } /* for i */
  6817. RECORD_MULTI_VALUE_STATS();
  6818. } /* for times */
  6819. count += times;
  6820. times = 0;
  6821. do {
  6822. bench_async_poll(&pending);
  6823. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6824. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6825. 0, &times, numBlocks, &pending)) {
  6826. ret = wc_Sm3Final(hash[i], digest[i]);
  6827. if (!bench_async_handle(&ret,
  6828. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6829. goto exit_sm3;
  6830. }
  6831. }
  6832. } /* for i */
  6833. } while (pending > 0);
  6834. } while (bench_stats_check(start)
  6835. #ifdef MULTI_VALUE_STATISTICS
  6836. || runs < minimum_runs
  6837. #endif
  6838. );
  6839. }
  6840. else {
  6841. bench_stats_start(&count, &start);
  6842. do {
  6843. for (times = 0; times < numBlocks; times++) {
  6844. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6845. useDeviceID ? devId: INVALID_DEVID);
  6846. if (ret == 0)
  6847. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6848. if (ret == 0)
  6849. ret = wc_Sm3Final(hash[0], digest[0]);
  6850. if (ret != 0)
  6851. goto exit_sm3;
  6852. RECORD_MULTI_VALUE_STATS();
  6853. } /* for times */
  6854. count += times;
  6855. } while (bench_stats_check(start)
  6856. #ifdef MULTI_VALUE_STATISTICS
  6857. || runs < minimum_runs
  6858. #endif
  6859. );
  6860. }
  6861. exit_sm3:
  6862. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6863. #ifdef MULTI_VALUE_STATISTICS
  6864. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6865. #endif
  6866. exit:
  6867. if (WC_ARRAY_OK(hash)) {
  6868. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6869. wc_Sm3Free(hash[i]);
  6870. }
  6871. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6872. }
  6873. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6874. }
  6875. #endif
  6876. #ifdef WOLFSSL_RIPEMD
  6877. void bench_ripemd(void)
  6878. {
  6879. RipeMd hash;
  6880. byte digest[RIPEMD_DIGEST_SIZE];
  6881. double start;
  6882. int i, count, ret = 0;
  6883. DECLARE_MULTI_VALUE_STATS_VARS()
  6884. if (digest_stream) {
  6885. ret = wc_InitRipeMd(&hash);
  6886. if (ret != 0) {
  6887. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6888. return;
  6889. }
  6890. bench_stats_start(&count, &start);
  6891. do {
  6892. for (i = 0; i < numBlocks; i++) {
  6893. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6894. if (ret != 0) {
  6895. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6896. return;
  6897. }
  6898. RECORD_MULTI_VALUE_STATS();
  6899. }
  6900. ret = wc_RipeMdFinal(&hash, digest);
  6901. if (ret != 0) {
  6902. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6903. return;
  6904. }
  6905. count += i;
  6906. } while (bench_stats_check(start)
  6907. #ifdef MULTI_VALUE_STATISTICS
  6908. || runs < minimum_runs
  6909. #endif
  6910. );
  6911. }
  6912. else {
  6913. bench_stats_start(&count, &start);
  6914. do {
  6915. for (i = 0; i < numBlocks; i++) {
  6916. ret = wc_InitRipeMd(&hash);
  6917. if (ret != 0) {
  6918. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6919. return;
  6920. }
  6921. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6922. if (ret != 0) {
  6923. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6924. return;
  6925. }
  6926. ret = wc_RipeMdFinal(&hash, digest);
  6927. if (ret != 0) {
  6928. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6929. return;
  6930. }
  6931. RECORD_MULTI_VALUE_STATS();
  6932. }
  6933. count += i;
  6934. } while (bench_stats_check(start)
  6935. #ifdef MULTI_VALUE_STATISTICS
  6936. || runs < minimum_runs
  6937. #endif
  6938. );
  6939. }
  6940. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  6941. #ifdef MULTI_VALUE_STATISTICS
  6942. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6943. #endif
  6944. return;
  6945. }
  6946. #endif
  6947. #ifdef HAVE_BLAKE2
  6948. void bench_blake2b(void)
  6949. {
  6950. Blake2b b2b;
  6951. byte digest[64];
  6952. double start;
  6953. int ret = 0, i, count;
  6954. DECLARE_MULTI_VALUE_STATS_VARS()
  6955. if (digest_stream) {
  6956. ret = wc_InitBlake2b(&b2b, 64);
  6957. if (ret != 0) {
  6958. printf("InitBlake2b failed, ret = %d\n", ret);
  6959. return;
  6960. }
  6961. bench_stats_start(&count, &start);
  6962. do {
  6963. for (i = 0; i < numBlocks; i++) {
  6964. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  6965. if (ret != 0) {
  6966. printf("Blake2bUpdate failed, ret = %d\n", ret);
  6967. return;
  6968. }
  6969. RECORD_MULTI_VALUE_STATS();
  6970. }
  6971. ret = wc_Blake2bFinal(&b2b, digest, 64);
  6972. if (ret != 0) {
  6973. printf("Blake2bFinal failed, ret = %d\n", ret);
  6974. return;
  6975. }
  6976. count += i;
  6977. } while (bench_stats_check(start)
  6978. #ifdef MULTI_VALUE_STATISTICS
  6979. || runs < minimum_runs
  6980. #endif
  6981. );
  6982. }
  6983. else {
  6984. bench_stats_start(&count, &start);
  6985. do {
  6986. for (i = 0; i < numBlocks; i++) {
  6987. ret = wc_InitBlake2b(&b2b, 64);
  6988. if (ret != 0) {
  6989. printf("InitBlake2b failed, ret = %d\n", ret);
  6990. return;
  6991. }
  6992. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  6993. if (ret != 0) {
  6994. printf("Blake2bUpdate failed, ret = %d\n", ret);
  6995. return;
  6996. }
  6997. ret = wc_Blake2bFinal(&b2b, digest, 64);
  6998. if (ret != 0) {
  6999. printf("Blake2bFinal failed, ret = %d\n", ret);
  7000. return;
  7001. }
  7002. RECORD_MULTI_VALUE_STATS();
  7003. }
  7004. count += i;
  7005. } while (bench_stats_check(start)
  7006. #ifdef MULTI_VALUE_STATISTICS
  7007. || runs < minimum_runs
  7008. #endif
  7009. );
  7010. }
  7011. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7012. #ifdef MULTI_VALUE_STATISTICS
  7013. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7014. #endif
  7015. }
  7016. #endif
  7017. #if defined(HAVE_BLAKE2S)
  7018. void bench_blake2s(void)
  7019. {
  7020. Blake2s b2s;
  7021. byte digest[32];
  7022. double start;
  7023. int ret = 0, i, count;
  7024. DECLARE_MULTI_VALUE_STATS_VARS()
  7025. if (digest_stream) {
  7026. ret = wc_InitBlake2s(&b2s, 32);
  7027. if (ret != 0) {
  7028. printf("InitBlake2s failed, ret = %d\n", ret);
  7029. return;
  7030. }
  7031. bench_stats_start(&count, &start);
  7032. do {
  7033. for (i = 0; i < numBlocks; i++) {
  7034. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7035. if (ret != 0) {
  7036. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7037. return;
  7038. }
  7039. RECORD_MULTI_VALUE_STATS();
  7040. }
  7041. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7042. if (ret != 0) {
  7043. printf("Blake2sFinal failed, ret = %d\n", ret);
  7044. return;
  7045. }
  7046. count += i;
  7047. } while (bench_stats_check(start)
  7048. #ifdef MULTI_VALUE_STATISTICS
  7049. || runs < minimum_runs
  7050. #endif
  7051. );
  7052. }
  7053. else {
  7054. bench_stats_start(&count, &start);
  7055. do {
  7056. for (i = 0; i < numBlocks; i++) {
  7057. ret = wc_InitBlake2s(&b2s, 32);
  7058. if (ret != 0) {
  7059. printf("InitBlake2b failed, ret = %d\n", ret);
  7060. return;
  7061. }
  7062. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7063. if (ret != 0) {
  7064. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7065. return;
  7066. }
  7067. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7068. if (ret != 0) {
  7069. printf("Blake2sFinal failed, ret = %d\n", ret);
  7070. return;
  7071. }
  7072. RECORD_MULTI_VALUE_STATS();
  7073. }
  7074. count += i;
  7075. } while (bench_stats_check(start)
  7076. #ifdef MULTI_VALUE_STATISTICS
  7077. || runs < minimum_runs
  7078. #endif
  7079. );
  7080. }
  7081. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7082. #ifdef MULTI_VALUE_STATISTICS
  7083. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7084. #endif
  7085. }
  7086. #endif
  7087. #ifdef WOLFSSL_CMAC
  7088. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7089. {
  7090. Cmac cmac;
  7091. byte digest[AES_BLOCK_SIZE];
  7092. word32 digestSz = sizeof(digest);
  7093. double start;
  7094. int ret, i, count;
  7095. DECLARE_MULTI_VALUE_STATS_VARS()
  7096. #ifdef WOLFSSL_SECO_CAAM
  7097. unsigned int keyID;
  7098. int keyGroup = 1; /* group one was chosen arbitrarily */
  7099. int keyInfo = CAAM_KEY_TRANSIENT;
  7100. int keyType = CAAM_KEYTYPE_AES128;
  7101. byte pubKey[AES_256_KEY_SIZE];
  7102. if (keySz == AES_256_KEY_SIZE) {
  7103. keyType = CAAM_KEYTYPE_AES256;
  7104. }
  7105. if (useDeviceID &&
  7106. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7107. keyInfo, &keyID) != 0) {
  7108. printf("Error generating key in hsm\n");
  7109. return;
  7110. }
  7111. #endif
  7112. (void)useDeviceID;
  7113. bench_stats_start(&count, &start);
  7114. do {
  7115. #ifdef HAVE_FIPS
  7116. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7117. #else
  7118. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7119. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7120. #endif
  7121. if (ret != 0) {
  7122. printf("InitCmac failed, ret = %d\n", ret);
  7123. return;
  7124. }
  7125. #ifdef WOLFSSL_SECO_CAAM
  7126. if (useDeviceID) {
  7127. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7128. }
  7129. #endif
  7130. for (i = 0; i < numBlocks; i++) {
  7131. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7132. if (ret != 0) {
  7133. printf("CmacUpdate failed, ret = %d\n", ret);
  7134. return;
  7135. }
  7136. RECORD_MULTI_VALUE_STATS();
  7137. }
  7138. /* Note: final force zero's the Cmac struct */
  7139. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7140. if (ret != 0) {
  7141. printf("CmacFinal failed, ret = %d\n", ret);
  7142. return;
  7143. }
  7144. count += i;
  7145. } while (bench_stats_check(start)
  7146. #ifdef MULTI_VALUE_STATISTICS
  7147. || runs < minimum_runs
  7148. #endif
  7149. );
  7150. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7151. #ifdef MULTI_VALUE_STATISTICS
  7152. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7153. #endif
  7154. }
  7155. void bench_cmac(int useDeviceID)
  7156. {
  7157. #ifdef WOLFSSL_AES_128
  7158. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7159. #endif
  7160. #ifdef WOLFSSL_AES_256
  7161. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7162. #endif
  7163. }
  7164. #endif /* WOLFSSL_CMAC */
  7165. #ifdef HAVE_SCRYPT
  7166. void bench_scrypt(void)
  7167. {
  7168. byte derived[64];
  7169. double start;
  7170. int ret, i, count;
  7171. DECLARE_MULTI_VALUE_STATS_VARS()
  7172. bench_stats_start(&count, &start);
  7173. do {
  7174. for (i = 0; i < scryptCnt; i++) {
  7175. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7176. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7177. sizeof(derived));
  7178. if (ret != 0) {
  7179. printf("scrypt failed, ret = %d\n", ret);
  7180. goto exit;
  7181. }
  7182. RECORD_MULTI_VALUE_STATS();
  7183. }
  7184. count += i;
  7185. } while (bench_stats_check(start)
  7186. #ifdef MULTI_VALUE_STATISTICS
  7187. || runs < minimum_runs
  7188. #endif
  7189. );
  7190. exit:
  7191. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7192. #ifdef MULTI_VALUE_STATISTICS
  7193. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7194. #endif
  7195. }
  7196. #endif /* HAVE_SCRYPT */
  7197. #ifndef NO_HMAC
  7198. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7199. const byte* key, word32 keySz, const char* label)
  7200. {
  7201. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7202. sizeof(Hmac), HEAP_HINT);
  7203. double start;
  7204. int ret = 0, i, count = 0, times, pending = 0;
  7205. DECLARE_MULTI_VALUE_STATS_VARS()
  7206. #ifdef WOLFSSL_ASYNC_CRYPT
  7207. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7208. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7209. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7210. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7211. #else
  7212. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7213. #endif
  7214. (void)digestSz;
  7215. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7216. sizeof(Hmac), HEAP_HINT);
  7217. /* init keys */
  7218. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7219. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7220. useDeviceID ? devId : INVALID_DEVID);
  7221. if (ret != 0) {
  7222. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7223. goto exit;
  7224. }
  7225. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7226. if (ret != 0) {
  7227. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7228. goto exit;
  7229. }
  7230. }
  7231. bench_stats_start(&count, &start);
  7232. do {
  7233. for (times = 0; times < numBlocks || pending > 0; ) {
  7234. bench_async_poll(&pending);
  7235. /* while free pending slots in queue, submit ops */
  7236. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7237. if (bench_async_check(&ret,
  7238. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7239. &times, numBlocks, &pending)) {
  7240. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7241. if (!bench_async_handle(&ret,
  7242. BENCH_ASYNC_GET_DEV(hmac[i]),
  7243. 0, &times, &pending)) {
  7244. goto exit_hmac;
  7245. }
  7246. }
  7247. } /* for i */
  7248. } /* for times */
  7249. count += times;
  7250. times = 0;
  7251. do {
  7252. bench_async_poll(&pending);
  7253. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7254. if (bench_async_check(&ret,
  7255. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7256. &times, numBlocks, &pending)) {
  7257. ret = wc_HmacFinal(hmac[i], digest[i]);
  7258. if (!bench_async_handle(&ret,
  7259. BENCH_ASYNC_GET_DEV(hmac[i]),
  7260. 0, &times, &pending)) {
  7261. goto exit_hmac;
  7262. }
  7263. }
  7264. RECORD_MULTI_VALUE_STATS();
  7265. } /* for i */
  7266. } while (pending > 0);
  7267. } while (bench_stats_check(start)
  7268. #ifdef MULTI_VALUE_STATISTICS
  7269. || runs < minimum_runs
  7270. #endif
  7271. );
  7272. exit_hmac:
  7273. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7274. #ifdef MULTI_VALUE_STATISTICS
  7275. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7276. #endif
  7277. exit:
  7278. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7279. wc_HmacFree(hmac[i]);
  7280. }
  7281. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7282. #ifdef WOLFSSL_ASYNC_CRYPT
  7283. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7284. #endif
  7285. }
  7286. #ifndef NO_MD5
  7287. void bench_hmac_md5(int useDeviceID)
  7288. {
  7289. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7290. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7291. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7292. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7293. "HMAC-MD5");
  7294. }
  7295. #endif /* NO_MD5 */
  7296. #ifndef NO_SHA
  7297. void bench_hmac_sha(int useDeviceID)
  7298. {
  7299. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7300. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7301. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7302. 0x0b, 0x0b, 0x0b, 0x0b };
  7303. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7304. "HMAC-SHA");
  7305. }
  7306. #endif /* NO_SHA */
  7307. #ifdef WOLFSSL_SHA224
  7308. void bench_hmac_sha224(int useDeviceID)
  7309. {
  7310. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7311. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7312. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7313. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7314. 0x0b, 0x0b, 0x0b, 0x0b };
  7315. bench_hmac(useDeviceID, WC_SHA224,
  7316. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7317. "HMAC-SHA224");
  7318. }
  7319. #endif /* WOLFSSL_SHA224 */
  7320. #ifndef NO_SHA256
  7321. void bench_hmac_sha256(int useDeviceID)
  7322. {
  7323. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7324. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7325. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7326. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7327. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7328. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7329. "HMAC-SHA256");
  7330. }
  7331. #endif /* NO_SHA256 */
  7332. #ifdef WOLFSSL_SHA384
  7333. void bench_hmac_sha384(int useDeviceID)
  7334. {
  7335. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7336. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7337. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7338. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7339. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7340. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7341. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7342. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7343. "HMAC-SHA384");
  7344. }
  7345. #endif /* WOLFSSL_SHA384 */
  7346. #ifdef WOLFSSL_SHA512
  7347. void bench_hmac_sha512(int useDeviceID)
  7348. {
  7349. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7350. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7351. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7352. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7353. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7354. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7355. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7356. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7357. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7358. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7359. "HMAC-SHA512");
  7360. }
  7361. #endif /* WOLFSSL_SHA512 */
  7362. #ifndef NO_PWDBASED
  7363. void bench_pbkdf2(void)
  7364. {
  7365. double start;
  7366. int ret = 0, count = 0;
  7367. const char* passwd32 = "passwordpasswordpasswordpassword";
  7368. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7369. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7370. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7371. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7372. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7373. byte derived[32];
  7374. DECLARE_MULTI_VALUE_STATS_VARS()
  7375. bench_stats_start(&count, &start);
  7376. PRIVATE_KEY_UNLOCK();
  7377. do {
  7378. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7379. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7380. count++;
  7381. RECORD_MULTI_VALUE_STATS();
  7382. } while (bench_stats_check(start)
  7383. #ifdef MULTI_VALUE_STATISTICS
  7384. || runs < minimum_runs
  7385. #endif
  7386. );
  7387. PRIVATE_KEY_LOCK();
  7388. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7389. #ifdef MULTI_VALUE_STATISTICS
  7390. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7391. #endif
  7392. }
  7393. #endif /* !NO_PWDBASED */
  7394. #endif /* NO_HMAC */
  7395. #ifdef WOLFSSL_SIPHASH
  7396. void bench_siphash(void)
  7397. {
  7398. double start;
  7399. int ret = 0, count;
  7400. const char* passwd16 = "passwordpassword";
  7401. byte out[16];
  7402. int i;
  7403. DECLARE_MULTI_VALUE_STATS_VARS()
  7404. bench_stats_start(&count, &start);
  7405. do {
  7406. for (i = 0; i < numBlocks; i++) {
  7407. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7408. out, 8);
  7409. RECORD_MULTI_VALUE_STATS();
  7410. }
  7411. count += i;
  7412. } while (bench_stats_check(start)
  7413. #ifdef MULTI_VALUE_STATISTICS
  7414. || runs < minimum_runs
  7415. #endif
  7416. );
  7417. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7418. #ifdef MULTI_VALUE_STATISTICS
  7419. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7420. #endif
  7421. RESET_MULTI_VALUE_STATS_VARS();
  7422. bench_stats_start(&count, &start);
  7423. do {
  7424. for (i = 0; i < numBlocks; i++) {
  7425. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7426. out, 16);
  7427. RECORD_MULTI_VALUE_STATS();
  7428. }
  7429. count += i;
  7430. } while (bench_stats_check(start)
  7431. #ifdef MULTI_VALUE_STATISTICS
  7432. || runs < minimum_runs
  7433. #endif
  7434. );
  7435. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7436. #ifdef MULTI_VALUE_STATISTICS
  7437. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7438. #endif
  7439. }
  7440. #endif
  7441. #ifdef WC_SRTP_KDF
  7442. void bench_srtpkdf(void)
  7443. {
  7444. double start;
  7445. int count;
  7446. int ret = 0;
  7447. byte keyE[32];
  7448. byte keyA[20];
  7449. byte keyS[14];
  7450. const byte *key = bench_key_buf;
  7451. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7452. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7453. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7454. int kdrIdx = 0;
  7455. int i;
  7456. DECLARE_MULTI_VALUE_STATS_VARS()
  7457. bench_stats_start(&count, &start);
  7458. PRIVATE_KEY_UNLOCK();
  7459. do {
  7460. for (i = 0; i < numBlocks; i++) {
  7461. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7462. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7463. keyS, sizeof(keyS));
  7464. RECORD_MULTI_VALUE_STATS();
  7465. }
  7466. count += i;
  7467. } while (bench_stats_check(start)
  7468. #ifdef MULTI_VALUE_STATISTICS
  7469. || runs < minimum_runs
  7470. #endif
  7471. );
  7472. PRIVATE_KEY_LOCK();
  7473. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7474. #ifdef MULTI_VALUE_STATISTICS
  7475. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7476. #endif
  7477. RESET_MULTI_VALUE_STATS_VARS();
  7478. bench_stats_start(&count, &start);
  7479. PRIVATE_KEY_UNLOCK();
  7480. do {
  7481. for (i = 0; i < numBlocks; i++) {
  7482. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7483. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7484. keyS, sizeof(keyS));
  7485. RECORD_MULTI_VALUE_STATS();
  7486. }
  7487. count += i;
  7488. } while (bench_stats_check(start)
  7489. #ifdef MULTI_VALUE_STATISTICS
  7490. || runs < minimum_runs
  7491. #endif
  7492. );
  7493. PRIVATE_KEY_LOCK();
  7494. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7495. #ifdef MULTI_VALUE_STATISTICS
  7496. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7497. #endif
  7498. RESET_MULTI_VALUE_STATS_VARS();
  7499. bench_stats_start(&count, &start);
  7500. PRIVATE_KEY_UNLOCK();
  7501. do {
  7502. for (i = 0; i < numBlocks; i++) {
  7503. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7504. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7505. keyS, sizeof(keyS));
  7506. RECORD_MULTI_VALUE_STATS();
  7507. }
  7508. count += i;
  7509. } while (bench_stats_check(start)
  7510. #ifdef MULTI_VALUE_STATISTICS
  7511. || runs < minimum_runs
  7512. #endif
  7513. );
  7514. PRIVATE_KEY_LOCK();
  7515. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7516. #ifdef MULTI_VALUE_STATISTICS
  7517. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7518. #endif
  7519. RESET_MULTI_VALUE_STATS_VARS();
  7520. bench_stats_start(&count, &start);
  7521. PRIVATE_KEY_UNLOCK();
  7522. do {
  7523. for (i = 0; i < numBlocks; i++) {
  7524. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7525. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7526. keyS, sizeof(keyS));
  7527. RECORD_MULTI_VALUE_STATS();
  7528. }
  7529. count += i;
  7530. } while (bench_stats_check(start)
  7531. #ifdef MULTI_VALUE_STATISTICS
  7532. || runs < minimum_runs
  7533. #endif
  7534. );
  7535. PRIVATE_KEY_LOCK();
  7536. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7537. #ifdef MULTI_VALUE_STATISTICS
  7538. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7539. #endif
  7540. }
  7541. #endif
  7542. #ifndef NO_RSA
  7543. #if defined(WOLFSSL_KEY_GEN)
  7544. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7545. {
  7546. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7547. sizeof(RsaKey), HEAP_HINT);
  7548. double start = 0;
  7549. int ret = 0, i, count = 0, times, pending = 0;
  7550. const long rsa_e_val = WC_RSA_EXPONENT;
  7551. const char**desc = bench_desc_words[lng_index];
  7552. DECLARE_MULTI_VALUE_STATS_VARS()
  7553. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7554. sizeof(RsaKey), HEAP_HINT);
  7555. bench_stats_start(&count, &start);
  7556. do {
  7557. /* while free pending slots in queue, submit ops */
  7558. for (times = 0; times < genTimes || pending > 0; ) {
  7559. bench_async_poll(&pending);
  7560. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7561. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7562. 0, &times, genTimes, &pending)) {
  7563. wc_FreeRsaKey(genKey[i]);
  7564. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7565. if (ret < 0) {
  7566. goto exit;
  7567. }
  7568. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7569. &gRng);
  7570. if (!bench_async_handle(&ret,
  7571. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7572. &times, &pending)) {
  7573. goto exit;
  7574. }
  7575. }
  7576. } /* for i */
  7577. RECORD_MULTI_VALUE_STATS();
  7578. } /* for times */
  7579. count += times;
  7580. } while (bench_stats_check(start)
  7581. #ifdef MULTI_VALUE_STATISTICS
  7582. || runs < minimum_runs
  7583. #endif
  7584. );
  7585. exit:
  7586. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7587. start, ret);
  7588. #ifdef MULTI_VALUE_STATISTICS
  7589. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7590. #endif
  7591. /* cleanup */
  7592. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7593. wc_FreeRsaKey(genKey[i]);
  7594. }
  7595. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7596. }
  7597. void bench_rsaKeyGen(int useDeviceID)
  7598. {
  7599. int k;
  7600. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  7601. static const word32 keySizes[2] = {1024, 2048};
  7602. #else
  7603. static const word32 keySizes[1] = {2048};
  7604. #endif
  7605. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7606. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7607. }
  7608. }
  7609. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7610. {
  7611. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7612. }
  7613. #endif /* WOLFSSL_KEY_GEN */
  7614. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7615. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7616. #if defined(WOLFSSL_MDK_SHELL)
  7617. static char *certRSAname = "certs/rsa2048.der";
  7618. /* set by shell command */
  7619. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7620. #elif defined(FREESCALE_MQX)
  7621. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7622. #else
  7623. static const char *certRSAname = "certs/rsa2048.der";
  7624. #endif
  7625. #endif
  7626. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7627. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7628. #if defined(USE_CERT_BUFFERS_2048)
  7629. static const unsigned char rsa_2048_sig[] = {
  7630. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7631. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7632. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7633. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7634. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7635. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7636. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7637. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7638. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7639. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7640. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7641. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7642. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7643. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7644. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7645. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7646. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7647. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7648. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7649. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7650. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7651. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7652. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7653. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7654. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7655. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7656. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7657. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7658. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7659. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7660. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7661. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7662. };
  7663. #elif defined(USE_CERT_BUFFERS_3072)
  7664. static const unsigned char rsa_3072_sig[] = {
  7665. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7666. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7667. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7668. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7669. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7670. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7671. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7672. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7673. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7674. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7675. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7676. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7677. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7678. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7679. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7680. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7681. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7682. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7683. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7684. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7685. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7686. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7687. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7688. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7689. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7690. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7691. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7692. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7693. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7694. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7695. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7696. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7697. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7698. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7699. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7700. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7701. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7702. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7703. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7704. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7705. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7706. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7707. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7708. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7709. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7710. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7711. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7712. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7713. };
  7714. #else
  7715. #error Not Supported Yet!
  7716. #endif
  7717. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7718. static void bench_rsa_helper(int useDeviceID,
  7719. WC_ARRAY_ARG(rsaKey,
  7720. RsaKey,
  7721. BENCH_MAX_PENDING,
  7722. sizeof(RsaKey)),
  7723. word32 rsaKeySz)
  7724. {
  7725. int ret = 0, i, times, count = 0, pending = 0;
  7726. word32 idx = 0;
  7727. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7728. const char* messageStr = TEST_STRING;
  7729. const int len = (int)TEST_STRING_SZ;
  7730. #endif
  7731. double start = 0.0F;
  7732. const char**desc = bench_desc_words[lng_index];
  7733. DECLARE_MULTI_VALUE_STATS_VARS()
  7734. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7735. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7736. #endif
  7737. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7738. rsaKeySz, HEAP_HINT);
  7739. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7740. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7741. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7742. rsaKeySz, HEAP_HINT);
  7743. #else
  7744. byte* out[BENCH_MAX_PENDING];
  7745. #endif
  7746. XMEMSET(out, 0, sizeof(out));
  7747. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7748. rsaKeySz, HEAP_HINT);
  7749. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7750. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7751. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7752. rsaKeySz, HEAP_HINT);
  7753. if (out[0] == NULL) {
  7754. ret = MEMORY_E;
  7755. goto exit;
  7756. }
  7757. #endif
  7758. if (enc[0] == NULL) {
  7759. ret = MEMORY_E;
  7760. goto exit;
  7761. }
  7762. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7763. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7764. XMEMCPY(message, messageStr, len);
  7765. #endif
  7766. if (!rsa_sign_verify) {
  7767. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7768. /* begin public RSA */
  7769. bench_stats_start(&count, &start);
  7770. do {
  7771. for (times = 0; times < ntimes || pending > 0; ) {
  7772. bench_async_poll(&pending);
  7773. /* while free pending slots in queue, submit ops */
  7774. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7775. if (bench_async_check(&ret,
  7776. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7777. 1, &times, ntimes, &pending)) {
  7778. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7779. rsaKeySz/8, rsaKey[i],
  7780. GLOBAL_RNG);
  7781. if (!bench_async_handle(&ret,
  7782. BENCH_ASYNC_GET_DEV(
  7783. rsaKey[i]), 1, &times,
  7784. &pending)) {
  7785. goto exit_rsa_verify;
  7786. }
  7787. }
  7788. } /* for i */
  7789. RECORD_MULTI_VALUE_STATS();
  7790. } /* for times */
  7791. count += times;
  7792. } while (bench_stats_check(start)
  7793. #ifdef MULTI_VALUE_STATISTICS
  7794. || runs < minimum_runs
  7795. #endif
  7796. );
  7797. exit_rsa_verify:
  7798. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7799. useDeviceID, count, start, ret);
  7800. #ifdef MULTI_VALUE_STATISTICS
  7801. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7802. #endif
  7803. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7804. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7805. if (ret < 0) {
  7806. goto exit;
  7807. }
  7808. RESET_MULTI_VALUE_STATS_VARS();
  7809. /* capture resulting encrypt length */
  7810. idx = (word32)(rsaKeySz/8);
  7811. /* begin private async RSA */
  7812. bench_stats_start(&count, &start);
  7813. do {
  7814. for (times = 0; times < ntimes || pending > 0; ) {
  7815. bench_async_poll(&pending);
  7816. /* while free pending slots in queue, submit ops */
  7817. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7818. if (bench_async_check(&ret,
  7819. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7820. 1, &times, ntimes, &pending)) {
  7821. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7822. rsaKeySz/8, rsaKey[i]);
  7823. if (!bench_async_handle(&ret,
  7824. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7825. 1, &times, &pending)) {
  7826. goto exit_rsa_pub;
  7827. }
  7828. }
  7829. } /* for i */
  7830. RECORD_MULTI_VALUE_STATS();
  7831. } /* for times */
  7832. count += times;
  7833. } while (bench_stats_check(start)
  7834. #ifdef MULTI_VALUE_STATISTICS
  7835. || runs < minimum_runs
  7836. #endif
  7837. );
  7838. exit_rsa_pub:
  7839. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7840. useDeviceID, count, start, ret);
  7841. #ifdef MULTI_VALUE_STATISTICS
  7842. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7843. #endif
  7844. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7845. }
  7846. else {
  7847. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7848. /* begin RSA sign */
  7849. bench_stats_start(&count, &start);
  7850. do {
  7851. for (times = 0; times < ntimes || pending > 0; ) {
  7852. bench_async_poll(&pending);
  7853. /* while free pending slots in queue, submit ops */
  7854. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7855. if (bench_async_check(&ret,
  7856. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7857. 1, &times, ntimes, &pending)) {
  7858. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7859. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7860. if (!bench_async_handle(&ret,
  7861. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7862. 1, &times, &pending)) {
  7863. goto exit_rsa_sign;
  7864. }
  7865. }
  7866. } /* for i */
  7867. RECORD_MULTI_VALUE_STATS();
  7868. } /* for times */
  7869. count += times;
  7870. } while (bench_stats_check(start)
  7871. #ifdef MULTI_VALUE_STATISTICS
  7872. || runs < minimum_runs
  7873. #endif
  7874. );
  7875. exit_rsa_sign:
  7876. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7877. count, start, ret);
  7878. #ifdef MULTI_VALUE_STATISTICS
  7879. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7880. #endif
  7881. if (ret < 0) {
  7882. goto exit;
  7883. }
  7884. RESET_MULTI_VALUE_STATS_VARS();
  7885. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7886. /* capture resulting encrypt length */
  7887. idx = rsaKeySz/8;
  7888. /* begin RSA verify */
  7889. bench_stats_start(&count, &start);
  7890. do {
  7891. for (times = 0; times < ntimes || pending > 0; ) {
  7892. bench_async_poll(&pending);
  7893. /* while free pending slots in queue, submit ops */
  7894. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7895. if (bench_async_check(&ret,
  7896. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7897. 1, &times, ntimes, &pending)) {
  7898. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7899. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7900. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  7901. rsaKeySz/8, rsaKey[i]);
  7902. #elif defined(USE_CERT_BUFFERS_2048)
  7903. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  7904. idx = sizeof(rsa_2048_sig);
  7905. out[i] = NULL;
  7906. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7907. &out[i], rsaKey[i]);
  7908. if (ret > 0) {
  7909. ret = 0;
  7910. }
  7911. #elif defined(USE_CERT_BUFFERS_3072)
  7912. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  7913. idx = sizeof(rsa_3072_sig);
  7914. out[i] = NULL;
  7915. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7916. &out[i], rsaKey[i]);
  7917. if (ret > 0)
  7918. ret = 0;
  7919. #endif
  7920. if (!bench_async_handle(&ret,
  7921. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7922. 1, &times, &pending)) {
  7923. goto exit_rsa_verifyinline;
  7924. }
  7925. }
  7926. } /* for i */
  7927. RECORD_MULTI_VALUE_STATS();
  7928. } /* for times */
  7929. count += times;
  7930. } while (bench_stats_check(start)
  7931. #ifdef MULTI_VALUE_STATISTICS
  7932. || runs < minimum_runs
  7933. #endif
  7934. );
  7935. exit_rsa_verifyinline:
  7936. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  7937. useDeviceID, count, start, ret);
  7938. #ifdef MULTI_VALUE_STATISTICS
  7939. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7940. #endif
  7941. }
  7942. exit:
  7943. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  7944. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7945. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  7946. #endif
  7947. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7948. WC_FREE_VAR(message, HEAP_HINT);
  7949. #endif
  7950. }
  7951. void bench_rsa(int useDeviceID)
  7952. {
  7953. int i;
  7954. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  7955. sizeof(RsaKey), HEAP_HINT);
  7956. int ret = 0;
  7957. word32 rsaKeySz = 0;
  7958. const byte* tmp;
  7959. size_t bytes;
  7960. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7961. word32 idx;
  7962. #endif
  7963. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  7964. sizeof(RsaKey), HEAP_HINT);
  7965. #ifdef USE_CERT_BUFFERS_1024
  7966. tmp = rsa_key_der_1024;
  7967. bytes = (size_t)sizeof_rsa_key_der_1024;
  7968. rsaKeySz = 1024;
  7969. #elif defined(USE_CERT_BUFFERS_2048)
  7970. tmp = rsa_key_der_2048;
  7971. bytes = (size_t)sizeof_rsa_key_der_2048;
  7972. rsaKeySz = 2048;
  7973. #elif defined(USE_CERT_BUFFERS_3072)
  7974. tmp = rsa_key_der_3072;
  7975. bytes = (size_t)sizeof_rsa_key_der_3072;
  7976. rsaKeySz = 3072;
  7977. #elif defined(USE_CERT_BUFFERS_4096)
  7978. tmp = client_key_der_4096;
  7979. bytes = (size_t)sizeof_client_key_der_4096;
  7980. rsaKeySz = 4096;
  7981. #else
  7982. #error "need a cert buffer size"
  7983. #endif /* USE_CERT_BUFFERS */
  7984. /* init keys */
  7985. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7986. /* setup an async context for each key */
  7987. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  7988. useDeviceID ? devId : INVALID_DEVID);
  7989. if (ret < 0) {
  7990. goto exit;
  7991. }
  7992. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7993. #ifdef WC_RSA_BLINDING
  7994. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  7995. if (ret != 0)
  7996. goto exit;
  7997. #endif
  7998. #endif
  7999. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8000. /* decode the private key */
  8001. idx = 0;
  8002. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8003. rsaKey[i], (word32)bytes)) != 0) {
  8004. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8005. goto exit;
  8006. }
  8007. #elif defined(WOLFSSL_PUBLIC_MP)
  8008. /* get offset to public portion of the RSA key */
  8009. #ifdef USE_CERT_BUFFERS_1024
  8010. bytes = 11;
  8011. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8012. bytes = 12;
  8013. #endif
  8014. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8015. if (ret != 0) {
  8016. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8017. goto exit;
  8018. }
  8019. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8020. if (ret != 0) {
  8021. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8022. goto exit;
  8023. }
  8024. #else
  8025. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8026. rsaKeySz = 0;
  8027. #endif
  8028. }
  8029. if (rsaKeySz > 0) {
  8030. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8031. }
  8032. (void)bytes;
  8033. (void)tmp;
  8034. exit:
  8035. /* cleanup */
  8036. if (WC_ARRAY_OK(rsaKey)) {
  8037. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8038. wc_FreeRsaKey(rsaKey[i]);
  8039. }
  8040. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8041. }
  8042. }
  8043. #ifdef WOLFSSL_KEY_GEN
  8044. /* bench any size of RSA key */
  8045. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8046. {
  8047. int ret = 0, i, pending = 0;
  8048. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8049. sizeof(RsaKey), HEAP_HINT);
  8050. int isPending[BENCH_MAX_PENDING];
  8051. long exp = 65537L;
  8052. /* clear for done cleanup */
  8053. XMEMSET(isPending, 0, sizeof(isPending));
  8054. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8055. sizeof(RsaKey), HEAP_HINT);
  8056. /* init keys */
  8057. do {
  8058. pending = 0;
  8059. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8060. if (!isPending[i]) { /* if making the key is pending then just call
  8061. * wc_MakeRsaKey again */
  8062. /* setup an async context for each key */
  8063. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8064. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8065. goto exit;
  8066. }
  8067. #ifdef WC_RSA_BLINDING
  8068. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8069. if (ret != 0)
  8070. goto exit;
  8071. #endif
  8072. }
  8073. /* create the RSA key */
  8074. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8075. if (ret == WC_PENDING_E) {
  8076. isPending[i] = 1;
  8077. pending = 1;
  8078. }
  8079. else if (ret != 0) {
  8080. printf("wc_MakeRsaKey failed! %d\n", ret);
  8081. goto exit;
  8082. }
  8083. } /* for i */
  8084. } while (pending > 0);
  8085. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8086. exit:
  8087. /* cleanup */
  8088. if (WC_ARRAY_OK(rsaKey)) {
  8089. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8090. wc_FreeRsaKey(rsaKey[i]);
  8091. }
  8092. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8093. }
  8094. }
  8095. #endif /* WOLFSSL_KEY_GEN */
  8096. #endif /* !NO_RSA */
  8097. #ifndef NO_DH
  8098. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8099. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8100. #if defined(WOLFSSL_MDK_SHELL)
  8101. static char *certDHname = "certs/dh2048.der";
  8102. /* set by shell command */
  8103. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8104. #elif defined(FREESCALE_MQX)
  8105. static char *certDHname = "a:\\certs\\dh2048.der";
  8106. #elif defined(NO_ASN)
  8107. /* do nothing, but don't need a file */
  8108. #else
  8109. static const char *certDHname = "certs/dh2048.der";
  8110. #endif
  8111. #endif
  8112. #ifdef HAVE_FFDHE_4096
  8113. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8114. #else
  8115. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8116. #endif
  8117. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8118. void bench_dh(int useDeviceID)
  8119. {
  8120. int ret = 0, i;
  8121. int count = 0, times, pending = 0;
  8122. const byte* tmp = NULL;
  8123. double start = 0.0F;
  8124. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8125. sizeof(DhKey), HEAP_HINT);
  8126. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8127. const char**desc = bench_desc_words[lng_index];
  8128. #ifndef NO_ASN
  8129. size_t bytes = 0;
  8130. word32 idx;
  8131. #endif
  8132. word32 pubSz[BENCH_MAX_PENDING];
  8133. word32 privSz[BENCH_MAX_PENDING];
  8134. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8135. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8136. word32 agreeSz[BENCH_MAX_PENDING];
  8137. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8138. #ifdef HAVE_PUBLIC_FFDHE
  8139. const DhParams *params = NULL;
  8140. #else
  8141. int paramName = 0;
  8142. #endif
  8143. #endif
  8144. DECLARE_MULTI_VALUE_STATS_VARS()
  8145. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8146. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8147. WC_DECLARE_VAR(pub2, byte,
  8148. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8149. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8150. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8151. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8152. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8153. WC_DECLARE_VAR(priv2, byte,
  8154. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8155. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8156. XMEMSET(pub, 0, sizeof(pub));
  8157. XMEMSET(agree, 0, sizeof(agree));
  8158. XMEMSET(priv, 0, sizeof(priv));
  8159. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8160. sizeof(DhKey), HEAP_HINT);
  8161. WC_ALLOC_ARRAY(pub, byte,
  8162. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8163. WC_ALLOC_ARRAY(agree, byte,
  8164. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8165. WC_ALLOC_ARRAY(priv, byte,
  8166. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8167. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8168. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8169. (void)tmp;
  8170. if (!use_ffdhe) {
  8171. #if defined(NO_ASN)
  8172. dhKeySz = 1024;
  8173. /* do nothing, but don't use default FILE */
  8174. #elif defined(USE_CERT_BUFFERS_1024)
  8175. tmp = dh_key_der_1024;
  8176. bytes = (size_t)sizeof_dh_key_der_1024;
  8177. dhKeySz = 1024;
  8178. #elif defined(USE_CERT_BUFFERS_2048)
  8179. tmp = dh_key_der_2048;
  8180. bytes = (size_t)sizeof_dh_key_der_2048;
  8181. dhKeySz = 2048;
  8182. #elif defined(USE_CERT_BUFFERS_3072)
  8183. tmp = dh_key_der_3072;
  8184. bytes = (size_t)sizeof_dh_key_der_3072;
  8185. dhKeySz = 3072;
  8186. #elif defined(USE_CERT_BUFFERS_4096)
  8187. tmp = dh_key_der_4096;
  8188. bytes = (size_t)sizeof_dh_key_der_4096;
  8189. dhKeySz = 4096;
  8190. #else
  8191. #error "need to define a cert buffer size"
  8192. #endif /* USE_CERT_BUFFERS */
  8193. }
  8194. #ifdef HAVE_FFDHE_2048
  8195. else if (use_ffdhe == 2048) {
  8196. #ifdef HAVE_PUBLIC_FFDHE
  8197. params = wc_Dh_ffdhe2048_Get();
  8198. #else
  8199. paramName = WC_FFDHE_2048;
  8200. #endif
  8201. dhKeySz = 2048;
  8202. }
  8203. #endif
  8204. #ifdef HAVE_FFDHE_3072
  8205. else if (use_ffdhe == 3072) {
  8206. #ifdef HAVE_PUBLIC_FFDHE
  8207. params = wc_Dh_ffdhe3072_Get();
  8208. #else
  8209. paramName = WC_FFDHE_3072;
  8210. #endif
  8211. dhKeySz = 3072;
  8212. }
  8213. #endif
  8214. #ifdef HAVE_FFDHE_4096
  8215. else if (use_ffdhe == 4096) {
  8216. #ifdef HAVE_PUBLIC_FFDHE
  8217. params = wc_Dh_ffdhe4096_Get();
  8218. #else
  8219. paramName = WC_FFDHE_4096;
  8220. #endif
  8221. dhKeySz = 4096;
  8222. }
  8223. #endif
  8224. /* init keys */
  8225. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8226. /* setup an async context for each key */
  8227. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8228. useDeviceID ? devId : INVALID_DEVID);
  8229. if (ret != 0)
  8230. goto exit;
  8231. /* setup key */
  8232. if (!use_ffdhe) {
  8233. #ifdef NO_ASN
  8234. ret = wc_DhSetKey(dhKey[i], dh_p,
  8235. sizeof(dh_p), dh_g, sizeof(dh_g));
  8236. #else
  8237. idx = 0;
  8238. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8239. #endif
  8240. }
  8241. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8242. #ifdef HAVE_PUBLIC_FFDHE
  8243. else if (params != NULL) {
  8244. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8245. params->g, params->g_len);
  8246. }
  8247. #else
  8248. else if (paramName != 0) {
  8249. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8250. }
  8251. #endif
  8252. #endif
  8253. if (ret != 0) {
  8254. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8255. goto exit;
  8256. }
  8257. }
  8258. /* Key Gen */
  8259. bench_stats_start(&count, &start);
  8260. PRIVATE_KEY_UNLOCK();
  8261. do {
  8262. /* while free pending slots in queue, submit ops */
  8263. for (times = 0; times < genTimes || pending > 0; ) {
  8264. bench_async_poll(&pending);
  8265. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8266. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8267. 0, &times, genTimes, &pending)) {
  8268. privSz[i] = BENCH_DH_PRIV_SIZE;
  8269. pubSz[i] = BENCH_DH_KEY_SIZE;
  8270. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8271. priv[i], &privSz[i],
  8272. pub[i], &pubSz[i]);
  8273. if (!bench_async_handle(&ret,
  8274. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8275. 0, &times, &pending)) {
  8276. goto exit_dh_gen;
  8277. }
  8278. }
  8279. } /* for i */
  8280. RECORD_MULTI_VALUE_STATS();
  8281. } /* for times */
  8282. count += times;
  8283. } while (bench_stats_check(start)
  8284. #ifdef MULTI_VALUE_STATISTICS
  8285. || runs < minimum_runs
  8286. #endif
  8287. );
  8288. PRIVATE_KEY_LOCK();
  8289. exit_dh_gen:
  8290. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8291. useDeviceID, count, start, ret);
  8292. #ifdef MULTI_VALUE_STATISTICS
  8293. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8294. #endif
  8295. if (ret < 0) {
  8296. goto exit;
  8297. }
  8298. RESET_MULTI_VALUE_STATS_VARS();
  8299. /* Generate key to use as other public */
  8300. PRIVATE_KEY_UNLOCK();
  8301. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8302. priv2, &privSz2, pub2, &pubSz2);
  8303. PRIVATE_KEY_LOCK();
  8304. #ifdef WOLFSSL_ASYNC_CRYPT
  8305. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8306. #endif
  8307. /* Key Agree */
  8308. bench_stats_start(&count, &start);
  8309. PRIVATE_KEY_UNLOCK();
  8310. do {
  8311. for (times = 0; times < agreeTimes || pending > 0; ) {
  8312. bench_async_poll(&pending);
  8313. /* while free pending slots in queue, submit ops */
  8314. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8315. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8316. 0, &times, agreeTimes, &pending)) {
  8317. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8318. privSz[i], pub2, pubSz2);
  8319. if (!bench_async_handle(&ret,
  8320. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8321. goto exit;
  8322. }
  8323. }
  8324. } /* for i */
  8325. RECORD_MULTI_VALUE_STATS();
  8326. } /* for times */
  8327. count += times;
  8328. } while (bench_stats_check(start)
  8329. #ifdef MULTI_VALUE_STATISTICS
  8330. || runs < minimum_runs
  8331. #endif
  8332. );
  8333. PRIVATE_KEY_LOCK();
  8334. exit:
  8335. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8336. useDeviceID, count, start, ret);
  8337. #ifdef MULTI_VALUE_STATISTICS
  8338. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8339. #endif
  8340. /* cleanup */
  8341. if (WC_ARRAY_OK(dhKey)) {
  8342. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8343. wc_FreeDhKey(dhKey[i]);
  8344. }
  8345. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8346. }
  8347. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8348. WC_FREE_VAR(pub2, HEAP_HINT);
  8349. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8350. WC_FREE_VAR(priv2, HEAP_HINT);
  8351. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8352. }
  8353. #endif /* !NO_DH */
  8354. #ifdef WOLFSSL_HAVE_KYBER
  8355. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8356. KyberKey* key)
  8357. {
  8358. int ret = 0, times, count, pending = 0;
  8359. double start;
  8360. const char**desc = bench_desc_words[lng_index];
  8361. DECLARE_MULTI_VALUE_STATS_VARS()
  8362. /* KYBER Make Key */
  8363. bench_stats_start(&count, &start);
  8364. do {
  8365. /* while free pending slots in queue, submit ops */
  8366. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8367. wc_KyberKey_Free(key);
  8368. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8369. if (ret != 0)
  8370. goto exit;
  8371. #ifdef KYBER_NONDETERMINISTIC
  8372. ret = wc_KyberKey_MakeKey(key, &gRng);
  8373. #else
  8374. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8375. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8376. #endif
  8377. if (ret != 0)
  8378. goto exit;
  8379. RECORD_MULTI_VALUE_STATS();
  8380. } /* for times */
  8381. count += times;
  8382. } while (bench_stats_check(start)
  8383. #ifdef MULTI_VALUE_STATISTICS
  8384. || runs < minimum_runs
  8385. #endif
  8386. );
  8387. exit:
  8388. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8389. #ifdef MULTI_VALUE_STATISTICS
  8390. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8391. #endif
  8392. }
  8393. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8394. {
  8395. int ret = 0, times, count, pending = 0;
  8396. double start;
  8397. const char**desc = bench_desc_words[lng_index];
  8398. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8399. byte ss[KYBER_SS_SZ];
  8400. word32 ctSz;
  8401. DECLARE_MULTI_VALUE_STATS_VARS()
  8402. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8403. if (ret != 0) {
  8404. return;
  8405. }
  8406. /* KYBER Encapsulate */
  8407. bench_stats_start(&count, &start);
  8408. do {
  8409. /* while free pending slots in queue, submit ops */
  8410. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8411. #ifdef KYBER_NONDETERMINISTIC
  8412. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8413. #else
  8414. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8415. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8416. sizeof(rand));
  8417. #endif
  8418. if (ret != 0)
  8419. goto exit_encap;
  8420. RECORD_MULTI_VALUE_STATS();
  8421. } /* for times */
  8422. count += times;
  8423. } while (bench_stats_check(start)
  8424. #ifdef MULTI_VALUE_STATISTICS
  8425. || runs < minimum_runs
  8426. #endif
  8427. );
  8428. exit_encap:
  8429. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8430. #ifdef MULTI_VALUE_STATISTICS
  8431. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8432. #endif
  8433. RESET_MULTI_VALUE_STATS_VARS();
  8434. /* KYBER Decapsulate */
  8435. bench_stats_start(&count, &start);
  8436. do {
  8437. /* while free pending slots in queue, submit ops */
  8438. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8439. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8440. if (ret != 0)
  8441. goto exit_decap;
  8442. RECORD_MULTI_VALUE_STATS();
  8443. } /* for times */
  8444. count += times;
  8445. } while (bench_stats_check(start)
  8446. #ifdef MULTI_VALUE_STATISTICS
  8447. || runs < minimum_runs
  8448. #endif
  8449. );
  8450. exit_decap:
  8451. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8452. #ifdef MULTI_VALUE_STATISTICS
  8453. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8454. #endif
  8455. }
  8456. void bench_kyber(int type)
  8457. {
  8458. KyberKey key;
  8459. const char* name = NULL;
  8460. int keySize = 0;
  8461. switch (type) {
  8462. #ifdef WOLFSSL_KYBER512
  8463. case KYBER512:
  8464. name = "KYBER512 ";
  8465. keySize = 128;
  8466. break;
  8467. #endif
  8468. #ifdef WOLFSSL_KYBER768
  8469. case KYBER768:
  8470. name = "KYBER768 ";
  8471. keySize = 192;
  8472. break;
  8473. #endif
  8474. #ifdef WOLFSSL_KYBER1024
  8475. case KYBER1024:
  8476. name = "KYBER1024";
  8477. keySize = 256;
  8478. break;
  8479. #endif
  8480. }
  8481. bench_kyber_keygen(type, name, keySize, &key);
  8482. bench_kyber_encap(name, keySize, &key);
  8483. wc_KyberKey_Free(&key);
  8484. }
  8485. #endif
  8486. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8487. /* WC_LMS_PARM_L2_H10_W2
  8488. * signature length: 9300 */
  8489. static const byte lms_priv_L2_H10_W2[64] =
  8490. {
  8491. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8492. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8493. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8494. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8495. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8496. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8497. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8498. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8499. };
  8500. static const byte lms_pub_L2_H10_W2[60] =
  8501. {
  8502. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8503. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8504. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8505. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8506. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8507. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8508. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8509. 0x7F,0xC8,0x91,0xB0
  8510. };
  8511. /* WC_LMS_PARM_L2_H10_W4
  8512. * signature length: 5076 */
  8513. static const byte lms_priv_L2_H10_W4[64] =
  8514. {
  8515. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8516. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8517. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8518. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8519. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8520. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8521. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8522. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8523. };
  8524. static const byte lms_pub_L2_H10_W4[60] =
  8525. {
  8526. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8527. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8528. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8529. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8530. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8531. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8532. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8533. 0x6B,0x9A,0xD3,0x14
  8534. };
  8535. /* WC_LMS_PARM_L3_H5_W4
  8536. * signature length: 7160 */
  8537. static const byte lms_priv_L3_H5_W4[64] =
  8538. {
  8539. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8540. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8541. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8542. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8543. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8544. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8545. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8546. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8547. };
  8548. static const byte lms_pub_L3_H5_W4[60] =
  8549. {
  8550. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8551. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8552. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8553. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8554. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8555. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8556. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8557. 0xAB,0x4B,0x51,0x39
  8558. };
  8559. /* WC_LMS_PARM_L3_H5_W8
  8560. * signature length: 3992 */
  8561. static const byte lms_priv_L3_H5_W8[64] =
  8562. {
  8563. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8564. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8565. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8566. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8567. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8568. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8569. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8570. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8571. };
  8572. static const byte lms_pub_L3_H5_W8[60] =
  8573. {
  8574. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8575. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8576. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8577. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8578. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8579. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8580. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8581. 0x83,0xAB,0x43,0xAF
  8582. };
  8583. /* WC_LMS_PARM_L3_H10_W4
  8584. * signature length: 7640 */
  8585. static const byte lms_priv_L3_H10_W4[64] =
  8586. {
  8587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8588. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8589. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8590. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8591. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8592. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8593. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8594. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8595. };
  8596. static const byte lms_pub_L3_H10_W4[60] =
  8597. {
  8598. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8599. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8600. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8601. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8602. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8603. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8604. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8605. 0x8D,0x78,0xD5,0xA8
  8606. };
  8607. /* WC_LMS_PARM_L4_H5_W8
  8608. * signature length: 5340 */
  8609. static const byte lms_priv_L4_H5_W8[64] =
  8610. {
  8611. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8612. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8613. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8614. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8615. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8616. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8617. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8618. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8619. };
  8620. static const byte lms_pub_L4_H5_W8[60] =
  8621. {
  8622. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8623. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8624. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8625. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8626. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8627. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8628. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8629. 0x74,0x24,0x12,0xC8
  8630. };
  8631. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8632. {
  8633. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8634. * BE USED FOR TESTING PURPOSES! Production applications should
  8635. * write only to non-volatile storage. */
  8636. XMEMCPY(context, priv, privSz);
  8637. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8638. }
  8639. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8640. {
  8641. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8642. * BE USED FOR TESTING PURPOSES! */
  8643. XMEMCPY(priv, context, privSz);
  8644. return WC_LMS_RC_READ_TO_MEMORY;
  8645. }
  8646. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8647. static void bench_lms_keygen(int parm, byte* pub)
  8648. {
  8649. WC_RNG rng;
  8650. LmsKey key;
  8651. int ret;
  8652. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8653. int times = 0;
  8654. int count = 0;
  8655. double start = 0.0F;
  8656. int levels;
  8657. int height;
  8658. int winternitz;
  8659. const char* str = wc_LmsKey_ParmToStr(parm);
  8660. DECLARE_MULTI_VALUE_STATS_VARS()
  8661. #ifndef HAVE_FIPS
  8662. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8663. #else
  8664. ret = wc_InitRng(&rng);
  8665. #endif
  8666. if (ret != 0) {
  8667. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8668. return;
  8669. }
  8670. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8671. if (ret) {
  8672. printf("wc_LmsKey_Init failed: %d\n", ret);
  8673. wc_FreeRng(&rng);
  8674. return;
  8675. }
  8676. count = 0;
  8677. bench_stats_start(&count, &start);
  8678. do {
  8679. /* LMS is stateful. Async queuing not practical. */
  8680. for (times = 0; times < 1; ++times) {
  8681. wc_LmsKey_Free(&key);
  8682. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8683. if (ret) {
  8684. printf("wc_LmsKey_Init failed: %d\n", ret);
  8685. goto exit_lms_keygen;
  8686. }
  8687. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8688. if (ret) {
  8689. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8690. goto exit_lms_keygen;
  8691. }
  8692. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8693. if (ret) {
  8694. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8695. ret);
  8696. goto exit_lms_keygen;
  8697. }
  8698. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8699. if (ret) {
  8700. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8701. ret);
  8702. goto exit_lms_keygen;
  8703. }
  8704. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8705. if (ret) {
  8706. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8707. goto exit_lms_keygen;
  8708. }
  8709. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8710. if (ret) {
  8711. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8712. ret);
  8713. goto exit_lms_keygen;
  8714. }
  8715. ret = wc_LmsKey_MakeKey(&key, &rng);
  8716. if (ret) {
  8717. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8718. goto exit_lms_keygen;
  8719. }
  8720. RECORD_MULTI_VALUE_STATS();
  8721. }
  8722. count += times;
  8723. } while (bench_stats_check(start)
  8724. #ifdef MULTI_VALUE_STATISTICS
  8725. || runs < minimum_runs
  8726. #endif
  8727. );
  8728. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8729. count, start, ret);
  8730. #ifdef MULTI_VALUE_STATISTICS
  8731. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8732. #endif
  8733. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8734. if (ret) {
  8735. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8736. }
  8737. exit_lms_keygen:
  8738. wc_LmsKey_Free(&key);
  8739. wc_FreeRng(&rng);
  8740. }
  8741. static void bench_lms_sign_verify(int parm, byte* pub)
  8742. {
  8743. LmsKey key;
  8744. int ret = 0;
  8745. const char * msg = TEST_STRING;
  8746. word32 msgSz = TEST_STRING_SZ;
  8747. byte * sig = NULL;
  8748. word32 sigSz = 0;
  8749. word32 privLen = 0;
  8750. int loaded = 0;
  8751. int times = 0;
  8752. int count = 0;
  8753. double start = 0.0F;
  8754. const char * str = wc_LmsKey_ParmToStr(parm);
  8755. DECLARE_MULTI_VALUE_STATS_VARS()
  8756. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8757. if (ret) {
  8758. printf("wc_LmsKey_Init failed: %d\n", ret);
  8759. goto exit_lms_sign_verify;
  8760. }
  8761. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8762. if (ret) {
  8763. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8764. goto exit_lms_sign_verify;
  8765. }
  8766. switch (parm) {
  8767. case WC_LMS_PARM_L2_H10_W2:
  8768. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8769. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8770. break;
  8771. case WC_LMS_PARM_L2_H10_W4:
  8772. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8773. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8774. break;
  8775. case WC_LMS_PARM_L3_H5_W4:
  8776. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8777. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8778. break;
  8779. case WC_LMS_PARM_L3_H5_W8:
  8780. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8781. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8782. break;
  8783. case WC_LMS_PARM_L3_H10_W4:
  8784. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8785. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8786. break;
  8787. case WC_LMS_PARM_L4_H5_W8:
  8788. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8789. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8790. break;
  8791. case WC_LMS_PARM_NONE:
  8792. case WC_LMS_PARM_L1_H15_W2:
  8793. case WC_LMS_PARM_L1_H15_W4:
  8794. case WC_LMS_PARM_L2_H10_W8:
  8795. case WC_LMS_PARM_L3_H5_W2:
  8796. default:
  8797. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8798. break;
  8799. }
  8800. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8801. if (ret) {
  8802. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8803. goto exit_lms_sign_verify;
  8804. }
  8805. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8806. if (ret) {
  8807. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8808. goto exit_lms_sign_verify;
  8809. }
  8810. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8811. if (ret) {
  8812. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8813. goto exit_lms_sign_verify;
  8814. }
  8815. /* Even with saved priv/pub keys, we must still reload the private
  8816. * key before using it. Reloading the private key is the bottleneck
  8817. * for larger heights. Only print load time in debug builds. */
  8818. count = 0;
  8819. bench_stats_start(&count, &start);
  8820. #ifndef WOLFSSL_WC_LMS_SMALL
  8821. do {
  8822. #ifdef WOLFSSL_WC_LMS
  8823. key.priv.inited = 0;
  8824. key.state = WC_LMS_STATE_PARMSET;
  8825. #endif
  8826. ret = wc_LmsKey_Reload(&key);
  8827. if (ret) {
  8828. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8829. goto exit_lms_sign_verify;
  8830. }
  8831. RECORD_MULTI_VALUE_STATS();
  8832. count++;
  8833. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8834. if (ret) {
  8835. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8836. goto exit_lms_sign_verify;
  8837. }
  8838. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8839. if (ret) {
  8840. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8841. goto exit_lms_sign_verify;
  8842. }
  8843. #ifdef HAVE_LIBLMS
  8844. break;
  8845. #endif
  8846. } while (bench_stats_check(start)
  8847. #ifdef MULTI_VALUE_STATISTICS
  8848. || runs < minimum_runs
  8849. #endif
  8850. );
  8851. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  8852. count, start, ret);
  8853. #ifdef MULTI_VALUE_STATISTICS
  8854. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8855. #endif
  8856. RESET_MULTI_VALUE_STATS_VARS();
  8857. #else
  8858. ret = wc_LmsKey_Reload(&key);
  8859. if (ret) {
  8860. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8861. goto exit_lms_sign_verify;
  8862. }
  8863. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8864. if (ret) {
  8865. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8866. goto exit_lms_sign_verify;
  8867. }
  8868. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8869. if (ret) {
  8870. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8871. goto exit_lms_sign_verify;
  8872. }
  8873. #endif
  8874. loaded = 1;
  8875. sig = XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8876. if (sig == NULL) {
  8877. printf("bench_lms_sign_verify malloc failed\n");
  8878. goto exit_lms_sign_verify;
  8879. }
  8880. count = 0;
  8881. bench_stats_start(&count, &start);
  8882. do {
  8883. /* LMS is stateful. Async queuing not practical. */
  8884. #ifndef WOLFSSL_WC_LMS_SMALL
  8885. for (times = 0; times < ntimes; ++times)
  8886. #else
  8887. for (times = 0; times < 1; ++times)
  8888. #endif
  8889. {
  8890. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  8891. if (ret) {
  8892. printf("wc_LmsKey_Sign failed: %d\n", ret);
  8893. goto exit_lms_sign_verify;
  8894. }
  8895. RECORD_MULTI_VALUE_STATS();
  8896. if (!wc_LmsKey_SigsLeft(&key)) {
  8897. break;
  8898. }
  8899. }
  8900. count += times;
  8901. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  8902. #ifdef MULTI_VALUE_STATISTICS
  8903. || runs < minimum_runs
  8904. #endif
  8905. ));
  8906. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  8907. count, start, ret);
  8908. #ifdef MULTI_VALUE_STATISTICS
  8909. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8910. #endif
  8911. RESET_MULTI_VALUE_STATS_VARS();
  8912. count = 0;
  8913. bench_stats_start(&count, &start);
  8914. do {
  8915. /* LMS is stateful. Async queuing not practical. */
  8916. for (times = 0; times < ntimes; ++times) {
  8917. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  8918. if (ret) {
  8919. printf("wc_LmsKey_Verify failed: %d\n", ret);
  8920. goto exit_lms_sign_verify;
  8921. }
  8922. RECORD_MULTI_VALUE_STATS();
  8923. }
  8924. count += times;
  8925. } while (bench_stats_check(start)
  8926. #ifdef MULTI_VALUE_STATISTICS
  8927. || runs < minimum_runs
  8928. #endif
  8929. );
  8930. exit_lms_sign_verify:
  8931. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  8932. count, start, ret);
  8933. #ifdef MULTI_VALUE_STATISTICS
  8934. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8935. #endif
  8936. if (loaded) {
  8937. wc_LmsKey_Free(&key);
  8938. }
  8939. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8940. return;
  8941. }
  8942. void bench_lms(void)
  8943. {
  8944. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  8945. #ifdef BENCH_LMS_SLOW_KEYGEN
  8946. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  8947. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  8948. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  8949. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  8950. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  8951. #undef LMS_PARAMS_BENCHED
  8952. #define LMS_PARAMS_BENCHED
  8953. #endif
  8954. #endif
  8955. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  8956. (LMS_MAX_HEIGHT >= 10))
  8957. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  8958. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  8959. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  8960. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  8961. #undef LMS_PARAMS_BENCHED
  8962. #define LMS_PARAMS_BENCHED
  8963. #ifdef BENCH_LMS_SLOW_KEYGEN
  8964. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  8965. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  8966. #endif
  8967. #endif
  8968. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  8969. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  8970. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  8971. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  8972. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  8973. #undef LMS_PARAMS_BENCHED
  8974. #define LMS_PARAMS_BENCHED
  8975. #endif
  8976. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  8977. (LMS_MAX_HEIGHT >= 10))
  8978. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  8979. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  8980. #endif
  8981. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  8982. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  8983. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  8984. #endif
  8985. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  8986. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  8987. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  8988. #endif
  8989. return;
  8990. }
  8991. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  8992. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  8993. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  8994. void *context)
  8995. {
  8996. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8997. * BE USED FOR TESTING PURPOSES! Production applications should
  8998. * write only to non-volatile storage. */
  8999. XMEMCPY(context, priv, privSz);
  9000. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9001. }
  9002. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9003. void *context)
  9004. {
  9005. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9006. * BE USED FOR TESTING PURPOSES! */
  9007. XMEMCPY(priv, context, privSz);
  9008. return WC_XMSS_RC_READ_TO_MEMORY;
  9009. }
  9010. static void bench_xmss_sign_verify(const char * params)
  9011. {
  9012. WC_RNG rng;
  9013. XmssKey key;
  9014. word32 pkSz = 0;
  9015. word32 skSz = 0;
  9016. int freeRng = 0;
  9017. int freeKey = 0;
  9018. unsigned char * sk = NULL;
  9019. const char * msg = "XMSS post quantum signature test";
  9020. word32 msgSz = (word32) XSTRLEN(msg);
  9021. int ret = 0;
  9022. byte * sig = NULL;
  9023. word32 sigSz = 0;
  9024. int times = 0;
  9025. int count = 0;
  9026. double start = 0.0F;
  9027. #ifndef HAVE_FIPS
  9028. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9029. #else
  9030. ret = wc_InitRng(&rng);
  9031. #endif
  9032. if (ret != 0) {
  9033. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9034. goto exit_xmss_sign_verify;
  9035. }
  9036. freeRng = 1;
  9037. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9038. if (ret != 0) {
  9039. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9040. goto exit_xmss_sign_verify;
  9041. }
  9042. ret = wc_XmssKey_SetParamStr(&key, params);
  9043. if (ret != 0) {
  9044. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9045. goto exit_xmss_sign_verify;
  9046. }
  9047. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9048. if (ret != 0) {
  9049. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9050. goto exit_xmss_sign_verify;
  9051. }
  9052. #ifndef WOLFSSL_WC_XMSS
  9053. if (pkSz != XMSS_SHA256_PUBLEN) {
  9054. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9055. XMSS_SHA256_PUBLEN);
  9056. goto exit_xmss_sign_verify;
  9057. }
  9058. #endif
  9059. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9060. if (ret != 0 || skSz <= 0) {
  9061. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9062. goto exit_xmss_sign_verify;
  9063. }
  9064. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9065. if (ret != 0 || sigSz <= 0) {
  9066. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9067. goto exit_xmss_sign_verify;
  9068. }
  9069. /* Allocate secret keys.*/
  9070. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9071. if (sk == NULL) {
  9072. fprintf(stderr, "error: allocate xmss sk failed\n");
  9073. goto exit_xmss_sign_verify;
  9074. }
  9075. /* Allocate signature array. */
  9076. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9077. if (sig == NULL) {
  9078. fprintf(stderr, "error: allocate xmss sig failed\n");
  9079. goto exit_xmss_sign_verify;
  9080. }
  9081. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9082. if (ret != 0) {
  9083. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9084. goto exit_xmss_sign_verify;
  9085. }
  9086. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9087. if (ret != 0) {
  9088. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9089. goto exit_xmss_sign_verify;
  9090. }
  9091. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9092. if (ret != 0) {
  9093. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9094. goto exit_xmss_sign_verify;
  9095. }
  9096. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9097. fprintf(stderr, "params: %s\n", params);
  9098. fprintf(stderr, "pkSz: %d\n", pkSz);
  9099. fprintf(stderr, "skSz: %d\n", skSz);
  9100. fprintf(stderr, "sigSz: %d\n", sigSz);
  9101. #endif
  9102. /* Making the private key is the bottleneck for larger heights. */
  9103. count = 0;
  9104. bench_stats_start(&count, &start);
  9105. ret = wc_XmssKey_MakeKey(&key, &rng);
  9106. if (ret != 0) {
  9107. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9108. goto exit_xmss_sign_verify;
  9109. }
  9110. /* Can only do one at a time - state changes after make key. */
  9111. count +=1;
  9112. bench_stats_check(start);
  9113. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9114. freeKey = 1;
  9115. count = 0;
  9116. bench_stats_start(&count, &start);
  9117. do {
  9118. /* XMSS is stateful. Async queuing not practical. */
  9119. #ifndef WOLFSSL_WC_XMSS_SMALL
  9120. for (times = 0; times < ntimes; ++times)
  9121. #else
  9122. for (times = 0; times < 1; ++times)
  9123. #endif
  9124. {
  9125. if (!wc_XmssKey_SigsLeft(&key))
  9126. break;
  9127. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9128. if (ret) {
  9129. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9130. goto exit_xmss_sign_verify;
  9131. }
  9132. }
  9133. count += times;
  9134. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9135. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9136. count = 0;
  9137. bench_stats_start(&count, &start);
  9138. do {
  9139. /* XMSS is stateful. Async queuing not practical. */
  9140. for (times = 0; times < ntimes; ++times) {
  9141. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9142. if (ret) {
  9143. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9144. goto exit_xmss_sign_verify;
  9145. }
  9146. }
  9147. count += times;
  9148. } while (bench_stats_check(start));
  9149. exit_xmss_sign_verify:
  9150. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9151. /* Cleanup everything. */
  9152. if (sig != NULL) {
  9153. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9154. sig = NULL;
  9155. }
  9156. if (sk != NULL) {
  9157. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9158. sk = NULL;
  9159. }
  9160. if (freeRng) {
  9161. wc_FreeRng(&rng);
  9162. }
  9163. if (freeKey) {
  9164. wc_XmssKey_Free(&key);
  9165. }
  9166. return;
  9167. }
  9168. void bench_xmss(int hash)
  9169. {
  9170. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9171. * sets.
  9172. *
  9173. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9174. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9175. * very slow, their signatures and private keys quite large,
  9176. * and xmss private keys are not portable across different
  9177. * XMSS/XMSS^MT implementations.
  9178. *
  9179. * The bottleneck in key generation is the height of the first
  9180. * level tree (or h/d).
  9181. *
  9182. * h is the total height of the hyper tree, and d the number of
  9183. * trees.
  9184. */
  9185. /* h/d h d */
  9186. #ifdef WC_XMSS_SHA256
  9187. if (hash == WC_HASH_TYPE_SHA256) {
  9188. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9189. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9190. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9191. #endif
  9192. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9193. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9194. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9195. #endif
  9196. #endif
  9197. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9198. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9199. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9200. #endif
  9201. #endif
  9202. #endif /* HASH_SIZE 256 */
  9203. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9204. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9205. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9206. #endif
  9207. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9208. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9209. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9210. #endif
  9211. #endif
  9212. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9213. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9214. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9215. #endif
  9216. #endif
  9217. #endif /* HASH_SIZE 192 */
  9218. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9219. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9220. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9221. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9222. #endif
  9223. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9224. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9225. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9226. #endif
  9227. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9228. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9229. #endif
  9230. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9231. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9232. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9233. #endif
  9234. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9235. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9236. #endif
  9237. #endif /* HASH_SIZE 256 */
  9238. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9239. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9240. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9241. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9242. #endif
  9243. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9244. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9245. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9246. #endif
  9247. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9248. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9249. #endif
  9250. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9251. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9252. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9253. #endif
  9254. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9255. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9256. #endif
  9257. #endif /* HASH_SIZE 192 */
  9258. }
  9259. #endif
  9260. #ifdef WC_XMSS_SHA512
  9261. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9262. if (hash == WC_HASH_TYPE_SHA512) {
  9263. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9264. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9265. #endif
  9266. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9267. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9268. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9269. #endif
  9270. #endif
  9271. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9272. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9273. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9274. #endif
  9275. #endif
  9276. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9277. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9278. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9279. #endif
  9280. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9281. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9282. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9283. #endif
  9284. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9285. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9286. #endif
  9287. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9288. #endif
  9289. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9290. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9291. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9292. #endif
  9293. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9294. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9295. #endif
  9296. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9297. #endif
  9298. }
  9299. #endif /* HASH_SIZE 512 */
  9300. #endif
  9301. #ifdef WC_XMSS_SHAKE128
  9302. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9303. if (hash == WC_HASH_TYPE_SHAKE128) {
  9304. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9305. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9306. #endif
  9307. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9308. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9309. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9310. #endif
  9311. #endif
  9312. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9313. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9314. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9315. #endif
  9316. #endif
  9317. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9318. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9319. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9320. #endif
  9321. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9322. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9323. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9324. #endif
  9325. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9326. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9327. #endif
  9328. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9329. #endif
  9330. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9331. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9332. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9333. #endif
  9334. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9335. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9336. #endif
  9337. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9338. #endif
  9339. }
  9340. #endif /* HASH_SIZE 256 */
  9341. #endif
  9342. #ifdef WC_XMSS_SHAKE256
  9343. if (hash == WC_HASH_TYPE_SHAKE256) {
  9344. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9345. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9346. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9347. #endif
  9348. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9349. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9350. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9351. #endif
  9352. #endif
  9353. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9354. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9355. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9356. #endif
  9357. #endif
  9358. #endif /* HASH_SIZE 512 */
  9359. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9360. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9361. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9362. #endif
  9363. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9364. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9365. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9366. #endif
  9367. #endif
  9368. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9369. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9370. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9371. #endif
  9372. #endif
  9373. #endif /* HASH_SIZE 256 */
  9374. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9375. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9376. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9377. #endif
  9378. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9379. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9380. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9381. #endif
  9382. #endif
  9383. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9384. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9385. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9386. #endif
  9387. #endif
  9388. #endif /* HASH_SIZE 192 */
  9389. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9390. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9391. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9392. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9393. #endif
  9394. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9395. #endif
  9396. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9397. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9398. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9399. #endif
  9400. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9401. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9402. #endif
  9403. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9404. #endif
  9405. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9406. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9407. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9408. #endif
  9409. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9410. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9411. #endif
  9412. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9413. #endif
  9414. #endif /* HASH_SIZE 512 */
  9415. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9416. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9417. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9418. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9419. #endif
  9420. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9421. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9422. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9423. #endif
  9424. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9425. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9426. #endif
  9427. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9428. #endif
  9429. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9430. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9431. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9432. #endif
  9433. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9434. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9435. #endif
  9436. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9437. #endif
  9438. #endif /* HASH_SIZE 256 */
  9439. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9440. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9441. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9442. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9443. #endif
  9444. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9445. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9446. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9447. #endif
  9448. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9449. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9450. #endif
  9451. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9452. #endif
  9453. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9454. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9455. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9456. #endif
  9457. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9458. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9459. #endif
  9460. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9461. #endif
  9462. #endif /* HASH_SIZE 192 */
  9463. }
  9464. #endif
  9465. return;
  9466. }
  9467. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9468. #ifdef HAVE_ECC
  9469. /* Maximum ECC name plus null terminator:
  9470. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9471. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9472. /* run all benchmarks on a curve */
  9473. void bench_ecc_curve(int curveId)
  9474. {
  9475. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9476. #ifndef NO_SW_BENCH
  9477. bench_eccMakeKey(0, curveId);
  9478. #endif
  9479. #if defined(BENCH_DEVID)
  9480. bench_eccMakeKey(1, curveId);
  9481. #endif
  9482. }
  9483. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9484. #ifndef NO_SW_BENCH
  9485. bench_ecc(0, curveId);
  9486. #endif
  9487. #if defined(BENCH_DEVID)
  9488. bench_ecc(1, curveId);
  9489. #endif
  9490. }
  9491. #ifdef HAVE_ECC_ENCRYPT
  9492. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9493. bench_eccEncrypt(curveId);
  9494. #endif
  9495. }
  9496. void bench_eccMakeKey(int useDeviceID, int curveId)
  9497. {
  9498. int ret = 0, i, times, count = 0, pending = 0;
  9499. int deviceID;
  9500. int keySize = 0;
  9501. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9502. sizeof(ecc_key), HEAP_HINT);
  9503. char name[BENCH_ECC_NAME_SZ];
  9504. double start = 0;
  9505. const char**desc = bench_desc_words[lng_index];
  9506. DECLARE_MULTI_VALUE_STATS_VARS()
  9507. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9508. sizeof(ecc_key), HEAP_HINT);
  9509. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9510. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9511. /* ECC Make Key */
  9512. bench_stats_start(&count, &start);
  9513. do {
  9514. /* while free pending slots in queue, submit ops */
  9515. for (times = 0; times < agreeTimes || pending > 0; ) {
  9516. bench_async_poll(&pending);
  9517. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9518. if (bench_async_check(&ret,
  9519. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9520. &times, agreeTimes, &pending)) {
  9521. wc_ecc_free(genKey[i]);
  9522. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9523. if (ret < 0) {
  9524. goto exit;
  9525. }
  9526. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9527. curveId);
  9528. if (!bench_async_handle(&ret,
  9529. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9530. &pending)) {
  9531. goto exit;
  9532. }
  9533. }
  9534. } /* for i */
  9535. RECORD_MULTI_VALUE_STATS();
  9536. } /* for times */
  9537. count += times;
  9538. } while (bench_stats_check(start)
  9539. #ifdef MULTI_VALUE_STATISTICS
  9540. || runs < minimum_runs
  9541. #endif
  9542. );
  9543. exit:
  9544. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9545. wc_ecc_get_name(curveId));
  9546. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9547. useDeviceID, count, start, ret);
  9548. #ifdef MULTI_VALUE_STATISTICS
  9549. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9550. #endif
  9551. /* cleanup */
  9552. if (WC_ARRAY_OK(genKey)) {
  9553. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9554. wc_ecc_free(genKey[i]);
  9555. }
  9556. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9557. }
  9558. }
  9559. void bench_ecc(int useDeviceID, int curveId)
  9560. {
  9561. int ret = 0, i, times, count, pending = 0;
  9562. int deviceID;
  9563. int keySize;
  9564. char name[BENCH_ECC_NAME_SZ];
  9565. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9566. sizeof(ecc_key), HEAP_HINT);
  9567. #ifdef HAVE_ECC_DHE
  9568. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9569. sizeof(ecc_key), HEAP_HINT);
  9570. #endif
  9571. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9572. #ifdef HAVE_ECC_VERIFY
  9573. int verify[BENCH_MAX_PENDING];
  9574. #endif
  9575. #endif
  9576. word32 x[BENCH_MAX_PENDING];
  9577. double start = 0;
  9578. const char**desc = bench_desc_words[lng_index];
  9579. DECLARE_MULTI_VALUE_STATS_VARS()
  9580. #ifdef HAVE_ECC_DHE
  9581. WC_DECLARE_ARRAY(shared, byte,
  9582. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9583. #endif
  9584. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9585. WC_DECLARE_ARRAY(sig, byte,
  9586. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9587. WC_DECLARE_ARRAY(digest, byte,
  9588. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9589. #endif
  9590. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9591. XMEMSET(sig, 0, sizeof(sig));
  9592. XMEMSET(digest, 0, sizeof(digest));
  9593. XMEMSET(shared, 0, sizeof(shared));
  9594. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9595. sizeof(ecc_key), HEAP_HINT);
  9596. #ifdef HAVE_ECC_DHE
  9597. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9598. sizeof(ecc_key), HEAP_HINT);
  9599. WC_ALLOC_ARRAY(shared, byte,
  9600. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9601. #endif
  9602. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9603. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9604. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9605. #endif
  9606. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9607. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9608. /* init keys */
  9609. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9610. /* setup an context for each key */
  9611. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9612. goto exit;
  9613. }
  9614. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9615. #ifdef WOLFSSL_ASYNC_CRYPT
  9616. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9617. #endif
  9618. if (ret < 0) {
  9619. goto exit;
  9620. }
  9621. #ifdef HAVE_ECC_DHE
  9622. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9623. goto exit;
  9624. }
  9625. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9626. curveId)) > 0) {
  9627. goto exit;
  9628. }
  9629. #endif
  9630. }
  9631. #ifdef HAVE_ECC_DHE
  9632. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9633. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9634. !defined(HAVE_SELFTEST)
  9635. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9636. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9637. }
  9638. #endif
  9639. /* ECC Shared Secret */
  9640. bench_stats_start(&count, &start);
  9641. PRIVATE_KEY_UNLOCK();
  9642. do {
  9643. for (times = 0; times < agreeTimes || pending > 0; ) {
  9644. bench_async_poll(&pending);
  9645. /* while free pending slots in queue, submit ops */
  9646. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9647. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9648. &times, agreeTimes, &pending)) {
  9649. x[i] = (word32)keySize;
  9650. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9651. shared[i], &x[i]);
  9652. if (!bench_async_handle(&ret,
  9653. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9654. &pending)) {
  9655. goto exit_ecdhe;
  9656. }
  9657. }
  9658. } /* for i */
  9659. RECORD_MULTI_VALUE_STATS();
  9660. } /* for times */
  9661. count += times;
  9662. } while (bench_stats_check(start)
  9663. #ifdef MULTI_VALUE_STATISTICS
  9664. || runs < minimum_runs
  9665. #endif
  9666. );
  9667. PRIVATE_KEY_UNLOCK();
  9668. exit_ecdhe:
  9669. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9670. wc_ecc_get_name(curveId));
  9671. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9672. useDeviceID, count, start, ret);
  9673. #ifdef MULTI_VALUE_STATISTICS
  9674. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9675. #endif
  9676. RESET_MULTI_VALUE_STATS_VARS();
  9677. if (ret < 0) {
  9678. goto exit;
  9679. }
  9680. #endif /* HAVE_ECC_DHE */
  9681. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9682. /* Init digest to sign */
  9683. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9684. for (count = 0; count < keySize; count++) {
  9685. digest[i][count] = (byte)count;
  9686. }
  9687. }
  9688. /* ECC Sign */
  9689. bench_stats_start(&count, &start);
  9690. do {
  9691. for (times = 0; times < agreeTimes || pending > 0; ) {
  9692. bench_async_poll(&pending);
  9693. /* while free pending slots in queue, submit ops */
  9694. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9695. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9696. &times, agreeTimes, &pending)) {
  9697. if (genKey[i]->state == 0) {
  9698. x[i] = ECC_MAX_SIG_SIZE;
  9699. }
  9700. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9701. &x[i], GLOBAL_RNG, genKey[i]);
  9702. if (!bench_async_handle(&ret,
  9703. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9704. &pending)) {
  9705. goto exit_ecdsa_sign;
  9706. }
  9707. } /* bench_async_check */
  9708. } /* for i */
  9709. RECORD_MULTI_VALUE_STATS();
  9710. } /* for times */
  9711. count += times;
  9712. } while (bench_stats_check(start)
  9713. #ifdef MULTI_VALUE_STATISTICS
  9714. || runs < minimum_runs
  9715. #endif
  9716. );
  9717. exit_ecdsa_sign:
  9718. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9719. wc_ecc_get_name(curveId));
  9720. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9721. useDeviceID, count, start, ret);
  9722. #ifdef MULTI_VALUE_STATISTICS
  9723. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9724. #endif
  9725. RESET_MULTI_VALUE_STATS_VARS();
  9726. if (ret < 0) {
  9727. goto exit;
  9728. }
  9729. #ifdef HAVE_ECC_VERIFY
  9730. /* ECC Verify */
  9731. bench_stats_start(&count, &start);
  9732. do {
  9733. for (times = 0; times < agreeTimes || pending > 0; ) {
  9734. bench_async_poll(&pending);
  9735. /* while free pending slots in queue, submit ops */
  9736. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9737. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9738. &times, agreeTimes, &pending)) {
  9739. if (genKey[i]->state == 0) {
  9740. verify[i] = 0;
  9741. }
  9742. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9743. (word32)keySize, &verify[i],
  9744. genKey[i]);
  9745. if (!bench_async_handle(&ret,
  9746. BENCH_ASYNC_GET_DEV(genKey[i]),
  9747. 1, &times,
  9748. &pending)) {
  9749. goto exit_ecdsa_verify;
  9750. }
  9751. } /* if bench_async_check */
  9752. } /* for i */
  9753. RECORD_MULTI_VALUE_STATS();
  9754. } /* for times */
  9755. count += times;
  9756. } while (bench_stats_check(start)
  9757. #ifdef MULTI_VALUE_STATISTICS
  9758. || runs < minimum_runs
  9759. #endif
  9760. );
  9761. exit_ecdsa_verify:
  9762. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9763. wc_ecc_get_name(curveId));
  9764. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9765. useDeviceID, count, start, ret);
  9766. #ifdef MULTI_VALUE_STATISTICS
  9767. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9768. #endif
  9769. #endif /* HAVE_ECC_VERIFY */
  9770. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9771. exit:
  9772. /* cleanup */
  9773. if (WC_ARRAY_OK(genKey)) {
  9774. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9775. wc_ecc_free(genKey[i]);
  9776. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9777. }
  9778. #ifdef HAVE_ECC_DHE
  9779. if (WC_ARRAY_OK(genKey2)) {
  9780. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9781. wc_ecc_free(genKey2[i]);
  9782. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  9783. }
  9784. #endif
  9785. #ifdef HAVE_ECC_DHE
  9786. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  9787. #endif
  9788. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9789. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  9790. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  9791. #endif
  9792. (void)useDeviceID;
  9793. (void)pending;
  9794. (void)x;
  9795. (void)count;
  9796. (void)times;
  9797. (void)desc;
  9798. (void)start;
  9799. (void)name;
  9800. }
  9801. #ifdef HAVE_ECC_ENCRYPT
  9802. void bench_eccEncrypt(int curveId)
  9803. {
  9804. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  9805. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  9806. WC_SHA256_DIGEST_SIZE + \
  9807. (MAX_ECC_BITS+3)/4 + 2)
  9808. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  9809. #ifdef WOLFSSL_SMALL_STACK
  9810. ecc_key *userA = NULL, *userB = NULL;
  9811. byte *msg = NULL;
  9812. byte *out = NULL;
  9813. #else
  9814. ecc_key userA[1], userB[1];
  9815. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  9816. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  9817. #endif
  9818. char name[BENCH_ECC_NAME_SZ];
  9819. int keySize;
  9820. word32 bench_plainSz = bench_size;
  9821. int ret, i, count;
  9822. double start;
  9823. const char**desc = bench_desc_words[lng_index];
  9824. DECLARE_MULTI_VALUE_STATS_VARS()
  9825. #ifdef WOLFSSL_SMALL_STACK
  9826. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  9827. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9828. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  9829. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9830. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  9831. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9832. out = (byte *)XMALLOC(outSz,
  9833. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9834. if ((! userA) || (! userB) || (! msg) || (! out)) {
  9835. printf("bench_eccEncrypt malloc failed\n");
  9836. goto exit;
  9837. }
  9838. #endif
  9839. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9840. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  9841. if (ret != 0) {
  9842. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  9843. goto exit;
  9844. }
  9845. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  9846. if (ret != 0) {
  9847. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  9848. goto exit;
  9849. }
  9850. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9851. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9852. !defined(HAVE_SELFTEST)
  9853. ret = wc_ecc_set_rng(userA, &gRng);
  9854. if (ret != 0) {
  9855. goto exit;
  9856. }
  9857. ret = wc_ecc_set_rng(userB, &gRng);
  9858. if (ret != 0) {
  9859. goto exit;
  9860. }
  9861. #endif
  9862. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  9863. #ifdef WOLFSSL_ASYNC_CRYPT
  9864. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  9865. #endif
  9866. if (ret != 0)
  9867. goto exit;
  9868. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  9869. #ifdef WOLFSSL_ASYNC_CRYPT
  9870. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  9871. #endif
  9872. if (ret != 0)
  9873. goto exit;
  9874. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  9875. msg[i] = (byte)i;
  9876. }
  9877. bench_stats_start(&count, &start);
  9878. do {
  9879. for (i = 0; i < ntimes; i++) {
  9880. /* encrypt msg to B */
  9881. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  9882. out, &outSz, NULL);
  9883. if (ret != 0) {
  9884. printf("wc_ecc_encrypt failed! %d\n", ret);
  9885. goto exit_enc;
  9886. }
  9887. RECORD_MULTI_VALUE_STATS();
  9888. }
  9889. count += i;
  9890. } while (bench_stats_check(start)
  9891. #ifdef MULTI_VALUE_STATISTICS
  9892. || runs < minimum_runs
  9893. #endif
  9894. );
  9895. exit_enc:
  9896. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9897. wc_ecc_get_name(curveId));
  9898. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  9899. #ifdef MULTI_VALUE_STATISTICS
  9900. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9901. #endif
  9902. RESET_MULTI_VALUE_STATS_VARS();
  9903. if (ret != 0)
  9904. goto exit;
  9905. bench_stats_start(&count, &start);
  9906. do {
  9907. for (i = 0; i < ntimes; i++) {
  9908. /* decrypt msg from A */
  9909. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  9910. &bench_plainSz, NULL);
  9911. if (ret != 0) {
  9912. printf("wc_ecc_decrypt failed! %d\n", ret);
  9913. goto exit_dec;
  9914. }
  9915. RECORD_MULTI_VALUE_STATS();
  9916. }
  9917. count += i;
  9918. } while (bench_stats_check(start)
  9919. #ifdef MULTI_VALUE_STATISTICS
  9920. || runs < minimum_runs
  9921. #endif
  9922. );
  9923. exit_dec:
  9924. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  9925. #ifdef MULTI_VALUE_STATISTICS
  9926. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9927. #endif
  9928. exit:
  9929. /* cleanup */
  9930. #ifdef WOLFSSL_SMALL_STACK
  9931. if (userA) {
  9932. wc_ecc_free(userA);
  9933. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9934. }
  9935. if (userB) {
  9936. wc_ecc_free(userB);
  9937. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9938. }
  9939. if (msg)
  9940. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9941. if (out)
  9942. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9943. #else
  9944. wc_ecc_free(userB);
  9945. wc_ecc_free(userA);
  9946. #endif
  9947. }
  9948. #endif
  9949. #ifdef WOLFSSL_SM2
  9950. static void bench_sm2_MakeKey(int useDeviceID)
  9951. {
  9952. int ret = 0, i, times, count = 0, pending = 0;
  9953. int deviceID;
  9954. int keySize;
  9955. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9956. sizeof(ecc_key), HEAP_HINT);
  9957. char name[BENCH_ECC_NAME_SZ];
  9958. double start = 0;
  9959. const char**desc = bench_desc_words[lng_index];
  9960. DECLARE_MULTI_VALUE_STATS_VARS()
  9961. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9962. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  9963. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9964. sizeof(ecc_key), HEAP_HINT);
  9965. /* ECC Make Key */
  9966. bench_stats_start(&count, &start);
  9967. do {
  9968. /* while free pending slots in queue, submit ops */
  9969. for (times = 0; times < agreeTimes || pending > 0; ) {
  9970. bench_async_poll(&pending);
  9971. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9972. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9973. &times, agreeTimes, &pending)) {
  9974. wc_ecc_free(genKey[i]);
  9975. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9976. if (ret < 0) {
  9977. goto exit;
  9978. }
  9979. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  9980. WC_ECC_FLAG_NONE);
  9981. if (!bench_async_handle(&ret,
  9982. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9983. &pending)) {
  9984. goto exit;
  9985. }
  9986. }
  9987. } /* for i */
  9988. RECORD_MULTI_VALUE_STATS();
  9989. } /* for times */
  9990. count += times;
  9991. } while (bench_stats_check(start)
  9992. #ifdef MULTI_VALUE_STATISTICS
  9993. || runs < minimum_runs
  9994. #endif
  9995. );
  9996. exit:
  9997. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9998. wc_ecc_get_name(ECC_SM2P256V1));
  9999. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10000. start, ret);
  10001. #ifdef MULTI_VALUE_STATISTICS
  10002. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10003. #endif
  10004. /* cleanup */
  10005. if (WC_ARRAY_OK(genKey)) {
  10006. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10007. wc_ecc_free(genKey[i]);
  10008. }
  10009. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10010. }
  10011. }
  10012. void bench_sm2(int useDeviceID)
  10013. {
  10014. int ret = 0, i, times, count, pending = 0;
  10015. int deviceID;
  10016. int keySize;
  10017. char name[BENCH_ECC_NAME_SZ];
  10018. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10019. sizeof(ecc_key), HEAP_HINT);
  10020. #ifdef HAVE_ECC_DHE
  10021. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10022. sizeof(ecc_key), HEAP_HINT);
  10023. #endif
  10024. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10025. #ifdef HAVE_ECC_VERIFY
  10026. int verify[BENCH_MAX_PENDING];
  10027. #endif
  10028. #endif
  10029. word32 x[BENCH_MAX_PENDING];
  10030. double start = 0;
  10031. const char**desc = bench_desc_words[lng_index];
  10032. DECLARE_MULTI_VALUE_STATS_VARS()
  10033. #ifdef HAVE_ECC_DHE
  10034. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10035. #endif
  10036. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10037. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10038. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10039. #endif
  10040. #ifdef HAVE_ECC_DHE
  10041. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10042. #endif
  10043. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10044. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10045. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10046. #endif
  10047. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10048. bench_sm2_MakeKey(useDeviceID);
  10049. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10050. sizeof(ecc_key), HEAP_HINT);
  10051. #ifdef HAVE_ECC_DHE
  10052. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10053. sizeof(ecc_key), HEAP_HINT);
  10054. #endif
  10055. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10056. /* init keys */
  10057. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10058. /* setup an context for each key */
  10059. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10060. goto exit;
  10061. }
  10062. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10063. #ifdef WOLFSSL_ASYNC_CRYPT
  10064. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10065. #endif
  10066. if (ret < 0) {
  10067. goto exit;
  10068. }
  10069. #ifdef HAVE_ECC_DHE
  10070. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10071. goto exit;
  10072. }
  10073. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10074. WC_ECC_FLAG_NONE)) > 0) {
  10075. goto exit;
  10076. }
  10077. #endif
  10078. }
  10079. #ifdef HAVE_ECC_DHE
  10080. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10081. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10082. !defined(HAVE_SELFTEST)
  10083. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10084. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10085. }
  10086. #endif
  10087. /* ECC Shared Secret */
  10088. bench_stats_start(&count, &start);
  10089. PRIVATE_KEY_UNLOCK();
  10090. do {
  10091. for (times = 0; times < agreeTimes || pending > 0; ) {
  10092. bench_async_poll(&pending);
  10093. /* while free pending slots in queue, submit ops */
  10094. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10095. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10096. &times, agreeTimes, &pending)) {
  10097. x[i] = (word32)keySize;
  10098. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10099. shared[i], &x[i]);
  10100. if (!bench_async_handle(&ret,
  10101. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10102. &pending)) {
  10103. goto exit_ecdhe;
  10104. }
  10105. }
  10106. } /* for i */
  10107. RECORD_MULTI_VALUE_STATS();
  10108. } /* for times */
  10109. count += times;
  10110. } while (bench_stats_check(start)
  10111. #ifdef MULTI_VALUE_STATISTICS
  10112. || runs < minimum_runs
  10113. #endif
  10114. );
  10115. PRIVATE_KEY_UNLOCK();
  10116. exit_ecdhe:
  10117. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10118. wc_ecc_get_name(ECC_SM2P256V1));
  10119. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10120. start, ret);
  10121. #ifdef MULTI_VALUE_STATISTICS
  10122. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10123. #endif
  10124. if (ret < 0) {
  10125. goto exit;
  10126. }
  10127. #endif /* HAVE_ECC_DHE */
  10128. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10129. /* Init digest to sign */
  10130. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10131. for (count = 0; count < keySize; count++) {
  10132. digest[i][count] = (byte)count;
  10133. }
  10134. }
  10135. RESET_MULTI_VALUE_STATS_VARS();
  10136. /* ECC Sign */
  10137. bench_stats_start(&count, &start);
  10138. do {
  10139. for (times = 0; times < agreeTimes || pending > 0; ) {
  10140. bench_async_poll(&pending);
  10141. /* while free pending slots in queue, submit ops */
  10142. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10143. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10144. &times, agreeTimes, &pending)) {
  10145. if (genKey[i]->state == 0)
  10146. x[i] = ECC_MAX_SIG_SIZE;
  10147. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10148. sig[i], &x[i], &gRng, genKey[i]);
  10149. if (!bench_async_handle(&ret,
  10150. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10151. &pending)) {
  10152. goto exit_ecdsa_sign;
  10153. }
  10154. }
  10155. } /* for i */
  10156. RECORD_MULTI_VALUE_STATS();
  10157. } /* for times */
  10158. count += times;
  10159. } while (bench_stats_check(start)
  10160. #ifdef MULTI_VALUE_STATISTICS
  10161. || runs < minimum_runs
  10162. #endif
  10163. );
  10164. exit_ecdsa_sign:
  10165. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10166. wc_ecc_get_name(ECC_SM2P256V1));
  10167. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10168. start, ret);
  10169. #ifdef MULTI_VALUE_STATISTICS
  10170. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10171. #endif
  10172. if (ret < 0) {
  10173. goto exit;
  10174. }
  10175. #ifdef HAVE_ECC_VERIFY
  10176. /* ECC Verify */
  10177. bench_stats_start(&count, &start);
  10178. do {
  10179. for (times = 0; times < agreeTimes || pending > 0; ) {
  10180. bench_async_poll(&pending);
  10181. /* while free pending slots in queue, submit ops */
  10182. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10183. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10184. &times, agreeTimes, &pending)) {
  10185. if (genKey[i]->state == 0)
  10186. verify[i] = 0;
  10187. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10188. (word32)keySize, &verify[i], genKey[i]);
  10189. if (!bench_async_handle(&ret,
  10190. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10191. &pending)) {
  10192. goto exit_ecdsa_verify;
  10193. }
  10194. }
  10195. } /* for i */
  10196. RECORD_MULTI_VALUE_STATS();
  10197. } /* for times */
  10198. count += times;
  10199. } while (bench_stats_check(start)
  10200. #ifdef MULTI_VALUE_STATISTICS
  10201. || runs < minimum_runs
  10202. #endif
  10203. );
  10204. exit_ecdsa_verify:
  10205. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10206. wc_ecc_get_name(ECC_SM2P256V1));
  10207. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10208. start, ret);
  10209. #ifdef MULTI_VALUE_STATISTICS
  10210. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10211. #endif
  10212. #endif /* HAVE_ECC_VERIFY */
  10213. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10214. exit:
  10215. /* cleanup */
  10216. if (WC_ARRAY_OK(genKey)) {
  10217. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10218. wc_ecc_free(genKey[i]);
  10219. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10220. }
  10221. #ifdef HAVE_ECC_DHE
  10222. if (WC_ARRAY_OK(genKey2)) {
  10223. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10224. wc_ecc_free(genKey2[i]);
  10225. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10226. }
  10227. #endif
  10228. #ifdef HAVE_ECC_DHE
  10229. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10230. #endif
  10231. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10232. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10233. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10234. #endif
  10235. (void)useDeviceID;
  10236. (void)pending;
  10237. (void)x;
  10238. (void)count;
  10239. (void)times;
  10240. (void)desc;
  10241. (void)start;
  10242. (void)name;
  10243. }
  10244. #endif /* WOLFSSL_SM2 */
  10245. #endif /* HAVE_ECC */
  10246. #ifdef HAVE_CURVE25519
  10247. void bench_curve25519KeyGen(int useDeviceID)
  10248. {
  10249. curve25519_key genKey;
  10250. double start;
  10251. int ret = 0, i, count;
  10252. const char**desc = bench_desc_words[lng_index];
  10253. DECLARE_MULTI_VALUE_STATS_VARS()
  10254. /* Key Gen */
  10255. bench_stats_start(&count, &start);
  10256. do {
  10257. for (i = 0; i < genTimes; i++) {
  10258. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10259. useDeviceID ? devId : INVALID_DEVID);
  10260. if (ret != 0) {
  10261. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10262. break;
  10263. }
  10264. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10265. wc_curve25519_free(&genKey);
  10266. if (ret != 0) {
  10267. printf("wc_curve25519_make_key failed: %d\n", ret);
  10268. break;
  10269. }
  10270. RECORD_MULTI_VALUE_STATS();
  10271. }
  10272. count += i;
  10273. } while (bench_stats_check(start)
  10274. #ifdef MULTI_VALUE_STATISTICS
  10275. || runs < minimum_runs
  10276. #endif
  10277. );
  10278. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10279. ret);
  10280. #ifdef MULTI_VALUE_STATISTICS
  10281. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10282. #endif
  10283. }
  10284. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10285. void bench_curve25519KeyAgree(int useDeviceID)
  10286. {
  10287. curve25519_key genKey, genKey2;
  10288. double start;
  10289. int ret, i, count;
  10290. byte shared[32];
  10291. const char**desc = bench_desc_words[lng_index];
  10292. word32 x = 0;
  10293. DECLARE_MULTI_VALUE_STATS_VARS()
  10294. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10295. useDeviceID ? devId : INVALID_DEVID);
  10296. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10297. useDeviceID ? devId : INVALID_DEVID);
  10298. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10299. if (ret != 0) {
  10300. printf("curve25519_make_key failed\n");
  10301. return;
  10302. }
  10303. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10304. if (ret != 0) {
  10305. printf("curve25519_make_key failed: %d\n", ret);
  10306. wc_curve25519_free(&genKey);
  10307. return;
  10308. }
  10309. /* Shared secret */
  10310. bench_stats_start(&count, &start);
  10311. do {
  10312. for (i = 0; i < agreeTimes; i++) {
  10313. x = sizeof(shared);
  10314. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10315. if (ret != 0) {
  10316. printf("curve25519_shared_secret failed: %d\n", ret);
  10317. goto exit;
  10318. }
  10319. RECORD_MULTI_VALUE_STATS();
  10320. }
  10321. count += i;
  10322. } while (bench_stats_check(start)
  10323. #ifdef MULTI_VALUE_STATISTICS
  10324. || runs < minimum_runs
  10325. #endif
  10326. );
  10327. exit:
  10328. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10329. ret);
  10330. #ifdef MULTI_VALUE_STATISTICS
  10331. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10332. #endif
  10333. wc_curve25519_free(&genKey2);
  10334. wc_curve25519_free(&genKey);
  10335. }
  10336. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10337. #endif /* HAVE_CURVE25519 */
  10338. #ifdef HAVE_ED25519
  10339. void bench_ed25519KeyGen(void)
  10340. {
  10341. #ifdef HAVE_ED25519_MAKE_KEY
  10342. ed25519_key genKey;
  10343. double start;
  10344. int i, count;
  10345. const char**desc = bench_desc_words[lng_index];
  10346. DECLARE_MULTI_VALUE_STATS_VARS()
  10347. /* Key Gen */
  10348. bench_stats_start(&count, &start);
  10349. do {
  10350. for (i = 0; i < genTimes; i++) {
  10351. wc_ed25519_init(&genKey);
  10352. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10353. wc_ed25519_free(&genKey);
  10354. RECORD_MULTI_VALUE_STATS();
  10355. }
  10356. count += i;
  10357. } while (bench_stats_check(start)
  10358. #ifdef MULTI_VALUE_STATISTICS
  10359. || runs < minimum_runs
  10360. #endif
  10361. );
  10362. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10363. #ifdef MULTI_VALUE_STATISTICS
  10364. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10365. #endif
  10366. #endif /* HAVE_ED25519_MAKE_KEY */
  10367. }
  10368. void bench_ed25519KeySign(void)
  10369. {
  10370. #ifdef HAVE_ED25519_MAKE_KEY
  10371. int ret;
  10372. #endif
  10373. ed25519_key genKey;
  10374. #ifdef HAVE_ED25519_SIGN
  10375. double start;
  10376. int i, count;
  10377. byte sig[ED25519_SIG_SIZE];
  10378. byte msg[512];
  10379. word32 x = 0;
  10380. const char**desc = bench_desc_words[lng_index];
  10381. DECLARE_MULTI_VALUE_STATS_VARS()
  10382. #endif
  10383. wc_ed25519_init(&genKey);
  10384. #ifdef HAVE_ED25519_MAKE_KEY
  10385. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10386. if (ret != 0) {
  10387. printf("ed25519_make_key failed\n");
  10388. return;
  10389. }
  10390. #endif
  10391. #ifdef HAVE_ED25519_SIGN
  10392. /* make dummy msg */
  10393. for (i = 0; i < (int)sizeof(msg); i++)
  10394. msg[i] = (byte)i;
  10395. bench_stats_start(&count, &start);
  10396. do {
  10397. for (i = 0; i < agreeTimes; i++) {
  10398. x = sizeof(sig);
  10399. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10400. if (ret != 0) {
  10401. printf("ed25519_sign_msg failed\n");
  10402. goto exit_ed_sign;
  10403. }
  10404. RECORD_MULTI_VALUE_STATS();
  10405. }
  10406. count += i;
  10407. } while (bench_stats_check(start)
  10408. #ifdef MULTI_VALUE_STATISTICS
  10409. || runs < minimum_runs
  10410. #endif
  10411. );
  10412. exit_ed_sign:
  10413. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10414. #ifdef MULTI_VALUE_STATISTICS
  10415. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10416. #endif
  10417. RESET_MULTI_VALUE_STATS_VARS();
  10418. #ifdef HAVE_ED25519_VERIFY
  10419. bench_stats_start(&count, &start);
  10420. do {
  10421. for (i = 0; i < agreeTimes; i++) {
  10422. int verify = 0;
  10423. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10424. &genKey);
  10425. if (ret != 0 || verify != 1) {
  10426. printf("ed25519_verify_msg failed\n");
  10427. goto exit_ed_verify;
  10428. }
  10429. RECORD_MULTI_VALUE_STATS();
  10430. }
  10431. count += i;
  10432. } while (bench_stats_check(start)
  10433. #ifdef MULTI_VALUE_STATISTICS
  10434. || runs < minimum_runs
  10435. #endif
  10436. );
  10437. exit_ed_verify:
  10438. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10439. #ifdef MULTI_VALUE_STATISTICS
  10440. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10441. #endif
  10442. #endif /* HAVE_ED25519_VERIFY */
  10443. #endif /* HAVE_ED25519_SIGN */
  10444. wc_ed25519_free(&genKey);
  10445. }
  10446. #endif /* HAVE_ED25519 */
  10447. #ifdef HAVE_CURVE448
  10448. void bench_curve448KeyGen(void)
  10449. {
  10450. curve448_key genKey;
  10451. double start;
  10452. int ret = 0, i, count;
  10453. const char**desc = bench_desc_words[lng_index];
  10454. DECLARE_MULTI_VALUE_STATS_VARS()
  10455. /* Key Gen */
  10456. bench_stats_start(&count, &start);
  10457. do {
  10458. for (i = 0; i < genTimes; i++) {
  10459. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10460. wc_curve448_free(&genKey);
  10461. if (ret != 0) {
  10462. printf("wc_curve448_make_key failed: %d\n", ret);
  10463. break;
  10464. }
  10465. RECORD_MULTI_VALUE_STATS();
  10466. }
  10467. count += i;
  10468. } while (bench_stats_check(start)
  10469. #ifdef MULTI_VALUE_STATISTICS
  10470. || runs < minimum_runs
  10471. #endif
  10472. );
  10473. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10474. #ifdef MULTI_VALUE_STATISTICS
  10475. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10476. #endif
  10477. }
  10478. #ifdef HAVE_CURVE448_SHARED_SECRET
  10479. void bench_curve448KeyAgree(void)
  10480. {
  10481. curve448_key genKey, genKey2;
  10482. double start;
  10483. int ret, i, count;
  10484. byte shared[56];
  10485. const char**desc = bench_desc_words[lng_index];
  10486. word32 x = 0;
  10487. DECLARE_MULTI_VALUE_STATS_VARS()
  10488. wc_curve448_init(&genKey);
  10489. wc_curve448_init(&genKey2);
  10490. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10491. if (ret != 0) {
  10492. printf("curve448_make_key failed\n");
  10493. return;
  10494. }
  10495. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10496. if (ret != 0) {
  10497. printf("curve448_make_key failed: %d\n", ret);
  10498. wc_curve448_free(&genKey);
  10499. return;
  10500. }
  10501. /* Shared secret */
  10502. bench_stats_start(&count, &start);
  10503. do {
  10504. for (i = 0; i < agreeTimes; i++) {
  10505. x = sizeof(shared);
  10506. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10507. if (ret != 0) {
  10508. printf("curve448_shared_secret failed: %d\n", ret);
  10509. goto exit;
  10510. }
  10511. RECORD_MULTI_VALUE_STATS();
  10512. }
  10513. count += i;
  10514. } while (bench_stats_check(start)
  10515. #ifdef MULTI_VALUE_STATISTICS
  10516. || runs < minimum_runs
  10517. #endif
  10518. );
  10519. exit:
  10520. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10521. #ifdef MULTI_VALUE_STATISTICS
  10522. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10523. #endif
  10524. wc_curve448_free(&genKey2);
  10525. wc_curve448_free(&genKey);
  10526. }
  10527. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10528. #endif /* HAVE_CURVE448 */
  10529. #ifdef HAVE_ED448
  10530. void bench_ed448KeyGen(void)
  10531. {
  10532. ed448_key genKey;
  10533. double start;
  10534. int i, count;
  10535. const char**desc = bench_desc_words[lng_index];
  10536. DECLARE_MULTI_VALUE_STATS_VARS()
  10537. /* Key Gen */
  10538. bench_stats_start(&count, &start);
  10539. do {
  10540. for (i = 0; i < genTimes; i++) {
  10541. wc_ed448_init(&genKey);
  10542. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10543. wc_ed448_free(&genKey);
  10544. RECORD_MULTI_VALUE_STATS();
  10545. }
  10546. count += i;
  10547. } while (bench_stats_check(start)
  10548. #ifdef MULTI_VALUE_STATISTICS
  10549. || runs < minimum_runs
  10550. #endif
  10551. );
  10552. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10553. #ifdef MULTI_VALUE_STATISTICS
  10554. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10555. #endif
  10556. }
  10557. void bench_ed448KeySign(void)
  10558. {
  10559. int ret;
  10560. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10561. #ifdef HAVE_ED448_SIGN
  10562. double start;
  10563. int i, count;
  10564. byte sig[ED448_SIG_SIZE];
  10565. byte msg[512];
  10566. word32 x = 0;
  10567. const char**desc = bench_desc_words[lng_index];
  10568. DECLARE_MULTI_VALUE_STATS_VARS()
  10569. #endif
  10570. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10571. wc_ed448_init(genKey);
  10572. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10573. if (ret != 0) {
  10574. printf("ed448_make_key failed\n");
  10575. goto exit;
  10576. }
  10577. #ifdef HAVE_ED448_SIGN
  10578. /* make dummy msg */
  10579. for (i = 0; i < (int)sizeof(msg); i++)
  10580. msg[i] = (byte)i;
  10581. bench_stats_start(&count, &start);
  10582. do {
  10583. for (i = 0; i < agreeTimes; i++) {
  10584. x = sizeof(sig);
  10585. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10586. NULL, 0);
  10587. if (ret != 0) {
  10588. printf("ed448_sign_msg failed\n");
  10589. goto exit;
  10590. }
  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", 448, desc[4], 0, count, start, ret);
  10600. #ifdef MULTI_VALUE_STATISTICS
  10601. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10602. #endif
  10603. RESET_MULTI_VALUE_STATS_VARS();
  10604. #ifdef HAVE_ED448_VERIFY
  10605. bench_stats_start(&count, &start);
  10606. do {
  10607. for (i = 0; i < agreeTimes; i++) {
  10608. int verify = 0;
  10609. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10610. genKey, NULL, 0);
  10611. if (ret != 0 || verify != 1) {
  10612. printf("ed448_verify_msg failed\n");
  10613. goto exit;
  10614. }
  10615. RECORD_MULTI_VALUE_STATS();
  10616. }
  10617. count += i;
  10618. } while (bench_stats_check(start)
  10619. #ifdef MULTI_VALUE_STATISTICS
  10620. || runs < minimum_runs
  10621. #endif
  10622. );
  10623. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10624. #ifdef MULTI_VALUE_STATISTICS
  10625. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10626. #endif
  10627. #endif /* HAVE_ED448_VERIFY */
  10628. #endif /* HAVE_ED448_SIGN */
  10629. exit:
  10630. wc_ed448_free(genKey);
  10631. WC_FREE_VAR(genKey, HEAP_HINT);
  10632. }
  10633. #endif /* HAVE_ED448 */
  10634. #ifdef WOLFCRYPT_HAVE_ECCSI
  10635. #ifdef WOLFCRYPT_ECCSI_KMS
  10636. void bench_eccsiKeyGen(void)
  10637. {
  10638. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10639. double start;
  10640. int i, count;
  10641. const char**desc = bench_desc_words[lng_index];
  10642. int ret;
  10643. DECLARE_MULTI_VALUE_STATS_VARS()
  10644. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10645. /* Key Gen */
  10646. bench_stats_start(&count, &start);
  10647. do {
  10648. for (i = 0; i < genTimes; i++) {
  10649. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10650. ret = wc_MakeEccsiKey(genKey, &gRng);
  10651. wc_FreeEccsiKey(genKey);
  10652. if (ret != 0) {
  10653. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10654. goto exit;
  10655. }
  10656. RECORD_MULTI_VALUE_STATS();
  10657. }
  10658. count += i;
  10659. } while (bench_stats_check(start)
  10660. #ifdef MULTI_VALUE_STATISTICS
  10661. || runs < minimum_runs
  10662. #endif
  10663. );
  10664. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10665. #ifdef MULTI_VALUE_STATISTICS
  10666. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10667. #endif
  10668. exit:
  10669. WC_FREE_VAR(genKey, HEAP_HINT);
  10670. }
  10671. void bench_eccsiPairGen(void)
  10672. {
  10673. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10674. double start;
  10675. int i, count;
  10676. const char**desc = bench_desc_words[lng_index];
  10677. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10678. ecc_point* pvt;
  10679. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10680. int ret;
  10681. DECLARE_MULTI_VALUE_STATS_VARS()
  10682. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10683. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10684. (void)mp_init(ssk);
  10685. pvt = wc_ecc_new_point();
  10686. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10687. (void)wc_MakeEccsiKey(genKey, &gRng);
  10688. /* RSK Gen */
  10689. bench_stats_start(&count, &start);
  10690. do {
  10691. for (i = 0; i < genTimes; i++) {
  10692. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10693. sizeof(id), ssk, pvt);
  10694. if (ret != 0) {
  10695. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10696. goto exit;
  10697. }
  10698. RECORD_MULTI_VALUE_STATS();
  10699. }
  10700. count += i;
  10701. } while (bench_stats_check(start)
  10702. #ifdef MULTI_VALUE_STATISTICS
  10703. || runs < minimum_runs
  10704. #endif
  10705. );
  10706. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10707. #ifdef MULTI_VALUE_STATISTICS
  10708. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10709. #endif
  10710. wc_FreeEccsiKey(genKey);
  10711. wc_ecc_del_point(pvt);
  10712. mp_free(ssk);
  10713. exit:
  10714. WC_FREE_VAR(genKey, HEAP_HINT);
  10715. WC_FREE_VAR(ssk, HEAP_HINT);
  10716. }
  10717. #endif
  10718. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10719. void bench_eccsiValidate(void)
  10720. {
  10721. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10722. double start;
  10723. int i, count;
  10724. const char**desc = bench_desc_words[lng_index];
  10725. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10726. ecc_point* pvt;
  10727. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10728. int valid;
  10729. int ret;
  10730. DECLARE_MULTI_VALUE_STATS_VARS()
  10731. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10732. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10733. (void)mp_init(ssk);
  10734. pvt = wc_ecc_new_point();
  10735. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10736. (void)wc_MakeEccsiKey(genKey, &gRng);
  10737. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10738. ssk, pvt);
  10739. /* Validation of RSK */
  10740. bench_stats_start(&count, &start);
  10741. do {
  10742. for (i = 0; i < genTimes; i++) {
  10743. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10744. sizeof(id), ssk, pvt, &valid);
  10745. if (ret != 0 || !valid) {
  10746. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10747. valid);
  10748. goto exit;
  10749. }
  10750. RECORD_MULTI_VALUE_STATS();
  10751. }
  10752. count += i;
  10753. } while (bench_stats_check(start)
  10754. #ifdef MULTI_VALUE_STATISTICS
  10755. || runs < minimum_runs
  10756. #endif
  10757. );
  10758. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10759. #ifdef MULTI_VALUE_STATISTICS
  10760. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10761. #endif
  10762. wc_FreeEccsiKey(genKey);
  10763. wc_ecc_del_point(pvt);
  10764. mp_free(ssk);
  10765. exit:
  10766. WC_FREE_VAR(genKey, HEAP_HINT);
  10767. WC_FREE_VAR(ssk, HEAP_HINT);
  10768. }
  10769. void bench_eccsi(void)
  10770. {
  10771. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10772. double start;
  10773. int i, count;
  10774. const char**desc = bench_desc_words[lng_index];
  10775. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10776. ecc_point* pvt;
  10777. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10778. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10779. byte hash[WC_SHA256_DIGEST_SIZE];
  10780. byte hashSz = (byte)sizeof(hash);
  10781. byte sig[257];
  10782. word32 sigSz = sizeof(sig);
  10783. int ret;
  10784. int verified;
  10785. DECLARE_MULTI_VALUE_STATS_VARS()
  10786. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10787. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10788. (void)mp_init(ssk);
  10789. pvt = wc_ecc_new_point();
  10790. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10791. (void)wc_MakeEccsiKey(genKey, &gRng);
  10792. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10793. ssk, pvt);
  10794. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  10795. hash, &hashSz);
  10796. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  10797. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  10798. /* Encapsulate */
  10799. bench_stats_start(&count, &start);
  10800. do {
  10801. for (i = 0; i < genTimes; i++) {
  10802. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  10803. sizeof(msg), sig, &sigSz);
  10804. if (ret != 0) {
  10805. printf("wc_SignEccsiHash failed: %d\n", ret);
  10806. break;
  10807. }
  10808. RECORD_MULTI_VALUE_STATS();
  10809. }
  10810. count += i;
  10811. } while (bench_stats_check(start)
  10812. #ifdef MULTI_VALUE_STATISTICS
  10813. || runs < minimum_runs
  10814. #endif
  10815. );
  10816. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  10817. #ifdef MULTI_VALUE_STATISTICS
  10818. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10819. #endif
  10820. RESET_MULTI_VALUE_STATS_VARS();
  10821. /* Derive */
  10822. bench_stats_start(&count, &start);
  10823. do {
  10824. for (i = 0; i < genTimes; i++) {
  10825. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  10826. sizeof(msg), sig, sigSz, &verified);
  10827. if (ret != 0 || !verified) {
  10828. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  10829. verified);
  10830. goto exit;
  10831. }
  10832. RECORD_MULTI_VALUE_STATS();
  10833. }
  10834. count += i;
  10835. } while (bench_stats_check(start)
  10836. #ifdef MULTI_VALUE_STATISTICS
  10837. || runs < minimum_runs
  10838. #endif
  10839. );
  10840. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  10841. #ifdef MULTI_VALUE_STATISTICS
  10842. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10843. #endif
  10844. wc_FreeEccsiKey(genKey);
  10845. wc_ecc_del_point(pvt);
  10846. exit:
  10847. WC_FREE_VAR(genKey, HEAP_HINT);
  10848. WC_FREE_VAR(ssk, HEAP_HINT);
  10849. }
  10850. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  10851. #endif /* WOLFCRYPT_HAVE_ECCSI */
  10852. #ifdef WOLFCRYPT_HAVE_SAKKE
  10853. #ifdef WOLFCRYPT_SAKKE_KMS
  10854. void bench_sakkeKeyGen(void)
  10855. {
  10856. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10857. double start;
  10858. int i, count;
  10859. const char**desc = bench_desc_words[lng_index];
  10860. int ret;
  10861. DECLARE_MULTI_VALUE_STATS_VARS()
  10862. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10863. /* Key Gen */
  10864. bench_stats_start(&count, &start);
  10865. do {
  10866. for (i = 0; i < genTimes; i++) {
  10867. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10868. ret = wc_MakeSakkeKey(genKey, &gRng);
  10869. if (ret != 0) {
  10870. printf("wc_MakeSakkeKey failed: %d\n", ret);
  10871. goto exit;
  10872. }
  10873. wc_FreeSakkeKey(genKey);
  10874. RECORD_MULTI_VALUE_STATS();
  10875. }
  10876. count += i;
  10877. } while (bench_stats_check(start)
  10878. #ifdef MULTI_VALUE_STATISTICS
  10879. || runs < minimum_runs
  10880. #endif
  10881. );
  10882. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  10883. #ifdef MULTI_VALUE_STATISTICS
  10884. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10885. #endif
  10886. exit:
  10887. WC_FREE_VAR(genKey, HEAP_HINT);
  10888. }
  10889. void bench_sakkeRskGen(void)
  10890. {
  10891. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10892. double start;
  10893. int i, count;
  10894. const char**desc = bench_desc_words[lng_index];
  10895. ecc_point* rsk;
  10896. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10897. int ret;
  10898. DECLARE_MULTI_VALUE_STATS_VARS()
  10899. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10900. rsk = wc_ecc_new_point();
  10901. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10902. (void)wc_MakeSakkeKey(genKey, &gRng);
  10903. /* RSK Gen */
  10904. bench_stats_start(&count, &start);
  10905. do {
  10906. for (i = 0; i < genTimes; i++) {
  10907. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  10908. if (ret != 0) {
  10909. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  10910. goto exit;
  10911. }
  10912. RECORD_MULTI_VALUE_STATS();
  10913. }
  10914. count += i;
  10915. } while (bench_stats_check(start)
  10916. #ifdef MULTI_VALUE_STATISTICS
  10917. || runs < minimum_runs
  10918. #endif
  10919. );
  10920. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  10921. #ifdef MULTI_VALUE_STATISTICS
  10922. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10923. #endif
  10924. wc_FreeSakkeKey(genKey);
  10925. wc_ecc_del_point(rsk);
  10926. exit:
  10927. WC_FREE_VAR(genKey, HEAP_HINT);
  10928. }
  10929. #endif
  10930. #ifdef WOLFCRYPT_SAKKE_CLIENT
  10931. void bench_sakkeValidate(void)
  10932. {
  10933. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10934. double start;
  10935. int i, count;
  10936. const char**desc = bench_desc_words[lng_index];
  10937. ecc_point* rsk;
  10938. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10939. int valid;
  10940. int ret;
  10941. DECLARE_MULTI_VALUE_STATS_VARS()
  10942. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10943. rsk = wc_ecc_new_point();
  10944. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10945. (void)wc_MakeSakkeKey(genKey, &gRng);
  10946. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  10947. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  10948. /* Validation of RSK */
  10949. bench_stats_start(&count, &start);
  10950. do {
  10951. for (i = 0; i < genTimes; i++) {
  10952. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  10953. if (ret != 0 || !valid) {
  10954. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  10955. valid);
  10956. goto exit;
  10957. }
  10958. RECORD_MULTI_VALUE_STATS();
  10959. }
  10960. count += i;
  10961. } while (bench_stats_check(start)
  10962. #ifdef MULTI_VALUE_STATISTICS
  10963. || runs < minimum_runs
  10964. #endif
  10965. );
  10966. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  10967. #ifdef MULTI_VALUE_STATISTICS
  10968. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10969. #endif
  10970. wc_FreeSakkeKey(genKey);
  10971. wc_ecc_del_point(rsk);
  10972. exit:
  10973. WC_FREE_VAR(genKey, HEAP_HINT);
  10974. }
  10975. void bench_sakke(void)
  10976. {
  10977. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10978. double start;
  10979. int i, count;
  10980. const char**desc = bench_desc_words[lng_index];
  10981. ecc_point* rsk;
  10982. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10983. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  10984. byte ssv[sizeof(ssv_init)];
  10985. byte derSSV[sizeof(ssv)];
  10986. byte auth[257];
  10987. word16 authSz = sizeof(auth);
  10988. int ret = 0;
  10989. byte* table = NULL;
  10990. word32 len = 0;
  10991. byte* iTable = NULL;
  10992. word32 iTableLen = 0;
  10993. DECLARE_MULTI_VALUE_STATS_VARS()
  10994. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10995. XMEMCPY(ssv, ssv_init, sizeof ssv);
  10996. rsk = wc_ecc_new_point();
  10997. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10998. (void)wc_MakeSakkeKey(genKey, &gRng);
  10999. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11000. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11001. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11002. /* Encapsulate */
  11003. bench_stats_start(&count, &start);
  11004. do {
  11005. for (i = 0; i < genTimes; i++) {
  11006. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11007. WC_HASH_TYPE_SHA256,
  11008. ssv, sizeof(ssv), auth, &authSz);
  11009. if (ret != 0) {
  11010. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11011. break;
  11012. }
  11013. RECORD_MULTI_VALUE_STATS();
  11014. } /* for */
  11015. count += i;
  11016. } while (bench_stats_check(start)
  11017. #ifdef MULTI_VALUE_STATISTICS
  11018. || runs < minimum_runs
  11019. #endif
  11020. );
  11021. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11022. 0, count, start, 0);
  11023. #ifdef MULTI_VALUE_STATISTICS
  11024. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11025. #endif
  11026. RESET_MULTI_VALUE_STATS_VARS();
  11027. /* Derive */
  11028. bench_stats_start(&count, &start);
  11029. do {
  11030. for (i = 0; i < genTimes; i++) {
  11031. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11032. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11033. sizeof(derSSV), auth, authSz);
  11034. if (ret != 0) {
  11035. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11036. break;
  11037. }
  11038. RECORD_MULTI_VALUE_STATS();
  11039. }
  11040. if (ret != 0) break;
  11041. count += i;
  11042. } while (bench_stats_check(start)
  11043. #ifdef MULTI_VALUE_STATISTICS
  11044. || runs < minimum_runs
  11045. #endif
  11046. );
  11047. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11048. 0, count, start, 0);
  11049. #ifdef MULTI_VALUE_STATISTICS
  11050. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11051. #endif
  11052. /* Calculate Point I and generate table. */
  11053. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11054. iTableLen = 0;
  11055. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11056. if (iTableLen != 0) {
  11057. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11058. if (iTable == NULL)
  11059. WC_ALLOC_DO_ON_FAILURE();
  11060. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11061. }
  11062. /* Encapsulate with Point I table */
  11063. bench_stats_start(&count, &start);
  11064. do {
  11065. for (i = 0; i < genTimes; i++) {
  11066. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11067. WC_HASH_TYPE_SHA256, ssv,
  11068. sizeof(ssv), auth, &authSz);
  11069. if (ret != 0) {
  11070. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11071. break;
  11072. }
  11073. RECORD_MULTI_VALUE_STATS();
  11074. }
  11075. count += i;
  11076. } while (bench_stats_check(start)
  11077. #ifdef MULTI_VALUE_STATISTICS
  11078. || runs < minimum_runs
  11079. #endif
  11080. );
  11081. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11082. count, start, 0);
  11083. #ifdef MULTI_VALUE_STATISTICS
  11084. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11085. #endif
  11086. RESET_MULTI_VALUE_STATS_VARS();
  11087. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11088. /* Derive with Point I table */
  11089. bench_stats_start(&count, &start);
  11090. do {
  11091. for (i = 0; i < genTimes; i++) {
  11092. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11093. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11094. sizeof(derSSV), auth, authSz);
  11095. if (ret != 0) {
  11096. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11097. break;
  11098. }
  11099. RECORD_MULTI_VALUE_STATS();
  11100. }
  11101. if (ret != 0) break;
  11102. count += i;
  11103. } while (bench_stats_check(start)
  11104. #ifdef MULTI_VALUE_STATISTICS
  11105. || runs < minimum_runs
  11106. #endif
  11107. );
  11108. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11109. count, start, 0);
  11110. #ifdef MULTI_VALUE_STATISTICS
  11111. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11112. #endif
  11113. RESET_MULTI_VALUE_STATS_VARS();
  11114. len = 0;
  11115. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11116. if (len > 0) {
  11117. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11118. if (table == NULL)
  11119. WC_ALLOC_DO_ON_FAILURE();
  11120. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11121. }
  11122. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11123. /* Derive with Point I table and RSK table */
  11124. bench_stats_start(&count, &start);
  11125. do {
  11126. for (i = 0; i < genTimes; i++) {
  11127. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11128. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11129. sizeof(derSSV), auth, authSz);
  11130. if (ret != 0) {
  11131. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11132. break;
  11133. }
  11134. RECORD_MULTI_VALUE_STATS();
  11135. }
  11136. if (ret != 0) break;
  11137. count += i;
  11138. } while (bench_stats_check(start)
  11139. #ifdef MULTI_VALUE_STATISTICS
  11140. || runs < minimum_runs
  11141. #endif
  11142. );
  11143. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11144. 0, count, start, 0);
  11145. #ifdef MULTI_VALUE_STATISTICS
  11146. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11147. #endif
  11148. RESET_MULTI_VALUE_STATS_VARS();
  11149. wc_ClearSakkePointITable(genKey);
  11150. /* Derive with RSK table */
  11151. bench_stats_start(&count, &start);
  11152. do {
  11153. for (i = 0; i < genTimes; i++) {
  11154. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11155. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11156. sizeof(derSSV), auth, authSz);
  11157. if (ret != 0) {
  11158. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11159. break;
  11160. }
  11161. RECORD_MULTI_VALUE_STATS();
  11162. }
  11163. if (ret != 0) break;
  11164. count += i;
  11165. } while (bench_stats_check(start)
  11166. #ifdef MULTI_VALUE_STATISTICS
  11167. || runs < minimum_runs
  11168. #endif
  11169. );
  11170. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11171. count, start, 0);
  11172. #ifdef MULTI_VALUE_STATISTICS
  11173. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11174. #endif
  11175. wc_FreeSakkeKey(genKey);
  11176. wc_ecc_del_point(rsk);
  11177. exit:
  11178. if (iTable)
  11179. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11180. if (table)
  11181. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11182. WC_FREE_VAR(genKey, HEAP_HINT);
  11183. }
  11184. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11185. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11186. #ifdef HAVE_FALCON
  11187. void bench_falconKeySign(byte level)
  11188. {
  11189. int ret = 0;
  11190. falcon_key key;
  11191. double start;
  11192. int i, count;
  11193. byte sig[FALCON_MAX_SIG_SIZE];
  11194. byte msg[512];
  11195. word32 x = 0;
  11196. const char**desc = bench_desc_words[lng_index];
  11197. DECLARE_MULTI_VALUE_STATS_VARS()
  11198. ret = wc_falcon_init(&key);
  11199. if (ret != 0) {
  11200. printf("wc_falcon_init failed %d\n", ret);
  11201. return;
  11202. }
  11203. ret = wc_falcon_set_level(&key, level);
  11204. if (ret != 0) {
  11205. printf("wc_falcon_set_level failed %d\n", ret);
  11206. }
  11207. if (ret == 0) {
  11208. if (level == 1) {
  11209. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11210. sizeof_bench_falcon_level1_key,
  11211. NULL, 0, &key);
  11212. }
  11213. else {
  11214. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11215. sizeof_bench_falcon_level5_key,
  11216. NULL, 0, &key);
  11217. }
  11218. if (ret != 0) {
  11219. printf("wc_falcon_import_private_key failed %d\n", ret);
  11220. }
  11221. }
  11222. /* make dummy msg */
  11223. for (i = 0; i < (int)sizeof(msg); i++) {
  11224. msg[i] = (byte)i;
  11225. }
  11226. bench_stats_start(&count, &start);
  11227. do {
  11228. for (i = 0; i < agreeTimes; i++) {
  11229. if (ret == 0) {
  11230. if (level == 1) {
  11231. x = FALCON_LEVEL1_SIG_SIZE;
  11232. }
  11233. else {
  11234. x = FALCON_LEVEL5_SIG_SIZE;
  11235. }
  11236. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11237. if (ret != 0) {
  11238. printf("wc_falcon_sign_msg failed\n");
  11239. }
  11240. }
  11241. RECORD_MULTI_VALUE_STATS();
  11242. }
  11243. count += i;
  11244. } while (bench_stats_check(start)
  11245. #ifdef MULTI_VALUE_STATISTICS
  11246. || runs < minimum_runs
  11247. #endif
  11248. );
  11249. if (ret == 0) {
  11250. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11251. count, start, ret);
  11252. #ifdef MULTI_VALUE_STATISTICS
  11253. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11254. #endif
  11255. }
  11256. RESET_MULTI_VALUE_STATS_VARS();
  11257. bench_stats_start(&count, &start);
  11258. do {
  11259. for (i = 0; i < agreeTimes; i++) {
  11260. if (ret == 0) {
  11261. int verify = 0;
  11262. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11263. &key);
  11264. if (ret != 0 || verify != 1) {
  11265. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11266. ret, verify);
  11267. ret = -1;
  11268. }
  11269. }
  11270. RECORD_MULTI_VALUE_STATS();
  11271. }
  11272. count += i;
  11273. } while (bench_stats_check(start)
  11274. #ifdef MULTI_VALUE_STATISTICS
  11275. || runs < minimum_runs
  11276. #endif
  11277. );
  11278. if (ret == 0) {
  11279. bench_stats_asym_finish("FALCON", level, desc[5],
  11280. 0, count, start, ret);
  11281. #ifdef MULTI_VALUE_STATISTICS
  11282. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11283. #endif
  11284. }
  11285. wc_falcon_free(&key);
  11286. }
  11287. #endif /* HAVE_FALCON */
  11288. #ifdef HAVE_DILITHIUM
  11289. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11290. #ifndef WOLFSSL_NO_ML_DSA_44
  11291. static const unsigned char bench_dilithium_level2_sig[] = {
  11292. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11293. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11294. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11295. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11296. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11297. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11298. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11299. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11300. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11301. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11302. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11303. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11304. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11305. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11306. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11307. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11308. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11309. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11310. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11311. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11312. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11313. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11314. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11315. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11316. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11317. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11318. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11319. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11320. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11321. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11322. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11323. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11324. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11325. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11326. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11327. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11328. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11329. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11330. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11331. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11332. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11333. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11334. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11335. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11336. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11337. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11338. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11339. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11340. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11341. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11342. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11343. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11344. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11345. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11346. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11347. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11348. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11349. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11350. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11351. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11352. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11353. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11354. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11355. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11356. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11357. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11358. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11359. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11360. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11361. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11362. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11363. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11364. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11365. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11366. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11367. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11368. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11369. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11370. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11371. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11372. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11373. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11374. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11375. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11376. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11377. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11378. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11379. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11380. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11381. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11382. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11383. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11384. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11385. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11386. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11387. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11388. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11389. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11390. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11391. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11392. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11393. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11394. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11395. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11396. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11397. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11398. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11399. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11400. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11401. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11402. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11403. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11404. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11405. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11406. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11407. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11408. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11409. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11410. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11411. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11412. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11413. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11414. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11415. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11416. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11417. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11418. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11419. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11420. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11421. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11422. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11423. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11424. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11425. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11426. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11427. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11428. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11429. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11430. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11431. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11432. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11433. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11434. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11435. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11436. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11437. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11438. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11439. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11440. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11441. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11442. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11443. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11444. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11445. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11446. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11447. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11448. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11449. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11450. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11451. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11452. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11453. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11454. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11455. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11456. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11457. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11458. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11459. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11460. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11461. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11462. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11463. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11464. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11465. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11466. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11467. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11468. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11469. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11470. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11471. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11472. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11473. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11474. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11475. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11476. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11477. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11478. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11479. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11480. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11481. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11482. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11483. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11484. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11485. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11486. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11487. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11488. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11489. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11490. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11491. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11492. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11493. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11494. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11495. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11496. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11497. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11498. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11499. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11500. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11501. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11502. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11503. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11504. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11505. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11506. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11507. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11508. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11509. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11510. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11511. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11512. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11513. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11514. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11515. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11516. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11517. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11518. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11519. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11520. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11521. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11522. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11523. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11524. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11525. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11526. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11527. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11528. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11529. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11530. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11531. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11532. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11533. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11534. };
  11535. static const int sizeof_bench_dilithium_level2_sig =
  11536. sizeof(bench_dilithium_level2_sig);
  11537. #endif
  11538. #ifndef WOLFSSL_NO_ML_DSA_65
  11539. static const unsigned char bench_dilithium_level3_sig[] = {
  11540. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11541. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11542. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11543. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11544. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11545. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11546. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11547. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11548. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11549. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11550. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11551. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11552. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11553. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11554. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11555. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11556. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11557. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11558. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11559. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11560. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11561. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11562. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11563. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11564. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11565. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11566. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11567. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11568. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11569. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11570. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11571. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11572. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11573. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11574. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11575. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11576. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11577. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11578. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11579. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11580. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11581. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11582. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11583. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11584. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11585. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11586. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11587. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11588. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11589. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11590. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11591. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11592. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11593. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11594. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11595. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11596. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11597. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11598. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11599. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11600. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11601. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11602. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11603. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11604. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11605. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11606. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11607. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11608. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11609. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11610. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11611. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11612. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11613. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11614. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11615. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11616. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11617. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11618. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11619. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11620. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11621. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11622. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11623. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11624. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11625. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11626. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11627. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11628. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11629. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11630. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11631. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11632. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11633. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11634. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11635. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11636. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11637. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11638. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11639. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11640. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11641. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11642. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11643. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11644. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11645. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11646. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11647. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11648. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11649. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11650. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11651. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11652. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11653. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11654. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11655. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11656. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11657. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11658. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11659. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11660. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11661. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11662. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11663. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11664. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11665. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11666. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11667. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11668. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11669. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11670. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11671. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11672. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11673. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11674. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11675. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11676. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11677. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11678. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11679. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11680. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11681. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11682. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11683. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11684. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11685. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11686. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11687. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11688. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11689. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11690. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11691. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11692. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11693. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11694. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11695. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11696. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11697. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11698. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11699. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11700. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11701. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11702. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11703. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11704. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11705. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11706. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11707. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11708. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11709. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11710. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11711. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11712. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11713. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11714. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11715. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11716. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11717. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11718. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11719. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11720. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11721. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11722. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11723. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11724. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11725. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11726. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11727. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11728. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11729. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11730. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11731. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11732. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11733. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11734. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11735. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11736. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11737. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11738. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11739. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11740. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11741. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11742. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11743. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11744. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11745. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11746. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11747. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11748. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11749. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11750. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11751. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11752. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11753. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11754. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11755. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11756. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11757. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11758. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11759. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11760. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11761. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11762. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11763. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11764. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11765. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11766. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11767. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11768. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11769. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11770. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11771. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11772. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11773. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11774. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11775. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11776. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11777. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11778. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11779. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11780. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11781. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  11782. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  11783. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  11784. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  11785. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  11786. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  11787. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  11788. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  11789. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  11790. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  11791. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  11792. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  11793. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  11794. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  11795. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  11796. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  11797. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  11798. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  11799. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  11800. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  11801. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  11802. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  11803. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  11804. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  11805. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  11806. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  11807. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  11808. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  11809. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  11810. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  11811. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  11812. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  11813. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  11814. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  11815. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  11816. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  11817. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  11818. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  11819. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  11820. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  11821. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  11822. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  11823. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  11824. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  11825. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  11826. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  11827. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  11828. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  11829. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  11830. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  11831. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  11832. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  11833. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  11834. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  11835. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  11836. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  11837. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  11838. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  11839. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  11840. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  11841. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  11842. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  11843. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  11844. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  11845. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  11846. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  11847. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  11848. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  11849. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  11850. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  11851. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  11852. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  11853. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  11854. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  11855. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  11856. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  11857. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  11858. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  11859. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  11860. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  11861. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  11862. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  11863. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  11864. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  11865. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  11866. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  11867. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  11868. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  11869. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11870. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  11871. };
  11872. static const int sizeof_bench_dilithium_level3_sig =
  11873. sizeof(bench_dilithium_level3_sig);
  11874. #endif
  11875. #ifndef WOLFSSL_NO_ML_DSA_87
  11876. static const unsigned char bench_dilithium_level5_sig[] = {
  11877. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  11878. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  11879. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  11880. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  11881. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  11882. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  11883. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  11884. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  11885. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  11886. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  11887. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  11888. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  11889. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  11890. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  11891. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  11892. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  11893. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  11894. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  11895. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  11896. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  11897. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  11898. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  11899. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  11900. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  11901. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  11902. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  11903. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  11904. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  11905. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  11906. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  11907. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  11908. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  11909. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  11910. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  11911. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  11912. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  11913. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  11914. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  11915. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  11916. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  11917. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  11918. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  11919. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  11920. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  11921. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  11922. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  11923. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  11924. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  11925. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  11926. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  11927. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  11928. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  11929. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  11930. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  11931. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  11932. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  11933. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  11934. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  11935. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  11936. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  11937. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  11938. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  11939. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  11940. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  11941. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  11942. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  11943. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  11944. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  11945. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  11946. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  11947. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  11948. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  11949. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  11950. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  11951. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  11952. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  11953. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  11954. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  11955. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  11956. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  11957. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  11958. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  11959. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  11960. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  11961. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  11962. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  11963. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  11964. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  11965. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  11966. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  11967. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  11968. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  11969. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  11970. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  11971. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  11972. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  11973. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  11974. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  11975. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  11976. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  11977. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  11978. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  11979. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  11980. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  11981. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  11982. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  11983. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  11984. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  11985. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  11986. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  11987. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  11988. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  11989. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  11990. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  11991. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  11992. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  11993. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  11994. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  11995. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  11996. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  11997. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  11998. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  11999. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12000. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12001. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12002. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12003. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12004. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12005. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12006. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12007. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12008. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12009. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12010. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12011. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12012. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12013. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12014. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12015. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12016. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12017. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12018. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12019. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12020. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12021. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12022. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12023. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12024. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12025. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12026. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12027. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12028. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12029. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12030. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12031. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12032. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12033. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12034. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12035. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12036. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12037. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12038. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12039. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12040. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12041. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12042. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12043. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12044. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12045. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12046. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12047. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12048. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12049. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12050. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12051. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12052. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12053. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12054. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12055. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12056. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12057. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12058. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12059. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12060. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12061. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12062. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12063. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12064. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12065. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12066. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12067. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12068. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12069. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12070. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12071. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12072. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12073. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12074. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12075. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12076. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12077. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12078. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12079. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12080. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12081. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12082. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12083. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12084. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12085. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12086. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12087. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12088. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12089. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12090. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12091. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12092. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12093. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12094. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12095. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12096. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12097. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12098. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12099. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12100. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12101. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12102. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12103. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12104. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12105. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12106. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12107. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12108. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12109. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12110. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12111. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12112. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12113. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12114. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12115. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12116. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12117. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12118. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12119. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12120. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12121. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12122. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12123. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12124. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12125. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12126. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12127. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12128. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12129. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12130. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12131. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12132. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12133. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12134. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12135. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12136. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12137. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12138. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12139. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12140. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12141. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12142. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12143. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12144. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12145. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12146. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12147. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12148. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12149. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12150. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12151. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12152. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12153. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12154. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12155. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12156. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12157. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12158. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12159. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12160. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12161. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12162. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12163. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12164. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12165. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12166. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12167. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12168. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12169. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12170. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12171. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12172. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12173. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12174. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12175. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12176. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12177. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12178. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12179. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12180. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12181. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12182. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12183. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12184. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12185. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12186. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12187. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12188. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12189. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12190. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12191. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12192. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12193. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12194. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12195. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12196. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12197. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12198. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12199. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12200. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12201. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12202. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12203. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12204. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12205. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12206. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12207. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12208. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12209. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12210. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12211. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12212. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12213. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12214. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12215. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12216. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12217. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12218. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12219. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12220. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12221. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12222. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12223. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12224. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12225. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12226. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12227. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12228. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12229. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12230. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12231. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12232. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12233. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12234. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12235. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12236. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12237. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12238. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12239. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12240. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12241. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12242. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12243. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12244. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12245. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12246. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12247. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12248. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12249. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12250. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12251. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12252. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12253. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12254. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12255. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12256. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12257. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12258. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12259. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12260. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12261. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12262. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12263. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12264. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12265. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12266. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12267. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12268. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12269. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12270. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12271. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12272. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12273. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12274. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12275. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12276. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12277. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12278. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12279. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12280. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12281. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12282. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12283. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12284. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12285. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12286. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12287. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12288. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12289. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12290. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12291. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12292. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12293. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12294. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12295. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12296. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12297. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12298. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12299. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12300. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12301. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12302. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12303. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12304. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12305. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12306. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12307. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12308. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12309. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12310. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12311. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12312. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12313. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12314. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12315. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12316. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12317. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12318. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12319. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12320. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12321. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12322. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12323. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12324. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12325. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12326. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12327. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12328. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12329. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12330. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12331. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12332. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12333. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12334. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12335. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12336. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12337. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12338. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12339. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12340. };
  12341. static const int sizeof_bench_dilithium_level5_sig =
  12342. sizeof(bench_dilithium_level5_sig);
  12343. #endif
  12344. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12345. void bench_dilithiumKeySign(byte level)
  12346. {
  12347. int ret = 0;
  12348. dilithium_key key;
  12349. double start;
  12350. int i, count;
  12351. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12352. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12353. byte msg[512];
  12354. word32 x = 0;
  12355. #endif
  12356. const char**desc = bench_desc_words[lng_index];
  12357. DECLARE_MULTI_VALUE_STATS_VARS()
  12358. byte params = 0;
  12359. if (level == 2) {
  12360. params = 44;
  12361. }
  12362. else if (level == 3) {
  12363. params = 65;
  12364. }
  12365. else if (level == 5) {
  12366. params = 87;
  12367. }
  12368. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12369. /* make dummy msg */
  12370. for (i = 0; i < (int)sizeof(msg); i++) {
  12371. msg[i] = (byte)i;
  12372. }
  12373. #endif
  12374. ret = wc_dilithium_init(&key);
  12375. if (ret != 0) {
  12376. printf("wc_dilithium_init failed %d\n", ret);
  12377. return;
  12378. }
  12379. ret = wc_dilithium_set_level(&key, level);
  12380. if (ret != 0) {
  12381. printf("wc_dilithium_set_level() failed %d\n", ret);
  12382. }
  12383. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12384. bench_stats_start(&count, &start);
  12385. do {
  12386. for (i = 0; i < agreeTimes; i++) {
  12387. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12388. if (ret != 0) {
  12389. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12390. return;
  12391. }
  12392. }
  12393. count += i;
  12394. } while (bench_stats_check(start)
  12395. #ifdef MULTI_VALUE_STATISTICS
  12396. || runs < minimum_runs
  12397. #endif
  12398. );
  12399. if (ret == 0) {
  12400. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12401. start, ret);
  12402. #ifdef MULTI_VALUE_STATISTICS
  12403. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12404. #endif
  12405. }
  12406. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12407. #ifndef WOLFSSL_NO_ML_DSA_44
  12408. if (level == 2) {
  12409. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12410. sizeof_bench_dilithium_level2_key, &key);
  12411. }
  12412. #endif
  12413. #ifndef WOLFSSL_NO_ML_DSA_65
  12414. if (level == 3) {
  12415. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12416. sizeof_bench_dilithium_level3_key, &key);
  12417. }
  12418. #endif
  12419. #ifndef WOLFSSL_NO_ML_DSA_87
  12420. if (level == 5) {
  12421. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12422. sizeof_bench_dilithium_level5_key, &key);
  12423. }
  12424. #endif
  12425. if (ret != 0) {
  12426. printf("Failed to load private key\n");
  12427. return;
  12428. }
  12429. #endif
  12430. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12431. if (level == 2) {
  12432. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12433. }
  12434. else if (level == 3) {
  12435. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12436. }
  12437. else {
  12438. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12439. }
  12440. RESET_MULTI_VALUE_STATS_VARS();
  12441. bench_stats_start(&count, &start);
  12442. do {
  12443. for (i = 0; i < agreeTimes; i++) {
  12444. if (ret == 0) {
  12445. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12446. GLOBAL_RNG);
  12447. if (ret != 0) {
  12448. printf("wc_dilithium_sign_msg failed\n");
  12449. }
  12450. }
  12451. RECORD_MULTI_VALUE_STATS();
  12452. }
  12453. count += i;
  12454. } while (bench_stats_check(start)
  12455. #ifdef MULTI_VALUE_STATISTICS
  12456. || runs < minimum_runs
  12457. #endif
  12458. );
  12459. if (ret == 0) {
  12460. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12461. ret);
  12462. #ifdef MULTI_VALUE_STATISTICS
  12463. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12464. #endif
  12465. }
  12466. #endif
  12467. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12468. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12469. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12470. #ifndef WOLFSSL_NO_ML_DSA_44
  12471. if (level == 2) {
  12472. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12473. x = sizeof_bench_dilithium_level2_sig;
  12474. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12475. #endif
  12476. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12477. sizeof_bench_dilithium_level2_pubkey, &key);
  12478. }
  12479. #endif
  12480. #ifndef WOLFSSL_NO_ML_DSA_65
  12481. if (level == 3) {
  12482. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12483. x = sizeof_bench_dilithium_level3_sig;
  12484. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12485. #endif
  12486. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12487. sizeof_bench_dilithium_level3_pubkey, &key);
  12488. }
  12489. #endif
  12490. #ifndef WOLFSSL_NO_ML_DSA_87
  12491. if (level == 5) {
  12492. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12493. x = sizeof_bench_dilithium_level5_sig;
  12494. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12495. #endif
  12496. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12497. sizeof_bench_dilithium_level5_pubkey, &key);
  12498. }
  12499. #endif
  12500. if (ret != 0) {
  12501. printf("Failed to load public key\n");
  12502. return;
  12503. }
  12504. #endif
  12505. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12506. RESET_MULTI_VALUE_STATS_VARS();
  12507. bench_stats_start(&count, &start);
  12508. do {
  12509. for (i = 0; i < agreeTimes; i++) {
  12510. if (ret == 0) {
  12511. int verify = 0;
  12512. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12513. &verify, &key);
  12514. if (ret != 0 || verify != 1) {
  12515. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12516. ret, verify);
  12517. ret = -1;
  12518. }
  12519. }
  12520. RECORD_MULTI_VALUE_STATS();
  12521. }
  12522. count += i;
  12523. } while (bench_stats_check(start)
  12524. #ifdef MULTI_VALUE_STATISTICS
  12525. || runs < minimum_runs
  12526. #endif
  12527. );
  12528. if (ret == 0) {
  12529. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12530. ret);
  12531. #ifdef MULTI_VALUE_STATISTICS
  12532. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12533. #endif
  12534. }
  12535. #endif
  12536. wc_dilithium_free(&key);
  12537. }
  12538. #endif /* HAVE_DILITHIUM */
  12539. #ifdef HAVE_SPHINCS
  12540. void bench_sphincsKeySign(byte level, byte optim)
  12541. {
  12542. int ret = 0;
  12543. sphincs_key key;
  12544. double start;
  12545. int i, count;
  12546. byte sig[SPHINCS_MAX_SIG_SIZE];
  12547. byte msg[512];
  12548. word32 x = 0;
  12549. const char**desc = bench_desc_words[lng_index];
  12550. DECLARE_MULTI_VALUE_STATS_VARS()
  12551. ret = wc_sphincs_init(&key);
  12552. if (ret != 0) {
  12553. printf("wc_sphincs_init failed %d\n", ret);
  12554. return;
  12555. }
  12556. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12557. if (ret != 0) {
  12558. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12559. }
  12560. if (ret == 0) {
  12561. ret = -1;
  12562. if ((level == 1) && (optim == FAST_VARIANT)) {
  12563. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12564. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12565. }
  12566. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12567. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12568. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12569. }
  12570. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12571. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12572. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12573. }
  12574. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12575. ret = wc_sphincs_import_private_key(
  12576. bench_sphincs_small_level1_key,
  12577. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12578. }
  12579. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12580. ret = wc_sphincs_import_private_key(
  12581. bench_sphincs_small_level3_key,
  12582. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12583. }
  12584. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12585. ret = wc_sphincs_import_private_key(
  12586. bench_sphincs_small_level5_key,
  12587. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12588. }
  12589. if (ret != 0) {
  12590. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12591. }
  12592. }
  12593. /* make dummy msg */
  12594. for (i = 0; i < (int)sizeof(msg); i++) {
  12595. msg[i] = (byte)i;
  12596. }
  12597. bench_stats_start(&count, &start);
  12598. do {
  12599. for (i = 0; i < agreeTimes; i++) {
  12600. if (ret == 0) {
  12601. if ((level == 1) && (optim == FAST_VARIANT)) {
  12602. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12603. }
  12604. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12605. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12606. }
  12607. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12608. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12609. }
  12610. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12611. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12612. }
  12613. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12614. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12615. }
  12616. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12617. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12618. }
  12619. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12620. if (ret != 0) {
  12621. printf("wc_sphincs_sign_msg failed\n");
  12622. }
  12623. }
  12624. RECORD_MULTI_VALUE_STATS();
  12625. }
  12626. count += i;
  12627. } while (bench_stats_check(start)
  12628. #ifdef MULTI_VALUE_STATISTICS
  12629. || runs < minimum_runs
  12630. #endif
  12631. );
  12632. if (ret == 0) {
  12633. if (optim == FAST_VARIANT) {
  12634. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12635. start, ret);
  12636. }
  12637. else {
  12638. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12639. start, ret);
  12640. }
  12641. #ifdef MULTI_VALUE_STATISTICS
  12642. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12643. #endif
  12644. }
  12645. RESET_MULTI_VALUE_STATS_VARS();
  12646. bench_stats_start(&count, &start);
  12647. do {
  12648. for (i = 0; i < agreeTimes; i++) {
  12649. if (ret == 0) {
  12650. int verify = 0;
  12651. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12652. &key);
  12653. if (ret != 0 || verify != 1) {
  12654. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12655. ret, verify);
  12656. ret = -1;
  12657. }
  12658. }
  12659. RECORD_MULTI_VALUE_STATS();
  12660. }
  12661. count += i;
  12662. } while (bench_stats_check(start)
  12663. #ifdef MULTI_VALUE_STATISTICS
  12664. || runs < minimum_runs
  12665. #endif
  12666. );
  12667. if (ret == 0) {
  12668. if (optim == FAST_VARIANT) {
  12669. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12670. start, ret);
  12671. }
  12672. else {
  12673. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12674. start, ret);
  12675. }
  12676. #ifdef MULTI_VALUE_STATISTICS
  12677. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12678. #endif
  12679. }
  12680. wc_sphincs_free(&key);
  12681. }
  12682. #endif /* HAVE_SPHINCS */
  12683. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12684. #define WIN32_LEAN_AND_MEAN
  12685. #include <windows.h>
  12686. double current_time(int reset)
  12687. {
  12688. static int init = 0;
  12689. static LARGE_INTEGER freq;
  12690. LARGE_INTEGER count;
  12691. (void)reset;
  12692. if (!init) {
  12693. QueryPerformanceFrequency(&freq);
  12694. init = 1;
  12695. }
  12696. QueryPerformanceCounter(&count);
  12697. #ifdef BENCH_MICROSECOND
  12698. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12699. #else
  12700. return (double)count.QuadPart / freq.QuadPart;
  12701. #endif
  12702. }
  12703. #elif defined MICROCHIP_PIC32
  12704. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12705. #define CLOCK 80000000.0
  12706. #else
  12707. #define CLOCK 40000000.0
  12708. #endif
  12709. extern void WriteCoreTimer(word32 t);
  12710. extern word32 ReadCoreTimer(void);
  12711. double current_time(int reset)
  12712. {
  12713. unsigned int ns;
  12714. if (reset) {
  12715. WriteCoreTimer(0);
  12716. }
  12717. /* get timer in ns */
  12718. ns = ReadCoreTimer();
  12719. /* return seconds as a double */
  12720. return ( ns / CLOCK * 2.0);
  12721. }
  12722. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12723. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12724. /* declared above at line 239 */
  12725. /* extern double current_time(int reset); */
  12726. #elif defined(FREERTOS)
  12727. #ifdef PLATFORMIO
  12728. #include <freertos/FreeRTOS.h>
  12729. #include <freertos/task.h>
  12730. #else
  12731. #include "task.h"
  12732. #endif
  12733. #if defined(WOLFSSL_ESPIDF)
  12734. /* prototype definition */
  12735. int construct_argv();
  12736. extern char* __argv[22];
  12737. /* current_time(reset)
  12738. *
  12739. * Benchmark passage of time, in fractional seconds.
  12740. * [reset] is non zero to adjust timer or counter to zero
  12741. *
  12742. * Use care when repeatedly calling calling. See implementation. */
  12743. double current_time(int reset)
  12744. {
  12745. double ret;
  12746. #if ESP_IDF_VERSION_MAJOR >= 4
  12747. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12748. #else
  12749. portTickType tickCount;
  12750. #endif
  12751. #if defined(__XTENSA__)
  12752. (void)reset;
  12753. if (reset) {
  12754. /* TODO: Determine a mechanism for reset that does not interfere
  12755. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12756. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12757. ESP_LOGW(TAG, "Current_time() reset!");
  12758. portTICK_TYPE_ENTER_CRITICAL();
  12759. {
  12760. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12761. _esp_cpu_count_last = xthal_get_ccount();
  12762. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12763. }
  12764. portTICK_TYPE_EXIT_CRITICAL();
  12765. */
  12766. }
  12767. #else
  12768. /* Only reset the CPU counter for RISC-V */
  12769. if (reset) {
  12770. ESP_LOGV(TAG, "current_time() reset!");
  12771. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12772. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12773. * See also esp_get_cycle_count_ex() */
  12774. #ifdef __XTENSA__
  12775. _esp_cpu_count_last = xthal_get_ccount();
  12776. #else
  12777. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12778. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12779. #endif
  12780. }
  12781. #endif
  12782. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  12783. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  12784. The count of ticks since vTaskStartScheduler was called,
  12785. typiclly in app_startup.c */
  12786. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12787. ESP_LOGV(TAG, "tickCount = %d", tickCount);
  12788. if (tickCount == last_tickCount) {
  12789. ESP_LOGW(TAG, "last_tickCount unchanged? %d", tickCount);
  12790. }
  12791. if (tickCount < last_tickCount) {
  12792. ESP_LOGW(TAG, "last_tickCount overflow?");
  12793. }
  12794. #endif
  12795. if (reset) {
  12796. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12797. ESP_LOGW(TAG, "Assign last_tickCount = %d", tickCount);
  12798. #endif
  12799. last_tickCount = tickCount;
  12800. }
  12801. else {
  12802. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12803. ESP_LOGV(TAG, "No Reset last_tickCount = %d", tickCount);
  12804. #endif
  12805. }
  12806. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  12807. ret = (double)tickCount / configTICK_RATE_HZ;
  12808. #else
  12809. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  12810. "assuming 1000 Hz.");
  12811. ret = (double)(tickCount / 1000.0);
  12812. #endif /* configTICK_RATE_HZ */
  12813. return ret;
  12814. } /* current_time */
  12815. #else
  12816. /* current_time(reset)
  12817. *
  12818. * Benchmark passage of time, in fractional seconds.
  12819. * [reset] is non zero to adjust timer or counter to zero
  12820. *
  12821. * Use care when repeatedly calling calling. See implementation. */
  12822. double current_time(int reset)
  12823. {
  12824. portTickType tickCount;
  12825. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  12826. tickCount = xTaskGetTickCount();
  12827. return (double)tickCount / 1000;
  12828. }
  12829. #endif
  12830. #elif defined (WOLFSSL_TIRTOS)
  12831. extern double current_time(int reset);
  12832. #elif defined(FREESCALE_MQX)
  12833. double current_time(int reset)
  12834. {
  12835. TIME_STRUCT tv;
  12836. _time_get(&tv);
  12837. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  12838. }
  12839. #elif defined(FREESCALE_KSDK_BM)
  12840. double current_time(int reset)
  12841. {
  12842. return (double)OSA_TimeGetMsec() / 1000;
  12843. }
  12844. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  12845. double current_time(int reset)
  12846. {
  12847. (void)reset;
  12848. return (double)osKernelGetTickCount() / 1000.0;
  12849. }
  12850. #elif defined(WOLFSSL_EMBOS)
  12851. #include "RTOS.h"
  12852. double current_time(int reset)
  12853. {
  12854. double time_now;
  12855. double current_s = OS_GetTime() / 1000.0;
  12856. double current_us = OS_GetTime_us() / MILLION_VALUE;
  12857. time_now = (double)( current_s + current_us);
  12858. (void) reset;
  12859. return time_now;
  12860. }
  12861. #elif defined(WOLFSSL_SGX)
  12862. double current_time(int reset);
  12863. #elif defined(WOLFSSL_DEOS)
  12864. double current_time(int reset)
  12865. {
  12866. const uint32_t systemTickTimeInHz
  12867. = 1000000 / systemTickInMicroseconds();
  12868. const volatile uint32_t *systemTickPtr = systemTickPointer();
  12869. (void)reset;
  12870. return (double) *systemTickPtr/systemTickTimeInHz;
  12871. }
  12872. #elif defined(MICRIUM)
  12873. double current_time(int reset)
  12874. {
  12875. #if (OS_VERSION < 50000)
  12876. CPU_ERR err;
  12877. (void)reset;
  12878. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  12879. #else
  12880. RTOS_ERR err;
  12881. double ret = 0;
  12882. OS_TICK tick = OSTimeGet(&err);
  12883. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  12884. (void)reset;
  12885. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  12886. ret = ((double)tick)/rate;
  12887. }
  12888. return ret;
  12889. #endif
  12890. }
  12891. #elif defined(WOLFSSL_ZEPHYR)
  12892. #include <time.h>
  12893. double current_time(int reset)
  12894. {
  12895. int64_t t;
  12896. (void)reset;
  12897. #if defined(CONFIG_ARCH_POSIX)
  12898. k_cpu_idle();
  12899. #endif
  12900. t = k_uptime_get(); /* returns current uptime in milliseconds */
  12901. return (double)(t / 1000);
  12902. }
  12903. #elif defined(WOLFSSL_NETBURNER)
  12904. #include <predef.h>
  12905. #include <utils.h>
  12906. #include <constants.h>
  12907. double current_time(int reset)
  12908. {
  12909. DWORD ticks = TimeTick; /* ticks since system start */
  12910. (void)reset;
  12911. return (double) ticks/TICKS_PER_SECOND;
  12912. }
  12913. #elif defined(THREADX)
  12914. #include "tx_api.h"
  12915. double current_time(int reset)
  12916. {
  12917. (void)reset;
  12918. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  12919. }
  12920. #elif defined(WOLFSSL_XILINX)
  12921. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  12922. #define COUNTS_PER_SECOND \
  12923. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  12924. #else
  12925. #define COUNTS_PER_SECOND \
  12926. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  12927. #endif
  12928. double current_time(int reset)
  12929. {
  12930. double timer;
  12931. uint64_t cntPct = 0;
  12932. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  12933. /* Convert to milliseconds */
  12934. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  12935. /* Convert to seconds.millisecond */
  12936. timer /= 1000;
  12937. return timer;
  12938. }
  12939. #elif defined(LINUX_RUSAGE_UTIME)
  12940. #include <sys/time.h>
  12941. #include <sys/resource.h>
  12942. static struct rusage base_rusage;
  12943. static struct rusage cur_rusage;
  12944. double current_time(int reset)
  12945. {
  12946. struct rusage rusage;
  12947. (void)reset;
  12948. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  12949. if (reset)
  12950. base_rusage = rusage;
  12951. else
  12952. cur_rusage = rusage;
  12953. /* only consider user time, as system time is host-related overhead
  12954. * outside wolfcrypt.
  12955. */
  12956. return (double)rusage.ru_utime.tv_sec +
  12957. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  12958. }
  12959. static void check_for_excessive_stime(const char *desc,
  12960. const char *desc_extra)
  12961. {
  12962. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  12963. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  12964. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  12965. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  12966. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  12967. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  12968. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  12969. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  12970. double stime_utime_ratio =
  12971. (cur_stime - start_stime) / (cur_utime - start_utime);
  12972. if (stime_utime_ratio > .1)
  12973. printf("%swarning, "
  12974. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  12975. err_prefix, desc, desc_extra,
  12976. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  12977. }
  12978. #elif defined(WOLFSSL_LINUXKM)
  12979. double current_time(int reset)
  12980. {
  12981. (void)reset;
  12982. u64 ns = ktime_get_ns();
  12983. return (double)ns / 1000000000.0;
  12984. }
  12985. #else
  12986. #include <sys/time.h>
  12987. double current_time(int reset)
  12988. {
  12989. struct timespec tv;
  12990. (void)reset;
  12991. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  12992. #ifdef BENCH_MICROSECOND
  12993. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  12994. #else
  12995. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  12996. #endif
  12997. }
  12998. #endif /* _WIN32 */
  12999. #if defined(HAVE_GET_CYCLES)
  13000. #if defined(WOLFSSL_ESPIDF)
  13001. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13002. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13003. {
  13004. /* Reminder for long duration between calls with
  13005. * multiple overflows will not be detected. */
  13006. return esp_get_cycle_count_ex();
  13007. }
  13008. /* implement other architectures here */
  13009. #else
  13010. static WC_INLINE word64 get_intel_cycles(void)
  13011. {
  13012. unsigned int lo_c, hi_c;
  13013. __asm__ __volatile__ (
  13014. "cpuid\n\t"
  13015. "rdtsc"
  13016. : "=a"(lo_c), "=d"(hi_c) /* out */
  13017. : "a"(0) /* in */
  13018. : "%ebx", "%ecx"); /* clobber */
  13019. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13020. }
  13021. #endif
  13022. #endif /* HAVE_GET_CYCLES */
  13023. void benchmark_configure(word32 block_size)
  13024. {
  13025. /* must be greater than 0 */
  13026. if (block_size > 0) {
  13027. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13028. bench_size = block_size;
  13029. }
  13030. }
  13031. #ifndef NO_MAIN_DRIVER
  13032. #ifndef MAIN_NO_ARGS
  13033. #ifndef WOLFSSL_BENCHMARK_ALL
  13034. /* Display the algorithm string and keep to 80 characters per line.
  13035. *
  13036. * str Algorithm string to print.
  13037. * line Length of line used so far.
  13038. */
  13039. #ifndef BENCH_MAX_LINE
  13040. #define BENCH_MAX_LINE 80
  13041. #endif
  13042. static void print_alg(const char* str, int* line)
  13043. {
  13044. const char* const ident = " ";
  13045. if (*line == 0) {
  13046. printf("%s", ident);
  13047. *line = (int)XSTRLEN(ident);
  13048. }
  13049. printf(" %s", str);
  13050. *line += (int)XSTRLEN(str) + 1;
  13051. if (*line > BENCH_MAX_LINE) {
  13052. printf("\n");
  13053. *line = 0;
  13054. }
  13055. }
  13056. #endif /* WOLFSSL_BENCHMARK_ALL */
  13057. /* Display the usage options of the benchmark program. */
  13058. static void Usage(void)
  13059. {
  13060. int e = 0;
  13061. #ifndef WOLFSSL_BENCHMARK_ALL
  13062. int i;
  13063. int line;
  13064. #endif
  13065. printf("benchmark\n");
  13066. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13067. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13068. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13069. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13070. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13071. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13072. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13073. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13074. #else
  13075. e += 3;
  13076. #endif
  13077. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13078. #ifndef NO_RSA
  13079. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13080. #ifdef WOLFSSL_KEY_GEN
  13081. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13082. #endif
  13083. e++;
  13084. #else
  13085. e += 2;
  13086. #endif
  13087. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13088. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13089. #endif
  13090. e++;
  13091. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13092. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13093. #endif
  13094. e++;
  13095. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13096. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13097. #endif
  13098. e++;
  13099. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13100. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13101. #endif
  13102. e++;
  13103. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13104. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13105. #endif
  13106. e++;
  13107. #if defined(HAVE_ECC)
  13108. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13109. #endif
  13110. e++;
  13111. #ifndef WOLFSSL_BENCHMARK_ALL
  13112. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13113. line = 0;
  13114. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13115. print_alg(bench_cipher_opt[i].str, &line);
  13116. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13117. print_alg(bench_digest_opt[i].str, &line);
  13118. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13119. print_alg(bench_mac_opt[i].str, &line);
  13120. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13121. print_alg(bench_kdf_opt[i].str, &line);
  13122. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13123. print_alg(bench_asym_opt[i].str, &line);
  13124. for (i=0; bench_other_opt[i].str != NULL; i++)
  13125. print_alg(bench_other_opt[i].str, &line);
  13126. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13127. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13128. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13129. print_alg(bench_pq_asym_opt[i].str, &line);
  13130. #if defined(HAVE_SPHINCS)
  13131. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13132. print_alg(bench_pq_asym_opt2[i].str, &line);
  13133. #endif /* HAVE_SPHINCS */
  13134. #endif
  13135. #if defined(BENCH_PQ_STATEFUL_HBS)
  13136. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13137. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13138. #endif /* BENCH_PQ_STATEFUL_HBS */
  13139. printf("\n");
  13140. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13141. e++;
  13142. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13143. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13144. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13145. #ifdef WC_ENABLE_BENCH_THREADING
  13146. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13147. #endif
  13148. e++;
  13149. #ifdef WC_BENCH_TRACK_STATS
  13150. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13151. #endif
  13152. e++;
  13153. #ifndef NO_FILESYSTEM
  13154. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13155. #endif
  13156. e++;
  13157. #ifndef NO_FILESYSTEM
  13158. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13159. #endif
  13160. #ifdef MULTI_VALUE_STATISTICS
  13161. e++;
  13162. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13163. #endif
  13164. }
  13165. /* Match the command line argument with the string.
  13166. *
  13167. * arg Command line argument.
  13168. * str String to check for.
  13169. * return 1 if the command line argument matches the string, 0 otherwise.
  13170. */
  13171. static int string_matches(const char* arg, const char* str)
  13172. {
  13173. return XSTRCMP(arg, str) == 0;
  13174. }
  13175. #endif /* MAIN_NO_ARGS */
  13176. /*
  13177. ** ----------------------------------------------------------------------------
  13178. ** determine how the benchmarks are called, the function name varies:
  13179. ** ----------------------------------------------------------------------------
  13180. */
  13181. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13182. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13183. /* for some environments, we'll call a function wolf_benchmark_task: */
  13184. int wolf_benchmark_task(void)
  13185. #elif defined(MAIN_NO_ARGS)
  13186. /* otherwise we'll use main() with no arguments as desired: */
  13187. int main()
  13188. #else
  13189. /* else we'll be calling main with default arg parameters */
  13190. int main(int argc, char** argv)
  13191. #endif
  13192. {
  13193. /* Code for main() or wolf_benchmark_task() */
  13194. #ifdef WOLFSSL_ESPIDF
  13195. int argc = construct_argv();
  13196. char** argv = (char**)__argv;
  13197. #elif defined(MAIN_NO_ARGS)
  13198. int argc = 0;
  13199. char** argv = NULL;
  13200. #endif
  13201. return wolfcrypt_benchmark_main(argc, argv);
  13202. }
  13203. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13204. int wolfcrypt_benchmark_main(int argc, char** argv)
  13205. {
  13206. int ret = 0;
  13207. #ifndef MAIN_NO_ARGS
  13208. int optMatched;
  13209. #ifndef WOLFSSL_BENCHMARK_ALL
  13210. int i;
  13211. #endif
  13212. #endif
  13213. benchmark_static_init(1);
  13214. printf("%s------------------------------------------------------------------------------\n",
  13215. info_prefix);
  13216. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13217. printf("%s------------------------------------------------------------------------------\n",
  13218. info_prefix);
  13219. #ifndef MAIN_NO_ARGS
  13220. while (argc > 1) {
  13221. if (string_matches(argv[1], "-?")) {
  13222. if (--argc > 1) {
  13223. lng_index = XATOI((++argv)[1]);
  13224. if (lng_index<0 || lng_index>1) {
  13225. lng_index = 0;
  13226. }
  13227. }
  13228. Usage();
  13229. return 0;
  13230. }
  13231. else if (string_matches(argv[1], "-lng")) {
  13232. argc--;
  13233. argv++;
  13234. if (argc > 1) {
  13235. lng_index = XATOI(argv[1]);
  13236. if (lng_index<0 || lng_index>1) {
  13237. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13238. lng_index);
  13239. lng_index = 0;
  13240. }
  13241. }
  13242. }
  13243. else if (string_matches(argv[1], "-base10"))
  13244. base2 = 0;
  13245. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13246. else if (string_matches(argv[1], "-no_aad"))
  13247. aes_aad_options = AAD_SIZE_ZERO;
  13248. else if (string_matches(argv[1], "-all_aad"))
  13249. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13250. else if (string_matches(argv[1], "-aad_size")) {
  13251. argc--;
  13252. argv++;
  13253. if (argc > 1) {
  13254. aes_aad_size = (word32)XATOI(argv[1]);
  13255. aes_aad_options |= AAD_SIZE_CUSTOM;
  13256. }
  13257. }
  13258. #endif
  13259. else if (string_matches(argv[1], "-dgst_full"))
  13260. digest_stream = 0;
  13261. else if (string_matches(argv[1], "-enc_only"))
  13262. encrypt_only = 1;
  13263. #ifndef NO_RSA
  13264. else if (string_matches(argv[1], "-rsa_sign"))
  13265. rsa_sign_verify = 1;
  13266. #endif
  13267. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13268. else if (string_matches(argv[1], "-ffdhe2048"))
  13269. use_ffdhe = 2048;
  13270. #endif
  13271. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13272. else if (string_matches(argv[1], "-ffdhe3072"))
  13273. use_ffdhe = 3072;
  13274. #endif
  13275. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13276. else if (string_matches(argv[1], "-ffdhe4096"))
  13277. use_ffdhe = 4096;
  13278. #endif
  13279. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13280. else if (string_matches(argv[1], "-p256"))
  13281. bench_asym_algs |= BENCH_ECC_P256;
  13282. #endif
  13283. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13284. else if (string_matches(argv[1], "-p384"))
  13285. bench_asym_algs |= BENCH_ECC_P384;
  13286. #endif
  13287. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13288. else if (string_matches(argv[1], "-p521"))
  13289. bench_asym_algs |= BENCH_ECC_P521;
  13290. #endif
  13291. #ifdef BENCH_ASYM
  13292. else if (string_matches(argv[1], "-csv")) {
  13293. csv_format = 1;
  13294. }
  13295. #endif
  13296. #ifdef WC_ENABLE_BENCH_THREADING
  13297. else if (string_matches(argv[1], "-threads")) {
  13298. argc--;
  13299. argv++;
  13300. if (argc > 1) {
  13301. g_threadCount = XATOI(argv[1]);
  13302. if (g_threadCount < 1 || lng_index > 128){
  13303. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13304. g_threadCount);
  13305. g_threadCount = 0;
  13306. }
  13307. }
  13308. }
  13309. #endif
  13310. #ifdef WC_BENCH_TRACK_STATS
  13311. else if (string_matches(argv[1], "-print")) {
  13312. gPrintStats = 1;
  13313. }
  13314. #endif
  13315. else if (string_matches(argv[1], "-blocks")) {
  13316. argc--;
  13317. argv++;
  13318. if (argc > 1)
  13319. numBlocks = XATOI(argv[1]);
  13320. }
  13321. #ifndef NO_FILESYSTEM
  13322. else if (string_matches(argv[1], "-hash_input")) {
  13323. argc--;
  13324. argv++;
  13325. if (argc > 1)
  13326. hash_input = argv[1];
  13327. }
  13328. else if (string_matches(argv[1], "-cipher_input")) {
  13329. argc--;
  13330. argv++;
  13331. if (argc > 1)
  13332. cipher_input = argv[1];
  13333. }
  13334. #endif
  13335. #ifdef MULTI_VALUE_STATISTICS
  13336. else if (string_matches(argv[1], "-min_runs")) {
  13337. argc--;
  13338. argv++;
  13339. if (argc > 1) {
  13340. minimum_runs = XATOI(argv[1]);
  13341. }
  13342. }
  13343. #endif
  13344. else if (argv[1][0] == '-') {
  13345. optMatched = 0;
  13346. #ifndef WOLFSSL_BENCHMARK_ALL
  13347. /* Check known algorithm choosing command line options. */
  13348. /* Known cipher algorithms */
  13349. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13350. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13351. bench_cipher_algs |= bench_cipher_opt[i].val;
  13352. bench_all = 0;
  13353. optMatched = 1;
  13354. }
  13355. }
  13356. /* Known digest algorithms */
  13357. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13358. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13359. bench_digest_algs |= bench_digest_opt[i].val;
  13360. bench_all = 0;
  13361. optMatched = 1;
  13362. }
  13363. }
  13364. /* Known MAC algorithms */
  13365. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13366. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13367. bench_mac_algs |= bench_mac_opt[i].val;
  13368. bench_all = 0;
  13369. optMatched = 1;
  13370. }
  13371. }
  13372. /* Known KDF algorithms */
  13373. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13374. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13375. bench_kdf_algs |= bench_kdf_opt[i].val;
  13376. bench_all = 0;
  13377. optMatched = 1;
  13378. }
  13379. }
  13380. /* Known asymmetric algorithms */
  13381. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13382. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13383. bench_asym_algs |= bench_asym_opt[i].val;
  13384. bench_all = 0;
  13385. optMatched = 1;
  13386. }
  13387. }
  13388. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13389. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13390. /* Known asymmetric post-quantum algorithms */
  13391. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13392. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13393. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13394. bench_all = 0;
  13395. optMatched = 1;
  13396. }
  13397. }
  13398. #ifdef HAVE_SPHINCS
  13399. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13400. * -pq, so we need to do a special case for -pq since optMatched
  13401. * was set to 1 just above. */
  13402. if ((bench_pq_asym_opt[0].str != NULL) &&
  13403. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13404. {
  13405. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13406. bench_all = 0;
  13407. optMatched = 1;
  13408. }
  13409. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13410. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13411. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13412. bench_all = 0;
  13413. optMatched = 1;
  13414. }
  13415. }
  13416. #endif
  13417. #endif
  13418. /* Other known cryptographic algorithms */
  13419. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13420. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13421. bench_other_algs |= bench_other_opt[i].val;
  13422. bench_all = 0;
  13423. optMatched = 1;
  13424. }
  13425. }
  13426. #if defined(BENCH_PQ_STATEFUL_HBS)
  13427. /* post-quantum stateful hash-based signatures */
  13428. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13429. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13430. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13431. bench_all = 0;
  13432. optMatched = 1;
  13433. }
  13434. }
  13435. #endif /* BENCH_PQ_STATEFUL_HBS */
  13436. #endif
  13437. if (!optMatched) {
  13438. printf("Option not recognized: %s\n", argv[1]);
  13439. Usage();
  13440. return 1;
  13441. }
  13442. }
  13443. else {
  13444. /* parse for block size */
  13445. benchmark_configure((word32)XATOI(argv[1]));
  13446. }
  13447. argc--;
  13448. argv++;
  13449. }
  13450. #endif /* MAIN_NO_ARGS */
  13451. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13452. /* when defined, we'll always output CSV regardless of params.
  13453. ** this is typically convenient in embedded environments.
  13454. */
  13455. csv_format = 1;
  13456. #endif
  13457. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13458. if (g_threadCount > 1) {
  13459. ret = benchmark_test_threaded(NULL);
  13460. }
  13461. else
  13462. #endif
  13463. {
  13464. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13465. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13466. defined(CONFIG_IDF_TARGET_ESP32C6)
  13467. {
  13468. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13469. if (esp_gptimer == NULL) {
  13470. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13471. &esp_gptimer) );
  13472. }
  13473. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13474. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13475. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13476. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13477. }
  13478. #endif
  13479. #ifdef HAVE_STACK_SIZE
  13480. ret = StackSizeCheck(NULL, benchmark_test);
  13481. #else
  13482. ret = benchmark_test(NULL);
  13483. #endif
  13484. }
  13485. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13486. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13487. defined(CONFIG_IDF_TARGET_ESP32C6)
  13488. {
  13489. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13490. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13491. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13492. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13493. }
  13494. #endif
  13495. return ret;
  13496. }
  13497. #endif /* !NO_MAIN_DRIVER */
  13498. #else
  13499. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13500. int main(void) { return 0; }
  13501. #endif
  13502. #endif /* !NO_CRYPT_BENCHMARK */