diff options
author | lloyd <[email protected]> | 2013-12-10 03:12:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-12-10 03:12:21 +0000 |
commit | 4874b0727843bba925bcd3b5c0659c5f1cb059d9 (patch) | |
tree | 0e946dde633162201396adb26eea165e74a6d779 /checks | |
parent | c6ad94933ec0d718414ba41b3c289b872c04017f (diff) |
Add Threefish-512
Diffstat (limited to 'checks')
-rw-r--r-- | checks/bench.h | 2 | ||||
-rw-r--r-- | checks/transform.cpp | 83 | ||||
-rw-r--r-- | checks/transform.vec | 12 | ||||
-rw-r--r-- | checks/validate.cpp | 1 | ||||
-rw-r--r-- | checks/validate.h | 1 |
5 files changed, 99 insertions, 0 deletions
diff --git a/checks/bench.h b/checks/bench.h index b423a2215..3840bc112 100644 --- a/checks/bench.h +++ b/checks/bench.h @@ -17,4 +17,6 @@ bool bench_algo(const std::string& algo_name, void bench_pk(Botan::RandomNumberGenerator&, const std::string&, double seconds); +void time_transform(const std::string& algo); + #endif diff --git a/checks/transform.cpp b/checks/transform.cpp new file mode 100644 index 000000000..292bcf467 --- /dev/null +++ b/checks/transform.cpp @@ -0,0 +1,83 @@ +#include "validate.h" +#include "bench.h" + +#include <botan/libstate.h> +#include <botan/botan.h> +#include <botan/threefish.h> +#include <botan/benchmark.h> +#include <botan/hex.h> +#include <iostream> +#include <fstream> + +using namespace Botan; + +namespace { + +Transformation* get_transform(const std::string& algo) + { + if(algo == "Threefish-512") + return new Threefish_512; + + throw std::runtime_error("Unknown transform " + algo); + } + +secure_vector<byte> transform_test(const std::string& algo, + const secure_vector<byte>& nonce, + const secure_vector<byte>& key, + const secure_vector<byte>& in) + { + std::unique_ptr<Transformation> transform(get_transform(algo)); + + transform->set_key(key); + transform->start_vec(nonce); + + secure_vector<byte> out = in; + transform->update(out, 0); + + return out; + } + +} + +void test_transform() + { + std::ifstream vec("checks/transform.vec"); + + run_tests(vec, "Transform", "Output", true, + [](std::map<std::string, std::string> m) + { + return hex_encode(transform_test(m["Transform"], + hex_decode_locked(m["Nonce"]), + hex_decode_locked(m["Key"]), + hex_decode_locked(m["Input"]))); + }); + + time_transform("Threefish-512"); + } + +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_size())); + + for(size_t mult : { 1, 2, 4, 8, 16, 128, 1024 }) + { + 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 << " blocks\n"; + } + } diff --git a/checks/transform.vec b/checks/transform.vec new file mode 100644 index 000000000..8f8a155e0 --- /dev/null +++ b/checks/transform.vec @@ -0,0 +1,12 @@ + +Transform = Threefish-512 +Input = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +Key = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +Nonce = 00000000000000000000000000000000 +Output = B1A2BBC6EF6025BC40EB3822161F36E375D1BB0AEE3186FBD19E47C5D479947B7BC2F8586E35F0CFF7E7F03084B0B7B1F1AB3961A580A3E97EB41EA14A6D7BBE + +Transform = Threefish-512 +Input = FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0EFEEEDECEBEAE9E8E7E6E5E4E3E2E1E0DFDEDDDCDBDAD9D8D7D6D5D4D3D2D1D0CFCECDCCCBCAC9C8C7C6C5C4C3C2C1C0 +Nonce = 000102030405060708090A0B0C0D0E0F +Key = 101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F +Output = E304439626D45A2CB401CAD8D636249A6338330EB06D45DD8B36B90E97254779272A0A8D99463504784420EA18C9A725AF11DFFEA10162348927673D5C1CAF3D diff --git a/checks/validate.cpp b/checks/validate.cpp index 48932f0e4..866f414eb 100644 --- a/checks/validate.cpp +++ b/checks/validate.cpp @@ -418,6 +418,7 @@ u32bit do_validation_tests(const std::string& filename, if(should_pass) { + test_transform(); test_ocb(); test_hkdf(); test_pbkdf(); diff --git a/checks/validate.h b/checks/validate.h index 48830619b..bb4114c3f 100644 --- a/checks/validate.h +++ b/checks/validate.h @@ -39,6 +39,7 @@ void test_hkdf(); void test_pbkdf(); void test_kdf(); void test_aead(); +void test_transform(); void run_tests_bb(std::istream& src, const std::string& name_key, |