diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/block/block_utils.h | 36 | ||||
-rw-r--r-- | src/lib/constructs/srp6/srp6.cpp | 8 | ||||
-rw-r--r-- | src/lib/engine/core_engine/core_engine.h | 15 | ||||
-rw-r--r-- | src/lib/engine/core_engine/core_modes.cpp | 74 | ||||
-rw-r--r-- | src/lib/engine/core_engine/info.txt | 1 | ||||
-rw-r--r-- | src/lib/engine/dyn_engine/dyn_engine.h | 7 | ||||
-rw-r--r-- | src/lib/engine/engine.cpp | 7 | ||||
-rw-r--r-- | src/lib/engine/engine.h | 12 | ||||
-rw-r--r-- | src/lib/hash/hash_utils.h | 33 | ||||
-rw-r--r-- | src/lib/kdf/kdf_utils.h | 28 | ||||
-rw-r--r-- | src/lib/libstate/lookup.cpp | 56 | ||||
-rw-r--r-- | src/lib/mac/mac_utils.h | 35 | ||||
-rw-r--r-- | src/lib/math/numbertheory/dsa_gen.cpp | 9 | ||||
-rw-r--r-- | src/lib/math/numbertheory/numthry.h | 4 | ||||
-rw-r--r-- | src/lib/passhash/passhash9/passhash9.cpp | 14 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp | 2 | ||||
-rw-r--r-- | src/lib/pk_pad/pad_utils.h | 45 | ||||
-rw-r--r-- | src/lib/pubkey/dl_group/dl_group.cpp | 10 | ||||
-rw-r--r-- | src/lib/stream/stream_utils.h | 33 | ||||
-rw-r--r-- | src/lib/tls/tls_handshake_hash.cpp | 10 | ||||
-rw-r--r-- | src/lib/tls/tls_record.cpp | 17 |
21 files changed, 284 insertions, 172 deletions
diff --git a/src/lib/block/block_utils.h b/src/lib/block/block_utils.h new file mode 100644 index 000000000..c1a1e34f8 --- /dev/null +++ b/src/lib/block/block_utils.h @@ -0,0 +1,36 @@ +/* +* Block Cipher Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_BLOCK_CIPHER_UTIL_H__ +#define BOTAN_BLOCK_CIPHER_UTIL_H__ + +#include <botan/algo_registry.h> +#include <botan/loadstor.h> +#include <botan/rotate.h> +#include <botan/internal/xor_buf.h> +#include <algorithm> +#include <functional> + +namespace Botan { + +#define BOTAN_REGISTER_BLOCK_CIPHER(name, maker) BOTAN_REGISTER_T(BlockCipher, name, maker) +#define BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(name) BOTAN_REGISTER_T_NOARGS(BlockCipher, name) + +#define BOTAN_REGISTER_BLOCK_CIPHER_1LEN(name, def) BOTAN_REGISTER_T_1LEN(BlockCipher, name, def) + +#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(type, name) BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, make_new_T<type>) +#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(type, name, def) \ + BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, (make_new_T_1len<type,def>)) +#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(type, name, def) \ + BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, std::bind(make_new_T_1str<type>, std::placeholders::_1, def)); + +#define BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(cond, type, name, provider) \ + BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, BlockCipher, type, name, provider) + +} + +#endif diff --git a/src/lib/constructs/srp6/srp6.cpp b/src/lib/constructs/srp6/srp6.cpp index c3bf3e19a..d3f7338bd 100644 --- a/src/lib/constructs/srp6/srp6.cpp +++ b/src/lib/constructs/srp6/srp6.cpp @@ -7,8 +7,8 @@ #include <botan/srp6.h> #include <botan/dl_group.h> -#include <botan/libstate.h> #include <botan/numthry.h> +#include <botan/lookup.h> namespace Botan { @@ -19,8 +19,7 @@ BigInt hash_seq(const std::string& hash_id, const BigInt& in1, const BigInt& in2) { - std::unique_ptr<HashFunction> hash_fn( - global_state().algorithm_factory().make_hash_function(hash_id)); + std::unique_ptr<HashFunction> hash_fn(get_hash(hash_id)); hash_fn->update(BigInt::encode_1363(in1, pad_to)); hash_fn->update(BigInt::encode_1363(in2, pad_to)); @@ -33,8 +32,7 @@ BigInt compute_x(const std::string& hash_id, const std::string& password, const std::vector<byte>& salt) { - std::unique_ptr<HashFunction> hash_fn( - global_state().algorithm_factory().make_hash_function(hash_id)); + std::unique_ptr<HashFunction> hash_fn(get_hash(hash_id)); hash_fn->update(identifier); hash_fn->update(":"); diff --git a/src/lib/engine/core_engine/core_engine.h b/src/lib/engine/core_engine/core_engine.h index 40afff515..9c914da66 100644 --- a/src/lib/engine/core_engine/core_engine.h +++ b/src/lib/engine/core_engine/core_engine.h @@ -36,9 +36,6 @@ class Core_Engine : public Engine Modular_Exponentiator* mod_exp(const BigInt& n, Power_Mod::Usage_Hints) const override; - Keyed_Filter* get_cipher(const std::string&, Cipher_Dir, - Algorithm_Factory&); - BlockCipher* find_block_cipher(const SCAN_Name&, Algorithm_Factory&) const override; @@ -55,18 +52,6 @@ class Core_Engine : public Engine Algorithm_Factory& af) const override; }; -/** -* Create a cipher mode filter object -* @param block_cipher a block cipher object -* @param direction are we encrypting or decrypting? -* @param mode the name of the cipher mode to use -* @param padding the mode padding to use (only used for ECB, CBC) -*/ -Keyed_Filter* get_cipher_mode(const BlockCipher* block_cipher, - Cipher_Dir direction, - const std::string& mode, - const std::string& padding); - } #endif diff --git a/src/lib/engine/core_engine/core_modes.cpp b/src/lib/engine/core_engine/core_modes.cpp deleted file mode 100644 index 02a55bcd6..000000000 --- a/src/lib/engine/core_engine/core_modes.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* -* Core Engine -* (C) 1999-2007,2011,2013 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/core_engine.h> -#include <botan/parsing.h> -#include <botan/filters.h> -#include <botan/algo_factory.h> -#include <botan/mode_pad.h> -#include <botan/transform_filter.h> -#include <botan/cipher_mode.h> - -#if defined(BOTAN_HAS_OFB) - #include <botan/ofb.h> -#endif - -#if defined(BOTAN_HAS_CTR_BE) - #include <botan/ctr.h> -#endif - -namespace Botan { - -/* -* Get a cipher object -*/ -Keyed_Filter* Core_Engine::get_cipher(const std::string& algo_spec, - Cipher_Dir direction, - Algorithm_Factory& af) - { - std::vector<std::string> algo_parts = split_on(algo_spec, '/'); - if(algo_parts.empty()) - throw Invalid_Algorithm_Name(algo_spec); - - const std::string cipher_name = algo_parts[0]; - - // check if it is a stream cipher first (easy case) - const StreamCipher* stream_cipher = af.prototype_stream_cipher(cipher_name); - if(stream_cipher) - return new StreamCipher_Filter(stream_cipher->clone()); - - const BlockCipher* block_cipher = af.prototype_block_cipher(cipher_name); - if(!block_cipher) - return nullptr; - - if(algo_parts.size() >= 4) - return nullptr; // 4 part mode, not something we know about - - if(algo_parts.size() < 2) - throw Lookup_Error("Cipher specification '" + algo_spec + - "' is missing mode identifier"); - - const std::string mode = algo_parts[1]; - -#if defined(BOTAN_HAS_OFB) - if(mode == "OFB") - return new StreamCipher_Filter(new OFB(block_cipher->clone())); -#endif - -#if defined(BOTAN_HAS_CTR_BE) - if(mode == "CTR-BE") - return new StreamCipher_Filter(new CTR_BE(block_cipher->clone())); -#endif - - std::unique_ptr<Cipher_Mode> c(get_cipher_mode(algo_spec, direction)); - if(c) - return new Transform_Filter(c.release()); - - throw Algorithm_Not_Found(algo_spec); - } - -} diff --git a/src/lib/engine/core_engine/info.txt b/src/lib/engine/core_engine/info.txt index 44843e26a..1343ad5e7 100644 --- a/src/lib/engine/core_engine/info.txt +++ b/src/lib/engine/core_engine/info.txt @@ -5,7 +5,6 @@ core_engine.h </header:internal> <source> -core_modes.cpp def_pk_ops.cpp def_powm.cpp lookup_block.cpp diff --git a/src/lib/engine/dyn_engine/dyn_engine.h b/src/lib/engine/dyn_engine/dyn_engine.h index 02a9d6343..d559a518a 100644 --- a/src/lib/engine/dyn_engine/dyn_engine.h +++ b/src/lib/engine/dyn_engine/dyn_engine.h @@ -68,13 +68,6 @@ class BOTAN_DLL Dynamically_Loaded_Engine : public Engine return engine->mod_exp(n, hints); } - Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir dir, - Algorithm_Factory& af) - { - return engine->get_cipher(algo_spec, dir, af); - } - PK_Ops::Key_Agreement* get_key_agreement_op(const Private_Key& key, RandomNumberGenerator& rng) const override { diff --git a/src/lib/engine/engine.cpp b/src/lib/engine/engine.cpp index 8c164804b..15543b289 100644 --- a/src/lib/engine/engine.cpp +++ b/src/lib/engine/engine.cpp @@ -51,13 +51,6 @@ Engine::mod_exp(const BigInt&, return nullptr; } -Keyed_Filter* Engine::get_cipher(const std::string&, - Cipher_Dir, - Algorithm_Factory&) - { - return nullptr; - } - PK_Ops::Key_Agreement* Engine::get_key_agreement_op(const Private_Key&, RandomNumberGenerator&) const { diff --git a/src/lib/engine/engine.h b/src/lib/engine/engine.h index d28bc28ab..ba8c02f93 100644 --- a/src/lib/engine/engine.h +++ b/src/lib/engine/engine.h @@ -21,7 +21,6 @@ namespace Botan { class Algorithm_Factory; -class Keyed_Filter; class RandomNumberGenerator; /** @@ -94,17 +93,6 @@ class BOTAN_DLL Engine Power_Mod::Usage_Hints hints) const; /** - * Return a new cipher object - * @param algo_spec the algorithm name/specification - * @param dir specifies if encryption or decryption is desired - * @param af an algorithm factory object - * @return newly allocated object, or NULL - */ - virtual Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir dir, - Algorithm_Factory& af); - - /** * Return a new operator object for this key, if possible * @param key the key we want an operator for * @return newly allocated operator object, or NULL diff --git a/src/lib/hash/hash_utils.h b/src/lib/hash/hash_utils.h new file mode 100644 index 000000000..00eabe820 --- /dev/null +++ b/src/lib/hash/hash_utils.h @@ -0,0 +1,33 @@ +/* +* Hash Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_HASH_UTIL_H__ +#define BOTAN_HASH_UTIL_H__ + +#include <botan/hash.h> +#include <botan/algo_registry.h> +#include <botan/loadstor.h> +#include <botan/rotate.h> + +namespace Botan { + +#define BOTAN_REGISTER_HASH(name, maker) BOTAN_REGISTER_T(HashFunction, name, maker) +#define BOTAN_REGISTER_HASH_NOARGS(name) BOTAN_REGISTER_T_NOARGS(HashFunction, name) + +#define BOTAN_REGISTER_HASH_1LEN(name, def) BOTAN_REGISTER_T_1LEN(HashFunction, name, def) + +#define BOTAN_REGISTER_HASH_NAMED_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(HashFunction, name, type, make_new_T<type>) +#define BOTAN_REGISTER_HASH_NAMED_1LEN(type, name, def) \ + BOTAN_REGISTER_NAMED_T(HashFunction, name, type, (make_new_T_1len<type,def>)) + +#define BOTAN_REGISTER_HASH_NOARGS_IF(cond, type, name, provider) \ + BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, HashFunction, type, name, provider) + +} + +#endif diff --git a/src/lib/kdf/kdf_utils.h b/src/lib/kdf/kdf_utils.h new file mode 100644 index 000000000..bf2bfb235 --- /dev/null +++ b/src/lib/kdf/kdf_utils.h @@ -0,0 +1,28 @@ +/* +* KDF Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_KDF_UTIL_H__ +#define BOTAN_KDF_UTIL_H__ + +#include <botan/kdf.h> +#include <botan/algo_registry.h> +#include <botan/exceptn.h> +#include <botan/internal/xor_buf.h> + +namespace Botan { + +#define BOTAN_REGISTER_KDF_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T<type>)) +#define BOTAN_REGISTER_KDF_1HASH(type, name) \ + BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1X<type, HashFunction>)) + +#define BOTAN_REGISTER_KDF_NAMED_1STR(type, name) \ + BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1str_req<type>)) + +} + +#endif diff --git a/src/lib/libstate/lookup.cpp b/src/lib/libstate/lookup.cpp index 290c266a3..08f0ac866 100644 --- a/src/lib/libstate/lookup.cpp +++ b/src/lib/libstate/lookup.cpp @@ -6,8 +6,19 @@ */ #include <botan/lookup.h> +#include <botan/cipher_mode.h> +#include <botan/filters.h> #include <botan/libstate.h> -#include <botan/engine.h> +#include <botan/parsing.h> +#include <botan/transform_filter.h> + +#if defined(BOTAN_HAS_OFB) + #include <botan/ofb.h> +#endif + +#if defined(BOTAN_HAS_CTR_BE) + #include <botan/ctr.h> +#endif namespace Botan { @@ -82,13 +93,44 @@ Keyed_Filter* get_cipher(const std::string& algo_spec, { Algorithm_Factory& af = global_state().algorithm_factory(); - Algorithm_Factory::Engine_Iterator i(af); + std::unique_ptr<Cipher_Mode> c(get_cipher_mode(algo_spec, direction)); + if(c) + return new Transform_Filter(c.release()); + + std::vector<std::string> algo_parts = split_on(algo_spec, '/'); + if(algo_parts.empty()) + throw Invalid_Algorithm_Name(algo_spec); + + const std::string cipher_name = algo_parts[0]; + + // check if it is a stream cipher first (easy case) + const StreamCipher* stream_cipher = af.prototype_stream_cipher(cipher_name); + if(stream_cipher) + return new StreamCipher_Filter(stream_cipher->clone()); + + const BlockCipher* block_cipher = af.prototype_block_cipher(cipher_name); + if(!block_cipher) + return nullptr; + + if(algo_parts.size() >= 4) + return nullptr; // 4 part mode, not something we know about + + if(algo_parts.size() < 2) + throw Lookup_Error("Cipher specification '" + algo_spec + + "' is missing mode identifier"); + + const std::string mode = algo_parts[1]; + + +#if defined(BOTAN_HAS_OFB) + if(mode == "OFB") + return new StreamCipher_Filter(new OFB(block_cipher->clone())); +#endif - while(Engine* engine = i.next()) - { - if(Keyed_Filter* algo = engine->get_cipher(algo_spec, direction, af)) - return algo; - } +#if defined(BOTAN_HAS_CTR_BE) + if(mode == "CTR-BE") + return new StreamCipher_Filter(new CTR_BE(block_cipher->clone())); +#endif throw Algorithm_Not_Found(algo_spec); } diff --git a/src/lib/mac/mac_utils.h b/src/lib/mac/mac_utils.h new file mode 100644 index 000000000..84c954789 --- /dev/null +++ b/src/lib/mac/mac_utils.h @@ -0,0 +1,35 @@ +/* +* Authentication Code Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_MAC_UTIL_H__ +#define BOTAN_MAC_UTIL_H__ + +#include <botan/algo_registry.h> +#include <botan/internal/xor_buf.h> +#include <botan/loadstor.h> +#include <botan/rotate.h> +#include <algorithm> + +namespace Botan { + +#define BOTAN_REGISTER_MAC(name, maker) BOTAN_REGISTER_T(MessageAuthenticationCode, name, maker) +#define BOTAN_REGISTER_MAC_NOARGS(name) BOTAN_REGISTER_T_NOARGS(MessageAuthenticationCode, name) + +#define BOTAN_REGISTER_MAC_1LEN(name, def) BOTAN_REGISTER_T_1LEN(MessageAuthenticationCode, name, def) + +#define BOTAN_REGISTER_MAC_NAMED_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, name, type, make_new_T<type>) + +#define BOTAN_REGISTER_MAC_NAMED_1LEN(type, name, def) \ + BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, name, type, (make_new_T_1len<type,def>)) +#define BOTAN_REGISTER_MAC_NAMED_1STR(type, name, def) \ + BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, name, type, \ + std::bind(make_new_T_1str<type>, std::placeholders::_1, def)); + +} + +#endif diff --git a/src/lib/math/numbertheory/dsa_gen.cpp b/src/lib/math/numbertheory/dsa_gen.cpp index 6524ad7d8..358b8bd6a 100644 --- a/src/lib/math/numbertheory/dsa_gen.cpp +++ b/src/lib/math/numbertheory/dsa_gen.cpp @@ -6,7 +6,7 @@ */ #include <botan/numthry.h> -#include <botan/algo_factory.h> +#include <botan/lookup.h> #include <botan/hash.h> #include <botan/parsing.h> #include <algorithm> @@ -38,7 +38,6 @@ bool fips186_3_valid_size(size_t pbits, size_t qbits) * Attempt DSA prime generation with given seed */ bool generate_dsa_primes(RandomNumberGenerator& rng, - Algorithm_Factory& af, BigInt& p, BigInt& q, size_t pbits, size_t qbits, const std::vector<byte>& seed_c) @@ -53,8 +52,7 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, "Generating a DSA parameter set with a " + std::to_string(qbits) + "long q requires a seed at least as many bits long"); - std::unique_ptr<HashFunction> hash( - af.make_hash_function("SHA-" + std::to_string(qbits))); + std::unique_ptr<HashFunction> hash(get_hash("SHA-" + std::to_string(qbits))); const size_t HASH_SIZE = hash->output_length(); @@ -116,7 +114,6 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, * Generate DSA Primes */ std::vector<byte> generate_dsa_primes(RandomNumberGenerator& rng, - Algorithm_Factory& af, BigInt& p, BigInt& q, size_t pbits, size_t qbits) { @@ -125,7 +122,7 @@ std::vector<byte> generate_dsa_primes(RandomNumberGenerator& rng, std::vector<byte> seed(qbits / 8); rng.randomize(&seed[0], seed.size()); - if(generate_dsa_primes(rng, af, p, q, pbits, qbits, seed)) + if(generate_dsa_primes(rng, p, q, pbits, qbits, seed)) return seed; } } diff --git a/src/lib/math/numbertheory/numthry.h b/src/lib/math/numbertheory/numthry.h index b7a77d4da..5df0858ee 100644 --- a/src/lib/math/numbertheory/numthry.h +++ b/src/lib/math/numbertheory/numthry.h @@ -168,8 +168,6 @@ BigInt BOTAN_DLL random_prime(RandomNumberGenerator& rng, BigInt BOTAN_DLL random_safe_prime(RandomNumberGenerator& rng, size_t bits); -class Algorithm_Factory; - /** * Generate DSA parameters using the FIPS 186 kosherizer * @param rng a random number generator @@ -182,7 +180,6 @@ class Algorithm_Factory; */ std::vector<byte> BOTAN_DLL generate_dsa_primes(RandomNumberGenerator& rng, - Algorithm_Factory& af, BigInt& p_out, BigInt& q_out, size_t pbits, size_t qbits); @@ -200,7 +197,6 @@ generate_dsa_primes(RandomNumberGenerator& rng, */ bool BOTAN_DLL generate_dsa_primes(RandomNumberGenerator& rng, - Algorithm_Factory& af, BigInt& p_out, BigInt& q_out, size_t pbits, size_t qbits, const std::vector<byte>& seed); diff --git a/src/lib/passhash/passhash9/passhash9.cpp b/src/lib/passhash/passhash9/passhash9.cpp index 2680ac3c4..f11a78dd0 100644 --- a/src/lib/passhash/passhash9/passhash9.cpp +++ b/src/lib/passhash/passhash9/passhash9.cpp @@ -7,7 +7,7 @@ #include <botan/passhash9.h> #include <botan/loadstor.h> -#include <botan/libstate.h> +#include <botan/lookup.h> #include <botan/pbkdf2.h> #include <botan/base64.h> @@ -26,20 +26,18 @@ const size_t WORK_FACTOR_SCALE = 10000; MessageAuthenticationCode* get_pbkdf_prf(byte alg_id) { - Algorithm_Factory& af = global_state().algorithm_factory(); - try { if(alg_id == 0) - return af.make_mac("HMAC(SHA-1)"); + return get_mac("HMAC(SHA-1)"); else if(alg_id == 1) - return af.make_mac("HMAC(SHA-256)"); + return get_mac("HMAC(SHA-256)"); else if(alg_id == 2) - return af.make_mac("CMAC(Blowfish)"); + return get_mac("CMAC(Blowfish)"); else if(alg_id == 3) - return af.make_mac("HMAC(SHA-384)"); + return get_mac("HMAC(SHA-384)"); else if(alg_id == 4) - return af.make_mac("HMAC(SHA-512)"); + return get_mac("HMAC(SHA-512)"); } catch(Algorithm_Not_Found) {} diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp index 6f6cf22b8..1b46e3f13 100644 --- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp +++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp @@ -10,7 +10,7 @@ namespace Botan { -BOTAN_REGISTER_EMSA_1HASH(EMSA_PKCS1v15, "PKCS1v15"); +BOTAN_REGISTER_EMSA_1HASH(EMSA_PKCS1v15, "EMSA_PKCS1"); namespace { diff --git a/src/lib/pk_pad/pad_utils.h b/src/lib/pk_pad/pad_utils.h new file mode 100644 index 000000000..fecdea2de --- /dev/null +++ b/src/lib/pk_pad/pad_utils.h @@ -0,0 +1,45 @@ +/* +* Public Key Padding Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_PK_PAD_UTIL_H__ +#define BOTAN_PK_PAD_UTIL_H__ + +#include <botan/algo_registry.h> +#include <botan/hash_id.h> +#include <botan/internal/xor_buf.h> +#include <botan/loadstor.h> +#include <algorithm> + +namespace Botan { + +#define BOTAN_REGISTER_EME(name, maker) BOTAN_REGISTER_T(EME, name, maker) +#define BOTAN_REGISTER_EME_NOARGS(name) BOTAN_REGISTER_T_NOARGS(EME, name) + +#define BOTAN_REGISTER_EME_NAMED_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(EME, name, type, make_new_T<type>) + +#define BOTAN_REGISTER_EMSA_1HASH_1LEN(type, name) \ + BOTAN_REGISTER_NAMED_T(EMSA, name, type, (make_new_T_1X_1len<type, HashFunction>)) + +#define BOTAN_REGISTER_EME_NAMED_1LEN(type, name, def) \ + BOTAN_REGISTER_NAMED_T(EME, name, type, (make_new_T_1len<type,def>)) +#define BOTAN_REGISTER_EME_NAMED_1STR(type, name, def) \ + BOTAN_REGISTER_NAMED_T(EME, name, type, \ + std::bind(make_new_T_1str<type>, std::placeholders::_1, def)); + +#define BOTAN_REGISTER_EMSA_NAMED_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(EMSA, name, type, make_new_T<type>) + +#define BOTAN_REGISTER_EMSA(name, maker) BOTAN_REGISTER_T(EMSA, name, maker) +#define BOTAN_REGISTER_EMSA_NOARGS(name) BOTAN_REGISTER_T_NOARGS(EMSA, name) + +#define BOTAN_REGISTER_EMSA_1HASH(type, name) \ + BOTAN_REGISTER_NAMED_T(EMSA, name, type, (make_new_T_1X<type, HashFunction>)) + +} + +#endif diff --git a/src/lib/pubkey/dl_group/dl_group.cpp b/src/lib/pubkey/dl_group/dl_group.cpp index 5cb5feae9..c519dcb99 100644 --- a/src/lib/pubkey/dl_group/dl_group.cpp +++ b/src/lib/pubkey/dl_group/dl_group.cpp @@ -6,7 +6,6 @@ */ #include <botan/dl_group.h> -#include <botan/libstate.h> #include <botan/parsing.h> #include <botan/numthry.h> #include <botan/der_enc.h> @@ -72,10 +71,7 @@ DL_Group::DL_Group(RandomNumberGenerator& rng, { qbits = qbits ? qbits : ((pbits <= 1024) ? 160 : 256); - generate_dsa_primes(rng, - global_state().algorithm_factory(), - p, q, - pbits, qbits); + generate_dsa_primes(rng, p, q, pbits, qbits); g = make_dsa_generator(p, q); } @@ -90,9 +86,7 @@ DL_Group::DL_Group(RandomNumberGenerator& rng, const std::vector<byte>& seed, size_t pbits, size_t qbits) { - if(!generate_dsa_primes(rng, - global_state().algorithm_factory(), - p, q, pbits, qbits, seed)) + if(!generate_dsa_primes(rng, p, q, pbits, qbits, seed)) throw Invalid_Argument("DL_Group: The seed given does not " "generate a DSA group"); diff --git a/src/lib/stream/stream_utils.h b/src/lib/stream/stream_utils.h new file mode 100644 index 000000000..7503029f6 --- /dev/null +++ b/src/lib/stream/stream_utils.h @@ -0,0 +1,33 @@ +/* +* Stream Cipher Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_STREAM_CIPHER_UTIL_H__ +#define BOTAN_STREAM_CIPHER_UTIL_H__ + +#include <botan/algo_registry.h> +#include <botan/loadstor.h> +#include <botan/rotate.h> +#include <botan/internal/xor_buf.h> +#include <algorithm> + +namespace Botan { + +#define BOTAN_REGISTER_STREAM_CIPHER(name, maker) BOTAN_REGISTER_T(StreamCipher, name, maker) +#define BOTAN_REGISTER_STREAM_CIPHER_NOARGS(name) BOTAN_REGISTER_T_NOARGS(StreamCipher, name) + +#define BOTAN_REGISTER_STREAM_CIPHER_1LEN(name, def) BOTAN_REGISTER_T_1LEN(StreamCipher, name, def) + +#define BOTAN_REGISTER_STREAM_CIPHER_NAMED_NOARGS(type, name) BOTAN_REGISTER_NAMED_T(StreamCipher, name, type, make_new_T<type>) +#define BOTAN_REGISTER_STREAM_CIPHER_NAMED_1LEN(type, name, def) \ + BOTAN_REGISTER_NAMED_T(StreamCipher, name, type, (make_new_T_1len<type,def>)) + +#define BOTAN_REGISTER_STREAM_CIPHER_NOARGS_IF(cond, type, name, provider) \ + BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, StreamCipher, type, name, provider) + +} + +#endif diff --git a/src/lib/tls/tls_handshake_hash.cpp b/src/lib/tls/tls_handshake_hash.cpp index a4222c60e..abbd725f6 100644 --- a/src/lib/tls/tls_handshake_hash.cpp +++ b/src/lib/tls/tls_handshake_hash.cpp @@ -7,7 +7,7 @@ #include <botan/internal/tls_handshake_hash.h> #include <botan/tls_exceptn.h> -#include <botan/libstate.h> +#include <botan/algo_registry.h> #include <botan/hash.h> namespace Botan { @@ -20,19 +20,17 @@ namespace TLS { secure_vector<byte> Handshake_Hash::final(Protocol_Version version, const std::string& mac_algo) const { - Algorithm_Factory& af = global_state().algorithm_factory(); - std::unique_ptr<HashFunction> hash; if(version.supports_ciphersuite_specific_prf()) { if(mac_algo == "MD5" || mac_algo == "SHA-1") - hash.reset(af.make_hash_function("SHA-256")); + hash.reset(make_a<HashFunction>("SHA-256")); else - hash.reset(af.make_hash_function(mac_algo)); + hash.reset(make_a<HashFunction>(mac_algo)); } else - hash.reset(af.make_hash_function("Parallel(MD5,SHA-160)")); + hash.reset(make_a<HashFunction>("Parallel(MD5,SHA-160)")); hash->update(data); return hash->final(); diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp index d5e3126f1..56648edb3 100644 --- a/src/lib/tls/tls_record.cpp +++ b/src/lib/tls/tls_record.cpp @@ -8,12 +8,12 @@ #include <botan/internal/tls_record.h> #include <botan/tls_ciphersuite.h> #include <botan/tls_exceptn.h> -#include <botan/libstate.h> #include <botan/loadstor.h> #include <botan/internal/tls_seq_numbers.h> #include <botan/internal/tls_session_key.h> #include <botan/internal/rounding.h> #include <botan/internal/xor_buf.h> +#include <botan/lookup.h> namespace Botan { @@ -62,9 +62,7 @@ Connection_Cipher_State::Connection_Cipher_State(Protocol_Version version, return; } - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(const BlockCipher* bc = af.prototype_block_cipher(cipher_algo)) + if(BlockCipher* bc = get_block_cipher(cipher_algo)) { m_block_cipher.reset(bc->clone()); m_block_cipher->set_key(cipher_key); @@ -74,7 +72,7 @@ Connection_Cipher_State::Connection_Cipher_State(Protocol_Version version, if(version.supports_explicit_cbc_ivs()) m_iv_size = m_block_size; } - else if(const StreamCipher* sc = af.prototype_stream_cipher(cipher_algo)) + else if(StreamCipher* sc = get_stream_cipher(cipher_algo)) { m_stream_cipher.reset(sc->clone()); m_stream_cipher->set_key(cipher_key); @@ -82,7 +80,7 @@ Connection_Cipher_State::Connection_Cipher_State(Protocol_Version version, else throw Invalid_Argument("Unknown TLS cipher " + cipher_algo); - m_mac.reset(af.make_mac("HMAC(" + mac_algo + ")")); + m_mac.reset(get_mac("HMAC(" + mac_algo + ")")); m_mac->set_key(mac_key); } @@ -305,9 +303,7 @@ size_t fill_buffer_to(secure_vector<byte>& readbuf, * * @fixme This should run in constant time */ -size_t tls_padding_check(size_t block_size, - const byte record[], - size_t record_len) +size_t tls_padding_check(const byte record[], size_t record_len) { const size_t padding_length = record[(record_len-1)]; @@ -405,8 +401,7 @@ void decrypt_record(secure_vector<byte>& output, { cbc_decrypt_record(record_contents, record_len, cs, *bc); - pad_size = tls_padding_check(cs.block_size(), - record_contents, record_len); + pad_size = tls_padding_check(record_contents, record_len); padding_bad = (pad_size == 0); } |