speed.c 136 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072
  1. /*
  2. * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #undef SECONDS
  11. #define SECONDS 3
  12. #define RSA_SECONDS 10
  13. #define DSA_SECONDS 10
  14. #define ECDSA_SECONDS 10
  15. #define ECDH_SECONDS 10
  16. #define EdDSA_SECONDS 10
  17. #define SM2_SECONDS 10
  18. /* We need to use some deprecated APIs */
  19. #define OPENSSL_SUPPRESS_DEPRECATED
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <math.h>
  24. #include "apps.h"
  25. #include "progs.h"
  26. #include <openssl/crypto.h>
  27. #include <openssl/rand.h>
  28. #include <openssl/err.h>
  29. #include <openssl/evp.h>
  30. #include <openssl/objects.h>
  31. #include <openssl/async.h>
  32. #if !defined(OPENSSL_SYS_MSDOS)
  33. # include <unistd.h>
  34. #endif
  35. #if defined(_WIN32)
  36. # include <windows.h>
  37. #endif
  38. #include <openssl/bn.h>
  39. #ifndef OPENSSL_NO_DES
  40. # include <openssl/des.h>
  41. #endif
  42. #ifndef OPENSSL_NO_DEPRECATED_3_0
  43. #include <openssl/aes.h>
  44. #endif
  45. #ifndef OPENSSL_NO_CAMELLIA
  46. # include <openssl/camellia.h>
  47. #endif
  48. #ifndef OPENSSL_NO_MD2
  49. # include <openssl/md2.h>
  50. #endif
  51. #ifndef OPENSSL_NO_MDC2
  52. # include <openssl/mdc2.h>
  53. #endif
  54. #ifndef OPENSSL_NO_MD4
  55. # include <openssl/md4.h>
  56. #endif
  57. #ifndef OPENSSL_NO_MD5
  58. # include <openssl/md5.h>
  59. #endif
  60. #include <openssl/hmac.h>
  61. #ifndef OPENSSL_NO_CMAC
  62. #include <openssl/cmac.h>
  63. #endif
  64. #include <openssl/sha.h>
  65. #ifndef OPENSSL_NO_RMD160
  66. # include <openssl/ripemd.h>
  67. #endif
  68. #ifndef OPENSSL_NO_WHIRLPOOL
  69. # include <openssl/whrlpool.h>
  70. #endif
  71. #ifndef OPENSSL_NO_RC4
  72. # include <openssl/rc4.h>
  73. #endif
  74. #ifndef OPENSSL_NO_RC5
  75. # include <openssl/rc5.h>
  76. #endif
  77. #ifndef OPENSSL_NO_RC2
  78. # include <openssl/rc2.h>
  79. #endif
  80. #ifndef OPENSSL_NO_IDEA
  81. # include <openssl/idea.h>
  82. #endif
  83. #ifndef OPENSSL_NO_SEED
  84. # include <openssl/seed.h>
  85. #endif
  86. #ifndef OPENSSL_NO_BF
  87. # include <openssl/blowfish.h>
  88. #endif
  89. #ifndef OPENSSL_NO_CAST
  90. # include <openssl/cast.h>
  91. #endif
  92. #ifndef OPENSSL_NO_RSA
  93. # include <openssl/rsa.h>
  94. # include "./testrsa.h"
  95. #endif
  96. #include <openssl/x509.h>
  97. #ifndef OPENSSL_NO_DSA
  98. # include <openssl/dsa.h>
  99. # include "./testdsa.h"
  100. #endif
  101. #ifndef OPENSSL_NO_EC
  102. # include <openssl/ec.h>
  103. #endif
  104. #include <openssl/modes.h>
  105. #ifndef HAVE_FORK
  106. # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
  107. # define HAVE_FORK 0
  108. # else
  109. # define HAVE_FORK 1
  110. # endif
  111. #endif
  112. #if HAVE_FORK
  113. # undef NO_FORK
  114. #else
  115. # define NO_FORK
  116. #endif
  117. #define MAX_MISALIGNMENT 63
  118. #define MAX_ECDH_SIZE 256
  119. #define MISALIGN 64
  120. typedef struct openssl_speed_sec_st {
  121. int sym;
  122. int rsa;
  123. int dsa;
  124. int ecdsa;
  125. int ecdh;
  126. int eddsa;
  127. int sm2;
  128. } openssl_speed_sec_t;
  129. static volatile int run = 0;
  130. static int mr = 0; /* machine-readeable output format to merge fork results */
  131. static int usertime = 1;
  132. static double Time_F(int s);
  133. static void print_message(const char *s, long num, int length, int tm);
  134. static void pkey_print_message(const char *str, const char *str2,
  135. long num, unsigned int bits, int sec);
  136. static void print_result(int alg, int run_no, int count, double time_used);
  137. #ifndef NO_FORK
  138. static int do_multi(int multi, int size_num);
  139. #endif
  140. static const int lengths_list[] = {
  141. 16, 64, 256, 1024, 8 * 1024, 16 * 1024
  142. };
  143. #define SIZE_NUM OSSL_NELEM(lengths_list)
  144. static const int *lengths = lengths_list;
  145. static const int aead_lengths_list[] = {
  146. 2, 31, 136, 1024, 8 * 1024, 16 * 1024
  147. };
  148. #define START 0
  149. #define STOP 1
  150. #ifdef SIGALRM
  151. static void alarmed(int sig)
  152. {
  153. signal(SIGALRM, alarmed);
  154. run = 0;
  155. }
  156. static double Time_F(int s)
  157. {
  158. double ret = app_tminterval(s, usertime);
  159. if (s == STOP)
  160. alarm(0);
  161. return ret;
  162. }
  163. #elif defined(_WIN32)
  164. # define SIGALRM -1
  165. static unsigned int lapse;
  166. static volatile unsigned int schlock;
  167. static void alarm_win32(unsigned int secs)
  168. {
  169. lapse = secs * 1000;
  170. }
  171. # define alarm alarm_win32
  172. static DWORD WINAPI sleepy(VOID * arg)
  173. {
  174. schlock = 1;
  175. Sleep(lapse);
  176. run = 0;
  177. return 0;
  178. }
  179. static double Time_F(int s)
  180. {
  181. double ret;
  182. static HANDLE thr;
  183. if (s == START) {
  184. schlock = 0;
  185. thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
  186. if (thr == NULL) {
  187. DWORD err = GetLastError();
  188. BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
  189. ExitProcess(err);
  190. }
  191. while (!schlock)
  192. Sleep(0); /* scheduler spinlock */
  193. ret = app_tminterval(s, usertime);
  194. } else {
  195. ret = app_tminterval(s, usertime);
  196. if (run)
  197. TerminateThread(thr, 0);
  198. CloseHandle(thr);
  199. }
  200. return ret;
  201. }
  202. #else
  203. static double Time_F(int s)
  204. {
  205. return app_tminterval(s, usertime);
  206. }
  207. #endif
  208. static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
  209. const openssl_speed_sec_t *seconds);
  210. static int opt_found(const char *name, unsigned int *result,
  211. const OPT_PAIR pairs[], unsigned int nbelem)
  212. {
  213. unsigned int idx;
  214. for (idx = 0; idx < nbelem; ++idx, pairs++)
  215. if (strcmp(name, pairs->name) == 0) {
  216. *result = pairs->retval;
  217. return 1;
  218. }
  219. return 0;
  220. }
  221. #define opt_found(value, pairs, result)\
  222. opt_found(value, result, pairs, OSSL_NELEM(pairs))
  223. typedef enum OPTION_choice {
  224. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
  225. OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
  226. OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
  227. OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
  228. } OPTION_CHOICE;
  229. const OPTIONS speed_options[] = {
  230. {OPT_HELP_STR, 1, '-', "Usage: %s [options] [algorithm...]\n"},
  231. OPT_SECTION("General"),
  232. {"help", OPT_HELP, '-', "Display this summary"},
  233. {"mb", OPT_MB, '-',
  234. "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
  235. {"mr", OPT_MR, '-', "Produce machine readable output"},
  236. #ifndef NO_FORK
  237. {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
  238. #endif
  239. #ifndef OPENSSL_NO_ASYNC
  240. {"async_jobs", OPT_ASYNCJOBS, 'p',
  241. "Enable async mode and start specified number of jobs"},
  242. #endif
  243. #ifndef OPENSSL_NO_ENGINE
  244. {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
  245. #endif
  246. {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
  247. OPT_SECTION("Selection"),
  248. {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
  249. {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
  250. #ifndef OPENSSL_NO_CMAC
  251. {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
  252. #endif
  253. {"decrypt", OPT_DECRYPT, '-',
  254. "Time decryption instead of encryption (only EVP)"},
  255. {"aead", OPT_AEAD, '-',
  256. "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
  257. OPT_SECTION("Timing"),
  258. {"elapsed", OPT_ELAPSED, '-',
  259. "Use wall-clock time instead of CPU user time as divisor"},
  260. {"seconds", OPT_SECONDS, 'p',
  261. "Run benchmarks for specified amount of seconds"},
  262. {"bytes", OPT_BYTES, 'p',
  263. "Run [non-PKI] benchmarks on custom-sized buffer"},
  264. {"misalign", OPT_MISALIGN, 'p',
  265. "Use specified offset to mis-align buffers"},
  266. OPT_R_OPTIONS,
  267. OPT_PARAMETERS(),
  268. {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"},
  269. {NULL}
  270. };
  271. enum {
  272. D_MD2, D_MDC2, D_MD4, D_MD5 , D_HMAC, D_SHA1, D_RMD160, D_RC4,
  273. D_CBC_DES, D_EDE3_DES, D_CBC_IDEA, D_CBC_SEED,
  274. D_CBC_RC2, D_CBC_RC5, D_CBC_BF, D_CBC_CAST,
  275. D_CBC_128_AES, D_CBC_192_AES, D_CBC_256_AES,
  276. D_CBC_128_CML, D_CBC_192_CML, D_CBC_256_CML,
  277. D_EVP, D_SHA256, D_SHA512, D_WHIRLPOOL,
  278. D_IGE_128_AES, D_IGE_192_AES, D_IGE_256_AES,
  279. D_GHASH, D_RAND, D_EVP_HMAC, D_EVP_CMAC, ALGOR_NUM
  280. };
  281. /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */
  282. static const char *names[ALGOR_NUM] = {
  283. "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
  284. "des cbc", "des ede3", "idea cbc", "seed cbc",
  285. "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
  286. "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
  287. "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
  288. "evp", "sha256", "sha512", "whirlpool",
  289. "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
  290. "rand", "hmac", "cmac"
  291. };
  292. /* list of configured algorithm (remaining), with some few alias */
  293. static const OPT_PAIR doit_choices[] = {
  294. #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  295. {"md2", D_MD2},
  296. #endif
  297. #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  298. {"mdc2", D_MDC2},
  299. #endif
  300. #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  301. {"md4", D_MD4},
  302. #endif
  303. #ifndef OPENSSL_NO_MD5
  304. {"md5", D_MD5},
  305. {"hmac", D_HMAC},
  306. #endif
  307. {"sha1", D_SHA1},
  308. {"sha256", D_SHA256},
  309. {"sha512", D_SHA512},
  310. #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  311. {"whirlpool", D_WHIRLPOOL},
  312. #endif
  313. #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  314. {"ripemd", D_RMD160},
  315. {"rmd160", D_RMD160},
  316. {"ripemd160", D_RMD160},
  317. #endif
  318. #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  319. {"rc4", D_RC4},
  320. #endif
  321. #ifndef OPENSSL_NO_DES
  322. {"des-cbc", D_CBC_DES},
  323. {"des-ede3", D_EDE3_DES},
  324. #endif
  325. #ifndef OPENSSL_NO_DEPRECATED_3_0
  326. {"aes-128-cbc", D_CBC_128_AES},
  327. {"aes-192-cbc", D_CBC_192_AES},
  328. {"aes-256-cbc", D_CBC_256_AES},
  329. {"aes-128-ige", D_IGE_128_AES},
  330. {"aes-192-ige", D_IGE_192_AES},
  331. {"aes-256-ige", D_IGE_256_AES},
  332. #endif
  333. #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  334. {"rc2-cbc", D_CBC_RC2},
  335. {"rc2", D_CBC_RC2},
  336. #endif
  337. #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  338. {"rc5-cbc", D_CBC_RC5},
  339. {"rc5", D_CBC_RC5},
  340. #endif
  341. #ifndef OPENSSL_NO_IDEA
  342. {"idea-cbc", D_CBC_IDEA},
  343. {"idea", D_CBC_IDEA},
  344. #endif
  345. #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  346. {"seed-cbc", D_CBC_SEED},
  347. {"seed", D_CBC_SEED},
  348. #endif
  349. #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  350. {"bf-cbc", D_CBC_BF},
  351. {"blowfish", D_CBC_BF},
  352. {"bf", D_CBC_BF},
  353. #endif
  354. #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  355. {"cast-cbc", D_CBC_CAST},
  356. {"cast", D_CBC_CAST},
  357. {"cast5", D_CBC_CAST},
  358. #endif
  359. {"ghash", D_GHASH},
  360. {"rand", D_RAND}
  361. };
  362. static double results[ALGOR_NUM][SIZE_NUM];
  363. #ifndef OPENSSL_NO_DSA
  364. enum { R_DSA_512, R_DSA_1024, R_DSA_2048, DSA_NUM };
  365. static const OPT_PAIR dsa_choices[DSA_NUM] = {
  366. {"dsa512", R_DSA_512},
  367. {"dsa1024", R_DSA_1024},
  368. {"dsa2048", R_DSA_2048}
  369. };
  370. static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */
  371. #endif /* OPENSSL_NO_DSA */
  372. #ifndef OPENSSL_NO_RSA
  373. enum {
  374. R_RSA_512, R_RSA_1024, R_RSA_2048, R_RSA_3072, R_RSA_4096, R_RSA_7680,
  375. R_RSA_15360, RSA_NUM
  376. };
  377. static const OPT_PAIR rsa_choices[RSA_NUM] = {
  378. {"rsa512", R_RSA_512},
  379. {"rsa1024", R_RSA_1024},
  380. {"rsa2048", R_RSA_2048},
  381. {"rsa3072", R_RSA_3072},
  382. {"rsa4096", R_RSA_4096},
  383. {"rsa7680", R_RSA_7680},
  384. {"rsa15360", R_RSA_15360}
  385. };
  386. static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
  387. #endif /* OPENSSL_NO_RSA */
  388. #ifndef OPENSSL_NO_EC
  389. enum ec_curves_t {
  390. R_EC_P160, R_EC_P192, R_EC_P224, R_EC_P256, R_EC_P384, R_EC_P521,
  391. # ifndef OPENSSL_NO_EC2M
  392. R_EC_K163, R_EC_K233, R_EC_K283, R_EC_K409, R_EC_K571,
  393. R_EC_B163, R_EC_B233, R_EC_B283, R_EC_B409, R_EC_B571,
  394. # endif
  395. R_EC_BRP256R1, R_EC_BRP256T1, R_EC_BRP384R1, R_EC_BRP384T1,
  396. R_EC_BRP512R1, R_EC_BRP512T1, ECDSA_NUM
  397. };
  398. /* list of ecdsa curves */
  399. static const OPT_PAIR ecdsa_choices[ECDSA_NUM] = {
  400. {"ecdsap160", R_EC_P160},
  401. {"ecdsap192", R_EC_P192},
  402. {"ecdsap224", R_EC_P224},
  403. {"ecdsap256", R_EC_P256},
  404. {"ecdsap384", R_EC_P384},
  405. {"ecdsap521", R_EC_P521},
  406. # ifndef OPENSSL_NO_EC2M
  407. {"ecdsak163", R_EC_K163},
  408. {"ecdsak233", R_EC_K233},
  409. {"ecdsak283", R_EC_K283},
  410. {"ecdsak409", R_EC_K409},
  411. {"ecdsak571", R_EC_K571},
  412. {"ecdsab163", R_EC_B163},
  413. {"ecdsab233", R_EC_B233},
  414. {"ecdsab283", R_EC_B283},
  415. {"ecdsab409", R_EC_B409},
  416. {"ecdsab571", R_EC_B571},
  417. # endif
  418. {"ecdsabrp256r1", R_EC_BRP256R1},
  419. {"ecdsabrp256t1", R_EC_BRP256T1},
  420. {"ecdsabrp384r1", R_EC_BRP384R1},
  421. {"ecdsabrp384t1", R_EC_BRP384T1},
  422. {"ecdsabrp512r1", R_EC_BRP512R1},
  423. {"ecdsabrp512t1", R_EC_BRP512T1}
  424. };
  425. enum { R_EC_X25519 = ECDSA_NUM, R_EC_X448, EC_NUM };
  426. /* list of ecdh curves, extension of |ecdsa_choices| list above */
  427. static const OPT_PAIR ecdh_choices[EC_NUM] = {
  428. {"ecdhp160", R_EC_P160},
  429. {"ecdhp192", R_EC_P192},
  430. {"ecdhp224", R_EC_P224},
  431. {"ecdhp256", R_EC_P256},
  432. {"ecdhp384", R_EC_P384},
  433. {"ecdhp521", R_EC_P521},
  434. # ifndef OPENSSL_NO_EC2M
  435. {"ecdhk163", R_EC_K163},
  436. {"ecdhk233", R_EC_K233},
  437. {"ecdhk283", R_EC_K283},
  438. {"ecdhk409", R_EC_K409},
  439. {"ecdhk571", R_EC_K571},
  440. {"ecdhb163", R_EC_B163},
  441. {"ecdhb233", R_EC_B233},
  442. {"ecdhb283", R_EC_B283},
  443. {"ecdhb409", R_EC_B409},
  444. {"ecdhb571", R_EC_B571},
  445. # endif
  446. {"ecdhbrp256r1", R_EC_BRP256R1},
  447. {"ecdhbrp256t1", R_EC_BRP256T1},
  448. {"ecdhbrp384r1", R_EC_BRP384R1},
  449. {"ecdhbrp384t1", R_EC_BRP384T1},
  450. {"ecdhbrp512r1", R_EC_BRP512R1},
  451. {"ecdhbrp512t1", R_EC_BRP512T1},
  452. {"ecdhx25519", R_EC_X25519},
  453. {"ecdhx448", R_EC_X448}
  454. };
  455. static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
  456. static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */
  457. enum { R_EC_Ed25519, R_EC_Ed448, EdDSA_NUM };
  458. static const OPT_PAIR eddsa_choices[EdDSA_NUM] = {
  459. {"ed25519", R_EC_Ed25519},
  460. {"ed448", R_EC_Ed448}
  461. };
  462. static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
  463. # ifndef OPENSSL_NO_SM2
  464. enum { R_EC_CURVESM2, SM2_NUM };
  465. static const OPT_PAIR sm2_choices[SM2_NUM] = {
  466. {"curveSM2", R_EC_CURVESM2}
  467. };
  468. # define SM2_ID "TLSv1.3+GM+Cipher+Suite"
  469. # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
  470. static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
  471. # endif /* OPENSSL_NO_SM2 */
  472. #endif /* OPENSSL_NO_EC */
  473. #ifndef SIGALRM
  474. # define COND(d) (count < (d))
  475. # define COUNT(d) (d)
  476. #else
  477. # define COND(unused_cond) (run && count<0x7fffffff)
  478. # define COUNT(d) (count)
  479. #endif /* SIGALRM */
  480. typedef struct loopargs_st {
  481. ASYNC_JOB *inprogress_job;
  482. ASYNC_WAIT_CTX *wait_ctx;
  483. unsigned char *buf;
  484. unsigned char *buf2;
  485. unsigned char *buf_malloc;
  486. unsigned char *buf2_malloc;
  487. unsigned char *key;
  488. unsigned int siglen;
  489. size_t sigsize;
  490. #ifndef OPENSSL_NO_RSA
  491. RSA *rsa_key[RSA_NUM];
  492. #endif
  493. #ifndef OPENSSL_NO_DSA
  494. DSA *dsa_key[DSA_NUM];
  495. #endif
  496. #ifndef OPENSSL_NO_EC
  497. EC_KEY *ecdsa[ECDSA_NUM];
  498. EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
  499. EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
  500. # ifndef OPENSSL_NO_SM2
  501. EVP_MD_CTX *sm2_ctx[SM2_NUM];
  502. EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM];
  503. EVP_PKEY *sm2_pkey[SM2_NUM];
  504. # endif
  505. unsigned char *secret_a;
  506. unsigned char *secret_b;
  507. size_t outlen[EC_NUM];
  508. #endif
  509. EVP_CIPHER_CTX *ctx;
  510. HMAC_CTX *hctx;
  511. #ifndef OPENSSL_NO_CMAC
  512. CMAC_CTX *cmac_ctx;
  513. #endif
  514. GCM128_CONTEXT *gcm_ctx;
  515. } loopargs_t;
  516. static int run_benchmark(int async_jobs, int (*loop_function) (void *),
  517. loopargs_t * loopargs);
  518. static unsigned int testnum;
  519. /* Nb of iterations to do per algorithm and key-size */
  520. static long c[ALGOR_NUM][SIZE_NUM];
  521. #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  522. static int EVP_Digest_MD2_loop(void *args)
  523. {
  524. loopargs_t *tempargs = *(loopargs_t **) args;
  525. unsigned char *buf = tempargs->buf;
  526. unsigned char md2[MD2_DIGEST_LENGTH];
  527. int count;
  528. for (count = 0; COND(c[D_MD2][testnum]); count++) {
  529. if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
  530. NULL))
  531. return -1;
  532. }
  533. return count;
  534. }
  535. #endif
  536. #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  537. static int EVP_Digest_MDC2_loop(void *args)
  538. {
  539. loopargs_t *tempargs = *(loopargs_t **) args;
  540. unsigned char *buf = tempargs->buf;
  541. unsigned char mdc2[MDC2_DIGEST_LENGTH];
  542. int count;
  543. for (count = 0; COND(c[D_MDC2][testnum]); count++) {
  544. if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
  545. NULL))
  546. return -1;
  547. }
  548. return count;
  549. }
  550. #endif
  551. #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  552. static int EVP_Digest_MD4_loop(void *args)
  553. {
  554. loopargs_t *tempargs = *(loopargs_t **) args;
  555. unsigned char *buf = tempargs->buf;
  556. unsigned char md4[MD4_DIGEST_LENGTH];
  557. int count;
  558. for (count = 0; COND(c[D_MD4][testnum]); count++) {
  559. if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
  560. NULL))
  561. return -1;
  562. }
  563. return count;
  564. }
  565. #endif
  566. #ifndef OPENSSL_NO_MD5
  567. static int MD5_loop(void *args)
  568. {
  569. loopargs_t *tempargs = *(loopargs_t **) args;
  570. unsigned char *buf = tempargs->buf;
  571. unsigned char md5[MD5_DIGEST_LENGTH];
  572. int count;
  573. for (count = 0; COND(c[D_MD5][testnum]); count++)
  574. MD5(buf, lengths[testnum], md5);
  575. return count;
  576. }
  577. static int HMAC_loop(void *args)
  578. {
  579. loopargs_t *tempargs = *(loopargs_t **) args;
  580. unsigned char *buf = tempargs->buf;
  581. HMAC_CTX *hctx = tempargs->hctx;
  582. unsigned char hmac[MD5_DIGEST_LENGTH];
  583. int count;
  584. for (count = 0; COND(c[D_HMAC][testnum]); count++) {
  585. HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
  586. HMAC_Update(hctx, buf, lengths[testnum]);
  587. HMAC_Final(hctx, hmac, NULL);
  588. }
  589. return count;
  590. }
  591. #endif
  592. static int SHA1_loop(void *args)
  593. {
  594. loopargs_t *tempargs = *(loopargs_t **) args;
  595. unsigned char *buf = tempargs->buf;
  596. unsigned char sha[SHA_DIGEST_LENGTH];
  597. int count;
  598. for (count = 0; COND(c[D_SHA1][testnum]); count++)
  599. SHA1(buf, lengths[testnum], sha);
  600. return count;
  601. }
  602. static int SHA256_loop(void *args)
  603. {
  604. loopargs_t *tempargs = *(loopargs_t **) args;
  605. unsigned char *buf = tempargs->buf;
  606. unsigned char sha256[SHA256_DIGEST_LENGTH];
  607. int count;
  608. for (count = 0; COND(c[D_SHA256][testnum]); count++)
  609. SHA256(buf, lengths[testnum], sha256);
  610. return count;
  611. }
  612. static int SHA512_loop(void *args)
  613. {
  614. loopargs_t *tempargs = *(loopargs_t **) args;
  615. unsigned char *buf = tempargs->buf;
  616. unsigned char sha512[SHA512_DIGEST_LENGTH];
  617. int count;
  618. for (count = 0; COND(c[D_SHA512][testnum]); count++)
  619. SHA512(buf, lengths[testnum], sha512);
  620. return count;
  621. }
  622. #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  623. static int WHIRLPOOL_loop(void *args)
  624. {
  625. loopargs_t *tempargs = *(loopargs_t **) args;
  626. unsigned char *buf = tempargs->buf;
  627. unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
  628. int count;
  629. for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
  630. WHIRLPOOL(buf, lengths[testnum], whirlpool);
  631. return count;
  632. }
  633. #endif
  634. #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  635. static int EVP_Digest_RMD160_loop(void *args)
  636. {
  637. loopargs_t *tempargs = *(loopargs_t **) args;
  638. unsigned char *buf = tempargs->buf;
  639. unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
  640. int count;
  641. for (count = 0; COND(c[D_RMD160][testnum]); count++) {
  642. if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
  643. NULL, EVP_ripemd160(), NULL))
  644. return -1;
  645. }
  646. return count;
  647. }
  648. #endif
  649. #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  650. static RC4_KEY rc4_ks;
  651. static int RC4_loop(void *args)
  652. {
  653. loopargs_t *tempargs = *(loopargs_t **) args;
  654. unsigned char *buf = tempargs->buf;
  655. int count;
  656. for (count = 0; COND(c[D_RC4][testnum]); count++)
  657. RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
  658. return count;
  659. }
  660. #endif
  661. #ifndef OPENSSL_NO_DES
  662. static unsigned char DES_iv[8];
  663. static DES_key_schedule sch[3];
  664. static int DES_ncbc_encrypt_loop(void *args)
  665. {
  666. loopargs_t *tempargs = *(loopargs_t **) args;
  667. unsigned char *buf = tempargs->buf;
  668. int count;
  669. for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
  670. DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch[0],
  671. &DES_iv, DES_ENCRYPT);
  672. return count;
  673. }
  674. static int DES_ede3_cbc_encrypt_loop(void *args)
  675. {
  676. loopargs_t *tempargs = *(loopargs_t **) args;
  677. unsigned char *buf = tempargs->buf;
  678. int count;
  679. for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
  680. DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
  681. &sch[0], &sch[1], &sch[2], &DES_iv, DES_ENCRYPT);
  682. return count;
  683. }
  684. #endif
  685. #define MAX_BLOCK_SIZE 128
  686. static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
  687. #ifndef OPENSSL_NO_DEPRECATED_3_0
  688. static AES_KEY aes_ks1, aes_ks2, aes_ks3;
  689. static int AES_cbc_128_encrypt_loop(void *args)
  690. {
  691. loopargs_t *tempargs = *(loopargs_t **) args;
  692. unsigned char *buf = tempargs->buf;
  693. int count;
  694. for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
  695. AES_cbc_encrypt(buf, buf,
  696. (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
  697. return count;
  698. }
  699. static int AES_cbc_192_encrypt_loop(void *args)
  700. {
  701. loopargs_t *tempargs = *(loopargs_t **) args;
  702. unsigned char *buf = tempargs->buf;
  703. int count;
  704. for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
  705. AES_cbc_encrypt(buf, buf,
  706. (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
  707. return count;
  708. }
  709. static int AES_cbc_256_encrypt_loop(void *args)
  710. {
  711. loopargs_t *tempargs = *(loopargs_t **) args;
  712. unsigned char *buf = tempargs->buf;
  713. int count;
  714. for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
  715. AES_cbc_encrypt(buf, buf,
  716. (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
  717. return count;
  718. }
  719. static int AES_ige_128_encrypt_loop(void *args)
  720. {
  721. loopargs_t *tempargs = *(loopargs_t **) args;
  722. unsigned char *buf = tempargs->buf;
  723. unsigned char *buf2 = tempargs->buf2;
  724. int count;
  725. for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
  726. AES_ige_encrypt(buf, buf2,
  727. (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
  728. return count;
  729. }
  730. static int AES_ige_192_encrypt_loop(void *args)
  731. {
  732. loopargs_t *tempargs = *(loopargs_t **) args;
  733. unsigned char *buf = tempargs->buf;
  734. unsigned char *buf2 = tempargs->buf2;
  735. int count;
  736. for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
  737. AES_ige_encrypt(buf, buf2,
  738. (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
  739. return count;
  740. }
  741. static int AES_ige_256_encrypt_loop(void *args)
  742. {
  743. loopargs_t *tempargs = *(loopargs_t **) args;
  744. unsigned char *buf = tempargs->buf;
  745. unsigned char *buf2 = tempargs->buf2;
  746. int count;
  747. for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
  748. AES_ige_encrypt(buf, buf2,
  749. (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
  750. return count;
  751. }
  752. static int CRYPTO_gcm128_aad_loop(void *args)
  753. {
  754. loopargs_t *tempargs = *(loopargs_t **) args;
  755. unsigned char *buf = tempargs->buf;
  756. GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
  757. int count;
  758. for (count = 0; COND(c[D_GHASH][testnum]); count++)
  759. CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
  760. return count;
  761. }
  762. #endif
  763. static int RAND_bytes_loop(void *args)
  764. {
  765. loopargs_t *tempargs = *(loopargs_t **) args;
  766. unsigned char *buf = tempargs->buf;
  767. int count;
  768. for (count = 0; COND(c[D_RAND][testnum]); count++)
  769. RAND_bytes(buf, lengths[testnum]);
  770. return count;
  771. }
  772. static int decrypt = 0;
  773. static int EVP_Update_loop(void *args)
  774. {
  775. loopargs_t *tempargs = *(loopargs_t **) args;
  776. unsigned char *buf = tempargs->buf;
  777. EVP_CIPHER_CTX *ctx = tempargs->ctx;
  778. int outl, count, rc;
  779. if (decrypt) {
  780. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  781. rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
  782. if (rc != 1) {
  783. /* reset iv in case of counter overflow */
  784. EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
  785. }
  786. }
  787. } else {
  788. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  789. rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
  790. if (rc != 1) {
  791. /* reset iv in case of counter overflow */
  792. EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
  793. }
  794. }
  795. }
  796. if (decrypt)
  797. EVP_DecryptFinal_ex(ctx, buf, &outl);
  798. else
  799. EVP_EncryptFinal_ex(ctx, buf, &outl);
  800. return count;
  801. }
  802. /*
  803. * CCM does not support streaming. For the purpose of performance measurement,
  804. * each message is encrypted using the same (key,iv)-pair. Do not use this
  805. * code in your application.
  806. */
  807. static int EVP_Update_loop_ccm(void *args)
  808. {
  809. loopargs_t *tempargs = *(loopargs_t **) args;
  810. unsigned char *buf = tempargs->buf;
  811. EVP_CIPHER_CTX *ctx = tempargs->ctx;
  812. int outl, count;
  813. unsigned char tag[12];
  814. if (decrypt) {
  815. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  816. EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
  817. /* reset iv */
  818. EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
  819. /* counter is reset on every update */
  820. EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
  821. }
  822. } else {
  823. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  824. /* restore iv length field */
  825. EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
  826. /* counter is reset on every update */
  827. EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
  828. }
  829. }
  830. if (decrypt)
  831. EVP_DecryptFinal_ex(ctx, buf, &outl);
  832. else
  833. EVP_EncryptFinal_ex(ctx, buf, &outl);
  834. return count;
  835. }
  836. /*
  837. * To make AEAD benchmarking more relevant perform TLS-like operations,
  838. * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
  839. * payload length is not actually limited by 16KB...
  840. */
  841. static int EVP_Update_loop_aead(void *args)
  842. {
  843. loopargs_t *tempargs = *(loopargs_t **) args;
  844. unsigned char *buf = tempargs->buf;
  845. EVP_CIPHER_CTX *ctx = tempargs->ctx;
  846. int outl, count;
  847. unsigned char aad[13] = { 0xcc };
  848. unsigned char faketag[16] = { 0xcc };
  849. if (decrypt) {
  850. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  851. EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
  852. EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  853. sizeof(faketag), faketag);
  854. EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
  855. EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
  856. EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
  857. }
  858. } else {
  859. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  860. EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
  861. EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
  862. EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
  863. EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
  864. }
  865. }
  866. return count;
  867. }
  868. static const EVP_MD *evp_md = NULL;
  869. static int EVP_Digest_loop(void *args)
  870. {
  871. loopargs_t *tempargs = *(loopargs_t **) args;
  872. unsigned char *buf = tempargs->buf;
  873. unsigned char md[EVP_MAX_MD_SIZE];
  874. int count;
  875. for (count = 0; COND(c[D_EVP][testnum]); count++) {
  876. if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
  877. return -1;
  878. }
  879. return count;
  880. }
  881. static const EVP_MD *evp_hmac_md = NULL;
  882. static char *evp_hmac_name = NULL;
  883. static int EVP_HMAC_loop(void *args)
  884. {
  885. loopargs_t *tempargs = *(loopargs_t **) args;
  886. unsigned char *buf = tempargs->buf;
  887. unsigned char no_key[32];
  888. int count;
  889. for (count = 0; COND(c[D_EVP_HMAC][testnum]); count++) {
  890. if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
  891. NULL, NULL) == NULL)
  892. return -1;
  893. }
  894. return count;
  895. }
  896. #ifndef OPENSSL_NO_CMAC
  897. static const EVP_CIPHER *evp_cmac_cipher = NULL;
  898. static char *evp_cmac_name = NULL;
  899. static int EVP_CMAC_loop(void *args)
  900. {
  901. loopargs_t *tempargs = *(loopargs_t **) args;
  902. unsigned char *buf = tempargs->buf;
  903. CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
  904. static const char key[16] = "This is a key...";
  905. unsigned char mac[16];
  906. size_t len = sizeof(mac);
  907. int count;
  908. for (count = 0; COND(c[D_EVP_CMAC][testnum]); count++) {
  909. if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
  910. || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
  911. || !CMAC_Final(cmac_ctx, mac, &len))
  912. return -1;
  913. }
  914. return count;
  915. }
  916. #endif
  917. #ifndef OPENSSL_NO_RSA
  918. static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
  919. static int RSA_sign_loop(void *args)
  920. {
  921. loopargs_t *tempargs = *(loopargs_t **) args;
  922. unsigned char *buf = tempargs->buf;
  923. unsigned char *buf2 = tempargs->buf2;
  924. unsigned int *rsa_num = &tempargs->siglen;
  925. RSA **rsa_key = tempargs->rsa_key;
  926. int ret, count;
  927. for (count = 0; COND(rsa_c[testnum][0]); count++) {
  928. ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
  929. if (ret == 0) {
  930. BIO_printf(bio_err, "RSA sign failure\n");
  931. ERR_print_errors(bio_err);
  932. count = -1;
  933. break;
  934. }
  935. }
  936. return count;
  937. }
  938. static int RSA_verify_loop(void *args)
  939. {
  940. loopargs_t *tempargs = *(loopargs_t **) args;
  941. unsigned char *buf = tempargs->buf;
  942. unsigned char *buf2 = tempargs->buf2;
  943. unsigned int rsa_num = tempargs->siglen;
  944. RSA **rsa_key = tempargs->rsa_key;
  945. int ret, count;
  946. for (count = 0; COND(rsa_c[testnum][1]); count++) {
  947. ret =
  948. RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
  949. if (ret <= 0) {
  950. BIO_printf(bio_err, "RSA verify failure\n");
  951. ERR_print_errors(bio_err);
  952. count = -1;
  953. break;
  954. }
  955. }
  956. return count;
  957. }
  958. #endif
  959. #ifndef OPENSSL_NO_DSA
  960. static long dsa_c[DSA_NUM][2];
  961. static int DSA_sign_loop(void *args)
  962. {
  963. loopargs_t *tempargs = *(loopargs_t **) args;
  964. unsigned char *buf = tempargs->buf;
  965. unsigned char *buf2 = tempargs->buf2;
  966. DSA **dsa_key = tempargs->dsa_key;
  967. unsigned int *siglen = &tempargs->siglen;
  968. int ret, count;
  969. for (count = 0; COND(dsa_c[testnum][0]); count++) {
  970. ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
  971. if (ret == 0) {
  972. BIO_printf(bio_err, "DSA sign failure\n");
  973. ERR_print_errors(bio_err);
  974. count = -1;
  975. break;
  976. }
  977. }
  978. return count;
  979. }
  980. static int DSA_verify_loop(void *args)
  981. {
  982. loopargs_t *tempargs = *(loopargs_t **) args;
  983. unsigned char *buf = tempargs->buf;
  984. unsigned char *buf2 = tempargs->buf2;
  985. DSA **dsa_key = tempargs->dsa_key;
  986. unsigned int siglen = tempargs->siglen;
  987. int ret, count;
  988. for (count = 0; COND(dsa_c[testnum][1]); count++) {
  989. ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
  990. if (ret <= 0) {
  991. BIO_printf(bio_err, "DSA verify failure\n");
  992. ERR_print_errors(bio_err);
  993. count = -1;
  994. break;
  995. }
  996. }
  997. return count;
  998. }
  999. #endif
  1000. #ifndef OPENSSL_NO_EC
  1001. static long ecdsa_c[ECDSA_NUM][2];
  1002. static int ECDSA_sign_loop(void *args)
  1003. {
  1004. loopargs_t *tempargs = *(loopargs_t **) args;
  1005. unsigned char *buf = tempargs->buf;
  1006. EC_KEY **ecdsa = tempargs->ecdsa;
  1007. unsigned char *ecdsasig = tempargs->buf2;
  1008. unsigned int *ecdsasiglen = &tempargs->siglen;
  1009. int ret, count;
  1010. for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
  1011. ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
  1012. if (ret == 0) {
  1013. BIO_printf(bio_err, "ECDSA sign failure\n");
  1014. ERR_print_errors(bio_err);
  1015. count = -1;
  1016. break;
  1017. }
  1018. }
  1019. return count;
  1020. }
  1021. static int ECDSA_verify_loop(void *args)
  1022. {
  1023. loopargs_t *tempargs = *(loopargs_t **) args;
  1024. unsigned char *buf = tempargs->buf;
  1025. EC_KEY **ecdsa = tempargs->ecdsa;
  1026. unsigned char *ecdsasig = tempargs->buf2;
  1027. unsigned int ecdsasiglen = tempargs->siglen;
  1028. int ret, count;
  1029. for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
  1030. ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
  1031. if (ret != 1) {
  1032. BIO_printf(bio_err, "ECDSA verify failure\n");
  1033. ERR_print_errors(bio_err);
  1034. count = -1;
  1035. break;
  1036. }
  1037. }
  1038. return count;
  1039. }
  1040. /* ******************************************************************** */
  1041. static long ecdh_c[EC_NUM][1];
  1042. static int ECDH_EVP_derive_key_loop(void *args)
  1043. {
  1044. loopargs_t *tempargs = *(loopargs_t **) args;
  1045. EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
  1046. unsigned char *derived_secret = tempargs->secret_a;
  1047. int count;
  1048. size_t *outlen = &(tempargs->outlen[testnum]);
  1049. for (count = 0; COND(ecdh_c[testnum][0]); count++)
  1050. EVP_PKEY_derive(ctx, derived_secret, outlen);
  1051. return count;
  1052. }
  1053. static long eddsa_c[EdDSA_NUM][2];
  1054. static int EdDSA_sign_loop(void *args)
  1055. {
  1056. loopargs_t *tempargs = *(loopargs_t **) args;
  1057. unsigned char *buf = tempargs->buf;
  1058. EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
  1059. unsigned char *eddsasig = tempargs->buf2;
  1060. size_t *eddsasigsize = &tempargs->sigsize;
  1061. int ret, count;
  1062. for (count = 0; COND(eddsa_c[testnum][0]); count++) {
  1063. ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
  1064. if (ret == 0) {
  1065. BIO_printf(bio_err, "EdDSA sign failure\n");
  1066. ERR_print_errors(bio_err);
  1067. count = -1;
  1068. break;
  1069. }
  1070. }
  1071. return count;
  1072. }
  1073. static int EdDSA_verify_loop(void *args)
  1074. {
  1075. loopargs_t *tempargs = *(loopargs_t **) args;
  1076. unsigned char *buf = tempargs->buf;
  1077. EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
  1078. unsigned char *eddsasig = tempargs->buf2;
  1079. size_t eddsasigsize = tempargs->sigsize;
  1080. int ret, count;
  1081. for (count = 0; COND(eddsa_c[testnum][1]); count++) {
  1082. ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
  1083. if (ret != 1) {
  1084. BIO_printf(bio_err, "EdDSA verify failure\n");
  1085. ERR_print_errors(bio_err);
  1086. count = -1;
  1087. break;
  1088. }
  1089. }
  1090. return count;
  1091. }
  1092. # ifndef OPENSSL_NO_SM2
  1093. static long sm2_c[SM2_NUM][2];
  1094. static int SM2_sign_loop(void *args)
  1095. {
  1096. loopargs_t *tempargs = *(loopargs_t **) args;
  1097. unsigned char *buf = tempargs->buf;
  1098. EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
  1099. unsigned char *sm2sig = tempargs->buf2;
  1100. size_t sm2sigsize = tempargs->sigsize;
  1101. const size_t max_size = tempargs->sigsize;
  1102. int ret, count;
  1103. EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
  1104. for (count = 0; COND(sm2_c[testnum][0]); count++) {
  1105. if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
  1106. NULL, sm2_pkey[testnum])) {
  1107. BIO_printf(bio_err, "SM2 init sign failure\n");
  1108. ERR_print_errors(bio_err);
  1109. count = -1;
  1110. break;
  1111. }
  1112. ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize,
  1113. buf, 20);
  1114. if (ret == 0) {
  1115. BIO_printf(bio_err, "SM2 sign failure\n");
  1116. ERR_print_errors(bio_err);
  1117. count = -1;
  1118. break;
  1119. }
  1120. /* update the latest returned size and always use the fixed buffer size */
  1121. tempargs->sigsize = sm2sigsize;
  1122. sm2sigsize = max_size;
  1123. }
  1124. return count;
  1125. }
  1126. static int SM2_verify_loop(void *args)
  1127. {
  1128. loopargs_t *tempargs = *(loopargs_t **) args;
  1129. unsigned char *buf = tempargs->buf;
  1130. EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx;
  1131. unsigned char *sm2sig = tempargs->buf2;
  1132. size_t sm2sigsize = tempargs->sigsize;
  1133. int ret, count;
  1134. EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
  1135. for (count = 0; COND(sm2_c[testnum][1]); count++) {
  1136. if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(),
  1137. NULL, sm2_pkey[testnum])) {
  1138. BIO_printf(bio_err, "SM2 verify init failure\n");
  1139. ERR_print_errors(bio_err);
  1140. count = -1;
  1141. break;
  1142. }
  1143. ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize,
  1144. buf, 20);
  1145. if (ret != 1) {
  1146. BIO_printf(bio_err, "SM2 verify failure\n");
  1147. ERR_print_errors(bio_err);
  1148. count = -1;
  1149. break;
  1150. }
  1151. }
  1152. return count;
  1153. }
  1154. # endif /* OPENSSL_NO_SM2 */
  1155. #endif /* OPENSSL_NO_EC */
  1156. static int run_benchmark(int async_jobs,
  1157. int (*loop_function) (void *), loopargs_t * loopargs)
  1158. {
  1159. int job_op_count = 0;
  1160. int total_op_count = 0;
  1161. int num_inprogress = 0;
  1162. int error = 0, i = 0, ret = 0;
  1163. OSSL_ASYNC_FD job_fd = 0;
  1164. size_t num_job_fds = 0;
  1165. if (async_jobs == 0) {
  1166. return loop_function((void *)&loopargs);
  1167. }
  1168. for (i = 0; i < async_jobs && !error; i++) {
  1169. loopargs_t *looparg_item = loopargs + i;
  1170. /* Copy pointer content (looparg_t item address) into async context */
  1171. ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
  1172. &job_op_count, loop_function,
  1173. (void *)&looparg_item, sizeof(looparg_item));
  1174. switch (ret) {
  1175. case ASYNC_PAUSE:
  1176. ++num_inprogress;
  1177. break;
  1178. case ASYNC_FINISH:
  1179. if (job_op_count == -1) {
  1180. error = 1;
  1181. } else {
  1182. total_op_count += job_op_count;
  1183. }
  1184. break;
  1185. case ASYNC_NO_JOBS:
  1186. case ASYNC_ERR:
  1187. BIO_printf(bio_err, "Failure in the job\n");
  1188. ERR_print_errors(bio_err);
  1189. error = 1;
  1190. break;
  1191. }
  1192. }
  1193. while (num_inprogress > 0) {
  1194. #if defined(OPENSSL_SYS_WINDOWS)
  1195. DWORD avail = 0;
  1196. #elif defined(OPENSSL_SYS_UNIX)
  1197. int select_result = 0;
  1198. OSSL_ASYNC_FD max_fd = 0;
  1199. fd_set waitfdset;
  1200. FD_ZERO(&waitfdset);
  1201. for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
  1202. if (loopargs[i].inprogress_job == NULL)
  1203. continue;
  1204. if (!ASYNC_WAIT_CTX_get_all_fds
  1205. (loopargs[i].wait_ctx, NULL, &num_job_fds)
  1206. || num_job_fds > 1) {
  1207. BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
  1208. ERR_print_errors(bio_err);
  1209. error = 1;
  1210. break;
  1211. }
  1212. ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
  1213. &num_job_fds);
  1214. FD_SET(job_fd, &waitfdset);
  1215. if (job_fd > max_fd)
  1216. max_fd = job_fd;
  1217. }
  1218. if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
  1219. BIO_printf(bio_err,
  1220. "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
  1221. "Decrease the value of async_jobs\n",
  1222. max_fd, FD_SETSIZE);
  1223. ERR_print_errors(bio_err);
  1224. error = 1;
  1225. break;
  1226. }
  1227. select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
  1228. if (select_result == -1 && errno == EINTR)
  1229. continue;
  1230. if (select_result == -1) {
  1231. BIO_printf(bio_err, "Failure in the select\n");
  1232. ERR_print_errors(bio_err);
  1233. error = 1;
  1234. break;
  1235. }
  1236. if (select_result == 0)
  1237. continue;
  1238. #endif
  1239. for (i = 0; i < async_jobs; i++) {
  1240. if (loopargs[i].inprogress_job == NULL)
  1241. continue;
  1242. if (!ASYNC_WAIT_CTX_get_all_fds
  1243. (loopargs[i].wait_ctx, NULL, &num_job_fds)
  1244. || num_job_fds > 1) {
  1245. BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
  1246. ERR_print_errors(bio_err);
  1247. error = 1;
  1248. break;
  1249. }
  1250. ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
  1251. &num_job_fds);
  1252. #if defined(OPENSSL_SYS_UNIX)
  1253. if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
  1254. continue;
  1255. #elif defined(OPENSSL_SYS_WINDOWS)
  1256. if (num_job_fds == 1
  1257. && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
  1258. && avail > 0)
  1259. continue;
  1260. #endif
  1261. ret = ASYNC_start_job(&loopargs[i].inprogress_job,
  1262. loopargs[i].wait_ctx, &job_op_count,
  1263. loop_function, (void *)(loopargs + i),
  1264. sizeof(loopargs_t));
  1265. switch (ret) {
  1266. case ASYNC_PAUSE:
  1267. break;
  1268. case ASYNC_FINISH:
  1269. if (job_op_count == -1) {
  1270. error = 1;
  1271. } else {
  1272. total_op_count += job_op_count;
  1273. }
  1274. --num_inprogress;
  1275. loopargs[i].inprogress_job = NULL;
  1276. break;
  1277. case ASYNC_NO_JOBS:
  1278. case ASYNC_ERR:
  1279. --num_inprogress;
  1280. loopargs[i].inprogress_job = NULL;
  1281. BIO_printf(bio_err, "Failure in the job\n");
  1282. ERR_print_errors(bio_err);
  1283. error = 1;
  1284. break;
  1285. }
  1286. }
  1287. }
  1288. return error ? -1 : total_op_count;
  1289. }
  1290. #define stop_it(do_it, test_num)\
  1291. memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num);
  1292. int speed_main(int argc, char **argv)
  1293. {
  1294. ENGINE *e = NULL;
  1295. loopargs_t *loopargs = NULL;
  1296. const char *prog;
  1297. const char *engine_id = NULL;
  1298. const EVP_CIPHER *evp_cipher = NULL;
  1299. double d = 0.0;
  1300. OPTION_CHOICE o;
  1301. int async_init = 0, multiblock = 0, pr_header = 0;
  1302. uint8_t doit[ALGOR_NUM] = { 0 };
  1303. int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
  1304. long count = 0;
  1305. unsigned int size_num = SIZE_NUM;
  1306. unsigned int i, k, loopargs_len = 0, async_jobs = 0;
  1307. int keylen;
  1308. int buflen;
  1309. #ifndef NO_FORK
  1310. int multi = 0;
  1311. #endif
  1312. #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
  1313. || !defined(OPENSSL_NO_EC)
  1314. long rsa_count = 1;
  1315. #endif
  1316. openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
  1317. ECDSA_SECONDS, ECDH_SECONDS,
  1318. EdDSA_SECONDS, SM2_SECONDS };
  1319. /* What follows are the buffers and key material. */
  1320. #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1321. RC5_32_KEY rc5_ks;
  1322. #endif
  1323. #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1324. RC2_KEY rc2_ks;
  1325. #endif
  1326. #ifndef OPENSSL_NO_IDEA
  1327. IDEA_KEY_SCHEDULE idea_ks;
  1328. #endif
  1329. #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1330. SEED_KEY_SCHEDULE seed_ks;
  1331. #endif
  1332. #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1333. BF_KEY bf_ks;
  1334. #endif
  1335. #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1336. CAST_KEY cast_ks;
  1337. #endif
  1338. static const unsigned char key16[16] = {
  1339. 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
  1340. 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
  1341. };
  1342. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1343. static const unsigned char key24[24] = {
  1344. 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
  1345. 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
  1346. 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
  1347. };
  1348. static const unsigned char key32[32] = {
  1349. 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
  1350. 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
  1351. 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
  1352. 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
  1353. };
  1354. #endif
  1355. #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1356. CAMELLIA_KEY camellia_ks[3];
  1357. #endif
  1358. #ifndef OPENSSL_NO_RSA
  1359. static const struct {
  1360. const unsigned char *data;
  1361. unsigned int length;
  1362. unsigned int bits;
  1363. } rsa_keys[] = {
  1364. { test512, sizeof(test512), 512 },
  1365. { test1024, sizeof(test1024), 1024 },
  1366. { test2048, sizeof(test2048), 2048 },
  1367. { test3072, sizeof(test3072), 3072 },
  1368. { test4096, sizeof(test4096), 4092 },
  1369. { test7680, sizeof(test7680), 7680 },
  1370. { test15360, sizeof(test15360), 15360 }
  1371. };
  1372. uint8_t rsa_doit[RSA_NUM] = { 0 };
  1373. int primes = RSA_DEFAULT_PRIME_NUM;
  1374. #endif
  1375. #ifndef OPENSSL_NO_DSA
  1376. static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
  1377. uint8_t dsa_doit[DSA_NUM] = { 0 };
  1378. #endif
  1379. #ifndef OPENSSL_NO_EC
  1380. typedef struct ec_curve_st {
  1381. const char *name;
  1382. unsigned int nid;
  1383. unsigned int bits;
  1384. size_t sigsize; /* only used for EdDSA curves */
  1385. } EC_CURVE;
  1386. /*
  1387. * We only test over the following curves as they are representative, To
  1388. * add tests over more curves, simply add the curve NID and curve name to
  1389. * the following arrays and increase the |ecdh_choices| and |ecdsa_choices|
  1390. * lists accordingly.
  1391. */
  1392. static const EC_CURVE ec_curves[EC_NUM] = {
  1393. /* Prime Curves */
  1394. {"secp160r1", NID_secp160r1, 160},
  1395. {"nistp192", NID_X9_62_prime192v1, 192},
  1396. {"nistp224", NID_secp224r1, 224},
  1397. {"nistp256", NID_X9_62_prime256v1, 256},
  1398. {"nistp384", NID_secp384r1, 384},
  1399. {"nistp521", NID_secp521r1, 521},
  1400. # ifndef OPENSSL_NO_EC2M
  1401. /* Binary Curves */
  1402. {"nistk163", NID_sect163k1, 163},
  1403. {"nistk233", NID_sect233k1, 233},
  1404. {"nistk283", NID_sect283k1, 283},
  1405. {"nistk409", NID_sect409k1, 409},
  1406. {"nistk571", NID_sect571k1, 571},
  1407. {"nistb163", NID_sect163r2, 163},
  1408. {"nistb233", NID_sect233r1, 233},
  1409. {"nistb283", NID_sect283r1, 283},
  1410. {"nistb409", NID_sect409r1, 409},
  1411. {"nistb571", NID_sect571r1, 571},
  1412. # endif
  1413. {"brainpoolP256r1", NID_brainpoolP256r1, 256},
  1414. {"brainpoolP256t1", NID_brainpoolP256t1, 256},
  1415. {"brainpoolP384r1", NID_brainpoolP384r1, 384},
  1416. {"brainpoolP384t1", NID_brainpoolP384t1, 384},
  1417. {"brainpoolP512r1", NID_brainpoolP512r1, 512},
  1418. {"brainpoolP512t1", NID_brainpoolP512t1, 512},
  1419. /* Other and ECDH only ones */
  1420. {"X25519", NID_X25519, 253},
  1421. {"X448", NID_X448, 448}
  1422. };
  1423. static const EC_CURVE ed_curves[EdDSA_NUM] = {
  1424. /* EdDSA */
  1425. {"Ed25519", NID_ED25519, 253, 64},
  1426. {"Ed448", NID_ED448, 456, 114}
  1427. };
  1428. # ifndef OPENSSL_NO_SM2
  1429. static const EC_CURVE sm2_curves[SM2_NUM] = {
  1430. /* SM2 */
  1431. {"CurveSM2", NID_sm2, 256}
  1432. };
  1433. uint8_t sm2_doit[SM2_NUM] = { 0 };
  1434. # endif
  1435. uint8_t ecdsa_doit[ECDSA_NUM] = { 0 };
  1436. uint8_t ecdh_doit[EC_NUM] = { 0 };
  1437. uint8_t eddsa_doit[EdDSA_NUM] = { 0 };
  1438. /* checks declarated curves against choices list. */
  1439. OPENSSL_assert(ed_curves[EdDSA_NUM - 1].nid == NID_ED448);
  1440. OPENSSL_assert(strcmp(eddsa_choices[EdDSA_NUM - 1].name, "ed448") == 0);
  1441. OPENSSL_assert(ec_curves[EC_NUM - 1].nid == NID_X448);
  1442. OPENSSL_assert(strcmp(ecdh_choices[EC_NUM - 1].name, "ecdhx448") == 0);
  1443. OPENSSL_assert(ec_curves[ECDSA_NUM - 1].nid == NID_brainpoolP512t1);
  1444. OPENSSL_assert(strcmp(ecdsa_choices[ECDSA_NUM - 1].name, "ecdsabrp512t1") == 0);
  1445. # ifndef OPENSSL_NO_SM2
  1446. OPENSSL_assert(sm2_curves[SM2_NUM - 1].nid == NID_sm2);
  1447. OPENSSL_assert(strcmp(sm2_choices[SM2_NUM - 1].name, "curveSM2") == 0);
  1448. # endif
  1449. #endif /* ndef OPENSSL_NO_EC */
  1450. prog = opt_init(argc, argv, speed_options);
  1451. while ((o = opt_next()) != OPT_EOF) {
  1452. switch (o) {
  1453. case OPT_EOF:
  1454. case OPT_ERR:
  1455. opterr:
  1456. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  1457. goto end;
  1458. case OPT_HELP:
  1459. opt_help(speed_options);
  1460. ret = 0;
  1461. goto end;
  1462. case OPT_ELAPSED:
  1463. usertime = 0;
  1464. break;
  1465. case OPT_EVP:
  1466. evp_md = NULL;
  1467. evp_cipher = EVP_get_cipherbyname(opt_arg());
  1468. if (evp_cipher == NULL)
  1469. evp_md = EVP_get_digestbyname(opt_arg());
  1470. if (evp_cipher == NULL && evp_md == NULL) {
  1471. BIO_printf(bio_err,
  1472. "%s: %s is an unknown cipher or digest\n",
  1473. prog, opt_arg());
  1474. goto end;
  1475. }
  1476. doit[D_EVP] = 1;
  1477. break;
  1478. case OPT_HMAC:
  1479. evp_hmac_md = EVP_get_digestbyname(opt_arg());
  1480. if (evp_hmac_md == NULL) {
  1481. BIO_printf(bio_err, "%s: %s is an unknown digest\n",
  1482. prog, opt_arg());
  1483. goto end;
  1484. }
  1485. doit[D_EVP_HMAC] = 1;
  1486. break;
  1487. case OPT_CMAC:
  1488. #ifndef OPENSSL_NO_CMAC
  1489. evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
  1490. if (evp_cmac_cipher == NULL) {
  1491. BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
  1492. prog, opt_arg());
  1493. goto end;
  1494. }
  1495. doit[D_EVP_CMAC] = 1;
  1496. #endif
  1497. break;
  1498. case OPT_DECRYPT:
  1499. decrypt = 1;
  1500. break;
  1501. case OPT_ENGINE:
  1502. /*
  1503. * In a forked execution, an engine might need to be
  1504. * initialised by each child process, not by the parent.
  1505. * So store the name here and run setup_engine() later on.
  1506. */
  1507. engine_id = opt_arg();
  1508. break;
  1509. case OPT_MULTI:
  1510. #ifndef NO_FORK
  1511. multi = atoi(opt_arg());
  1512. #endif
  1513. break;
  1514. case OPT_ASYNCJOBS:
  1515. #ifndef OPENSSL_NO_ASYNC
  1516. async_jobs = atoi(opt_arg());
  1517. if (!ASYNC_is_capable()) {
  1518. BIO_printf(bio_err,
  1519. "%s: async_jobs specified but async not supported\n",
  1520. prog);
  1521. goto opterr;
  1522. }
  1523. if (async_jobs > 99999) {
  1524. BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
  1525. goto opterr;
  1526. }
  1527. #endif
  1528. break;
  1529. case OPT_MISALIGN:
  1530. if (!opt_int(opt_arg(), &misalign))
  1531. goto end;
  1532. if (misalign > MISALIGN) {
  1533. BIO_printf(bio_err,
  1534. "%s: Maximum offset is %d\n", prog, MISALIGN);
  1535. goto opterr;
  1536. }
  1537. break;
  1538. case OPT_MR:
  1539. mr = 1;
  1540. break;
  1541. case OPT_MB:
  1542. multiblock = 1;
  1543. #ifdef OPENSSL_NO_MULTIBLOCK
  1544. BIO_printf(bio_err,
  1545. "%s: -mb specified but multi-block support is disabled\n",
  1546. prog);
  1547. goto end;
  1548. #endif
  1549. break;
  1550. case OPT_R_CASES:
  1551. if (!opt_rand(o))
  1552. goto end;
  1553. break;
  1554. case OPT_PRIMES:
  1555. if (!opt_int(opt_arg(), &primes))
  1556. goto end;
  1557. break;
  1558. case OPT_SECONDS:
  1559. seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
  1560. = seconds.ecdh = seconds.eddsa
  1561. = seconds.sm2 = atoi(opt_arg());
  1562. break;
  1563. case OPT_BYTES:
  1564. lengths_single = atoi(opt_arg());
  1565. lengths = &lengths_single;
  1566. size_num = 1;
  1567. break;
  1568. case OPT_AEAD:
  1569. aead = 1;
  1570. break;
  1571. }
  1572. }
  1573. argc = opt_num_rest();
  1574. argv = opt_rest();
  1575. /* Remaining arguments are algorithms. */
  1576. for (; *argv; argv++) {
  1577. const char *algo = *argv;
  1578. if (opt_found(algo, doit_choices, &i)) {
  1579. doit[i] = 1;
  1580. continue;
  1581. }
  1582. #ifndef OPENSSL_NO_DES
  1583. if (strcmp(algo, "des") == 0) {
  1584. doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
  1585. continue;
  1586. }
  1587. #endif
  1588. if (strcmp(algo, "sha") == 0) {
  1589. doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
  1590. continue;
  1591. }
  1592. #ifndef OPENSSL_NO_RSA
  1593. if (strcmp(algo, "openssl") == 0) /* just for compatibility */
  1594. continue;
  1595. if (strncmp(algo, "rsa", 3) == 0) {
  1596. if (algo[3] == '\0') {
  1597. memset(rsa_doit, 1, sizeof(rsa_doit));
  1598. continue;
  1599. }
  1600. if (opt_found(algo, rsa_choices, &i)) {
  1601. rsa_doit[i] = 1;
  1602. continue;
  1603. }
  1604. }
  1605. #endif
  1606. #ifndef OPENSSL_NO_DSA
  1607. if (strncmp(algo, "dsa", 3) == 0) {
  1608. if (algo[3] == '\0') {
  1609. memset(dsa_doit, 1, sizeof(dsa_doit));
  1610. continue;
  1611. }
  1612. if (opt_found(algo, dsa_choices, &i)) {
  1613. dsa_doit[i] = 2;
  1614. continue;
  1615. }
  1616. }
  1617. #endif
  1618. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1619. if (strcmp(algo, "aes") == 0) {
  1620. doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
  1621. continue;
  1622. }
  1623. #endif
  1624. #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1625. if (strcmp(algo, "camellia") == 0) {
  1626. doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
  1627. continue;
  1628. }
  1629. #endif
  1630. #ifndef OPENSSL_NO_EC
  1631. if (strncmp(algo, "ecdsa", 5) == 0) {
  1632. if (algo[5] == '\0') {
  1633. memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
  1634. continue;
  1635. }
  1636. if (opt_found(algo, ecdsa_choices, &i)) {
  1637. ecdsa_doit[i] = 2;
  1638. continue;
  1639. }
  1640. }
  1641. if (strncmp(algo, "ecdh", 4) == 0) {
  1642. if (algo[4] == '\0') {
  1643. memset(ecdh_doit, 1, sizeof(ecdh_doit));
  1644. continue;
  1645. }
  1646. if (opt_found(algo, ecdh_choices, &i)) {
  1647. ecdh_doit[i] = 2;
  1648. continue;
  1649. }
  1650. }
  1651. if (strcmp(algo, "eddsa") == 0) {
  1652. memset(eddsa_doit, 1, sizeof(eddsa_doit));
  1653. continue;
  1654. }
  1655. if (opt_found(algo, eddsa_choices, &i)) {
  1656. eddsa_doit[i] = 2;
  1657. continue;
  1658. }
  1659. # ifndef OPENSSL_NO_SM2
  1660. if (strcmp(algo, "sm2") == 0) {
  1661. memset(sm2_doit, 1, sizeof(sm2_doit));
  1662. continue;
  1663. }
  1664. if (opt_found(algo, sm2_choices, &i)) {
  1665. sm2_doit[i] = 2;
  1666. continue;
  1667. }
  1668. # endif
  1669. #endif /* OPENSSL_NO_EC */
  1670. BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, algo);
  1671. goto end;
  1672. }
  1673. /* Sanity checks */
  1674. if (aead) {
  1675. if (evp_cipher == NULL) {
  1676. BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
  1677. goto end;
  1678. } else if (!(EVP_CIPHER_flags(evp_cipher) &
  1679. EVP_CIPH_FLAG_AEAD_CIPHER)) {
  1680. BIO_printf(bio_err, "%s is not an AEAD cipher\n",
  1681. OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
  1682. goto end;
  1683. }
  1684. }
  1685. if (multiblock) {
  1686. if (evp_cipher == NULL) {
  1687. BIO_printf(bio_err,"-mb can be used only with a multi-block"
  1688. " capable cipher\n");
  1689. goto end;
  1690. } else if (!(EVP_CIPHER_flags(evp_cipher) &
  1691. EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
  1692. BIO_printf(bio_err, "%s is not a multi-block capable\n",
  1693. OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
  1694. goto end;
  1695. } else if (async_jobs > 0) {
  1696. BIO_printf(bio_err, "Async mode is not supported with -mb");
  1697. goto end;
  1698. }
  1699. }
  1700. /* Initialize the job pool if async mode is enabled */
  1701. if (async_jobs > 0) {
  1702. async_init = ASYNC_init_thread(async_jobs, async_jobs);
  1703. if (!async_init) {
  1704. BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
  1705. goto end;
  1706. }
  1707. }
  1708. loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
  1709. loopargs =
  1710. app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
  1711. memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
  1712. for (i = 0; i < loopargs_len; i++) {
  1713. if (async_jobs > 0) {
  1714. loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
  1715. if (loopargs[i].wait_ctx == NULL) {
  1716. BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
  1717. goto end;
  1718. }
  1719. }
  1720. buflen = lengths[size_num - 1];
  1721. if (buflen < 36) /* size of random vector in RSA benchmark */
  1722. buflen = 36;
  1723. buflen += MAX_MISALIGNMENT + 1;
  1724. loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
  1725. loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
  1726. memset(loopargs[i].buf_malloc, 0, buflen);
  1727. memset(loopargs[i].buf2_malloc, 0, buflen);
  1728. /* Align the start of buffers on a 64 byte boundary */
  1729. loopargs[i].buf = loopargs[i].buf_malloc + misalign;
  1730. loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
  1731. #ifndef OPENSSL_NO_EC
  1732. loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
  1733. loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
  1734. #endif
  1735. }
  1736. #ifndef NO_FORK
  1737. if (multi && do_multi(multi, size_num))
  1738. goto show_res;
  1739. #endif
  1740. /* Initialize the engine after the fork */
  1741. e = setup_engine(engine_id, 0);
  1742. /* No parameters; turn on everything. */
  1743. if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
  1744. memset(doit, 1, sizeof(doit));
  1745. doit[D_EVP] = doit[D_EVP_HMAC] = doit[D_EVP_CMAC] = 0;
  1746. #ifndef OPENSSL_NO_RSA
  1747. memset(rsa_doit, 1, sizeof(rsa_doit));
  1748. #endif
  1749. #ifndef OPENSSL_NO_DSA
  1750. memset(dsa_doit, 1, sizeof(dsa_doit));
  1751. #endif
  1752. #ifndef OPENSSL_NO_EC
  1753. memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
  1754. memset(ecdh_doit, 1, sizeof(ecdh_doit));
  1755. memset(eddsa_doit, 1, sizeof(eddsa_doit));
  1756. # ifndef OPENSSL_NO_SM2
  1757. memset(sm2_doit, 1, sizeof(sm2_doit));
  1758. # endif
  1759. #endif
  1760. }
  1761. for (i = 0; i < ALGOR_NUM; i++)
  1762. if (doit[i])
  1763. pr_header++;
  1764. if (usertime == 0 && !mr)
  1765. BIO_printf(bio_err,
  1766. "You have chosen to measure elapsed time "
  1767. "instead of user CPU time.\n");
  1768. #ifndef OPENSSL_NO_RSA
  1769. for (i = 0; i < loopargs_len; i++) {
  1770. if (primes > RSA_DEFAULT_PRIME_NUM) {
  1771. /* for multi-prime RSA, skip this */
  1772. break;
  1773. }
  1774. for (k = 0; k < RSA_NUM; k++) {
  1775. const unsigned char *p = rsa_keys[k].data;
  1776. loopargs[i].rsa_key[k] =
  1777. d2i_RSAPrivateKey(NULL, &p, rsa_keys[k].length);
  1778. if (loopargs[i].rsa_key[k] == NULL) {
  1779. BIO_printf(bio_err,
  1780. "internal error loading RSA key number %d\n", k);
  1781. goto end;
  1782. }
  1783. }
  1784. }
  1785. #endif
  1786. #ifndef OPENSSL_NO_DSA
  1787. for (i = 0; i < loopargs_len; i++) {
  1788. loopargs[i].dsa_key[0] = get_dsa(512);
  1789. loopargs[i].dsa_key[1] = get_dsa(1024);
  1790. loopargs[i].dsa_key[2] = get_dsa(2048);
  1791. }
  1792. #endif
  1793. #ifndef OPENSSL_NO_DES
  1794. if (doit[D_CBC_DES] || doit[D_EDE3_DES]) {
  1795. static DES_cblock keys[] = {
  1796. { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, /* keys[0] */
  1797. { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }, /* keys[1] */
  1798. { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 } /* keys[3] */
  1799. };
  1800. DES_set_key_unchecked(&keys[0], &sch[0]);
  1801. DES_set_key_unchecked(&keys[1], &sch[1]);
  1802. DES_set_key_unchecked(&keys[2], &sch[2]);
  1803. }
  1804. #endif
  1805. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1806. AES_set_encrypt_key(key16, 128, &aes_ks1);
  1807. AES_set_encrypt_key(key24, 192, &aes_ks2);
  1808. AES_set_encrypt_key(key32, 256, &aes_ks3);
  1809. #endif
  1810. #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1811. if (doit[D_CBC_128_CML] || doit[D_CBC_192_CML] || doit[D_CBC_256_CML]) {
  1812. Camellia_set_key(key16, 128, &camellia_ks[0]);
  1813. Camellia_set_key(key24, 192, &camellia_ks[1]);
  1814. Camellia_set_key(key32, 256, &camellia_ks[2]);
  1815. }
  1816. #endif
  1817. #ifndef OPENSSL_NO_IDEA
  1818. if (doit[D_CBC_IDEA])
  1819. IDEA_set_encrypt_key(key16, &idea_ks);
  1820. #endif
  1821. #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1822. if (doit[D_CBC_SEED])
  1823. SEED_set_key(key16, &seed_ks);
  1824. #endif
  1825. #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1826. if (doit[D_RC4])
  1827. RC4_set_key(&rc4_ks, 16, key16);
  1828. #endif
  1829. #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1830. if (doit[D_CBC_RC2])
  1831. RC2_set_key(&rc2_ks, 16, key16, 128);
  1832. #endif
  1833. #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1834. if (doit[D_CBC_RC5])
  1835. if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
  1836. BIO_printf(bio_err, "Failed setting RC5 key\n");
  1837. goto end;
  1838. }
  1839. #endif
  1840. #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1841. if (doit[D_CBC_BF])
  1842. BF_set_key(&bf_ks, 16, key16);
  1843. #endif
  1844. #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1845. if (doit[D_CBC_CAST])
  1846. CAST_set_key(&cast_ks, 16, key16);
  1847. #endif
  1848. #ifndef SIGALRM
  1849. # ifndef OPENSSL_NO_DES
  1850. BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
  1851. count = 10;
  1852. do {
  1853. long it;
  1854. count *= 2;
  1855. Time_F(START);
  1856. for (it = count; it; it--)
  1857. DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
  1858. (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
  1859. d = Time_F(STOP);
  1860. } while (d < 3);
  1861. c[D_MD2][0] = count / 10;
  1862. c[D_MDC2][0] = count / 10;
  1863. c[D_MD4][0] = count;
  1864. c[D_MD5][0] = count;
  1865. c[D_HMAC][0] = count;
  1866. c[D_SHA1][0] = count;
  1867. c[D_RMD160][0] = count;
  1868. c[D_RC4][0] = count * 5;
  1869. c[D_CBC_DES][0] = count;
  1870. c[D_EDE3_DES][0] = count / 3;
  1871. c[D_CBC_IDEA][0] = count;
  1872. c[D_CBC_SEED][0] = count;
  1873. c[D_CBC_RC2][0] = count;
  1874. c[D_CBC_RC5][0] = count;
  1875. c[D_CBC_BF][0] = count;
  1876. c[D_CBC_CAST][0] = count;
  1877. c[D_CBC_128_AES][0] = count;
  1878. c[D_CBC_192_AES][0] = count;
  1879. c[D_CBC_256_AES][0] = count;
  1880. c[D_CBC_128_CML][0] = count;
  1881. c[D_CBC_192_CML][0] = count;
  1882. c[D_CBC_256_CML][0] = count;
  1883. c[D_EVP][0] = count;
  1884. c[D_SHA256][0] = count;
  1885. c[D_SHA512][0] = count;
  1886. c[D_WHIRLPOOL][0] = count;
  1887. c[D_IGE_128_AES][0] = count;
  1888. c[D_IGE_192_AES][0] = count;
  1889. c[D_IGE_256_AES][0] = count;
  1890. c[D_GHASH][0] = count;
  1891. c[D_RAND][0] = count;
  1892. c[D_EVP_HMAC][0] = count;
  1893. c[D_EVP_CMAC][0] = count;
  1894. for (i = 1; i < size_num; i++) {
  1895. long l0 = (long)lengths[0];
  1896. long l1 = (long)lengths[i];
  1897. c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
  1898. c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
  1899. c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
  1900. c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
  1901. c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
  1902. c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
  1903. c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
  1904. c[D_EVP][i] = = c[D_EVP][0] * 4 * l0 / l1;
  1905. c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
  1906. c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
  1907. c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
  1908. c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
  1909. c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
  1910. c[D_EVP_HMAC][i] = = c[D_EVP_HMAC][0] * 4 * l0 / l1;
  1911. c[D_EVP_CMAC][i] = = c[D_EVP_CMAC][0] * 4 * l0 / l1;
  1912. l0 = (long)lengths[i - 1];
  1913. c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
  1914. c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
  1915. c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
  1916. c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
  1917. c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
  1918. c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
  1919. c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
  1920. c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
  1921. c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
  1922. c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
  1923. c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
  1924. c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
  1925. c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
  1926. c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
  1927. c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
  1928. c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
  1929. c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
  1930. c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
  1931. }
  1932. # ifndef OPENSSL_NO_RSA
  1933. rsa_c[R_RSA_512][0] = count / 2000;
  1934. rsa_c[R_RSA_512][1] = count / 400;
  1935. for (i = 1; i < RSA_NUM; i++) {
  1936. rsa_c[i][0] = rsa_c[i - 1][0] / 8;
  1937. rsa_c[i][1] = rsa_c[i - 1][1] / 4;
  1938. if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
  1939. rsa_doit[i] = 0;
  1940. else {
  1941. if (rsa_c[i][0] == 0) {
  1942. rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
  1943. rsa_c[i][1] = 20;
  1944. }
  1945. }
  1946. }
  1947. # endif
  1948. # ifndef OPENSSL_NO_DSA
  1949. dsa_c[R_DSA_512][0] = count / 1000;
  1950. dsa_c[R_DSA_512][1] = count / 1000 / 2;
  1951. for (i = 1; i < DSA_NUM; i++) {
  1952. dsa_c[i][0] = dsa_c[i - 1][0] / 4;
  1953. dsa_c[i][1] = dsa_c[i - 1][1] / 4;
  1954. if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
  1955. dsa_doit[i] = 0;
  1956. else {
  1957. if (dsa_c[i][0] == 0) {
  1958. dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
  1959. dsa_c[i][1] = 1;
  1960. }
  1961. }
  1962. }
  1963. # endif
  1964. # ifndef OPENSSL_NO_EC
  1965. ecdsa_c[R_EC_P160][0] = count / 1000;
  1966. ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
  1967. for (i = R_EC_P192; i <= R_EC_P521; i++) {
  1968. ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
  1969. ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
  1970. if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
  1971. ecdsa_doit[i] = 0;
  1972. else {
  1973. if (ecdsa_c[i][0] == 0) {
  1974. ecdsa_c[i][0] = 1;
  1975. ecdsa_c[i][1] = 1;
  1976. }
  1977. }
  1978. }
  1979. # ifndef OPENSSL_NO_EC2M
  1980. ecdsa_c[R_EC_K163][0] = count / 1000;
  1981. ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
  1982. for (i = R_EC_K233; i <= R_EC_K571; i++) {
  1983. ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
  1984. ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
  1985. if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
  1986. ecdsa_doit[i] = 0;
  1987. else {
  1988. if (ecdsa_c[i][0] == 0) {
  1989. ecdsa_c[i][0] = 1;
  1990. ecdsa_c[i][1] = 1;
  1991. }
  1992. }
  1993. }
  1994. ecdsa_c[R_EC_B163][0] = count / 1000;
  1995. ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
  1996. for (i = R_EC_B233; i <= R_EC_B571; i++) {
  1997. ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
  1998. ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
  1999. if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
  2000. ecdsa_doit[i] = 0;
  2001. else {
  2002. if (ecdsa_c[i][0] == 0) {
  2003. ecdsa_c[i][0] = 1;
  2004. ecdsa_c[i][1] = 1;
  2005. }
  2006. }
  2007. }
  2008. # endif
  2009. ecdh_c[R_EC_P160][0] = count / 1000;
  2010. for (i = R_EC_P192; i <= R_EC_P521; i++) {
  2011. ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
  2012. if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
  2013. ecdh_doit[i] = 0;
  2014. else {
  2015. if (ecdh_c[i][0] == 0) {
  2016. ecdh_c[i][0] = 1;
  2017. }
  2018. }
  2019. }
  2020. # ifndef OPENSSL_NO_EC2M
  2021. ecdh_c[R_EC_K163][0] = count / 1000;
  2022. for (i = R_EC_K233; i <= R_EC_K571; i++) {
  2023. ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
  2024. if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
  2025. ecdh_doit[i] = 0;
  2026. else {
  2027. if (ecdh_c[i][0] == 0) {
  2028. ecdh_c[i][0] = 1;
  2029. }
  2030. }
  2031. }
  2032. ecdh_c[R_EC_B163][0] = count / 1000;
  2033. for (i = R_EC_B233; i <= R_EC_B571; i++) {
  2034. ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
  2035. if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
  2036. ecdh_doit[i] = 0;
  2037. else {
  2038. if (ecdh_c[i][0] == 0) {
  2039. ecdh_c[i][0] = 1;
  2040. }
  2041. }
  2042. }
  2043. # endif
  2044. /* repeated code good to factorize */
  2045. ecdh_c[R_EC_BRP256R1][0] = count / 1000;
  2046. for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
  2047. ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
  2048. if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
  2049. ecdh_doit[i] = 0;
  2050. else {
  2051. if (ecdh_c[i][0] == 0) {
  2052. ecdh_c[i][0] = 1;
  2053. }
  2054. }
  2055. }
  2056. ecdh_c[R_EC_BRP256T1][0] = count / 1000;
  2057. for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
  2058. ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
  2059. if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
  2060. ecdh_doit[i] = 0;
  2061. else {
  2062. if (ecdh_c[i][0] == 0) {
  2063. ecdh_c[i][0] = 1;
  2064. }
  2065. }
  2066. }
  2067. /* default iteration count for the last two EC Curves */
  2068. ecdh_c[R_EC_X25519][0] = count / 1800;
  2069. ecdh_c[R_EC_X448][0] = count / 7200;
  2070. eddsa_c[R_EC_Ed25519][0] = count / 1800;
  2071. eddsa_c[R_EC_Ed448][0] = count / 7200;
  2072. # ifndef OPENSSL_NO_SM2
  2073. sm2_c[R_EC_SM2P256][0] = count / 1800;
  2074. # endif
  2075. # endif /* OPENSSL_NO_EC */
  2076. # else
  2077. /* not worth fixing */
  2078. # error "You cannot disable DES on systems without SIGALRM."
  2079. # endif /* OPENSSL_NO_DES */
  2080. #elif SIGALRM > 0
  2081. signal(SIGALRM, alarmed);
  2082. #endif /* SIGALRM */
  2083. #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2084. if (doit[D_MD2]) {
  2085. for (testnum = 0; testnum < size_num; testnum++) {
  2086. print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
  2087. seconds.sym);
  2088. Time_F(START);
  2089. count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
  2090. d = Time_F(STOP);
  2091. print_result(D_MD2, testnum, count, d);
  2092. }
  2093. }
  2094. #endif
  2095. #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2096. if (doit[D_MDC2]) {
  2097. for (testnum = 0; testnum < size_num; testnum++) {
  2098. print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
  2099. seconds.sym);
  2100. Time_F(START);
  2101. count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
  2102. d = Time_F(STOP);
  2103. print_result(D_MDC2, testnum, count, d);
  2104. if (count < 0)
  2105. break;
  2106. }
  2107. }
  2108. #endif
  2109. #if !defined(OPENSSL_NO_MD4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2110. if (doit[D_MD4]) {
  2111. for (testnum = 0; testnum < size_num; testnum++) {
  2112. print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
  2113. seconds.sym);
  2114. Time_F(START);
  2115. count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
  2116. d = Time_F(STOP);
  2117. print_result(D_MD4, testnum, count, d);
  2118. if (count < 0)
  2119. break;
  2120. }
  2121. }
  2122. #endif
  2123. #ifndef OPENSSL_NO_MD5
  2124. if (doit[D_MD5]) {
  2125. for (testnum = 0; testnum < size_num; testnum++) {
  2126. print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
  2127. seconds.sym);
  2128. Time_F(START);
  2129. count = run_benchmark(async_jobs, MD5_loop, loopargs);
  2130. d = Time_F(STOP);
  2131. print_result(D_MD5, testnum, count, d);
  2132. }
  2133. }
  2134. if (doit[D_HMAC]) {
  2135. static const char hmac_key[] = "This is a key...";
  2136. int len = strlen(hmac_key);
  2137. for (i = 0; i < loopargs_len; i++) {
  2138. loopargs[i].hctx = HMAC_CTX_new();
  2139. if (loopargs[i].hctx == NULL) {
  2140. BIO_printf(bio_err, "HMAC malloc failure, exiting...");
  2141. exit(1);
  2142. }
  2143. HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
  2144. }
  2145. for (testnum = 0; testnum < size_num; testnum++) {
  2146. print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
  2147. seconds.sym);
  2148. Time_F(START);
  2149. count = run_benchmark(async_jobs, HMAC_loop, loopargs);
  2150. d = Time_F(STOP);
  2151. print_result(D_HMAC, testnum, count, d);
  2152. }
  2153. for (i = 0; i < loopargs_len; i++)
  2154. HMAC_CTX_free(loopargs[i].hctx);
  2155. }
  2156. #endif
  2157. if (doit[D_SHA1]) {
  2158. for (testnum = 0; testnum < size_num; testnum++) {
  2159. print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
  2160. seconds.sym);
  2161. Time_F(START);
  2162. count = run_benchmark(async_jobs, SHA1_loop, loopargs);
  2163. d = Time_F(STOP);
  2164. print_result(D_SHA1, testnum, count, d);
  2165. }
  2166. }
  2167. if (doit[D_SHA256]) {
  2168. for (testnum = 0; testnum < size_num; testnum++) {
  2169. print_message(names[D_SHA256], c[D_SHA256][testnum],
  2170. lengths[testnum], seconds.sym);
  2171. Time_F(START);
  2172. count = run_benchmark(async_jobs, SHA256_loop, loopargs);
  2173. d = Time_F(STOP);
  2174. print_result(D_SHA256, testnum, count, d);
  2175. }
  2176. }
  2177. if (doit[D_SHA512]) {
  2178. for (testnum = 0; testnum < size_num; testnum++) {
  2179. print_message(names[D_SHA512], c[D_SHA512][testnum],
  2180. lengths[testnum], seconds.sym);
  2181. Time_F(START);
  2182. count = run_benchmark(async_jobs, SHA512_loop, loopargs);
  2183. d = Time_F(STOP);
  2184. print_result(D_SHA512, testnum, count, d);
  2185. }
  2186. }
  2187. #if !defined(OPENSSL_NO_WHIRLPOOL) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2188. if (doit[D_WHIRLPOOL]) {
  2189. for (testnum = 0; testnum < size_num; testnum++) {
  2190. print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
  2191. lengths[testnum], seconds.sym);
  2192. Time_F(START);
  2193. count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
  2194. d = Time_F(STOP);
  2195. print_result(D_WHIRLPOOL, testnum, count, d);
  2196. }
  2197. }
  2198. #endif
  2199. #if !defined(OPENSSL_NO_RMD160) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2200. if (doit[D_RMD160]) {
  2201. for (testnum = 0; testnum < size_num; testnum++) {
  2202. print_message(names[D_RMD160], c[D_RMD160][testnum],
  2203. lengths[testnum], seconds.sym);
  2204. Time_F(START);
  2205. count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
  2206. d = Time_F(STOP);
  2207. print_result(D_RMD160, testnum, count, d);
  2208. if (count < 0)
  2209. break;
  2210. }
  2211. }
  2212. #endif
  2213. #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2214. if (doit[D_RC4]) {
  2215. for (testnum = 0; testnum < size_num; testnum++) {
  2216. print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
  2217. seconds.sym);
  2218. Time_F(START);
  2219. count = run_benchmark(async_jobs, RC4_loop, loopargs);
  2220. d = Time_F(STOP);
  2221. print_result(D_RC4, testnum, count, d);
  2222. }
  2223. }
  2224. #endif
  2225. #ifndef OPENSSL_NO_DES
  2226. if (doit[D_CBC_DES]) {
  2227. for (testnum = 0; testnum < size_num; testnum++) {
  2228. print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
  2229. lengths[testnum], seconds.sym);
  2230. Time_F(START);
  2231. count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
  2232. d = Time_F(STOP);
  2233. print_result(D_CBC_DES, testnum, count, d);
  2234. }
  2235. }
  2236. if (doit[D_EDE3_DES]) {
  2237. for (testnum = 0; testnum < size_num; testnum++) {
  2238. print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
  2239. lengths[testnum], seconds.sym);
  2240. Time_F(START);
  2241. count =
  2242. run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
  2243. d = Time_F(STOP);
  2244. print_result(D_EDE3_DES, testnum, count, d);
  2245. }
  2246. }
  2247. #endif
  2248. #ifndef OPENSSL_NO_DEPRECATED_3_0
  2249. if (doit[D_CBC_128_AES]) {
  2250. for (testnum = 0; testnum < size_num; testnum++) {
  2251. print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
  2252. lengths[testnum], seconds.sym);
  2253. Time_F(START);
  2254. count =
  2255. run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
  2256. d = Time_F(STOP);
  2257. print_result(D_CBC_128_AES, testnum, count, d);
  2258. }
  2259. }
  2260. if (doit[D_CBC_192_AES]) {
  2261. for (testnum = 0; testnum < size_num; testnum++) {
  2262. print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
  2263. lengths[testnum], seconds.sym);
  2264. Time_F(START);
  2265. count =
  2266. run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
  2267. d = Time_F(STOP);
  2268. print_result(D_CBC_192_AES, testnum, count, d);
  2269. }
  2270. }
  2271. if (doit[D_CBC_256_AES]) {
  2272. for (testnum = 0; testnum < size_num; testnum++) {
  2273. print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
  2274. lengths[testnum], seconds.sym);
  2275. Time_F(START);
  2276. count =
  2277. run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
  2278. d = Time_F(STOP);
  2279. print_result(D_CBC_256_AES, testnum, count, d);
  2280. }
  2281. }
  2282. if (doit[D_IGE_128_AES]) {
  2283. for (testnum = 0; testnum < size_num; testnum++) {
  2284. print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
  2285. lengths[testnum], seconds.sym);
  2286. Time_F(START);
  2287. count =
  2288. run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
  2289. d = Time_F(STOP);
  2290. print_result(D_IGE_128_AES, testnum, count, d);
  2291. }
  2292. }
  2293. if (doit[D_IGE_192_AES]) {
  2294. for (testnum = 0; testnum < size_num; testnum++) {
  2295. print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
  2296. lengths[testnum], seconds.sym);
  2297. Time_F(START);
  2298. count =
  2299. run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
  2300. d = Time_F(STOP);
  2301. print_result(D_IGE_192_AES, testnum, count, d);
  2302. }
  2303. }
  2304. if (doit[D_IGE_256_AES]) {
  2305. for (testnum = 0; testnum < size_num; testnum++) {
  2306. print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
  2307. lengths[testnum], seconds.sym);
  2308. Time_F(START);
  2309. count =
  2310. run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
  2311. d = Time_F(STOP);
  2312. print_result(D_IGE_256_AES, testnum, count, d);
  2313. }
  2314. }
  2315. if (doit[D_GHASH]) {
  2316. for (i = 0; i < loopargs_len; i++) {
  2317. loopargs[i].gcm_ctx =
  2318. CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
  2319. CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
  2320. (unsigned char *)"0123456789ab", 12);
  2321. }
  2322. for (testnum = 0; testnum < size_num; testnum++) {
  2323. print_message(names[D_GHASH], c[D_GHASH][testnum],
  2324. lengths[testnum], seconds.sym);
  2325. Time_F(START);
  2326. count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
  2327. d = Time_F(STOP);
  2328. print_result(D_GHASH, testnum, count, d);
  2329. }
  2330. for (i = 0; i < loopargs_len; i++)
  2331. CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
  2332. }
  2333. #endif /* OPENSSL_NO_DEPRECATED_3_0 */
  2334. #if !defined(OPENSSL_NO_CAMELLIA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2335. if (doit[D_CBC_128_CML]) {
  2336. if (async_jobs > 0) {
  2337. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2338. names[D_CBC_128_CML]);
  2339. doit[D_CBC_128_CML] = 0;
  2340. }
  2341. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2342. print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
  2343. lengths[testnum], seconds.sym);
  2344. Time_F(START);
  2345. for (count = 0; COND(c[D_CBC_128_CML][testnum]); count++)
  2346. Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2347. (size_t)lengths[testnum], &camellia_ks[0],
  2348. iv, CAMELLIA_ENCRYPT);
  2349. d = Time_F(STOP);
  2350. print_result(D_CBC_128_CML, testnum, count, d);
  2351. }
  2352. }
  2353. if (doit[D_CBC_192_CML]) {
  2354. if (async_jobs > 0) {
  2355. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2356. names[D_CBC_192_CML]);
  2357. doit[D_CBC_192_CML] = 0;
  2358. }
  2359. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2360. print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
  2361. lengths[testnum], seconds.sym);
  2362. if (async_jobs > 0) {
  2363. BIO_printf(bio_err, "Async mode is not supported, exiting...");
  2364. exit(1);
  2365. }
  2366. Time_F(START);
  2367. for (count = 0; COND(c[D_CBC_192_CML][testnum]); count++)
  2368. Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2369. (size_t)lengths[testnum], &camellia_ks[1],
  2370. iv, CAMELLIA_ENCRYPT);
  2371. d = Time_F(STOP);
  2372. print_result(D_CBC_192_CML, testnum, count, d);
  2373. }
  2374. }
  2375. if (doit[D_CBC_256_CML]) {
  2376. if (async_jobs > 0) {
  2377. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2378. names[D_CBC_256_CML]);
  2379. doit[D_CBC_256_CML] = 0;
  2380. }
  2381. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2382. print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
  2383. lengths[testnum], seconds.sym);
  2384. Time_F(START);
  2385. for (count = 0; COND(c[D_CBC_256_CML][testnum]); count++)
  2386. Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2387. (size_t)lengths[testnum], &camellia_ks[2],
  2388. iv, CAMELLIA_ENCRYPT);
  2389. d = Time_F(STOP);
  2390. print_result(D_CBC_256_CML, testnum, count, d);
  2391. }
  2392. }
  2393. #endif
  2394. #ifndef OPENSSL_NO_IDEA
  2395. if (doit[D_CBC_IDEA]) {
  2396. if (async_jobs > 0) {
  2397. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2398. names[D_CBC_IDEA]);
  2399. doit[D_CBC_IDEA] = 0;
  2400. }
  2401. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2402. print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
  2403. lengths[testnum], seconds.sym);
  2404. Time_F(START);
  2405. for (count = 0; COND(c[D_CBC_IDEA][testnum]); count++)
  2406. IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2407. (size_t)lengths[testnum], &idea_ks,
  2408. iv, IDEA_ENCRYPT);
  2409. d = Time_F(STOP);
  2410. print_result(D_CBC_IDEA, testnum, count, d);
  2411. }
  2412. }
  2413. #endif
  2414. #if !defined(OPENSSL_NO_SEED) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2415. if (doit[D_CBC_SEED]) {
  2416. if (async_jobs > 0) {
  2417. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2418. names[D_CBC_SEED]);
  2419. doit[D_CBC_SEED] = 0;
  2420. }
  2421. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2422. print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
  2423. lengths[testnum], seconds.sym);
  2424. Time_F(START);
  2425. for (count = 0; COND(c[D_CBC_SEED][testnum]); count++)
  2426. SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2427. (size_t)lengths[testnum], &seed_ks, iv, 1);
  2428. d = Time_F(STOP);
  2429. print_result(D_CBC_SEED, testnum, count, d);
  2430. }
  2431. }
  2432. #endif
  2433. #if !defined(OPENSSL_NO_RC2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2434. if (doit[D_CBC_RC2]) {
  2435. if (async_jobs > 0) {
  2436. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2437. names[D_CBC_RC2]);
  2438. doit[D_CBC_RC2] = 0;
  2439. }
  2440. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2441. print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
  2442. lengths[testnum], seconds.sym);
  2443. if (async_jobs > 0) {
  2444. BIO_printf(bio_err, "Async mode is not supported, exiting...");
  2445. exit(1);
  2446. }
  2447. Time_F(START);
  2448. for (count = 0; COND(c[D_CBC_RC2][testnum]); count++)
  2449. RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2450. (size_t)lengths[testnum], &rc2_ks,
  2451. iv, RC2_ENCRYPT);
  2452. d = Time_F(STOP);
  2453. print_result(D_CBC_RC2, testnum, count, d);
  2454. }
  2455. }
  2456. #endif
  2457. #if !defined(OPENSSL_NO_RC5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2458. if (doit[D_CBC_RC5]) {
  2459. if (async_jobs > 0) {
  2460. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2461. names[D_CBC_RC5]);
  2462. doit[D_CBC_RC5] = 0;
  2463. }
  2464. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2465. print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
  2466. lengths[testnum], seconds.sym);
  2467. if (async_jobs > 0) {
  2468. BIO_printf(bio_err, "Async mode is not supported, exiting...");
  2469. exit(1);
  2470. }
  2471. Time_F(START);
  2472. for (count = 0; COND(c[D_CBC_RC5][testnum]); count++)
  2473. RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2474. (size_t)lengths[testnum], &rc5_ks,
  2475. iv, RC5_ENCRYPT);
  2476. d = Time_F(STOP);
  2477. print_result(D_CBC_RC5, testnum, count, d);
  2478. }
  2479. }
  2480. #endif
  2481. #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2482. if (doit[D_CBC_BF]) {
  2483. if (async_jobs > 0) {
  2484. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2485. names[D_CBC_BF]);
  2486. doit[D_CBC_BF] = 0;
  2487. }
  2488. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2489. print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
  2490. lengths[testnum], seconds.sym);
  2491. Time_F(START);
  2492. for (count = 0; COND(c[D_CBC_BF][testnum]); count++)
  2493. BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2494. (size_t)lengths[testnum], &bf_ks,
  2495. iv, BF_ENCRYPT);
  2496. d = Time_F(STOP);
  2497. print_result(D_CBC_BF, testnum, count, d);
  2498. }
  2499. }
  2500. #endif
  2501. #if !defined(OPENSSL_NO_CAST) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  2502. if (doit[D_CBC_CAST]) {
  2503. if (async_jobs > 0) {
  2504. BIO_printf(bio_err, "Async mode is not supported with %s\n",
  2505. names[D_CBC_CAST]);
  2506. doit[D_CBC_CAST] = 0;
  2507. }
  2508. for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
  2509. print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
  2510. lengths[testnum], seconds.sym);
  2511. Time_F(START);
  2512. for (count = 0; COND(c[D_CBC_CAST][testnum]); count++)
  2513. CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
  2514. (size_t)lengths[testnum], &cast_ks,
  2515. iv, CAST_ENCRYPT);
  2516. d = Time_F(STOP);
  2517. print_result(D_CBC_CAST, testnum, count, d);
  2518. }
  2519. }
  2520. #endif
  2521. if (doit[D_RAND]) {
  2522. for (testnum = 0; testnum < size_num; testnum++) {
  2523. print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
  2524. seconds.sym);
  2525. Time_F(START);
  2526. count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
  2527. d = Time_F(STOP);
  2528. print_result(D_RAND, testnum, count, d);
  2529. }
  2530. }
  2531. if (doit[D_EVP]) {
  2532. if (evp_cipher != NULL) {
  2533. int (*loopfunc) (void *) = EVP_Update_loop;
  2534. if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
  2535. EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
  2536. multiblock_speed(evp_cipher, lengths_single, &seconds);
  2537. ret = 0;
  2538. goto end;
  2539. }
  2540. names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
  2541. if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
  2542. loopfunc = EVP_Update_loop_ccm;
  2543. } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
  2544. EVP_CIPH_FLAG_AEAD_CIPHER)) {
  2545. loopfunc = EVP_Update_loop_aead;
  2546. if (lengths == lengths_list) {
  2547. lengths = aead_lengths_list;
  2548. size_num = OSSL_NELEM(aead_lengths_list);
  2549. }
  2550. }
  2551. for (testnum = 0; testnum < size_num; testnum++) {
  2552. print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
  2553. seconds.sym);
  2554. for (k = 0; k < loopargs_len; k++) {
  2555. loopargs[k].ctx = EVP_CIPHER_CTX_new();
  2556. if (loopargs[k].ctx == NULL) {
  2557. BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
  2558. exit(1);
  2559. }
  2560. if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
  2561. NULL, iv, decrypt ? 0 : 1)) {
  2562. BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
  2563. ERR_print_errors(bio_err);
  2564. exit(1);
  2565. }
  2566. EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
  2567. keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
  2568. loopargs[k].key = app_malloc(keylen, "evp_cipher key");
  2569. EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
  2570. if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
  2571. loopargs[k].key, NULL, -1)) {
  2572. BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
  2573. ERR_print_errors(bio_err);
  2574. exit(1);
  2575. }
  2576. OPENSSL_clear_free(loopargs[k].key, keylen);
  2577. /* SIV mode only allows for a single Update operation */
  2578. if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
  2579. EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
  2580. }
  2581. Time_F(START);
  2582. count = run_benchmark(async_jobs, loopfunc, loopargs);
  2583. d = Time_F(STOP);
  2584. for (k = 0; k < loopargs_len; k++) {
  2585. EVP_CIPHER_CTX_free(loopargs[k].ctx);
  2586. }
  2587. print_result(D_EVP, testnum, count, d);
  2588. }
  2589. } else if (evp_md != NULL) {
  2590. names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
  2591. for (testnum = 0; testnum < size_num; testnum++) {
  2592. print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum],
  2593. seconds.sym);
  2594. Time_F(START);
  2595. count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
  2596. d = Time_F(STOP);
  2597. print_result(D_EVP, testnum, count, d);
  2598. }
  2599. }
  2600. }
  2601. if (doit[D_EVP_HMAC] && evp_hmac_md != NULL) {
  2602. const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
  2603. evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
  2604. "HMAC name");
  2605. sprintf(evp_hmac_name, "HMAC(%s)", md_name);
  2606. names[D_EVP_HMAC] = evp_hmac_name;
  2607. for (testnum = 0; testnum < size_num; testnum++) {
  2608. print_message(names[D_EVP_HMAC], c[D_EVP_HMAC][testnum], lengths[testnum],
  2609. seconds.sym);
  2610. Time_F(START);
  2611. count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
  2612. d = Time_F(STOP);
  2613. print_result(D_EVP_HMAC, testnum, count, d);
  2614. }
  2615. }
  2616. #ifndef OPENSSL_NO_CMAC
  2617. if (doit[D_EVP_CMAC] && evp_cmac_cipher != NULL) {
  2618. const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
  2619. evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
  2620. "CMAC name");
  2621. sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
  2622. names[D_EVP_CMAC] = evp_cmac_name;
  2623. for (i = 0; i < loopargs_len; i++) {
  2624. loopargs[i].cmac_ctx = CMAC_CTX_new();
  2625. if (loopargs[i].cmac_ctx == NULL) {
  2626. BIO_printf(bio_err, "CMAC malloc failure, exiting...");
  2627. exit(1);
  2628. }
  2629. }
  2630. for (testnum = 0; testnum < size_num; testnum++) {
  2631. print_message(names[D_EVP_CMAC], c[D_EVP_CMAC][testnum], lengths[testnum],
  2632. seconds.sym);
  2633. Time_F(START);
  2634. count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
  2635. d = Time_F(STOP);
  2636. print_result(D_EVP_CMAC, testnum, count, d);
  2637. }
  2638. for (i = 0; i < loopargs_len; i++)
  2639. CMAC_CTX_free(loopargs[i].cmac_ctx);
  2640. }
  2641. #endif
  2642. for (i = 0; i < loopargs_len; i++)
  2643. if (RAND_bytes(loopargs[i].buf, 36) <= 0)
  2644. goto end;
  2645. #ifndef OPENSSL_NO_RSA
  2646. for (testnum = 0; testnum < RSA_NUM; testnum++) {
  2647. int st = 0;
  2648. if (!rsa_doit[testnum])
  2649. continue;
  2650. for (i = 0; i < loopargs_len; i++) {
  2651. if (primes > RSA_DEFAULT_PRIME_NUM) {
  2652. /* we haven't set keys yet, generate multi-prime RSA keys */
  2653. BIGNUM *bn = BN_new();
  2654. if (bn == NULL)
  2655. goto end;
  2656. if (!BN_set_word(bn, RSA_F4)) {
  2657. BN_free(bn);
  2658. goto end;
  2659. }
  2660. BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
  2661. rsa_choices[testnum].name);
  2662. loopargs[i].rsa_key[testnum] = RSA_new();
  2663. if (loopargs[i].rsa_key[testnum] == NULL) {
  2664. BN_free(bn);
  2665. goto end;
  2666. }
  2667. if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
  2668. rsa_keys[testnum].bits,
  2669. primes, bn, NULL)) {
  2670. BN_free(bn);
  2671. goto end;
  2672. }
  2673. BN_free(bn);
  2674. }
  2675. st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
  2676. &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
  2677. if (st == 0)
  2678. break;
  2679. }
  2680. if (st == 0) {
  2681. BIO_printf(bio_err,
  2682. "RSA sign failure. No RSA sign will be done.\n");
  2683. ERR_print_errors(bio_err);
  2684. rsa_count = 1;
  2685. } else {
  2686. pkey_print_message("private", "rsa",
  2687. rsa_c[testnum][0], rsa_keys[testnum].bits,
  2688. seconds.rsa);
  2689. /* RSA_blinding_on(rsa_key[testnum],NULL); */
  2690. Time_F(START);
  2691. count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
  2692. d = Time_F(STOP);
  2693. BIO_printf(bio_err,
  2694. mr ? "+R1:%ld:%d:%.2f\n"
  2695. : "%ld %u bits private RSA's in %.2fs\n",
  2696. count, rsa_keys[testnum].bits, d);
  2697. rsa_results[testnum][0] = (double)count / d;
  2698. rsa_count = count;
  2699. }
  2700. for (i = 0; i < loopargs_len; i++) {
  2701. st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
  2702. loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
  2703. if (st <= 0)
  2704. break;
  2705. }
  2706. if (st <= 0) {
  2707. BIO_printf(bio_err,
  2708. "RSA verify failure. No RSA verify will be done.\n");
  2709. ERR_print_errors(bio_err);
  2710. rsa_doit[testnum] = 0;
  2711. } else {
  2712. pkey_print_message("public", "rsa",
  2713. rsa_c[testnum][1], rsa_keys[testnum].bits,
  2714. seconds.rsa);
  2715. Time_F(START);
  2716. count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
  2717. d = Time_F(STOP);
  2718. BIO_printf(bio_err,
  2719. mr ? "+R2:%ld:%d:%.2f\n"
  2720. : "%ld %u bits public RSA's in %.2fs\n",
  2721. count, rsa_keys[testnum].bits, d);
  2722. rsa_results[testnum][1] = (double)count / d;
  2723. }
  2724. if (rsa_count <= 1) {
  2725. /* if longer than 10s, don't do any more */
  2726. stop_it(rsa_doit, testnum);
  2727. }
  2728. }
  2729. #endif /* OPENSSL_NO_RSA */
  2730. for (i = 0; i < loopargs_len; i++)
  2731. if (RAND_bytes(loopargs[i].buf, 36) <= 0)
  2732. goto end;
  2733. #ifndef OPENSSL_NO_DSA
  2734. for (testnum = 0; testnum < DSA_NUM; testnum++) {
  2735. int st = 0;
  2736. if (!dsa_doit[testnum])
  2737. continue;
  2738. /* DSA_generate_key(dsa_key[testnum]); */
  2739. /* DSA_sign_setup(dsa_key[testnum],NULL); */
  2740. for (i = 0; i < loopargs_len; i++) {
  2741. st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
  2742. &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
  2743. if (st == 0)
  2744. break;
  2745. }
  2746. if (st == 0) {
  2747. BIO_printf(bio_err,
  2748. "DSA sign failure. No DSA sign will be done.\n");
  2749. ERR_print_errors(bio_err);
  2750. rsa_count = 1;
  2751. } else {
  2752. pkey_print_message("sign", "dsa",
  2753. dsa_c[testnum][0], dsa_bits[testnum],
  2754. seconds.dsa);
  2755. Time_F(START);
  2756. count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
  2757. d = Time_F(STOP);
  2758. BIO_printf(bio_err,
  2759. mr ? "+R3:%ld:%u:%.2f\n"
  2760. : "%ld %u bits DSA signs in %.2fs\n",
  2761. count, dsa_bits[testnum], d);
  2762. dsa_results[testnum][0] = (double)count / d;
  2763. rsa_count = count;
  2764. }
  2765. for (i = 0; i < loopargs_len; i++) {
  2766. st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
  2767. loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
  2768. if (st <= 0)
  2769. break;
  2770. }
  2771. if (st <= 0) {
  2772. BIO_printf(bio_err,
  2773. "DSA verify failure. No DSA verify will be done.\n");
  2774. ERR_print_errors(bio_err);
  2775. dsa_doit[testnum] = 0;
  2776. } else {
  2777. pkey_print_message("verify", "dsa",
  2778. dsa_c[testnum][1], dsa_bits[testnum],
  2779. seconds.dsa);
  2780. Time_F(START);
  2781. count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
  2782. d = Time_F(STOP);
  2783. BIO_printf(bio_err,
  2784. mr ? "+R4:%ld:%u:%.2f\n"
  2785. : "%ld %u bits DSA verify in %.2fs\n",
  2786. count, dsa_bits[testnum], d);
  2787. dsa_results[testnum][1] = (double)count / d;
  2788. }
  2789. if (rsa_count <= 1) {
  2790. /* if longer than 10s, don't do any more */
  2791. stop_it(dsa_doit, testnum);
  2792. }
  2793. }
  2794. #endif /* OPENSSL_NO_DSA */
  2795. #ifndef OPENSSL_NO_EC
  2796. for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
  2797. int st = 1;
  2798. if (!ecdsa_doit[testnum])
  2799. continue; /* Ignore Curve */
  2800. for (i = 0; i < loopargs_len; i++) {
  2801. loopargs[i].ecdsa[testnum] =
  2802. EC_KEY_new_by_curve_name(ec_curves[testnum].nid);
  2803. if (loopargs[i].ecdsa[testnum] == NULL) {
  2804. st = 0;
  2805. break;
  2806. }
  2807. }
  2808. if (st == 0) {
  2809. BIO_printf(bio_err, "ECDSA failure.\n");
  2810. ERR_print_errors(bio_err);
  2811. rsa_count = 1;
  2812. } else {
  2813. for (i = 0; i < loopargs_len; i++) {
  2814. EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
  2815. /* Perform ECDSA signature test */
  2816. EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
  2817. st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
  2818. &loopargs[i].siglen,
  2819. loopargs[i].ecdsa[testnum]);
  2820. if (st == 0)
  2821. break;
  2822. }
  2823. if (st == 0) {
  2824. BIO_printf(bio_err,
  2825. "ECDSA sign failure. No ECDSA sign will be done.\n");
  2826. ERR_print_errors(bio_err);
  2827. rsa_count = 1;
  2828. } else {
  2829. pkey_print_message("sign", "ecdsa",
  2830. ecdsa_c[testnum][0],
  2831. ec_curves[testnum].bits, seconds.ecdsa);
  2832. Time_F(START);
  2833. count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
  2834. d = Time_F(STOP);
  2835. BIO_printf(bio_err,
  2836. mr ? "+R5:%ld:%u:%.2f\n" :
  2837. "%ld %u bits ECDSA signs in %.2fs \n",
  2838. count, ec_curves[testnum].bits, d);
  2839. ecdsa_results[testnum][0] = (double)count / d;
  2840. rsa_count = count;
  2841. }
  2842. /* Perform ECDSA verification test */
  2843. for (i = 0; i < loopargs_len; i++) {
  2844. st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
  2845. loopargs[i].siglen,
  2846. loopargs[i].ecdsa[testnum]);
  2847. if (st != 1)
  2848. break;
  2849. }
  2850. if (st != 1) {
  2851. BIO_printf(bio_err,
  2852. "ECDSA verify failure. No ECDSA verify will be done.\n");
  2853. ERR_print_errors(bio_err);
  2854. ecdsa_doit[testnum] = 0;
  2855. } else {
  2856. pkey_print_message("verify", "ecdsa",
  2857. ecdsa_c[testnum][1],
  2858. ec_curves[testnum].bits, seconds.ecdsa);
  2859. Time_F(START);
  2860. count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
  2861. d = Time_F(STOP);
  2862. BIO_printf(bio_err,
  2863. mr ? "+R6:%ld:%u:%.2f\n"
  2864. : "%ld %u bits ECDSA verify in %.2fs\n",
  2865. count, ec_curves[testnum].bits, d);
  2866. ecdsa_results[testnum][1] = (double)count / d;
  2867. }
  2868. if (rsa_count <= 1) {
  2869. /* if longer than 10s, don't do any more */
  2870. stop_it(ecdsa_doit, testnum);
  2871. }
  2872. }
  2873. }
  2874. for (testnum = 0; testnum < EC_NUM; testnum++) {
  2875. int ecdh_checks = 1;
  2876. if (!ecdh_doit[testnum])
  2877. continue;
  2878. for (i = 0; i < loopargs_len; i++) {
  2879. EVP_PKEY_CTX *kctx = NULL;
  2880. EVP_PKEY_CTX *test_ctx = NULL;
  2881. EVP_PKEY_CTX *ctx = NULL;
  2882. EVP_PKEY *key_A = NULL;
  2883. EVP_PKEY *key_B = NULL;
  2884. size_t outlen;
  2885. size_t test_outlen;
  2886. /* Ensure that the error queue is empty */
  2887. if (ERR_peek_error()) {
  2888. BIO_printf(bio_err,
  2889. "WARNING: the error queue contains previous unhandled errors.\n");
  2890. ERR_print_errors(bio_err);
  2891. }
  2892. /* Let's try to create a ctx directly from the NID: this works for
  2893. * curves like Curve25519 that are not implemented through the low
  2894. * level EC interface.
  2895. * If this fails we try creating a EVP_PKEY_EC generic param ctx,
  2896. * then we set the curve by NID before deriving the actual keygen
  2897. * ctx for that specific curve. */
  2898. kctx = EVP_PKEY_CTX_new_id(ec_curves[testnum].nid, NULL); /* keygen ctx from NID */
  2899. if (!kctx) {
  2900. EVP_PKEY_CTX *pctx = NULL;
  2901. EVP_PKEY *params = NULL;
  2902. /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
  2903. * "int_ctx_new:unsupported algorithm" error was added to the
  2904. * error queue.
  2905. * We remove it from the error queue as we are handling it. */
  2906. unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
  2907. if (error == ERR_peek_last_error() && /* oldest and latest errors match */
  2908. /* check that the error origin matches */
  2909. ERR_GET_LIB(error) == ERR_LIB_EVP &&
  2910. ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
  2911. ERR_get_error(); /* pop error from queue */
  2912. if (ERR_peek_error()) {
  2913. BIO_printf(bio_err,
  2914. "Unhandled error in the error queue during ECDH init.\n");
  2915. ERR_print_errors(bio_err);
  2916. rsa_count = 1;
  2917. break;
  2918. }
  2919. /* Create the context for parameter generation */
  2920. if (!(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
  2921. /* Initialise the parameter generation */
  2922. !EVP_PKEY_paramgen_init(pctx) ||
  2923. /* Set the curve by NID */
  2924. !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
  2925. ec_curves
  2926. [testnum].nid) ||
  2927. /* Create the parameter object params */
  2928. !EVP_PKEY_paramgen(pctx, &params)) {
  2929. ecdh_checks = 0;
  2930. BIO_printf(bio_err, "ECDH EC params init failure.\n");
  2931. ERR_print_errors(bio_err);
  2932. rsa_count = 1;
  2933. break;
  2934. }
  2935. /* Create the context for the key generation */
  2936. kctx = EVP_PKEY_CTX_new(params, NULL);
  2937. EVP_PKEY_free(params);
  2938. params = NULL;
  2939. EVP_PKEY_CTX_free(pctx);
  2940. pctx = NULL;
  2941. }
  2942. if (kctx == NULL || /* keygen ctx is not null */
  2943. EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
  2944. ecdh_checks = 0;
  2945. BIO_printf(bio_err, "ECDH keygen failure.\n");
  2946. ERR_print_errors(bio_err);
  2947. rsa_count = 1;
  2948. break;
  2949. }
  2950. if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
  2951. EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
  2952. !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
  2953. EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
  2954. EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
  2955. EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
  2956. outlen == 0 || /* ensure outlen is a valid size */
  2957. outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
  2958. ecdh_checks = 0;
  2959. BIO_printf(bio_err, "ECDH key generation failure.\n");
  2960. ERR_print_errors(bio_err);
  2961. rsa_count = 1;
  2962. break;
  2963. }
  2964. /* Here we perform a test run, comparing the output of a*B and b*A;
  2965. * we try this here and assume that further EVP_PKEY_derive calls
  2966. * never fail, so we can skip checks in the actually benchmarked
  2967. * code, for maximum performance. */
  2968. if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
  2969. !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
  2970. !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
  2971. !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
  2972. !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
  2973. !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
  2974. test_outlen != outlen /* compare output length */ ) {
  2975. ecdh_checks = 0;
  2976. BIO_printf(bio_err, "ECDH computation failure.\n");
  2977. ERR_print_errors(bio_err);
  2978. rsa_count = 1;
  2979. break;
  2980. }
  2981. /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
  2982. if (CRYPTO_memcmp(loopargs[i].secret_a,
  2983. loopargs[i].secret_b, outlen)) {
  2984. ecdh_checks = 0;
  2985. BIO_printf(bio_err, "ECDH computations don't match.\n");
  2986. ERR_print_errors(bio_err);
  2987. rsa_count = 1;
  2988. break;
  2989. }
  2990. loopargs[i].ecdh_ctx[testnum] = ctx;
  2991. loopargs[i].outlen[testnum] = outlen;
  2992. EVP_PKEY_free(key_A);
  2993. EVP_PKEY_free(key_B);
  2994. EVP_PKEY_CTX_free(kctx);
  2995. kctx = NULL;
  2996. EVP_PKEY_CTX_free(test_ctx);
  2997. test_ctx = NULL;
  2998. }
  2999. if (ecdh_checks != 0) {
  3000. pkey_print_message("", "ecdh",
  3001. ecdh_c[testnum][0],
  3002. ec_curves[testnum].bits, seconds.ecdh);
  3003. Time_F(START);
  3004. count =
  3005. run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
  3006. d = Time_F(STOP);
  3007. BIO_printf(bio_err,
  3008. mr ? "+R7:%ld:%d:%.2f\n" :
  3009. "%ld %u-bits ECDH ops in %.2fs\n", count,
  3010. ec_curves[testnum].bits, d);
  3011. ecdh_results[testnum][0] = (double)count / d;
  3012. rsa_count = count;
  3013. }
  3014. if (rsa_count <= 1) {
  3015. /* if longer than 10s, don't do any more */
  3016. stop_it(ecdh_doit, testnum);
  3017. }
  3018. }
  3019. for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
  3020. int st = 1;
  3021. EVP_PKEY *ed_pkey = NULL;
  3022. EVP_PKEY_CTX *ed_pctx = NULL;
  3023. if (!eddsa_doit[testnum])
  3024. continue; /* Ignore Curve */
  3025. for (i = 0; i < loopargs_len; i++) {
  3026. loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
  3027. if (loopargs[i].eddsa_ctx[testnum] == NULL) {
  3028. st = 0;
  3029. break;
  3030. }
  3031. if ((ed_pctx = EVP_PKEY_CTX_new_id(ed_curves[testnum].nid, NULL))
  3032. == NULL
  3033. || EVP_PKEY_keygen_init(ed_pctx) <= 0
  3034. || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
  3035. st = 0;
  3036. EVP_PKEY_CTX_free(ed_pctx);
  3037. break;
  3038. }
  3039. EVP_PKEY_CTX_free(ed_pctx);
  3040. if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
  3041. NULL, ed_pkey)) {
  3042. st = 0;
  3043. EVP_PKEY_free(ed_pkey);
  3044. break;
  3045. }
  3046. EVP_PKEY_free(ed_pkey);
  3047. }
  3048. if (st == 0) {
  3049. BIO_printf(bio_err, "EdDSA failure.\n");
  3050. ERR_print_errors(bio_err);
  3051. rsa_count = 1;
  3052. } else {
  3053. for (i = 0; i < loopargs_len; i++) {
  3054. /* Perform EdDSA signature test */
  3055. loopargs[i].sigsize = ed_curves[testnum].sigsize;
  3056. st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
  3057. loopargs[i].buf2, &loopargs[i].sigsize,
  3058. loopargs[i].buf, 20);
  3059. if (st == 0)
  3060. break;
  3061. }
  3062. if (st == 0) {
  3063. BIO_printf(bio_err,
  3064. "EdDSA sign failure. No EdDSA sign will be done.\n");
  3065. ERR_print_errors(bio_err);
  3066. rsa_count = 1;
  3067. } else {
  3068. pkey_print_message("sign", ed_curves[testnum].name,
  3069. eddsa_c[testnum][0],
  3070. ed_curves[testnum].bits, seconds.eddsa);
  3071. Time_F(START);
  3072. count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
  3073. d = Time_F(STOP);
  3074. BIO_printf(bio_err,
  3075. mr ? "+R8:%ld:%u:%s:%.2f\n" :
  3076. "%ld %u bits %s signs in %.2fs \n",
  3077. count, ed_curves[testnum].bits,
  3078. ed_curves[testnum].name, d);
  3079. eddsa_results[testnum][0] = (double)count / d;
  3080. rsa_count = count;
  3081. }
  3082. /* Perform EdDSA verification test */
  3083. for (i = 0; i < loopargs_len; i++) {
  3084. st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
  3085. loopargs[i].buf2, loopargs[i].sigsize,
  3086. loopargs[i].buf, 20);
  3087. if (st != 1)
  3088. break;
  3089. }
  3090. if (st != 1) {
  3091. BIO_printf(bio_err,
  3092. "EdDSA verify failure. No EdDSA verify will be done.\n");
  3093. ERR_print_errors(bio_err);
  3094. eddsa_doit[testnum] = 0;
  3095. } else {
  3096. pkey_print_message("verify", ed_curves[testnum].name,
  3097. eddsa_c[testnum][1],
  3098. ed_curves[testnum].bits, seconds.eddsa);
  3099. Time_F(START);
  3100. count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
  3101. d = Time_F(STOP);
  3102. BIO_printf(bio_err,
  3103. mr ? "+R9:%ld:%u:%s:%.2f\n"
  3104. : "%ld %u bits %s verify in %.2fs\n",
  3105. count, ed_curves[testnum].bits,
  3106. ed_curves[testnum].name, d);
  3107. eddsa_results[testnum][1] = (double)count / d;
  3108. }
  3109. if (rsa_count <= 1) {
  3110. /* if longer than 10s, don't do any more */
  3111. stop_it(eddsa_doit, testnum);
  3112. }
  3113. }
  3114. }
  3115. # ifndef OPENSSL_NO_SM2
  3116. for (testnum = 0; testnum < SM2_NUM; testnum++) {
  3117. int st = 1;
  3118. EVP_PKEY *sm2_pkey = NULL;
  3119. if (!sm2_doit[testnum])
  3120. continue; /* Ignore Curve */
  3121. /* Init signing and verification */
  3122. for (i = 0; i < loopargs_len; i++) {
  3123. EVP_PKEY_CTX *sm2_pctx = NULL;
  3124. EVP_PKEY_CTX *sm2_vfy_pctx = NULL;
  3125. EVP_PKEY_CTX *pctx = NULL;
  3126. st = 0;
  3127. loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new();
  3128. loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new();
  3129. if (loopargs[i].sm2_ctx[testnum] == NULL
  3130. || loopargs[i].sm2_vfy_ctx[testnum] == NULL)
  3131. break;
  3132. /* SM2 keys are generated as normal EC keys with a special curve */
  3133. st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL
  3134. || EVP_PKEY_keygen_init(pctx) <= 0
  3135. || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
  3136. sm2_curves[testnum].nid) <= 0
  3137. || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0);
  3138. EVP_PKEY_CTX_free(pctx);
  3139. if (st == 0)
  3140. break;
  3141. st = 0; /* set back to zero */
  3142. /* attach it sooner to rely on main final cleanup */
  3143. loopargs[i].sm2_pkey[testnum] = sm2_pkey;
  3144. loopargs[i].sigsize = ECDSA_size(EVP_PKEY_get0_EC_KEY(sm2_pkey));
  3145. if (!EVP_PKEY_set_alias_type(sm2_pkey, EVP_PKEY_SM2))
  3146. break;
  3147. sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
  3148. sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
  3149. if (sm2_pctx == NULL || sm2_vfy_pctx == NULL) {
  3150. EVP_PKEY_CTX_free(sm2_vfy_pctx);
  3151. break;
  3152. }
  3153. /* attach them directly to respective ctx */
  3154. EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx);
  3155. EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx);
  3156. /*
  3157. * No need to allow user to set an explicit ID here, just use
  3158. * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
  3159. */
  3160. if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1
  3161. || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1)
  3162. break;
  3163. if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL,
  3164. EVP_sm3(), NULL, sm2_pkey))
  3165. break;
  3166. if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL,
  3167. EVP_sm3(), NULL, sm2_pkey))
  3168. break;
  3169. st = 1; /* mark loop as succeeded */
  3170. }
  3171. if (st == 0) {
  3172. BIO_printf(bio_err, "SM2 init failure.\n");
  3173. ERR_print_errors(bio_err);
  3174. rsa_count = 1;
  3175. } else {
  3176. for (i = 0; i < loopargs_len; i++) {
  3177. size_t sm2_sigsize = loopargs[i].sigsize;
  3178. /* Perform SM2 signature test */
  3179. st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
  3180. loopargs[i].buf2, &sm2_sigsize,
  3181. loopargs[i].buf, 20);
  3182. if (st == 0)
  3183. break;
  3184. }
  3185. if (st == 0) {
  3186. BIO_printf(bio_err,
  3187. "SM2 sign failure. No SM2 sign will be done.\n");
  3188. ERR_print_errors(bio_err);
  3189. rsa_count = 1;
  3190. } else {
  3191. pkey_print_message("sign", sm2_curves[testnum].name,
  3192. sm2_c[testnum][0],
  3193. sm2_curves[testnum].bits, seconds.sm2);
  3194. Time_F(START);
  3195. count = run_benchmark(async_jobs, SM2_sign_loop, loopargs);
  3196. d = Time_F(STOP);
  3197. BIO_printf(bio_err,
  3198. mr ? "+R8:%ld:%u:%s:%.2f\n" :
  3199. "%ld %u bits %s signs in %.2fs \n",
  3200. count, sm2_curves[testnum].bits,
  3201. sm2_curves[testnum].name, d);
  3202. sm2_results[testnum][0] = (double)count / d;
  3203. rsa_count = count;
  3204. }
  3205. /* Perform SM2 verification test */
  3206. for (i = 0; i < loopargs_len; i++) {
  3207. st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum],
  3208. loopargs[i].buf2, loopargs[i].sigsize,
  3209. loopargs[i].buf, 20);
  3210. if (st != 1)
  3211. break;
  3212. }
  3213. if (st != 1) {
  3214. BIO_printf(bio_err,
  3215. "SM2 verify failure. No SM2 verify will be done.\n");
  3216. ERR_print_errors(bio_err);
  3217. sm2_doit[testnum] = 0;
  3218. } else {
  3219. pkey_print_message("verify", sm2_curves[testnum].name,
  3220. sm2_c[testnum][1],
  3221. sm2_curves[testnum].bits, seconds.sm2);
  3222. Time_F(START);
  3223. count = run_benchmark(async_jobs, SM2_verify_loop, loopargs);
  3224. d = Time_F(STOP);
  3225. BIO_printf(bio_err,
  3226. mr ? "+R9:%ld:%u:%s:%.2f\n"
  3227. : "%ld %u bits %s verify in %.2fs\n",
  3228. count, sm2_curves[testnum].bits,
  3229. sm2_curves[testnum].name, d);
  3230. sm2_results[testnum][1] = (double)count / d;
  3231. }
  3232. if (rsa_count <= 1) {
  3233. /* if longer than 10s, don't do any more */
  3234. for (testnum++; testnum < SM2_NUM; testnum++)
  3235. sm2_doit[testnum] = 0;
  3236. }
  3237. }
  3238. }
  3239. # endif /* OPENSSL_NO_SM2 */
  3240. #endif /* OPENSSL_NO_EC */
  3241. #ifndef NO_FORK
  3242. show_res:
  3243. #endif
  3244. if (!mr) {
  3245. printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
  3246. printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
  3247. printf("options:");
  3248. printf("%s ", BN_options());
  3249. #if !defined(OPENSSL_NO_MD2) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  3250. printf("%s ", MD2_options());
  3251. #endif
  3252. #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  3253. printf("%s ", RC4_options());
  3254. #endif
  3255. #ifndef OPENSSL_NO_DES
  3256. printf("%s ", DES_options());
  3257. #endif
  3258. #ifndef OPENSSL_NO_DEPRECATED_3_0
  3259. printf("%s ", AES_options());
  3260. #endif
  3261. #ifndef OPENSSL_NO_IDEA
  3262. printf("%s ", IDEA_options());
  3263. #endif
  3264. #if !defined(OPENSSL_NO_BF) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  3265. printf("%s ", BF_options());
  3266. #endif
  3267. printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
  3268. printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
  3269. }
  3270. if (pr_header) {
  3271. if (mr)
  3272. printf("+H");
  3273. else {
  3274. printf
  3275. ("The 'numbers' are in 1000s of bytes per second processed.\n");
  3276. printf("type ");
  3277. }
  3278. for (testnum = 0; testnum < size_num; testnum++)
  3279. printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
  3280. printf("\n");
  3281. }
  3282. for (k = 0; k < ALGOR_NUM; k++) {
  3283. if (!doit[k])
  3284. continue;
  3285. if (mr)
  3286. printf("+F:%u:%s", k, names[k]);
  3287. else
  3288. printf("%-13s", names[k]);
  3289. for (testnum = 0; testnum < size_num; testnum++) {
  3290. if (results[k][testnum] > 10000 && !mr)
  3291. printf(" %11.2fk", results[k][testnum] / 1e3);
  3292. else
  3293. printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
  3294. }
  3295. printf("\n");
  3296. }
  3297. #ifndef OPENSSL_NO_RSA
  3298. testnum = 1;
  3299. for (k = 0; k < RSA_NUM; k++) {
  3300. if (!rsa_doit[k])
  3301. continue;
  3302. if (testnum && !mr) {
  3303. printf("%18ssign verify sign/s verify/s\n", " ");
  3304. testnum = 0;
  3305. }
  3306. if (mr)
  3307. printf("+F2:%u:%u:%f:%f\n",
  3308. k, rsa_keys[k].bits, rsa_results[k][0], rsa_results[k][1]);
  3309. else
  3310. printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
  3311. rsa_keys[k].bits, 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
  3312. rsa_results[k][0], rsa_results[k][1]);
  3313. }
  3314. #endif
  3315. #ifndef OPENSSL_NO_DSA
  3316. testnum = 1;
  3317. for (k = 0; k < DSA_NUM; k++) {
  3318. if (!dsa_doit[k])
  3319. continue;
  3320. if (testnum && !mr) {
  3321. printf("%18ssign verify sign/s verify/s\n", " ");
  3322. testnum = 0;
  3323. }
  3324. if (mr)
  3325. printf("+F3:%u:%u:%f:%f\n",
  3326. k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
  3327. else
  3328. printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
  3329. dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
  3330. dsa_results[k][0], dsa_results[k][1]);
  3331. }
  3332. #endif
  3333. #ifndef OPENSSL_NO_EC
  3334. testnum = 1;
  3335. for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
  3336. if (!ecdsa_doit[k])
  3337. continue;
  3338. if (testnum && !mr) {
  3339. printf("%30ssign verify sign/s verify/s\n", " ");
  3340. testnum = 0;
  3341. }
  3342. if (mr)
  3343. printf("+F4:%u:%u:%f:%f\n",
  3344. k, ec_curves[k].bits,
  3345. ecdsa_results[k][0], ecdsa_results[k][1]);
  3346. else
  3347. printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
  3348. ec_curves[k].bits, ec_curves[k].name,
  3349. 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
  3350. ecdsa_results[k][0], ecdsa_results[k][1]);
  3351. }
  3352. testnum = 1;
  3353. for (k = 0; k < EC_NUM; k++) {
  3354. if (!ecdh_doit[k])
  3355. continue;
  3356. if (testnum && !mr) {
  3357. printf("%30sop op/s\n", " ");
  3358. testnum = 0;
  3359. }
  3360. if (mr)
  3361. printf("+F5:%u:%u:%f:%f\n",
  3362. k, ec_curves[k].bits,
  3363. ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
  3364. else
  3365. printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
  3366. ec_curves[k].bits, ec_curves[k].name,
  3367. 1.0 / ecdh_results[k][0], ecdh_results[k][0]);
  3368. }
  3369. testnum = 1;
  3370. for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
  3371. if (!eddsa_doit[k])
  3372. continue;
  3373. if (testnum && !mr) {
  3374. printf("%30ssign verify sign/s verify/s\n", " ");
  3375. testnum = 0;
  3376. }
  3377. if (mr)
  3378. printf("+F6:%u:%u:%s:%f:%f\n",
  3379. k, ed_curves[k].bits, ed_curves[k].name,
  3380. eddsa_results[k][0], eddsa_results[k][1]);
  3381. else
  3382. printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
  3383. ed_curves[k].bits, ed_curves[k].name,
  3384. 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
  3385. eddsa_results[k][0], eddsa_results[k][1]);
  3386. }
  3387. # ifndef OPENSSL_NO_SM2
  3388. testnum = 1;
  3389. for (k = 0; k < OSSL_NELEM(sm2_doit); k++) {
  3390. if (!sm2_doit[k])
  3391. continue;
  3392. if (testnum && !mr) {
  3393. printf("%30ssign verify sign/s verify/s\n", " ");
  3394. testnum = 0;
  3395. }
  3396. if (mr)
  3397. printf("+F6:%u:%u:%s:%f:%f\n",
  3398. k, sm2_curves[k].bits, sm2_curves[k].name,
  3399. sm2_results[k][0], sm2_results[k][1]);
  3400. else
  3401. printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
  3402. sm2_curves[k].bits, sm2_curves[k].name,
  3403. 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1],
  3404. sm2_results[k][0], sm2_results[k][1]);
  3405. }
  3406. # endif
  3407. #endif /* OPENSSL_NO_EC */
  3408. ret = 0;
  3409. end:
  3410. ERR_print_errors(bio_err);
  3411. for (i = 0; i < loopargs_len; i++) {
  3412. OPENSSL_free(loopargs[i].buf_malloc);
  3413. OPENSSL_free(loopargs[i].buf2_malloc);
  3414. #ifndef OPENSSL_NO_RSA
  3415. for (k = 0; k < RSA_NUM; k++)
  3416. RSA_free(loopargs[i].rsa_key[k]);
  3417. #endif
  3418. #ifndef OPENSSL_NO_DSA
  3419. for (k = 0; k < DSA_NUM; k++)
  3420. DSA_free(loopargs[i].dsa_key[k]);
  3421. #endif
  3422. #ifndef OPENSSL_NO_EC
  3423. for (k = 0; k < ECDSA_NUM; k++)
  3424. EC_KEY_free(loopargs[i].ecdsa[k]);
  3425. for (k = 0; k < EC_NUM; k++)
  3426. EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
  3427. for (k = 0; k < EdDSA_NUM; k++)
  3428. EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
  3429. # ifndef OPENSSL_NO_SM2
  3430. for (k = 0; k < SM2_NUM; k++) {
  3431. EVP_PKEY_CTX *pctx = NULL;
  3432. /* free signing ctx */
  3433. if (loopargs[i].sm2_ctx[k] != NULL
  3434. && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL)
  3435. EVP_PKEY_CTX_free(pctx);
  3436. EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]);
  3437. /* free verification ctx */
  3438. if (loopargs[i].sm2_vfy_ctx[k] != NULL
  3439. && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL)
  3440. EVP_PKEY_CTX_free(pctx);
  3441. EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]);
  3442. /* free pkey */
  3443. EVP_PKEY_free(loopargs[i].sm2_pkey[k]);
  3444. }
  3445. # endif
  3446. OPENSSL_free(loopargs[i].secret_a);
  3447. OPENSSL_free(loopargs[i].secret_b);
  3448. #endif
  3449. }
  3450. OPENSSL_free(evp_hmac_name);
  3451. #ifndef OPENSSL_NO_CMAC
  3452. OPENSSL_free(evp_cmac_name);
  3453. #endif
  3454. if (async_jobs > 0) {
  3455. for (i = 0; i < loopargs_len; i++)
  3456. ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
  3457. }
  3458. if (async_init) {
  3459. ASYNC_cleanup_thread();
  3460. }
  3461. OPENSSL_free(loopargs);
  3462. release_engine(e);
  3463. return ret;
  3464. }
  3465. static void print_message(const char *s, long num, int length, int tm)
  3466. {
  3467. #ifdef SIGALRM
  3468. BIO_printf(bio_err,
  3469. mr ? "+DT:%s:%d:%d\n"
  3470. : "Doing %s for %ds on %d size blocks: ", s, tm, length);
  3471. (void)BIO_flush(bio_err);
  3472. run = 1;
  3473. alarm(tm);
  3474. #else
  3475. BIO_printf(bio_err,
  3476. mr ? "+DN:%s:%ld:%d\n"
  3477. : "Doing %s %ld times on %d size blocks: ", s, num, length);
  3478. (void)BIO_flush(bio_err);
  3479. #endif
  3480. }
  3481. static void pkey_print_message(const char *str, const char *str2, long num,
  3482. unsigned int bits, int tm)
  3483. {
  3484. #ifdef SIGALRM
  3485. BIO_printf(bio_err,
  3486. mr ? "+DTP:%d:%s:%s:%d\n"
  3487. : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm);
  3488. (void)BIO_flush(bio_err);
  3489. run = 1;
  3490. alarm(tm);
  3491. #else
  3492. BIO_printf(bio_err,
  3493. mr ? "+DNP:%ld:%d:%s:%s\n"
  3494. : "Doing %ld %u bits %s %s's: ", num, bits, str, str2);
  3495. (void)BIO_flush(bio_err);
  3496. #endif
  3497. }
  3498. static void print_result(int alg, int run_no, int count, double time_used)
  3499. {
  3500. if (count == -1) {
  3501. BIO_printf(bio_err, "%s error!\n", names[alg]);
  3502. ERR_print_errors(bio_err);
  3503. /* exit(1); disable exit until default provider enabled */
  3504. return;
  3505. }
  3506. BIO_printf(bio_err,
  3507. mr ? "+R:%d:%s:%f\n"
  3508. : "%d %s's in %.2fs\n", count, names[alg], time_used);
  3509. results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
  3510. }
  3511. #ifndef NO_FORK
  3512. static char *sstrsep(char **string, const char *delim)
  3513. {
  3514. char isdelim[256];
  3515. char *token = *string;
  3516. if (**string == 0)
  3517. return NULL;
  3518. memset(isdelim, 0, sizeof(isdelim));
  3519. isdelim[0] = 1;
  3520. while (*delim) {
  3521. isdelim[(unsigned char)(*delim)] = 1;
  3522. delim++;
  3523. }
  3524. while (!isdelim[(unsigned char)(**string)]) {
  3525. (*string)++;
  3526. }
  3527. if (**string) {
  3528. **string = 0;
  3529. (*string)++;
  3530. }
  3531. return token;
  3532. }
  3533. static int do_multi(int multi, int size_num)
  3534. {
  3535. int n;
  3536. int fd[2];
  3537. int *fds;
  3538. static char sep[] = ":";
  3539. fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
  3540. for (n = 0; n < multi; ++n) {
  3541. if (pipe(fd) == -1) {
  3542. BIO_printf(bio_err, "pipe failure\n");
  3543. exit(1);
  3544. }
  3545. fflush(stdout);
  3546. (void)BIO_flush(bio_err);
  3547. if (fork()) {
  3548. close(fd[1]);
  3549. fds[n] = fd[0];
  3550. } else {
  3551. close(fd[0]);
  3552. close(1);
  3553. if (dup(fd[1]) == -1) {
  3554. BIO_printf(bio_err, "dup failed\n");
  3555. exit(1);
  3556. }
  3557. close(fd[1]);
  3558. mr = 1;
  3559. usertime = 0;
  3560. OPENSSL_free(fds);
  3561. return 0;
  3562. }
  3563. printf("Forked child %d\n", n);
  3564. }
  3565. /* for now, assume the pipe is long enough to take all the output */
  3566. for (n = 0; n < multi; ++n) {
  3567. FILE *f;
  3568. char buf[1024];
  3569. char *p;
  3570. f = fdopen(fds[n], "r");
  3571. while (fgets(buf, sizeof(buf), f)) {
  3572. p = strchr(buf, '\n');
  3573. if (p)
  3574. *p = '\0';
  3575. if (buf[0] != '+') {
  3576. BIO_printf(bio_err,
  3577. "Don't understand line '%s' from child %d\n", buf,
  3578. n);
  3579. continue;
  3580. }
  3581. printf("Got: %s from %d\n", buf, n);
  3582. if (strncmp(buf, "+F:", 3) == 0) {
  3583. int alg;
  3584. int j;
  3585. p = buf + 3;
  3586. alg = atoi(sstrsep(&p, sep));
  3587. sstrsep(&p, sep);
  3588. for (j = 0; j < size_num; ++j)
  3589. results[alg][j] += atof(sstrsep(&p, sep));
  3590. } else if (strncmp(buf, "+F2:", 4) == 0) {
  3591. int k;
  3592. double d;
  3593. p = buf + 4;
  3594. k = atoi(sstrsep(&p, sep));
  3595. sstrsep(&p, sep);
  3596. d = atof(sstrsep(&p, sep));
  3597. rsa_results[k][0] += d;
  3598. d = atof(sstrsep(&p, sep));
  3599. rsa_results[k][1] += d;
  3600. }
  3601. # ifndef OPENSSL_NO_DSA
  3602. else if (strncmp(buf, "+F3:", 4) == 0) {
  3603. int k;
  3604. double d;
  3605. p = buf + 4;
  3606. k = atoi(sstrsep(&p, sep));
  3607. sstrsep(&p, sep);
  3608. d = atof(sstrsep(&p, sep));
  3609. dsa_results[k][0] += d;
  3610. d = atof(sstrsep(&p, sep));
  3611. dsa_results[k][1] += d;
  3612. }
  3613. # endif
  3614. # ifndef OPENSSL_NO_EC
  3615. else if (strncmp(buf, "+F4:", 4) == 0) {
  3616. int k;
  3617. double d;
  3618. p = buf + 4;
  3619. k = atoi(sstrsep(&p, sep));
  3620. sstrsep(&p, sep);
  3621. d = atof(sstrsep(&p, sep));
  3622. ecdsa_results[k][0] += d;
  3623. d = atof(sstrsep(&p, sep));
  3624. ecdsa_results[k][1] += d;
  3625. } else if (strncmp(buf, "+F5:", 4) == 0) {
  3626. int k;
  3627. double d;
  3628. p = buf + 4;
  3629. k = atoi(sstrsep(&p, sep));
  3630. sstrsep(&p, sep);
  3631. d = atof(sstrsep(&p, sep));
  3632. ecdh_results[k][0] += d;
  3633. } else if (strncmp(buf, "+F6:", 4) == 0) {
  3634. int k;
  3635. double d;
  3636. p = buf + 4;
  3637. k = atoi(sstrsep(&p, sep));
  3638. sstrsep(&p, sep);
  3639. sstrsep(&p, sep);
  3640. d = atof(sstrsep(&p, sep));
  3641. eddsa_results[k][0] += d;
  3642. d = atof(sstrsep(&p, sep));
  3643. eddsa_results[k][1] += d;
  3644. }
  3645. # ifndef OPENSSL_NO_SM2
  3646. else if (strncmp(buf, "+F7:", 4) == 0) {
  3647. int k;
  3648. double d;
  3649. p = buf + 4;
  3650. k = atoi(sstrsep(&p, sep));
  3651. sstrsep(&p, sep);
  3652. d = atof(sstrsep(&p, sep));
  3653. sm2_results[k][0] += d;
  3654. d = atof(sstrsep(&p, sep));
  3655. sm2_results[k][1] += d;
  3656. }
  3657. # endif /* OPENSSL_NO_SM2 */
  3658. # endif
  3659. else if (strncmp(buf, "+H:", 3) == 0) {
  3660. ;
  3661. } else
  3662. BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,
  3663. n);
  3664. }
  3665. fclose(f);
  3666. }
  3667. OPENSSL_free(fds);
  3668. return 1;
  3669. }
  3670. #endif
  3671. static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
  3672. const openssl_speed_sec_t *seconds)
  3673. {
  3674. static const int mblengths_list[] =
  3675. { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
  3676. const int *mblengths = mblengths_list;
  3677. int j, count, keylen, num = OSSL_NELEM(mblengths_list);
  3678. const char *alg_name;
  3679. unsigned char *inp, *out, *key, no_key[32], no_iv[16];
  3680. EVP_CIPHER_CTX *ctx;
  3681. double d = 0.0;
  3682. if (lengths_single) {
  3683. mblengths = &lengths_single;
  3684. num = 1;
  3685. }
  3686. inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
  3687. out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
  3688. ctx = EVP_CIPHER_CTX_new();
  3689. EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
  3690. keylen = EVP_CIPHER_CTX_key_length(ctx);
  3691. key = app_malloc(keylen, "evp_cipher key");
  3692. EVP_CIPHER_CTX_rand_key(ctx, key);
  3693. EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
  3694. OPENSSL_clear_free(key, keylen);
  3695. EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
  3696. alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
  3697. for (j = 0; j < num; j++) {
  3698. print_message(alg_name, 0, mblengths[j], seconds->sym);
  3699. Time_F(START);
  3700. for (count = 0; run && count < 0x7fffffff; count++) {
  3701. unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
  3702. EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
  3703. size_t len = mblengths[j];
  3704. int packlen;
  3705. memset(aad, 0, 8); /* avoid uninitialized values */
  3706. aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
  3707. aad[9] = 3; /* version */
  3708. aad[10] = 2;
  3709. aad[11] = 0; /* length */
  3710. aad[12] = 0;
  3711. mb_param.out = NULL;
  3712. mb_param.inp = aad;
  3713. mb_param.len = len;
  3714. mb_param.interleave = 8;
  3715. packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
  3716. sizeof(mb_param), &mb_param);
  3717. if (packlen > 0) {
  3718. mb_param.out = out;
  3719. mb_param.inp = inp;
  3720. mb_param.len = len;
  3721. EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
  3722. sizeof(mb_param), &mb_param);
  3723. } else {
  3724. int pad;
  3725. RAND_bytes(out, 16);
  3726. len += 16;
  3727. aad[11] = (unsigned char)(len >> 8);
  3728. aad[12] = (unsigned char)(len);
  3729. pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
  3730. EVP_AEAD_TLS1_AAD_LEN, aad);
  3731. EVP_Cipher(ctx, out, inp, len + pad);
  3732. }
  3733. }
  3734. d = Time_F(STOP);
  3735. BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
  3736. : "%d %s's in %.2fs\n", count, "evp", d);
  3737. results[D_EVP][j] = ((double)count) / d * mblengths[j];
  3738. }
  3739. if (mr) {
  3740. fprintf(stdout, "+H");
  3741. for (j = 0; j < num; j++)
  3742. fprintf(stdout, ":%d", mblengths[j]);
  3743. fprintf(stdout, "\n");
  3744. fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
  3745. for (j = 0; j < num; j++)
  3746. fprintf(stdout, ":%.2f", results[D_EVP][j]);
  3747. fprintf(stdout, "\n");
  3748. } else {
  3749. fprintf(stdout,
  3750. "The 'numbers' are in 1000s of bytes per second processed.\n");
  3751. fprintf(stdout, "type ");
  3752. for (j = 0; j < num; j++)
  3753. fprintf(stdout, "%7d bytes", mblengths[j]);
  3754. fprintf(stdout, "\n");
  3755. fprintf(stdout, "%-24s", alg_name);
  3756. for (j = 0; j < num; j++) {
  3757. if (results[D_EVP][j] > 10000)
  3758. fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
  3759. else
  3760. fprintf(stdout, " %11.2f ", results[D_EVP][j]);
  3761. }
  3762. fprintf(stdout, "\n");
  3763. }
  3764. OPENSSL_free(inp);
  3765. OPENSSL_free(out);
  3766. EVP_CIPHER_CTX_free(ctx);
  3767. }