crypto_bench.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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/twofish.h"
  70. #include "libavutil/rc4.h"
  71. #include "libavutil/xtea.h"
  72. #define IMPL_USE_lavu IMPL_USE
  73. static void run_lavu_md5(uint8_t *output,
  74. const uint8_t *input, unsigned size)
  75. {
  76. av_md5_sum(output, input, size);
  77. }
  78. #define DEFINE_LAVU_MD(suffix, type, namespace, hsize) \
  79. static void run_lavu_ ## suffix(uint8_t *output, \
  80. const uint8_t *input, unsigned size) \
  81. { \
  82. static struct type *h; \
  83. if (!h && !(h = av_ ## namespace ## _alloc())) \
  84. fatal_error("out of memory"); \
  85. av_ ## namespace ## _init(h, hsize); \
  86. av_ ## namespace ## _update(h, input, size); \
  87. av_ ## namespace ## _final(h, output); \
  88. }
  89. DEFINE_LAVU_MD(sha1, AVSHA, sha, 160);
  90. DEFINE_LAVU_MD(sha256, AVSHA, sha, 256);
  91. DEFINE_LAVU_MD(sha512, AVSHA512, sha512, 512);
  92. DEFINE_LAVU_MD(ripemd128, AVRIPEMD, ripemd, 128);
  93. DEFINE_LAVU_MD(ripemd160, AVRIPEMD, ripemd, 160);
  94. static void run_lavu_aes128(uint8_t *output,
  95. const uint8_t *input, unsigned size)
  96. {
  97. static struct AVAES *aes;
  98. if (!aes && !(aes = av_aes_alloc()))
  99. fatal_error("out of memory");
  100. av_aes_init(aes, hardcoded_key, 128, 0);
  101. av_aes_crypt(aes, output, input, size >> 4, NULL, 0);
  102. }
  103. static void run_lavu_blowfish(uint8_t *output,
  104. const uint8_t *input, unsigned size)
  105. {
  106. static struct AVBlowfish *blowfish;
  107. if (!blowfish && !(blowfish = av_blowfish_alloc()))
  108. fatal_error("out of memory");
  109. av_blowfish_init(blowfish, hardcoded_key, 16);
  110. av_blowfish_crypt(blowfish, output, input, size >> 3, NULL, 0);
  111. }
  112. static void run_lavu_camellia(uint8_t *output,
  113. const uint8_t *input, unsigned size)
  114. {
  115. static struct AVCAMELLIA *camellia;
  116. if (!camellia && !(camellia = av_camellia_alloc()))
  117. fatal_error("out of memory");
  118. av_camellia_init(camellia, hardcoded_key, 128);
  119. av_camellia_crypt(camellia, output, input, size >> 4, NULL, 0);
  120. }
  121. static void run_lavu_cast128(uint8_t *output,
  122. const uint8_t *input, unsigned size)
  123. {
  124. static struct AVCAST5 *cast;
  125. if (!cast && !(cast = av_cast5_alloc()))
  126. fatal_error("out of memory");
  127. av_cast5_init(cast, hardcoded_key, 128);
  128. av_cast5_crypt(cast, output, input, size >> 3, 0);
  129. }
  130. static void run_lavu_twofish(uint8_t *output,
  131. const uint8_t *input, unsigned size)
  132. {
  133. static struct AVTWOFISH *twofish;
  134. if (!twofish && !(twofish = av_twofish_alloc()))
  135. fatal_error("out of memory");
  136. av_twofish_init(twofish, hardcoded_key, 128);
  137. av_twofish_crypt(twofish, output, input, size >> 4, NULL, 0);
  138. }
  139. static void run_lavu_rc4(uint8_t *output,
  140. const uint8_t *input, unsigned size)
  141. {
  142. static struct AVRC4 *rc4;
  143. if (!rc4 && !(rc4 = av_rc4_alloc()))
  144. fatal_error("out of memory");
  145. av_rc4_init(rc4, hardcoded_key, 128, 0);
  146. av_rc4_crypt(rc4, output, input, size, NULL, 0);
  147. }
  148. static void run_lavu_xtea(uint8_t *output,
  149. const uint8_t *input, unsigned size)
  150. {
  151. static struct AVXTEA *xtea;
  152. if (!xtea && !(xtea = av_xtea_alloc()))
  153. fatal_error("out of memory");
  154. av_xtea_init(xtea, hardcoded_key);
  155. av_xtea_crypt(xtea, output, input, size >> 3, NULL, 0);
  156. }
  157. /***************************************************************************
  158. * crypto: OpenSSL's libcrypto
  159. ***************************************************************************/
  160. #if (USE_EXT_LIBS) & USE_crypto
  161. #include <openssl/md5.h>
  162. #include <openssl/sha.h>
  163. #include <openssl/ripemd.h>
  164. #include <openssl/aes.h>
  165. #include <openssl/blowfish.h>
  166. #include <openssl/camellia.h>
  167. #include <openssl/cast.h>
  168. #include <openssl/rc4.h>
  169. #define DEFINE_CRYPTO_WRAPPER(suffix, function) \
  170. static void run_crypto_ ## suffix(uint8_t *output, \
  171. const uint8_t *input, unsigned size) \
  172. { \
  173. function(input, size, output); \
  174. }
  175. DEFINE_CRYPTO_WRAPPER(md5, MD5)
  176. DEFINE_CRYPTO_WRAPPER(sha1, SHA1)
  177. DEFINE_CRYPTO_WRAPPER(sha256, SHA256)
  178. DEFINE_CRYPTO_WRAPPER(sha512, SHA512)
  179. DEFINE_CRYPTO_WRAPPER(ripemd160, RIPEMD160)
  180. static void run_crypto_aes128(uint8_t *output,
  181. const uint8_t *input, unsigned size)
  182. {
  183. AES_KEY aes;
  184. unsigned i;
  185. AES_set_encrypt_key(hardcoded_key, 128, &aes);
  186. size -= 15;
  187. for (i = 0; i < size; i += 16)
  188. AES_encrypt(input + i, output + i, &aes);
  189. }
  190. static void run_crypto_blowfish(uint8_t *output,
  191. const uint8_t *input, unsigned size)
  192. {
  193. BF_KEY blowfish;
  194. unsigned i;
  195. BF_set_key(&blowfish, 16, hardcoded_key);
  196. for (i = 0; i < size; i += 8)
  197. BF_ecb_encrypt(input + i, output + i, &blowfish, 1);
  198. }
  199. static void run_crypto_camellia(uint8_t *output,
  200. const uint8_t *input, unsigned size)
  201. {
  202. CAMELLIA_KEY camellia;
  203. unsigned i;
  204. Camellia_set_key(hardcoded_key, 128, &camellia);
  205. size -= 15;
  206. for (i = 0; i < size; i += 16)
  207. Camellia_ecb_encrypt(input + i, output + i, &camellia, 1);
  208. }
  209. static void run_crypto_cast128(uint8_t *output,
  210. const uint8_t *input, unsigned size)
  211. {
  212. CAST_KEY cast;
  213. unsigned i;
  214. CAST_set_key(&cast, 16, hardcoded_key);
  215. for (i = 0; i < size; i += 8)
  216. CAST_ecb_encrypt(input + i, output + i, &cast, 1);
  217. }
  218. static void run_crypto_rc4(uint8_t *output,
  219. const uint8_t *input, unsigned size)
  220. {
  221. RC4_KEY rc4;
  222. RC4_set_key(&rc4, 16, hardcoded_key);
  223. RC4(&rc4, size, input, output);
  224. }
  225. #define IMPL_USE_crypto(...) IMPL_USE(__VA_ARGS__)
  226. #else
  227. #define IMPL_USE_crypto(...) /* ignore */
  228. #endif
  229. /***************************************************************************
  230. * gcrypt: GnuTLS's libgcrypt
  231. ***************************************************************************/
  232. #if (USE_EXT_LIBS) & USE_gcrypt
  233. #include <gcrypt.h>
  234. #define DEFINE_GCRYPT_WRAPPER(suffix, algo) \
  235. static void run_gcrypt_ ## suffix(uint8_t *output, \
  236. const uint8_t *input, unsigned size) \
  237. { \
  238. gcry_md_hash_buffer(GCRY_MD_ ## algo, output, input, size); \
  239. }
  240. DEFINE_GCRYPT_WRAPPER(md5, MD5)
  241. DEFINE_GCRYPT_WRAPPER(sha1, SHA1)
  242. DEFINE_GCRYPT_WRAPPER(sha256, SHA256)
  243. DEFINE_GCRYPT_WRAPPER(sha512, SHA512)
  244. DEFINE_GCRYPT_WRAPPER(ripemd160, RMD160)
  245. static void run_gcrypt_aes128(uint8_t *output,
  246. const uint8_t *input, unsigned size)
  247. {
  248. static gcry_cipher_hd_t aes;
  249. if (!aes)
  250. gcry_cipher_open(&aes, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, 0);
  251. gcry_cipher_setkey(aes, hardcoded_key, 16);
  252. gcry_cipher_encrypt(aes, output, size, input, size);
  253. }
  254. static void run_gcrypt_blowfish(uint8_t *output,
  255. const uint8_t *input, unsigned size)
  256. {
  257. static gcry_cipher_hd_t blowfish;
  258. if (!blowfish)
  259. gcry_cipher_open(&blowfish, GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_ECB, 0);
  260. gcry_cipher_setkey(blowfish, hardcoded_key, 16);
  261. gcry_cipher_encrypt(blowfish, output, size, input, size);
  262. }
  263. static void run_gcrypt_camellia(uint8_t *output,
  264. const uint8_t *input, unsigned size)
  265. {
  266. static gcry_cipher_hd_t camellia;
  267. if (!camellia)
  268. gcry_cipher_open(&camellia, GCRY_CIPHER_CAMELLIA128, GCRY_CIPHER_MODE_ECB, 0);
  269. gcry_cipher_setkey(camellia, hardcoded_key, 16);
  270. gcry_cipher_encrypt(camellia, output, size, input, size);
  271. }
  272. static void run_gcrypt_cast128(uint8_t *output,
  273. const uint8_t *input, unsigned size)
  274. {
  275. static gcry_cipher_hd_t cast;
  276. if (!cast)
  277. gcry_cipher_open(&cast, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_ECB, 0);
  278. gcry_cipher_setkey(cast, hardcoded_key, 16);
  279. gcry_cipher_encrypt(cast, output, size, input, size);
  280. }
  281. static void run_gcrypt_twofish(uint8_t *output,
  282. const uint8_t *input, unsigned size)
  283. {
  284. static gcry_cipher_hd_t twofish;
  285. if (!twofish)
  286. gcry_cipher_open(&twofish, GCRY_CIPHER_TWOFISH128, GCRY_CIPHER_MODE_ECB, 0);
  287. gcry_cipher_setkey(twofish, hardcoded_key, 16);
  288. gcry_cipher_encrypt(twofish, output, size, input, size);
  289. }
  290. #define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__)
  291. #else
  292. #define IMPL_USE_gcrypt(...) /* ignore */
  293. #endif
  294. /***************************************************************************
  295. * tomcrypt: LibTomCrypt
  296. ***************************************************************************/
  297. #if (USE_EXT_LIBS) & USE_tomcrypt
  298. #include <tomcrypt.h>
  299. #define DEFINE_TOMCRYPT_WRAPPER(suffix, namespace, algo) \
  300. static void run_tomcrypt_ ## suffix(uint8_t *output, \
  301. const uint8_t *input, unsigned size) \
  302. { \
  303. hash_state md; \
  304. namespace ## _init(&md); \
  305. namespace ## _process(&md, input, size); \
  306. namespace ## _done(&md, output); \
  307. }
  308. DEFINE_TOMCRYPT_WRAPPER(md5, md5, MD5)
  309. DEFINE_TOMCRYPT_WRAPPER(sha1, sha1, SHA1)
  310. DEFINE_TOMCRYPT_WRAPPER(sha256, sha256, SHA256)
  311. DEFINE_TOMCRYPT_WRAPPER(sha512, sha512, SHA512)
  312. DEFINE_TOMCRYPT_WRAPPER(ripemd128, rmd128, RIPEMD128)
  313. DEFINE_TOMCRYPT_WRAPPER(ripemd160, rmd160, RIPEMD160)
  314. static void run_tomcrypt_aes128(uint8_t *output,
  315. const uint8_t *input, unsigned size)
  316. {
  317. symmetric_key aes;
  318. unsigned i;
  319. aes_setup(hardcoded_key, 16, 0, &aes);
  320. size -= 15;
  321. for (i = 0; i < size; i += 16)
  322. aes_ecb_encrypt(input + i, output + i, &aes);
  323. }
  324. static void run_tomcrypt_blowfish(uint8_t *output,
  325. const uint8_t *input, unsigned size)
  326. {
  327. symmetric_key blowfish;
  328. unsigned i;
  329. blowfish_setup(hardcoded_key, 16, 0, &blowfish);
  330. for (i = 0; i < size; i += 8)
  331. blowfish_ecb_encrypt(input + i, output + i, &blowfish);
  332. }
  333. static void run_tomcrypt_camellia(uint8_t *output,
  334. const uint8_t *input, unsigned size)
  335. {
  336. symmetric_key camellia;
  337. unsigned i;
  338. camellia_setup(hardcoded_key, 16, 0, &camellia);
  339. size -= 15;
  340. for (i = 0; i < size; i += 16)
  341. camellia_ecb_encrypt(input + i, output + i, &camellia);
  342. }
  343. static void run_tomcrypt_cast128(uint8_t *output,
  344. const uint8_t *input, unsigned size)
  345. {
  346. symmetric_key cast;
  347. unsigned i;
  348. cast5_setup(hardcoded_key, 16, 0, &cast);
  349. for (i = 0; i < size; i += 8)
  350. cast5_ecb_encrypt(input + i, output + i, &cast);
  351. }
  352. static void run_tomcrypt_twofish(uint8_t *output,
  353. const uint8_t *input, unsigned size)
  354. {
  355. symmetric_key twofish;
  356. unsigned i;
  357. twofish_setup(hardcoded_key, 16, 0, &twofish);
  358. size -= 15;
  359. for (i = 0; i < size; i += 16)
  360. twofish_ecb_encrypt(input + i, output + i, &twofish);
  361. }
  362. static void run_tomcrypt_xtea(uint8_t *output,
  363. const uint8_t *input, unsigned size)
  364. {
  365. symmetric_key xtea;
  366. unsigned i;
  367. xtea_setup(hardcoded_key, 16, 0, &xtea);
  368. for (i = 0; i < size; i += 8)
  369. xtea_ecb_encrypt(input + i, output + i, &xtea);
  370. }
  371. #define IMPL_USE_tomcrypt(...) IMPL_USE(__VA_ARGS__)
  372. #else
  373. #define IMPL_USE_tomcrypt(...) /* ignore */
  374. #endif
  375. /***************************************************************************
  376. * Driver code
  377. ***************************************************************************/
  378. static unsigned crc32(const uint8_t *data, unsigned size)
  379. {
  380. return av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, data, size);
  381. }
  382. static void run_implementation(const uint8_t *input, uint8_t *output,
  383. struct hash_impl *impl, unsigned size)
  384. {
  385. uint64_t t0, t1;
  386. unsigned nruns = specified_runs ? specified_runs : (1 << 30) / size;
  387. unsigned outlen = 0, outcrc = 0;
  388. unsigned i, j, val;
  389. double mtime, ttime = 0, ttime2 = 0, stime;
  390. uint8_t outref[MAX_OUTPUT_SIZE];
  391. if (enabled_libs && !av_stristr(enabled_libs, impl->lib) ||
  392. enabled_algos && !av_stristr(enabled_algos, impl->name))
  393. return;
  394. if (!sscanf(impl->output, "crc:%x", &outcrc)) {
  395. outlen = strlen(impl->output) / 2;
  396. for (i = 0; i < outlen; i++) {
  397. sscanf(impl->output + i * 2, "%02x", &val);
  398. outref[i] = val;
  399. }
  400. }
  401. for (i = 0; i < 8; i++) /* heat caches */
  402. impl->run(output, input, size);
  403. for (i = 0; i < nruns; i++) {
  404. memset(output, 0, size); /* avoid leftovers from previous runs */
  405. t0 = AV_READ_TIME();
  406. impl->run(output, input, size);
  407. t1 = AV_READ_TIME();
  408. if (outlen ? memcmp(output, outref, outlen) :
  409. crc32(output, size) != outcrc) {
  410. fprintf(stderr, "Expected: ");
  411. if (outlen)
  412. for (j = 0; j < outlen; j++)
  413. fprintf(stderr, "%02x", output[j]);
  414. else
  415. fprintf(stderr, "%08x", crc32(output, size));
  416. fprintf(stderr, "\n");
  417. fatal_error("output mismatch");
  418. }
  419. mtime = (double)(t1 - t0) / size;
  420. ttime += mtime;
  421. ttime2 += mtime * mtime;
  422. }
  423. ttime /= nruns;
  424. ttime2 /= nruns;
  425. stime = sqrt(ttime2 - ttime * ttime);
  426. printf("%-10s %-12s size: %7d runs: %6d time: %8.3f +- %.3f\n",
  427. impl->lib, impl->name, size, nruns, ttime, stime);
  428. fflush(stdout);
  429. }
  430. #define IMPL_USE(lib, name, symbol, output) \
  431. { #lib, name, run_ ## lib ## _ ## symbol, output },
  432. #define IMPL(lib, ...) IMPL_USE_ ## lib(lib, __VA_ARGS__)
  433. #define IMPL_ALL(...) \
  434. IMPL(lavu, __VA_ARGS__) \
  435. IMPL(crypto, __VA_ARGS__) \
  436. IMPL(gcrypt, __VA_ARGS__) \
  437. IMPL(tomcrypt, __VA_ARGS__)
  438. struct hash_impl implementations[] = {
  439. IMPL_ALL("MD5", md5, "aa26ff5b895356bcffd9292ba9f89e66")
  440. IMPL_ALL("SHA-1", sha1, "1fd8bd1fa02f5b0fe916b0d71750726b096c5744")
  441. IMPL_ALL("SHA-256", sha256, "14028ac673b3087e51a1d407fbf0df4deeec8f217119e13b07bf2138f93db8c5")
  442. IMPL_ALL("SHA-512", sha512, "3afdd44a80d99af15c87bd724cb717243193767835ce866dd5d58c02d674bb57"
  443. "7c25b9e118c200a189fcd5a01ef106a4e200061f3e97dbf50ba065745fd46bef")
  444. IMPL(lavu, "RIPEMD-128", ripemd128, "9ab8bfba2ddccc5d99c9d4cdfb844a5f")
  445. IMPL(tomcrypt, "RIPEMD-128", ripemd128, "9ab8bfba2ddccc5d99c9d4cdfb844a5f")
  446. IMPL_ALL("RIPEMD-160", ripemd160, "62a5321e4fc8784903bb43ab7752c75f8b25af00")
  447. IMPL_ALL("AES-128", aes128, "crc:ff6bc888")
  448. IMPL_ALL("CAMELLIA", camellia, "crc:7abb59a7")
  449. IMPL_ALL("CAST-128", cast128, "crc:456aa584")
  450. IMPL_ALL("BLOWFISH", blowfish, "crc:33e8aa74")
  451. IMPL(lavu, "TWOFISH", twofish, "crc:9edbd5c1")
  452. IMPL(gcrypt, "TWOFISH", twofish, "crc:9edbd5c1")
  453. IMPL(tomcrypt, "TWOFISH", twofish, "crc:9edbd5c1")
  454. IMPL(lavu, "RC4", rc4, "crc:538d37b2")
  455. IMPL(crypto, "RC4", rc4, "crc:538d37b2")
  456. IMPL(lavu, "XTEA", xtea, "crc:931fc270")
  457. IMPL(tomcrypt, "XTEA", xtea, "crc:931fc270")
  458. };
  459. int main(int argc, char **argv)
  460. {
  461. uint8_t *input = av_malloc(MAX_INPUT_SIZE * 2);
  462. uint8_t *output = input + MAX_INPUT_SIZE;
  463. unsigned i, impl, size;
  464. int opt;
  465. while ((opt = getopt(argc, argv, "hl:a:r:")) != -1) {
  466. switch (opt) {
  467. case 'l':
  468. enabled_libs = optarg;
  469. break;
  470. case 'a':
  471. enabled_algos = optarg;
  472. break;
  473. case 'r':
  474. specified_runs = strtol(optarg, NULL, 0);
  475. break;
  476. case 'h':
  477. default:
  478. fprintf(stderr, "Usage: %s [-l libs] [-a algos] [-r runs]\n",
  479. argv[0]);
  480. if ((USE_EXT_LIBS)) {
  481. char buf[1024];
  482. snprintf(buf, sizeof(buf), "%s%s%s",
  483. ((USE_EXT_LIBS) & USE_crypto) ? "+crypto" : "",
  484. ((USE_EXT_LIBS) & USE_gcrypt) ? "+gcrypt" : "",
  485. ((USE_EXT_LIBS) & USE_tomcrypt) ? "+tomcrypt" : "");
  486. fprintf(stderr, "Built with the following external libraries:\n"
  487. "make VERSUS=%s\n", buf + 1);
  488. } else {
  489. fprintf(stderr, "Built without external libraries; use\n"
  490. "make VERSUS=crypto+gcrypt+tomcrypt tools/crypto_bench\n"
  491. "to enable them.\n");
  492. }
  493. exit(opt != 'h');
  494. }
  495. }
  496. if (!input)
  497. fatal_error("out of memory");
  498. for (i = 0; i < MAX_INPUT_SIZE; i += 4)
  499. AV_WB32(input + i, i);
  500. size = MAX_INPUT_SIZE;
  501. for (impl = 0; impl < FF_ARRAY_ELEMS(implementations); impl++)
  502. run_implementation(input, output, &implementations[impl], size);
  503. av_free(input);
  504. return 0;
  505. }