8#include <botan/benchmark.h>
9#include <botan/buf_comp.h>
10#include <botan/block_cipher.h>
11#include <botan/stream_cipher.h>
12#include <botan/hash.h>
14#include <botan/time.h>
26 const byte buf[],
size_t buf_len)
29 u64bit nanoseconds_used = 0;
31 while(nanoseconds_used < nanoseconds_max)
34 buf_comp->update(buf, buf_len);
40 return std::make_pair(reps * buf_len, nanoseconds_used);
46std::pair<u64bit, u64bit>
49 byte buf[],
size_t buf_len)
51 const size_t in_blocks = buf_len / block_cipher->block_size();
54 u64bit nanoseconds_used = 0;
56 block_cipher->set_key(buf, block_cipher->maximum_keylength());
58 while(nanoseconds_used < nanoseconds_max)
61 block_cipher->encrypt_n(buf, buf, in_blocks);
67 return std::make_pair(reps * in_blocks * block_cipher->block_size(),
74std::pair<u64bit, u64bit>
77 byte buf[],
size_t buf_len)
80 u64bit nanoseconds_used = 0;
82 stream_cipher->set_key(buf, stream_cipher->maximum_keylength());
84 while(nanoseconds_used < nanoseconds_max)
87 stream_cipher->cipher1(buf, buf_len);
93 return std::make_pair(reps * buf_len, nanoseconds_used);
99std::pair<u64bit, u64bit>
102 const byte buf[],
size_t buf_len)
104 return bench_buf_comp(hash, nanoseconds_max, buf, buf_len);
110std::pair<u64bit, u64bit>
113 const byte buf[],
size_t buf_len)
115 mac->set_key(buf, mac->maximum_keylength());
116 return bench_buf_comp(mac, nanoseconds_max, buf, buf_len);
121std::map<std::string, double>
128 std::vector<std::string> providers = af.
providers_of(name);
129 std::map<std::string, double> all_results;
131 if(providers.empty())
134 const u64bit ns_per_provider =
135 (
static_cast<u64bit>(milliseconds) * 1000 * 1000) / providers.size();
137 std::vector<byte> buf(buf_size * 1024);
140 for(
size_t i = 0; i != providers.size(); ++i)
142 const std::string provider = providers[i];
144 std::pair<u64bit, u64bit> results(0, 0);
149 std::auto_ptr<BlockCipher> block_cipher(proto->clone());
150 results = bench_block_cipher(block_cipher.get(),
152 &buf[0], buf.size());
157 std::auto_ptr<StreamCipher> stream_cipher(proto->clone());
158 results = bench_stream_cipher(stream_cipher.get(),
160 &buf[0], buf.size());
165 std::auto_ptr<HashFunction> hash(proto->clone());
166 results = bench_hash(hash.get(), ns_per_provider,
167 &buf[0], buf.size());
172 std::auto_ptr<MessageAuthenticationCode> mac(proto->clone());
173 results = bench_mac(mac.get(), ns_per_provider,
174 &buf[0], buf.size());
177 if(results.first && results.second)
182 double speed = (953.67 * results.first) / results.second;
183 all_results[provider] = speed;
std::vector< std::string > providers_of(const std::string &algo_spec)
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
virtual void randomize(byte output[], size_t length)=0
u64bit get_nanoseconds_clock()
unsigned long long u64bit
std::map< std::string, double > algorithm_benchmark(const std::string &name, Algorithm_Factory &af, RandomNumberGenerator &rng, u32bit milliseconds, size_t buf_size)