diff options
author | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
commit | 0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch) | |
tree | ed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/modes/cipher_mode.cpp | |
parent | f9a7c85b74be0f4a7273e8e0591703af83036e81 (diff) |
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry
The shared pool of entropy sources remains but is moved to EntropySource.
With that and few remaining initializations (default OIDs and aliases)
moved elsewhere, the global state is empty and init and shutdown are no-ops.
Remove almost all of the headers and code for handling the global
state, except LibraryInitializer which remains as a compatability stub.
Update seeding for blinding so only one hacky almost-global RNG
instance needs to be setup instead of across all pubkey uses (it uses
either the system RNG or an AutoSeeded_RNG if the system RNG is not
available).
Diffstat (limited to 'src/lib/modes/cipher_mode.cpp')
-rw-r--r-- | src/lib/modes/cipher_mode.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/lib/modes/cipher_mode.cpp b/src/lib/modes/cipher_mode.cpp index ded7b4c81..f568415f4 100644 --- a/src/lib/modes/cipher_mode.cpp +++ b/src/lib/modes/cipher_mode.cpp @@ -6,16 +6,17 @@ */ #include <botan/cipher_mode.h> +#include <botan/lookup.h> #include <sstream> namespace Botan { Cipher_Mode* get_cipher_mode(const std::string& algo_spec, Cipher_Dir direction) { - const char* dir_string = (direction == ENCRYPTION) ? "_Encryption" : "_Decryption"; - const std::string provider = ""; + const char* dir_string = (direction == ENCRYPTION) ? "_Encryption" : "_Decryption"; + std::unique_ptr<Transform> t; t.reset(get_transform(algo_spec, provider, dir_string)); @@ -36,16 +37,19 @@ Cipher_Mode* get_cipher_mode(const std::string& algo_spec, Cipher_Dir direction) if(mode_info.empty()) return nullptr; - std::ostringstream t_name; + std::ostringstream alg_args; - t_name << mode_info[0] << dir_string << '(' << cipher_name; + alg_args << '(' << cipher_name; for(size_t i = 1; i < mode_info.size(); ++i) - t_name << ',' << mode_info[i]; + alg_args << ',' << mode_info[i]; for(size_t i = 2; i < algo_parts.size(); ++i) - t_name << ',' << algo_parts[i]; - t_name << ')'; + alg_args << ',' << algo_parts[i]; + alg_args << ')'; - t.reset(get_transform(t_name.str(), provider)); + const std::string mode_name = mode_info[0] + alg_args.str(); + const std::string mode_name_directional = mode_info[0] + dir_string + alg_args.str(); + + t.reset(get_transform(mode_name_directional, provider)); if(Cipher_Mode* cipher = dynamic_cast<Cipher_Mode*>(t.get())) { @@ -53,6 +57,17 @@ Cipher_Mode* get_cipher_mode(const std::string& algo_spec, Cipher_Dir direction) return cipher; } + t.reset(get_transform(mode_name, provider)); + + if(Cipher_Mode* cipher = dynamic_cast<Cipher_Mode*>(t.get())) + { + t.release(); + return cipher; + } + + if(StreamCipher* stream_cipher = get_stream_cipher(mode_name, provider)) + return new Stream_Cipher_Mode(stream_cipher); + return nullptr; } |