crypto_bench.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Copyright (c) 2013 Nicolas George
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /* Optional external libraries; can be enabled using:
  21. * make VERSUS=crypto+gcrypt+tomcrypt tools/crypto_bench */
  22. #define USE_crypto 0x01 /* OpenSSL's libcrypto */
  23. #define USE_gcrypt 0x02 /* GnuTLS's libgcrypt */
  24. #define USE_tomcrypt 0x04 /* LibTomCrypt */
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include "libavutil/avutil.h"
  28. #include "libavutil/avstring.h"
  29. #include "libavutil/crc.h"
  30. #include "libavutil/intreadwrite.h"
  31. #include "libavutil/timer.h"
  32. #ifndef AV_READ_TIME
  33. #define AV_READ_TIME(x) 0
  34. #endif
  35. #if HAVE_UNISTD_H
  36. #include <unistd.h> /* for getopt */
  37. #endif
  38. #if !HAVE_GETOPT
  39. #include "compat/getopt.c"
  40. #endif
  41. #define MAX_INPUT_SIZE 1048576
  42. #define MAX_OUTPUT_SIZE 128
  43. static const char *enabled_libs;
  44. static const char *enabled_algos;
  45. static unsigned specified_runs;
  46. static const uint8_t *hardcoded_key = "FFmpeg is the best program ever.";
  47. static void fatal_error(const char *tag)
  48. {
  49. av_log(NULL, AV_LOG_ERROR, "Fatal error: %s\n", tag);
  50. exit(1);
  51. }
  52. struct hash_impl {
  53. const char *lib;
  54. const char *name;
  55. void (*run)(uint8_t *output, const uint8_t *input, unsigned size);
  56. const char *output;
  57. };
  58. /***************************************************************************
  59. * lavu: libavutil
  60. ***************************************************************************/
  61. #include "libavutil/md5.h"
  62. #include "libavutil/sha.h"
  63. #include "libavutil/sha512.h"
  64. #include "libavutil/ripemd.h"
  65. #include "libavutil/aes.h"
  66. #include "libavutil/blowfish.h"
  67. #include "libavutil/camellia.h"
  68. #include "libavutil/cast5.h"
  69. #include "libavutil/des.h"
  70. #include "libavutil/twofish.h"
  71. #include "libavutil/rc4.h"
  72. #include "libavutil/xtea.h"
  73. #define IMPL_USE_lavu IMPL_USE
  74. static void run_lavu_md5(uint8_t *output,
  75. const uint8_t *input, unsigned size)
  76. {
  77. av_md5_sum(output, input, size);
  78. }
  79. #define DEFINE_LAVU_MD(suffix, type, namespace, hsize) \
  80. static void run_lavu_ ## suffix(uint8_t *output, \
  81. const uint8_t *input, unsigned size) \
  82. { \
  83. static struct type *h; \
  84. if (!h && !(h = av_ ## namespace ## _alloc())) \
  85. fatal_error("out of memory"); \
  86. av_ ## namespace ## _init(h, hsize); \
  87. av_ ## namespace ## _update(h, input, size); \
  88. av_ ## namespace ## _final(h, output); \
  89. }
  90. DEFINE_LAVU_MD(sha1, AVSHA, sha, 160);
  91. DEFINE_LAVU_MD(sha256, AVSHA, sha, 256);
  92. DEFINE_LAVU_MD(sha512, AVSHA512, sha512, 512);
  93. DEFINE_LAVU_MD(ripemd128, AVRIPEMD, ripemd, 128);
  94. DEFINE_LAVU_MD(ripemd160, AVRIPEMD, ripemd, 160);
  95. static void run_lavu_aes128(uint8_t *output,
  96. const uint8_t *input, unsigned size)
  97. {
  98. static struct AVAES *aes;
  99. if (!aes && !(aes = av_aes_alloc()))
  100. fatal_error("out of memory");
  101. av_aes_init(aes, hardcoded_key, 128, 0);
  102. av_aes_crypt(aes, output, input, size >> 4, NULL, 0);
  103. }
  104. static void run_lavu_blowfish(uint8_t *output,
  105. const uint8_t *input, unsigned size)
  106. {
  107. static struct AVBlowfish *blowfish;
  108. if (!blowfish && !(blowfish = av_blowfish_alloc()))
  109. fatal_error("out of memory");
  110. av_blowfish_init(blowfish, hardcoded_key, 16);
  111. av_blowfish_crypt(blowfish, output, input, size >> 3, NULL, 0);
  112. }
  113. static void run_lavu_camellia(uint8_t *output,
  114. const uint8_t *input, unsigned size)
  115. {
  116. static struct AVCAMELLIA *camellia;
  117. if (!camellia && !(camellia = av_camellia_alloc()))
  118. fatal_error("out of memory");
  119. av_camellia_init(camellia, hardcoded_key, 128);
  120. av_camellia_crypt(camellia, output, input, size >> 4, NULL, 0);
  121. }
  122. static void run_lavu_cast128(uint8_t *output,
  123. const uint8_t *input, unsigned size)
  124. {
  125. static struct AVCAST5 *cast;
  126. if (!cast && !(cast = av_cast5_alloc()))
  127. fatal_error("out of memory");
  128. av_cast5_init(cast, hardcoded_key, 128);
  129. av_cast5_crypt(cast, output, input, size >> 3, 0);
  130. }
  131. static void run_lavu_des(uint8_t *output,
  132. const uint8_t *input, unsigned size)
  133. {
  134. static struct AVDES *des;
  135. if (!des && !(des = av_des_alloc()))
  136. fatal_error("out of memory");
  137. av_des_init(des, hardcoded_key, 64, 0);
  138. av_des_crypt(des, output, input, size >> 3, NULL, 0);
  139. }
  140. static void run_lavu_twofish(uint8_t *output,
  141. const uint8_t *input, unsigned size)
  142. {
  143. static struct AVTWOFISH *twofish;
  144. if (!twofish && !(twofish = av_twofish_alloc()))
  145. fatal_error("out of memory");
  146. av_twofish_init(twofish, hardcoded_key, 128);
  147. av_twofish_crypt(twofish, output, input, size >> 4, NULL, 0);
  148. }
  149. static void run_lavu_rc4(uint8_t *output,
  150. const uint8_t *input, unsigned size)
  151. {
  152. static struct AVRC4 *rc4;
  153. if (!rc4 && !(rc4 = av_rc4_alloc()))
  154. fatal_error("out of memory");
  155. av_rc4_init(rc4, hardcoded_key, 128, 0);
  156. av_rc4_crypt(rc4, output, input, size, NULL, 0);
  157. }
  158. static void run_lavu_xtea(uint8_t *output,
  159. const uint8_t *input, unsigned size)
  160. {
  161. static struct AVXTEA *xtea;
  162. if (!xtea && !(xtea = av_xtea_alloc()))
  163. fatal_error("out of memory");
  164. av_xtea_init(xtea, hardcoded_key);
  165. av_xtea_crypt(xtea, output, input, size >> 3, NULL, 0);
  166. }
  167. /***************************************************************************
  168. * crypto: OpenSSL's libcrypto
  169. ***************************************************************************/
  170. #if (USE_EXT_LIBS) & USE_crypto
  171. #define OPENSSL_DISABLE_OLD_DES_SUPPORT
  172. #include <openssl/md5.h>
  173. #include <openssl/sha.h>
  174. #include <openssl/ripemd.h>
  175. #include <openssl/aes.h>
  176. #include <openssl/blowfish.h>
  177. #include <openssl/camellia.h>
  178. #include <openssl/cast.h>
  179. #include <openssl/des.h>
  180. #include <openssl/rc4.h>
  181. #define DEFINE_CRYPTO_WRAPPER(suffix, function) \
  182. static void run_crypto_ ## suffix(uint8_t *output, \
  183. const uint8_t *input, unsigned size) \
  184. { \
  185. function(input, size, output); \
  186. }
  187. DEFINE_CRYPTO_WRAPPER(md5, MD5)
  188. DEFINE_CRYPTO_WRAPPER(sha1, SHA1)
  189. DEFINE_CRYPTO_WRAPPER(sha256, SHA256)
  190. DEFINE_CRYPTO_WRAPPER(sha512, SHA512)
  191. DEFINE_CRYPTO_WRAPPER(ripemd160, RIPEMD160)
  192. static void run_crypto_aes128(uint8_t *output,
  193. const uint8_t *input, unsigned size)
  194. {
  195. AES_KEY aes;
  196. unsigned i;
  197. AES_set_encrypt_key(hardcoded_key, 128, &aes);
  198. size -= 15;
  199. for (i = 0; i < size; i += 16)
  200. AES_encrypt(input + i, output + i, &aes);
  201. }
  202. static void run_crypto_blowfish(uint8_t *output,
  203. const uint8_t *input, unsigned size)
  204. {
  205. BF_KEY blowfish;
  206. unsigned i;
  207. BF_set_key(&blowfish, 16, hardcoded_key);
  208. for (i = 0; i < size; i += 8)
  209. BF_ecb_encrypt(input + i, output + i, &blowfish, 1);
  210. }
  211. static void run_crypto_camellia(uint8_t *output,
  212. const uint8_t *input, unsigned size)
  213. {
  214. CAMELLIA_KEY camellia;
  215. unsigned i;
  216. Camellia_set_key(hardcoded_key, 128, &camellia);
  217. size -= 15;
  218. for (i = 0; i < size; i += 16)
  219. Camellia_ecb_encrypt(input + i, output + i, &camellia, 1);
  220. }
  221. static void run_crypto_cast128(uint8_t *output,
  222. const uint8_t *input, unsigned size)
  223. {
  224. CAST_KEY cast;
  225. unsigned i;
  226. CAST_set_key(&cast, 16, hardcoded_key);
  227. for (i = 0; i < size; i += 8)
  228. CAST_ecb_encrypt(input + i, output + i, &cast, 1);
  229. }
  230. static void run_crypto_des(uint8_t *output,
  231. const uint8_t *input, unsigned size)
  232. {
  233. DES_key_schedule des;
  234. unsigned i;
  235. DES_set_key(hardcoded_key, &des);
  236. for (i = 0; i < size; i += 8)
  237. DES_ecb_encrypt(input + i, output + i, &des, 1);
  238. }
  239. static void run_crypto_rc4(uint8_t *output,
  240. const uint8_t *input, unsigned size)
  241. {
  242. RC4_KEY rc4;
  243. RC4_set_key(&rc4, 16, hardcoded_key);
  244. RC4(&rc4, size, input, output);
  245. }
  246. #define IMPL_USE_crypto(...) IMPL_USE(__VA_ARGS__)
  247. #else
  248. #define IMPL_USE_crypto(...) /* ignore */
  249. #endif
  250. /***************************************************************************
  251. * gcrypt: GnuTLS's libgcrypt
  252. ***************************************************************************/
  253. #if (USE_EXT_LIBS) & USE_gcrypt
  254. #include <gcrypt.h>
  255. #define DEFINE_GCRYPT_WRAPPER(suffix, algo) \
  256. static void run_gcrypt_ ## suffix(uint8_t *output, \
  257. const uint8_t *input, unsigned size) \
  258. { \
  259. gcry_md_hash_buffer(GCRY_MD_ ## algo, output, input, size); \
  260. }
  261. DEFINE_GCRYPT_WRAPPER(md5, MD5)
  262. DEFINE_GCRYPT_WRAPPER(sha1, SHA1)
  263. DEFINE_GCRYPT_WRAPPER(sha256, SHA256)
  264. DEFINE_GCRYPT_WRAPPER(sha512, SHA512)
  265. DEFINE_GCRYPT_WRAPPER(ripemd160, RMD160)
  266. #define DEFINE_GCRYPT_CYPHER_WRAPPER(suffix, cypher, sz) \
  267. static void run_gcrypt_ ## suffix(uint8_t *output, \
  268. const uint8_t *input, unsigned size) \
  269. { \
  270. static gcry_cipher_hd_t suffix; \
  271. if (!suffix) \
  272. gcry_cipher_open(&suffix, GCRY_CIPHER_ ## cypher, GCRY_CIPHER_MODE_ECB, 0); \
  273. gcry_cipher_setkey(suffix, hardcoded_key, sz); \
  274. gcry_cipher_encrypt(suffix, output, size, input, size); \
  275. }
  276. DEFINE_GCRYPT_CYPHER_WRAPPER(aes128, AES128, 16)
  277. DEFINE_GCRYPT_CYPHER_WRAPPER(blowfish, BLOWFISH, 16)
  278. DEFINE_GCRYPT_CYPHER_WRAPPER(camellia, CAMELLIA128, 16)
  279. DEFINE_GCRYPT_CYPHER_WRAPPER(cast128, CAST5, 16)
  280. DEFINE_GCRYPT_CYPHER_WRAPPER(des, DES, 8)
  281. DEFINE_GCRYPT_CYPHER_WRAPPER(twofish, TWOFISH128, 16)
  282. #define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__)
  283. #else
  284. #define IMPL_USE_gcrypt(...) /* ignore */
  285. #endif
  286. /***************************************************************************
  287. * tomcrypt: LibTomCrypt
  288. ***************************************************************************/
  289. #if (USE_EXT_LIBS) & USE_tomcrypt
  290. #include <tomcrypt.h>
  291. #define DEFINE_TOMCRYPT_WRAPPER(suffix, namespace, algo) \
  292. static void run_tomcrypt_ ## suffix(uint8_t *output, \
  293. const uint8_t *input, unsigned size) \
  294. { \
  295. hash_state md; \
  296. namespace ## _init(&md); \
  297. namespace ## _process(&md, input, size); \
  298. namespace ## _done(&md, output); \
  299. }
  300. DEFINE_TOMCRYPT_WRAPPER(md5, md5, MD5)
  301. DEFINE_TOMCRYPT_WRAPPER(sha1, sha1, SHA1)
  302. DEFINE_TOMCRYPT_WRAPPER(sha256, sha256, SHA256)
  303. DEFINE_TOMCRYPT_WRAPPER(sha512, sha512, SHA512)
  304. DEFINE_TOMCRYPT_WRAPPER(ripemd128, rmd128, RIPEMD128)
  305. DEFINE_TOMCRYPT_WRAPPER(ripemd160, rmd160, RIPEMD160)
  306. static void run_tomcrypt_aes128(uint8_t *output,
  307. const uint8_t *input, unsigned size)
  308. {
  309. symmetric_key aes;
  310. unsigned i;
  311. aes_setup(hardcoded_key, 16, 0, &aes);
  312. size -= 15;
  313. for (i = 0; i < size; i += 16)
  314. aes_ecb_encrypt(input + i, output + i, &aes);
  315. }
  316. static void run_tomcrypt_blowfish(uint8_t *output,
  317. const uint8_t *input, unsigned size)
  318. {
  319. symmetric_key blowfish;
  320. unsigned i;
  321. blowfish_setup(hardcoded_key, 16, 0, &blowfish);
  322. for (i = 0; i < size; i += 8)
  323. blowfish_ecb_encrypt(input + i, output + i, &blowfish);
  324. }
  325. static void run_tomcrypt_camellia(uint8_t *output,
  326. const uint8_t *input, unsigned size)
  327. {
  328. symmetric_key camellia;
  329. unsigned i;
  330. camellia_setup(hardcoded_key, 16, 0, &camellia);
  331. size -= 15;
  332. for (i = 0; i < size; i += 16)
  333. camellia_ecb_encrypt(input + i, output + i, &camellia);
  334. }
  335. static void run_tomcrypt_cast128(uint8_t *output,
  336. const uint8_t *input, unsigned size)
  337. {
  338. symmetric_key cast;
  339. unsigned i;
  340. cast5_setup(hardcoded_key, 16, 0, &cast);
  341. for (i = 0; i < size; i += 8)
  342. cast5_ecb_encrypt(input + i, output + i, &cast);
  343. }
  344. static void run_tomcrypt_des(uint8_t *output,
  345. const uint8_t *input, unsigned size)
  346. {
  347. symmetric_key des;
  348. unsigned i;
  349. des_setup(hardcoded_key, 8, 0, &des);
  350. for (i = 0; i < size; i += 8)
  351. des_ecb_encrypt(input + i, output + i, &des);
  352. }
  353. static void run_tomcrypt_twofish(uint8_t *output,
  354. const uint8_t *input, unsigned size)
  355. {
  356. symmetric_key twofish;
  357. unsigned i;
  358. twofish_setup(hardcoded_key, 16, 0, &twofish);
  359. size -= 15;
  360. for (i = 0; i < size; i += 16)
  361. twofish_ecb_encrypt(input + i, output + i, &twofish);
  362. }
  363. static void run_tomcrypt_xtea(uint8_t *output,
  364. const uint8_t *input, unsigned size)
  365. {
  366. symmetric_key xtea;
  367. unsigned i;
  368. xtea_setup(hardcoded_key, 16, 0, &xtea);
  369. for (i = 0; i < size; i += 8)
  370. xtea_ecb_encrypt(input + i, output + i, &xtea);
  371. }
  372. #define IMPL_USE_tomcrypt(...) IMPL_USE(__VA_ARGS__)
  373. #else
  374. #define IMPL_USE_tomcrypt(...) /* ignore */
  375. #endif
  376. /***************************************************************************
  377. * Driver code
  378. ***************************************************************************/
  379. static unsigned crc32(const uint8_t *data, unsigned size)
  380. {
  381. return av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, data, size);
  382. }
  383. static void run_implementation(const uint8_t *input, uint8_t *output,
  384. struct hash_impl *impl, unsigned size)
  385. {
  386. uint64_t t0, t1;
  387. unsigned nruns = specified_runs ? specified_runs : (1 << 30) / size;
  388. unsigned outlen = 0, outcrc = 0;
  389. unsigned i, j, val;
  390. double mtime, ttime = 0, ttime2 = 0, stime;
  391. uint8_t outref[MAX_OUTPUT_SIZE];
  392. if (enabled_libs && !av_stristr(enabled_libs, impl->lib) ||
  393. enabled_algos && !av_stristr(enabled_algos, impl->name))
  394. return;
  395. if (!sscanf(impl->output, "crc:%x", &outcrc)) {
  396. outlen = strlen(impl->output) / 2;
  397. for (i = 0; i < outlen; i++) {
  398. sscanf(impl->output + i * 2, "%02x", &val);
  399. outref[i] = val;
  400. }
  401. }
  402. for (i = 0; i < 8; i++) /* heat caches */
  403. impl->run(output, input, size);
  404. for (i = 0; i < nruns; i++) {
  405. memset(output, 0, size); /* avoid leftovers from previous runs */
  406. t0 = AV_READ_TIME();
  407. impl->run(output, input, size);
  408. t1 = AV_READ_TIME();
  409. if (outlen ? memcmp(output, outref, outlen) :
  410. crc32(output, size) != outcrc) {
  411. fprintf(stderr, "Expected: ");
  412. if (outlen)
  413. for (j = 0; j < outlen; j++)
  414. fprintf(stderr, "%02x", output[j]);
  415. else
  416. fprintf(stderr, "%08x", crc32(output, size));
  417. fprintf(stderr, "\n");
  418. fatal_error("output mismatch");
  419. }
  420. mtime = (double)(t1 - t0) / size;
  421. ttime += mtime;
  422. ttime2 += mtime * mtime;
  423. }
  424. ttime /= nruns;
  425. ttime2 /= nruns;
  426. stime = sqrt(ttime2 - ttime * ttime);
  427. printf("%-10s %-12s size: %7d runs: %6d time: %8.3f +- %.3f\n",
  428. impl->lib, impl->name, size, nruns, ttime, stime);
  429. fflush(stdout);
  430. }
  431. #define IMPL_USE(lib, name, symbol, output) \
  432. { #lib, name, run_ ## lib ## _ ## symbol, output },
  433. #define IMPL(lib, ...) IMPL_USE_ ## lib(lib, __VA_ARGS__)
  434. #define IMPL_ALL(...) \
  435. IMPL(lavu, __VA_ARGS__) \
  436. IMPL(crypto, __VA_ARGS__) \
  437. IMPL(gcrypt, __VA_ARGS__) \
  438. IMPL(tomcrypt, __VA_ARGS__)
  439. struct hash_impl implementations[] = {
  440. IMPL_ALL("MD5", md5, "aa26ff5b895356bcffd9292ba9f89e66")
  441. IMPL_ALL("SHA-1", sha1, "1fd8bd1fa02f5b0fe916b0d71750726b096c5744")
  442. IMPL_ALL("SHA-256", sha256, "14028ac673b3087e51a1d407fbf0df4deeec8f217119e13b07bf2138f93db8c5")
  443. IMPL_ALL("SHA-512", sha512, "3afdd44a80d99af15c87bd724cb717243193767835ce866dd5d58c02d674bb57"
  444. "7c25b9e118c200a189fcd5a01ef106a4e200061f3e97dbf50ba065745fd46bef")
  445. IMPL(lavu, "RIPEMD-128", ripemd128, "9ab8bfba2ddccc5d99c9d4cdfb844a5f")
  446. IMPL(tomcrypt, "RIPEMD-128", ripemd128, "9ab8bfba2ddccc5d99c9d4cdfb844a5f")
  447. IMPL_ALL("RIPEMD-160", ripemd160, "62a5321e4fc8784903bb43ab7752c75f8b25af00")
  448. IMPL_ALL("AES-128", aes128, "crc:ff6bc888")
  449. IMPL_ALL("CAMELLIA", camellia, "crc:7abb59a7")
  450. IMPL_ALL("CAST-128", cast128, "crc:456aa584")
  451. IMPL_ALL("BLOWFISH", blowfish, "crc:33e8aa74")
  452. IMPL_ALL("DES", des, "crc:31291e0b")
  453. IMPL(lavu, "TWOFISH", twofish, "crc:9edbd5c1")
  454. IMPL(gcrypt, "TWOFISH", twofish, "crc:9edbd5c1")
  455. IMPL(tomcrypt, "TWOFISH", twofish, "crc:9edbd5c1")
  456. IMPL(lavu, "RC4", rc4, "crc:538d37b2")
  457. IMPL(crypto, "RC4", rc4, "crc:538d37b2")
  458. IMPL(lavu, "XTEA", xtea, "crc:931fc270")
  459. IMPL(tomcrypt, "XTEA", xtea, "crc:931fc270")
  460. };
  461. int main(int argc, char **argv)
  462. {
  463. uint8_t *input = av_malloc(MAX_INPUT_SIZE * 2);
  464. uint8_t *output = input + MAX_INPUT_SIZE;
  465. unsigned i, impl, size;
  466. int opt;
  467. while ((opt = getopt(argc, argv, "hl:a:r:")) != -1) {
  468. switch (opt) {
  469. case 'l':
  470. enabled_libs = optarg;
  471. break;
  472. case 'a':
  473. enabled_algos = optarg;
  474. break;
  475. case 'r':
  476. specified_runs = strtol(optarg, NULL, 0);
  477. break;
  478. case 'h':
  479. default:
  480. fprintf(stderr, "Usage: %s [-l libs] [-a algos] [-r runs]\n",
  481. argv[0]);
  482. if ((USE_EXT_LIBS)) {
  483. char buf[1024];
  484. snprintf(buf, sizeof(buf), "%s%s%s",
  485. ((USE_EXT_LIBS) & USE_crypto) ? "+crypto" : "",
  486. ((USE_EXT_LIBS) & USE_gcrypt) ? "+gcrypt" : "",
  487. ((USE_EXT_LIBS) & USE_tomcrypt) ? "+tomcrypt" : "");
  488. fprintf(stderr, "Built with the following external libraries:\n"
  489. "make VERSUS=%s\n", buf + 1);
  490. } else {
  491. fprintf(stderr, "Built without external libraries; use\n"
  492. "make VERSUS=crypto+gcrypt+tomcrypt tools/crypto_bench\n"
  493. "to enable them.\n");
  494. }
  495. exit(opt != 'h');
  496. }
  497. }
  498. if (!input)
  499. fatal_error("out of memory");
  500. for (i = 0; i < MAX_INPUT_SIZE; i += 4)
  501. AV_WB32(input + i, i);
  502. size = MAX_INPUT_SIZE;
  503. for (impl = 0; impl < FF_ARRAY_ELEMS(implementations); impl++)
  504. run_implementation(input, output, &implementations[impl], size);
  505. av_free(input);
  506. return 0;
  507. }