From 7b56f1bd570dc684ffd7c945dee0d9b5480354ff Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 28 Jan 2015 04:32:10 +0000 Subject: Add a runtime map of string->func() which when called return Transforms and BlockCiphers. Registration for all types is done at startup but is very cheap as just a std::function and a std::map entry are created, no actual objects are created until needed. This is a huge improvement over Algorithm_Factory which used T::clone() as the function and thus kept a prototype object of each type in memory. Replace existing lookup mechanisms for ciphers, AEADs, and compression to use the transform lookup. The existing Engine framework remains in place for BlockCipher, but the engines now just call to the registry instead of having hardcoded lookups. s/Transformation/Transform/ with typedefs for compatability. Remove lib/selftest code (for runtime selftesting): not the right approach. --- src/cmd/compress.cpp | 18 +++++++++++++++--- src/cmd/speed.cpp | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/compress.cpp b/src/cmd/compress.cpp index 8480801e9..646a4d587 100644 --- a/src/cmd/compress.cpp +++ b/src/cmd/compress.cpp @@ -11,7 +11,7 @@ namespace { -void do_compress(Transformation& comp, std::ifstream& in, std::ostream& out) +void do_compress(Transform& comp, std::ifstream& in, std::ostream& out) { secure_vector buf; @@ -53,7 +53,13 @@ int compress(int argc, char* argv[]) const size_t level = 9; const std::string suffix = argc == 3 ? argv[2] : "gz"; - std::unique_ptr compress(make_compressor(suffix, level)); + std::unique_ptr compress(make_compressor(suffix, level)); + + if(!compress) + { + std::cout << suffix << " compression not supported\n"; + return 1; + } const std::string out_file = in_file + "." + suffix; std::ofstream out(out_file.c_str()); @@ -91,7 +97,13 @@ int uncompress(int argc, char* argv[]) std::ofstream out(out_file.c_str()); - std::unique_ptr decompress(make_decompressor(suffix)); + std::unique_ptr decompress(make_decompressor(suffix)); + + if(!decompress) + { + std::cout << suffix << " decompression not supported\n"; + return 1; + } do_compress(*decompress, in, out); diff --git a/src/cmd/speed.cpp b/src/cmd/speed.cpp index 8f19063be..4558c4250 100644 --- a/src/cmd/speed.cpp +++ b/src/cmd/speed.cpp @@ -121,7 +121,7 @@ void report_results(const std::string& algo, std::cout << std::endl; } -void time_transform(std::unique_ptr tf, +void time_transform(std::unique_ptr tf, RandomNumberGenerator& rng) { if(!tf) @@ -162,7 +162,7 @@ void time_transform(std::unique_ptr tf, void time_transform(const std::string& algo, RandomNumberGenerator& rng) { - std::unique_ptr tf; + std::unique_ptr tf; tf.reset(get_aead(algo, ENCRYPTION)); if(Keyed_Transform* keyed = dynamic_cast(tf.get())) -- cgit v1.2.3