1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197 |
- /* benchmark.c
- *
- * Copyright (C) 2006-2024 wolfSSL Inc.
- *
- * This file is part of wolfSSL.
- *
- * wolfSSL is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * wolfSSL is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
- */
- /* wolfCrypt benchmark */
- /* Some common, optional build settings:
- * these can also be set in wolfssl/options.h or user_settings.h
- * -------------------------------------------------------------
- * make the binary always use CSV format:
- * WOLFSSL_BENCHMARK_FIXED_CSV
- *
- * choose to use the same units, regardless of scale. pick 1:
- * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
- * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
- * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
- * WOLFSSL_BENCHMARK_FIXED_UNITS_B
- *
- * when the output should be in machine-parseable format:
- * GENERATE_MACHINE_PARSEABLE_REPORT
- *
- * use microseconds as the unit of time:
- * BENCH_MICROSECOND
- *
- * display mean, max, min and sd of operation durations:
- * MULTI_VALUE_STATISTICS
- *
- * Enable tracking of the stats into an allocated linked list:
- * (use -print to display results):
- * WC_BENCH_TRACK_STATS
- *
- * set the default devId for cryptocb to the value instead of INVALID_DEVID
- * WC_USE_DEVID=0x1234
- *
- * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
- * DEBUG_WOLFSSL_BENCHMARK_TIMING
- *
- * Turn on timer debugging (used when CPU cycles not available)
- * WOLFSSL_BENCHMARK_TIMER_DEBUG
- */
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #ifndef WOLFSSL_USER_SETTINGS
- #include <wolfssl/options.h>
- #endif
- #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
- /* Macro to disable benchmark */
- #ifndef NO_CRYPT_BENCHMARK
- #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)
- #include <wolfssl/wolfcrypt/types.h>
- #include <wolfssl/wolfcrypt/wc_port.h>
- #include <wolfssl/wolfcrypt/wolfmath.h>
- #include <wolfssl/wolfcrypt/memory.h>
- #include <wolfssl/wolfcrypt/random.h>
- #include <wolfssl/wolfcrypt/error-crypt.h>
- #include <wolfssl/wolfcrypt/asn.h>
- #include <wolfssl/version.h>
- #ifdef WOLFSSL_LINUXKM
- /* remap current_time() -- collides with a function in kernel linux/fs.h */
- #define current_time benchmark_current_time
- #endif /* WOLFSSL_LINUXKM */
- #ifdef HAVE_CHACHA
- #include <wolfssl/wolfcrypt/chacha.h>
- #endif
- #ifdef HAVE_POLY1305
- #include <wolfssl/wolfcrypt/poly1305.h>
- #endif
- #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
- #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
- #endif
- #ifndef NO_AES
- #include <wolfssl/wolfcrypt/aes.h>
- #endif
- #ifdef HAVE_CAMELLIA
- #include <wolfssl/wolfcrypt/camellia.h>
- #endif
- #ifdef WOLFSSL_SM4
- #include <wolfssl/wolfcrypt/sm4.h>
- #endif
- #ifndef NO_MD5
- #include <wolfssl/wolfcrypt/md5.h>
- #endif
- #ifndef NO_SHA
- #include <wolfssl/wolfcrypt/sha.h>
- #endif
- #ifndef NO_SHA256
- #include <wolfssl/wolfcrypt/sha256.h>
- #endif
- #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
- #include <wolfssl/wolfcrypt/sha512.h>
- #endif
- #ifdef WOLFSSL_SHA3
- #include <wolfssl/wolfcrypt/sha3.h>
- #endif
- #ifdef WOLFSSL_SM3
- #include <wolfssl/wolfcrypt/sm3.h>
- #endif
- #ifndef NO_RSA
- #include <wolfssl/wolfcrypt/rsa.h>
- #endif
- #ifdef WOLFSSL_RIPEMD
- #include <wolfssl/wolfcrypt/ripemd.h>
- #endif
- #ifdef WOLFSSL_CMAC
- #include <wolfssl/wolfcrypt/cmac.h>
- #endif
- #ifndef NO_DH
- #include <wolfssl/wolfcrypt/dh.h>
- #endif
- #ifndef NO_DES3
- #include <wolfssl/wolfcrypt/des3.h>
- #endif
- #ifndef NO_RC4
- #include <wolfssl/wolfcrypt/arc4.h>
- #endif
- #ifndef NO_HMAC
- #include <wolfssl/wolfcrypt/hmac.h>
- #endif
- #ifdef WOLFSSL_SIPHASH
- #include <wolfssl/wolfcrypt/siphash.h>
- #endif
- #include <wolfssl/wolfcrypt/kdf.h>
- #ifndef NO_PWDBASED
- #include <wolfssl/wolfcrypt/pwdbased.h>
- #endif
- #ifdef HAVE_ECC
- #include <wolfssl/wolfcrypt/ecc.h>
- #endif
- #ifdef WOLFSSL_SM2
- #include <wolfssl/wolfcrypt/sm2.h>
- #endif
- #ifdef HAVE_CURVE25519
- #include <wolfssl/wolfcrypt/curve25519.h>
- #endif
- #ifdef HAVE_ED25519
- #include <wolfssl/wolfcrypt/ed25519.h>
- #endif
- #ifdef HAVE_CURVE448
- #include <wolfssl/wolfcrypt/curve448.h>
- #endif
- #ifdef HAVE_ED448
- #include <wolfssl/wolfcrypt/ed448.h>
- #endif
- #ifdef WOLFSSL_HAVE_KYBER
- #include <wolfssl/wolfcrypt/kyber.h>
- #ifdef WOLFSSL_WC_KYBER
- #include <wolfssl/wolfcrypt/wc_kyber.h>
- #endif
- #if defined(HAVE_LIBOQS)
- #include <wolfssl/wolfcrypt/ext_kyber.h>
- #endif
- #endif
- #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
- #include <wolfssl/wolfcrypt/lms.h>
- #ifdef HAVE_LIBLMS
- #include <wolfssl/wolfcrypt/ext_lms.h>
- #else
- #include <wolfssl/wolfcrypt/wc_lms.h>
- #endif
- #endif
- #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
- #include <wolfssl/wolfcrypt/xmss.h>
- #ifdef HAVE_LIBXMSS
- #include <wolfssl/wolfcrypt/ext_xmss.h>
- #else
- #include <wolfssl/wolfcrypt/wc_xmss.h>
- #endif
- #endif
- #ifdef WOLFCRYPT_HAVE_ECCSI
- #include <wolfssl/wolfcrypt/eccsi.h>
- #endif
- #ifdef WOLFCRYPT_HAVE_SAKKE
- #include <wolfssl/wolfcrypt/sakke.h>
- #endif
- #if defined(HAVE_FALCON)
- #include <wolfssl/wolfcrypt/falcon.h>
- #endif
- #if defined(HAVE_DILITHIUM)
- #include <wolfssl/wolfcrypt/dilithium.h>
- #endif
- #if defined(HAVE_SPHINCS)
- #include <wolfssl/wolfcrypt/sphincs.h>
- #endif
- #ifdef WOLF_CRYPTO_CB
- #include <wolfssl/wolfcrypt/cryptocb.h>
- #ifdef HAVE_INTEL_QA_SYNC
- #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
- #endif
- #ifdef HAVE_CAVIUM_OCTEON_SYNC
- #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
- #endif
- #ifdef HAVE_RENESAS_SYNC
- #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
- #endif
- #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
- #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
- #endif
- #endif
- #ifdef WOLFSSL_ASYNC_CRYPT
- #include <wolfssl/wolfcrypt/async.h>
- #endif
- #ifdef USE_FLAT_BENCHMARK_H
- #include "benchmark.h"
- #else
- #include "wolfcrypt/benchmark/benchmark.h"
- #endif
- /* define the max length for each string of metric reported */
- #ifndef WC_BENCH_MAX_LINE_LEN
- #define WC_BENCH_MAX_LINE_LEN 150
- #endif
- /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
- #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
- #define MILLION_VALUE 1000000.0
- #ifdef BENCH_MICROSECOND
- #define WOLFSSL_FIXED_TIME_UNIT "μs"
- #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
- #else
- #define WOLFSSL_FIXED_TIME_UNIT "s"
- #endif
- #ifdef MULTI_VALUE_STATISTICS
- #define STATS_CLAUSE_SEPARATOR ""
- #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
- squareSum = 0, prev = 0, delta;\
- int runs = 0;
- #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
- delta = current_time(0) - start;\
- min = delta;\
- max = delta;\
- }\
- else {\
- delta = current_time(0) - prev;\
- }\
- if (max < delta)\
- max = delta;\
- else if (min > delta)\
- min = delta;\
- sum += delta;\
- squareSum += delta * delta;\
- runs++;\
- prev = current_time(0)
- #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
- runs = 0;\
- sum = 0;\
- squareSum = 0
- #else
- #define STATS_CLAUSE_SEPARATOR "\n"
- #define DECLARE_MULTI_VALUE_STATS_VARS()
- #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
- #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
- #endif
- #ifdef WOLFSSL_NO_FLOAT_FMT
- #define FLT_FMT "%0ld,%09lu"
- #define FLT_FMT_PREC "%0ld.%0*lu"
- #define FLT_FMT_PREC2 FLT_FMT_PREC
- #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
- (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
- (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
- static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
- 10000.0, 100000.0, 1000000.0, \
- 10000000.0, 100000000.0, \
- 1000000000.0 };
- #define FLT_FMT_PREC_ARGS(p, x) \
- (long)(x), \
- p, \
- (x) >= 0.0 ? \
- (unsigned long int)((((x) - (double)(long)(x)) * \
- pow_10_array[(p)+1]) + 0.5) : \
- (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
- pow_10_array[(p)+1]) + 0.5)
- #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
- #else
- #define FLT_FMT "%f"
- #define FLT_FMT_PREC "%.*f"
- #define FLT_FMT_PREC2 "%*.*f"
- #define FLT_FMT_ARGS(x) x
- #define FLT_FMT_PREC_ARGS(p, x) p, x
- #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
- #endif /* WOLFSSL_NO_FLOAT_FMT */
- #ifdef WOLFSSL_ESPIDF
- #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
- /* Benchmark uses 64 bit integer formatting support. When new nanolib is
- * enabled, all if the values in report are blank. */
- #ifdef CONFIG_NEWLIB_NANO_FORMAT
- #if CONFIG_NEWLIB_NANO_FORMAT == 1
- #error "Nano newlib formatting must not be enabled for benchmark"
- #endif
- #endif
- #if ESP_IDF_VERSION_MAJOR >= 5
- #define TFMT "%lu"
- #else
- #define TFMT "%d"
- #endif
- #ifdef configTICK_RATE_HZ
- /* Define CPU clock cycles per tick of FreeRTOS clock
- * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
- * configTICK_RATE_HZ is typically 100 or 1000.
- **/
- #if defined(CONFIG_IDF_TARGET_ESP8266)
- #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
- CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
- #endif
- #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
- #endif
- #endif
- #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
- /* This section is for pre-v5 ESP-IDF */
- #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
- CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
- #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
- CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
- #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
- CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
- #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
- CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
- #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
- #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
- CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
- #else
- /* TODO unsupported */
- #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
- #endif
- #define CPU_TICK_CYCLES ( \
- (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
- / configTICK_RATE_HZ \
- )
- #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
- #if defined(CONFIG_IDF_TARGET_ESP32C2)
- #include "driver/gptimer.h"
- static gptimer_handle_t esp_gptimer = NULL;
- static gptimer_config_t esp_timer_config = {
- .clk_src = GPTIMER_CLK_SRC_DEFAULT,
- .direction = GPTIMER_COUNT_UP,
- .resolution_hz = CONFIG_XTAL_FREQ * 100000,
- };
- #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
- defined(CONFIG_IDF_TARGET_ESP32C6)
- #include <esp_cpu.h>
- #if ESP_IDF_VERSION_MAJOR >= 5
- #include <driver/gptimer.h>
- #endif
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- #define RESOLUTION_SCALE 100
- /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
- static gptimer_handle_t esp_gptimer = NULL;
- static gptimer_config_t esp_timer_config = {
- .clk_src = GPTIMER_CLK_SRC_DEFAULT,
- .direction = GPTIMER_COUNT_UP,
- /* CONFIG_XTAL_FREQ = 40,
- * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
- .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
- (MILLION_VALUE / RESOLUTION_SCALE),
- };
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- #elif defined(CONFIG_IDF_TARGET_ESP32) || \
- defined(CONFIG_IDF_TARGET_ESP32S2) || \
- defined(CONFIG_IDF_TARGET_ESP32S3)
- #include <xtensa/hal.h>
- #elif defined(CONFIG_IDF_TARGET_ESP8266)
- /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
- #include <FreeRTOS.h>
- #include <esp_system.h>
- #include <esp_timer.h>
- #include <xtensa/hal.h>
- #elif defined(CONFIG_IDF_TARGET_ESP32H2)
- /* TODO add ESP32-H2 benchmark support */
- #else
- /* Other platform */
- #endif
- #include <esp_log.h>
- #endif /* WOLFSSL_ESPIDF */
- #if defined(HAVE_PTHREAD) || \
- (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
- !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
- !defined(BENCH_EMBEDDED))
- #include <errno.h>
- #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
- #include <unistd.h>
- #endif
- #endif
- #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
- /* fflush in Zephyr doesn't work on stdout and stderr. Use
- * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
- #undef XFFLUSH
- #define XFFLUSH(...) WC_DO_NOTHING
- #endif
- /* only for stack size check */
- #include <wolfssl/wolfcrypt/mem_track.h>
- #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
- #define WC_ENABLE_BENCH_THREADING
- #endif
- /* enable tracking of stats for threaded benchmark */
- #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
- #define WC_BENCH_TRACK_STATS
- #endif
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- static const char info_prefix[] = "###, ";
- static const char err_prefix[] = "!!!, ";
- #else
- static const char info_prefix[] = "";
- static const char err_prefix[] = "";
- #endif
- /* printf mappings */
- #ifdef FREESCALE_MQX
- #include <mqx.h>
- /* see wc_port.h for fio.h and nio.h includes */
- #elif defined(FREESCALE_KSDK_1_3)
- #include "fsl_debug_console.h"
- #include "fsl_os_abstraction.h"
- #undef printf
- #define printf PRINTF
- #elif defined(WOLFSSL_DEOS)
- #include <deos.h>
- #include <printx.h>
- #undef printf
- #define printf printx
- #elif defined(MICRIUM)
- #if (OS_VERSION < 50000)
- #include <bsp_ser.h>
- void BSP_Ser_Printf (CPU_CHAR* format, ...);
- #undef printf
- #define printf BSP_Ser_Printf
- #endif
- #elif defined(WOLFSSL_ZEPHYR)
- #include <stdio.h>
- #include <stdarg.h>
- #define BENCH_EMBEDDED
- #define printf printfk
- static int printfk(const char *fmt, ...)
- {
- int ret;
- char line[WC_BENCH_MAX_LINE_LEN];
- va_list ap;
- va_start(ap, fmt);
- ret = vsnprintf(line, sizeof(line), fmt, ap);
- line[sizeof(line)-1] = '\0';
- printk("%s", line);
- va_end(ap);
- return ret;
- }
- #elif defined(WOLFSSL_TELIT_M2MB)
- #include <stdarg.h>
- #include <stdio.h>
- #include <string.h>
- #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
- /* remap printf */
- #undef printf
- #define printf M2M_LOG_INFO
- /* OS requires occasional sleep() */
- #ifndef TEST_SLEEP_MS
- #define TEST_SLEEP_MS 50
- #endif
- #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
- /* don't use file system for these tests, since ./certs dir isn't loaded */
- #undef NO_FILESYSTEM
- #define NO_FILESYSTEM
- /* ANDROID_V454 (for android studio) displays information in a textview
- * and redirects printf to the textview output instead of using
- * __android_log_print() */
- #elif defined(ANDROID) && !defined(ANDROID_V454)
- #ifdef XMALLOC_USER
- #include <stdlib.h> /* we're using malloc / free direct here */
- #endif
- #ifndef STRING_USER
- #include <stdio.h>
- #endif
- #include <android/log.h>
- #define printf(...) \
- __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
- #define fprintf(fp, ...) \
- __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
- #else
- #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
- /* MQX classic needs for EXIT_FAILURE */
- #include <stdlib.h> /* we're using malloc / free direct here */
- #endif
- #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
- #include <string.h>
- #include <stdio.h>
- #endif
- /* enable way for customer to override test/bench printf */
- #ifdef XPRINTF
- #undef printf
- #define printf XPRINTF
- #elif defined(NETOS)
- #undef printf
- #define printf dc_log_printf
- #endif
- #endif
- #ifdef HAVE_FIPS
- #include <wolfssl/wolfcrypt/fips_test.h>
- static void myFipsCb(int ok, int err, const char* hash)
- {
- printf("%sin my Fips callback, ok = %d, err = %d\n",
- ok ? info_prefix : err_prefix, ok, err);
- printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
- wc_GetErrorString(err));
- printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
- if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
- printf("%sIn core integrity hash check failure, copy above hash\n",
- err_prefix);
- printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
- err_prefix);
- }
- }
- #endif
- #ifdef WOLFSSL_STATIC_MEMORY
- static WOLFSSL_HEAP_HINT* HEAP_HINT;
- #else
- #define HEAP_HINT NULL
- #endif /* WOLFSSL_STATIC_MEMORY */
- #ifndef EXIT_FAILURE
- #define EXIT_FAILURE 1
- #endif
- #undef LIBCALL_CHECK_RET
- #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
- defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
- #define LIBCALL_CHECK_RET(...) __VA_ARGS__
- #else
- #define LIBCALL_CHECK_RET(...) do { \
- int _libcall_ret = (__VA_ARGS__); \
- if (_libcall_ret < 0) { \
- printf("%s%s L%d error %d for \"%s\"\n", \
- err_prefix, __FILE__, __LINE__, \
- errno, #__VA_ARGS__); \
- XFFLUSH(stdout); \
- _exit(1); \
- } \
- } while(0)
- #endif
- #undef THREAD_CHECK_RET
- #define THREAD_CHECK_RET(...) do { \
- int _thread_ret = (__VA_ARGS__); \
- if (_thread_ret != 0) { \
- errno = _thread_ret; \
- printf("%s%s L%d error %d for \"%s\"\n", \
- err_prefix, __FILE__, __LINE__, \
- _thread_ret, #__VA_ARGS__); \
- XFFLUSH(stdout); \
- _exit(1); \
- } \
- } while(0)
- /* optional macro to add sleep between tests */
- #ifndef TEST_SLEEP
- /* stub the sleep macro */
- #define TEST_SLEEP() WC_DO_NOTHING
- #endif
- #define TEST_STRING "Everyone gets Friday off."
- #define TEST_STRING_SZ 25
- /* Bit values for each algorithm that is able to be benchmarked.
- * Common grouping of algorithms also.
- * Each algorithm has a unique value for its type e.g. cipher.
- */
- /* Cipher algorithms. */
- #define BENCH_AES_CBC 0x00000001
- #define BENCH_AES_GCM 0x00000002
- #define BENCH_AES_ECB 0x00000004
- #define BENCH_AES_XTS 0x00000008
- #define BENCH_AES_CTR 0x00000010
- #define BENCH_AES_CCM 0x00000020
- #define BENCH_CAMELLIA 0x00000100
- #define BENCH_ARC4 0x00000200
- #define BENCH_CHACHA20 0x00001000
- #define BENCH_CHACHA20_POLY1305 0x00002000
- #define BENCH_DES 0x00004000
- #define BENCH_AES_CFB 0x00010000
- #define BENCH_AES_OFB 0x00020000
- #define BENCH_AES_SIV 0x00040000
- #define BENCH_SM4_CBC 0x00080000
- #define BENCH_SM4_GCM 0x00100000
- #define BENCH_SM4_CCM 0x00200000
- #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
- /* Digest algorithms. */
- #define BENCH_MD5 0x00000001
- #define BENCH_POLY1305 0x00000002
- #define BENCH_SHA 0x00000004
- #define BENCH_SHA224 0x00000010
- #define BENCH_SHA256 0x00000020
- #define BENCH_SHA384 0x00000040
- #define BENCH_SHA512 0x00000080
- #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
- BENCH_SHA384 | BENCH_SHA512)
- #define BENCH_SHA3_224 0x00000100
- #define BENCH_SHA3_256 0x00000200
- #define BENCH_SHA3_384 0x00000400
- #define BENCH_SHA3_512 0x00000800
- #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
- BENCH_SHA3_384 | BENCH_SHA3_512)
- #define BENCH_SHAKE128 0x00001000
- #define BENCH_SHAKE256 0x00002000
- #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
- #define BENCH_RIPEMD 0x00004000
- #define BENCH_BLAKE2B 0x00008000
- #define BENCH_BLAKE2S 0x00010000
- #define BENCH_SM3 0x00020000
- /* MAC algorithms. */
- #define BENCH_CMAC 0x00000001
- #define BENCH_HMAC_MD5 0x00000002
- #define BENCH_HMAC_SHA 0x00000004
- #define BENCH_HMAC_SHA224 0x00000010
- #define BENCH_HMAC_SHA256 0x00000020
- #define BENCH_HMAC_SHA384 0x00000040
- #define BENCH_HMAC_SHA512 0x00000080
- #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
- BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
- BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
- #define BENCH_PBKDF2 0x00000100
- #define BENCH_SIPHASH 0x00000200
- /* KDF algorithms */
- #define BENCH_SRTP_KDF 0x00000001
- /* Asymmetric algorithms. */
- #define BENCH_RSA_KEYGEN 0x00000001
- #define BENCH_RSA 0x00000002
- #define BENCH_RSA_SZ 0x00000004
- #define BENCH_DH 0x00000010
- #define BENCH_ECC_MAKEKEY 0x00001000
- #define BENCH_ECC 0x00002000
- #define BENCH_ECC_ENCRYPT 0x00004000
- #define BENCH_ECC_ALL 0x00008000
- #define BENCH_CURVE25519_KEYGEN 0x00010000
- #define BENCH_CURVE25519_KA 0x00020000
- #define BENCH_ED25519_KEYGEN 0x00040000
- #define BENCH_ED25519_SIGN 0x00080000
- #define BENCH_CURVE448_KEYGEN 0x00100000
- #define BENCH_CURVE448_KA 0x00200000
- #define BENCH_ED448_KEYGEN 0x00400000
- #define BENCH_ED448_SIGN 0x00800000
- #define BENCH_ECC_P256 0x01000000
- #define BENCH_ECC_P384 0x02000000
- #define BENCH_ECC_P521 0x04000000
- #define BENCH_SM2 0x08000000
- #define BENCH_ECCSI_KEYGEN 0x00000020
- #define BENCH_ECCSI_PAIRGEN 0x00000040
- #define BENCH_ECCSI_VALIDATE 0x00000080
- #define BENCH_ECCSI 0x00000400
- #define BENCH_SAKKE_KEYGEN 0x10000000
- #define BENCH_SAKKE_RSKGEN 0x20000000
- #define BENCH_SAKKE_VALIDATE 0x40000000
- #define BENCH_SAKKE 0x80000000
- /* Post-Quantum Asymmetric algorithms. */
- #define BENCH_KYBER512 0x00000020
- #define BENCH_KYBER768 0x00000040
- #define BENCH_KYBER1024 0x00000080
- #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
- BENCH_KYBER1024)
- #define BENCH_ML_KEM_512 0x00000020
- #define BENCH_ML_KEM_768 0x00000040
- #define BENCH_ML_KEM_1024 0x00000080
- #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
- BENCH_ML_KEM_1024)
- #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
- #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
- #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
- #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
- #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
- #define BENCH_ML_DSA_44_SIGN 0x04000000
- #define BENCH_ML_DSA_65_SIGN 0x08000000
- #define BENCH_ML_DSA_87_SIGN 0x10000000
- #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
- BENCH_ML_DSA_65_SIGN | \
- BENCH_ML_DSA_87_SIGN)
- /* Post-Quantum Asymmetric algorithms. (Part 2) */
- #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
- #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
- #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
- #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
- #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
- #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
- /* Post-Quantum Stateful Hash-Based sig algorithms. */
- #define BENCH_LMS_HSS 0x00000001
- #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
- #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
- #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
- #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
- #ifndef NO_SHA256
- #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
- #elif defined(WOLFSSL_SHA512)
- #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
- #elif defined(WOLFSSL_SHAKE128)
- #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
- #elif defined(WOLFSSL_SHAKE256)
- #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
- #else
- #define BENCH_XMSS_XMSSMT 0x00000000
- #endif
- /* Other */
- #define BENCH_RNG 0x00000001
- #define BENCH_SCRYPT 0x00000002
- #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
- /* Define AES_AUTH_ADD_SZ already here, since it's used in the
- * static declaration of `bench_Usage_msg1`. */
- #if !defined(AES_AUTH_ADD_SZ) && \
- defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
- defined(WOLFSSL_XILINX_CRYPT_VERSAL)
- /* For STM32 use multiple of 4 to leverage crypto hardware
- * Xilinx Versal requires to use multiples of 16 bytes */
- #define AES_AUTH_ADD_SZ 16
- #endif
- #ifndef AES_AUTH_ADD_SZ
- #define AES_AUTH_ADD_SZ 13
- #endif
- #endif
- #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
- (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
- #define BENCH_PQ_STATEFUL_HBS
- #endif
- /* Benchmark all compiled in algorithms.
- * When 1, ignore other benchmark algorithm values.
- * 0, only benchmark algorithm values set.
- */
- static int bench_all = 1;
- /* Cipher algorithms to benchmark. */
- static word32 bench_cipher_algs = 0;
- /* Digest algorithms to benchmark. */
- static word32 bench_digest_algs = 0;
- /* MAC algorithms to benchmark. */
- static word32 bench_mac_algs = 0;
- /* KDF algorithms to benchmark. */
- static word32 bench_kdf_algs = 0;
- /* Asymmetric algorithms to benchmark. */
- static word32 bench_asym_algs = 0;
- /* Post-Quantum Asymmetric algorithms to benchmark. */
- static word32 bench_pq_asym_algs = 0;
- /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
- static word32 bench_pq_asym_algs2 = 0;
- /* Other cryptographic algorithms to benchmark. */
- static word32 bench_other_algs = 0;
- /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
- static word32 bench_pq_hash_sig_algs = 0;
- #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
- /* The mapping of command line option to bit values. */
- typedef struct bench_alg {
- /* Command line option string. */
- const char* str;
- /* Bit values to set. */
- word32 val;
- } bench_alg;
- #ifndef MAIN_NO_ARGS
- /* All recognized cipher algorithm choosing command line options. */
- static const bench_alg bench_cipher_opt[] = {
- { "-cipher", 0xffffffff },
- #ifdef HAVE_AES_CBC
- { "-aes-cbc", BENCH_AES_CBC },
- #endif
- #ifdef HAVE_AESGCM
- { "-aes-gcm", BENCH_AES_GCM },
- #endif
- #ifdef WOLFSSL_AES_DIRECT
- { "-aes-ecb", BENCH_AES_ECB },
- #endif
- #ifdef WOLFSSL_AES_XTS
- { "-aes-xts", BENCH_AES_XTS },
- #endif
- #ifdef WOLFSSL_AES_CFB
- { "-aes-cfb", BENCH_AES_CFB },
- #endif
- #ifdef WOLFSSL_AES_OFB
- { "-aes-ofb", BENCH_AES_OFB },
- #endif
- #ifdef WOLFSSL_AES_COUNTER
- { "-aes-ctr", BENCH_AES_CTR },
- #endif
- #ifdef HAVE_AESCCM
- { "-aes-ccm", BENCH_AES_CCM },
- #endif
- #ifdef WOLFSSL_AES_SIV
- { "-aes-siv", BENCH_AES_SIV },
- #endif
- #ifdef HAVE_CAMELLIA
- { "-camellia", BENCH_CAMELLIA },
- #endif
- #ifndef NO_RC4
- { "-arc4", BENCH_ARC4 },
- #endif
- #ifdef HAVE_CHACHA
- { "-chacha20", BENCH_CHACHA20 },
- #endif
- #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
- { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
- #endif
- #ifdef WOLFSSL_SM4_CBC
- { "-sm4-cbc", BENCH_SM4_CBC },
- #endif
- #ifdef WOLFSSL_SM4_GCM
- { "-sm4-gcm", BENCH_SM4_GCM },
- #endif
- #ifdef WOLFSSL_SM4_CCM
- { "-sm4-ccm", BENCH_SM4_CCM },
- #endif
- #ifdef WOLFSSL_SM4
- { "-sm4", BENCH_SM4 },
- #endif
- #ifndef NO_DES3
- { "-des", BENCH_DES },
- #endif
- { NULL, 0 }
- };
- /* All recognized digest algorithm choosing command line options. */
- static const bench_alg bench_digest_opt[] = {
- { "-digest", 0xffffffff },
- #ifndef NO_MD5
- { "-md5", BENCH_MD5 },
- #endif
- #ifdef HAVE_POLY1305
- { "-poly1305", BENCH_POLY1305 },
- #endif
- #ifndef NO_SHA
- { "-sha", BENCH_SHA },
- #endif
- #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
- || defined(WOLFSSL_SHA512)
- { "-sha2", BENCH_SHA2 },
- #endif
- #ifdef WOLFSSL_SHA224
- { "-sha224", BENCH_SHA224 },
- #endif
- #ifndef NO_SHA256
- { "-sha256", BENCH_SHA256 },
- #endif
- #ifdef WOLFSSL_SHA384
- { "-sha384", BENCH_SHA384 },
- #endif
- #ifdef WOLFSSL_SHA512
- { "-sha512", BENCH_SHA512 },
- #endif
- #ifdef WOLFSSL_SHA3
- { "-sha3", BENCH_SHA3 },
- #ifndef WOLFSSL_NOSHA3_224
- { "-sha3-224", BENCH_SHA3_224 },
- #endif
- #ifndef WOLFSSL_NOSHA3_256
- { "-sha3-256", BENCH_SHA3_256 },
- #endif
- #ifndef WOLFSSL_NOSHA3_384
- { "-sha3-384", BENCH_SHA3_384 },
- #endif
- #ifndef WOLFSSL_NOSHA3_512
- { "-sha3-512", BENCH_SHA3_512 },
- #endif
- #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
- { "-shake", BENCH_SHAKE },
- #endif
- #ifdef WOLFSSL_SHAKE128
- { "-shake128", BENCH_SHAKE128 },
- #endif
- #ifdef WOLFSSL_SHAKE256
- { "-shake256", BENCH_SHAKE256 },
- #endif
- #endif
- #ifdef WOLFSSL_SM3
- { "-sm3", BENCH_SM3 },
- #endif
- #ifdef WOLFSSL_RIPEMD
- { "-ripemd", BENCH_RIPEMD },
- #endif
- #ifdef HAVE_BLAKE2
- { "-blake2b", BENCH_BLAKE2B },
- #endif
- #ifdef HAVE_BLAKE2S
- { "-blake2s", BENCH_BLAKE2S },
- #endif
- { NULL, 0 }
- };
- /* All recognized MAC algorithm choosing command line options. */
- static const bench_alg bench_mac_opt[] = {
- { "-mac", 0xffffffff },
- #ifdef WOLFSSL_CMAC
- { "-cmac", BENCH_CMAC },
- #endif
- #ifndef NO_HMAC
- { "-hmac", BENCH_HMAC },
- #ifndef NO_MD5
- { "-hmac-md5", BENCH_HMAC_MD5 },
- #endif
- #ifndef NO_SHA
- { "-hmac-sha", BENCH_HMAC_SHA },
- #endif
- #ifdef WOLFSSL_SHA224
- { "-hmac-sha224", BENCH_HMAC_SHA224 },
- #endif
- #ifndef NO_SHA256
- { "-hmac-sha256", BENCH_HMAC_SHA256 },
- #endif
- #ifdef WOLFSSL_SHA384
- { "-hmac-sha384", BENCH_HMAC_SHA384 },
- #endif
- #ifdef WOLFSSL_SHA512
- { "-hmac-sha512", BENCH_HMAC_SHA512 },
- #endif
- #ifndef NO_PWDBASED
- { "-pbkdf2", BENCH_PBKDF2 },
- #endif
- #endif
- #ifdef WOLFSSL_SIPHASH
- { "-siphash", BENCH_SIPHASH },
- #endif
- { NULL, 0 }
- };
- /* All recognized KDF algorithm choosing command line options. */
- static const bench_alg bench_kdf_opt[] = {
- { "-kdf", 0xffffffff },
- #ifdef WC_SRTP_KDF
- { "-srtp-kdf", BENCH_SRTP_KDF },
- #endif
- { NULL, 0 }
- };
- /* All recognized asymmetric algorithm choosing command line options. */
- static const bench_alg bench_asym_opt[] = {
- { "-asym", 0xffffffff },
- #ifndef NO_RSA
- #ifdef WOLFSSL_KEY_GEN
- { "-rsa-kg", BENCH_RSA_KEYGEN },
- #endif
- { "-rsa", BENCH_RSA },
- #ifdef WOLFSSL_KEY_GEN
- { "-rsa-sz", BENCH_RSA_SZ },
- #endif
- #endif
- #ifndef NO_DH
- { "-dh", BENCH_DH },
- #endif
- #ifdef HAVE_ECC
- { "-ecc-kg", BENCH_ECC_MAKEKEY },
- { "-ecc", BENCH_ECC },
- #ifdef HAVE_ECC_ENCRYPT
- { "-ecc-enc", BENCH_ECC_ENCRYPT },
- #endif
- { "-ecc-all", BENCH_ECC_ALL },
- #endif
- #ifdef WOLFSSL_SM2
- { "-sm2", BENCH_SM2 },
- #endif
- #ifdef HAVE_CURVE25519
- { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
- #ifdef HAVE_CURVE25519_SHARED_SECRET
- { "-x25519", BENCH_CURVE25519_KA },
- #endif
- #endif
- #ifdef HAVE_ED25519
- { "-ed25519-kg", BENCH_ED25519_KEYGEN },
- { "-ed25519", BENCH_ED25519_SIGN },
- #endif
- #ifdef HAVE_CURVE448
- { "-curve448-kg", BENCH_CURVE448_KEYGEN },
- #ifdef HAVE_CURVE448_SHARED_SECRET
- { "-x448", BENCH_CURVE448_KA },
- #endif
- #endif
- #ifdef HAVE_ED448
- { "-ed448-kg", BENCH_ED448_KEYGEN },
- { "-ed448", BENCH_ED448_SIGN },
- #endif
- #ifdef WOLFCRYPT_HAVE_ECCSI
- { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
- { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
- { "-eccsi-val", BENCH_ECCSI_VALIDATE },
- { "-eccsi", BENCH_ECCSI },
- #endif
- #ifdef WOLFCRYPT_HAVE_SAKKE
- { "-sakke-kg", BENCH_SAKKE_KEYGEN },
- { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
- { "-sakke-val", BENCH_SAKKE_VALIDATE },
- { "-sakke", BENCH_SAKKE },
- #endif
- { NULL, 0 }
- };
- /* All recognized other cryptographic algorithm choosing command line options.
- */
- static const bench_alg bench_other_opt[] = {
- { "-other", 0xffffffff },
- #ifndef WC_NO_RNG
- { "-rng", BENCH_RNG },
- #endif
- #ifdef HAVE_SCRYPT
- { "-scrypt", BENCH_SCRYPT },
- #endif
- { NULL, 0}
- };
- #endif /* MAIN_NO_ARGS */
- #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
- #if defined(BENCH_PQ_STATEFUL_HBS)
- typedef struct bench_pq_hash_sig_alg {
- /* Command line option string. */
- const char* str;
- /* Bit values to set. */
- word32 val;
- } bench_pq_hash_sig_alg;
- static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
- { "-pq_hash_sig", 0xffffffff},
- #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
- { "-lms_hss", BENCH_LMS_HSS},
- #endif
- #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
- { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
- #ifdef WC_XMSS_SHA256
- { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
- #endif
- #ifdef WC_XMSS_SHA512
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
- { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
- #endif
- #endif
- #ifdef WC_XMSS_SHAKE128
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
- { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
- #endif
- #endif
- #ifdef WC_XMSS_SHAKE256
- { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
- #endif
- #endif
- { NULL, 0}
- };
- #endif /* BENCH_PQ_STATEFUL_HBS */
- #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
- defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
- /* The post-quantum-specific mapping of command line option to bit values and
- * OQS name. */
- typedef struct bench_pq_alg {
- /* Command line option string. */
- const char* str;
- /* Bit values to set. */
- word32 val;
- } bench_pq_alg;
- /* All recognized post-quantum asymmetric algorithm choosing command line
- * options. */
- static const bench_pq_alg bench_pq_asym_opt[] = {
- { "-pq", 0xffffffff },
- #ifdef WOLFSSL_HAVE_KYBER
- { "-kyber", BENCH_KYBER },
- { "-kyber512", BENCH_KYBER512 },
- { "-kyber768", BENCH_KYBER768 },
- { "-kyber1024", BENCH_KYBER1024 },
- { "-ml-kem", BENCH_ML_KEM },
- { "-ml-kem-512", BENCH_ML_KEM_512 },
- { "-ml-kem-768", BENCH_ML_KEM_768 },
- { "-ml-kem-1024", BENCH_ML_KEM_1024 },
- #endif
- #if defined(HAVE_FALCON)
- { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
- { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
- #endif
- #if defined(HAVE_DILITHIUM)
- { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
- { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
- { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
- { "-ml-dsa", BENCH_ML_DSA_SIGN },
- { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
- { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
- { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
- #endif
- { NULL, 0 }
- };
- #if defined(HAVE_SPHINCS)
- /* All recognized post-quantum asymmetric algorithm choosing command line
- * options. (Part 2) */
- static const bench_pq_alg bench_pq_asym_opt2[] = {
- { "-pq", 0xffffffff },
- { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
- { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
- { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
- { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
- { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
- { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
- { NULL, 0, }
- };
- #endif /* HAVE_SPHINCS */
- #endif
- #ifdef HAVE_WNR
- const char* wnrConfigFile = "wnr-example.conf";
- #endif
- #if defined(WOLFSSL_MDK_ARM)
- extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
- #define fopen wolfSSL_fopen
- #endif
- static int lng_index = 0;
- #ifndef NO_MAIN_DRIVER
- #ifndef MAIN_NO_ARGS
- static const char* bench_Usage_msg1[][25] = {
- /* 0 English */
- { "-? <num> Help, print this usage\n",
- " 0: English, 1: Japanese\n",
- "-csv Print terminal output in csv format\n",
- "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
- "-no_aad No additional authentication data passed.\n",
- "-aad_size <num> With <num> bytes of AAD.\n",
- ("-all_aad With AAD length of 0, "
- WC_STRINGIFY(AES_AUTH_ADD_SZ)
- " and\n"
- " (if set via -aad_size) <aad_size> bytes.\n"
- ),
- "-dgst_full Full digest operation performed.\n",
- "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
- "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
- "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
- "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
- "-p256 Measure ECC using P-256 curve.\n",
- "-p384 Measure ECC using P-384 curve.\n",
- "-p521 Measure ECC using P-521 curve.\n",
- "-ecc-all Bench all enabled ECC curves.\n",
- "-<alg> Algorithm to benchmark. Available algorithms include:\n",
- ("-lng <num> Display benchmark result by specified language.\n"
- " 0: English, 1: Japanese\n"
- ),
- "<num> Size of block in bytes\n",
- ("-blocks <num> Number of blocks. Can be used together with the "
- "'Size of block'\n"
- " option, but must be used after that one.\n"
- ),
- "-threads <num> Number of threads to run\n",
- "-print Show benchmark stats summary\n",
- "-hash_input <file> Input data to use for hash benchmarking\n",
- "-cipher_input <file> Input data to use for cipher benchmarking\n",
- "-min_runs <num> Specify minimum number of operation runs\n"
- },
- #ifndef NO_MULTIBYTE_PRINT
- /* 1 Japanese */
- { "-? <num> ヘルプ, 使い方を表示します。\n",
- " 0: 英語、 1: 日本語\n",
- "-csv csv 形式で端末に出力します。\n",
- "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
- "-no_aad 追加の認証データを使用しません.\n",
- "-aad_size <num> TBD.\n",
- "-all_aad TBD.\n",
- "-dgst_full フルの digest 暗号操作を実施します。\n",
- "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
- "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
- "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
- "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
- "-p256 Measure ECC using P-256 curve.\n",
- "-p384 Measure ECC using P-384 curve.\n",
- "-p521 Measure ECC using P-521 curve.\n",
- "-ecc-all Bench all enabled ECC curves.\n",
- ("-<alg> アルゴリズムのベンチマークを実施します。\n"
- " 利用可能なアルゴリズムは下記を含みます:\n"
- ),
- ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
- " 0: 英語、 1: 日本語\n"
- ),
- "<num> ブロックサイズをバイト単位で指定します。\n",
- "-blocks <num> TBD.\n",
- "-threads <num> 実行するスレッド数\n",
- "-print ベンチマーク統計の要約を表示する\n",
- /* TODO: translate below */
- "-hash_input <file> Input data to use for hash benchmarking\n",
- "-cipher_input <file> Input data to use for cipher benchmarking\n",
- "-min_runs <num> Specify minimum number of operation runs\n"
- },
- #endif
- };
- #endif /* MAIN_NO_ARGS */
- #endif
- static const char* bench_result_words1[][4] = {
- { "took",
- #ifdef BENCH_MICROSECOND
- "microseconds"
- #else
- "seconds"
- #endif
- , "Cycles per byte", NULL }, /* 0 English */
- #ifndef NO_MULTIBYTE_PRINT
- { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
- #endif
- };
- #if !defined(NO_RSA) || \
- defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
- defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
- defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
- defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
- defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
- static const char* bench_desc_words[][15] = {
- /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
- {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
- #ifndef NO_MULTIBYTE_PRINT
- {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
- #endif
- };
- #endif
- #ifdef MULTI_VALUE_STATISTICS
- static const char* bench_result_words3[][5] = {
- /* 0 English */
- { "max duration", "min duration" , "mean duration", "sd", NULL },
- /* TODO: Add japenese version */
- { "max duration", "min duration" , "mean duration", "sd", NULL }
- };
- #endif
- #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
- #define HAVE_GET_CYCLES
- static WC_INLINE word64 get_intel_cycles(void);
- static THREAD_LS_T word64 total_cycles;
- #define INIT_CYCLE_COUNTER
- #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
- #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
- /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
- #define SHOW_INTEL_CYCLES(b, n, s) \
- (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
- " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
- bench_result_words1[lng_index][2], \
- FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
- (double)total_cycles / ((word64)count*(s))))
- #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
- (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
- STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
- (double)total_cycles / ((word64)count*(s))))
- #elif defined(LINUX_CYCLE_COUNT)
- #include <linux/perf_event.h>
- #include <sys/syscall.h>
- #include <unistd.h>
- static THREAD_LS_T word64 begin_cycles;
- static THREAD_LS_T word64 total_cycles;
- static THREAD_LS_T int cycles = -1;
- static THREAD_LS_T struct perf_event_attr atr;
- #define INIT_CYCLE_COUNTER do { \
- atr.type = PERF_TYPE_HARDWARE; \
- atr.config = PERF_COUNT_HW_CPU_CYCLES; \
- cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
- } while (0);
- #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
- #define END_INTEL_CYCLES do { \
- read(cycles, &total_cycles, sizeof(total_cycles)); \
- total_cycles = total_cycles - begin_cycles; \
- } while (0);
- /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
- #define SHOW_INTEL_CYCLES(b, n, s) \
- (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
- " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
- bench_result_words1[lng_index][2], \
- FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
- (count*s)))
- #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
- (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
- STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
- / (count*s)))
- #elif defined(SYNERGY_CYCLE_COUNT)
- #include "hal_data.h"
- static THREAD_LS_T word64 begin_cycles;
- static THREAD_LS_T word64 total_cycles;
- #define INIT_CYCLE_COUNTER
- #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
- #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
- /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
- #define SHOW_INTEL_CYCLES(b, n, s) \
- (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
- " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
- bench_result_words1[lng_index][2], \
- FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
- #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
- (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
- FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
- #elif defined(WOLFSSL_ESPIDF)
- /* TAG for ESP_LOGx() */
- static const char* TAG = "wolfssl_benchmark";
- static THREAD_LS_T word64 begin_cycles = 0;
- static THREAD_LS_T word64 begin_cycles_ticks = 0;
- static THREAD_LS_T word64 end_cycles = 0;
- static THREAD_LS_T word64 total_cycles = 0;
- /* the return value, as a global var */
- static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
- /* the last value seen, adjusted for an overflow, as a global var */
- static THREAD_LS_T word64 _esp_cpu_count_last = 0;
- static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
- /* esp_get_cpu_benchmark_cycles(void):
- *
- * Architecture-independant CPU clock counter.
- * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
- static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
- /* Some vars for debugging, compare ticks to cycles */
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
- static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
- static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
- static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
- #if ESP_IDF_VERSION_MAJOR >= 5
- /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
- #define HAVE_GET_CYCLES
- #define INIT_CYCLE_COUNTER do { \
- ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
- esp_cpu_set_cycle_count(0); \
- } while (0);
- #else
- #define HAVE_GET_CYCLES
- #define INIT_CYCLE_COUNTER do { \
- ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
- } while (0);
- #endif
- #define BEGIN_ESP_CYCLES do { \
- ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
- begin_cycles = esp_get_cpu_benchmark_cycles(); \
- begin_cycles_ticks = xTaskGetTickCount(); \
- } while (0);
- /* since it rolls over, we have something that will tolerate one */
- #define END_ESP_CYCLES \
- end_cycles = esp_get_cpu_benchmark_cycles(); \
- ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
- end_cycles, \
- begin_cycles \
- ); \
- total_cycles = (end_cycles - begin_cycles);
- #define SHOW_ESP_CYCLES(b, n, s) \
- (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
- " %s = " FLT_FMT_PREC2 "\n", \
- bench_result_words1[lng_index][2], \
- FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
- )
- #define SHOW_ESP_CYCLES_CSV(b, n, s) \
- (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
- FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- /* 64 bit, unisgned, absolute difference
- * used in CPU cycle counter debug calcs. */
- static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
- {
- uint64_t ret;
- ret = (x > y) ? (x - y) : (y - x);
- return ret;
- }
- #endif
- /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
- ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
- ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
- ** at least once during full benchmark tests.
- **
- ** To test timing overflow, add a delay longer than max cycles:
- ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
- */
- uint64_t esp_get_cycle_count_ex()
- {
- /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
- /* unsigned int max = 4,294,967,295 */
- uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
- uint64_t thisIncrement = 0; /* The adjusted increment amount. */
- uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- uint64_t tickCount = 0; /* Current rtos tick counter. */
- uint64_t tickDiff = 0; /* Tick difference from last check. */
- uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
- #endif
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
- uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
- * (current - last) */
- #endif
- #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
- defined(CONFIG_IDF_TARGET_ESP32C3) || \
- defined(CONFIG_IDF_TARGET_ESP32C6)
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
- thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- #if ESP_IDF_VERSION_MAJOR >= 5
- thisVal = esp_cpu_get_cycle_count();
- #else
- thisVal = cpu_hal_get_cycle_count();
- #endif
- #elif defined(CONFIG_IDF_TARGET_ESP32H2)
- thisVal = esp_cpu_get_cycle_count();
- #elif defined(CONFIG_IDF_TARGET_ESP8266)
- thisVal = esp_timer_get_time();
- #else
- /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
- * Calling current_time(1) to reset time causes thisVal overflow,
- * on Xtensa, but not on RISC-V architecture. See also, below */
- #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
- #ifndef configCPU_CLOCK_HZ
- /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
- #define configCPU_CLOCK_HZ \
- (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
- #endif
- /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
- thisVal = (uint64_t)xTaskGetTickCount() *
- (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
- #elif defined(__XTENSA__)
- thisVal = esp_cpu_get_cycle_count();
- #else
- /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
- thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
- #endif
- #endif
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- {
- tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
- tickDiff = tickCount - last_tickCount; /* ticks since bench start */
- expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
- ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
- ESP_LOGV(TAG, "tickCount = %llu", tickCount);
- ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
- ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
- ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
- }
- #endif
- /* If either thisVal is smaller than last (overflow), and/or the
- * expected value calculated from FreeRTOS tick difference that would
- * have never fit into an unsigned 32 bit integer anyhow... then we
- * need to adjust thisVal to save. */
- if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
- {
- /* Warning: we assume the return type of esp_cpu_get_cycle_count()
- ** will always be unsigned int (or uint32_t) to add UINT_MAX.
- **
- ** NOTE for long duration between calls with multiple overflows:
- **
- ** WILL NOT BE DETECTED - the return value will be INCORRECT.
- **
- ** At this time no single test overflows. This is currently only a
- ** concern for cumulative counts over multiple tests. As long
- ** as well call xthal_get_ccount_ex() with no more than one
- ** overflow CPU tick count, all will be well.
- */
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
- "(%llu < %llu) adding UINT_MAX = %llu.",
- thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
- #endif
- #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
- !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
- #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
- #endif
- /* double check expected diff calc */
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- #if defined(CONFIG_IDF_TARGET_ESP8266)
- expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
- * MILLION_VALUE)
- * tickDiff / configTICK_RATE_HZ;
- #else
- expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
- * tickDiff / configTICK_RATE_HZ;
- #endif
- ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
- #endif
- if (expected_diff > UINT_MAX) {
- /* The number of cycles expected from FreeRTOS ticks is
- * greater than the maximum size of an unsigned 32-bit
- * integer, meaning multiple overflows occurred. */
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
- #endif
- thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
- }
- else {
- thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
- }
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- {
- tickBeginDiff = tickCount - begin_cycles_ticks;
- ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
- ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
- ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
- ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
- ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
- }
- #endif
- }
- else {
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
- #endif
- } /* if thisVal adjustment check */
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- if (thisTimerVal < _esp_cpu_timer_last)
- {
- ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
- "adding %ull", UINT_MAX);
- thisTimerVal += (word64)UINT_MAX;
- }
- /* Check an alternate counter using a timer */
- _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- /* Adjust our actual returned value that takes into account overflow,
- * increment 64 bit extended total by this 32 bit differential: */
- thisIncrement = (thisVal - _esp_cpu_count_last);
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
- #endif
- /* Add our adjustment, taking into account overflows (see above) */
- _esp_get_cycle_count_ex += thisIncrement;
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
- _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
- diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- /* all of this took some time, so reset the "last seen" value
- * for the next measurement. */
- #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
- defined(CONFIG_IDF_TARGET_ESP32C3) || \
- defined(CONFIG_IDF_TARGET_ESP32C6)
- {
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
- &_esp_cpu_timer_last));
- ESP_LOGI(TAG, "thisVal = %llu", thisVal);
- ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
- ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
- ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- #if ESP_IDF_VERSION_MAJOR >= 5
- _esp_cpu_count_last = esp_cpu_get_cycle_count();
- #else
- _esp_cpu_count_last = cpu_hal_get_cycle_count();
- #endif
- ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
- }
- #elif defined(CONFIG_IDF_TARGET_ESP32H2)
- _esp_cpu_count_last = esp_cpu_get_cycle_count();
- #else
- /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
- * when resetting CPU cycle counter? FreeRTOS tick collision?
- * thisVal = esp_cpu_get_cycle_count(); See also, above
- * or thisVal = xthal_get_ccount(); */
- #if defined(CONFIG_IDF_TARGET_ESP8266)
- /* There's no CPU counter on the ESP8266, so we'll estimate
- * cycles based on defined CPU frequency from sdkconfig and
- * the RTOS tick frequency */
- _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
- (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
- #elif ESP_IDF_VERSION_MAJOR < 5
- _esp_cpu_count_last = xthal_get_ccount();
- #else
- _esp_cpu_count_last = esp_cpu_get_cycle_count();
- #endif
- #endif
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
- #endif
- /* Return the 64 bit extended total from 32 bit counter. */
- return _esp_get_cycle_count_ex;
- } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
- /* implement other architecture cycle counters here */
- #else
- /* if we don't know the platform, it is unlikely we can count CPU cycles */
- #undef HAVE_GET_CYCLES
- #define INIT_CYCLE_COUNTER
- #define BEGIN_INTEL_CYCLES
- #define END_INTEL_CYCLES
- #ifdef MULTI_VALUE_STATISTICS
- #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
- #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
- #else
- #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
- #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
- #endif
- #endif
- /* determine benchmark buffer to use (if NO_FILESYSTEM) */
- #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
- !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
- #define USE_CERT_BUFFERS_2048 /* default to 2048 */
- #endif
- #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
- defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
- !defined(NO_DH)
- /* include test cert and key buffers for use with NO_FILESYSTEM */
- #include <wolfssl/certs_test.h>
- #endif
- #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
- #include <wolfssl/wolfcrypt/blake2.h>
- #endif
- #ifdef _MSC_VER
- /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
- #pragma warning(disable: 4996)
- #endif
- #ifdef WOLFSSL_CURRTIME_REMAP
- #define current_time WOLFSSL_CURRTIME_REMAP
- #else
- double current_time(int reset);
- #endif
- #ifdef LINUX_RUSAGE_UTIME
- static void check_for_excessive_stime(const char *desc,
- const char *desc_extra);
- #endif
- #if !defined(WC_NO_RNG) && \
- ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
- || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
- || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
- || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
- || defined(WOLFSSL_HAVE_KYBER))
- #define HAVE_LOCAL_RNG
- static THREAD_LS_T WC_RNG gRng;
- #define GLOBAL_RNG &gRng
- #else
- #define GLOBAL_RNG NULL
- #endif
- #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
- defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
- defined(HAVE_ECC) || !defined(NO_DH) || \
- !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
- defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
- defined(WOLFSSL_HAVE_LMS)
- #define BENCH_ASYM
- #endif
- #if defined(BENCH_ASYM)
- #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
- defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
- defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
- defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
- defined(WOLFSSL_HAVE_LMS)
- static const char* bench_result_words2[][5] = {
- #ifdef BENCH_MICROSECOND
- { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
- for μsec */
- #else
- { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
- #endif
- #ifndef NO_MULTIBYTE_PRINT
- { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
- #endif
- };
- #endif
- #endif
- #ifdef WOLFSSL_CAAM
- #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
- #ifdef WOLFSSL_SECO_CAAM
- #define SECO_MAX_UPDATES 10000
- #define SECO_BENCHMARK_NONCE 0x7777
- #define SECO_KEY_STORE_ID 1
- #endif
- static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
- #else
- #ifdef WC_USE_DEVID
- static THREAD_LS_T int devId = WC_USE_DEVID;
- #else
- static THREAD_LS_T int devId = INVALID_DEVID;
- #endif
- #endif
- /* Asynchronous helper macros */
- #ifdef WC_ENABLE_BENCH_THREADING
- typedef struct ThreadData {
- pthread_t thread_id;
- } ThreadData;
- static ThreadData* g_threadData;
- static volatile int g_threadCount;
- #endif
- #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
- #ifndef NO_HW_BENCH
- #define BENCH_DEVID
- #endif
- #ifndef HAVE_RENESAS_SYNC
- #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
- #else
- #define BENCH_DEVID_GET_NAME(useDeviceID) ""
- #endif
- #else
- #define BENCH_DEVID_GET_NAME(useDeviceID) ""
- #endif
- #ifdef WOLFSSL_ASYNC_CRYPT
- static WOLF_EVENT_QUEUE eventQueue;
- #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
- #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
- static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
- int callAgain, int* times, int limit, int* pending)
- {
- int allowNext = 0;
- /* this state can be set from a different thread */
- WOLF_EVENT_STATE state = asyncDev->event.state;
- /* if algo doesn't require calling again then use this flow */
- if (state == WOLF_EVENT_STATE_DONE) {
- if (callAgain) {
- /* needs called again, so allow it and handle completion in
- * bench_async_handle */
- allowNext = 1;
- }
- else {
- *ret = asyncDev->event.ret;
- asyncDev->event.state = WOLF_EVENT_STATE_READY;
- (*times)++;
- if (*pending > 0) /* to support case where async blocks */
- (*pending)--;
- if ((*times + *pending) < limit)
- allowNext = 1;
- }
- }
- /* if slot is available and we haven't reached limit, start another */
- else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
- allowNext = 1;
- }
- return allowNext;
- }
- static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
- int callAgain, int* times, int* pending)
- {
- WOLF_EVENT_STATE state = asyncDev->event.state;
- if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
- if (state == WOLF_EVENT_STATE_DONE) {
- *ret = asyncDev->event.ret;
- asyncDev->event.state = WOLF_EVENT_STATE_READY;
- (*times)++;
- (*pending)--;
- }
- else {
- (*pending)++;
- *ret = wc_AsyncHandle(asyncDev, &eventQueue,
- callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
- }
- }
- else if (*ret >= 0) {
- *ret = asyncDev->event.ret;
- asyncDev->event.state = WOLF_EVENT_STATE_READY;
- (*times)++;
- if (*pending > 0) /* to support case where async blocks */
- (*pending)--;
- }
- return (*ret >= 0) ? 1 : 0;
- }
- static WC_INLINE int bench_async_poll(int* pending)
- {
- int ret, asyncDone = 0;
- ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
- WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
- if (ret != 0) {
- printf("%sAsync poll failed %d\n", err_prefix, ret);
- return ret;
- }
- if (asyncDone == 0) {
- #ifndef WC_NO_ASYNC_THREADING
- /* give time to other threads */
- wc_AsyncThreadYield();
- #endif
- }
- (void)pending;
- return asyncDone;
- }
- #else
- #define BENCH_MAX_PENDING 1
- #define BENCH_ASYNC_GET_DEV(obj) NULL
- static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
- int callAgain, int* times, int limit, int* pending)
- {
- (void)ret;
- (void)asyncDev;
- (void)callAgain;
- (void)times;
- (void)limit;
- (void)pending;
- return 1;
- }
- static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
- int callAgain, int* times, int* pending)
- {
- (void)asyncDev;
- (void)callAgain;
- (void)pending;
- if (*ret >= 0) {
- /* operation completed */
- (*times)++;
- return 1;
- }
- return 0;
- }
- #define bench_async_poll(p) WC_DO_NOTHING
- #endif /* WOLFSSL_ASYNC_CRYPT */
- /* maximum runtime for each benchmark */
- #ifndef BENCH_MIN_RUNTIME_SEC
- #define BENCH_MIN_RUNTIME_SEC 1.0F
- #endif
- #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
- #define AES_AUTH_TAG_SZ 16
- #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
- static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
- #if !defined(AES_AAD_OPTIONS_DEFAULT)
- #if !defined(NO_MAIN_DRIVER)
- #define AES_AAD_OPTIONS_DEFAULT 0x1U
- #else
- #define AES_AAD_OPTIONS_DEFAULT 0x3U
- #endif
- #endif
- #define AES_AAD_STRING(s) \
- (aesAuthAddSz == 0 ? (s "-no_AAD") : \
- (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
- enum en_aad_options {
- AAD_SIZE_DEFAULT = 0x1U,
- AAD_SIZE_ZERO = 0x2U,
- AAD_SIZE_CUSTOM = 0x4U,
- };
- static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
- static word32 aes_aad_size = 0;
- static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
- {
- word32 aesAuthAddSz_orig = aesAuthAddSz;
- word32 options = aes_aad_options;
- while(options) {
- if (options & AAD_SIZE_DEFAULT) {
- aesAuthAddSz = AES_AUTH_ADD_SZ;
- options &= ~(word32)AAD_SIZE_DEFAULT;
- }
- else if (options & AAD_SIZE_ZERO) {
- aesAuthAddSz = 0;
- options &= ~(word32)AAD_SIZE_ZERO;
- }
- else if (options & AAD_SIZE_CUSTOM) {
- aesAuthAddSz = aes_aad_size;
- options &= ~(word32)AAD_SIZE_CUSTOM;
- }
- fn(i);
- aesAuthAddSz = aesAuthAddSz_orig;
- }
- }
- #endif
- #ifndef BENCH_CIPHER_ADD
- #define BENCH_CIPHER_ADD 0
- #endif
- /* use kB instead of mB for embedded benchmarking */
- #ifdef BENCH_EMBEDDED
- #ifndef BENCH_NTIMES
- #define BENCH_NTIMES 2
- #endif
- #ifndef BENCH_AGREETIMES
- #define BENCH_AGREETIMES 2
- #endif
- enum BenchmarkBounds {
- scryptCnt = 1,
- ntimes = BENCH_NTIMES,
- genTimes = BENCH_MAX_PENDING,
- agreeTimes = BENCH_AGREETIMES
- };
- /* how many kB to test (en/de)cryption */
- #define NUM_BLOCKS 25
- #define BENCH_SIZE (1024uL)
- #else
- #ifndef BENCH_NTIMES
- #define BENCH_NTIMES 100
- #endif
- #ifndef BENCH_AGREETIMES
- #define BENCH_AGREETIMES 100
- #endif
- enum BenchmarkBounds {
- scryptCnt = 10,
- ntimes = BENCH_NTIMES,
- genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
- agreeTimes = BENCH_AGREETIMES
- };
- /* how many megs to test (en/de)cryption */
- #define NUM_BLOCKS 5
- #define BENCH_SIZE (1024*1024uL)
- #endif
- static int numBlocks = NUM_BLOCKS;
- static word32 bench_size = BENCH_SIZE;
- static int base2 = 1;
- static int digest_stream = 1;
- #ifdef HAVE_CHACHA
- static int encrypt_only = 0;
- #endif
- #ifdef HAVE_AES_CBC
- static int cipher_same_buffer = 0;
- #endif
- #ifdef MULTI_VALUE_STATISTICS
- static int minimum_runs = 0;
- #endif
- #ifndef NO_RSA
- /* Don't measure RSA sign/verify by default */
- static int rsa_sign_verify = 0;
- #endif
- #ifndef NO_DH
- /* Use the FFDHE parameters */
- static int use_ffdhe = 0;
- #endif
- /* Don't print out in CSV format by default */
- static int csv_format = 0;
- #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
- /* Versal PLM maybe prints an error message to the same console.
- * In order to not mix those outputs up, sleep a little while
- * before erroring out.
- */
- #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
- #else
- #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
- #endif
- /* globals for cipher tests */
- static THREAD_LS_T byte* bench_plain = NULL;
- static THREAD_LS_T byte* bench_cipher = NULL;
- #ifndef NO_FILESYSTEM
- static THREAD_LS_T char* hash_input = NULL;
- static THREAD_LS_T char* cipher_input = NULL;
- #endif
- static const XGEN_ALIGN byte bench_key_buf[] =
- {
- 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
- 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
- 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
- 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
- 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
- 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
- 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
- 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
- };
- static const XGEN_ALIGN byte bench_iv_buf[] =
- {
- 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
- };
- static THREAD_LS_T byte* bench_key = NULL;
- static THREAD_LS_T byte* bench_iv = NULL;
- #ifdef HAVE_RENESAS_SYNC
- static THREAD_LS_T byte* bench_key1 = NULL;
- static THREAD_LS_T byte* bench_key2 = NULL;
- #endif
- #ifdef WOLFSSL_STATIC_MEMORY
- #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
- static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
- #elif defined(BENCH_EMBEDDED)
- static byte gBenchMemory[50000];
- #else
- static byte gBenchMemory[400000];
- #endif
- #endif
- /* This code handles cases with systems where static (non cost) ram variables
- aren't properly initialized with data */
- static void benchmark_static_init(int force)
- {
- static int gBenchStaticInit = 0;
- if (gBenchStaticInit == 0 || force) {
- gBenchStaticInit = 1;
- /* Init static variables */
- numBlocks = NUM_BLOCKS;
- bench_size = BENCH_SIZE;
- #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
- aesAuthAddSz = AES_AUTH_ADD_SZ;
- aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
- aes_aad_size = 0;
- #endif
- base2 = 1;
- digest_stream = 1;
- #ifdef MULTI_VALUE_STATISTICS
- minimum_runs = 0;
- #endif
- bench_all = 1;
- bench_cipher_algs = 0;
- bench_digest_algs = 0;
- bench_mac_algs = 0;
- bench_kdf_algs = 0;
- bench_asym_algs = 0;
- bench_pq_asym_algs = 0;
- bench_other_algs = 0;
- bench_pq_hash_sig_algs = 0;
- csv_format = 0;
- }
- }
- /*****************************************************************************/
- /* Begin Stats Functions */
- /*****************************************************************************/
- typedef enum bench_stat_type {
- BENCH_STAT_ASYM,
- BENCH_STAT_SYM,
- BENCH_STAT_IGNORE,
- } bench_stat_type_t;
- #ifdef WC_BENCH_TRACK_STATS
- static int gPrintStats = 0;
- #ifdef WC_ENABLE_BENCH_THREADING
- static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
- #endif
- #ifndef BENCH_MAX_NAME_SZ
- #define BENCH_MAX_NAME_SZ 24
- #endif
- typedef struct bench_stats {
- struct bench_stats* next;
- struct bench_stats* prev;
- char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
- const char* desc;
- double perfsec;
- int strength;
- int useDeviceID;
- int finishCount;
- bench_stat_type_t type;
- int lastRet;
- const char* perftype;
- } bench_stats_t;
- static bench_stats_t* bench_stats_head;
- static bench_stats_t* bench_stats_tail;
- static bench_stats_t* bench_stats_add(bench_stat_type_t type,
- const char* algo, int strength, const char* desc, int useDeviceID,
- double perfsec, const char* perftype, int ret)
- {
- bench_stats_t* bstat = NULL;
- #ifdef WC_ENABLE_BENCH_THREADING
- /* protect bench_stats_head and bench_stats_tail access */
- THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
- #endif
- if (algo != NULL) {
- /* locate existing in list */
- for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
- /* match based on algo, strength and desc */
- if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
- bstat->strength == strength &&
- bstat->desc == desc &&
- bstat->useDeviceID == useDeviceID) {
- break;
- }
- }
- }
- if (bstat == NULL) {
- /* allocate new and put on list */
- bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
- DYNAMIC_TYPE_INFO);
- if (bstat) {
- XMEMSET(bstat, 0, sizeof(bench_stats_t));
- /* add to list */
- bstat->next = NULL;
- if (bench_stats_tail == NULL) {
- bench_stats_head = bstat;
- }
- else {
- bench_stats_tail->next = bstat;
- bstat->prev = bench_stats_tail;
- }
- bench_stats_tail = bstat; /* add to the end either way */
- }
- }
- if (bstat) {
- bstat->type = type;
- if (algo != NULL)
- XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
- bstat->strength = strength;
- bstat->desc = desc;
- bstat->useDeviceID = useDeviceID;
- bstat->perfsec += perfsec;
- bstat->finishCount++;
- bstat->perftype = perftype;
- if (bstat->lastRet > ret)
- bstat->lastRet = ret; /* track last error */
- }
- #ifdef WC_ENABLE_BENCH_THREADING
- THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
- #endif
- return bstat;
- }
- void bench_stats_print(void)
- {
- bench_stats_t* bstat;
- int digits;
- #ifdef WC_ENABLE_BENCH_THREADING
- /* protect bench_stats_head and bench_stats_tail access */
- THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
- #endif
- #ifdef BENCH_MICROSECOND
- digits = 5;
- #else
- digits = 3;
- #endif
- for (bstat = bench_stats_head; bstat != NULL; ) {
- if (bstat->type == BENCH_STAT_SYM) {
- printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
- "\n", bstat->desc,
- BENCH_DEVID_GET_NAME(bstat->useDeviceID),
- FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
- base2 ? "MB" : "mB");
- }
- else {
- printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec\n",
- bstat->algo, bstat->strength, bstat->desc,
- BENCH_DEVID_GET_NAME(bstat->useDeviceID),
- FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
- }
- bstat = bstat->next;
- }
- #ifdef WC_ENABLE_BENCH_THREADING
- THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
- #endif
- }
- #endif /* WC_BENCH_TRACK_STATS */
- static WC_INLINE void bench_stats_init(void)
- {
- #ifdef WC_BENCH_TRACK_STATS
- bench_stats_head = NULL;
- bench_stats_tail = NULL;
- #endif
- INIT_CYCLE_COUNTER
- }
- static WC_INLINE void bench_stats_start(int* count, double* start)
- {
- *count = 0;
- *start = current_time(1);
- #ifdef WOLFSSL_ESPIDF
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
- ", start=" FLT_FMT,
- total_cycles, FLT_FMT_ARGS(*start) );
- #endif
- BEGIN_ESP_CYCLES
- #else
- BEGIN_INTEL_CYCLES
- #endif
- }
- #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
- #define bench_stats_start(count, start) do { \
- SAVE_VECTOR_REGISTERS(pr_err( \
- "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
- return; ); \
- bench_stats_start(count, start); \
- } while (0)
- #endif
- static WC_INLINE int bench_stats_check(double start)
- {
- int ret = 0;
- double this_current_time = 0.0;
- this_current_time = current_time(0); /* get the timestamp, no reset */
- #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
- #if defined(WOLFSSL_ESPIDF)
- ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
- this_current_time, start );
- #endif
- #endif
- ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
- #ifdef BENCH_MICROSECOND
- * 1000000
- #endif
- );
- return ret;
- }
- /* return text for units and scale the value of blocks as needed */
- static const char* get_blocktype(double* blocks)
- {
- const char* rt;
- #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
- defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
- #undef WOLFSSL_FIXED_UNIT
- #define WOLFSSL_FIXED_UNIT "GB"
- *blocks /= (1024UL * 1024UL * 1024UL);
- rt = "GiB";
- #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
- defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
- #undef WOLFSSL_FIXED_UNIT
- #define WOLFSSL_FIXED_UNIT "MB"
- *blocks /= (1024UL * 1024UL);
- rt = "MiB";
- #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
- defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
- #undef WOLFSSL_FIXED_UNIT
- #define WOLFSSL_FIXED_UNIT "KB"
- *blocks /= 1024;
- rt = "KiB";
- #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
- #undef WOLFSSL_FIXED_UNIT
- #define WOLFSSL_FIXED_UNIT "bytes"
- (void)(*blocks); /* no adjustment, just appease compiler for not used */
- rt = "bytes";
- #else
- /* If no user-specified, auto-scale each metric (results vary).
- * Determine if we should show as KB or MB or bytes. No GiB here. */
- if (*blocks > (1024UL * 1024UL)) {
- *blocks /= (1024UL * 1024UL);
- rt = "MiB";
- }
- else if (*blocks > 1024) {
- *blocks /= 1024;
- rt = "KiB";
- }
- else {
- rt = "bytes";
- }
- #endif
- return rt;
- }
- /* return text for units and scale the value of blocks as needed for base2 */
- static const char* get_blocktype_base10(double* blocks)
- {
- const char* rt;
- #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
- defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
- *blocks /= (1000UL * 1000UL * 1000UL);
- rt = "GB";
- #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
- defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
- *blocks /= (1000UL * 1000UL);
- rt = "MB";
- #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
- defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
- *blocks /= (1000UL);
- rt = "KB";
- #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
- (void)(*blocks); /* no adjustment, just appease compiler */
- rt = "bytes";
- #else
- /* If not user-specified, auto-scale each metric (results vary).
- * Determine if we should show as KB or MB or bytes */
- if (*blocks > (1000UL * 1000UL)) {
- *blocks /= (1000UL * 1000UL);
- rt = "MB";
- }
- else if (*blocks > 1000) {
- *blocks /= 1000; /* make KB */
- rt = "KB";
- }
- else {
- rt = "bytes";
- }
- #endif
- return rt;
- }
- #ifdef MULTI_VALUE_STATISTICS
- static double wc_sqroot(double in)
- {
- /* do 32 iterations for the sqroot */
- int iter = 32;
- double root = in/3.0;
- if (in < 0.0)
- return -1;
- for (int i=0; i < iter; i++)
- root = (root + in / root) / 2.0;
- return root;
- }
- static void bench_multi_value_stats(double max, double min, double sum,
- double squareSum, int runs)
- {
- double mean = 0;
- double sd = 0;
- char msg[WC_BENCH_MAX_LINE_LEN];
- const char** word = bench_result_words3[lng_index];
- XMEMSET(msg, 0, sizeof(msg));
- mean = sum / runs;
- /* Calculating standard deviation */
- sd = (squareSum / runs) - (mean * mean);
- sd = wc_sqroot(sd);
- if (csv_format == 1) {
- (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
- FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
- FLT_FMT_PREC2_ARGS(3, 3, max),
- FLT_FMT_PREC2_ARGS(3, 3, min),
- FLT_FMT_PREC2_ARGS(3, 3, mean),
- FLT_FMT_PREC2_ARGS(3, 3, sd));
- }
- else{
- (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
- WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
- WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
- WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
- WOLFSSL_FIXED_TIME_UNIT "\n",
- word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
- word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
- word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
- word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
- }
- printf("%s", msg);
- #ifndef WOLFSSL_SGX
- XFFLUSH(stdout);
- #endif
- }
- #endif
- /* countSz is number of bytes that 1 count represents. Normally bench_size,
- * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */
- static void bench_stats_sym_finish(const char* desc, int useDeviceID,
- int count, word32 countSz,
- double start, int ret)
- {
- double total, persec = 0, blocks = (double)count;
- const char* blockType;
- char msg[WC_BENCH_MAX_LINE_LEN];
- const char** word = bench_result_words1[lng_index];
- static int sym_header_printed = 0;
- XMEMSET(msg, 0, sizeof(msg));
- #ifdef WOLFSSL_ESPIDF
- END_ESP_CYCLES
- #else
- END_INTEL_CYCLES
- #endif
- total = current_time(0) - start;
- #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
- ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
- #endif
- #ifdef LINUX_RUSAGE_UTIME
- check_for_excessive_stime(desc, "");
- #endif
- /* calculate actual bytes */
- blocks *= countSz;
- if (csv_format == 1) {
- /* only print out header once */
- if (sym_header_printed == 0) {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- /* machine parseable CSV */
- #ifdef HAVE_GET_CYCLES
- printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
- WOLFSSL_FIXED_TIME_UNIT "econds_total,"
- WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
- ",cycles_total,Cycles per byte,");
- #else
- printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
- WOLFSSL_FIXED_TIME_UNIT "econds_total,"
- WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
- ",cycles_total,");
- #endif
- #else
- /* normal CSV */
- #ifdef BENCH_DEVID
- #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
- #else
- #define BENCH_DEVID_COLUMN_HEADER
- #endif
- #ifdef HAVE_GET_CYCLES
- printf("\n\nSymmetric Ciphers:\n\n");
- printf("Algorithm,"
- BENCH_DEVID_COLUMN_HEADER
- WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
- ",Cycles per byte,");
- #else
- printf("\n\nSymmetric Ciphers:\n\n");
- printf("Algorithm,"
- BENCH_DEVID_COLUMN_HEADER
- WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
- #endif
- #endif
- #ifdef MULTI_VALUE_STATISTICS
- printf("max duration,min duration,mean duration,sd,\n");
- #else
- printf("\n");
- #endif
- sym_header_printed = 1;
- }
- }
- /* determine if we have fixed units, or auto-scale bits or bytes for units.
- * note that the blockType text is assigned AND the blocks param is scaled.
- */
- if (base2) {
- blockType = get_blocktype(&blocks);
- }
- else {
- blockType = get_blocktype_base10(&blocks);
- }
- /* calculate blocks per second */
- if (total > 0) {
- persec = (1 / total) * blocks;
- }
- SLEEP_ON_ERROR(ret);
- /* format and print to terminal */
- if (csv_format == 1) {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef WOLFSSL_ESPIDF
- unsigned long bytes_processed =
- (unsigned long)count * (unsigned long)countSz;
- #else
- word64 bytes_processed = (word64)count * (word64)countSz;
- #endif
- /* note this codepath brings in all the fields from the non-CSV case. */
- #ifdef WOLFSSL_ESPIDF
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
- BENCH_DEVID_GET_NAME(useDeviceID),
- bytes_processed, FLT_FMT_ARGS(total),
- FLT_FMT_ARGS(persec),
- (long unsigned int) total_cycles);
- #else
- #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
- #endif
- /* implement other architectures here */
- #else
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
- BENCH_DEVID_GET_NAME(useDeviceID),
- bytes_processed, FLT_FMT_ARGS(total),
- FLT_FMT_ARGS(persec), total_cycles);
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
- BENCH_DEVID_GET_NAME(useDeviceID),
- bytes_processed, FLT_FMT_ARGS(total),
- FLT_FMT_ARGS(persec));
- #endif
- #endif
- #elif defined(BENCH_DEVID)
- (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
- BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
- #else
- (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
- FLT_FMT_ARGS(persec));
- #endif
- #ifdef WOLFSSL_ESPIDF
- SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
- total_cycles);
- #endif
- /* implement other cycle counters here */
- #else
- /* the default cycle counter is Intel */
- SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
- #endif
- } /* if (csv_format == 1) */
- else {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
- FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
- desc, BENCH_DEVID_GET_NAME(useDeviceID),
- FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
- word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
- FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
- (unsigned long) total_cycles);
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
- FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
- desc, BENCH_DEVID_GET_NAME(useDeviceID),
- FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
- word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
- FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
- #endif /* HAVE_GET_CYCLES */
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
- FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
- desc, BENCH_DEVID_GET_NAME(useDeviceID),
- FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
- word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
- FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
- #endif
- #ifdef WOLFSSL_ESPIDF
- SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
- /* implement other architecture cycle counters here */
- #else
- SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
- #endif
- } /* not CSV format */
- printf("%s", msg);
- /* show errors */
- if (ret < 0) {
- printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
- }
- #ifndef WOLFSSL_SGX
- XFFLUSH(stdout);
- #endif
- #ifdef WC_BENCH_TRACK_STATS
- /* Add to thread stats */
- bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
- blockType, ret);
- #endif
- (void)useDeviceID;
- (void)ret;
- #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
- RESTORE_VECTOR_REGISTERS();
- #endif
- TEST_SLEEP();
- } /* bench_stats_sym_finish */
- #ifdef BENCH_ASYM
- #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
- defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
- defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
- defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
- defined(WOLFSSL_HAVE_LMS)
- static void bench_stats_asym_finish_ex(const char* algo, int strength,
- const char* desc, const char* desc_extra, int useDeviceID, int count,
- double start, int ret)
- {
- double total, each = 0, opsSec, milliEach;
- const char **word = bench_result_words2[lng_index];
- #ifdef WC_BENCH_TRACK_STATS
- const char* kOpsSec = "Ops/Sec";
- #endif
- char msg[256];
- static int asym_header_printed = 0;
- #ifdef BENCH_MICROSECOND
- const int digits = 5;
- #else
- const int digits = 3;
- #endif
- XMEMSET(msg, 0, sizeof(msg));
- total = current_time(0) - start;
- #ifdef LINUX_RUSAGE_UTIME
- check_for_excessive_stime(desc, desc_extra);
- #endif
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef WOLFSSL_ESPIDF
- END_ESP_CYCLES
- #else
- END_INTEL_CYCLES
- #endif
- #endif
- /* some sanity checks on the final numbers */
- if (count > 0) {
- each = total / count; /* per second */
- }
- else {
- count = 0;
- each = 0;
- }
- if (total > 0) {
- opsSec = count / total; /* ops second */
- }
- else {
- opsSec = 0;
- }
- #ifdef BENCH_MICROSECOND
- milliEach = each / 1000; /* milliseconds */
- #else
- milliEach = each * 1000; /* milliseconds */
- #endif
- SLEEP_ON_ERROR(ret);
- #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
- (void)milliEach;
- /* format and print to terminal */
- if (csv_format == 1) {
- /* only print out header once */
- if (asym_header_printed == 0) {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
- "ecs,cycles,cycles/op,");
- #else
- printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
- "ecs,");
- #endif
- #else
- printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
- printf("%sAlgorithm,key size,operation,ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
- #endif
- printf("max duration,min duration,mean duration,sd,\n");
- asym_header_printed = 1;
- }
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
- FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- FLT_FMT_PREC_ARGS(digits, opsSec),
- count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
- FLT_FMT_PREC_ARGS(6,
- (double)total_cycles / (double)count));
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
- FLT_FMT STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- FLT_FMT_PREC_ARGS(digits, opsSec),
- count, FLT_FMT_ARGS(total));
- #endif
- #else
- (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
- FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- FLT_FMT_PREC_ARGS(digits, opsSec));
- #endif
- } /* if (csv_format == 1) */
- else {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
- FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
- FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
- FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
- (unsigned long)total_cycles);
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
- FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
- FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
- FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
- #endif /* HAVE_GET_CYCLES */
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
- FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
- FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
- FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
- #endif
- }
- #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
- /* format and print to terminal */
- if (csv_format == 1) {
- /* only print out header once */
- if (asym_header_printed == 0) {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
- "ecs,cycles,cycles/op,");
- #else
- printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
- "ecs,");
- #endif
- #else
- printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
- printf("%sAlgorithm,key size,operation,avg ms,ops/"
- WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
- #endif
- printf("\n");
- asym_header_printed = 1;
- }
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
- FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- FLT_FMT_PREC_ARGS(3, milliEach),
- FLT_FMT_PREC_ARGS(digits, opsSec),
- count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
- FLT_FMT_PREC_ARGS(6,
- (double)total_cycles / (double)count));
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
- FLT_FMT STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- FLT_FMT_PREC_ARGS(3, milliEach),
- FLT_FMT_PREC_ARGS(digits, opsSec),
- count, FLT_FMT_ARGS(total));
- #endif
- #else
- (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
- FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- FLT_FMT_PREC_ARGS(3, milliEach),
- FLT_FMT_PREC_ARGS(digits, opsSec));
- #endif
- } /* if (csv_format == 1) */
- else {
- #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
- #ifdef HAVE_GET_CYCLES
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
- FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
- STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
- FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
- FLT_FMT_PREC2_ARGS(5, 3, milliEach),
- FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
- (unsigned long)total_cycles);
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
- FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
- STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
- FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
- FLT_FMT_PREC2_ARGS(5, 3, milliEach),
- FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
- #endif /* HAVE_GET_CYCLES */
- #else
- (void)XSNPRINTF(msg, sizeof(msg),
- "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
- FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
- STATS_CLAUSE_SEPARATOR,
- algo, strength, desc, desc_extra,
- BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
- FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
- FLT_FMT_PREC2_ARGS(5, 3, milliEach),
- FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
- #endif
- }
- #endif /* MULTI_VALUE_STATISTICS */
- printf("%s", msg);
- /* show errors */
- if (ret < 0) {
- printf("%sBenchmark %s %s %d failed: %d\n",
- err_prefix, algo, desc, strength, ret);
- }
- #ifndef WOLFSSL_SGX
- XFFLUSH(stdout);
- #endif
- #ifdef WC_BENCH_TRACK_STATS
- /* Add to thread stats */
- bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
- kOpsSec, ret);
- #endif
- (void)useDeviceID;
- (void)ret;
- #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
- RESTORE_VECTOR_REGISTERS();
- #endif
- TEST_SLEEP();
- } /* bench_stats_asym_finish_ex */
- static void bench_stats_asym_finish(const char* algo, int strength,
- const char* desc, int useDeviceID, int count, double start, int ret)
- {
- bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
- start, ret);
- }
- #endif
- #endif /* BENCH_ASYM */
- static WC_INLINE void bench_stats_free(void)
- {
- #ifdef WC_BENCH_TRACK_STATS
- bench_stats_t* bstat;
- for (bstat = bench_stats_head; bstat != NULL; ) {
- bench_stats_t* next = bstat->next;
- XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
- bstat = next;
- }
- bench_stats_head = NULL;
- bench_stats_tail = NULL;
- #endif
- }
- /*****************************************************************************/
- /* End Stats Functions */
- /*****************************************************************************/
- static void* benchmarks_do(void* args)
- {
- long bench_buf_size;
- #ifdef WOLFSSL_ASYNC_CRYPT
- #ifndef WC_NO_ASYNC_THREADING
- ThreadData* threadData = (ThreadData*)args;
- if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
- #else
- if (wolfAsync_DevOpen(&devId) < 0)
- #endif
- {
- printf("%sAsync device open failed\n%sRunning without async\n",
- err_prefix, err_prefix);
- }
- #endif /* WOLFSSL_ASYNC_CRYPT */
- (void)args;
- #ifdef WOLFSSL_ASYNC_CRYPT
- if (wolfEventQueue_Init(&eventQueue) != 0) {
- printf("%sAsync event queue init failure!\n", err_prefix);
- }
- #endif
- #ifdef WOLF_CRYPTO_CB
- #ifdef HAVE_INTEL_QA_SYNC
- devId = wc_CryptoCb_InitIntelQa();
- if (devId == INVALID_DEVID) {
- printf("%sCouldn't init the Intel QA\n", err_prefix);
- }
- #endif
- #ifdef HAVE_CAVIUM_OCTEON_SYNC
- devId = wc_CryptoCb_InitOcteon();
- if (devId == INVALID_DEVID) {
- printf("%sCouldn't get the Octeon device ID\n", err_prefix);
- }
- #endif
- #ifdef HAVE_RENESAS_SYNC
- devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
- if (devId == INVALID_DEVID) {
- printf("%sCouldn't get the Renesas device ID\n", err_prefix);
- }
- #endif
- #endif
- #if defined(HAVE_LOCAL_RNG)
- {
- int rngRet;
- #ifndef HAVE_FIPS
- rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
- #else
- rngRet = wc_InitRng(&gRng);
- #endif
- if (rngRet < 0) {
- printf("%sInitRNG failed\n", err_prefix);
- return NULL;
- }
- }
- #endif
- /* setup bench plain, cipher, key and iv globals */
- /* make sure bench buffer is multiple of 16 (AES block size) */
- bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
- if (bench_buf_size % 16)
- bench_buf_size += 16 - (bench_buf_size % 16);
- #ifdef WOLFSSL_AFALG_XILINX_AES
- bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
- bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
- #else
- bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
- HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
- HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- #endif
- if (bench_plain == NULL || bench_cipher == NULL) {
- XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- bench_plain = bench_cipher = NULL;
- printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
- goto exit;
- }
- #ifndef NO_FILESYSTEM
- if (hash_input) {
- size_t rawSz;
- XFILE file;
- file = XFOPEN(hash_input, "rb");
- if (file == XBADFILE)
- goto exit;
- if (XFSEEK(file, 0, XSEEK_END) != 0) {
- XFCLOSE(file);
- goto exit;
- }
- bench_buf_size = XFTELL(file);
- if(XFSEEK(file, 0, XSEEK_SET) != 0) {
- XFCLOSE(file);
- goto exit;
- }
- XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- rawSz = (size_t)bench_buf_size;
- if (bench_buf_size % 16)
- bench_buf_size += 16 - (bench_buf_size % 16);
- bench_size = (word32)bench_buf_size;
- bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
- HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- if (bench_plain == NULL) {
- XFCLOSE(file);
- goto exit;
- }
- if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
- != rawSz) {
- XFCLOSE(file);
- goto exit;
- }
- XFCLOSE(file);
- }
- else {
- XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
- }
- if (cipher_input) {
- size_t rawSz;
- XFILE file;
- file = XFOPEN(cipher_input, "rb");
- if (file == XBADFILE)
- goto exit;
- if (XFSEEK(file, 0, XSEEK_END) != 0) {
- XFCLOSE(file);
- goto exit;
- }
- bench_buf_size = XFTELL(file);
- if(XFSEEK(file, 0, XSEEK_SET) != 0) {
- XFCLOSE(file);
- goto exit;
- }
- XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- rawSz = (size_t)bench_buf_size;
- if (bench_buf_size % 16)
- bench_buf_size += 16 - (bench_buf_size % 16);
- if (bench_size > (word32)bench_buf_size)
- bench_size = (word32)bench_buf_size;
- bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
- HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- if (bench_cipher == NULL) {
- XFCLOSE(file);
- goto exit;
- }
- if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
- != rawSz) {
- XFCLOSE(file);
- goto exit;
- }
- XFCLOSE(file);
- }
- else {
- XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
- }
- #endif
- #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
- bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
- HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
- HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- if (bench_key == NULL || bench_iv == NULL) {
- XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- bench_key = bench_iv = NULL;
- printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
- goto exit;
- }
- XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
- XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
- #elif defined(HAVE_RENESAS_SYNC)
- bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
- bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
- bench_key = (byte*)bench_key_buf;
- bench_iv = (byte*)bench_iv_buf;
- #else
- bench_key = (byte*)bench_key_buf;
- bench_iv = (byte*)bench_iv_buf;
- #endif
- #ifndef WC_NO_RNG
- if (bench_all || (bench_other_algs & BENCH_RNG))
- bench_rng();
- #endif /* WC_NO_RNG */
- #ifndef NO_AES
- #ifdef HAVE_AES_CBC
- if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
- #ifndef NO_SW_BENCH
- bench_aescbc(0);
- #endif
- #if defined(BENCH_DEVID)
- bench_aescbc(1);
- #endif
- }
- #endif
- #ifdef HAVE_AESGCM
- if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
- #ifndef NO_SW_BENCH
- bench_aes_aad_options_wrap(bench_aesgcm, 0);
- #endif
- #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
- defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
- defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
- ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
- defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
- bench_aes_aad_options_wrap(bench_aesgcm, 1);
- #endif
- #ifndef NO_SW_BENCH
- bench_gmac(0);
- #endif
- #if defined(BENCH_DEVID)
- bench_gmac(1);
- #endif
- }
- #endif
- #ifdef HAVE_AES_ECB
- if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
- #ifndef NO_SW_BENCH
- bench_aesecb(0);
- #endif
- #ifdef BENCH_DEVID
- bench_aesecb(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_AES_XTS
- if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
- bench_aesxts();
- #endif
- #ifdef WOLFSSL_AES_CFB
- if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
- bench_aescfb();
- #endif
- #ifdef WOLFSSL_AES_OFB
- if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
- bench_aesofb();
- #endif
- #ifdef WOLFSSL_AES_COUNTER
- if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
- bench_aesctr(0);
- #ifdef BENCH_DEVID
- bench_aesctr(1);
- #endif
- }
- #endif
- #ifdef HAVE_AESCCM
- if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
- bench_aes_aad_options_wrap(bench_aesccm, 0);
- #ifdef BENCH_DEVID
- bench_aes_aad_options_wrap(bench_aesccm, 1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_AES_SIV
- if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
- bench_aessiv();
- #endif
- #endif /* !NO_AES */
- #ifdef HAVE_CAMELLIA
- if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
- bench_camellia();
- #endif
- #ifdef WOLFSSL_SM4_CBC
- if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
- bench_sm4_cbc();
- #endif
- #ifdef WOLFSSL_SM4_GCM
- if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
- bench_sm4_gcm();
- #endif
- #ifdef WOLFSSL_SM4_CCM
- if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
- bench_sm4_ccm();
- #endif
- #ifndef NO_RC4
- if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
- #ifndef NO_SW_BENCH
- bench_arc4(0);
- #endif
- #ifdef BENCH_DEVID
- bench_arc4(1);
- #endif
- }
- #endif
- #ifdef HAVE_CHACHA
- if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
- bench_chacha();
- #endif
- #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
- if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
- bench_chacha20_poly1305_aead();
- #endif
- #ifndef NO_DES3
- if (bench_all || (bench_cipher_algs & BENCH_DES)) {
- #ifndef NO_SW_BENCH
- bench_des(0);
- #endif
- #ifdef BENCH_DEVID
- bench_des(1);
- #endif
- }
- #endif
- #ifndef NO_MD5
- if (bench_all || (bench_digest_algs & BENCH_MD5)) {
- #ifndef NO_SW_BENCH
- bench_md5(0);
- #endif
- #ifdef BENCH_DEVID
- bench_md5(1);
- #endif
- }
- #endif
- #ifdef HAVE_POLY1305
- if (bench_all || (bench_digest_algs & BENCH_POLY1305))
- bench_poly1305();
- #endif
- #ifndef NO_SHA
- if (bench_all || (bench_digest_algs & BENCH_SHA)) {
- #ifndef NO_SW_BENCH
- bench_sha(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SHA224
- if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
- #ifndef NO_SW_BENCH
- bench_sha224(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha224(1);
- #endif
- }
- #endif
- #ifndef NO_SHA256
- if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
- #ifndef NO_SW_BENCH
- bench_sha256(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha256(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SHA384
- if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
- #ifndef NO_SW_BENCH
- bench_sha384(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha384(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SHA512
- if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
- #ifndef NO_SW_BENCH
- bench_sha512(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha512(1);
- #endif
- }
- #if !defined(WOLFSSL_NOSHA512_224) && \
- (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
- if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
- #ifndef NO_SW_BENCH
- bench_sha512_224(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha512_224(1);
- #endif
- }
- #endif /* WOLFSSL_NOSHA512_224 */
- #if !defined(WOLFSSL_NOSHA512_256) && \
- (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
- if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
- #ifndef NO_SW_BENCH
- bench_sha512_256(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha512_256(1);
- #endif
- }
- #endif /* WOLFSSL_NOSHA512_256 */
- #endif /* WOLFSSL_SHA512 */
- #ifdef WOLFSSL_SHA3
- #ifndef WOLFSSL_NOSHA3_224
- if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
- #ifndef NO_SW_BENCH
- bench_sha3_224(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha3_224(1);
- #endif
- }
- #endif /* WOLFSSL_NOSHA3_224 */
- #ifndef WOLFSSL_NOSHA3_256
- if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
- #ifndef NO_SW_BENCH
- bench_sha3_256(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha3_256(1);
- #endif
- }
- #endif /* WOLFSSL_NOSHA3_256 */
- #ifndef WOLFSSL_NOSHA3_384
- if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
- #ifndef NO_SW_BENCH
- bench_sha3_384(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha3_384(1);
- #endif
- }
- #endif /* WOLFSSL_NOSHA3_384 */
- #ifndef WOLFSSL_NOSHA3_512
- if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
- #ifndef NO_SW_BENCH
- bench_sha3_512(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sha3_512(1);
- #endif
- }
- #endif /* WOLFSSL_NOSHA3_512 */
- #ifdef WOLFSSL_SHAKE128
- if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
- #ifndef NO_SW_BENCH
- bench_shake128(0);
- #endif
- #ifdef BENCH_DEVID
- bench_shake128(1);
- #endif
- }
- #endif /* WOLFSSL_SHAKE128 */
- #ifdef WOLFSSL_SHAKE256
- if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
- #ifndef NO_SW_BENCH
- bench_shake256(0);
- #endif
- #ifdef BENCH_DEVID
- bench_shake256(1);
- #endif
- }
- #endif /* WOLFSSL_SHAKE256 */
- #endif
- #ifdef WOLFSSL_SM3
- if (bench_all || (bench_digest_algs & BENCH_SM3)) {
- #ifndef NO_SW_BENCH
- bench_sm3(0);
- #endif
- #ifdef BENCH_DEVID
- bench_sm3(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_RIPEMD
- if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
- bench_ripemd();
- #endif
- #ifdef HAVE_BLAKE2
- if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
- bench_blake2b();
- #endif
- #ifdef HAVE_BLAKE2S
- if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
- bench_blake2s();
- #endif
- #ifdef WOLFSSL_CMAC
- if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
- bench_cmac(0);
- #ifdef BENCH_DEVID
- bench_cmac(1);
- #endif
- }
- #endif
- #ifndef NO_HMAC
- #ifndef NO_MD5
- if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
- #ifndef NO_SW_BENCH
- bench_hmac_md5(0);
- #endif
- #ifdef BENCH_DEVID
- bench_hmac_md5(1);
- #endif
- }
- #endif
- #ifndef NO_SHA
- if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
- #ifndef NO_SW_BENCH
- bench_hmac_sha(0);
- #endif
- #ifdef BENCH_DEVID
- bench_hmac_sha(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SHA224
- if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
- #ifndef NO_SW_BENCH
- bench_hmac_sha224(0);
- #endif
- #ifdef BENCH_DEVID
- bench_hmac_sha224(1);
- #endif
- }
- #endif
- #ifndef NO_SHA256
- if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
- #ifndef NO_SW_BENCH
- bench_hmac_sha256(0);
- #endif
- #ifdef BENCH_DEVID
- bench_hmac_sha256(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SHA384
- if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
- #ifndef NO_SW_BENCH
- bench_hmac_sha384(0);
- #endif
- #ifdef BENCH_DEVID
- bench_hmac_sha384(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SHA512
- if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
- #ifndef NO_SW_BENCH
- bench_hmac_sha512(0);
- #endif
- #ifdef BENCH_DEVID
- bench_hmac_sha512(1);
- #endif
- }
- #endif
- #ifndef NO_PWDBASED
- if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
- bench_pbkdf2();
- }
- #endif
- #endif /* NO_HMAC */
- #ifdef WOLFSSL_SIPHASH
- if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
- bench_siphash();
- }
- #endif
- #ifdef WC_SRTP_KDF
- if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
- bench_srtpkdf();
- }
- #endif
- #ifdef HAVE_SCRYPT
- if (bench_all || (bench_other_algs & BENCH_SCRYPT))
- bench_scrypt();
- #endif
- #ifndef NO_RSA
- #ifndef HAVE_RENESAS_SYNC
- #ifdef WOLFSSL_KEY_GEN
- if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
- #ifndef NO_SW_BENCH
- if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
- (bench_asym_algs & BENCH_RSA_SZ) == 0) {
- bench_rsaKeyGen(0);
- }
- else {
- bench_rsaKeyGen_size(0, bench_size);
- }
- #endif
- #ifdef BENCH_DEVID
- if (bench_asym_algs & BENCH_RSA_SZ) {
- bench_rsaKeyGen_size(1, bench_size);
- }
- else {
- bench_rsaKeyGen(1);
- }
- #endif
- }
- #endif
- if (bench_all || (bench_asym_algs & BENCH_RSA)) {
- #ifndef NO_SW_BENCH
- bench_rsa(0);
- #endif
- #ifdef BENCH_DEVID
- bench_rsa(1);
- #endif
- }
- #ifdef WOLFSSL_KEY_GEN
- if (bench_asym_algs & BENCH_RSA_SZ) {
- #ifndef NO_SW_BENCH
- bench_rsa_key(0, bench_size);
- #endif
- #ifdef BENCH_DEVID
- bench_rsa_key(1, bench_size);
- #endif
- }
- #endif
- #endif
- #endif
- #ifndef NO_DH
- if (bench_all || (bench_asym_algs & BENCH_DH)) {
- #ifndef NO_SW_BENCH
- bench_dh(0);
- #endif
- #ifdef BENCH_DEVID
- bench_dh(1);
- #endif
- }
- #endif
- #ifdef WOLFSSL_HAVE_KYBER
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
- #ifndef WOLFSSL_NO_ML_KEM
- #ifdef WOLFSSL_KYBER512
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
- bench_kyber(WC_ML_KEM_512);
- }
- #endif
- #ifdef WOLFSSL_KYBER768
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
- bench_kyber(WC_ML_KEM_768);
- }
- #endif
- #ifdef WOLFSSL_KYBER1024
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
- bench_kyber(WC_ML_KEM_1024);
- }
- #endif
- #endif
- #ifdef WOLFSSL_KYBER_ORIGINAL
- #ifdef WOLFSSL_KYBER512
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
- bench_kyber(KYBER512);
- }
- #endif
- #ifdef WOLFSSL_KYBER768
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
- bench_kyber(KYBER768);
- }
- #endif
- #ifdef WOLFSSL_KYBER1024
- if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
- bench_kyber(KYBER1024);
- }
- #endif
- #endif
- }
- #endif
- #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
- if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
- bench_lms();
- }
- #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
- #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
- if (bench_all) {
- bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
- }
- #ifndef NO_SHA256
- if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
- bench_xmss(WC_HASH_TYPE_SHA256);
- }
- #endif
- #ifdef WOLFSSL_SHA512
- if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
- bench_xmss(WC_HASH_TYPE_SHA512);
- }
- #endif
- #ifdef WOLFSSL_SHAKE128
- if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
- bench_xmss(WC_HASH_TYPE_SHAKE128);
- }
- #endif
- #ifdef WOLFSSL_SHAKE256
- if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
- bench_xmss(WC_HASH_TYPE_SHAKE256);
- }
- #endif
- #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
- #ifdef HAVE_ECC
- if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
- (bench_asym_algs & BENCH_ECC) ||
- (bench_asym_algs & BENCH_ECC_ALL) ||
- (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
- if (bench_asym_algs & BENCH_ECC_ALL) {
- #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
- printf("%snot supported in FIPS mode (no ending enum value)\n",
- err_prefix);
- #else
- int curveId = (int)ECC_SECP192R1;
- /* set make key and encrypt */
- bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
- BENCH_ECC_ENCRYPT;
- if (csv_format != 1) {
- printf("\n%sECC Benchmarks:\n", info_prefix);
- }
- do {
- #ifdef WOLFCRYPT_HAVE_SAKKE
- /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
- if (curveId == ECC_SAKKE_1) {
- curveId++;
- continue;
- }
- #endif
- if (wc_ecc_get_curve_size_from_id(curveId) !=
- WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
- bench_ecc_curve(curveId);
- if (csv_format != 1) {
- printf("\n");
- }
- }
- curveId++;
- } while (curveId != (int)ECC_CURVE_MAX);
- #endif
- }
- else if (bench_asym_algs & BENCH_ECC_P256) {
- bench_ecc_curve((int)ECC_SECP256R1);
- }
- else if (bench_asym_algs & BENCH_ECC_P384) {
- bench_ecc_curve((int)ECC_SECP384R1);
- }
- else if (bench_asym_algs & BENCH_ECC_P521) {
- bench_ecc_curve((int)ECC_SECP521R1);
- }
- else {
- #ifndef NO_ECC256
- bench_ecc_curve((int)ECC_SECP256R1);
- #elif defined(HAVE_ECC384)
- bench_ecc_curve((int)ECC_SECP384R1);
- #elif defined(HAVE_ECC521)
- bench_ecc_curve((int)ECC_SECP521R1);
- #endif
- #ifdef HAVE_ECC_BRAINPOOL
- bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
- #endif
- }
- }
- #endif
- #ifdef WOLFSSL_SM2
- if (bench_all || (bench_asym_algs & BENCH_SM2)) {
- bench_sm2(0);
- }
- #endif
- #ifdef HAVE_CURVE25519
- if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
- bench_curve25519KeyGen(0);
- #ifdef BENCH_DEVID
- bench_curve25519KeyGen(1);
- #endif
- }
- #ifdef HAVE_CURVE25519_SHARED_SECRET
- if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
- bench_curve25519KeyAgree(0);
- #ifdef BENCH_DEVID
- bench_curve25519KeyAgree(1);
- #endif
- }
- #endif
- #endif
- #ifdef HAVE_ED25519
- if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
- bench_ed25519KeyGen();
- if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
- bench_ed25519KeySign();
- #endif
- #ifdef HAVE_CURVE448
- if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
- bench_curve448KeyGen();
- #ifdef HAVE_CURVE448_SHARED_SECRET
- if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
- bench_curve448KeyAgree();
- #endif
- #endif
- #ifdef HAVE_ED448
- if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
- bench_ed448KeyGen();
- if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
- bench_ed448KeySign();
- #endif
- #ifdef WOLFCRYPT_HAVE_ECCSI
- #ifdef WOLFCRYPT_ECCSI_KMS
- if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
- bench_eccsiKeyGen();
- }
- if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
- bench_eccsiPairGen();
- }
- #endif
- #ifdef WOLFCRYPT_ECCSI_CLIENT
- if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
- bench_eccsiValidate();
- }
- if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
- bench_eccsi();
- }
- #endif
- #endif
- #ifdef WOLFCRYPT_HAVE_SAKKE
- #ifdef WOLFCRYPT_SAKKE_KMS
- if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
- bench_sakkeKeyGen();
- }
- if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
- bench_sakkeRskGen();
- }
- #endif
- #ifdef WOLFCRYPT_SAKKE_CLIENT
- if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
- bench_sakkeValidate();
- }
- if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
- bench_sakke();
- }
- #endif
- #endif
- #ifdef HAVE_FALCON
- if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
- bench_falconKeySign(1);
- if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
- bench_falconKeySign(5);
- #endif
- #ifdef HAVE_DILITHIUM
- #ifndef WOLFSSL_NO_ML_DSA_44
- if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
- bench_dilithiumKeySign(2);
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_65
- if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
- bench_dilithiumKeySign(3);
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_87
- if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
- bench_dilithiumKeySign(5);
- #endif
- #endif
- #ifdef HAVE_SPHINCS
- if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
- bench_sphincsKeySign(1, FAST_VARIANT);
- if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
- bench_sphincsKeySign(3, FAST_VARIANT);
- if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
- bench_sphincsKeySign(5, FAST_VARIANT);
- if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
- bench_sphincsKeySign(1, SMALL_VARIANT);
- if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
- bench_sphincsKeySign(3, SMALL_VARIANT);
- if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
- bench_sphincsKeySign(5, SMALL_VARIANT);
- #endif
- exit:
- /* free benchmark buffers */
- XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- #ifdef WOLFSSL_ASYNC_CRYPT
- XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
- #endif
- #if defined(HAVE_LOCAL_RNG)
- wc_FreeRng(&gRng);
- #endif
- /* cleanup the thread if fixed point cache is enabled and have thread local */
- #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
- wc_ecc_fp_free();
- #endif
- (void)bench_cipher_algs;
- (void)bench_digest_algs;
- (void)bench_mac_algs;
- (void)bench_asym_algs;
- (void)bench_other_algs;
- (void)bench_pq_asym_algs;
- (void)bench_pq_asym_algs2;
- return NULL;
- }
- int benchmark_init(void)
- {
- int ret = 0;
- benchmark_static_init(0);
- #ifdef WOLFSSL_STATIC_MEMORY
- ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
- sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
- if (ret != 0) {
- printf("%sunable to load static memory %d\n", err_prefix, ret);
- }
- #endif /* WOLFSSL_STATIC_MEMORY */
- if ((ret = wolfCrypt_Init()) != 0) {
- printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
- return EXIT_FAILURE;
- }
- #ifdef HAVE_WC_INTROSPECTION
- printf("Math: %s\n", wc_GetMathInfo());
- #endif
- #ifdef WOLFSSL_SECO_CAAM
- if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
- SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
- != 0) {
- printf("%sunable to open HSM\n", err_prefix);
- wolfCrypt_Cleanup();
- return EXIT_FAILURE;
- }
- #endif
- #ifdef WC_RNG_SEED_CB
- wc_SetSeed_Cb(wc_GenerateSeed);
- #endif
- bench_stats_init();
- #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
- wolfSSL_Debugging_ON();
- #endif
- printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
- info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
- #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
- if (csv_format == 1) {
- printf("This format allows you to easily copy "
- "the output to a csv file.");
- }
- #endif
- #ifdef HAVE_WNR
- ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
- if (ret != 0) {
- printf("%sWhitewood netRandom config init failed %d\n",
- err_prefix, ret);
- }
- #endif /* HAVE_WNR */
- return ret;
- }
- int benchmark_free(void)
- {
- int ret;
- #ifdef WC_BENCH_TRACK_STATS
- if (gPrintStats || devId != INVALID_DEVID) {
- bench_stats_print();
- }
- #endif
- bench_stats_free();
- #ifdef WOLF_CRYPTO_CB
- #ifdef HAVE_INTEL_QA_SYNC
- wc_CryptoCb_CleanupIntelQa(&devId);
- #endif
- #ifdef HAVE_CAVIUM_OCTEON_SYNC
- wc_CryptoCb_CleanupOcteon(&devId);
- #endif
- #ifdef HAVE_RENESAS_SYNC
- wc_CryptoCb_CleanupRenesasCmn(&devId);
- #endif
- #endif
- #ifdef WOLFSSL_ASYNC_CRYPT
- /* free event queue */
- wolfEventQueue_Free(&eventQueue);
- /* close device */
- wolfAsync_DevClose(&devId);
- #endif
- #ifdef HAVE_WNR
- ret = wc_FreeNetRandom();
- if (ret < 0) {
- printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
- }
- #endif
- #ifdef WOLFSSL_SECO_CAAM
- if (wc_SECO_CloseHSM() != 0) {
- printf("%sError closing down the key store\n", err_prefix);
- }
- #endif
- if ((ret = wolfCrypt_Cleanup()) != 0) {
- printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
- }
- return ret;
- }
- #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
- static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
- {
- benchmark_test(args);
- EXIT_TEST(0);
- }
- static int benchmark_test_threaded(void* args)
- {
- int i;
- printf("%sThreads: %d\n", info_prefix, g_threadCount);
- g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
- HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (g_threadData == NULL) {
- printf("%sThread data alloc failed!\n", err_prefix);
- return EXIT_FAILURE;
- }
- for (i = 0; i < g_threadCount; i++) {
- THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
- NULL, run_bench, args));
- }
- for (i = 0; i < g_threadCount; i++) {
- THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
- }
- printf("\n");
- bench_stats_print();
- return 0;
- }
- #endif
- /* so embedded projects can pull in tests on their own */
- #ifdef HAVE_STACK_SIZE
- THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
- #else
- int benchmark_test(void *args)
- #endif
- {
- int ret;
- (void)args;
- #ifdef HAVE_FIPS
- wolfCrypt_SetCb_fips(myFipsCb);
- #endif
- ret = benchmark_init();
- if (ret != 0)
- EXIT_TEST(ret);
- #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
- {
- /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
- **
- ** Chapter Two, Build Options:
- **
- ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
- **
- ** asynchronous cryptography using hardware based adapters such as
- ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
- */
- int i;
- if (g_threadCount == 0) {
- #ifdef WC_ASYNC_BENCH_THREAD_COUNT
- g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
- #else
- g_threadCount = wc_AsyncGetNumberOfCpus();
- if (g_threadCount > 0) {
- g_threadCount /= 2; /* use physical core count */
- }
- #endif
- }
- if (g_threadCount <= 0) {
- g_threadCount = 1;
- }
- printf("%sCPUs: %d\n", info_prefix, g_threadCount);
- g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
- HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (g_threadData == NULL) {
- printf("%sThread data alloc failed!\n", err_prefix);
- EXIT_TEST(EXIT_FAILURE);
- }
- /* Create threads */
- for (i = 0; i < g_threadCount; i++) {
- ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
- benchmarks_do, &g_threadData[i]);
- if (ret != 0) {
- printf("%sError creating benchmark thread %d\n", err_prefix, ret);
- EXIT_TEST(EXIT_FAILURE);
- }
- }
- /* Start threads */
- for (i = 0; i < g_threadCount; i++) {
- wc_AsyncThreadJoin(&g_threadData[i].thread_id);
- }
- XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- }
- #else
- benchmarks_do(NULL);
- #endif
- SLEEP_ON_ERROR(1);
- printf("%sBenchmark complete\n", info_prefix);
- ret = benchmark_free();
- EXIT_TEST(ret);
- }
- #ifndef WC_NO_RNG
- void bench_rng(void)
- {
- int ret, i, count;
- double start;
- long pos, len, remain;
- WC_RNG myrng;
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifndef HAVE_FIPS
- ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
- #else
- ret = wc_InitRng(&myrng);
- #endif
- if (ret < 0) {
- printf("InitRNG failed %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- /* Split request to handle large RNG request */
- pos = 0;
- remain = (int)bench_size;
- while (remain > 0) {
- len = remain;
- if (len > RNG_MAX_BLOCK_LEN)
- len = RNG_MAX_BLOCK_LEN;
- ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
- (word32)len);
- if (ret < 0)
- goto exit_rng;
- remain -= len;
- pos += len;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_rng:
- bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeRng(&myrng);
- }
- #endif /* WC_NO_RNG */
- #ifndef NO_AES
- #ifdef HAVE_AES_CBC
- static void bench_aescbc_internal(int useDeviceID,
- const byte* key, word32 keySz,
- const byte* iv, const char* encLabel,
- const char* decLabel)
- {
- const byte* in = bench_cipher;
- byte* out = bench_plain;
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_AesInit(enc[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID)) != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- goto exit;
- }
- ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
- if (ret != 0) {
- printf("AesSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- if (cipher_same_buffer) {
- in = bench_plain;
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_aes_enc;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_enc:
- bench_stats_sym_finish(encLabel, useDeviceID, count,
- bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret < 0) {
- goto exit;
- }
- #ifdef HAVE_AES_DECRYPT
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
- if (ret != 0) {
- printf("AesSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_aes_dec;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_dec:
- bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_AES_DECRYPT */
- (void)decLabel;
- exit:
- if (WC_ARRAY_OK(enc)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_AesFree(enc[i]);
- }
- WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- void bench_aescbc(int useDeviceID)
- {
- #ifdef WOLFSSL_AES_128
- #ifdef HAVE_RENESAS_SYNC
- bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
- "AES-128-CBC-enc", "AES-128-CBC-dec");
- #else
- bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
- "AES-128-CBC-enc", "AES-128-CBC-dec");
- #endif
- #endif
- #ifdef WOLFSSL_AES_192
- bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
- "AES-192-CBC-enc", "AES-192-CBC-dec");
- #endif
- #ifdef WOLFSSL_AES_256
- #ifdef HAVE_RENESAS_SYNC
- bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
- "AES-256-CBC-enc", "AES-256-CBC-dec");
- #else
- bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
- "AES-256-CBC-enc", "AES-256-CBC-dec");
- #endif
- #endif
- }
- #endif /* HAVE_AES_CBC */
- #ifdef HAVE_AESGCM
- static void bench_aesgcm_internal(int useDeviceID,
- const byte* key, word32 keySz,
- const byte* iv, word32 ivSz,
- const char* encLabel, const char* decLabel)
- {
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #ifdef HAVE_AES_DECRYPT
- WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #endif
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #ifdef HAVE_AES_DECRYPT
- WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #endif
- XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
- XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_AesInit(enc[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID)) != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- goto exit;
- }
- ret = wc_AesGcmSetKey(enc[i], key, keySz);
- if (ret != 0) {
- printf("AesGcmSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- /* GCM uses same routine in backend for both encrypt and decrypt */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
- bench_plain, bench_size,
- iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
- bench_additional, aesAuthAddSz);
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_aes_gcm;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_gcm:
- bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #ifdef HAVE_AES_DECRYPT
- RESET_MULTI_VALUE_STATS_VARS();
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_AesInit(dec[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID)) != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- goto exit;
- }
- ret = wc_AesGcmSetKey(dec[i], key, keySz);
- if (ret != 0) {
- printf("AesGcmSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_AesGcmDecrypt(dec[i], bench_plain,
- bench_cipher, bench_size,
- iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
- bench_additional, aesAuthAddSz);
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
- 0, ×, &pending)) {
- goto exit_aes_gcm_dec;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_gcm_dec:
- bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_AES_DECRYPT */
- (void)decLabel;
- exit:
- if (ret < 0) {
- printf("bench_aesgcm failed: %d\n", ret);
- }
- #ifdef HAVE_AES_DECRYPT
- if (WC_ARRAY_OK(dec)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_AesFree(dec[i]);
- }
- WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- if (WC_ARRAY_OK(enc)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_AesFree(enc[i]);
- }
- WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_VAR(bench_additional, HEAP_HINT);
- WC_FREE_VAR(bench_tag, HEAP_HINT);
- }
- #ifdef WOLFSSL_AESGCM_STREAM
- static void bench_aesgcm_stream_internal(int useDeviceID,
- const byte* key, word32 keySz, const byte* iv, word32 ivSz,
- const char* encLabel, const char* decLabel)
- {
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #ifdef HAVE_AES_DECRYPT
- WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #endif
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #ifdef HAVE_AES_DECRYPT
- WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- #endif
- XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
- XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_AesInit(enc[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID)) != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- goto exit;
- }
- ret = wc_AesGcmSetKey(enc[i], key, keySz);
- if (ret != 0) {
- printf("AesGcmSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- /* GCM uses same routine in backend for both encrypt and decrypt */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
- if (ret == 0) {
- ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
- bench_plain, bench_size, bench_additional,
- aesAuthAddSz);
- }
- if (ret == 0) {
- ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
- AES_AUTH_TAG_SZ);
- }
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_aes_gcm;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_gcm:
- bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #ifdef HAVE_AES_DECRYPT
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_AesInit(dec[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID)) != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- goto exit;
- }
- ret = wc_AesGcmSetKey(dec[i], key, keySz);
- if (ret != 0) {
- printf("AesGcmSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
- if (ret == 0) {
- ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
- bench_cipher, bench_size, bench_additional,
- aesAuthAddSz);
- }
- if (ret == 0) {
- ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
- AES_AUTH_TAG_SZ);
- }
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
- 0, ×, &pending)) {
- goto exit_aes_gcm_dec;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_gcm_dec:
- bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_AES_DECRYPT */
- (void)decLabel;
- exit:
- if (ret < 0) {
- printf("bench_aesgcm failed: %d\n", ret);
- }
- #ifdef HAVE_AES_DECRYPT
- if (WC_ARRAY_OK(dec)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_AesFree(dec[i]);
- }
- WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- if (WC_ARRAY_OK(enc)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_AesFree(enc[i]);
- }
- WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_VAR(bench_additional, HEAP_HINT);
- WC_FREE_VAR(bench_tag, HEAP_HINT);
- }
- #endif
- void bench_aesgcm(int useDeviceID)
- {
- #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
- #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
- && !defined(WOLFSSL_XILINX_CRYPT) \
- || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
- #ifdef HAVE_RENESAS_SYNC
- bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
- AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
- #else
- bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
- AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
- #endif
- #endif
- #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
- && !defined(WOLFSSL_XILINX_CRYPT)
- bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
- AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
- #endif
- #ifdef WOLFSSL_AES_256
- #ifdef HAVE_RENESAS_SYNC
- bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
- AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
- #else
- bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
- AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
- #endif
- #endif
- #ifdef WOLFSSL_AESGCM_STREAM
- #undef AES_GCM_STRING
- #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
- #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
- && !defined(WOLFSSL_XILINX_CRYPT) \
- || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
- bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
- AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
- #endif
- #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
- && !defined(WOLFSSL_XILINX_CRYPT)
- bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
- AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
- #endif
- #ifdef WOLFSSL_AES_256
- bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
- AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
- #endif
- #endif /* WOLFSSL_AESGCM_STREAM */
- #undef AES_GCM_STRING
- }
- /* GMAC */
- void bench_gmac(int useDeviceID)
- {
- int ret, count = 0;
- Gmac gmac;
- double start;
- byte tag[AES_AUTH_TAG_SZ];
- DECLARE_MULTI_VALUE_STATS_VARS()
- /* determine GCM GHASH method */
- #ifdef GCM_SMALL
- const char* gmacStr = "GMAC Small";
- #elif defined(GCM_TABLE)
- const char* gmacStr = "GMAC Table";
- #elif defined(GCM_TABLE_4BIT)
- const char* gmacStr = "GMAC Table 4-bit";
- #elif defined(GCM_WORD32)
- const char* gmacStr = "GMAC Word32";
- #else
- const char* gmacStr = "GMAC Default";
- #endif
- /* init keys */
- XMEMSET(bench_plain, 0, bench_size);
- XMEMSET(tag, 0, sizeof(tag));
- XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
- (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID);
- #ifdef HAVE_RENESAS_SYNC
- wc_GmacSetKey(&gmac, bench_key1, 16);
- #else
- wc_GmacSetKey(&gmac, bench_key, 16);
- #endif
- bench_stats_start(&count, &start);
- do {
- ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
- tag, sizeof(tag));
- count++;
- RECORD_MULTI_VALUE_STATS();
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- wc_AesFree((Aes*)&gmac);
- bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif /* HAVE_AESGCM */
- #ifdef HAVE_AES_ECB
- static void bench_aesecb_internal(int useDeviceID,
- const byte* key, word32 keySz,
- const char* encLabel, const char* decLabel)
- {
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifdef HAVE_FIPS
- const word32 benchSz = WC_AES_BLOCK_SIZE;
- #else
- const word32 benchSz = bench_size;
- #endif
- WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
- sizeof(Aes), HEAP_HINT);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_AesInit(enc[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID)) != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- goto exit;
- }
- ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
- if (ret != 0) {
- printf("AesSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
- for (times = 0;
- times < outer_loop_limit /* numBlocks */ || pending > 0;
- ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, outer_loop_limit, &pending)) {
- #ifdef HAVE_FIPS
- wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
- #else
- wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
- benchSz);
- #endif
- ret = 0;
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_aes_enc;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_enc:
- bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #ifdef HAVE_AES_DECRYPT
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
- if (ret != 0) {
- printf("AesSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
- for (times = 0; times < outer_loop_limit || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, outer_loop_limit, &pending)) {
- #ifdef HAVE_FIPS
- wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
- #else
- wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
- benchSz);
- #endif
- ret = 0;
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_aes_dec;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_aes_dec:
- bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_AES_DECRYPT */
- (void)decLabel;
- exit:
- if (WC_ARRAY_OK(enc)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_AesFree(enc[i]);
- }
- WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- void bench_aesecb(int useDeviceID)
- {
- #ifdef WOLFSSL_AES_128
- bench_aesecb_internal(useDeviceID, bench_key, 16,
- "AES-128-ECB-enc", "AES-128-ECB-dec");
- #endif
- #ifdef WOLFSSL_AES_192
- bench_aesecb_internal(useDeviceID, bench_key, 24,
- "AES-192-ECB-enc", "AES-192-ECB-dec");
- #endif
- #ifdef WOLFSSL_AES_256
- bench_aesecb_internal(useDeviceID, bench_key, 32,
- "AES-256-ECB-enc", "AES-256-ECB-dec");
- #endif
- }
- #endif /* HAVE_AES_ECB */
- #ifdef WOLFSSL_AES_CFB
- static void bench_aescfb_internal(const byte* key,
- word32 keySz, const byte* iv,
- const char* label)
- {
- Aes enc;
- double start;
- int i, ret, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
- if (ret != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- return;
- }
- ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
- if (ret != 0) {
- printf("AesSetKey failed, ret = %d\n", ret);
- goto out;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
- bench_size)) != 0) {
- printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
- goto out;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- out:
- wc_AesFree(&enc);
- return;
- }
- void bench_aescfb(void)
- {
- #ifdef WOLFSSL_AES_128
- bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
- #endif
- #ifdef WOLFSSL_AES_192
- bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
- #endif
- #ifdef WOLFSSL_AES_256
- bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
- #endif
- }
- #endif /* WOLFSSL_AES_CFB */
- #ifdef WOLFSSL_AES_OFB
- static void bench_aesofb_internal(const byte* key,
- word32 keySz, const byte* iv,
- const char* label)
- {
- Aes enc;
- double start;
- int i, ret, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
- if (ret != 0) {
- printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
- return;
- }
- ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
- if (ret != 0) {
- printf("AesSetKey failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
- bench_size)) != 0) {
- printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_AesFree(&enc);
- }
- void bench_aesofb(void)
- {
- #ifdef WOLFSSL_AES_128
- bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
- #endif
- #ifdef WOLFSSL_AES_192
- bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
- #endif
- #ifdef WOLFSSL_AES_256
- bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
- #endif
- }
- #endif /* WOLFSSL_AES_CFB */
- #ifdef WOLFSSL_AES_XTS
- void bench_aesxts(void)
- {
- WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
- double start;
- int i, count, ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- static const unsigned char k1[] = {
- 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
- 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
- 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
- 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
- };
- static const unsigned char i1[] = {
- 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
- 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
- };
- WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
- ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
- HEAP_HINT, devId);
- if (ret != 0) {
- printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
- bench_size, i1, sizeof(i1))) != 0) {
- printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_AesXtsFree(aes);
- /* decryption benchmark */
- ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
- HEAP_HINT, devId);
- if (ret != 0) {
- printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
- bench_size, i1, sizeof(i1))) != 0) {
- printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- wc_AesXtsFree(aes);
- WC_FREE_VAR(aes, HEAP_HINT);
- }
- #endif /* WOLFSSL_AES_XTS */
- #ifdef WOLFSSL_AES_COUNTER
- static void bench_aesctr_internal(const byte* key, word32 keySz,
- const byte* iv, const char* label,
- int useDeviceID)
- {
- Aes enc;
- double start;
- int i, count, ret = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- if ((ret = wc_AesInit(&enc, HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID)) != 0) {
- printf("wc_AesInit failed, ret = %d\n", ret);
- }
- if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
- printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
- bench_size)) != 0) {
- printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_AesFree(&enc);
- }
- void bench_aesctr(int useDeviceID)
- {
- #ifdef WOLFSSL_AES_128
- bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
- #endif
- #ifdef WOLFSSL_AES_192
- bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
- #endif
- #ifdef WOLFSSL_AES_256
- bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
- #endif
- }
- #endif /* WOLFSSL_AES_COUNTER */
- #ifdef HAVE_AESCCM
- void bench_aesccm(int useDeviceID)
- {
- Aes enc;
- int enc_inited = 0;
- double start;
- int ret, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
- XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
- if ((ret = wc_AesInit(&enc, HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID)) != 0)
- {
- printf("wc_AesInit failed, ret = %d\n", ret);
- goto exit;
- }
- if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
- printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- enc_inited = 1;
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
- bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
- bench_additional, 0);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
- bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret != 0) {
- printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
- goto exit;
- }
- #ifdef HAVE_AES_DECRYPT
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
- bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
- bench_additional, 0);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
- bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret != 0) {
- printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
- goto exit;
- }
- #endif
- exit:
- if (enc_inited)
- wc_AesFree(&enc);
- WC_FREE_VAR(bench_additional, HEAP_HINT);
- WC_FREE_VAR(bench_tag, HEAP_HINT);
- }
- #endif /* HAVE_AESCCM */
- #ifdef WOLFSSL_AES_SIV
- static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
- encLabel, const char* decLabel)
- {
- int i;
- int ret = 0;
- byte assoc[WC_AES_BLOCK_SIZE];
- byte nonce[WC_AES_BLOCK_SIZE];
- byte siv[WC_AES_BLOCK_SIZE];
- int count = 0;
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
- WC_AES_BLOCK_SIZE, bench_plain, bench_size,
- siv, bench_cipher);
- if (ret != 0) {
- printf("wc_AesSivEncrypt failed (%d)\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
- WC_AES_BLOCK_SIZE, bench_cipher, bench_size,
- siv, bench_plain);
- if (ret != 0) {
- printf("wc_AesSivDecrypt failed (%d)\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- void bench_aessiv(void)
- {
- bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
- bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
- bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
- }
- #endif /* WOLFSSL_AES_SIV */
- #endif /* !NO_AES */
- #ifdef HAVE_POLY1305
- void bench_poly1305(void)
- {
- Poly1305 enc;
- byte mac[16];
- double start;
- int ret = 0, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- if (digest_stream) {
- ret = wc_Poly1305SetKey(&enc, bench_key, 32);
- if (ret != 0) {
- printf("Poly1305SetKey failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
- if (ret != 0) {
- printf("Poly1305Update failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- wc_Poly1305Final(&enc, mac);
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Poly1305SetKey(&enc, bench_key, 32);
- if (ret != 0) {
- printf("Poly1305SetKey failed, ret = %d\n", ret);
- return;
- }
- ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
- if (ret != 0) {
- printf("Poly1305Update failed: %d\n", ret);
- break;
- }
- wc_Poly1305Final(&enc, mac);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif /* HAVE_POLY1305 */
- #ifdef HAVE_CAMELLIA
- void bench_camellia(void)
- {
- wc_Camellia cam;
- double start;
- int ret, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
- if (ret != 0) {
- printf("CamelliaSetKey failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
- bench_size);
- if (ret < 0) {
- printf("CamelliaCbcEncrypt failed: %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SM4_CBC
- void bench_sm4_cbc(void)
- {
- wc_Sm4 sm4;
- double start;
- int ret;
- int i;
- int count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
- if (ret != 0) {
- printf("Sm4SetKey failed, ret = %d\n", ret);
- return;
- }
- ret = wc_Sm4SetIV(&sm4, bench_iv);
- if (ret != 0) {
- printf("Sm4SetIV failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
- if (ret < 0) {
- printf("Sm4CbcEncrypt failed: %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
- if (ret < 0) {
- printf("Sm4CbcDecrypt failed: %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SM4_GCM
- void bench_sm4_gcm(void)
- {
- wc_Sm4 sm4;
- double start;
- int ret;
- int i;
- int count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
- if (ret != 0) {
- printf("Sm4GcmSetKey failed, ret = %d\n", ret);
- goto exit;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
- bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
- bench_additional, aesAuthAddSz);
- if (ret < 0) {
- printf("Sm4GcmEncrypt failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
- bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
- bench_additional, aesAuthAddSz);
- if (ret < 0) {
- printf("Sm4GcmDecrypt failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- WC_FREE_VAR(bench_additional, HEAP_HINT);
- WC_FREE_VAR(bench_tag, HEAP_HINT);
- }
- #endif
- #ifdef WOLFSSL_SM4_CCM
- void bench_sm4_ccm(void)
- {
- wc_Sm4 enc;
- double start;
- int ret, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
- WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
- XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
- XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
- if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
- printf("wc_Sm4SetKey failed, ret = %d\n", ret);
- goto exit;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
- bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
- bench_additional, 0);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret != 0) {
- printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
- goto exit;
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
- bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
- bench_additional, 0);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret != 0) {
- printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
- goto exit;
- }
- exit:
- WC_FREE_VAR(bench_additional, HEAP_HINT);
- WC_FREE_VAR(bench_tag, HEAP_HINT);
- }
- #endif /* HAVE_AESCCM */
- #ifndef NO_DES3
- void bench_des(int useDeviceID)
- {
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
- sizeof(Des3), HEAP_HINT);
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
- sizeof(Des3), HEAP_HINT);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID)) != 0) {
- printf("Des3Init failed, ret = %d\n", ret);
- goto exit;
- }
- ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
- if (ret != 0) {
- printf("Des3_SetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_Des3_CbcEncrypt(enc[i],
- bench_cipher,
- bench_plain, bench_size);
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_3des;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_3des:
- bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(enc)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Des3Free(enc[i]);
- }
- WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- #endif /* !NO_DES3 */
- #ifndef NO_RC4
- void bench_arc4(int useDeviceID)
- {
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
- sizeof(Arc4), HEAP_HINT);
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
- sizeof(Arc4), HEAP_HINT);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID)) != 0) {
- printf("Arc4Init failed, ret = %d\n", ret);
- goto exit;
- }
- ret = wc_Arc4SetKey(enc[i], bench_key, 16);
- if (ret != 0) {
- printf("Arc4SetKey failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
- bench_size);
- if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
- 0, ×, &pending)) {
- goto exit_arc4;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_arc4:
- bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(enc)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Arc4Free(enc[i]);
- }
- WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- #endif /* !NO_RC4 */
- #ifdef HAVE_CHACHA
- void bench_chacha(void)
- {
- WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
- double start;
- int ret, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
- XMEMSET(enc, 0, sizeof(ChaCha));
- wc_Chacha_SetKey(enc, bench_key, 16);
- if (encrypt_only) {
- ret = wc_Chacha_SetIV(enc, bench_iv, 0);
- if (ret < 0) {
- printf("wc_Chacha_SetIV error: %d\n", ret);
- goto exit;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
- bench_size);
- if (ret < 0) {
- printf("wc_Chacha_Process error: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Chacha_SetIV(enc, bench_iv, 0);
- if (ret < 0) {
- printf("wc_Chacha_SetIV error: %d\n", ret);
- goto exit;
- }
- ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
- bench_size);
- if (ret < 0) {
- printf("wc_Chacha_Process error: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- WC_FREE_VAR(enc, HEAP_HINT);
- }
- #endif /* HAVE_CHACHA*/
- #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
- void bench_chacha20_poly1305_aead(void)
- {
- double start;
- int ret = 0, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
- WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
- XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
- bench_plain, bench_size, bench_cipher, authTag);
- if (ret < 0) {
- printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- WC_FREE_VAR(authTag, HEAP_HINT);
- }
- #endif /* HAVE_CHACHA && HAVE_POLY1305 */
- #ifndef NO_MD5
- void bench_md5(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
- sizeof(wc_Md5), HEAP_HINT);
- double start = 0;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_MD5_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
- sizeof(wc_Md5), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_MD5_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitMd5_ex failed, ret = %d\n", ret);
- goto exit;
- }
- #ifdef WOLFSSL_PIC32MZ_HASH
- wc_Md5SizeSet(hash[i], numBlocks * bench_size);
- #endif
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Md5Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, &pending)) {
- goto exit_md5;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Md5Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_md5;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
- if (ret == 0)
- ret = wc_Md5Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Md5Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_md5;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_md5:
- bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- #ifdef WOLFSSL_ASYNC_CRYPT
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Md5Free(hash[i]);
- }
- }
- #endif
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* !NO_MD5 */
- #ifndef NO_SHA
- void bench_sha(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
- sizeof(wc_Sha), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
- sizeof(wc_Sha), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha failed, ret = %d\n", ret);
- goto exit;
- }
- #ifdef WOLFSSL_PIC32MZ_HASH
- wc_ShaSizeSet(hash[i], numBlocks * bench_size);
- #endif
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_ShaUpdate(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_ShaFinal(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_ShaFinal(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha:
- bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_ShaFree(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* NO_SHA */
- #ifdef WOLFSSL_SHA224
- void bench_sha224(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
- sizeof(wc_Sha224), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA224_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
- sizeof(wc_Sha224), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA224_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha224_ex failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha224Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha224;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha224Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha224;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha224Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha224;
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha224:
- bench_stats_sym_finish("SHA-224", useDeviceID, count,
- bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha224Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- #ifndef NO_SHA256
- void bench_sha256(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
- sizeof(wc_Sha256), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA256_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
- sizeof(wc_Sha256), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA256_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha256_ex failed, ret = %d\n", ret);
- goto exit;
- }
- #ifdef WOLFSSL_PIC32MZ_HASH
- wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
- #endif
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha256Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha256;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha256Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha256;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha256Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha256;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha256:
- bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha256Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- #ifdef WOLFSSL_SHA384
- void bench_sha384(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
- sizeof(wc_Sha384), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA384_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
- sizeof(wc_Sha384), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA384_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha384_ex failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha384Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha384;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha384Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha384;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha384Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha384;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha384:
- bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha384Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- #ifdef WOLFSSL_SHA512
- void bench_sha512(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
- sizeof(wc_Sha512), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA512_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
- sizeof(wc_Sha512), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA512_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha512_ex failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha512Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha512;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha512Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha512;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha512Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha512;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha512:
- bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha512Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #if !defined(WOLFSSL_NOSHA512_224) && \
- (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
- void bench_sha512_224(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
- sizeof(wc_Sha512_224), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
- sizeof(wc_Sha512_224), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha512_224_ex failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha512_224Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha512_224;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha512_224Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha512_224;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha512_224Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha512_224;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha512_224:
- bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha512_224Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
- #if !defined(WOLFSSL_NOSHA512_256) && \
- (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
- void bench_sha512_256(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
- sizeof(wc_Sha512_256), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
- sizeof(wc_Sha512_256), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha512_256_ex failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha512_256Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha512_256;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha512_256Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha512_256;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha512_256Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha512_256;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha512_256:
- bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha512_256Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
- #endif /* WOLFSSL_SHA512 */
- #ifdef WOLFSSL_SHA3
- #ifndef WOLFSSL_NOSHA3_224
- void bench_sha3_224(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha3_224(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha3_224 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_224_Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_224;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_224_Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_224;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha3_224(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha3_224_Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha3_224;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha3_224:
- bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha3_224_Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_NOSHA3_224 */
- #ifndef WOLFSSL_NOSHA3_256
- void bench_sha3_256(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- double start;
- DECLARE_MULTI_VALUE_STATS_VARS()
- int ret = 0, i, count = 0, times, pending = 0;
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha3_256(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha3_256 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_256_Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_256;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_256_Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_256;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha3_256(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha3_256_Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha3_256;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha3_256:
- bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha3_256_Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_NOSHA3_256 */
- #ifndef WOLFSSL_NOSHA3_384
- void bench_sha3_384(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha3_384(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha3_384 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_384_Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_384;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_384_Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_384;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha3_384(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha3_384_Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha3_384;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha3_384:
- bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha3_384_Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_NOSHA3_384 */
- #ifndef WOLFSSL_NOSHA3_512
- void bench_sha3_512(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
- sizeof(wc_Sha3), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSha3_512(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitSha3_512 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_512_Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_512;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sha3_512_Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_sha3_512;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSha3_512(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sha3_512_Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sha3_512;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sha3_512:
- bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sha3_512_Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_NOSHA3_512 */
- #ifdef WOLFSSL_SHAKE128
- void bench_shake128(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
- sizeof(wc_Shake), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
- sizeof(wc_Shake), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitShake128(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitShake128 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Shake128_Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_shake128;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Shake128_Final(hash[i], digest[i],
- WC_SHA3_128_BLOCK_SIZE);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_shake128;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitShake128(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Shake128_Final(hash[0], digest[0],
- WC_SHA3_128_BLOCK_SIZE);
- if (ret != 0)
- goto exit_shake128;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_shake128:
- bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Shake128_Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_SHAKE128 */
- #ifdef WOLFSSL_SHAKE256
- void bench_shake256(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
- sizeof(wc_Shake), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
- sizeof(wc_Shake), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitShake256(hash[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("InitShake256 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Shake256_Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_shake256;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Shake256_Final(hash[i], digest[i],
- WC_SHA3_256_BLOCK_SIZE);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0,
- ×, &pending)) {
- goto exit_shake256;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitShake256(hash[0], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret == 0)
- ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Shake256_Final(hash[0], digest[0],
- WC_SHA3_256_BLOCK_SIZE);
- if (ret != 0)
- goto exit_shake256;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_shake256:
- bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Shake256_Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* WOLFSSL_SHAKE256 */
- #endif
- #ifdef WOLFSSL_SM3
- void bench_sm3(int useDeviceID)
- {
- WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
- sizeof(wc_Sm3), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
- HEAP_HINT);
- WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
- sizeof(wc_Sm3), HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
- HEAP_HINT);
- if (digest_stream) {
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_InitSm3(hash[i], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID);
- if (ret != 0) {
- printf("InitSm3 failed, ret = %d\n", ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sm3Update(hash[i], bench_plain,
- bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0, ×, &pending)) {
- goto exit_sm3;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
- 0, ×, numBlocks, &pending)) {
- ret = wc_Sm3Final(hash[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hash[i]), 0, ×, &pending)) {
- goto exit_sm3;
- }
- }
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks; times++) {
- ret = wc_InitSm3(hash[0], HEAP_HINT,
- useDeviceID ? devId: INVALID_DEVID);
- if (ret == 0)
- ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
- if (ret == 0)
- ret = wc_Sm3Final(hash[0], digest[0]);
- if (ret != 0)
- goto exit_sm3;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- exit_sm3:
- bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- if (WC_ARRAY_OK(hash)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_Sm3Free(hash[i]);
- }
- WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- #ifdef WOLFSSL_RIPEMD
- void bench_ripemd(void)
- {
- RipeMd hash;
- byte digest[RIPEMD_DIGEST_SIZE];
- double start;
- int i, count, ret = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- if (digest_stream) {
- ret = wc_InitRipeMd(&hash);
- if (ret != 0) {
- printf("wc_InitRipeMd failed, retval %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
- if (ret != 0) {
- printf("wc_RipeMdUpdate failed, retval %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- ret = wc_RipeMdFinal(&hash, digest);
- if (ret != 0) {
- printf("wc_RipeMdFinal failed, retval %d\n", ret);
- return;
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_InitRipeMd(&hash);
- if (ret != 0) {
- printf("wc_InitRipeMd failed, retval %d\n", ret);
- return;
- }
- ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
- if (ret != 0) {
- printf("wc_RipeMdUpdate failed, retval %d\n", ret);
- return;
- }
- ret = wc_RipeMdFinal(&hash, digest);
- if (ret != 0) {
- printf("wc_RipeMdFinal failed, retval %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- return;
- }
- #endif
- #ifdef HAVE_BLAKE2
- void bench_blake2b(void)
- {
- Blake2b b2b;
- byte digest[64];
- double start;
- int ret = 0, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- if (digest_stream) {
- ret = wc_InitBlake2b(&b2b, 64);
- if (ret != 0) {
- printf("InitBlake2b failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
- if (ret != 0) {
- printf("Blake2bUpdate failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- ret = wc_Blake2bFinal(&b2b, digest, 64);
- if (ret != 0) {
- printf("Blake2bFinal failed, ret = %d\n", ret);
- return;
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_InitBlake2b(&b2b, 64);
- if (ret != 0) {
- printf("InitBlake2b failed, ret = %d\n", ret);
- return;
- }
- ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
- if (ret != 0) {
- printf("Blake2bUpdate failed, ret = %d\n", ret);
- return;
- }
- ret = wc_Blake2bFinal(&b2b, digest, 64);
- if (ret != 0) {
- printf("Blake2bFinal failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #if defined(HAVE_BLAKE2S)
- void bench_blake2s(void)
- {
- Blake2s b2s;
- byte digest[32];
- double start;
- int ret = 0, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- if (digest_stream) {
- ret = wc_InitBlake2s(&b2s, 32);
- if (ret != 0) {
- printf("InitBlake2s failed, ret = %d\n", ret);
- return;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
- if (ret != 0) {
- printf("Blake2sUpdate failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- ret = wc_Blake2sFinal(&b2s, digest, 32);
- if (ret != 0) {
- printf("Blake2sFinal failed, ret = %d\n", ret);
- return;
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- else {
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_InitBlake2s(&b2s, 32);
- if (ret != 0) {
- printf("InitBlake2b failed, ret = %d\n", ret);
- return;
- }
- ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
- if (ret != 0) {
- printf("Blake2bUpdate failed, ret = %d\n", ret);
- return;
- }
- ret = wc_Blake2sFinal(&b2s, digest, 32);
- if (ret != 0) {
- printf("Blake2sFinal failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- }
- bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #ifdef WOLFSSL_CMAC
- static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
- {
- Cmac cmac;
- byte digest[WC_AES_BLOCK_SIZE];
- word32 digestSz = sizeof(digest);
- double start;
- int ret, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifdef WOLFSSL_SECO_CAAM
- unsigned int keyID;
- int keyGroup = 1; /* group one was chosen arbitrarily */
- int keyInfo = CAAM_KEY_TRANSIENT;
- int keyType = CAAM_KEYTYPE_AES128;
- byte pubKey[AES_256_KEY_SIZE];
- if (keySz == AES_256_KEY_SIZE) {
- keyType = CAAM_KEYTYPE_AES256;
- }
- if (useDeviceID &&
- wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
- keyInfo, &keyID) != 0) {
- printf("Error generating key in hsm\n");
- return;
- }
- #endif
- (void)useDeviceID;
- bench_stats_start(&count, &start);
- do {
- #ifdef HAVE_FIPS
- ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
- #else
- ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
- HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
- #endif
- if (ret != 0) {
- printf("InitCmac failed, ret = %d\n", ret);
- return;
- }
- #ifdef WOLFSSL_SECO_CAAM
- if (useDeviceID) {
- wc_SECO_CMACSetKeyID(&cmac, keyID);
- }
- #endif
- for (i = 0; i < numBlocks; i++) {
- ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
- if (ret != 0) {
- printf("CmacUpdate failed, ret = %d\n", ret);
- return;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- /* Note: final force zero's the Cmac struct */
- ret = wc_CmacFinal(&cmac, digest, &digestSz);
- if (ret != 0) {
- printf("CmacFinal failed, ret = %d\n", ret);
- return;
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- void bench_cmac(int useDeviceID)
- {
- #ifdef WOLFSSL_AES_128
- bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
- #endif
- #ifdef WOLFSSL_AES_256
- bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
- #endif
- }
- #endif /* WOLFSSL_CMAC */
- #ifdef HAVE_SCRYPT
- void bench_scrypt(void)
- {
- byte derived[64];
- double start;
- int ret, i, count;
- DECLARE_MULTI_VALUE_STATS_VARS()
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < scryptCnt; i++) {
- ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
- (byte*)"SodiumChloride", 14, 14, 8, 1,
- sizeof(derived));
- if (ret != 0) {
- printf("scrypt failed, ret = %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif /* HAVE_SCRYPT */
- #ifndef NO_HMAC
- static void bench_hmac(int useDeviceID, int type, int digestSz,
- const byte* key, word32 keySz, const char* label)
- {
- WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
- sizeof(Hmac), HEAP_HINT);
- double start;
- int ret = 0, i, count = 0, times, pending = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifdef WOLFSSL_ASYNC_CRYPT
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_MAX_DIGEST_SIZE, HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
- WC_MAX_DIGEST_SIZE, HEAP_HINT);
- #else
- byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
- #endif
- (void)digestSz;
- WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
- sizeof(Hmac), HEAP_HINT);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- ret = wc_HmacInit(hmac[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
- goto exit;
- }
- ret = wc_HmacSetKey(hmac[i], type, key, keySz);
- if (ret != 0) {
- printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
- goto exit;
- }
- }
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < numBlocks || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(hmac[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hmac[i]),
- 0, ×, &pending)) {
- goto exit_hmac;
- }
- }
- } /* for i */
- } /* for times */
- count += times;
- times = 0;
- do {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(hmac[i]), 0,
- ×, numBlocks, &pending)) {
- ret = wc_HmacFinal(hmac[i], digest[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(hmac[i]),
- 0, ×, &pending)) {
- goto exit_hmac;
- }
- }
- RECORD_MULTI_VALUE_STATS();
- } /* for i */
- } while (pending > 0);
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_hmac:
- bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_HmacFree(hmac[i]);
- }
- WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
- #ifdef WOLFSSL_ASYNC_CRYPT
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- #endif
- }
- #ifndef NO_MD5
- void bench_hmac_md5(int useDeviceID)
- {
- WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
- bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
- "HMAC-MD5");
- }
- #endif /* NO_MD5 */
- #ifndef NO_SHA
- void bench_hmac_sha(int useDeviceID)
- {
- WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b };
- bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
- "HMAC-SHA");
- }
- #endif /* NO_SHA */
- #ifdef WOLFSSL_SHA224
- void bench_hmac_sha224(int useDeviceID)
- {
- WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b };
- bench_hmac(useDeviceID, WC_SHA224,
- WC_SHA224_DIGEST_SIZE, key, sizeof(key),
- "HMAC-SHA224");
- }
- #endif /* WOLFSSL_SHA224 */
- #ifndef NO_SHA256
- void bench_hmac_sha256(int useDeviceID)
- {
- WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
- bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
- "HMAC-SHA256");
- }
- #endif /* NO_SHA256 */
- #ifdef WOLFSSL_SHA384
- void bench_hmac_sha384(int useDeviceID)
- {
- WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
- bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
- "HMAC-SHA384");
- }
- #endif /* WOLFSSL_SHA384 */
- #ifdef WOLFSSL_SHA512
- void bench_hmac_sha512(int useDeviceID)
- {
- WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
- bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
- "HMAC-SHA512");
- }
- #endif /* WOLFSSL_SHA512 */
- #ifndef NO_PWDBASED
- void bench_pbkdf2(void)
- {
- double start;
- int ret = 0, count = 0;
- const char* passwd32 = "passwordpasswordpasswordpassword";
- WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
- 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
- 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
- 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
- 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
- byte derived[32];
- DECLARE_MULTI_VALUE_STATS_VARS()
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
- salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
- count++;
- RECORD_MULTI_VALUE_STATS();
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif /* !NO_PWDBASED */
- #endif /* NO_HMAC */
- #ifdef WOLFSSL_SIPHASH
- void bench_siphash(void)
- {
- double start;
- int ret = 0, count;
- const char* passwd16 = "passwordpassword";
- byte out[16];
- int i;
- DECLARE_MULTI_VALUE_STATS_VARS()
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
- out, 8);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
- out, 16);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #ifdef WC_SRTP_KDF
- void bench_srtpkdf(void)
- {
- double start;
- int count;
- int ret = 0;
- byte keyE[32];
- byte keyA[20];
- byte keyS[14];
- const byte *key = bench_key_buf;
- const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
- const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
- int kdrIdx = 0;
- int i;
- DECLARE_MULTI_VALUE_STATS_VARS()
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
- kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
- keyS, sizeof(keyS));
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
- kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
- keyS, sizeof(keyS));
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
- kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
- keyS, sizeof(keyS));
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (i = 0; i < numBlocks; i++) {
- ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
- kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
- keyS, sizeof(keyS));
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #ifndef NO_RSA
- #if defined(WOLFSSL_KEY_GEN)
- static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
- {
- WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
- sizeof(RsaKey), HEAP_HINT);
- double start = 0;
- int ret = 0, i, count = 0, times, pending = 0;
- const long rsa_e_val = WC_RSA_EXPONENT;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
- sizeof(RsaKey), HEAP_HINT);
- bench_stats_start(&count, &start);
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < genTimes || pending > 0; ) {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
- 0, ×, genTimes, &pending)) {
- wc_FreeRsaKey(genKey[i]);
- ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
- if (ret < 0) {
- goto exit;
- }
- ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
- &gRng);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 0,
- ×, &pending)) {
- goto exit;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- /* cleanup */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_FreeRsaKey(genKey[i]);
- }
- WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- void bench_rsaKeyGen(int useDeviceID)
- {
- int k;
- #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
- static const word32 keySizes[2] = {1024, 2048 };
- #elif RSA_MAX_SIZE >= 4096
- #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
- (RSA_MIN_SIZE <= 1024)
- static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
- #else
- static const word32 keySizes[3] = {2048, 3072, 4096};
- #endif
- #elif RSA_MAX_SIZE >= 3072
- #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
- (RSA_MIN_SIZE <= 1024)
- static const word32 keySizes[3] = {1024, 2048, 3072 };
- #else
- static const word32 keySizes[2] = {2048, 3072 };
- #endif
- #elif RSA_MAX_SIZE >= 2048
- #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
- (RSA_MIN_SIZE <= 1024)
- static const word32 keySizes[2] = {1024, 2048 };
- #else
- static const word32 keySizes[1] = {2048};
- #endif
- #else
- #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
- (RSA_MIN_SIZE <= 1024)
- static const word32 keySizes[1] = {1024 };
- #else
- #error No candidate RSA key sizes to benchmark.
- #endif
- #endif
- for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
- bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
- }
- }
- void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
- {
- bench_rsaKeyGen_helper(useDeviceID, keySz);
- }
- #endif /* WOLFSSL_KEY_GEN */
- #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
- !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
- #if defined(WOLFSSL_MDK_SHELL)
- static char *certRSAname = "certs/rsa2048.der";
- /* set by shell command */
- static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
- #elif defined(FREESCALE_MQX)
- static char *certRSAname = "a:\\certs\\rsa2048.der";
- #else
- static const char *certRSAname = "certs/rsa2048.der";
- #endif
- #endif
- #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
- #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
- #if defined(USE_CERT_BUFFERS_2048)
- static const unsigned char rsa_2048_sig[] = {
- 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
- 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
- 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
- 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
- 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
- 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
-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 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
- 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
- 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
- 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
- };
- #elif defined(USE_CERT_BUFFERS_3072)
- static const unsigned char rsa_3072_sig[] = {
- 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
- 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
- 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
- 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
- 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
- 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
- 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
- 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
- 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
- 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
- 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
- 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
- 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
- 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
- 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
- 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
- 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
- 0x56, 0x5b,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, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
- 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
- 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
- 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
- 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
- 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
- 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
- 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
- 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
- };
- #else
- #error Not Supported Yet!
- #endif
- #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
- static void bench_rsa_helper(int useDeviceID,
- WC_ARRAY_ARG(rsaKey,
- RsaKey,
- BENCH_MAX_PENDING,
- sizeof(RsaKey)),
- word32 rsaKeySz)
- {
- int ret = 0, i, times, count = 0, pending = 0;
- word32 idx = 0;
- #ifndef WOLFSSL_RSA_VERIFY_ONLY
- const char* messageStr = TEST_STRING;
- const int len = (int)TEST_STRING_SZ;
- #endif
- double start = 0.0F;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifndef WOLFSSL_RSA_VERIFY_ONLY
- WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
- #endif
- WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
- rsaKeySz, HEAP_HINT);
- #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
- !defined(WOLFSSL_RSA_PUBLIC_ONLY))
- WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
- rsaKeySz, HEAP_HINT);
- #else
- byte* out[BENCH_MAX_PENDING];
- #endif
- XMEMSET(out, 0, sizeof(out));
- WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
- rsaKeySz, HEAP_HINT);
- #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
- !defined(WOLFSSL_RSA_PUBLIC_ONLY))
- WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
- rsaKeySz, HEAP_HINT);
- if (out[0] == NULL) {
- ret = MEMORY_E;
- goto exit;
- }
- #endif
- if (enc[0] == NULL) {
- ret = MEMORY_E;
- goto exit;
- }
- #ifndef WOLFSSL_RSA_VERIFY_ONLY
- WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
- XMEMCPY(message, messageStr, len);
- #endif
- if (!rsa_sign_verify) {
- #ifndef WOLFSSL_RSA_VERIFY_ONLY
- /* begin public RSA */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < ntimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, ntimes, &pending)) {
- ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
- rsaKeySz/8, rsaKey[i],
- GLOBAL_RNG);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(
- rsaKey[i]), 1, ×,
- &pending)) {
- goto exit_rsa_verify;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_rsa_verify:
- bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
- #ifndef WOLFSSL_RSA_PUBLIC_ONLY
- if (ret < 0) {
- goto exit;
- }
- RESET_MULTI_VALUE_STATS_VARS();
- /* capture resulting encrypt length */
- idx = (word32)(rsaKeySz/8);
- /* begin private async RSA */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < ntimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, ntimes, &pending)) {
- ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
- rsaKeySz/8, rsaKey[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, &pending)) {
- goto exit_rsa_pub;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_rsa_pub:
- bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
- }
- else {
- #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
- /* begin RSA sign */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < ntimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, ntimes, &pending)) {
- ret = wc_RsaSSL_Sign(message, len, enc[i],
- rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, &pending)) {
- goto exit_rsa_sign;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_rsa_sign:
- bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
- count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret < 0) {
- goto exit;
- }
- RESET_MULTI_VALUE_STATS_VARS();
- #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
- /* capture resulting encrypt length */
- idx = rsaKeySz/8;
- /* begin RSA verify */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < ntimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, ntimes, &pending)) {
- #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
- !defined(WOLFSSL_RSA_PUBLIC_ONLY)
- ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
- rsaKeySz/8, rsaKey[i]);
- #elif defined(USE_CERT_BUFFERS_2048)
- XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
- idx = sizeof(rsa_2048_sig);
- out[i] = NULL;
- ret = wc_RsaSSL_VerifyInline(enc[i], idx,
- &out[i], rsaKey[i]);
- if (ret > 0) {
- ret = 0;
- }
- #elif defined(USE_CERT_BUFFERS_3072)
- XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
- idx = sizeof(rsa_3072_sig);
- out[i] = NULL;
- ret = wc_RsaSSL_VerifyInline(enc[i], idx,
- &out[i], rsaKey[i]);
- if (ret > 0)
- ret = 0;
- #endif
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(rsaKey[i]),
- 1, ×, &pending)) {
- goto exit_rsa_verifyinline;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_rsa_verifyinline:
- bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- exit:
- WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
- #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
- WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
- #endif
- #ifndef WOLFSSL_RSA_VERIFY_ONLY
- WC_FREE_VAR(message, HEAP_HINT);
- #endif
- }
- void bench_rsa(int useDeviceID)
- {
- int i;
- WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
- sizeof(RsaKey), HEAP_HINT);
- int ret = 0;
- word32 rsaKeySz = 0;
- const byte* tmp;
- size_t bytes;
- #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
- word32 idx;
- #endif
- WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
- sizeof(RsaKey), HEAP_HINT);
- #ifdef USE_CERT_BUFFERS_1024
- tmp = rsa_key_der_1024;
- bytes = (size_t)sizeof_rsa_key_der_1024;
- rsaKeySz = 1024;
- #elif defined(USE_CERT_BUFFERS_2048)
- tmp = rsa_key_der_2048;
- bytes = (size_t)sizeof_rsa_key_der_2048;
- rsaKeySz = 2048;
- #elif defined(USE_CERT_BUFFERS_3072)
- tmp = rsa_key_der_3072;
- bytes = (size_t)sizeof_rsa_key_der_3072;
- rsaKeySz = 3072;
- #elif defined(USE_CERT_BUFFERS_4096)
- tmp = client_key_der_4096;
- bytes = (size_t)sizeof_client_key_der_4096;
- rsaKeySz = 4096;
- #else
- #error "need a cert buffer size"
- #endif /* USE_CERT_BUFFERS */
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- /* setup an async context for each key */
- ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret < 0) {
- goto exit;
- }
- #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
- #ifdef WC_RSA_BLINDING
- ret = wc_RsaSetRNG(rsaKey[i], &gRng);
- if (ret != 0)
- goto exit;
- #endif
- #endif
- #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
- /* decode the private key */
- idx = 0;
- if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
- rsaKey[i], (word32)bytes)) != 0) {
- printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
- goto exit;
- }
- #elif defined(WOLFSSL_PUBLIC_MP)
- /* get offset to public portion of the RSA key */
- #ifdef USE_CERT_BUFFERS_1024
- bytes = 11;
- #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
- bytes = 12;
- #endif
- ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
- if (ret != 0) {
- printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
- goto exit;
- }
- ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
- if (ret != 0) {
- printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
- goto exit;
- }
- #else
- /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
- rsaKeySz = 0;
- #endif
- }
- if (rsaKeySz > 0) {
- bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
- }
- (void)bytes;
- (void)tmp;
- exit:
- /* cleanup */
- if (WC_ARRAY_OK(rsaKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_FreeRsaKey(rsaKey[i]);
- }
- WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- #ifdef WOLFSSL_KEY_GEN
- /* bench any size of RSA key */
- void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
- {
- int ret = 0, i, pending = 0;
- WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
- sizeof(RsaKey), HEAP_HINT);
- int isPending[BENCH_MAX_PENDING];
- long exp = 65537L;
- /* clear for done cleanup */
- XMEMSET(isPending, 0, sizeof(isPending));
- WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
- sizeof(RsaKey), HEAP_HINT);
- /* init keys */
- do {
- pending = 0;
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (!isPending[i]) { /* if making the key is pending then just call
- * wc_MakeRsaKey again */
- /* setup an async context for each key */
- if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID) < 0) {
- goto exit;
- }
- #ifdef WC_RSA_BLINDING
- ret = wc_RsaSetRNG(rsaKey[i], &gRng);
- if (ret != 0)
- goto exit;
- #endif
- }
- /* create the RSA key */
- ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
- if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
- isPending[i] = 1;
- pending = 1;
- }
- else if (ret != 0) {
- printf("wc_MakeRsaKey failed! %d\n", ret);
- goto exit;
- }
- } /* for i */
- } while (pending > 0);
- bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
- exit:
- /* cleanup */
- if (WC_ARRAY_OK(rsaKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_FreeRsaKey(rsaKey[i]);
- }
- WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- #endif /* WOLFSSL_KEY_GEN */
- #endif /* !NO_RSA */
- #ifndef NO_DH
- #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
- !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
- #if defined(WOLFSSL_MDK_SHELL)
- static char *certDHname = "certs/dh2048.der";
- /* set by shell command */
- void set_Bench_DH_File(char * cert) { certDHname = cert ; }
- #elif defined(FREESCALE_MQX)
- static char *certDHname = "a:\\certs\\dh2048.der";
- #elif defined(NO_ASN)
- /* do nothing, but don't need a file */
- #else
- static const char *certDHname = "certs/dh2048.der";
- #endif
- #endif
- #ifdef HAVE_FFDHE_4096
- #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
- #else
- #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
- #endif
- #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
- void bench_dh(int useDeviceID)
- {
- int ret = 0, i;
- int count = 0, times, pending = 0;
- const byte* tmp = NULL;
- double start = 0.0F;
- WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
- sizeof(DhKey), HEAP_HINT);
- int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
- const char**desc = bench_desc_words[lng_index];
- #ifndef NO_ASN
- size_t bytes = 0;
- word32 idx;
- #endif
- word32 pubSz[BENCH_MAX_PENDING];
- word32 privSz[BENCH_MAX_PENDING];
- word32 pubSz2 = BENCH_DH_KEY_SIZE;
- word32 privSz2 = BENCH_DH_PRIV_SIZE;
- word32 agreeSz[BENCH_MAX_PENDING];
- #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
- #ifdef HAVE_PUBLIC_FFDHE
- const DhParams *params = NULL;
- #else
- int paramName = 0;
- #endif
- #endif
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
- BENCH_DH_KEY_SIZE, HEAP_HINT);
- WC_DECLARE_VAR(pub2, byte,
- BENCH_DH_KEY_SIZE, HEAP_HINT);
- WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
- BENCH_DH_KEY_SIZE, HEAP_HINT);
- WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
- BENCH_DH_PRIV_SIZE, HEAP_HINT);
- WC_DECLARE_VAR(priv2, byte,
- BENCH_DH_PRIV_SIZE, HEAP_HINT);
- /* old scan-build misfires -Wmaybe-uninitialized on these. */
- XMEMSET(pub, 0, sizeof(pub));
- XMEMSET(agree, 0, sizeof(agree));
- XMEMSET(priv, 0, sizeof(priv));
- WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
- sizeof(DhKey), HEAP_HINT);
- WC_ALLOC_ARRAY(pub, byte,
- BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
- WC_ALLOC_ARRAY(agree, byte,
- BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
- WC_ALLOC_ARRAY(priv, byte,
- BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
- WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
- WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
- (void)tmp;
- if (!use_ffdhe) {
- #if defined(NO_ASN)
- dhKeySz = 1024;
- /* do nothing, but don't use default FILE */
- #elif defined(USE_CERT_BUFFERS_1024)
- tmp = dh_key_der_1024;
- bytes = (size_t)sizeof_dh_key_der_1024;
- dhKeySz = 1024;
- #elif defined(USE_CERT_BUFFERS_2048)
- tmp = dh_key_der_2048;
- bytes = (size_t)sizeof_dh_key_der_2048;
- dhKeySz = 2048;
- #elif defined(USE_CERT_BUFFERS_3072)
- tmp = dh_key_der_3072;
- bytes = (size_t)sizeof_dh_key_der_3072;
- dhKeySz = 3072;
- #elif defined(USE_CERT_BUFFERS_4096)
- tmp = dh_key_der_4096;
- bytes = (size_t)sizeof_dh_key_der_4096;
- dhKeySz = 4096;
- #else
- #error "need to define a cert buffer size"
- #endif /* USE_CERT_BUFFERS */
- }
- #ifdef HAVE_FFDHE_2048
- else if (use_ffdhe == 2048) {
- #ifdef HAVE_PUBLIC_FFDHE
- params = wc_Dh_ffdhe2048_Get();
- #else
- paramName = WC_FFDHE_2048;
- #endif
- dhKeySz = 2048;
- }
- #endif
- #ifdef HAVE_FFDHE_3072
- else if (use_ffdhe == 3072) {
- #ifdef HAVE_PUBLIC_FFDHE
- params = wc_Dh_ffdhe3072_Get();
- #else
- paramName = WC_FFDHE_3072;
- #endif
- dhKeySz = 3072;
- }
- #endif
- #ifdef HAVE_FFDHE_4096
- else if (use_ffdhe == 4096) {
- #ifdef HAVE_PUBLIC_FFDHE
- params = wc_Dh_ffdhe4096_Get();
- #else
- paramName = WC_FFDHE_4096;
- #endif
- dhKeySz = 4096;
- }
- #endif
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- /* setup an async context for each key */
- ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0)
- goto exit;
- /* setup key */
- if (!use_ffdhe) {
- #ifdef NO_ASN
- ret = wc_DhSetKey(dhKey[i], dh_p,
- sizeof(dh_p), dh_g, sizeof(dh_g));
- #else
- idx = 0;
- ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
- #endif
- }
- #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
- #ifdef HAVE_PUBLIC_FFDHE
- else if (params != NULL) {
- ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
- params->g, params->g_len);
- }
- #else
- else if (paramName != 0) {
- ret = wc_DhSetNamedKey(dhKey[i], paramName);
- }
- #endif
- #endif
- if (ret != 0) {
- printf("DhKeyDecode failed %d, can't benchmark\n", ret);
- goto exit;
- }
- }
- /* Key Gen */
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < genTimes || pending > 0; ) {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
- 0, ×, genTimes, &pending)) {
- privSz[i] = BENCH_DH_PRIV_SIZE;
- pubSz[i] = BENCH_DH_KEY_SIZE;
- ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
- priv[i], &privSz[i],
- pub[i], &pubSz[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(dhKey[i]),
- 0, ×, &pending)) {
- goto exit_dh_gen;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- exit_dh_gen:
- bench_stats_asym_finish("DH", dhKeySz, desc[2],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret < 0) {
- goto exit;
- }
- RESET_MULTI_VALUE_STATS_VARS();
- /* Generate key to use as other public */
- PRIVATE_KEY_UNLOCK();
- ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
- priv2, &privSz2, pub2, &pubSz2);
- PRIVATE_KEY_LOCK();
- #ifdef WOLFSSL_ASYNC_CRYPT
- ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
- #endif
- /* Key Agree */
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
- 0, ×, agreeTimes, &pending)) {
- ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
- privSz[i], pub2, pubSz2);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(dhKey[i]), 0, ×, &pending)) {
- goto exit;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_LOCK();
- exit:
- bench_stats_asym_finish("DH", dhKeySz, desc[3],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- /* cleanup */
- if (WC_ARRAY_OK(dhKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_FreeDhKey(dhKey[i]);
- }
- WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
- WC_FREE_VAR(pub2, HEAP_HINT);
- WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
- WC_FREE_VAR(priv2, HEAP_HINT);
- WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif /* !NO_DH */
- #ifdef WOLFSSL_HAVE_KYBER
- static void bench_kyber_keygen(int type, const char* name, int keySize,
- KyberKey* key)
- {
- int ret = 0, times, count, pending = 0;
- double start;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- /* KYBER Make Key */
- bench_stats_start(&count, &start);
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < agreeTimes || pending > 0; times++) {
- wc_KyberKey_Free(key);
- ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
- if (ret != 0)
- goto exit;
- #ifdef KYBER_NONDETERMINISTIC
- ret = wc_KyberKey_MakeKey(key, &gRng);
- #else
- unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
- ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
- #endif
- if (ret != 0)
- goto exit;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
- {
- int ret = 0, times, count, pending = 0;
- double start;
- const char**desc = bench_desc_words[lng_index];
- byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
- byte ss[KYBER_SS_SZ];
- word32 ctSz;
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_KyberKey_CipherTextSize(key, &ctSz);
- if (ret != 0) {
- return;
- }
- /* KYBER Encapsulate */
- bench_stats_start(&count, &start);
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < agreeTimes || pending > 0; times++) {
- #ifdef KYBER_NONDETERMINISTIC
- ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
- #else
- unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
- ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
- sizeof(rand));
- #endif
- if (ret != 0)
- goto exit_encap;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_encap:
- bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- /* KYBER Decapsulate */
- bench_stats_start(&count, &start);
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < agreeTimes || pending > 0; times++) {
- ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
- if (ret != 0)
- goto exit_decap;
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_decap:
- bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- void bench_kyber(int type)
- {
- KyberKey key;
- const char* name = NULL;
- int keySize = 0;
- switch (type) {
- #ifndef WOLFSSL_NO_ML_KEM
- #ifdef WOLFSSL_WC_ML_KEM_512
- case WC_ML_KEM_512:
- name = "ML-KEM 512 ";
- keySize = 128;
- break;
- #endif
- #ifdef WOLFSSL_WC_ML_KEM_768
- case WC_ML_KEM_768:
- name = "ML-KEM 768 ";
- keySize = 192;
- break;
- #endif
- #ifdef WOLFSSL_WC_ML_KEM_1024
- case WC_ML_KEM_1024:
- name = "ML-KEM 1024 ";
- keySize = 256;
- break;
- #endif
- #endif
- #ifdef WOLFSSL_KYBER_ORIGINAL
- #ifdef WOLFSSL_KYBER512
- case KYBER512:
- name = "KYBER512 ";
- keySize = 128;
- break;
- #endif
- #ifdef WOLFSSL_KYBER768
- case KYBER768:
- name = "KYBER768 ";
- keySize = 192;
- break;
- #endif
- #ifdef WOLFSSL_KYBER1024
- case KYBER1024:
- name = "KYBER1024";
- keySize = 256;
- break;
- #endif
- #endif
- }
- bench_kyber_keygen(type, name, keySize, &key);
- bench_kyber_encap(name, keySize, &key);
- wc_KyberKey_Free(&key);
- }
- #endif
- #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
- #ifndef WOLFSSL_NO_LMS_SHA256_256
- /* WC_LMS_PARM_L2_H10_W2
- * signature length: 9300 */
- static const byte lms_priv_L2_H10_W2[64] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
- 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
- 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
- 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
- 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
- 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
- };
- static const byte lms_pub_L2_H10_W2[60] =
- {
- 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
- 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
- 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
- 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
- 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
- 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
- 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
- 0x7F,0xC8,0x91,0xB0
- };
- /* WC_LMS_PARM_L2_H10_W4
- * signature length: 5076 */
- static const byte lms_priv_L2_H10_W4[64] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
- 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
- 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
- 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
- 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
- 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
- };
- static const byte lms_pub_L2_H10_W4[60] =
- {
- 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
- 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
- 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
- 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
- 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
- 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
- 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
- 0x6B,0x9A,0xD3,0x14
- };
- /* WC_LMS_PARM_L3_H5_W4
- * signature length: 7160 */
- static const byte lms_priv_L3_H5_W4[64] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
- 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
- 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
- 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
- 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
- 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
- };
- static const byte lms_pub_L3_H5_W4[60] =
- {
- 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
- 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
- 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
- 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
- 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
- 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
- 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
- 0xAB,0x4B,0x51,0x39
- };
- /* WC_LMS_PARM_L3_H5_W8
- * signature length: 3992 */
- static const byte lms_priv_L3_H5_W8[64] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
- 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
- 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
- 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
- 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
- 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
- };
- static const byte lms_pub_L3_H5_W8[60] =
- {
- 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
- 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
- 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
- 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
- 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
- 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
- 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
- 0x83,0xAB,0x43,0xAF
- };
- /* WC_LMS_PARM_L3_H10_W4
- * signature length: 7640 */
- static const byte lms_priv_L3_H10_W4[64] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
- 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
- 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
- 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
- 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
- 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
- };
- static const byte lms_pub_L3_H10_W4[60] =
- {
- 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
- 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
- 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
- 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
- 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
- 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
- 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
- 0x8D,0x78,0xD5,0xA8
- };
- /* WC_LMS_PARM_L4_H5_W8
- * signature length: 5340 */
- static const byte lms_priv_L4_H5_W8[64] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
- 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
- 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
- 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
- 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
- 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
- 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
- };
- static const byte lms_pub_L4_H5_W8[60] =
- {
- 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
- 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
- 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
- 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
- 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
- 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
- 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
- 0x74,0x24,0x12,0xC8
- };
- #endif
- static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
- {
- /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
- * BE USED FOR TESTING PURPOSES! Production applications should
- * write only to non-volatile storage. */
- XMEMCPY(context, priv, privSz);
- return WC_LMS_RC_SAVED_TO_NV_MEMORY;
- }
- static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
- {
- /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
- * BE USED FOR TESTING PURPOSES! */
- XMEMCPY(priv, context, privSz);
- return WC_LMS_RC_READ_TO_MEMORY;
- }
- static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
- static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
- {
- WC_RNG rng;
- LmsKey key;
- int ret;
- word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
- int times = 0;
- int count = 0;
- double start = 0.0F;
- int levels;
- int height;
- int winternitz;
- const char* str = wc_LmsKey_ParmToStr(parm);
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifndef HAVE_FIPS
- ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
- #else
- ret = wc_InitRng(&rng);
- #endif
- if (ret != 0) {
- fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
- return;
- }
- ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
- if (ret) {
- printf("wc_LmsKey_Init failed: %d\n", ret);
- wc_FreeRng(&rng);
- return;
- }
- count = 0;
- bench_stats_start(&count, &start);
- do {
- /* LMS is stateful. Async queuing not practical. */
- for (times = 0; times < 1; ++times) {
- wc_LmsKey_Free(&key);
- ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
- if (ret) {
- printf("wc_LmsKey_Init failed: %d\n", ret);
- goto exit_lms_keygen;
- }
- ret = wc_LmsKey_SetLmsParm(&key, parm);
- if (ret) {
- printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
- goto exit_lms_keygen;
- }
- ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
- ret);
- goto exit_lms_keygen;
- }
- ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
- ret);
- goto exit_lms_keygen;
- }
- ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
- goto exit_lms_keygen;
- }
- ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
- ret);
- goto exit_lms_keygen;
- }
- ret = wc_LmsKey_MakeKey(&key, &rng);
- if (ret) {
- printf("wc_LmsKey_MakeKey failed: %d\n", ret);
- goto exit_lms_keygen;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish(str, levels * height, "keygen", 0,
- count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
- }
- exit_lms_keygen:
- wc_LmsKey_Free(&key);
- wc_FreeRng(&rng);
- }
- static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
- {
- LmsKey key;
- int ret = 0;
- const char * msg = TEST_STRING;
- word32 msgSz = TEST_STRING_SZ;
- byte * sig = NULL;
- word32 sigSz = 0;
- word32 privLen = 0;
- int loaded = 0;
- int times = 0;
- int count = 0;
- double start = 0.0F;
- const char * str = wc_LmsKey_ParmToStr(parm);
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
- if (ret) {
- printf("wc_LmsKey_Init failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- ret = wc_LmsKey_SetLmsParm(&key, parm);
- if (ret) {
- printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- switch (parm) {
- #ifndef WOLFSSL_NO_LMS_SHA256_256
- case WC_LMS_PARM_L2_H10_W2:
- XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
- XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- case WC_LMS_PARM_L2_H10_W4:
- XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
- XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- case WC_LMS_PARM_L3_H5_W4:
- XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
- XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- case WC_LMS_PARM_L3_H5_W8:
- XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
- XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- case WC_LMS_PARM_L3_H10_W4:
- XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
- XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- case WC_LMS_PARM_L4_H5_W8:
- XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
- XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- case WC_LMS_PARM_NONE:
- case WC_LMS_PARM_L1_H15_W2:
- case WC_LMS_PARM_L1_H15_W4:
- case WC_LMS_PARM_L2_H10_W8:
- case WC_LMS_PARM_L3_H5_W2:
- case WC_LMS_PARM_L1_H5_W1:
- case WC_LMS_PARM_L1_H5_W2:
- case WC_LMS_PARM_L1_H5_W4:
- case WC_LMS_PARM_L1_H5_W8:
- case WC_LMS_PARM_L1_H10_W2:
- case WC_LMS_PARM_L1_H10_W4:
- case WC_LMS_PARM_L1_H10_W8:
- case WC_LMS_PARM_L1_H15_W8:
- case WC_LMS_PARM_L1_H20_W2:
- case WC_LMS_PARM_L1_H20_W4:
- case WC_LMS_PARM_L1_H20_W8:
- case WC_LMS_PARM_L2_H5_W2:
- case WC_LMS_PARM_L2_H5_W4:
- case WC_LMS_PARM_L2_H5_W8:
- case WC_LMS_PARM_L2_H15_W2:
- case WC_LMS_PARM_L2_H15_W4:
- case WC_LMS_PARM_L2_H15_W8:
- case WC_LMS_PARM_L2_H20_W2:
- case WC_LMS_PARM_L2_H20_W4:
- case WC_LMS_PARM_L2_H20_W8:
- case WC_LMS_PARM_L3_H10_W8:
- case WC_LMS_PARM_L4_H5_W2:
- case WC_LMS_PARM_L4_H5_W4:
- case WC_LMS_PARM_L4_H10_W4:
- case WC_LMS_PARM_L4_H10_W8:
- #endif
- #ifdef WOLFSSL_LMS_SHA256_192
- case WC_LMS_PARM_SHA256_192_L1_H5_W1:
- case WC_LMS_PARM_SHA256_192_L1_H5_W2:
- case WC_LMS_PARM_SHA256_192_L1_H5_W4:
- case WC_LMS_PARM_SHA256_192_L1_H5_W8:
- case WC_LMS_PARM_SHA256_192_L1_H10_W2:
- case WC_LMS_PARM_SHA256_192_L1_H10_W4:
- case WC_LMS_PARM_SHA256_192_L1_H10_W8:
- case WC_LMS_PARM_SHA256_192_L1_H15_W2:
- case WC_LMS_PARM_SHA256_192_L1_H15_W4:
- case WC_LMS_PARM_SHA256_192_L2_H10_W2:
- case WC_LMS_PARM_SHA256_192_L2_H10_W4:
- case WC_LMS_PARM_SHA256_192_L2_H10_W8:
- case WC_LMS_PARM_SHA256_192_L3_H5_W2:
- case WC_LMS_PARM_SHA256_192_L3_H5_W4:
- case WC_LMS_PARM_SHA256_192_L3_H5_W8:
- case WC_LMS_PARM_SHA256_192_L3_H10_W4:
- case WC_LMS_PARM_SHA256_192_L4_H5_W8:
- #endif
- default:
- XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
- break;
- }
- ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
- if (ret) {
- fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- /* Even with saved priv/pub keys, we must still reload the private
- * key before using it. Reloading the private key is the bottleneck
- * for larger heights. Only print load time in debug builds. */
- count = 0;
- bench_stats_start(&count, &start);
- #ifndef WOLFSSL_WC_LMS_SMALL
- do {
- #ifdef WOLFSSL_WC_LMS
- key.priv.inited = 0;
- key.state = WC_LMS_STATE_PARMSET;
- #endif
- ret = wc_LmsKey_Reload(&key);
- if (ret) {
- printf("wc_LmsKey_Reload failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- RECORD_MULTI_VALUE_STATS();
- count++;
- ret = wc_LmsKey_GetSigLen(&key, &sigSz);
- if (ret) {
- printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- ret = wc_LmsKey_GetPrivLen(&key, &privLen);
- if (ret) {
- printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- #ifdef HAVE_LIBLMS
- break;
- #endif
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish(str, (int)privLen, "load", 0,
- count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- #else
- ret = wc_LmsKey_Reload(&key);
- if (ret) {
- printf("wc_LmsKey_Reload failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- ret = wc_LmsKey_GetSigLen(&key, &sigSz);
- if (ret) {
- printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- ret = wc_LmsKey_GetPrivLen(&key, &privLen);
- if (ret) {
- printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- #endif
- loaded = 1;
- sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (sig == NULL) {
- printf("bench_lms_sign_verify malloc failed\n");
- goto exit_lms_sign_verify;
- }
- count = 0;
- bench_stats_start(&count, &start);
- do {
- /* LMS is stateful. Async queuing not practical. */
- #ifndef WOLFSSL_WC_LMS_SMALL
- for (times = 0; times < ntimes; ++times)
- #else
- for (times = 0; times < 1; ++times)
- #endif
- {
- ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
- if (ret) {
- printf("wc_LmsKey_Sign failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- RECORD_MULTI_VALUE_STATS();
- if (!wc_LmsKey_SigsLeft(&key)) {
- break;
- }
- }
- count += times;
- } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- ));
- bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
- count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- count = 0;
- bench_stats_start(&count, &start);
- do {
- /* LMS is stateful. Async queuing not practical. */
- for (times = 0; times < ntimes; ++times) {
- ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
- if (ret) {
- printf("wc_LmsKey_Verify failed: %d\n", ret);
- goto exit_lms_sign_verify;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_lms_sign_verify:
- bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
- count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (loaded) {
- wc_LmsKey_Free(&key);
- }
- XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- return;
- }
- void bench_lms(void)
- {
- byte pub[HSS_MAX_PUBLIC_KEY_LEN];
- #ifndef WOLFSSL_NO_LMS_SHA256_256
- #ifdef BENCH_LMS_SLOW_KEYGEN
- #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
- bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
- bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
- #undef LMS_PARAMS_BENCHED
- #define LMS_PARAMS_BENCHED
- #endif
- #endif
- #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
- (LMS_MAX_HEIGHT >= 10))
- bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
- bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
- #undef LMS_PARAMS_BENCHED
- #define LMS_PARAMS_BENCHED
- #ifdef BENCH_LMS_SLOW_KEYGEN
- bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
- #endif
- #endif
- #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
- bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
- bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
- #undef LMS_PARAMS_BENCHED
- #define LMS_PARAMS_BENCHED
- #endif
- #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
- (LMS_MAX_HEIGHT >= 10))
- bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
- #endif
- #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
- bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
- #endif
- #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
- bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
- bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
- #endif
- #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
- #ifdef WOLFSSL_LMS_SHA256_192
- #ifdef BENCH_LMS_SLOW_KEYGEN
- #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
- #undef LMS_PARAMS_BENCHED
- #define LMS_PARAMS_BENCHED
- #endif
- #endif
- #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
- (LMS_MAX_HEIGHT >= 10))
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
- #undef LMS_PARAMS_BENCHED
- #define LMS_PARAMS_BENCHED
- #ifdef BENCH_LMS_SLOW_KEYGEN
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
- #endif
- #endif
- #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
- #undef LMS_PARAMS_BENCHED
- #define LMS_PARAMS_BENCHED
- #endif
- #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
- (LMS_MAX_HEIGHT >= 10))
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
- #endif
- #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
- #endif
- #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
- bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
- bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
- #endif
- #endif /* WOLFSSL_LMS_SHA256_192 */
- return;
- }
- #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
- #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
- static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
- void *context)
- {
- /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
- * BE USED FOR TESTING PURPOSES! Production applications should
- * write only to non-volatile storage. */
- XMEMCPY(context, priv, privSz);
- return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
- }
- static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
- void *context)
- {
- /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
- * BE USED FOR TESTING PURPOSES! */
- XMEMCPY(priv, context, privSz);
- return WC_XMSS_RC_READ_TO_MEMORY;
- }
- static void bench_xmss_sign_verify(const char * params)
- {
- WC_RNG rng;
- XmssKey key;
- word32 pkSz = 0;
- word32 skSz = 0;
- int freeRng = 0;
- int freeKey = 0;
- unsigned char * sk = NULL;
- const char * msg = "XMSS post quantum signature test";
- word32 msgSz = (word32) XSTRLEN(msg);
- int ret = 0;
- byte * sig = NULL;
- word32 sigSz = 0;
- int times = 0;
- int count = 0;
- double start = 0.0F;
- #ifndef HAVE_FIPS
- ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
- #else
- ret = wc_InitRng(&rng);
- #endif
- if (ret != 0) {
- fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- freeRng = 1;
- ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
- if (ret != 0) {
- fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- ret = wc_XmssKey_SetParamStr(&key, params);
- if (ret != 0) {
- fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- ret = wc_XmssKey_GetPubLen(&key, &pkSz);
- if (ret != 0) {
- fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- #ifndef WOLFSSL_WC_XMSS
- if (pkSz != XMSS_SHA256_PUBLEN) {
- fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
- XMSS_SHA256_PUBLEN);
- goto exit_xmss_sign_verify;
- }
- #endif
- ret = wc_XmssKey_GetPrivLen(&key, &skSz);
- if (ret != 0 || skSz <= 0) {
- fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
- goto exit_xmss_sign_verify;
- }
- ret = wc_XmssKey_GetSigLen(&key, &sigSz);
- if (ret != 0 || sigSz <= 0) {
- fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
- goto exit_xmss_sign_verify;
- }
- /* Allocate secret keys.*/
- sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (sk == NULL) {
- fprintf(stderr, "error: allocate xmss sk failed\n");
- goto exit_xmss_sign_verify;
- }
- /* Allocate signature array. */
- sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (sig == NULL) {
- fprintf(stderr, "error: allocate xmss sig failed\n");
- goto exit_xmss_sign_verify;
- }
- ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
- if (ret != 0) {
- fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
- if (ret != 0) {
- fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- ret = wc_XmssKey_SetContext(&key, (void *)sk);
- if (ret != 0) {
- fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
- fprintf(stderr, "params: %s\n", params);
- fprintf(stderr, "pkSz: %d\n", pkSz);
- fprintf(stderr, "skSz: %d\n", skSz);
- fprintf(stderr, "sigSz: %d\n", sigSz);
- #endif
- /* Making the private key is the bottleneck for larger heights. */
- count = 0;
- bench_stats_start(&count, &start);
- ret = wc_XmssKey_MakeKey(&key, &rng);
- if (ret != 0) {
- printf("wc_XmssKey_MakeKey failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- /* Can only do one at a time - state changes after make key. */
- count +=1;
- bench_stats_check(start);
- bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
- freeKey = 1;
- count = 0;
- bench_stats_start(&count, &start);
- do {
- /* XMSS is stateful. Async queuing not practical. */
- #ifndef WOLFSSL_WC_XMSS_SMALL
- for (times = 0; times < ntimes; ++times)
- #else
- for (times = 0; times < 1; ++times)
- #endif
- {
- if (!wc_XmssKey_SigsLeft(&key))
- break;
- ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
- if (ret) {
- printf("wc_XmssKey_Sign failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- }
- count += times;
- } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
- bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
- count = 0;
- bench_stats_start(&count, &start);
- do {
- /* XMSS is stateful. Async queuing not practical. */
- for (times = 0; times < ntimes; ++times) {
- ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
- if (ret) {
- printf("wc_XmssKey_Verify failed: %d\n", ret);
- goto exit_xmss_sign_verify;
- }
- }
- count += times;
- } while (bench_stats_check(start));
- exit_xmss_sign_verify:
- bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
- /* Cleanup everything. */
- XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- sig = NULL;
- XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- sk = NULL;
- if (freeRng) {
- wc_FreeRng(&rng);
- }
- if (freeKey) {
- wc_XmssKey_Free(&key);
- }
- return;
- }
- void bench_xmss(int hash)
- {
- /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
- * sets.
- *
- * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
- * and "XMSSMT-SHA2_60/3_256", because their keygen can be
- * very slow, their signatures and private keys quite large,
- * and xmss private keys are not portable across different
- * XMSS/XMSS^MT implementations.
- *
- * The bottleneck in key generation is the height of the first
- * level tree (or h/d).
- *
- * h is the total height of the hyper tree, and d the number of
- * trees.
- */
- /* h/d h d */
- #ifdef WC_XMSS_SHA256
- if (hash == WC_HASH_TYPE_SHA256) {
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
- #endif
- #endif
- #endif /* HASH_SIZE 256 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
- #endif
- #endif
- #endif /* HASH_SIZE 192 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
- bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
- bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
- bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
- #endif
- #endif /* HASH_SIZE 256 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
- bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
- bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
- bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
- #endif
- #endif /* HASH_SIZE 192 */
- }
- #endif
- #ifdef WC_XMSS_SHA512
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
- if (hash == WC_HASH_TYPE_SHA512) {
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
- bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
- #endif
- }
- #endif /* HASH_SIZE 512 */
- #endif
- #ifdef WC_XMSS_SHAKE128
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
- if (hash == WC_HASH_TYPE_SHAKE128) {
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
- bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
- #endif
- }
- #endif /* HASH_SIZE 256 */
- #endif
- #ifdef WC_XMSS_SHAKE256
- if (hash == WC_HASH_TYPE_SHAKE256) {
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
- #endif
- #endif
- #endif /* HASH_SIZE 512 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
- #endif
- #endif
- #endif /* HASH_SIZE 256 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
- bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
- #endif
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
- #endif
- #endif
- #endif /* HASH_SIZE 192 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
- #endif
- #endif /* HASH_SIZE 512 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
- bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
- #endif
- #endif /* HASH_SIZE 256 */
- #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
- bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
- bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
- #endif
- #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
- #endif
- #ifdef BENCH_XMSS_SLOW_KEYGEN
- bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
- #endif
- bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
- #endif
- #endif /* HASH_SIZE 192 */
- }
- #endif
- return;
- }
- #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
- #ifdef HAVE_ECC
- /* Maximum ECC name plus null terminator:
- * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
- #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
- /* run all benchmarks on a curve */
- void bench_ecc_curve(int curveId)
- {
- if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
- #ifndef NO_SW_BENCH
- bench_eccMakeKey(0, curveId);
- #endif
- #if defined(BENCH_DEVID)
- bench_eccMakeKey(1, curveId);
- #endif
- }
- if (bench_all || (bench_asym_algs & BENCH_ECC)) {
- #ifndef NO_SW_BENCH
- bench_ecc(0, curveId);
- #endif
- #if defined(BENCH_DEVID)
- bench_ecc(1, curveId);
- #endif
- }
- #ifdef HAVE_ECC_ENCRYPT
- if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
- bench_eccEncrypt(curveId);
- #endif
- }
- void bench_eccMakeKey(int useDeviceID, int curveId)
- {
- int ret = 0, i, times, count = 0, pending = 0;
- int deviceID;
- int keySize = 0;
- WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- char name[BENCH_ECC_NAME_SZ];
- double start = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- deviceID = useDeviceID ? devId : INVALID_DEVID;
- keySize = wc_ecc_get_curve_size_from_id(curveId);
- /* ECC Make Key */
- bench_stats_start(&count, &start);
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 0,
- ×, agreeTimes, &pending)) {
- wc_ecc_free(genKey[i]);
- ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
- if (ret < 0) {
- goto exit;
- }
- ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
- curveId);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 0, ×,
- &pending)) {
- goto exit;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
- wc_ecc_get_name(curveId));
- bench_stats_asym_finish(name, keySize * 8, desc[2],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- /* cleanup */
- if (WC_ARRAY_OK(genKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_ecc_free(genKey[i]);
- }
- WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- void bench_ecc(int useDeviceID, int curveId)
- {
- int ret = 0, i, times, count, pending = 0;
- int deviceID;
- int keySize;
- char name[BENCH_ECC_NAME_SZ];
- WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #ifdef HAVE_ECC_DHE
- WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- #ifdef HAVE_ECC_VERIFY
- int verify[BENCH_MAX_PENDING];
- #endif
- #endif
- word32 x[BENCH_MAX_PENDING];
- double start = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifdef HAVE_ECC_DHE
- WC_DECLARE_ARRAY(shared, byte,
- BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- WC_DECLARE_ARRAY(sig, byte,
- BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
- WC_DECLARE_ARRAY(digest, byte,
- BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- /* old scan-build misfires -Wmaybe-uninitialized on these. */
- XMEMSET(sig, 0, sizeof(sig));
- XMEMSET(digest, 0, sizeof(digest));
- #endif
- #ifdef HAVE_ECC_DHE
- XMEMSET(shared, 0, sizeof(shared));
- #endif
- WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #ifdef HAVE_ECC_DHE
- WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- WC_ALLOC_ARRAY(shared, byte,
- BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- deviceID = useDeviceID ? devId : INVALID_DEVID;
- keySize = wc_ecc_get_curve_size_from_id(curveId);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- /* setup an context for each key */
- if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
- goto exit;
- }
- ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
- #ifdef WOLFSSL_ASYNC_CRYPT
- ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
- #endif
- if (ret < 0) {
- goto exit;
- }
- #ifdef HAVE_ECC_DHE
- if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
- goto exit;
- }
- if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
- curveId)) > 0) {
- goto exit;
- }
- #endif
- }
- #ifdef HAVE_ECC_DHE
- #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
- (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
- !defined(HAVE_SELFTEST)
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- (void)wc_ecc_set_rng(genKey[i], &gRng);
- }
- #endif
- /* ECC Shared Secret */
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
- ×, agreeTimes, &pending)) {
- x[i] = (word32)keySize;
- ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
- shared[i], &x[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
- &pending)) {
- goto exit_ecdhe;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_UNLOCK();
- exit_ecdhe:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
- wc_ecc_get_name(curveId));
- bench_stats_asym_finish(name, keySize * 8, desc[3],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- if (ret < 0) {
- goto exit;
- }
- #endif /* HAVE_ECC_DHE */
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- /* Init digest to sign */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- for (count = 0; count < keySize; count++) {
- digest[i][count] = (byte)count;
- }
- }
- /* ECC Sign */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
- ×, agreeTimes, &pending)) {
- if (genKey[i]->state == 0) {
- x[i] = ECC_MAX_SIG_SIZE;
- }
- ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
- &x[i], GLOBAL_RNG, genKey[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
- &pending)) {
- goto exit_ecdsa_sign;
- }
- } /* bench_async_check */
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_ecdsa_sign:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
- wc_ecc_get_name(curveId));
- bench_stats_asym_finish(name, keySize * 8, desc[4],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- if (ret < 0) {
- goto exit;
- }
- #ifdef HAVE_ECC_VERIFY
- /* ECC Verify */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
- ×, agreeTimes, &pending)) {
- if (genKey[i]->state == 0) {
- verify[i] = 0;
- }
- ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
- (word32)keySize, &verify[i],
- genKey[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]),
- 1, ×,
- &pending)) {
- goto exit_ecdsa_verify;
- }
- } /* if bench_async_check */
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_ecdsa_verify:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
- wc_ecc_get_name(curveId));
- bench_stats_asym_finish(name, keySize * 8, desc[5],
- useDeviceID, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_ECC_VERIFY */
- #endif /* !NO_ASN && HAVE_ECC_SIGN */
- exit:
- /* cleanup */
- if (WC_ARRAY_OK(genKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++)
- wc_ecc_free(genKey[i]);
- WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #ifdef HAVE_ECC_DHE
- if (WC_ARRAY_OK(genKey2)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++)
- wc_ecc_free(genKey2[i]);
- WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- #ifdef HAVE_ECC_DHE
- WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- #endif
- (void)useDeviceID;
- (void)pending;
- (void)x;
- (void)count;
- (void)times;
- (void)desc;
- (void)start;
- (void)name;
- }
- #ifdef HAVE_ECC_ENCRYPT
- void bench_eccEncrypt(int curveId)
- {
- #define BENCH_ECCENCRYPT_MSG_SIZE 48
- #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
- WC_SHA256_DIGEST_SIZE + \
- (MAX_ECC_BITS+3)/4 + 2)
- word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
- #ifdef WOLFSSL_SMALL_STACK
- ecc_key *userA = NULL, *userB = NULL;
- byte *msg = NULL;
- byte *out = NULL;
- #else
- ecc_key userA[1], userB[1];
- byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
- byte out[BENCH_ECCENCRYPT_OUT_SIZE];
- #endif
- char name[BENCH_ECC_NAME_SZ];
- int keySize;
- word32 bench_plainSz = bench_size;
- int ret, i, count;
- double start;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifdef WOLFSSL_SMALL_STACK
- userA = (ecc_key *)XMALLOC(sizeof(*userA),
- HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- userB = (ecc_key *)XMALLOC(sizeof(*userB),
- HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
- HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- out = (byte *)XMALLOC(outSz,
- HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if ((! userA) || (! userB) || (! msg) || (! out)) {
- printf("bench_eccEncrypt malloc failed\n");
- goto exit;
- }
- #endif
- keySize = wc_ecc_get_curve_size_from_id(curveId);
- ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
- if (ret != 0) {
- printf("wc_ecc_encrypt make key A failed: %d\n", ret);
- goto exit;
- }
- ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
- if (ret != 0) {
- printf("wc_ecc_encrypt make key B failed: %d\n", ret);
- goto exit;
- }
- #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
- (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
- !defined(HAVE_SELFTEST)
- ret = wc_ecc_set_rng(userA, &gRng);
- if (ret != 0) {
- goto exit;
- }
- ret = wc_ecc_set_rng(userB, &gRng);
- if (ret != 0) {
- goto exit;
- }
- #endif
- ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
- #ifdef WOLFSSL_ASYNC_CRYPT
- ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
- #endif
- if (ret != 0)
- goto exit;
- ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
- #ifdef WOLFSSL_ASYNC_CRYPT
- ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
- #endif
- if (ret != 0)
- goto exit;
- for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
- msg[i] = (byte)i;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < ntimes; i++) {
- /* encrypt msg to B */
- ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
- out, &outSz, NULL);
- if (ret != 0) {
- printf("wc_ecc_encrypt failed! %d\n", ret);
- goto exit_enc;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_enc:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
- wc_ecc_get_name(curveId));
- bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- if (ret != 0)
- goto exit;
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < ntimes; i++) {
- /* decrypt msg from A */
- ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
- &bench_plainSz, NULL);
- if (ret != 0) {
- printf("wc_ecc_decrypt failed! %d\n", ret);
- goto exit_dec;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_dec:
- bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- /* cleanup */
- #ifdef WOLFSSL_SMALL_STACK
- if (userA) {
- wc_ecc_free(userA);
- XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- }
- if (userB) {
- wc_ecc_free(userB);
- XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- }
- XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- #else
- wc_ecc_free(userB);
- wc_ecc_free(userA);
- #endif
- }
- #endif
- #ifdef WOLFSSL_SM2
- static void bench_sm2_MakeKey(int useDeviceID)
- {
- int ret = 0, i, times, count = 0, pending = 0;
- int deviceID;
- int keySize;
- WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- char name[BENCH_ECC_NAME_SZ];
- double start = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- deviceID = useDeviceID ? devId : INVALID_DEVID;
- keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
- WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- /* ECC Make Key */
- bench_stats_start(&count, &start);
- do {
- /* while free pending slots in queue, submit ops */
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
- ×, agreeTimes, &pending)) {
- wc_ecc_free(genKey[i]);
- ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
- if (ret < 0) {
- goto exit;
- }
- ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
- WC_ECC_FLAG_NONE);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 0, ×,
- &pending)) {
- goto exit;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
- wc_ecc_get_name(ECC_SM2P256V1));
- bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- /* cleanup */
- if (WC_ARRAY_OK(genKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- wc_ecc_free(genKey[i]);
- }
- WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- }
- void bench_sm2(int useDeviceID)
- {
- int ret = 0, i, times, count, pending = 0;
- int deviceID;
- int keySize;
- char name[BENCH_ECC_NAME_SZ];
- WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #ifdef HAVE_ECC_DHE
- WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- #ifdef HAVE_ECC_VERIFY
- int verify[BENCH_MAX_PENDING];
- #endif
- #endif
- word32 x[BENCH_MAX_PENDING];
- double start = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- #ifdef HAVE_ECC_DHE
- WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
- WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- #ifdef HAVE_ECC_DHE
- WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
- WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
- #endif
- deviceID = useDeviceID ? devId : INVALID_DEVID;
- bench_sm2_MakeKey(useDeviceID);
- WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #ifdef HAVE_ECC_DHE
- WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
- sizeof(ecc_key), HEAP_HINT);
- #endif
- keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
- /* init keys */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- /* setup an context for each key */
- if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
- goto exit;
- }
- ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
- #ifdef WOLFSSL_ASYNC_CRYPT
- ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
- #endif
- if (ret < 0) {
- goto exit;
- }
- #ifdef HAVE_ECC_DHE
- if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
- goto exit;
- }
- if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
- WC_ECC_FLAG_NONE)) > 0) {
- goto exit;
- }
- #endif
- }
- #ifdef HAVE_ECC_DHE
- #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
- (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
- !defined(HAVE_SELFTEST)
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- (void)wc_ecc_set_rng(genKey[i], &gRng);
- }
- #endif
- /* ECC Shared Secret */
- bench_stats_start(&count, &start);
- PRIVATE_KEY_UNLOCK();
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
- ×, agreeTimes, &pending)) {
- x[i] = (word32)keySize;
- ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
- shared[i], &x[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
- &pending)) {
- goto exit_ecdhe;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- PRIVATE_KEY_UNLOCK();
- exit_ecdhe:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
- wc_ecc_get_name(ECC_SM2P256V1));
- bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret < 0) {
- goto exit;
- }
- #endif /* HAVE_ECC_DHE */
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- /* Init digest to sign */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- for (count = 0; count < keySize; count++) {
- digest[i][count] = (byte)count;
- }
- }
- RESET_MULTI_VALUE_STATS_VARS();
- /* ECC Sign */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
- ×, agreeTimes, &pending)) {
- if (genKey[i]->state == 0)
- x[i] = ECC_MAX_SIG_SIZE;
- ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
- sig[i], &x[i], &gRng, genKey[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
- &pending)) {
- goto exit_ecdsa_sign;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_ecdsa_sign:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
- wc_ecc_get_name(ECC_SM2P256V1));
- bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- if (ret < 0) {
- goto exit;
- }
- #ifdef HAVE_ECC_VERIFY
- /* ECC Verify */
- bench_stats_start(&count, &start);
- do {
- for (times = 0; times < agreeTimes || pending > 0; ) {
- bench_async_poll(&pending);
- /* while free pending slots in queue, submit ops */
- for (i = 0; i < BENCH_MAX_PENDING; i++) {
- if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
- ×, agreeTimes, &pending)) {
- if (genKey[i]->state == 0)
- verify[i] = 0;
- ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
- (word32)keySize, &verify[i], genKey[i]);
- if (!bench_async_handle(&ret,
- BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
- &pending)) {
- goto exit_ecdsa_verify;
- }
- }
- } /* for i */
- RECORD_MULTI_VALUE_STATS();
- } /* for times */
- count += times;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_ecdsa_verify:
- (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
- wc_ecc_get_name(ECC_SM2P256V1));
- bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_ECC_VERIFY */
- #endif /* !NO_ASN && HAVE_ECC_SIGN */
- exit:
- /* cleanup */
- if (WC_ARRAY_OK(genKey)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++)
- wc_ecc_free(genKey[i]);
- WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #ifdef HAVE_ECC_DHE
- if (WC_ARRAY_OK(genKey2)) {
- for (i = 0; i < BENCH_MAX_PENDING; i++)
- wc_ecc_free(genKey2[i]);
- WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
- }
- #endif
- #ifdef HAVE_ECC_DHE
- WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
- #endif
- #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
- WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
- WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
- #endif
- (void)useDeviceID;
- (void)pending;
- (void)x;
- (void)count;
- (void)times;
- (void)desc;
- (void)start;
- (void)name;
- }
- #endif /* WOLFSSL_SM2 */
- #endif /* HAVE_ECC */
- #ifdef HAVE_CURVE25519
- void bench_curve25519KeyGen(int useDeviceID)
- {
- curve25519_key genKey;
- double start;
- int ret = 0, i, count;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- /* Key Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- if (ret != 0) {
- printf("wc_curve25519_init_ex failed: %d\n", ret);
- break;
- }
- ret = wc_curve25519_make_key(&gRng, 32, &genKey);
- wc_curve25519_free(&genKey);
- if (ret != 0) {
- printf("wc_curve25519_make_key failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
- ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #ifdef HAVE_CURVE25519_SHARED_SECRET
- void bench_curve25519KeyAgree(int useDeviceID)
- {
- curve25519_key genKey, genKey2;
- double start;
- int ret, i, count;
- byte shared[32];
- const char**desc = bench_desc_words[lng_index];
- word32 x = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- wc_curve25519_init_ex(&genKey, HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- wc_curve25519_init_ex(&genKey2, HEAP_HINT,
- useDeviceID ? devId : INVALID_DEVID);
- ret = wc_curve25519_make_key(&gRng, 32, &genKey);
- if (ret != 0) {
- printf("curve25519_make_key failed\n");
- return;
- }
- ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
- if (ret != 0) {
- printf("curve25519_make_key failed: %d\n", ret);
- wc_curve25519_free(&genKey);
- return;
- }
- /* Shared secret */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- x = sizeof(shared);
- ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
- if (ret != 0) {
- printf("curve25519_shared_secret failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
- ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_curve25519_free(&genKey2);
- wc_curve25519_free(&genKey);
- }
- #endif /* HAVE_CURVE25519_SHARED_SECRET */
- #endif /* HAVE_CURVE25519 */
- #ifdef HAVE_ED25519
- void bench_ed25519KeyGen(void)
- {
- #ifdef HAVE_ED25519_MAKE_KEY
- ed25519_key genKey;
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- /* Key Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- wc_ed25519_init(&genKey);
- (void)wc_ed25519_make_key(&gRng, 32, &genKey);
- wc_ed25519_free(&genKey);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_ED25519_MAKE_KEY */
- }
- void bench_ed25519KeySign(void)
- {
- #ifdef HAVE_ED25519_MAKE_KEY
- int ret;
- #endif
- ed25519_key genKey;
- #ifdef HAVE_ED25519_SIGN
- double start;
- int i, count;
- byte sig[ED25519_SIG_SIZE];
- byte msg[512];
- word32 x = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- #endif
- wc_ed25519_init(&genKey);
- #ifdef HAVE_ED25519_MAKE_KEY
- ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
- if (ret != 0) {
- printf("ed25519_make_key failed\n");
- return;
- }
- #endif
- #ifdef HAVE_ED25519_SIGN
- /* make dummy msg */
- for (i = 0; i < (int)sizeof(msg); i++)
- msg[i] = (byte)i;
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- x = sizeof(sig);
- ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
- if (ret != 0) {
- printf("ed25519_sign_msg failed\n");
- goto exit_ed_sign;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_ed_sign:
- bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- #ifdef HAVE_ED25519_VERIFY
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- int verify = 0;
- ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
- &genKey);
- if (ret != 0 || verify != 1) {
- printf("ed25519_verify_msg failed\n");
- goto exit_ed_verify;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit_ed_verify:
- bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_ED25519_VERIFY */
- #endif /* HAVE_ED25519_SIGN */
- wc_ed25519_free(&genKey);
- }
- #endif /* HAVE_ED25519 */
- #ifdef HAVE_CURVE448
- void bench_curve448KeyGen(void)
- {
- curve448_key genKey;
- double start;
- int ret = 0, i, count;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- /* Key Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_curve448_make_key(&gRng, 56, &genKey);
- wc_curve448_free(&genKey);
- if (ret != 0) {
- printf("wc_curve448_make_key failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #ifdef HAVE_CURVE448_SHARED_SECRET
- void bench_curve448KeyAgree(void)
- {
- curve448_key genKey, genKey2;
- double start;
- int ret, i, count;
- byte shared[56];
- const char**desc = bench_desc_words[lng_index];
- word32 x = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- wc_curve448_init(&genKey);
- wc_curve448_init(&genKey2);
- ret = wc_curve448_make_key(&gRng, 56, &genKey);
- if (ret != 0) {
- printf("curve448_make_key failed\n");
- return;
- }
- ret = wc_curve448_make_key(&gRng, 56, &genKey2);
- if (ret != 0) {
- printf("curve448_make_key failed: %d\n", ret);
- wc_curve448_free(&genKey);
- return;
- }
- /* Shared secret */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- x = sizeof(shared);
- ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
- if (ret != 0) {
- printf("curve448_shared_secret failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- exit:
- bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_curve448_free(&genKey2);
- wc_curve448_free(&genKey);
- }
- #endif /* HAVE_CURVE448_SHARED_SECRET */
- #endif /* HAVE_CURVE448 */
- #ifdef HAVE_ED448
- void bench_ed448KeyGen(void)
- {
- ed448_key genKey;
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- /* Key Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- wc_ed448_init(&genKey);
- (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
- wc_ed448_free(&genKey);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- void bench_ed448KeySign(void)
- {
- int ret;
- WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
- #ifdef HAVE_ED448_SIGN
- double start;
- int i, count;
- byte sig[ED448_SIG_SIZE];
- byte msg[512];
- word32 x = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- #endif
- WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
- wc_ed448_init(genKey);
- ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
- if (ret != 0) {
- printf("ed448_make_key failed\n");
- goto exit;
- }
- #ifdef HAVE_ED448_SIGN
- /* make dummy msg */
- for (i = 0; i < (int)sizeof(msg); i++)
- msg[i] = (byte)i;
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- x = sizeof(sig);
- ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
- NULL, 0);
- if (ret != 0) {
- printf("ed448_sign_msg failed\n");
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- #ifdef HAVE_ED448_VERIFY
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- int verify = 0;
- ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
- genKey, NULL, 0);
- if (ret != 0 || verify != 1) {
- printf("ed448_verify_msg failed\n");
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- #endif /* HAVE_ED448_VERIFY */
- #endif /* HAVE_ED448_SIGN */
- exit:
- wc_ed448_free(genKey);
- WC_FREE_VAR(genKey, HEAP_HINT);
- }
- #endif /* HAVE_ED448 */
- #ifdef WOLFCRYPT_HAVE_ECCSI
- #ifdef WOLFCRYPT_ECCSI_KMS
- void bench_eccsiKeyGen(void)
- {
- WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- int ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- /* Key Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
- ret = wc_MakeEccsiKey(genKey, &gRng);
- wc_FreeEccsiKey(genKey);
- if (ret != 0) {
- printf("wc_MakeEccsiKey failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- }
- void bench_eccsiPairGen(void)
- {
- WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
- ecc_point* pvt;
- static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
- int ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
- (void)mp_init(ssk);
- pvt = wc_ecc_new_point();
- wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
- (void)wc_MakeEccsiKey(genKey, &gRng);
- /* RSK Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
- sizeof(id), ssk, pvt);
- if (ret != 0) {
- printf("wc_MakeEccsiPair failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeEccsiKey(genKey);
- wc_ecc_del_point(pvt);
- mp_free(ssk);
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- WC_FREE_VAR(ssk, HEAP_HINT);
- }
- #endif
- #ifdef WOLFCRYPT_ECCSI_CLIENT
- void bench_eccsiValidate(void)
- {
- WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
- ecc_point* pvt;
- static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
- int valid;
- int ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
- (void)mp_init(ssk);
- pvt = wc_ecc_new_point();
- wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
- (void)wc_MakeEccsiKey(genKey, &gRng);
- (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
- ssk, pvt);
- /* Validation of RSK */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
- sizeof(id), ssk, pvt, &valid);
- if (ret != 0 || !valid) {
- printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
- valid);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeEccsiKey(genKey);
- wc_ecc_del_point(pvt);
- mp_free(ssk);
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- WC_FREE_VAR(ssk, HEAP_HINT);
- }
- void bench_eccsi(void)
- {
- WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
- ecc_point* pvt;
- static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
- static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
- byte hash[WC_SHA256_DIGEST_SIZE];
- byte hashSz = (byte)sizeof(hash);
- byte sig[257];
- word32 sigSz = sizeof(sig);
- int ret;
- int verified;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
- WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
- (void)mp_init(ssk);
- pvt = wc_ecc_new_point();
- (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
- (void)wc_MakeEccsiKey(genKey, &gRng);
- (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
- ssk, pvt);
- (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
- hash, &hashSz);
- (void)wc_SetEccsiHash(genKey, hash, hashSz);
- (void)wc_SetEccsiPair(genKey, ssk, pvt);
- /* Encapsulate */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
- sizeof(msg), sig, &sigSz);
- if (ret != 0) {
- printf("wc_SignEccsiHash failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- /* Derive */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
- sizeof(msg), sig, sigSz, &verified);
- if (ret != 0 || !verified) {
- printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
- verified);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeEccsiKey(genKey);
- wc_ecc_del_point(pvt);
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- WC_FREE_VAR(ssk, HEAP_HINT);
- }
- #endif /* WOLFCRYPT_ECCSI_CLIENT */
- #endif /* WOLFCRYPT_HAVE_ECCSI */
- #ifdef WOLFCRYPT_HAVE_SAKKE
- #ifdef WOLFCRYPT_SAKKE_KMS
- void bench_sakkeKeyGen(void)
- {
- WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- int ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- /* Key Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
- ret = wc_MakeSakkeKey(genKey, &gRng);
- if (ret != 0) {
- printf("wc_MakeSakkeKey failed: %d\n", ret);
- goto exit;
- }
- wc_FreeSakkeKey(genKey);
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- }
- void bench_sakkeRskGen(void)
- {
- WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- ecc_point* rsk;
- static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
- int ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- rsk = wc_ecc_new_point();
- wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
- (void)wc_MakeSakkeKey(genKey, &gRng);
- /* RSK Gen */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
- if (ret != 0) {
- printf("wc_MakeSakkeRsk failed: %d\n", ret);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeSakkeKey(genKey);
- wc_ecc_del_point(rsk);
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- }
- #endif
- #ifdef WOLFCRYPT_SAKKE_CLIENT
- void bench_sakkeValidate(void)
- {
- WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- ecc_point* rsk;
- static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
- int valid;
- int ret;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- rsk = wc_ecc_new_point();
- (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
- (void)wc_MakeSakkeKey(genKey, &gRng);
- (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
- (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
- /* Validation of RSK */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
- if (ret != 0 || !valid) {
- printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
- valid);
- goto exit;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeSakkeKey(genKey);
- wc_ecc_del_point(rsk);
- exit:
- WC_FREE_VAR(genKey, HEAP_HINT);
- }
- void bench_sakke(void)
- {
- WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- double start;
- int i, count;
- const char**desc = bench_desc_words[lng_index];
- ecc_point* rsk;
- static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
- static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
- byte ssv[sizeof(ssv_init)];
- byte derSSV[sizeof(ssv)];
- byte auth[257];
- word16 authSz = sizeof(auth);
- int ret = 0;
- byte* table = NULL;
- word32 len = 0;
- byte* iTable = NULL;
- word32 iTableLen = 0;
- DECLARE_MULTI_VALUE_STATS_VARS()
- WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
- XMEMCPY(ssv, ssv_init, sizeof ssv);
- rsk = wc_ecc_new_point();
- (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
- (void)wc_MakeSakkeKey(genKey, &gRng);
- (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
- (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
- (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
- /* Encapsulate */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_MakeSakkeEncapsulatedSSV(genKey,
- WC_HASH_TYPE_SHA256,
- ssv, sizeof(ssv), auth, &authSz);
- if (ret != 0) {
- printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- } /* for */
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
- 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- /* Derive */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- XMEMCPY(derSSV, ssv, sizeof(ssv));
- ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
- sizeof(derSSV), auth, authSz);
- if (ret != 0) {
- printf("wc_DeriveSakkeSSV failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- if (ret != 0) break;
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
- 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- /* Calculate Point I and generate table. */
- (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
- iTableLen = 0;
- (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
- if (iTableLen != 0) {
- iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (iTable == NULL)
- WC_ALLOC_DO_ON_FAILURE();
- (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
- }
- /* Encapsulate with Point I table */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- ret = wc_MakeSakkeEncapsulatedSSV(genKey,
- WC_HASH_TYPE_SHA256, ssv,
- sizeof(ssv), auth, &authSz);
- if (ret != 0) {
- printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
- count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- (void)wc_SetSakkeRsk(genKey, rsk, table, len);
- /* Derive with Point I table */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- XMEMCPY(derSSV, ssv, sizeof(ssv));
- ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
- sizeof(derSSV), auth, authSz);
- if (ret != 0) {
- printf("wc_DeriveSakkeSSV failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- if (ret != 0) break;
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
- count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- len = 0;
- (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
- if (len > 0) {
- table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- if (table == NULL)
- WC_ALLOC_DO_ON_FAILURE();
- (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
- }
- (void)wc_SetSakkeRsk(genKey, rsk, table, len);
- /* Derive with Point I table and RSK table */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- XMEMCPY(derSSV, ssv, sizeof(ssv));
- ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
- sizeof(derSSV), auth, authSz);
- if (ret != 0) {
- printf("wc_DeriveSakkeSSV failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- if (ret != 0) break;
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
- 0, count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- RESET_MULTI_VALUE_STATS_VARS();
- wc_ClearSakkePointITable(genKey);
- /* Derive with RSK table */
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < genTimes; i++) {
- XMEMCPY(derSSV, ssv, sizeof(ssv));
- ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
- sizeof(derSSV), auth, authSz);
- if (ret != 0) {
- printf("wc_DeriveSakkeSSV failed: %d\n", ret);
- break;
- }
- RECORD_MULTI_VALUE_STATS();
- }
- if (ret != 0) break;
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
- count, start, 0);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- wc_FreeSakkeKey(genKey);
- wc_ecc_del_point(rsk);
- exit:
- XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
- WC_FREE_VAR(genKey, HEAP_HINT);
- }
- #endif /* WOLFCRYPT_SAKKE_CLIENT */
- #endif /* WOLFCRYPT_HAVE_SAKKE */
- #ifdef HAVE_FALCON
- void bench_falconKeySign(byte level)
- {
- int ret = 0;
- falcon_key key;
- double start;
- int i, count;
- byte sig[FALCON_MAX_SIG_SIZE];
- byte msg[512];
- word32 x = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_falcon_init(&key);
- if (ret != 0) {
- printf("wc_falcon_init failed %d\n", ret);
- return;
- }
- ret = wc_falcon_set_level(&key, level);
- if (ret != 0) {
- printf("wc_falcon_set_level failed %d\n", ret);
- }
- if (ret == 0) {
- if (level == 1) {
- ret = wc_falcon_import_private_key(bench_falcon_level1_key,
- sizeof_bench_falcon_level1_key,
- NULL, 0, &key);
- }
- else {
- ret = wc_falcon_import_private_key(bench_falcon_level5_key,
- sizeof_bench_falcon_level5_key,
- NULL, 0, &key);
- }
- if (ret != 0) {
- printf("wc_falcon_import_private_key failed %d\n", ret);
- }
- }
- /* make dummy msg */
- for (i = 0; i < (int)sizeof(msg); i++) {
- msg[i] = (byte)i;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- if (ret == 0) {
- if (level == 1) {
- x = FALCON_LEVEL1_SIG_SIZE;
- }
- else {
- x = FALCON_LEVEL5_SIG_SIZE;
- }
- ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
- if (ret != 0) {
- printf("wc_falcon_sign_msg failed\n");
- }
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- bench_stats_asym_finish("FALCON", level, desc[4], 0,
- count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- if (ret == 0) {
- int verify = 0;
- ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
- &key);
- if (ret != 0 || verify != 1) {
- printf("wc_falcon_verify_msg failed %d, verify %d\n",
- ret, verify);
- ret = -1;
- }
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- bench_stats_asym_finish("FALCON", level, desc[5],
- 0, count, start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- wc_falcon_free(&key);
- }
- #endif /* HAVE_FALCON */
- #ifdef HAVE_DILITHIUM
- #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
- #ifndef WOLFSSL_NO_ML_DSA_44
- static const unsigned char bench_dilithium_level2_sig[] = {
- 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
- 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
- 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
- 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
- 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x3e, 0x62, 0x67,
- 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
- 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
- 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
- 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
- 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
- };
- static const int sizeof_bench_dilithium_level2_sig =
- sizeof(bench_dilithium_level2_sig);
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_65
- static const unsigned char bench_dilithium_level3_sig[] = {
- 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
- 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
- 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
- 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
- 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
- 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
- 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
- 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
- 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
- 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22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- };
- static const int sizeof_bench_dilithium_level3_sig =
- sizeof(bench_dilithium_level3_sig);
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_87
- static const unsigned char bench_dilithium_level5_sig[] = {
- 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
- 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
- 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
- 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
- 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
- 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
- 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
- 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
- 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
- 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
- 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
- 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
- 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
- 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
- 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
- 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
- 0xff, 0x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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
- 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
- };
- static const int sizeof_bench_dilithium_level5_sig =
- sizeof(bench_dilithium_level5_sig);
- #endif
- #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
- void bench_dilithiumKeySign(byte level)
- {
- int ret = 0;
- dilithium_key key;
- double start;
- int i, count;
- #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
- byte sig[DILITHIUM_MAX_SIG_SIZE];
- byte msg[512];
- word32 x = 0;
- #endif
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- byte params = 0;
- if (level == 2) {
- params = 44;
- }
- else if (level == 3) {
- params = 65;
- }
- else if (level == 5) {
- params = 87;
- }
- #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
- /* make dummy msg */
- for (i = 0; i < (int)sizeof(msg); i++) {
- msg[i] = (byte)i;
- }
- #endif
- ret = wc_dilithium_init(&key);
- if (ret != 0) {
- printf("wc_dilithium_init failed %d\n", ret);
- return;
- }
- ret = wc_dilithium_set_level(&key, level);
- if (ret != 0) {
- printf("wc_dilithium_set_level() failed %d\n", ret);
- }
- #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
- if (ret != 0) {
- printf("wc_dilithium_import_private_key failed %d\n", ret);
- return;
- }
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
- start, ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
- #ifndef WOLFSSL_NO_ML_DSA_44
- if (level == 2) {
- ret = wc_dilithium_import_private(bench_dilithium_level2_key,
- sizeof_bench_dilithium_level2_key, &key);
- }
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_65
- if (level == 3) {
- ret = wc_dilithium_import_private(bench_dilithium_level3_key,
- sizeof_bench_dilithium_level3_key, &key);
- }
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_87
- if (level == 5) {
- ret = wc_dilithium_import_private(bench_dilithium_level5_key,
- sizeof_bench_dilithium_level5_key, &key);
- }
- #endif
- if (ret != 0) {
- printf("Failed to load private key\n");
- return;
- }
- #endif
- #ifndef WOLFSSL_DILITHIUM_NO_SIGN
- if (level == 2) {
- x = DILITHIUM_LEVEL2_SIG_SIZE;
- }
- else if (level == 3) {
- x = DILITHIUM_LEVEL3_SIG_SIZE;
- }
- else {
- x = DILITHIUM_LEVEL5_SIG_SIZE;
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- if (ret == 0) {
- ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
- GLOBAL_RNG);
- if (ret != 0) {
- printf("wc_dilithium_sign_msg failed\n");
- }
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
- ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
- (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
- defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
- #ifndef WOLFSSL_NO_ML_DSA_44
- if (level == 2) {
- #ifdef WOLFSSL_DILITHIUM_NO_SIGN
- x = sizeof_bench_dilithium_level2_sig;
- XMEMCPY(sig, bench_dilithium_level2_sig, x);
- #endif
- ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
- sizeof_bench_dilithium_level2_pubkey, &key);
- }
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_65
- if (level == 3) {
- #ifdef WOLFSSL_DILITHIUM_NO_SIGN
- x = sizeof_bench_dilithium_level3_sig;
- XMEMCPY(sig, bench_dilithium_level3_sig, x);
- #endif
- ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
- sizeof_bench_dilithium_level3_pubkey, &key);
- }
- #endif
- #ifndef WOLFSSL_NO_ML_DSA_87
- if (level == 5) {
- #ifdef WOLFSSL_DILITHIUM_NO_SIGN
- x = sizeof_bench_dilithium_level5_sig;
- XMEMCPY(sig, bench_dilithium_level5_sig, x);
- #endif
- ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
- sizeof_bench_dilithium_level5_pubkey, &key);
- }
- #endif
- if (ret != 0) {
- printf("Failed to load public key\n");
- return;
- }
- #endif
- #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- if (ret == 0) {
- int verify = 0;
- ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
- &verify, &key);
- if (ret != 0 || verify != 1) {
- printf("wc_dilithium_verify_msg failed %d, verify %d\n",
- ret, verify);
- ret = -1;
- }
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
- ret);
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- #endif
- wc_dilithium_free(&key);
- }
- #endif /* HAVE_DILITHIUM */
- #ifdef HAVE_SPHINCS
- void bench_sphincsKeySign(byte level, byte optim)
- {
- int ret = 0;
- sphincs_key key;
- double start;
- int i, count;
- byte sig[SPHINCS_MAX_SIG_SIZE];
- byte msg[512];
- word32 x = 0;
- const char**desc = bench_desc_words[lng_index];
- DECLARE_MULTI_VALUE_STATS_VARS()
- ret = wc_sphincs_init(&key);
- if (ret != 0) {
- printf("wc_sphincs_init failed %d\n", ret);
- return;
- }
- ret = wc_sphincs_set_level_and_optim(&key, level, optim);
- if (ret != 0) {
- printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
- }
- if (ret == 0) {
- ret = -1;
- if ((level == 1) && (optim == FAST_VARIANT)) {
- ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
- sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
- }
- else if ((level == 3) && (optim == FAST_VARIANT)) {
- ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
- sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
- }
- else if ((level == 5) && (optim == FAST_VARIANT)) {
- ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
- sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
- }
- else if ((level == 1) && (optim == SMALL_VARIANT)) {
- ret = wc_sphincs_import_private_key(
- bench_sphincs_small_level1_key,
- sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
- }
- else if ((level == 3) && (optim == SMALL_VARIANT)) {
- ret = wc_sphincs_import_private_key(
- bench_sphincs_small_level3_key,
- sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
- }
- else if ((level == 5) && (optim == SMALL_VARIANT)) {
- ret = wc_sphincs_import_private_key(
- bench_sphincs_small_level5_key,
- sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
- }
- if (ret != 0) {
- printf("wc_sphincs_import_private_key failed %d\n", ret);
- }
- }
- /* make dummy msg */
- for (i = 0; i < (int)sizeof(msg); i++) {
- msg[i] = (byte)i;
- }
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- if (ret == 0) {
- if ((level == 1) && (optim == FAST_VARIANT)) {
- x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
- }
- else if ((level == 3) && (optim == FAST_VARIANT)) {
- x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
- }
- else if ((level == 5) && (optim == FAST_VARIANT)) {
- x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
- }
- else if ((level == 1) && (optim == SMALL_VARIANT)) {
- x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
- }
- else if ((level == 3) && (optim == SMALL_VARIANT)) {
- x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
- }
- else if ((level == 5) && (optim == SMALL_VARIANT)) {
- x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
- }
- ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
- if (ret != 0) {
- printf("wc_sphincs_sign_msg failed\n");
- }
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- if (optim == FAST_VARIANT) {
- bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
- start, ret);
- }
- else {
- bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
- start, ret);
- }
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- RESET_MULTI_VALUE_STATS_VARS();
- bench_stats_start(&count, &start);
- do {
- for (i = 0; i < agreeTimes; i++) {
- if (ret == 0) {
- int verify = 0;
- ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
- &key);
- if (ret != 0 || verify != 1) {
- printf("wc_sphincs_verify_msg failed %d, verify %d\n",
- ret, verify);
- ret = -1;
- }
- }
- RECORD_MULTI_VALUE_STATS();
- }
- count += i;
- } while (bench_stats_check(start)
- #ifdef MULTI_VALUE_STATISTICS
- || runs < minimum_runs
- #endif
- );
- if (ret == 0) {
- if (optim == FAST_VARIANT) {
- bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
- start, ret);
- }
- else {
- bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
- start, ret);
- }
- #ifdef MULTI_VALUE_STATISTICS
- bench_multi_value_stats(max, min, sum, squareSum, runs);
- #endif
- }
- wc_sphincs_free(&key);
- }
- #endif /* HAVE_SPHINCS */
- #if defined(_WIN32) && !defined(INTIME_RTOS)
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- double current_time(int reset)
- {
- static int init = 0;
- static LARGE_INTEGER freq;
- LARGE_INTEGER count;
- (void)reset;
- if (!init) {
- QueryPerformanceFrequency(&freq);
- init = 1;
- }
- QueryPerformanceCounter(&count);
- #ifdef BENCH_MICROSECOND
- return ((double)count.QuadPart * 1000000) / freq.QuadPart;
- #else
- return (double)count.QuadPart / freq.QuadPart;
- #endif
- }
- #elif defined MICROCHIP_PIC32
- #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
- #define CLOCK 80000000.0
- #else
- #define CLOCK 40000000.0
- #endif
- extern void WriteCoreTimer(word32 t);
- extern word32 ReadCoreTimer(void);
- double current_time(int reset)
- {
- unsigned int ns;
- if (reset) {
- WriteCoreTimer(0);
- }
- /* get timer in ns */
- ns = ReadCoreTimer();
- /* return seconds as a double */
- return ( ns / CLOCK * 2.0);
- }
- #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
- defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
- /* declared above at line 239 */
- /* extern double current_time(int reset); */
- #elif defined(FREERTOS)
- #ifdef PLATFORMIO
- #include <freertos/FreeRTOS.h>
- #include <freertos/task.h>
- #else
- #include "task.h"
- #endif
- #if defined(WOLFSSL_ESPIDF)
- /* prototype definition */
- int construct_argv();
- extern char* __argv[22];
- /* current_time(reset)
- *
- * Benchmark passage of time, in fractional seconds.
- * [reset] is non zero to adjust timer or counter to zero
- *
- * Use care when repeatedly calling calling. See implementation. */
- double current_time(int reset)
- {
- double ret;
- #if ESP_IDF_VERSION_MAJOR >= 4
- TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
- #else
- portTickType tickCount;
- #endif
- #if defined(__XTENSA__)
- (void)reset;
- if (reset) {
- /* TODO: Determine a mechanism for reset that does not interfere
- * with freeRTOS tick. Using this code for Xtensa appears to cause
- * RTOS tick timer to stick. See "last_tickCount unchanged".
- ESP_LOGW(TAG, "Current_time() reset!");
- portTICK_TYPE_ENTER_CRITICAL();
- {
- esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
- _esp_cpu_count_last = xthal_get_ccount();
- _esp_cpu_count_last = esp_cpu_get_cycle_count();
- }
- portTICK_TYPE_EXIT_CRITICAL();
- */
- }
- #else
- /* Only reset the CPU counter for RISC-V */
- if (reset) {
- ESP_LOGV(TAG, "current_time() reset!");
- /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
- * unexpected rollovers in return values for Xtensa but not RISC-V?
- * See also esp_get_cycle_count_ex() */
- #ifdef __XTENSA__
- _esp_cpu_count_last = xthal_get_ccount();
- #else
- #if ESP_IDF_VERSION_MAJOR >= 5
- esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
- _esp_cpu_count_last = esp_cpu_get_cycle_count();
- #else
- cpu_hal_set_cycle_count((uint32_t)0);
- _esp_cpu_count_last = cpu_hal_get_cycle_count();
- #endif
- #endif
- }
- #endif
- /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
- tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
- The count of ticks since vTaskStartScheduler was called,
- typiclly in app_startup.c */
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
- if (tickCount == last_tickCount) {
- ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
- }
- if (tickCount < last_tickCount) {
- ESP_LOGW(TAG, "last_tickCount overflow?");
- }
- #endif
- if (reset) {
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
- #endif
- last_tickCount = tickCount;
- }
- else {
- #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
- ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
- #endif
- }
- #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
- ret = (double)tickCount / configTICK_RATE_HZ;
- #else
- ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
- "assuming 1000 Hz.");
- ret = (double)(tickCount / 1000.0);
- #endif /* configTICK_RATE_HZ */
- return ret;
- } /* current_time */
- #else
- /* current_time(reset)
- *
- * Benchmark passage of time, in fractional seconds.
- * [reset] is non zero to adjust timer or counter to zero
- *
- * Use care when repeatedly calling calling. See implementation. */
- double current_time(int reset)
- {
- portTickType tickCount = xTaskGetTickCount();
- /* if configTICK_RATE_HZ is available use if (default is 1000) */
- #ifdef configTICK_RATE_HZ
- return (double)tickCount / configTICK_RATE_HZ;
- #else
- return (double)tickCount / 1000;
- #endif
- }
- #endif
- #elif defined (WOLFSSL_TIRTOS)
- extern double current_time(int reset);
- #elif defined(FREESCALE_MQX)
- double current_time(int reset)
- {
- TIME_STRUCT tv;
- _time_get(&tv);
- return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
- }
- #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
- && defined(MAX3266X_RTC)
- double current_time(int reset)
- {
- (void)reset;
- return wc_MXC_RTC_Time();
- }
- #elif defined(FREESCALE_KSDK_BM)
- double current_time(int reset)
- {
- return (double)OSA_TimeGetMsec() / 1000;
- }
- #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
- double current_time(int reset)
- {
- (void)reset;
- return (double)osKernelGetTickCount() / 1000.0;
- }
- #elif defined(WOLFSSL_EMBOS)
- #include "RTOS.h"
- double current_time(int reset)
- {
- double time_now;
- double current_s = OS_GetTime() / 1000.0;
- double current_us = OS_GetTime_us() / MILLION_VALUE;
- time_now = (double)( current_s + current_us);
- (void) reset;
- return time_now;
- }
- #elif defined(WOLFSSL_SGX)
- double current_time(int reset);
- #elif defined(WOLFSSL_DEOS)
- double current_time(int reset)
- {
- const uint32_t systemTickTimeInHz
- = 1000000 / systemTickInMicroseconds();
- const volatile uint32_t *systemTickPtr = systemTickPointer();
- (void)reset;
- return (double) *systemTickPtr/systemTickTimeInHz;
- }
- #elif defined(MICRIUM)
- double current_time(int reset)
- {
- #if (OS_VERSION < 50000)
- CPU_ERR err;
- (void)reset;
- return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
- #else
- RTOS_ERR err;
- double ret = 0;
- OS_TICK tick = OSTimeGet(&err);
- OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
- (void)reset;
- if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
- ret = ((double)tick)/rate;
- }
- return ret;
- #endif
- }
- #elif defined(WOLFSSL_ZEPHYR)
- #include <time.h>
- double current_time(int reset)
- {
- int64_t t;
- (void)reset;
- #if defined(CONFIG_ARCH_POSIX)
- k_cpu_idle();
- #endif
- t = k_uptime_get(); /* returns current uptime in milliseconds */
- return (double)(t / 1000);
- }
- #elif defined(WOLFSSL_NETBURNER)
- #include <predef.h>
- #include <utils.h>
- #include <constants.h>
- double current_time(int reset)
- {
- DWORD ticks = TimeTick; /* ticks since system start */
- (void)reset;
- return (double) ticks/TICKS_PER_SECOND;
- }
- #elif defined(WOLFSSL_RPIPICO)
- #include "pico/stdlib.h"
- double current_time(int reset)
- {
- (void)reset;
- return (double) time_us_64() / 1000000;
- }
- #elif defined(THREADX)
- #include "tx_api.h"
- double current_time(int reset)
- {
- (void)reset;
- return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
- }
- #elif defined(WOLFSSL_XILINX)
- #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
- #define COUNTS_PER_SECOND \
- XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
- #else
- #define COUNTS_PER_SECOND \
- XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
- #endif
- double current_time(int reset)
- {
- double timer;
- uint64_t cntPct = 0;
- asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
- /* Convert to milliseconds */
- timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
- /* Convert to seconds.millisecond */
- timer /= 1000;
- return timer;
- }
- #elif defined(LINUX_RUSAGE_UTIME)
- #include <sys/time.h>
- #include <sys/resource.h>
- static struct rusage base_rusage;
- static struct rusage cur_rusage;
- double current_time(int reset)
- {
- struct rusage rusage;
- (void)reset;
- LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
- if (reset)
- base_rusage = rusage;
- else
- cur_rusage = rusage;
- /* only consider user time, as system time is host-related overhead
- * outside wolfcrypt.
- */
- return (double)rusage.ru_utime.tv_sec +
- (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
- }
- static void check_for_excessive_stime(const char *desc,
- const char *desc_extra)
- {
- double start_utime = (double)base_rusage.ru_utime.tv_sec +
- (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
- double start_stime = (double)base_rusage.ru_stime.tv_sec +
- (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
- double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
- (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
- double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
- (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
- double stime_utime_ratio =
- (cur_stime - start_stime) / (cur_utime - start_utime);
- if (stime_utime_ratio > .1)
- printf("%swarning, "
- "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
- err_prefix, desc, desc_extra,
- FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
- }
- #elif defined(WOLFSSL_LINUXKM)
- double current_time(int reset)
- {
- (void)reset;
- u64 ns = ktime_get_ns();
- return (double)ns / 1000000000.0;
- }
- #else
- #include <sys/time.h>
- double current_time(int reset)
- {
- struct timespec tv;
- (void)reset;
- LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
- #ifdef BENCH_MICROSECOND
- return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
- #else
- return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
- #endif
- }
- #endif /* _WIN32 */
- #if defined(HAVE_GET_CYCLES)
- #if defined(WOLFSSL_ESPIDF)
- /* Generic CPU cycle counter for either Xtensa or RISC-V */
- static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
- {
- /* Reminder for long duration between calls with
- * multiple overflows will not be detected. */
- return esp_get_cycle_count_ex();
- }
- /* implement other architectures here */
- #else
- static WC_INLINE word64 get_intel_cycles(void)
- {
- unsigned int lo_c, hi_c;
- __asm__ __volatile__ (
- "cpuid\n\t"
- "rdtsc"
- : "=a"(lo_c), "=d"(hi_c) /* out */
- : "a"(0) /* in */
- : "%ebx", "%ecx"); /* clobber */
- return ((word64)lo_c) | (((word64)hi_c) << 32);
- }
- #endif
- #endif /* HAVE_GET_CYCLES */
- void benchmark_configure(word32 block_size)
- {
- /* must be greater than 0 */
- if (block_size > 0) {
- numBlocks = (int)((word32)numBlocks * bench_size / block_size);
- bench_size = block_size;
- }
- }
- #ifndef NO_MAIN_DRIVER
- #ifndef MAIN_NO_ARGS
- #ifndef WOLFSSL_BENCHMARK_ALL
- /* Display the algorithm string and keep to 80 characters per line.
- *
- * str Algorithm string to print.
- * line Length of line used so far.
- */
- #ifndef BENCH_MAX_LINE
- #define BENCH_MAX_LINE 80
- #endif
- static void print_alg(const char* str, int* line)
- {
- const char* const ident = " ";
- if (*line == 0) {
- printf("%s", ident);
- *line = (int)XSTRLEN(ident);
- }
- printf(" %s", str);
- *line += (int)XSTRLEN(str) + 1;
- if (*line > BENCH_MAX_LINE) {
- printf("\n");
- *line = 0;
- }
- }
- #endif /* WOLFSSL_BENCHMARK_ALL */
- /* Display the usage options of the benchmark program. */
- static void Usage(void)
- {
- int e = 0;
- #ifndef WOLFSSL_BENCHMARK_ALL
- int i;
- int line;
- #endif
- printf("benchmark\n");
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
- #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
- #else
- e += 3;
- #endif
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
- #ifndef NO_RSA
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
- #ifdef WOLFSSL_KEY_GEN
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
- #endif
- e++;
- #else
- e += 2;
- #endif
- #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
- #endif
- e++;
- #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
- #endif
- e++;
- #if defined(HAVE_ECC) && !defined(NO_ECC256)
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
- #endif
- e++;
- #if defined(HAVE_ECC) && defined(HAVE_ECC384)
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
- #endif
- e++;
- #if defined(HAVE_ECC) && defined(HAVE_ECC521)
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
- #endif
- e++;
- #if defined(HAVE_ECC)
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
- #endif
- e++;
- #ifndef WOLFSSL_BENCHMARK_ALL
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
- line = 0;
- for (i=0; bench_cipher_opt[i].str != NULL; i++)
- print_alg(bench_cipher_opt[i].str, &line);
- for (i=0; bench_digest_opt[i].str != NULL; i++)
- print_alg(bench_digest_opt[i].str, &line);
- for (i=0; bench_mac_opt[i].str != NULL; i++)
- print_alg(bench_mac_opt[i].str, &line);
- for (i=0; bench_kdf_opt[i].str != NULL; i++)
- print_alg(bench_kdf_opt[i].str, &line);
- for (i=0; bench_asym_opt[i].str != NULL; i++)
- print_alg(bench_asym_opt[i].str, &line);
- for (i=0; bench_other_opt[i].str != NULL; i++)
- print_alg(bench_other_opt[i].str, &line);
- #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
- defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
- for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
- print_alg(bench_pq_asym_opt[i].str, &line);
- #if defined(HAVE_SPHINCS)
- for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
- print_alg(bench_pq_asym_opt2[i].str, &line);
- #endif /* HAVE_SPHINCS */
- #endif
- #if defined(BENCH_PQ_STATEFUL_HBS)
- for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
- print_alg(bench_pq_hash_sig_opt[i].str, &line);
- #endif /* BENCH_PQ_STATEFUL_HBS */
- printf("\n");
- #endif /* !WOLFSSL_BENCHMARK_ALL */
- e++;
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
- printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
- #ifdef WC_ENABLE_BENCH_THREADING
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
- #endif
- e++;
- #ifdef WC_BENCH_TRACK_STATS
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
- #endif
- e++;
- #ifndef NO_FILESYSTEM
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
- #endif
- e++;
- #ifndef NO_FILESYSTEM
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
- #endif
- #ifdef MULTI_VALUE_STATISTICS
- e++;
- printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
- #endif
- }
- /* Match the command line argument with the string.
- *
- * arg Command line argument.
- * str String to check for.
- * return 1 if the command line argument matches the string, 0 otherwise.
- */
- static int string_matches(const char* arg, const char* str)
- {
- return XSTRCMP(arg, str) == 0;
- }
- #endif /* MAIN_NO_ARGS */
- /*
- ** ----------------------------------------------------------------------------
- ** determine how the benchmarks are called, the function name varies:
- ** ----------------------------------------------------------------------------
- */
- #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
- #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
- /* for some environments, we'll call a function wolf_benchmark_task: */
- int wolf_benchmark_task(void)
- #elif defined(MAIN_NO_ARGS)
- /* otherwise we'll use main() with no arguments as desired: */
- int main()
- #else
- /* else we'll be calling main with default arg parameters */
- int main(int argc, char** argv)
- #endif
- {
- /* Code for main() or wolf_benchmark_task() */
- #ifdef WOLFSSL_ESPIDF
- int argc = construct_argv();
- char** argv = (char**)__argv;
- #elif defined(MAIN_NO_ARGS)
- int argc = 0;
- char** argv = NULL;
- #endif
- return wolfcrypt_benchmark_main(argc, argv);
- }
- #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
- int wolfcrypt_benchmark_main(int argc, char** argv)
- {
- int ret = 0;
- #ifndef MAIN_NO_ARGS
- int optMatched;
- #ifndef WOLFSSL_BENCHMARK_ALL
- int i;
- #endif
- #endif
- benchmark_static_init(1);
- printf("%s------------------------------------------------------------------------------\n",
- info_prefix);
- printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
- printf("%s------------------------------------------------------------------------------\n",
- info_prefix);
- #ifndef MAIN_NO_ARGS
- while (argc > 1) {
- if (string_matches(argv[1], "-?")) {
- if (--argc > 1) {
- lng_index = XATOI((++argv)[1]);
- if (lng_index<0 || lng_index>1) {
- lng_index = 0;
- }
- }
- Usage();
- return 0;
- }
- else if (string_matches(argv[1], "-lng")) {
- argc--;
- argv++;
- if (argc > 1) {
- lng_index = XATOI(argv[1]);
- if (lng_index<0 || lng_index>1) {
- printf("invalid number(%d) is specified. [<num> :0-1]\n",
- lng_index);
- lng_index = 0;
- }
- }
- }
- else if (string_matches(argv[1], "-base10"))
- base2 = 0;
- #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
- else if (string_matches(argv[1], "-no_aad"))
- aes_aad_options = AAD_SIZE_ZERO;
- else if (string_matches(argv[1], "-all_aad"))
- aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
- else if (string_matches(argv[1], "-aad_size")) {
- argc--;
- argv++;
- if (argc > 1) {
- aes_aad_size = (word32)XATOI(argv[1]);
- aes_aad_options |= AAD_SIZE_CUSTOM;
- }
- }
- #endif
- else if (string_matches(argv[1], "-dgst_full"))
- digest_stream = 0;
- #ifdef HAVE_CHACHA
- else if (string_matches(argv[1], "-enc_only"))
- encrypt_only = 1;
- #endif
- #ifndef NO_RSA
- else if (string_matches(argv[1], "-rsa_sign"))
- rsa_sign_verify = 1;
- #endif
- #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
- else if (string_matches(argv[1], "-ffdhe2048"))
- use_ffdhe = 2048;
- #endif
- #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
- else if (string_matches(argv[1], "-ffdhe3072"))
- use_ffdhe = 3072;
- #endif
- #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
- else if (string_matches(argv[1], "-ffdhe4096"))
- use_ffdhe = 4096;
- #endif
- #if defined(HAVE_ECC) && !defined(NO_ECC256)
- else if (string_matches(argv[1], "-p256"))
- bench_asym_algs |= BENCH_ECC_P256;
- #endif
- #if defined(HAVE_ECC) && defined(HAVE_ECC384)
- else if (string_matches(argv[1], "-p384"))
- bench_asym_algs |= BENCH_ECC_P384;
- #endif
- #if defined(HAVE_ECC) && defined(HAVE_ECC521)
- else if (string_matches(argv[1], "-p521"))
- bench_asym_algs |= BENCH_ECC_P521;
- #endif
- #ifdef BENCH_ASYM
- else if (string_matches(argv[1], "-csv")) {
- csv_format = 1;
- }
- #endif
- #ifdef WC_ENABLE_BENCH_THREADING
- else if (string_matches(argv[1], "-threads")) {
- argc--;
- argv++;
- if (argc > 1) {
- g_threadCount = XATOI(argv[1]);
- if (g_threadCount < 1 || lng_index > 128){
- printf("invalid number(%d) is specified. [<num> :1-128]\n",
- g_threadCount);
- g_threadCount = 0;
- }
- }
- }
- #endif
- #ifdef WC_BENCH_TRACK_STATS
- else if (string_matches(argv[1], "-print")) {
- gPrintStats = 1;
- }
- #endif
- else if (string_matches(argv[1], "-blocks")) {
- argc--;
- argv++;
- if (argc > 1)
- numBlocks = XATOI(argv[1]);
- }
- #ifndef NO_FILESYSTEM
- else if (string_matches(argv[1], "-hash_input")) {
- argc--;
- argv++;
- if (argc > 1)
- hash_input = argv[1];
- }
- else if (string_matches(argv[1], "-cipher_input")) {
- argc--;
- argv++;
- if (argc > 1)
- cipher_input = argv[1];
- }
- #endif
- #ifdef MULTI_VALUE_STATISTICS
- else if (string_matches(argv[1], "-min_runs")) {
- argc--;
- argv++;
- if (argc > 1) {
- minimum_runs = XATOI(argv[1]);
- }
- }
- #endif
- else if (argv[1][0] == '-') {
- optMatched = 0;
- #ifndef WOLFSSL_BENCHMARK_ALL
- /* Check known algorithm choosing command line options. */
- /* Known cipher algorithms */
- for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_cipher_opt[i].str)) {
- bench_cipher_algs |= bench_cipher_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- /* Known digest algorithms */
- for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_digest_opt[i].str)) {
- bench_digest_algs |= bench_digest_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- /* Known MAC algorithms */
- for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_mac_opt[i].str)) {
- bench_mac_algs |= bench_mac_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- /* Known KDF algorithms */
- for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_kdf_opt[i].str)) {
- bench_kdf_algs |= bench_kdf_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- /* Known asymmetric algorithms */
- for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_asym_opt[i].str)) {
- bench_asym_algs |= bench_asym_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
- defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
- /* Known asymmetric post-quantum algorithms */
- for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
- bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- #ifdef HAVE_SPHINCS
- /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
- * -pq, so we need to do a special case for -pq since optMatched
- * was set to 1 just above. */
- if ((bench_pq_asym_opt[0].str != NULL) &&
- string_matches(argv[1], bench_pq_asym_opt[0].str))
- {
- bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
- bench_all = 0;
- optMatched = 1;
- }
- for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
- bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- #endif
- #endif
- /* Other known cryptographic algorithms */
- for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_other_opt[i].str)) {
- bench_other_algs |= bench_other_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- #if defined(BENCH_PQ_STATEFUL_HBS)
- /* post-quantum stateful hash-based signatures */
- for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
- if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
- bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
- bench_all = 0;
- optMatched = 1;
- }
- }
- #endif /* BENCH_PQ_STATEFUL_HBS */
- #endif
- if (!optMatched) {
- printf("Option not recognized: %s\n", argv[1]);
- Usage();
- return 1;
- }
- }
- else {
- /* parse for block size */
- benchmark_configure((word32)XATOI(argv[1]));
- }
- argc--;
- argv++;
- }
- #endif /* MAIN_NO_ARGS */
- #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
- /* when defined, we'll always output CSV regardless of params.
- ** this is typically convenient in embedded environments.
- */
- csv_format = 1;
- #endif
- #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
- if (g_threadCount > 1) {
- ret = benchmark_test_threaded(NULL);
- }
- else
- #endif
- {
- #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
- defined(CONFIG_IDF_TARGET_ESP32C3) || \
- defined(CONFIG_IDF_TARGET_ESP32C6)
- {
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- if (esp_gptimer == NULL) {
- ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
- &esp_gptimer) );
- }
- ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
- ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
- ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- }
- #endif
- #ifdef HAVE_STACK_SIZE
- ret = StackSizeCheck(NULL, benchmark_test);
- #else
- ret = benchmark_test(NULL);
- #endif
- }
- #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
- defined(CONFIG_IDF_TARGET_ESP32C3) || \
- defined(CONFIG_IDF_TARGET_ESP32C6)
- {
- #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
- ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
- ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
- #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
- }
- #endif
- return ret;
- }
- #endif /* !NO_MAIN_DRIVER */
- #else
- #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
- int main(void) { return 0; }
- #endif
- #endif /* !NO_CRYPT_BENCHMARK */
|