1 /*
2 * (C) 2009 Jack Lloyd
3 *
4 * Distributed under the terms of the Botan license
5 */
6 
7 #include <botan/benchmark.h>
8 #include <botan/init.h>
9 #include <botan/auto_rng.h>
10 #include <botan/libstate.h>
11 
12 using namespace Botan;
13 
14 #include <iostream>
15 
16 namespace {
17 
18 const std::string algos[] = {
19    "AES-128",
20    "AES-192",
21    "AES-256",
22    "Blowfish",
23    "CAST-128",
24    "CAST-256",
25    "DES",
26    "DESX",
27    "TripleDES",
28    "GOST",
29    "IDEA",
30    "KASUMI",
31    "Lion(SHA-256,Turing,8192)",
32    "Luby-Rackoff(SHA-512)",
33    "MARS",
34    "MISTY1",
35    "Noekeon",
36    "RC2",
37    "RC5(12)",
38    "RC5(16)",
39    "RC6",
40    "SAFER-SK(10)",
41    "SEED",
42    "Serpent",
43    "Skipjack",
44    "Square",
45    "TEA",
46    "Twofish",
47    "XTEA",
48    "Adler32",
49    "CRC32",
50    "GOST-34.11",
51    "HAS-160",
52    "MD2",
53    "MD4",
54    "MD5",
55    "RIPEMD-128",
56    "RIPEMD-160",
57    "SHA-160",
58    "SHA-256",
59    "SHA-384",
60    "SHA-512",
61    "Skein-512",
62    "Tiger",
63    "Whirlpool",
64    "CMAC(AES-128)",
65    "HMAC(SHA-1)",
66    "X9.19-MAC",
67    "",
68 };
69 
benchmark_algo(const std::string & algo,RandomNumberGenerator & rng)70 void benchmark_algo(const std::string& algo,
71                     RandomNumberGenerator& rng)
72    {
73    u32bit milliseconds = 1000;
74    Algorithm_Factory& af = global_state().algorithm_factory();
75 
76    std::map<std::string, double> speeds =
77       algorithm_benchmark(algo, af, rng, milliseconds, 16);
78 
79    std::cout << algo << ":";
80 
81    for(std::map<std::string, double>::const_iterator i = speeds.begin();
82        i != speeds.end(); ++i)
83       {
84       std::cout << " " << i->second << " [" << i->first << "]";
85       }
86    std::cout << "\n";
87    }
88 
89 }
90 
main(int argc,char * argv[])91 int main(int argc, char* argv[])
92    {
93    LibraryInitializer init;
94 
95    AutoSeeded_RNG rng;
96 
97    if(argc == 1) // no args, benchmark everything
98       {
99       for(u32bit i = 0; algos[i] != ""; ++i)
100          benchmark_algo(algos[i], rng);
101       }
102    else
103       {
104       for(int i = 1; argv[i]; ++i)
105          benchmark_algo(argv[i], rng);
106       }
107    }
108