diff options
author | lloyd <[email protected]> | 2015-01-28 04:32:10 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-28 04:32:10 +0000 |
commit | 7b56f1bd570dc684ffd7c945dee0d9b5480354ff (patch) | |
tree | 0c50ad534280a292a1b76daee9a19b34cfd96367 /src/lib/block/lion | |
parent | b8fa304ec981d273c45d7ef31705d65ccfb00cc1 (diff) |
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.
Diffstat (limited to 'src/lib/block/lion')
-rw-r--r-- | src/lib/block/lion/lion.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/lib/block/lion/lion.cpp b/src/lib/block/lion/lion.cpp index 7e18eec56..420b92cdb 100644 --- a/src/lib/block/lion/lion.cpp +++ b/src/lib/block/lion/lion.cpp @@ -5,12 +5,36 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/block_utils.h> #include <botan/lion.h> -#include <botan/internal/xor_buf.h> #include <botan/parsing.h> +#include <botan/libstate.h> namespace Botan { +namespace { + +Lion* make_lion(const BlockCipher::Spec& spec) + { + if(spec.arg_count_between(2, 3)) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + const HashFunction* hash = af.prototype_hash_function(spec.arg(0)); + const StreamCipher* stream_cipher = af.prototype_stream_cipher(spec.arg(1)); + + if(hash && stream_cipher) + { + const size_t block_size = spec.arg_as_integer(2, 1024); + return new Lion(hash->clone(), stream_cipher->clone(), block_size); + } + } + return nullptr; + } + +} + +BOTAN_REGISTER_NAMED_T(BlockCipher, "Lion", Lion, make_lion); + /* * Lion Encryption */ |