aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--checks/bench.cpp9
-rw-r--r--checks/bench.h6
-rw-r--r--checks/check.cpp19
-rw-r--r--src/algo_factory/algo_factory.h4
-rw-r--r--src/benchmark/benchmark.cpp7
-rw-r--r--src/benchmark/benchmark.h28
-rw-r--r--src/filters/data_snk.h2
-rw-r--r--src/utils/dyn_load/dyn_load.cpp9
8 files changed, 67 insertions, 17 deletions
diff --git a/checks/bench.cpp b/checks/bench.cpp
index 5ee50d89d..8d35ac1c4 100644
--- a/checks/bench.cpp
+++ b/checks/bench.cpp
@@ -162,14 +162,15 @@ void report_results(const std::string& algo,
bool bench_algo(const std::string& algo,
Botan::RandomNumberGenerator& rng,
- double seconds)
+ double seconds,
+ u32bit buf_size)
{
Botan::Algorithm_Factory& af = Botan::global_state().algorithm_factory();
u32bit milliseconds = static_cast<u32bit>(seconds * 1000);
std::map<std::string, double> speeds =
- algorithm_benchmark(algo, milliseconds, rng, af);
+ algorithm_benchmark(algo, af, rng, milliseconds, buf_size);
if(speeds.empty()) // maybe a cipher mode, then?
{
@@ -243,8 +244,8 @@ bool bench_algo(const std::string& algo,
}
void benchmark(Botan::RandomNumberGenerator& rng,
- double seconds)
+ double seconds, u32bit buf_size)
{
for(u32bit i = 0; algos[i] != ""; ++i)
- bench_algo(algos[i], rng, seconds);
+ bench_algo(algos[i], rng, seconds, buf_size);
}
diff --git a/checks/bench.h b/checks/bench.h
index 835db0101..b423a2215 100644
--- a/checks/bench.h
+++ b/checks/bench.h
@@ -6,11 +6,13 @@
#include <string>
void benchmark(Botan::RandomNumberGenerator& rng,
- double seconds);
+ double seconds,
+ u32bit buf_size);
bool bench_algo(const std::string& algo_name,
Botan::RandomNumberGenerator& rng,
- double seconds);
+ double seconds,
+ u32bit buf_size);
void bench_pk(Botan::RandomNumberGenerator&,
const std::string&, double seconds);
diff --git a/checks/check.cpp b/checks/check.cpp
index 74348402a..d2a05ab35 100644
--- a/checks/check.cpp
+++ b/checks/check.cpp
@@ -103,7 +103,8 @@ int main(int argc, char* argv[])
try
{
OptionParser opts("help|test|validate|dyn-load=|"
- "benchmark|bench-type=|bench-algo=|seconds=");
+ "benchmark|bench-type=|bench-algo=|"
+ "seconds=|buf-size=");
opts.parse(argv);
test_types(); // do this always
@@ -149,6 +150,8 @@ int main(int argc, char* argv[])
{
double seconds = 5;
+ u32bit buf_size = 16;
+
if(opts.is_set("seconds"))
{
seconds = std::atof(opts.value("seconds").c_str());
@@ -159,9 +162,19 @@ int main(int argc, char* argv[])
}
}
+ if(opts.is_set("buf-size"))
+ {
+ buf_size = std::atoi(opts.value("buf-size").c_str());
+ if(buf_size == 0 || buf_size > 8192)
+ {
+ std::cout << "Invalid argument to --buf-size\n";
+ return 2;
+ }
+ }
+
if(opts.is_set("benchmark"))
{
- benchmark(rng, seconds);
+ benchmark(rng, seconds, buf_size);
}
else if(opts.is_set("bench-algo"))
{
@@ -171,7 +184,7 @@ int main(int argc, char* argv[])
for(u32bit j = 0; j != algs.size(); j++)
{
const std::string alg = algs[j];
- if(!bench_algo(alg, rng, seconds)) // maybe it's a PK algorithm
+ if(!bench_algo(alg, rng, seconds, buf_size))
bench_pk(rng, alg, seconds);
}
}
diff --git a/src/algo_factory/algo_factory.h b/src/algo_factory/algo_factory.h
index fe046eac1..33a778b01 100644
--- a/src/algo_factory/algo_factory.h
+++ b/src/algo_factory/algo_factory.h
@@ -183,6 +183,10 @@ class BOTAN_DLL Algorithm_Factory
friend class Engine_Iterator;
private:
+ Algorithm_Factory(const Algorithm_Factory&) {}
+ Algorithm_Factory& operator=(const Algorithm_Factory&)
+ { return (*this); }
+
Engine* get_engine_n(u32bit) const;
std::vector<Engine*> engines;
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp
index 887c64e70..fc4a8ba37 100644
--- a/src/benchmark/benchmark.cpp
+++ b/src/benchmark/benchmark.cpp
@@ -120,9 +120,10 @@ bench_mac(MessageAuthenticationCode* mac,
std::map<std::string, double>
algorithm_benchmark(const std::string& name,
- u32bit milliseconds,
+ Algorithm_Factory& af,
RandomNumberGenerator& rng,
- Algorithm_Factory& af)
+ u32bit milliseconds,
+ u32bit buf_size)
{
std::vector<std::string> providers = af.providers_of(name);
std::map<std::string, double> all_results;
@@ -133,7 +134,7 @@ algorithm_benchmark(const std::string& name,
const u64bit ns_per_provider =
(static_cast<u64bit>(milliseconds) * 1000 * 1000) / providers.size();
- std::vector<byte> buf(16 * 1024);
+ std::vector<byte> buf(buf_size * 1024);
rng.randomize(&buf[0], buf.size());
for(u32bit i = 0; i != providers.size(); ++i)
diff --git a/src/benchmark/benchmark.h b/src/benchmark/benchmark.h
index 4f1d91b79..304fae2fc 100644
--- a/src/benchmark/benchmark.h
+++ b/src/benchmark/benchmark.h
@@ -18,16 +18,36 @@ namespace Botan {
/**
* Algorithm benchmark
* @param name the name of the algorithm to test (cipher, hash, or MAC)
-* @param milliseconds total time for the benchmark to run
-* @param rng the rng to use to generate random inputs
* @param af the algorithm factory used to create objects
+* @param rng the rng to use to generate random inputs
+* @param milliseconds total time for the benchmark to run
+* @param buf_size size of buffer to benchmark against, in KiB
* @return results a map from provider to speed in mebibytes per second
*/
std::map<std::string, double>
BOTAN_DLL algorithm_benchmark(const std::string& name,
- u32bit milliseconds,
+ Algorithm_Factory& af,
RandomNumberGenerator& rng,
- Algorithm_Factory& af);
+ u32bit milliseconds,
+ u32bit buf_size);
+
+/**
+* Algorithm benchmark (1.8 compatability version)
+* @deprecated Use variant taking buf_size defined above
+* @param name the name of the algorithm to test (cipher, hash, or MAC)
+* @param milliseconds total time for the benchmark to run
+* @param rng the rng to use to generate random inputs
+* @param af the algorithm factory used to create objects
+* @return results a map from provider to speed in mebibytes per second
+*/
+std::map<std::string, double>
+inline algorithm_benchmark(const std::string& name,
+ u32bit milliseconds,
+ RandomNumberGenerator& rng,
+ Algorithm_Factory& af)
+ {
+ return algorithm_benchmark(name, af, rng, milliseconds, 16);
+ }
}
diff --git a/src/filters/data_snk.h b/src/filters/data_snk.h
index db0bfc858..509fdae20 100644
--- a/src/filters/data_snk.h
+++ b/src/filters/data_snk.h
@@ -33,6 +33,8 @@ class BOTAN_DLL DataSink : public Filter
class BOTAN_DLL DataSink_Stream : public DataSink
{
public:
+ std::string name() const { return identifier; }
+
void write(const byte[], u32bit);
/**
diff --git a/src/utils/dyn_load/dyn_load.cpp b/src/utils/dyn_load/dyn_load.cpp
index 621737d0c..6d359bc01 100644
--- a/src/utils/dyn_load/dyn_load.cpp
+++ b/src/utils/dyn_load/dyn_load.cpp
@@ -23,7 +23,14 @@ Dynamically_Loaded_Library::Dynamically_Loaded_Library(
lib = ::dlopen(lib_name.c_str(), RTLD_LAZY);
if(!lib)
- throw std::runtime_error("Failed to load engine " + lib_name);
+ {
+ const char* dl_err = dlerror();
+ if(!dl_err)
+ dl_err = "Unknown error";
+
+ throw std::runtime_error("Failed to load engine " + lib_name + ": " +
+ dl_err);
+ }
#endif
}