aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-01 01:13:21 +0000
committerlloyd <[email protected]>2014-01-01 01:13:21 +0000
commitf4ecb88106f116f538deeecb62c8d451fddd831b (patch)
tree61b98115ddc0982e151aa70c2d403587e9949b1f /checks
parent588bf2b1bd33017542b3711b8a1a3c8846ee7c35 (diff)
Remove filter based benchmark code
Diffstat (limited to 'checks')
-rw-r--r--checks/bench.cpp134
-rw-r--r--checks/bench.h4
-rw-r--r--checks/common.cpp (renamed from checks/misc.cpp)0
-rw-r--r--checks/common.h12
-rw-r--r--checks/test_ecc.cpp1
-rw-r--r--checks/test_ecdsa.cpp3
-rw-r--r--checks/test_transform.cpp31
7 files changed, 44 insertions, 141 deletions
diff --git a/checks/bench.cpp b/checks/bench.cpp
index b5e8e82f8..16eddd563 100644
--- a/checks/bench.cpp
+++ b/checks/bench.cpp
@@ -8,6 +8,7 @@
#include <iomanip>
#include <botan/benchmark.h>
+#include <botan/aead.h>
#include <botan/libstate.h>
#include <botan/pipe.h>
#include <botan/filters.h>
@@ -23,6 +24,8 @@ typedef std::chrono::high_resolution_clock benchmark_clock;
#include "common.h"
#include "bench.h"
+using namespace Botan;
+
namespace {
const std::string algos[] = {
@@ -56,11 +59,6 @@ const std::string algos[] = {
"Twofish",
"XTEA",
- /* Cipher constructions */
- "Cascade(Serpent,AES-128)",
- "Lion(SHA-256,Salsa20,8192)",
- "Luby-Rackoff(SHA-512)",
-
/* Cipher modes */
"AES-128/CBC/PKCS7",
"AES-128/CTR-BE",
@@ -80,23 +78,13 @@ const std::string algos[] = {
"RC4",
"Salsa20",
- /* Checksums */
- "Adler32",
- "CRC24",
- "CRC32",
-
/* Hashes */
- "BMW-512",
- "GOST-34.11",
"HAS-160",
"Keccak-1600(224)",
"Keccak-1600(256)",
"Keccak-1600(384)",
"Keccak-1600(512)",
- "MD2",
- "MD4",
"MD5",
- "RIPEMD-128",
"RIPEMD-160",
"SHA-160",
"SHA-256",
@@ -109,7 +97,6 @@ const std::string algos[] = {
/* MACs */
"CMAC(AES-128)",
"HMAC(SHA-1)",
- "X9.19-MAC",
"",
};
@@ -138,105 +125,62 @@ void report_results(const std::string& algo,
std::cout << std::endl;
}
-}
-
-bool bench_algo(const std::string& algo,
- Botan::RandomNumberGenerator& rng,
- double seconds,
- u32bit buf_size)
+bool time_transform(const std::string& algo, RandomNumberGenerator& rng)
{
- Botan::Algorithm_Factory& af = Botan::global_state().algorithm_factory();
+ std::unique_ptr<Transformation> tf(get_aead(algo, ENCRYPTION));
- std::chrono::milliseconds ms(
- static_cast<std::chrono::milliseconds::rep>(seconds * 1000));
+ if(!tf)
+ return false;
- std::map<std::string, double> speeds =
- algorithm_benchmark(algo, af, rng, ms, buf_size);
+ tf->set_key(rng.random_vec(tf->maximum_keylength()));
+ tf->start_vec(rng.random_vec(tf->default_nonce_length()));
- if(speeds.empty()) // maybe a cipher mode, then?
+ for(size_t mult : { 1, 2, 4, 8, 16, 128 })
{
- Botan::Algorithm_Factory::Engine_Iterator i(af);
-
- std::vector<std::string> algo_parts = Botan::split_on(algo, '/');
-
- if(algo_parts.size() < 2) // not a cipher mode
- return false;
-
- std::string cipher = algo_parts[0];
-
- const Botan::BlockCipher* proto_cipher =
- af.prototype_block_cipher(cipher);
-
- if(!proto_cipher)
- {
- std::cout << "Unknown algorithm " << cipher << "\n";
- return false;
- }
-
- size_t cipher_keylen = proto_cipher->maximum_keylength();
- size_t cipher_ivlen = proto_cipher->block_size();
-
- // hacks! (cipher_ivlen = transform->default_nonce_size())
+ const size_t buf_size = mult * tf->update_granularity();
- if(algo_parts[1] == "XTS")
- cipher_keylen *= 2;
- if(algo_parts[1] == "OCB")
- cipher_ivlen -= 1;
- if(algo_parts[1] == "ECB")
- cipher_ivlen = 0;
+ secure_vector<byte> buffer(buf_size);
- std::vector<byte> buf(16 * 1024);
- rng.randomize(&buf[0], buf.size());
+ double res = time_op(std::chrono::seconds(1),
+ [&tf,&buffer,buf_size]{
+ tf->update(buffer);
+ buffer.resize(buf_size);
+ });
- while(Botan::Engine* engine = i.next())
- {
- u64bit nanoseconds_max = static_cast<u64bit>(seconds * 1000000000.0);
+ const u64bit Mbytes = (res * buf_size) / 1024 / 1024;
- Botan::Keyed_Filter* filt =
- engine->get_cipher(algo, Botan::ENCRYPTION, af);
-
- if(!filt)
- continue;
-
- filt->set_key(Botan::SymmetricKey(&buf[0], cipher_keylen));
- filt->set_iv(Botan::InitializationVector(&buf[0], cipher_ivlen));
-
- Botan::Pipe pipe(filt, new Botan::BitBucket);
- pipe.start_msg();
-
- std::chrono::nanoseconds max_time(nanoseconds_max);
- std::chrono::nanoseconds time_used(0);
-
- auto start = benchmark_clock::now();
+ std::cout << algo << " " << Mbytes << " MiB / sec with " << buf_size << " byte blocks\n";
+ }
- u64bit reps = 0;
+ return true;
+ }
- while(time_used < max_time)
- {
- pipe.write(&buf[0], buf.size());
- ++reps;
- time_used = benchmark_clock::now() - start;
- }
+}
- u64bit nanoseconds_used =
- std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count();
+bool bench_algo(const std::string& algo,
+ RandomNumberGenerator& rng,
+ double seconds,
+ size_t buf_size)
+ {
+ Algorithm_Factory& af = global_state().algorithm_factory();
- double mbytes_per_second =
- (953.67 * (buf.size() * reps)) / nanoseconds_used;
+ std::chrono::milliseconds ms(
+ static_cast<std::chrono::milliseconds::rep>(seconds * 1000));
- speeds[engine->provider_name()] = mbytes_per_second;
- }
- }
+ std::map<std::string, double> speeds = algorithm_benchmark(algo, af, rng, ms, buf_size);
if(!speeds.empty())
+ {
report_results(algo, speeds);
+ return true;
+ }
- return !speeds.empty();
+ return time_transform(algo, rng);
}
-void benchmark(Botan::RandomNumberGenerator& rng,
- double seconds, u32bit buf_size)
+void benchmark(RandomNumberGenerator& rng,
+ double seconds, size_t buf_size)
{
- for(u32bit i = 0; algos[i] != ""; ++i)
+ for(size_t i = 0; algos[i] != ""; ++i)
bench_algo(algos[i], rng, seconds, buf_size);
}
diff --git a/checks/bench.h b/checks/bench.h
index 3840bc112..ba27a1c16 100644
--- a/checks/bench.h
+++ b/checks/bench.h
@@ -7,12 +7,12 @@
void benchmark(Botan::RandomNumberGenerator& rng,
double seconds,
- u32bit buf_size);
+ size_t buf_size);
bool bench_algo(const std::string& algo_name,
Botan::RandomNumberGenerator& rng,
double seconds,
- u32bit buf_size);
+ size_t buf_size);
void bench_pk(Botan::RandomNumberGenerator&,
const std::string&, double seconds);
diff --git a/checks/misc.cpp b/checks/common.cpp
index 31bc60435..31bc60435 100644
--- a/checks/misc.cpp
+++ b/checks/common.cpp
diff --git a/checks/common.h b/checks/common.h
index a6f6d3281..4b5a6c3d9 100644
--- a/checks/common.h
+++ b/checks/common.h
@@ -3,19 +3,7 @@
#ifndef BOTAN_CHECK_COMMON_H__
#define BOTAN_CHECK_COMMON_H__
-#include <vector>
#include <string>
-#include <deque>
-#include <stdexcept>
-
-#include <botan/secmem.h>
-#include <botan/filter.h>
-#include <botan/rng.h>
-#include <botan/hex.h>
-
-using Botan::byte;
-using Botan::u32bit;
-using Botan::u64bit;
void strip_comments(std::string& line);
void strip_newlines(std::string& line);
diff --git a/checks/test_ecc.cpp b/checks/test_ecc.cpp
index ba01d0a79..d61c685c9 100644
--- a/checks/test_ecc.cpp
+++ b/checks/test_ecc.cpp
@@ -9,6 +9,7 @@
#include "getopt.h"
#include "common.h"
+#include <botan/hex.h>
#include <botan/auto_rng.h>
#include <botan/bigint.h>
#include <botan/numthry.h>
diff --git a/checks/test_ecdsa.cpp b/checks/test_ecdsa.cpp
index dccb17813..aa998a3f5 100644
--- a/checks/test_ecdsa.cpp
+++ b/checks/test_ecdsa.cpp
@@ -8,7 +8,8 @@
#include "tests.h"
-#include <botan/botan.h>
+#include <botan/hex.h>
+#include <botan/auto_rng.h>
#include <botan/pubkey.h>
#include <botan/ecdsa.h>
#include <botan/rsa.h>
diff --git a/checks/test_transform.cpp b/checks/test_transform.cpp
index 08911dd7a..2c491bd89 100644
--- a/checks/test_transform.cpp
+++ b/checks/test_transform.cpp
@@ -33,37 +33,6 @@ secure_vector<byte> transform_test(const std::string& algo,
return out;
}
-namespace {
-
-void time_transform(const std::string& algo)
- {
- std::unique_ptr<Transformation> tf(get_transform(algo));
-
- AutoSeeded_RNG rng;
-
- tf->set_key(rng.random_vec(tf->maximum_keylength()));
- tf->start_vec(rng.random_vec(tf->default_nonce_length()));
-
- for(size_t mult : { 1, 2, 4, 8, 16, 128 })
- {
- const size_t buf_size = mult*tf->update_granularity();
-
- secure_vector<byte> buffer(buf_size);
-
- double res = time_op(std::chrono::seconds(1),
- [&tf,&buffer,buf_size]{
- tf->update(buffer);
- buffer.resize(buf_size);
- });
-
- const u64bit Mbytes = (res * buf_size) / 1024 / 1024;
-
- std::cout << Mbytes << " MiB / second in " << buf_size << " byte blocks\n";
- }
- }
-
-}
-
}
size_t test_transform()