diff options
author | Jack Lloyd <[email protected]> | 2016-10-11 13:00:57 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-10-21 16:53:16 -0400 |
commit | 558808900bffc3c48da5e6d79ba602e88e619154 (patch) | |
tree | fd76ee2d009c2b707d888683cbd767351c4ff6b3 /src/lib/modes/aead | |
parent | 6aa855bba613c7b6fedfbe71d15930964acb1633 (diff) |
Remove Algo_Registry
I repent my use of global constructors.
I repent my use of global locks.
Hopefully I will never touch this code again.
:)
Diffstat (limited to 'src/lib/modes/aead')
-rw-r--r-- | src/lib/modes/aead/aead.cpp | 113 | ||||
-rw-r--r-- | src/lib/modes/aead/aead.h | 2 | ||||
-rw-r--r-- | src/lib/modes/aead/ccm/ccm.cpp | 1 | ||||
-rw-r--r-- | src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp | 1 | ||||
-rw-r--r-- | src/lib/modes/aead/eax/eax.cpp | 1 | ||||
-rw-r--r-- | src/lib/modes/aead/gcm/gcm.cpp | 2 | ||||
-rw-r--r-- | src/lib/modes/aead/ocb/ocb.cpp | 2 | ||||
-rw-r--r-- | src/lib/modes/aead/siv/siv.cpp | 1 |
8 files changed, 94 insertions, 29 deletions
diff --git a/src/lib/modes/aead/aead.cpp b/src/lib/modes/aead/aead.cpp index 88e6cbeaa..033dad94e 100644 --- a/src/lib/modes/aead/aead.cpp +++ b/src/lib/modes/aead/aead.cpp @@ -5,8 +5,12 @@ */ #include <botan/aead.h> -#include <botan/internal/mode_utils.h> -#include <botan/internal/algo_registry.h> +#include <botan/scan_name.h> +#include <sstream> + +#if defined(BOTAN_HAS_BLOCK_CIPHER) + #include <botan/block_cipher.h> +#endif #if defined(BOTAN_HAS_AEAD_CCM) #include <botan/ccm.h> @@ -34,42 +38,107 @@ namespace Botan { -AEAD_Mode::~AEAD_Mode() {} +AEAD_Mode* get_aead(const std::string& algo, Cipher_Dir dir) + { +#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305) + if(algo == "ChaCha20Poly1305") + { + if(dir == ENCRYPTION) + return new ChaCha20Poly1305_Encryption; + else + return new ChaCha20Poly1305_Decryption; -#if defined(BOTAN_HAS_AEAD_CCM) -BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN2(CCM_Encryption, CCM_Decryption, 16, 3); + } #endif -#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305) -BOTAN_REGISTER_T_NOARGS(Cipher_Mode, ChaCha20Poly1305_Encryption); -BOTAN_REGISTER_T_NOARGS(Cipher_Mode, ChaCha20Poly1305_Decryption); -#endif + if(algo.find('/') != std::string::npos) + { + const std::vector<std::string> algo_parts = split_on(algo, '/'); + const std::string cipher_name = algo_parts[0]; + const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]); -#if defined(BOTAN_HAS_AEAD_EAX) -BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(EAX_Encryption, EAX_Decryption, 0); + if(mode_info.empty()) + return nullptr; + + std::ostringstream alg_args; + + alg_args << '(' << cipher_name; + for(size_t i = 1; i < mode_info.size(); ++i) + alg_args << ',' << mode_info[i]; + for(size_t i = 2; i < algo_parts.size(); ++i) + alg_args << ',' << algo_parts[i]; + alg_args << ')'; + + const std::string mode_name = mode_info[0] + alg_args.str(); + return get_aead(mode_name, dir); + } + +#if defined(BOTAN_HAS_BLOCK_CIPHER) + + SCAN_Name req(algo); + std::unique_ptr<BlockCipher> bc(BlockCipher::create(req.arg(0))); + + if(!bc) + { + return nullptr; + } + +#if defined(BOTAN_HAS_AEAD_CCM) + if(req.algo_name() == "CCM") + { + size_t tag_len = req.arg_as_integer(1, 16); + size_t L_len = req.arg_as_integer(2, 3); + if(dir == ENCRYPTION) + return new CCM_Encryption(bc.release(), tag_len, L_len); + else + return new CCM_Decryption(bc.release(), tag_len, L_len); + } #endif #if defined(BOTAN_HAS_AEAD_GCM) -BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(GCM_Encryption, GCM_Decryption, 16); + if(req.algo_name() == "GCM") + { + size_t tag_len = req.arg_as_integer(1, 16); + if(dir == ENCRYPTION) + return new GCM_Encryption(bc.release(), tag_len); + else + return new GCM_Decryption(bc.release(), tag_len); + } #endif #if defined(BOTAN_HAS_AEAD_OCB) -BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(OCB_Encryption, OCB_Decryption, 16); + if(req.algo_name() == "OCB") + { + size_t tag_len = req.arg_as_integer(1, 16); + if(dir == ENCRYPTION) + return new OCB_Encryption(bc.release(), tag_len); + else + return new OCB_Decryption(bc.release(), tag_len); + } #endif -#if defined(BOTAN_HAS_AEAD_SIV) -BOTAN_REGISTER_BLOCK_CIPHER_MODE(SIV_Encryption, SIV_Decryption); +#if defined(BOTAN_HAS_AEAD_EAX) + if(req.algo_name() == "EAX") + { + size_t tag_len = req.arg_as_integer(1, bc->block_size()); + if(dir == ENCRYPTION) + return new EAX_Encryption(bc.release(), tag_len); + else + return new EAX_Decryption(bc.release(), tag_len); + } #endif -AEAD_Mode* get_aead(const std::string& algo_spec, Cipher_Dir direction) - { - std::unique_ptr<Cipher_Mode> mode(get_cipher_mode(algo_spec, direction)); - - if(AEAD_Mode* aead = dynamic_cast<AEAD_Mode*>(mode.get())) +#if defined(BOTAN_HAS_AEAD_SIV) + if(req.algo_name() == "SIV") { - mode.release(); - return aead; + if(dir == ENCRYPTION) + return new SIV_Encryption(bc.release()); + else + return new SIV_Decryption(bc.release()); } +#endif + +#endif return nullptr; } diff --git a/src/lib/modes/aead/aead.h b/src/lib/modes/aead/aead.h index 0769a1829..2cdc6137e 100644 --- a/src/lib/modes/aead/aead.h +++ b/src/lib/modes/aead/aead.h @@ -74,7 +74,7 @@ class BOTAN_DLL AEAD_Mode : public Cipher_Mode */ size_t default_nonce_length() const override { return 12; } - virtual ~AEAD_Mode(); + virtual ~AEAD_Mode() {} }; /** diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp index d5559bfb5..81b9f4943 100644 --- a/src/lib/modes/aead/ccm/ccm.cpp +++ b/src/lib/modes/aead/ccm/ccm.cpp @@ -5,7 +5,6 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/mode_utils.h> #include <botan/ccm.h> #include <botan/parsing.h> diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp index 04326dede..d2f16c225 100644 --- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp +++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp @@ -6,7 +6,6 @@ */ #include <botan/chacha20poly1305.h> -#include <botan/internal/mode_utils.h> namespace Botan { diff --git a/src/lib/modes/aead/eax/eax.cpp b/src/lib/modes/aead/eax/eax.cpp index f26a1eae3..c76f15b48 100644 --- a/src/lib/modes/aead/eax/eax.cpp +++ b/src/lib/modes/aead/eax/eax.cpp @@ -5,7 +5,6 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/mode_utils.h> #include <botan/eax.h> #include <botan/cmac.h> #include <botan/ctr.h> diff --git a/src/lib/modes/aead/gcm/gcm.cpp b/src/lib/modes/aead/gcm/gcm.cpp index 32c6c0b70..a73e5ee5b 100644 --- a/src/lib/modes/aead/gcm/gcm.cpp +++ b/src/lib/modes/aead/gcm/gcm.cpp @@ -6,8 +6,8 @@ */ #include <botan/gcm.h> -#include <botan/internal/mode_utils.h> #include <botan/internal/ct_utils.h> +#include <botan/loadstor.h> #include <botan/ctr.h> #if defined(BOTAN_HAS_GCM_CLMUL) diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp index e21749f3b..0ce2b6f00 100644 --- a/src/lib/modes/aead/ocb/ocb.cpp +++ b/src/lib/modes/aead/ocb/ocb.cpp @@ -5,9 +5,9 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/mode_utils.h> #include <botan/ocb.h> #include <botan/cmac.h> +#include <botan/internal/bit_ops.h> namespace Botan { diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp index 5f8c13f7f..ce20f3ada 100644 --- a/src/lib/modes/aead/siv/siv.cpp +++ b/src/lib/modes/aead/siv/siv.cpp @@ -5,7 +5,6 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/mode_utils.h> #include <botan/siv.h> #include <botan/cmac.h> #include <botan/ctr.h> |