aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2015-09-21 16:09:36 -0400
committerJack Lloyd <[email protected]>2015-09-21 16:09:36 -0400
commit7ebe7511496b8a6950acced513a81516565354ed (patch)
treeadd1163c2afbd1ae3d163aaac8375a3b56bd6c9c /src/lib
parent8f732dccce692eaca509fc9732702df62cfa5c87 (diff)
parent04319af23bf8ed467b17f9b74c814343e051ab6b (diff)
Merge pull request #279 from randombit/fix-static-lib-registration
Move the algorithm factory functions to T::create and move object registration to the source file for its base class. These resolve the issues which prevented successful use of a static library that was built with individual object files. Removes the restriction in configure.py which prevented building non-amalgamation static libs.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/asn1/ber_dec.cpp2
-rw-r--r--src/lib/asn1/der_enc.cpp2
-rw-r--r--src/lib/base/algo_registry.h10
-rw-r--r--src/lib/base/buf_comp.h2
-rw-r--r--src/lib/base/info.txt1
-rw-r--r--src/lib/base/lookup.cpp109
-rw-r--r--src/lib/base/lookup.h108
-rw-r--r--src/lib/base/symkey.cpp1
-rw-r--r--src/lib/base/transform.cpp20
-rw-r--r--src/lib/block/aes/aes.cpp6
-rw-r--r--src/lib/block/aes_ni/aes_ni.cpp6
-rw-r--r--src/lib/block/aes_ssse3/aes_ssse3.cpp8
-rw-r--r--src/lib/block/block_cipher.cpp319
-rw-r--r--src/lib/block/block_cipher.h15
-rw-r--r--src/lib/block/block_utils.h38
-rw-r--r--src/lib/block/blowfish/blowfish.cpp4
-rw-r--r--src/lib/block/camellia/camellia.cpp6
-rw-r--r--src/lib/block/cascade/cascade.cpp7
-rw-r--r--src/lib/block/cast/cast128.cpp4
-rw-r--r--src/lib/block/cast/cast256.cpp4
-rw-r--r--src/lib/block/des/des.cpp5
-rw-r--r--src/lib/block/des/desx.cpp3
-rw-r--r--src/lib/block/gost_28147/gost_28147.cpp4
-rw-r--r--src/lib/block/idea/idea.cpp4
-rw-r--r--src/lib/block/idea_sse2/idea_sse2.cpp4
-rw-r--r--src/lib/block/info.txt4
-rw-r--r--src/lib/block/kasumi/kasumi.cpp4
-rw-r--r--src/lib/block/lion/lion.cpp13
-rw-r--r--src/lib/block/lion/lion.h2
-rw-r--r--src/lib/block/mars/mars.cpp4
-rw-r--r--src/lib/block/misty1/misty1.cpp4
-rw-r--r--src/lib/block/noekeon/noekeon.cpp4
-rw-r--r--src/lib/block/noekeon_simd/noekeon_simd.cpp4
-rw-r--r--src/lib/block/rc2/rc2.cpp4
-rw-r--r--src/lib/block/rc5/rc5.cpp4
-rw-r--r--src/lib/block/rc6/rc6.cpp4
-rw-r--r--src/lib/block/safer/safer_sk.cpp4
-rw-r--r--src/lib/block/seed/seed.cpp4
-rw-r--r--src/lib/block/serpent/serpent.cpp4
-rw-r--r--src/lib/block/serpent_simd/serp_simd.cpp4
-rw-r--r--src/lib/block/tea/tea.cpp4
-rw-r--r--src/lib/block/threefish/threefish.cpp4
-rw-r--r--src/lib/block/threefish_avx2/threefish_avx2.cpp4
-rw-r--r--src/lib/block/twofish/twofish.cpp5
-rw-r--r--src/lib/block/xtea/xtea.cpp4
-rw-r--r--src/lib/block/xtea_simd/xtea_simd.cpp4
-rw-r--r--src/lib/cert/x509/ocsp_types.cpp5
-rw-r--r--src/lib/cert/x509/x509_ca.cpp7
-rw-r--r--src/lib/cert/x509/x509cert.cpp3
-rw-r--r--src/lib/ffi/ffi.cpp13
-rw-r--r--src/lib/filters/algo_filt.cpp25
-rw-r--r--src/lib/hash/checksum/adler32/adler32.cpp4
-rw-r--r--src/lib/hash/checksum/crc24/crc24.cpp5
-rw-r--r--src/lib/hash/checksum/crc32/crc32.cpp4
-rw-r--r--src/lib/hash/comb4p/comb4p.cpp8
-rw-r--r--src/lib/hash/gost_3411/gost_3411.cpp4
-rw-r--r--src/lib/hash/has160/has160.cpp3
-rw-r--r--src/lib/hash/hash.cpp206
-rw-r--r--src/lib/hash/hash.h21
-rw-r--r--src/lib/hash/hash_utils.h33
-rw-r--r--src/lib/hash/info.txt4
-rw-r--r--src/lib/hash/keccak/keccak.cpp4
-rw-r--r--src/lib/hash/md2/md2.cpp4
-rw-r--r--src/lib/hash/md4/md4.cpp3
-rw-r--r--src/lib/hash/md5/md5.cpp3
-rw-r--r--src/lib/hash/par_hash/par_hash.cpp5
-rw-r--r--src/lib/hash/rmd128/rmd128.cpp3
-rw-r--r--src/lib/hash/rmd160/rmd160.cpp3
-rw-r--r--src/lib/hash/sha1/sha160.cpp3
-rw-r--r--src/lib/hash/sha1_sse2/sha1_sse2.cpp4
-rw-r--r--src/lib/hash/sha2_32/sha2_32.cpp4
-rw-r--r--src/lib/hash/sha2_64/sha2_64.cpp5
-rw-r--r--src/lib/hash/skein/skein_512.cpp4
-rw-r--r--src/lib/hash/tiger/tiger.cpp3
-rw-r--r--src/lib/hash/whirlpool/whirlpool.cpp3
-rw-r--r--src/lib/kdf/hkdf/hkdf.cpp11
-rw-r--r--src/lib/kdf/info.txt4
-rw-r--r--src/lib/kdf/kdf.cpp77
-rw-r--r--src/lib/kdf/kdf.h15
-rw-r--r--src/lib/kdf/kdf1/kdf1.cpp3
-rw-r--r--src/lib/kdf/kdf2/kdf2.cpp3
-rw-r--r--src/lib/kdf/kdf_utils.h28
-rw-r--r--src/lib/kdf/prf_tls/prf_tls.cpp20
-rw-r--r--src/lib/kdf/prf_x942/prf_x942.cpp5
-rw-r--r--src/lib/mac/cbc_mac/cbc_mac.cpp5
-rw-r--r--src/lib/mac/cmac/cmac.cpp7
-rw-r--r--src/lib/mac/hmac/hmac.cpp7
-rw-r--r--src/lib/mac/info.txt4
-rw-r--r--src/lib/mac/mac.cpp62
-rw-r--r--src/lib/mac/mac.h19
-rw-r--r--src/lib/mac/mac_utils.h35
-rw-r--r--src/lib/mac/poly1305/poly1305.cpp3
-rw-r--r--src/lib/mac/siphash/siphash.cpp3
-rw-r--r--src/lib/mac/x919_mac/x919_mac.cpp10
-rw-r--r--src/lib/math/bigint/bigint.cpp2
-rw-r--r--src/lib/math/bigint/bigint.h2
-rw-r--r--src/lib/math/numbertheory/dsa_gen.cpp6
-rw-r--r--src/lib/misc/aont/package.cpp3
-rw-r--r--src/lib/misc/benchmark/benchmark.cpp25
-rw-r--r--src/lib/misc/cryptobox/cryptobox.cpp3
-rw-r--r--src/lib/misc/pbes2/pbes2.cpp1
-rw-r--r--src/lib/misc/rfc3394/rfc3394.cpp12
-rw-r--r--src/lib/misc/srp6/srp6.cpp11
-rw-r--r--src/lib/modes/aead/aead.cpp51
-rw-r--r--src/lib/modes/aead/aead.h2
-rw-r--r--src/lib/modes/aead/ccm/ccm.cpp2
-rw-r--r--src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp12
-rw-r--r--src/lib/modes/aead/eax/eax.cpp2
-rw-r--r--src/lib/modes/aead/gcm/gcm.cpp2
-rw-r--r--src/lib/modes/aead/ocb/ocb.cpp2
-rw-r--r--src/lib/modes/aead/siv/siv.cpp2
-rw-r--r--src/lib/modes/cbc/cbc.cpp21
-rw-r--r--src/lib/modes/cfb/cfb.cpp2
-rw-r--r--src/lib/modes/cipher_mode.cpp70
-rw-r--r--src/lib/modes/ecb/ecb.cpp13
-rw-r--r--src/lib/modes/mode_utils.h13
-rw-r--r--src/lib/modes/xts/xts.cpp2
-rw-r--r--src/lib/passhash/passhash9/passhash9.cpp21
-rw-r--r--src/lib/pbkdf/info.txt4
-rw-r--r--src/lib/pbkdf/pbkdf.cpp33
-rw-r--r--src/lib/pbkdf/pbkdf.h30
-rw-r--r--src/lib/pbkdf/pbkdf1/pbkdf1.cpp3
-rw-r--r--src/lib/pbkdf/pbkdf2/pbkdf2.cpp14
-rw-r--r--src/lib/pbkdf/pbkdf_utils.h23
-rw-r--r--src/lib/pk_pad/eme.cpp44
-rw-r--r--src/lib/pk_pad/eme_oaep/oaep.cpp9
-rw-r--r--src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp3
-rw-r--r--src/lib/pk_pad/eme_raw/eme_raw.cpp3
-rw-r--r--src/lib/pk_pad/emsa.cpp83
-rw-r--r--src/lib/pk_pad/emsa.h7
-rw-r--r--src/lib/pk_pad/emsa1/emsa1.cpp3
-rw-r--r--src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp3
-rw-r--r--src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp13
-rw-r--r--src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h2
-rw-r--r--src/lib/pk_pad/emsa_pssr/pssr.cpp9
-rw-r--r--src/lib/pk_pad/emsa_raw/emsa_raw.cpp3
-rw-r--r--src/lib/pk_pad/emsa_x931/emsa_x931.cpp3
-rw-r--r--src/lib/pk_pad/get_pk_pad.cpp38
-rw-r--r--src/lib/pk_pad/info.txt4
-rw-r--r--src/lib/pk_pad/mgf1/mgf1.cpp1
-rw-r--r--src/lib/pk_pad/pad_utils.h44
-rw-r--r--src/lib/pubkey/dlies/dlies.cpp1
-rw-r--r--src/lib/pubkey/ecdh/ecdh.cpp2
-rw-r--r--src/lib/pubkey/ecdh/ecdh.h2
-rw-r--r--src/lib/pubkey/mce/binary_matrix.cpp1
-rw-r--r--src/lib/pubkey/mce/mceliece.cpp1
-rw-r--r--src/lib/pubkey/rfc6979/rfc6979.cpp4
-rw-r--r--src/lib/rng/hmac_rng/hmac_rng.cpp2
-rw-r--r--src/lib/rng/rng.cpp8
-rw-r--r--src/lib/rng/x931_rng/x931_rng.cpp1
-rw-r--r--src/lib/stream/chacha/chacha.cpp4
-rw-r--r--src/lib/stream/ctr/ctr.cpp7
-rw-r--r--src/lib/stream/info.txt4
-rw-r--r--src/lib/stream/ofb/ofb.cpp7
-rw-r--r--src/lib/stream/rc4/rc4.cpp3
-rw-r--r--src/lib/stream/salsa20/salsa20.cpp4
-rw-r--r--src/lib/stream/stream_cipher.cpp73
-rw-r--r--src/lib/stream/stream_cipher.h24
-rw-r--r--src/lib/stream/stream_utils.h31
-rw-r--r--src/lib/tls/msg_hello_verify.cpp3
-rw-r--r--src/lib/tls/sessions_sql/tls_session_manager_sql.cpp1
-rw-r--r--src/lib/tls/tls_ciphersuite.cpp10
-rw-r--r--src/lib/tls/tls_handshake_hash.cpp3
-rw-r--r--src/lib/tls/tls_record.cpp23
-rw-r--r--src/lib/tls/tls_version.h2
-rw-r--r--src/lib/utils/cpuid.cpp2
-rw-r--r--src/lib/utils/get_byte.h12
-rw-r--r--src/lib/utils/info.txt4
-rw-r--r--src/lib/utils/loadstor.h14
-rw-r--r--src/lib/utils/mem_ops.h127
-rw-r--r--src/lib/utils/parsing.cpp2
-rw-r--r--src/lib/vendor/openssl/openssl_block.cpp5
-rw-r--r--src/lib/vendor/openssl/openssl_hash.cpp3
-rw-r--r--src/lib/vendor/openssl/openssl_rc4.cpp3
174 files changed, 1574 insertions, 981 deletions
diff --git a/src/lib/asn1/ber_dec.cpp b/src/lib/asn1/ber_dec.cpp
index 4267d79dc..80dfba3bb 100644
--- a/src/lib/asn1/ber_dec.cpp
+++ b/src/lib/asn1/ber_dec.cpp
@@ -8,7 +8,7 @@
#include <botan/ber_dec.h>
#include <botan/bigint.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/lib/asn1/der_enc.cpp b/src/lib/asn1/der_enc.cpp
index f886e8ed3..f1bcf634e 100644
--- a/src/lib/asn1/der_enc.cpp
+++ b/src/lib/asn1/der_enc.cpp
@@ -8,7 +8,7 @@
#include <botan/der_enc.h>
#include <botan/asn1_obj.h>
#include <botan/bigint.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/internal/bit_ops.h>
#include <algorithm>
diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h
index 498021194..e16522d94 100644
--- a/src/lib/base/algo_registry.h
+++ b/src/lib/base/algo_registry.h
@@ -7,7 +7,7 @@
#ifndef BOTAN_ALGO_REGISTRY_H__
#define BOTAN_ALGO_REGISTRY_H__
-#include <botan/lookup.h>
+#include <botan/types.h>
#include <functional>
#include <stdexcept>
#include <mutex>
@@ -35,7 +35,8 @@ class Algo_Registry
void add(const std::string& name, const std::string& provider, maker_fn fn, byte pref)
{
std::unique_lock<std::mutex> lock(m_mutex);
- m_algo_info[name].add_provider(provider, fn, pref);
+ if(!m_algo_info[name].add_provider(provider, fn, pref))
+ throw std::runtime_error("Duplicated registration of " + name + "/" + provider);
}
std::vector<std::string> providers_of(const Spec& spec)
@@ -102,13 +103,14 @@ class Algo_Registry
struct Algo_Info
{
public:
- void add_provider(const std::string& provider, maker_fn fn, byte pref)
+ bool add_provider(const std::string& provider, maker_fn fn, byte pref)
{
if(m_maker_fns.count(provider) > 0)
- throw std::runtime_error("Duplicated registration of '" + provider + "'");
+ return false;
m_maker_fns[provider] = fn;
m_prefs.insert(std::make_pair(pref, provider));
+ return true;
}
std::vector<std::string> providers() const
diff --git a/src/lib/base/buf_comp.h b/src/lib/base/buf_comp.h
index 30e30c71c..d0793b84b 100644
--- a/src/lib/base/buf_comp.h
+++ b/src/lib/base/buf_comp.h
@@ -9,7 +9,7 @@
#define BOTAN_BUFFERED_COMPUTATION_H__
#include <botan/secmem.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <string>
namespace Botan {
diff --git a/src/lib/base/info.txt b/src/lib/base/info.txt
index 19eee6608..33d22a279 100644
--- a/src/lib/base/info.txt
+++ b/src/lib/base/info.txt
@@ -23,7 +23,6 @@ hash
hex
mac
modes
-pbkdf
rng
stream
utils
diff --git a/src/lib/base/lookup.cpp b/src/lib/base/lookup.cpp
deleted file mode 100644
index 6655a4fb4..000000000
--- a/src/lib/base/lookup.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
-* Algorithm Retrieval
-* (C) 1999-2007,2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#include <botan/lookup.h>
-#include <botan/internal/algo_registry.h>
-#include <botan/cipher_mode.h>
-#include <botan/block_cipher.h>
-#include <botan/stream_cipher.h>
-#include <botan/hash.h>
-#include <botan/mac.h>
-#include <botan/pbkdf.h>
-
-namespace Botan {
-
-Transform* get_transform(const std::string& specstr,
- const std::string& provider,
- const std::string& dirstr)
- {
- Algo_Registry<Transform>::Spec spec(specstr, dirstr);
- return Algo_Registry<Transform>::global_registry().make(spec, provider);
- }
-
-BlockCipher* get_block_cipher(const std::string& algo_spec, const std::string& provider)
- {
- return make_a<BlockCipher>(algo_spec, provider);
- }
-
-StreamCipher* get_stream_cipher(const std::string& algo_spec, const std::string& provider)
- {
- return make_a<StreamCipher>(algo_spec, provider);
- }
-
-HashFunction* get_hash_function(const std::string& algo_spec, const std::string& provider)
- {
- return make_a<HashFunction>(algo_spec, provider);
- }
-
-MessageAuthenticationCode* get_mac(const std::string& algo_spec, const std::string& provider)
- {
- return make_a<MessageAuthenticationCode>(algo_spec, provider);
- }
-
-std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec,
- const std::string& provider)
- {
- if(auto x = get_block_cipher(algo_spec, provider))
- return std::unique_ptr<BlockCipher>(x);
- throw Algorithm_Not_Found(algo_spec);
- }
-
-std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec,
- const std::string& provider)
- {
- if(auto x = get_stream_cipher(algo_spec, provider))
- return std::unique_ptr<StreamCipher>(x);
- throw Algorithm_Not_Found(algo_spec);
- }
-
-std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec,
- const std::string& provider)
- {
- if(auto x = get_hash_function(algo_spec, provider))
- return std::unique_ptr<HashFunction>(x);
- throw Algorithm_Not_Found(algo_spec);
- }
-
-std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec,
- const std::string& provider)
- {
- if(auto x = get_mac(algo_spec, provider))
- return std::unique_ptr<MessageAuthenticationCode>(x);
- throw Algorithm_Not_Found(algo_spec);
- }
-
-std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec)
- {
- return providers_of<BlockCipher>(BlockCipher::Spec(algo_spec));
- }
-
-std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec)
- {
- return providers_of<StreamCipher>(StreamCipher::Spec(algo_spec));
- }
-
-std::vector<std::string> get_hash_function_providers(const std::string& algo_spec)
- {
- return providers_of<HashFunction>(HashFunction::Spec(algo_spec));
- }
-
-std::vector<std::string> get_mac_providers(const std::string& algo_spec)
- {
- return providers_of<MessageAuthenticationCode>(MessageAuthenticationCode::Spec(algo_spec));
- }
-
-/*
-* Get a PBKDF algorithm by name
-*/
-PBKDF* get_pbkdf(const std::string& algo_spec, const std::string& provider)
- {
- if(PBKDF* pbkdf = make_a<PBKDF>(algo_spec, provider))
- return pbkdf;
- throw Algorithm_Not_Found(algo_spec);
- }
-
-}
diff --git a/src/lib/base/lookup.h b/src/lib/base/lookup.h
index d5b17237e..9595d1f06 100644
--- a/src/lib/base/lookup.h
+++ b/src/lib/base/lookup.h
@@ -8,19 +8,17 @@
#ifndef BOTAN_LOOKUP_H__
#define BOTAN_LOOKUP_H__
-#include <botan/types.h>
+#include <botan/block_cipher.h>
+#include <botan/stream_cipher.h>
+#include <botan/hash.h>
+#include <botan/mac.h>
+#include <botan/exceptn.h>
#include <string>
#include <vector>
#include <memory>
namespace Botan {
-class BlockCipher;
-class StreamCipher;
-class HashFunction;
-class MessageAuthenticationCode;
-class PBKDF;
-
/*
* Get an algorithm object
* NOTE: these functions create and return new objects, letting the
@@ -33,13 +31,25 @@ class PBKDF;
* @param algo_spec the name of the desired block cipher
* @return pointer to the block cipher object
*/
-BOTAN_DLL BlockCipher* get_block_cipher(const std::string& algo_spec,
- const std::string& provider = "");
+inline BlockCipher* get_block_cipher(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ return BlockCipher::create(algo_spec, provider).release();
+ }
-BOTAN_DLL std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec,
- const std::string& provider = "");
+inline std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ std::unique_ptr<BlockCipher> p(BlockCipher::create(algo_spec, provider));
+ if(p)
+ return p;
+ throw Algorithm_Not_Found(algo_spec);
+ }
-BOTAN_DLL std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec);
+inline std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec)
+ {
+ return BlockCipher::providers(algo_spec);
+ }
/**
* Stream cipher factory method.
@@ -47,13 +57,25 @@ BOTAN_DLL std::vector<std::string> get_block_cipher_providers(const std::string&
* @param algo_spec the name of the desired stream cipher
* @return pointer to the stream cipher object
*/
-BOTAN_DLL StreamCipher* get_stream_cipher(const std::string& algo_spec,
- const std::string& provider = "");
+inline StreamCipher* get_stream_cipher(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ return StreamCipher::create(algo_spec, provider).release();
+ }
-BOTAN_DLL std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec,
- const std::string& provider = "");
+inline std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ std::unique_ptr<StreamCipher> p(StreamCipher::create(algo_spec, provider));
+ if(p)
+ return p;
+ throw Algorithm_Not_Found(algo_spec);
+ }
-BOTAN_DLL std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec);
+inline std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec)
+ {
+ return StreamCipher::providers(algo_spec);
+ }
/**
* Hash function factory method.
@@ -61,11 +83,20 @@ BOTAN_DLL std::vector<std::string> get_stream_cipher_providers(const std::string
* @param algo_spec the name of the desired hash function
* @return pointer to the hash function object
*/
-BOTAN_DLL HashFunction* get_hash_function(const std::string& algo_spec,
- const std::string& provider = "");
+inline HashFunction* get_hash_function(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ return HashFunction::create(algo_spec, provider).release();
+ }
-BOTAN_DLL std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec,
- const std::string& provider = "");
+inline std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ std::unique_ptr<HashFunction> p(HashFunction::create(algo_spec, provider));
+ if(p)
+ return p;
+ throw Algorithm_Not_Found(algo_spec);
+ }
inline HashFunction* get_hash(const std::string& algo_spec,
const std::string& provider = "")
@@ -73,7 +104,10 @@ inline HashFunction* get_hash(const std::string& algo_spec,
return get_hash_function(algo_spec, provider);
}
-BOTAN_DLL std::vector<std::string> get_hash_function_providers(const std::string& algo_spec);
+inline std::vector<std::string> get_hash_function_providers(const std::string& algo_spec)
+ {
+ return HashFunction::providers(algo_spec);
+ }
/**
* MAC factory method.
@@ -81,21 +115,25 @@ BOTAN_DLL std::vector<std::string> get_hash_function_providers(const std::string
* @param algo_spec the name of the desired MAC
* @return pointer to the MAC object
*/
-BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string& algo_spec,
- const std::string& provider = "");
-
-BOTAN_DLL std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec,
- const std::string& provider = "");
+inline MessageAuthenticationCode* get_mac(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ return MessageAuthenticationCode::create(algo_spec, provider).release();
+ }
-BOTAN_DLL std::vector<std::string> get_mac_providers(const std::string& algo_spec);
+inline std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ std::unique_ptr<MessageAuthenticationCode> p(MessageAuthenticationCode::create(algo_spec, provider));
+ if(p)
+ return p;
+ throw Algorithm_Not_Found(algo_spec);
+ }
-/**
-* Password based key derivation function factory method
-* @param algo_spec the name of the desired PBKDF algorithm
-* @return pointer to newly allocated object of that type
-*/
-BOTAN_DLL PBKDF* get_pbkdf(const std::string& algo_spec,
- const std::string& provider = "");
+inline std::vector<std::string> get_mac_providers(const std::string& algo_spec)
+ {
+ return MessageAuthenticationCode::providers(algo_spec);
+ }
}
diff --git a/src/lib/base/symkey.cpp b/src/lib/base/symkey.cpp
index 88642747b..2c98da051 100644
--- a/src/lib/base/symkey.cpp
+++ b/src/lib/base/symkey.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/symkey.h>
-#include <botan/internal/xor_buf.h>
#include <botan/rng.h>
#include <botan/hex.h>
#include <algorithm>
diff --git a/src/lib/base/transform.cpp b/src/lib/base/transform.cpp
new file mode 100644
index 000000000..8f05a33ad
--- /dev/null
+++ b/src/lib/base/transform.cpp
@@ -0,0 +1,20 @@
+/*
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/internal/algo_registry.h>
+#include <botan/transform.h>
+
+namespace Botan {
+
+Transform* get_transform(const std::string& specstr,
+ const std::string& provider,
+ const std::string& dirstr)
+ {
+ Algo_Registry<Transform>::Spec spec(specstr, dirstr);
+ return Algo_Registry<Transform>::global_registry().make(spec, provider);
+ }
+
+}
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp
index b9e00fe6c..61cc9d777 100644
--- a/src/lib/block/aes/aes.cpp
+++ b/src/lib/block/aes/aes.cpp
@@ -7,15 +7,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/aes.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_128, "AES-128");
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_192, "AES-192");
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_256, "AES-256");
-
namespace {
const byte SE[256] = {
diff --git a/src/lib/block/aes_ni/aes_ni.cpp b/src/lib/block/aes_ni/aes_ni.cpp
index 29e729da4..d359ec772 100644
--- a/src/lib/block/aes_ni/aes_ni.cpp
+++ b/src/lib/block/aes_ni/aes_ni.cpp
@@ -5,17 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/aes_ni.h>
+#include <botan/loadstor.h>
#include <botan/cpuid.h>
#include <wmmintrin.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_128_NI, "AES-128", "aes_ni", 200);
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_192_NI, "AES-192", "aes_ni", 200);
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_256_NI, "AES-256", "aes_ni", 200);
-
namespace {
__m128i aes_128_key_expansion(__m128i key, __m128i key_with_rcon)
diff --git a/src/lib/block/aes_ssse3/aes_ssse3.cpp b/src/lib/block/aes_ssse3/aes_ssse3.cpp
index 50acd7668..bfc76ecee 100644
--- a/src/lib/block/aes_ssse3/aes_ssse3.cpp
+++ b/src/lib/block/aes_ssse3/aes_ssse3.cpp
@@ -10,20 +10,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/aes_ssse3.h>
#include <botan/cpuid.h>
#include <tmmintrin.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_128_SSSE3, "AES-128",
- "ssse3", BOTAN_SIMD_ALGORITHM_PRIO);
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_192_SSSE3, "AES-192",
- "ssse3", BOTAN_SIMD_ALGORITHM_PRIO);
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_256_SSSE3, "AES-256",
- "ssse3", BOTAN_SIMD_ALGORITHM_PRIO);
-
namespace {
const __m128i low_nibs = _mm_set1_epi8(0x0F);
diff --git a/src/lib/block/block_cipher.cpp b/src/lib/block/block_cipher.cpp
new file mode 100644
index 000000000..5b9c4f0ba
--- /dev/null
+++ b/src/lib/block/block_cipher.cpp
@@ -0,0 +1,319 @@
+/*
+* Block Ciphers
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/block_cipher.h>
+#include <botan/cpuid.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_SIMD_32)
+ #include <botan/internal/simd_32.h>
+#endif
+
+#if defined(BOTAN_HAS_AES)
+ #include <botan/aes.h>
+#endif
+
+#if defined(BOTAN_HAS_AES_SSSE3)
+ #include <botan/aes_ssse3.h>
+#endif
+
+#if defined(BOTAN_HAS_AES_NI)
+ #include <botan/aes_ni.h>
+#endif
+
+#if defined(BOTAN_HAS_BLOWFISH)
+ #include <botan/blowfish.h>
+#endif
+
+#if defined(BOTAN_HAS_CAMELLIA)
+ #include <botan/camellia.h>
+#endif
+
+#if defined(BOTAN_HAS_CAST)
+ #include <botan/cast128.h>
+ #include <botan/cast256.h>
+#endif
+
+#if defined(BOTAN_HAS_CASCADE)
+ #include <botan/cascade.h>
+#endif
+
+#if defined(BOTAN_HAS_DES)
+ #include <botan/des.h>
+ #include <botan/desx.h>
+#endif
+
+#if defined(BOTAN_HAS_GOST_28147_89)
+ #include <botan/gost_28147.h>
+#endif
+
+#if defined(BOTAN_HAS_IDEA)
+ #include <botan/idea.h>
+#endif
+
+#if defined(BOTAN_HAS_IDEA_SSE2)
+ #include <botan/idea_sse2.h>
+#endif
+
+#if defined(BOTAN_HAS_KASUMI)
+ #include <botan/kasumi.h>
+#endif
+
+#if defined(BOTAN_HAS_LION)
+ #include <botan/lion.h>
+#endif
+
+#if defined(BOTAN_HAS_LUBY_RACKOFF)
+ #include <botan/lubyrack.h>
+#endif
+
+#if defined(BOTAN_HAS_MARS)
+ #include <botan/mars.h>
+#endif
+
+#if defined(BOTAN_HAS_MISTY1)
+ #include <botan/misty1.h>
+#endif
+
+#if defined(BOTAN_HAS_NOEKEON)
+ #include <botan/noekeon.h>
+#endif
+
+#if defined(BOTAN_HAS_NOEKEON_SIMD)
+ #include <botan/noekeon_simd.h>
+#endif
+
+#if defined(BOTAN_HAS_RC2)
+ #include <botan/rc2.h>
+#endif
+
+#if defined(BOTAN_HAS_RC5)
+ #include <botan/rc5.h>
+#endif
+
+#if defined(BOTAN_HAS_RC6)
+ #include <botan/rc6.h>
+#endif
+
+#if defined(BOTAN_HAS_SAFER)
+ #include <botan/safer_sk.h>
+#endif
+
+#if defined(BOTAN_HAS_SEED)
+ #include <botan/seed.h>
+#endif
+
+#if defined(BOTAN_HAS_SERPENT)
+ #include <botan/serpent.h>
+#endif
+
+#if defined(BOTAN_HAS_SERPENT_SIMD)
+ #include <botan/serp_simd.h>
+#endif
+
+#if defined(BOTAN_HAS_SKIPJACK)
+ #include <botan/skipjack.h>
+#endif
+
+#if defined(BOTAN_HAS_SQUARE)
+ #include <botan/square.h>
+#endif
+
+#if defined(BOTAN_HAS_TEA)
+ #include <botan/tea.h>
+#endif
+
+#if defined(BOTAN_HAS_TWOFISH)
+ #include <botan/twofish.h>
+#endif
+
+#if defined(BOTAN_HAS_THREEFISH_512)
+ #include <botan/threefish.h>
+#endif
+
+#if defined(BOTAN_HAS_THREEFISH_512_AVX2)
+ #include <botan/threefish_avx2.h>
+#endif
+
+#if defined(BOTAN_HAS_XTEA)
+ #include <botan/xtea.h>
+#endif
+
+#if defined(BOTAN_HAS_XTEA_SIMD)
+ #include <botan/xtea_simd.h>
+#endif
+
+namespace Botan {
+
+BlockCipher::~BlockCipher() {}
+
+std::unique_ptr<BlockCipher> BlockCipher::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<BlockCipher>(make_a<BlockCipher>(algo_spec, provider));
+ }
+
+std::vector<std::string> BlockCipher::providers(const std::string& algo_spec)
+ {
+ return providers_of<BlockCipher>(BlockCipher::Spec(algo_spec));
+ }
+
+#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, pref) \
+ BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, BlockCipher, type, name, provider, pref)
+
+#if defined(BOTAN_HAS_AES)
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_128, "AES-128");
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_192, "AES-192");
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_256, "AES-256");
+#endif
+
+#if defined(BOTAN_HAS_AES_NI)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_128_NI, "AES-128", "aes_ni", 200);
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_192_NI, "AES-192", "aes_ni", 200);
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_256_NI, "AES-256", "aes_ni", 200);
+#endif
+
+#if defined(BOTAN_HAS_AES_SSSE3)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_128_SSSE3, "AES-128",
+ "ssse3", BOTAN_SIMD_ALGORITHM_PRIO);
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_192_SSSE3, "AES-192",
+ "ssse3", BOTAN_SIMD_ALGORITHM_PRIO);
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_256_SSSE3, "AES-256",
+ "ssse3", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_BLOWFISH)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Blowfish);
+#endif
+
+#if defined(BOTAN_HAS_CAMELLIA)
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_128, "Camellia-128");
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_192, "Camellia-192");
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_256, "Camellia-256");
+#endif
+
+#if defined(BOTAN_HAS_CAST)
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_128, "CAST-128");
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_256, "CAST-256");
+#endif
+
+#if defined(BOTAN_HAS_DES)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DES);
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TripleDES);
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DESX);
+#endif
+
+#if defined(BOTAN_HAS_GOST_28147_89)
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(GOST_28147_89, "GOST-28147-89", "R3411_94_TestParam");
+#endif
+
+#if defined(BOTAN_HAS_IDEA)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(IDEA);
+#endif
+
+#if defined(BOTAN_HAS_IDEA_SSE2)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_sse2(), IDEA_SSE2, "IDEA",
+ "sse2", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_KASUMI)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(KASUMI);
+#endif
+
+#if defined(BOTAN_HAS_MARS)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MARS);
+#endif
+
+#if defined(BOTAN_HAS_MISTY1)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MISTY1);
+#endif
+
+#if defined(BOTAN_HAS_NOEKEON)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Noekeon);
+#endif
+
+#if defined(BOTAN_HAS_NOEKEON_SIMD)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Noekeon_SIMD, "Noekeon",
+ "simd32", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_RC2)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC2);
+#endif
+
+#if defined(BOTAN_HAS_RC5)
+BOTAN_REGISTER_BLOCK_CIPHER_1LEN(RC5, 12);
+#endif
+
+#if defined(BOTAN_HAS_RC6)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC6);
+#endif
+
+#if defined(BOTAN_HAS_SAFER)
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(SAFER_SK, "SAFER-SK", 10);
+#endif
+
+#if defined(BOTAN_HAS_SEED)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(SEED);
+#endif
+
+#if defined(BOTAN_HAS_SERPENT)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Serpent);
+#endif
+
+#if defined(BOTAN_HAS_SERPENT_SIMD)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Serpent_SIMD, "Serpent",
+ "simd32", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_TEA)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TEA);
+#endif
+
+#if defined(BOTAN_HAS_TWOFISH)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Twofish);
+#endif
+
+#if defined(BOTAN_HAS_THREEFISH_512)
+BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Threefish_512, "Threefish-512");
+#endif
+
+#if defined(BOTAN_HAS_THREEFISH_512_AVX2)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_avx2(), Threefish_512_AVX2, "Threefish-512",
+ "avx2", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_XTEA)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(XTEA);
+#endif
+
+#if defined(BOTAN_HAS_XTEA_SIMD)
+BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), XTEA_SIMD, "XTEA",
+ "simd32", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_CASCADE)
+BOTAN_REGISTER_NAMED_T(BlockCipher, "Cascade", Cascade_Cipher, Cascade_Cipher::make);
+#endif
+
+#if defined(BOTAN_HAS_LION)
+BOTAN_REGISTER_NAMED_T(BlockCipher, "Lion", Lion, Lion::make);
+#endif
+
+}
diff --git a/src/lib/block/block_cipher.h b/src/lib/block/block_cipher.h
index 08bf18fd3..0f4c2c1c5 100644
--- a/src/lib/block/block_cipher.h
+++ b/src/lib/block/block_cipher.h
@@ -22,6 +22,19 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
typedef SCAN_Name Spec;
/**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<BlockCipher> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
+
+ /**
* @return block size of this algorithm
*/
virtual size_t block_size() const = 0;
@@ -141,6 +154,8 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
* @return new object representing the same algorithm as *this
*/
virtual BlockCipher* clone() const = 0;
+
+ virtual ~BlockCipher();
};
/**
diff --git a/src/lib/block/block_utils.h b/src/lib/block/block_utils.h
deleted file mode 100644
index 89f8a3dd3..000000000
--- a/src/lib/block/block_utils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-* Block Cipher Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_BLOCK_CIPHER_UTILS_H__
-#define BOTAN_BLOCK_CIPHER_UTILS_H__
-
-#include <botan/block_cipher.h>
-#include <botan/internal/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, pref) \
- BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, BlockCipher, type, name, provider, pref)
-
-}
-
-#endif
diff --git a/src/lib/block/blowfish/blowfish.cpp b/src/lib/block/blowfish/blowfish.cpp
index 63838929d..2488838c3 100644
--- a/src/lib/block/blowfish/blowfish.cpp
+++ b/src/lib/block/blowfish/blowfish.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/blowfish.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Blowfish);
-
/*
* Blowfish Encryption
*/
diff --git a/src/lib/block/camellia/camellia.cpp b/src/lib/block/camellia/camellia.cpp
index 887878910..dc57e26bc 100644
--- a/src/lib/block/camellia/camellia.cpp
+++ b/src/lib/block/camellia/camellia.cpp
@@ -5,16 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/camellia.h>
#include <botan/internal/camellia_sbox.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_128, "Camellia-128");
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_192, "Camellia-192");
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_256, "Camellia-256");
-
namespace Camellia_F {
namespace {
diff --git a/src/lib/block/cascade/cascade.cpp b/src/lib/block/cascade/cascade.cpp
index 3b59a4362..100fb33ab 100644
--- a/src/lib/block/cascade/cascade.cpp
+++ b/src/lib/block/cascade/cascade.cpp
@@ -5,17 +5,14 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/cascade.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(BlockCipher, "Cascade", Cascade_Cipher, Cascade_Cipher::make);
-
Cascade_Cipher* Cascade_Cipher::make(const BlockCipher::Spec& spec)
{
- std::unique_ptr<BlockCipher> c1(get_block_cipher(spec.arg(0)));
- std::unique_ptr<BlockCipher> c2(get_block_cipher(spec.arg(1)));
+ std::unique_ptr<BlockCipher> c1(BlockCipher::create(spec.arg(0)));
+ std::unique_ptr<BlockCipher> c2(BlockCipher::create(spec.arg(1)));
if(c1 && c2)
return new Cascade_Cipher(c1.release(), c2.release());
diff --git a/src/lib/block/cast/cast128.cpp b/src/lib/block/cast/cast128.cpp
index e19c6dcb1..3973418a3 100644
--- a/src/lib/block/cast/cast128.cpp
+++ b/src/lib/block/cast/cast128.cpp
@@ -5,14 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/cast128.h>
#include <botan/internal/cast_sboxes.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_128, "CAST-128");
-
namespace {
/*
diff --git a/src/lib/block/cast/cast256.cpp b/src/lib/block/cast/cast256.cpp
index bbb9894e7..7178dc5c1 100644
--- a/src/lib/block/cast/cast256.cpp
+++ b/src/lib/block/cast/cast256.cpp
@@ -5,14 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/cast256.h>
#include <botan/internal/cast_sboxes.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_256, "CAST-256");
-
namespace {
/*
diff --git a/src/lib/block/des/des.cpp b/src/lib/block/des/des.cpp
index c1013b9af..6d2bcfe1e 100644
--- a/src/lib/block/des/des.cpp
+++ b/src/lib/block/des/des.cpp
@@ -8,14 +8,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/des.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DES);
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TripleDES);
-
namespace {
/*
diff --git a/src/lib/block/des/desx.cpp b/src/lib/block/des/desx.cpp
index 0e19460fc..f6538748c 100644
--- a/src/lib/block/des/desx.cpp
+++ b/src/lib/block/des/desx.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/desx.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DESX);
-
/*
* DESX Encryption
*/
diff --git a/src/lib/block/gost_28147/gost_28147.cpp b/src/lib/block/gost_28147/gost_28147.cpp
index 90bf9328d..b8c3b7280 100644
--- a/src/lib/block/gost_28147/gost_28147.cpp
+++ b/src/lib/block/gost_28147/gost_28147.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/gost_28147.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(GOST_28147_89, "GOST-28147-89", "R3411_94_TestParam");
-
byte GOST_28147_89_Params::sbox_entry(size_t row, size_t col) const
{
byte x = sboxes[4 * col + (row / 2)];
diff --git a/src/lib/block/idea/idea.cpp b/src/lib/block/idea/idea.cpp
index 764115013..ddfd8e5fb 100644
--- a/src/lib/block/idea/idea.cpp
+++ b/src/lib/block/idea/idea.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/idea.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(IDEA);
-
namespace {
/*
diff --git a/src/lib/block/idea_sse2/idea_sse2.cpp b/src/lib/block/idea_sse2/idea_sse2.cpp
index 8549d74d7..a2a54ac32 100644
--- a/src/lib/block/idea_sse2/idea_sse2.cpp
+++ b/src/lib/block/idea_sse2/idea_sse2.cpp
@@ -5,16 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/idea_sse2.h>
#include <botan/cpuid.h>
#include <emmintrin.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_sse2(), IDEA_SSE2, "IDEA",
- "sse2", BOTAN_SIMD_ALGORITHM_PRIO);
-
namespace {
inline __m128i mul(__m128i X, u16bit K_16)
diff --git a/src/lib/block/info.txt b/src/lib/block/info.txt
index e1aa52d85..30f7392ef 100644
--- a/src/lib/block/info.txt
+++ b/src/lib/block/info.txt
@@ -3,7 +3,3 @@ define BLOCK_CIPHER 20131128
<header:public>
block_cipher.h
</header:public>
-
-<header:internal>
-block_utils.h
-</header:internal>
diff --git a/src/lib/block/kasumi/kasumi.cpp b/src/lib/block/kasumi/kasumi.cpp
index d0233cf5c..604d2d21a 100644
--- a/src/lib/block/kasumi/kasumi.cpp
+++ b/src/lib/block/kasumi/kasumi.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/kasumi.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(KASUMI);
-
namespace {
/*
diff --git a/src/lib/block/lion/lion.cpp b/src/lib/block/lion/lion.cpp
index a487e3eb0..559816aea 100644
--- a/src/lib/block/lion/lion.cpp
+++ b/src/lib/block/lion/lion.cpp
@@ -5,20 +5,17 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/lion.h>
#include <botan/parsing.h>
namespace Botan {
-namespace {
-
-Lion* make_lion(const BlockCipher::Spec& spec)
+Lion* Lion::make(const BlockCipher::Spec& spec)
{
if(spec.arg_count_between(2, 3))
{
- std::unique_ptr<HashFunction> hash(get_hash_function(spec.arg(0)));
- std::unique_ptr<StreamCipher> stream(get_stream_cipher(spec.arg(1)));
+ std::unique_ptr<HashFunction> hash(HashFunction::create(spec.arg(0)));
+ std::unique_ptr<StreamCipher> stream(StreamCipher::create(spec.arg(1)));
if(hash && stream)
{
@@ -29,10 +26,6 @@ Lion* make_lion(const BlockCipher::Spec& spec)
return nullptr;
}
-}
-
-BOTAN_REGISTER_NAMED_T(BlockCipher, "Lion", Lion, make_lion);
-
/*
* Lion Encryption
*/
diff --git a/src/lib/block/lion/lion.h b/src/lib/block/lion/lion.h
index d03d1d1a0..116fa911b 100644
--- a/src/lib/block/lion/lion.h
+++ b/src/lib/block/lion/lion.h
@@ -39,6 +39,8 @@ class BOTAN_DLL Lion : public BlockCipher
std::string name() const override;
BlockCipher* clone() const override;
+ static Lion* make(const Spec&);
+
/**
* @param hash the hash to use internally
* @param cipher the stream cipher to use internally
diff --git a/src/lib/block/mars/mars.cpp b/src/lib/block/mars/mars.cpp
index 50f264861..becbbf2db 100644
--- a/src/lib/block/mars/mars.cpp
+++ b/src/lib/block/mars/mars.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/mars.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MARS);
-
namespace {
/**
diff --git a/src/lib/block/misty1/misty1.cpp b/src/lib/block/misty1/misty1.cpp
index 23233e02f..490eec826 100644
--- a/src/lib/block/misty1/misty1.cpp
+++ b/src/lib/block/misty1/misty1.cpp
@@ -5,14 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/misty1.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MISTY1);
-
namespace {
static const byte MISTY1_SBOX_S7[128] = {
diff --git a/src/lib/block/noekeon/noekeon.cpp b/src/lib/block/noekeon/noekeon.cpp
index fb1a215fe..d63ec3129 100644
--- a/src/lib/block/noekeon/noekeon.cpp
+++ b/src/lib/block/noekeon/noekeon.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/noekeon.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Noekeon);
-
namespace {
/*
diff --git a/src/lib/block/noekeon_simd/noekeon_simd.cpp b/src/lib/block/noekeon_simd/noekeon_simd.cpp
index a51c6bc8f..07fcf19ff 100644
--- a/src/lib/block/noekeon_simd/noekeon_simd.cpp
+++ b/src/lib/block/noekeon_simd/noekeon_simd.cpp
@@ -5,15 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/noekeon_simd.h>
#include <botan/internal/simd_32.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Noekeon_SIMD, "Noekeon",
- "simd32", BOTAN_SIMD_ALGORITHM_PRIO);
-
/*
* Noekeon's Theta Operation
*/
diff --git a/src/lib/block/rc2/rc2.cpp b/src/lib/block/rc2/rc2.cpp
index d1fc8a2e6..bcd8475e3 100644
--- a/src/lib/block/rc2/rc2.cpp
+++ b/src/lib/block/rc2/rc2.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/rc2.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC2);
-
/*
* RC2 Encryption
*/
diff --git a/src/lib/block/rc5/rc5.cpp b/src/lib/block/rc5/rc5.cpp
index 27fa0e14d..a32efd775 100644
--- a/src/lib/block/rc5/rc5.cpp
+++ b/src/lib/block/rc5/rc5.cpp
@@ -5,14 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/rc5.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_1LEN(RC5, 12);
-
/*
* RC5 Encryption
*/
diff --git a/src/lib/block/rc6/rc6.cpp b/src/lib/block/rc6/rc6.cpp
index e9aa5fe8b..48fb1c32e 100644
--- a/src/lib/block/rc6/rc6.cpp
+++ b/src/lib/block/rc6/rc6.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/rc6.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC6);
-
/*
* RC6 Encryption
*/
diff --git a/src/lib/block/safer/safer_sk.cpp b/src/lib/block/safer/safer_sk.cpp
index f5996a986..a8781697d 100644
--- a/src/lib/block/safer/safer_sk.cpp
+++ b/src/lib/block/safer/safer_sk.cpp
@@ -5,16 +5,14 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/safer_sk.h>
+#include <botan/rotate.h>
#include <botan/parsing.h>
namespace Botan {
namespace {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(SAFER_SK, "SAFER-SK", 10);
-
const byte EXP[256] = {
0x01, 0x2D, 0xE2, 0x93, 0xBE, 0x45, 0x15, 0xAE, 0x78, 0x03, 0x87, 0xA4,
0xB8, 0x38, 0xCF, 0x3F, 0x08, 0x67, 0x09, 0x94, 0xEB, 0x26, 0xA8, 0x6B,
diff --git a/src/lib/block/seed/seed.cpp b/src/lib/block/seed/seed.cpp
index 316ef1e04..833f9943f 100644
--- a/src/lib/block/seed/seed.cpp
+++ b/src/lib/block/seed/seed.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/seed.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(SEED);
-
/*
* SEED G Function
*/
diff --git a/src/lib/block/serpent/serpent.cpp b/src/lib/block/serpent/serpent.cpp
index b809e602c..c0a65ed33 100644
--- a/src/lib/block/serpent/serpent.cpp
+++ b/src/lib/block/serpent/serpent.cpp
@@ -5,14 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/serpent.h>
+#include <botan/loadstor.h>
#include <botan/internal/serpent_sbox.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Serpent);
-
namespace {
/*
diff --git a/src/lib/block/serpent_simd/serp_simd.cpp b/src/lib/block/serpent_simd/serp_simd.cpp
index 56747dd16..02fe7d6d9 100644
--- a/src/lib/block/serpent_simd/serp_simd.cpp
+++ b/src/lib/block/serpent_simd/serp_simd.cpp
@@ -5,16 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/serp_simd.h>
#include <botan/internal/serpent_sbox.h>
#include <botan/internal/simd_32.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Serpent_SIMD, "Serpent",
- "simd32", BOTAN_SIMD_ALGORITHM_PRIO);
-
namespace {
#define key_xor(round, B0, B1, B2, B3) \
diff --git a/src/lib/block/tea/tea.cpp b/src/lib/block/tea/tea.cpp
index ef630f715..01f342607 100644
--- a/src/lib/block/tea/tea.cpp
+++ b/src/lib/block/tea/tea.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/tea.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TEA);
-
/*
* TEA Encryption
*/
diff --git a/src/lib/block/threefish/threefish.cpp b/src/lib/block/threefish/threefish.cpp
index 322f54881..93fd122c2 100644
--- a/src/lib/block/threefish/threefish.cpp
+++ b/src/lib/block/threefish/threefish.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/threefish.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Threefish_512, "Threefish-512");
-
#define THREEFISH_ROUND(X0,X1,X2,X3,X4,X5,X6,X7,ROT1,ROT2,ROT3,ROT4) \
do { \
X0 += X4; \
diff --git a/src/lib/block/threefish_avx2/threefish_avx2.cpp b/src/lib/block/threefish_avx2/threefish_avx2.cpp
index 435c75dbf..bed98fafa 100644
--- a/src/lib/block/threefish_avx2/threefish_avx2.cpp
+++ b/src/lib/block/threefish_avx2/threefish_avx2.cpp
@@ -5,16 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/threefish_avx2.h>
#include <botan/cpuid.h>
#include <immintrin.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_avx2(), Threefish_512_AVX2, "Threefish-512",
- "avx2", BOTAN_SIMD_ALGORITHM_PRIO);
-
namespace {
inline void interleave_epi64(__m256i& X0, __m256i& X1)
diff --git a/src/lib/block/twofish/twofish.cpp b/src/lib/block/twofish/twofish.cpp
index 43ea41bfd..ffdf4b198 100644
--- a/src/lib/block/twofish/twofish.cpp
+++ b/src/lib/block/twofish/twofish.cpp
@@ -8,13 +8,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/twofish.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Twofish);
-
/*
* Twofish Encryption
*/
diff --git a/src/lib/block/xtea/xtea.cpp b/src/lib/block/xtea/xtea.cpp
index 9fe265457..59060dff7 100644
--- a/src/lib/block/xtea/xtea.cpp
+++ b/src/lib/block/xtea/xtea.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/xtea.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(XTEA);
-
namespace {
void xtea_encrypt_4(const byte in[32], byte out[32], const u32bit EK[64])
diff --git a/src/lib/block/xtea_simd/xtea_simd.cpp b/src/lib/block/xtea_simd/xtea_simd.cpp
index a9984ce23..6e50f4ff7 100644
--- a/src/lib/block/xtea_simd/xtea_simd.cpp
+++ b/src/lib/block/xtea_simd/xtea_simd.cpp
@@ -5,15 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
#include <botan/xtea_simd.h>
#include <botan/internal/simd_32.h>
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), XTEA_SIMD, "XTEA",
- "simd32", BOTAN_SIMD_ALGORITHM_PRIO);
-
namespace {
void xtea_encrypt_8(const byte in[64], byte out[64], const u32bit EK[64])
diff --git a/src/lib/cert/x509/ocsp_types.cpp b/src/lib/cert/x509/ocsp_types.cpp
index 0877f848d..04ab1ea03 100644
--- a/src/lib/cert/x509/ocsp_types.cpp
+++ b/src/lib/cert/x509/ocsp_types.cpp
@@ -9,7 +9,6 @@
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/x509_ext.h>
-#include <botan/lookup.h>
#include <botan/hash.h>
#include <botan/oids.h>
@@ -24,7 +23,7 @@ CertID::CertID(const X509_Certificate& issuer,
In practice it seems some responders, including, notably,
ocsp.verisign.com, will reject anything but SHA-1 here
*/
- std::unique_ptr<HashFunction> hash(get_hash("SHA-160"));
+ std::unique_ptr<HashFunction> hash(HashFunction::create("SHA-160"));
m_hash_id = AlgorithmIdentifier(hash->name(), AlgorithmIdentifier::USE_NULL_PARAM);
m_issuer_key_hash = unlock(hash->process(extract_key_bitstr(issuer)));
@@ -54,7 +53,7 @@ bool CertID::is_id_for(const X509_Certificate& issuer,
if(BigInt::decode(subject.serial_number()) != m_subject_serial)
return false;
- std::unique_ptr<HashFunction> hash(get_hash(OIDS::lookup(m_hash_id.oid)));
+ std::unique_ptr<HashFunction> hash(HashFunction::create(OIDS::lookup(m_hash_id.oid)));
if(m_issuer_dn_hash != unlock(hash->process(subject.raw_issuer_dn())))
return false;
diff --git a/src/lib/cert/x509/x509_ca.cpp b/src/lib/cert/x509/x509_ca.cpp
index e6f689016..b6bb5d8ce 100644
--- a/src/lib/cert/x509/x509_ca.cpp
+++ b/src/lib/cert/x509/x509_ca.cpp
@@ -11,7 +11,6 @@
#include <botan/ber_dec.h>
#include <botan/bigint.h>
#include <botan/parsing.h>
-#include <botan/lookup.h>
#include <botan/oids.h>
#include <botan/hash.h>
#include <botan/key_constraint.h>
@@ -102,6 +101,7 @@ X509_Certificate X509_CA::make_cert(PK_Signer* signer,
BigInt serial_no(rng, SERIAL_BITS);
+ // clang-format off
return X509_Certificate(X509_Object::make_signed(
signer, rng, sig_algo,
DER_Encoder().start_cons(SEQUENCE)
@@ -130,6 +130,7 @@ X509_Certificate X509_CA::make_cert(PK_Signer* signer,
.end_cons()
.get_contents()
));;
+ // clang-format on
}
/*
@@ -179,6 +180,7 @@ X509_CRL X509_CA::make_crl(const std::vector<CRL_Entry>& revoked,
new Cert_Extension::Authority_Key_ID(cert.subject_key_id()));
extensions.add(new Cert_Extension::CRL_Number(crl_number));
+ // clang-format off
const std::vector<byte> crl = X509_Object::make_signed(
signer, rng, ca_sig_algo,
DER_Encoder().start_cons(SEQUENCE)
@@ -200,6 +202,7 @@ X509_CRL X509_CA::make_crl(const std::vector<CRL_Entry>& revoked,
.end_explicit()
.end_cons()
.get_contents());
+ // clang-format on
return X509_CRL(crl);
}
@@ -221,7 +224,7 @@ PK_Signer* choose_sig_format(const Private_Key& key,
{
const std::string algo_name = key.algo_name();
- std::unique_ptr<HashFunction> hash(get_hash(hash_fn));
+ std::unique_ptr<HashFunction> hash(HashFunction::create(hash_fn));
if(!hash)
throw Algorithm_Not_Found(hash_fn);
diff --git a/src/lib/cert/x509/x509cert.cpp b/src/lib/cert/x509/x509cert.cpp
index f6f87bbf4..48e437352 100644
--- a/src/lib/cert/x509/x509cert.cpp
+++ b/src/lib/cert/x509/x509cert.cpp
@@ -12,7 +12,6 @@
#include <botan/internal/stl_util.h>
#include <botan/parsing.h>
#include <botan/bigint.h>
-#include <botan/lookup.h>
#include <botan/oids.h>
#include <botan/pem.h>
#include <botan/hash.h>
@@ -369,7 +368,7 @@ bool cert_subject_dns_match(const std::string& name,
std::string X509_Certificate::fingerprint(const std::string& hash_name) const
{
- std::unique_ptr<HashFunction> hash(get_hash(hash_name));
+ std::unique_ptr<HashFunction> hash(HashFunction::create(hash_name));
hash->update(this->BER_encode());
const auto hex_print = hex_encode(hash->final());
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index 625b1947b..606415575 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -7,7 +7,6 @@
#include <botan/ffi.h>
#include <botan/system_rng.h>
#include <botan/auto_rng.h>
-#include <botan/lookup.h>
#include <botan/aead.h>
#include <botan/hash.h>
#include <botan/mac.h>
@@ -277,9 +276,10 @@ int botan_hash_init(botan_hash_t* hash, const char* hash_name, uint32_t flags)
if(flags != 0)
return BOTAN_FFI_ERROR_BAD_FLAG;
- if(auto h = Botan::get_hash_function(hash_name))
+ auto h = Botan::HashFunction::create(hash_name);
+ if(h)
{
- *hash = new botan_hash_struct(h);
+ *hash = new botan_hash_struct(h.release());
return 0;
}
}
@@ -328,9 +328,10 @@ int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags)
if(!mac || !mac_name || flags != 0)
return -1;
- if(auto m = Botan::get_mac(mac_name))
+ auto m = Botan::MessageAuthenticationCode::create(mac_name);
+ if(m)
{
- *mac = new botan_mac_struct(m);
+ *mac = new botan_mac_struct(m.release());
return 0;
}
}
@@ -898,7 +899,7 @@ int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash_fn,
uint8_t out[], size_t* out_len)
{
return BOTAN_FFI_DO(Botan::Public_Key, key, {
- std::unique_ptr<Botan::HashFunction> h(Botan::get_hash(hash_fn));
+ std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn));
return write_vec_output(out, out_len, h->process(key.x509_subject_public_key()));
});
}
diff --git a/src/lib/filters/algo_filt.cpp b/src/lib/filters/algo_filt.cpp
index 6ec8cdd1d..bfadef924 100644
--- a/src/lib/filters/algo_filt.cpp
+++ b/src/lib/filters/algo_filt.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/filters.h>
-#include <botan/lookup.h>
#include <algorithm>
namespace Botan {
@@ -26,14 +25,18 @@ StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher, const SymmetricKe
StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name) :
m_buffer(DEFAULT_BUFFERSIZE),
- m_cipher(make_stream_cipher(sc_name))
+ m_cipher(StreamCipher::create(sc_name))
{
+ if(!m_cipher)
+ throw Algorithm_Not_Found(sc_name);
}
StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name, const SymmetricKey& key) :
m_buffer(DEFAULT_BUFFERSIZE),
- m_cipher(make_stream_cipher(sc_name))
+ m_cipher(StreamCipher::create(sc_name))
{
+ if(!m_cipher)
+ throw Algorithm_Not_Found(sc_name);
m_cipher->set_key(key);
}
@@ -50,13 +53,13 @@ void StreamCipher_Filter::write(const byte input[], size_t length)
}
Hash_Filter::Hash_Filter(const std::string& hash_name, size_t len) :
- m_hash(make_hash_function(hash_name)),
+ m_hash(HashFunction::create(hash_name)),
m_out_len(len)
{
+ if(!m_hash)
+ throw Algorithm_Not_Found(hash_name);
}
-
-void Hash_Filter::end_msg()
- {
+void Hash_Filter::end_msg() {
secure_vector<byte> output = m_hash->final();
if(m_out_len)
send(output, std::min<size_t>(m_out_len, output.size()));
@@ -65,15 +68,19 @@ void Hash_Filter::end_msg()
}
MAC_Filter::MAC_Filter(const std::string& mac_name, size_t len) :
- m_mac(make_message_auth(mac_name)),
+ m_mac(MessageAuthenticationCode::create(mac_name)),
m_out_len(len)
{
+ if(!m_mac)
+ throw Algorithm_Not_Found(mac_name);
}
MAC_Filter::MAC_Filter(const std::string& mac_name, const SymmetricKey& key, size_t len) :
- m_mac(make_message_auth(mac_name)),
+ m_mac(MessageAuthenticationCode::create(mac_name)),
m_out_len(len)
{
+ if(!m_mac)
+ throw Algorithm_Not_Found(mac_name);
m_mac->set_key(key);
}
diff --git a/src/lib/hash/checksum/adler32/adler32.cpp b/src/lib/hash/checksum/adler32/adler32.cpp
index f2385c5b8..f368b627c 100644
--- a/src/lib/hash/checksum/adler32/adler32.cpp
+++ b/src/lib/hash/checksum/adler32/adler32.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/adler32.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(Adler32);
-
namespace {
void adler32_update(const byte input[], size_t length,
diff --git a/src/lib/hash/checksum/crc24/crc24.cpp b/src/lib/hash/checksum/crc24/crc24.cpp
index 4f747c232..1484f643d 100644
--- a/src/lib/hash/checksum/crc24/crc24.cpp
+++ b/src/lib/hash/checksum/crc24/crc24.cpp
@@ -5,14 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/crc24.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(CRC24);
-
/*
* Update a CRC24 Checksum
*/
diff --git a/src/lib/hash/checksum/crc32/crc32.cpp b/src/lib/hash/checksum/crc32/crc32.cpp
index cb4ff7b5f..10d989cc6 100644
--- a/src/lib/hash/checksum/crc32/crc32.cpp
+++ b/src/lib/hash/checksum/crc32/crc32.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/crc32.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(CRC32);
-
/*
* Update a CRC32 Checksum
*/
diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp
index 843c530ef..4222eaf54 100644
--- a/src/lib/hash/comb4p/comb4p.cpp
+++ b/src/lib/hash/comb4p/comb4p.cpp
@@ -5,15 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/comb4p.h>
-#include <botan/internal/xor_buf.h>
#include <stdexcept>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(HashFunction, "Comb4P", Comb4P, Comb4P::make);
-
namespace {
void comb4p_round(secure_vector<byte>& out,
@@ -41,8 +37,8 @@ Comb4P* Comb4P::make(const Spec& spec)
{
if(spec.arg_count() == 2)
{
- std::unique_ptr<HashFunction> h1(make_hash_function(spec.arg(0)));
- std::unique_ptr<HashFunction> h2(make_hash_function(spec.arg(1)));
+ std::unique_ptr<HashFunction> h1(HashFunction::create(spec.arg(0)));
+ std::unique_ptr<HashFunction> h2(HashFunction::create(spec.arg(1)));
if(h1 && h2)
return new Comb4P(h1.release(), h2.release());
diff --git a/src/lib/hash/gost_3411/gost_3411.cpp b/src/lib/hash/gost_3411/gost_3411.cpp
index 918556ca0..f8c9c0069 100644
--- a/src/lib/hash/gost_3411/gost_3411.cpp
+++ b/src/lib/hash/gost_3411/gost_3411.cpp
@@ -5,14 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/gost_3411.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(GOST_34_11, "GOST-R-34.11-94");
-
/**
* GOST 34.11 Constructor
*/
diff --git a/src/lib/hash/has160/has160.cpp b/src/lib/hash/has160/has160.cpp
index 2f2a5f9de..6b12e10ad 100644
--- a/src/lib/hash/has160/has160.cpp
+++ b/src/lib/hash/has160/has160.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/has160.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(HAS_160, "HAS-160");
-
namespace HAS_160_F {
/*
diff --git a/src/lib/hash/hash.cpp b/src/lib/hash/hash.cpp
new file mode 100644
index 000000000..fe210705e
--- /dev/null
+++ b/src/lib/hash/hash.cpp
@@ -0,0 +1,206 @@
+/*
+* Hash Functions
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/hash.h>
+#include <botan/cpuid.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_ADLER32)
+ #include <botan/adler32.h>
+#endif
+
+#if defined(BOTAN_HAS_CRC24)
+ #include <botan/crc24.h>
+#endif
+
+#if defined(BOTAN_HAS_CRC32)
+ #include <botan/crc32.h>
+#endif
+
+#if defined(BOTAN_HAS_GOST_34_11)
+ #include <botan/gost_3411.h>
+#endif
+
+#if defined(BOTAN_HAS_HAS_160)
+ #include <botan/has160.h>
+#endif
+
+#if defined(BOTAN_HAS_KECCAK)
+ #include <botan/keccak.h>
+#endif
+
+#if defined(BOTAN_HAS_MD2)
+ #include <botan/md2.h>
+#endif
+
+#if defined(BOTAN_HAS_MD4)
+ #include <botan/md4.h>
+#endif
+
+#if defined(BOTAN_HAS_MD5)
+ #include <botan/md5.h>
+#endif
+
+#if defined(BOTAN_HAS_RIPEMD_128)
+ #include <botan/rmd128.h>
+#endif
+
+#if defined(BOTAN_HAS_RIPEMD_160)
+ #include <botan/rmd160.h>
+#endif
+
+#if defined(BOTAN_HAS_SHA1)
+ #include <botan/sha160.h>
+#endif
+
+#if defined(BOTAN_HAS_SHA1_SSE2)
+ #include <botan/sha1_sse2.h>
+#endif
+
+#if defined(BOTAN_HAS_SHA2_32)
+ #include <botan/sha2_32.h>
+#endif
+
+#if defined(BOTAN_HAS_SHA2_64)
+ #include <botan/sha2_64.h>
+#endif
+
+#if defined(BOTAN_HAS_SKEIN_512)
+ #include <botan/skein_512.h>
+#endif
+
+#if defined(BOTAN_HAS_TIGER)
+ #include <botan/tiger.h>
+#endif
+
+#if defined(BOTAN_HAS_WHIRLPOOL)
+ #include <botan/whrlpool.h>
+#endif
+
+#if defined(BOTAN_HAS_PARALLEL_HASH)
+ #include <botan/par_hash.h>
+#endif
+
+#if defined(BOTAN_HAS_COMB4P)
+ #include <botan/comb4p.h>
+#endif
+
+namespace Botan {
+
+std::unique_ptr<HashFunction> HashFunction::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<HashFunction>(make_a<HashFunction>(algo_spec, provider));
+ }
+
+std::vector<std::string> HashFunction::providers(const std::string& algo_spec)
+ {
+ return providers_of<HashFunction>(HashFunction::Spec(algo_spec));
+ }
+
+HashFunction::HashFunction() {}
+
+HashFunction::~HashFunction() {}
+
+#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, pref) \
+ BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, HashFunction, type, name, provider, pref)
+
+#if defined(BOTAN_HAS_ADLER32)
+BOTAN_REGISTER_HASH_NOARGS(Adler32);
+#endif
+
+#if defined(BOTAN_HAS_CRC24)
+BOTAN_REGISTER_HASH_NOARGS(CRC24);
+#endif
+
+#if defined(BOTAN_HAS_CRC32)
+BOTAN_REGISTER_HASH_NOARGS(CRC32);
+#endif
+
+#if defined(BOTAN_HAS_COMB4P)
+BOTAN_REGISTER_NAMED_T(HashFunction, "Comb4P", Comb4P, Comb4P::make);
+#endif
+
+#if defined(BOTAN_HAS_PARALLEL_HASH)
+BOTAN_REGISTER_NAMED_T(HashFunction, "Parallel", Parallel, Parallel::make);
+#endif
+
+#if defined(BOTAN_HAS_GOST_34_11)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(GOST_34_11, "GOST-R-34.11-94");
+#endif
+
+#if defined(BOTAN_HAS_HAS_160)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(HAS_160, "HAS-160");
+#endif
+
+#if defined(BOTAN_HAS_KECCAK)
+BOTAN_REGISTER_HASH_NAMED_1LEN(Keccak_1600, "Keccak-1600", 512);
+#endif
+
+#if defined(BOTAN_HAS_MD2)
+BOTAN_REGISTER_HASH_NOARGS(MD2);
+#endif
+
+#if defined(BOTAN_HAS_MD4)
+BOTAN_REGISTER_HASH_NOARGS(MD4);
+#endif
+
+#if defined(BOTAN_HAS_MD5)
+BOTAN_REGISTER_HASH_NOARGS(MD5);
+#endif
+
+#if defined(BOTAN_HAS_RIPEMD_128)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(RIPEMD_128, "RIPEMD-128");
+#endif
+
+#if defined(BOTAN_HAS_RIPEMD_160)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(RIPEMD_160, "RIPEMD-160");
+#endif
+
+#if defined(BOTAN_HAS_SHA1)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_160, "SHA-160");
+#endif
+
+#if defined(BOTAN_HAS_SHA1_SSE2)
+BOTAN_REGISTER_HASH_NOARGS_IF(CPUID::has_sse2(), SHA_160_SSE2, "SHA-160",
+ "sse2", BOTAN_SIMD_ALGORITHM_PRIO);
+#endif
+
+#if defined(BOTAN_HAS_SHA2_32)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_224, "SHA-224");
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_256, "SHA-256");
+#endif
+
+#if defined(BOTAN_HAS_SHA2_64)
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_384, "SHA-384");
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_512, "SHA-512");
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_512_256, "SHA-512-256");
+#endif
+
+#if defined(BOTAN_HAS_TIGER)
+BOTAN_REGISTER_NAMED_T_2LEN(HashFunction, Tiger, "Tiger", "base", 24, 3);
+#endif
+
+#if defined(BOTAN_HAS_SKEIN_512)
+BOTAN_REGISTER_NAMED_T(HashFunction, "Skein-512", Skein_512, Skein_512::make);
+#endif
+
+#if defined(BOTAN_HAS_WHIRLPOOL)
+BOTAN_REGISTER_HASH_NOARGS(Whirlpool);
+#endif
+
+}
diff --git a/src/lib/hash/hash.h b/src/lib/hash/hash.h
index 9b2ca0d3b..ac1c22a65 100644
--- a/src/lib/hash/hash.h
+++ b/src/lib/hash/hash.h
@@ -20,11 +20,30 @@ namespace Botan {
class BOTAN_DLL HashFunction : public Buffered_Computation
{
public:
+ typedef SCAN_Name Spec;
+
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<HashFunction> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
+
/**
* @return new object representing the same algorithm as *this
*/
virtual HashFunction* clone() const = 0;
+ HashFunction();
+
+ virtual ~HashFunction();
+
virtual void clear() = 0;
virtual std::string name() const = 0;
@@ -33,8 +52,6 @@ class BOTAN_DLL HashFunction : public Buffered_Computation
* @return hash block size as defined for this algorithm
*/
virtual size_t hash_block_size() const { return 0; }
-
- typedef SCAN_Name Spec;
};
}
diff --git a/src/lib/hash/hash_utils.h b/src/lib/hash/hash_utils.h
deleted file mode 100644
index 3286b0087..000000000
--- a/src/lib/hash/hash_utils.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-* Hash Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_HASH_UTILS_H__
-#define BOTAN_HASH_UTILS_H__
-
-#include <botan/hash.h>
-#include <botan/internal/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, pref) \
- BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, HashFunction, type, name, provider, pref)
-
-}
-
-#endif
diff --git a/src/lib/hash/info.txt b/src/lib/hash/info.txt
index 481b39b67..e71318b73 100644
--- a/src/lib/hash/info.txt
+++ b/src/lib/hash/info.txt
@@ -1,7 +1,3 @@
-<header:internal>
-hash_utils.h
-</header:internal>
-
<header:public>
hash.h
</header:public>
diff --git a/src/lib/hash/keccak/keccak.cpp b/src/lib/hash/keccak/keccak.cpp
index 8ee2357b6..39d0c822b 100644
--- a/src/lib/hash/keccak/keccak.cpp
+++ b/src/lib/hash/keccak/keccak.cpp
@@ -5,16 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/keccak.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_1LEN(Keccak_1600, "Keccak-1600", 512);
-
namespace {
void keccak_f_1600(u64bit A[25])
diff --git a/src/lib/hash/md2/md2.cpp b/src/lib/hash/md2/md2.cpp
index 6543cf1a0..8fe016962 100644
--- a/src/lib/hash/md2/md2.cpp
+++ b/src/lib/hash/md2/md2.cpp
@@ -5,14 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/md2.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(MD2);
-
/**
* MD2 Compression Function
*/
diff --git a/src/lib/hash/md4/md4.cpp b/src/lib/hash/md4/md4.cpp
index cc11baafa..6f4503ac0 100644
--- a/src/lib/hash/md4/md4.cpp
+++ b/src/lib/hash/md4/md4.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/md4.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(MD4);
-
namespace {
/*
diff --git a/src/lib/hash/md5/md5.cpp b/src/lib/hash/md5/md5.cpp
index 2ce8df48a..89ca52419 100644
--- a/src/lib/hash/md5/md5.cpp
+++ b/src/lib/hash/md5/md5.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/md5.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(MD5);
-
namespace {
/*
diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp
index b6133929c..5e970ab13 100644
--- a/src/lib/hash/par_hash/par_hash.cpp
+++ b/src/lib/hash/par_hash/par_hash.cpp
@@ -5,21 +5,18 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/par_hash.h>
#include <botan/parsing.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(HashFunction, "Parallel", Parallel, Parallel::make);
-
Parallel* Parallel::make(const Spec& spec)
{
std::vector<std::unique_ptr<HashFunction>> hashes;
for(size_t i = 0; i != spec.arg_count(); ++i)
{
- std::unique_ptr<HashFunction> h(get_hash_function(spec.arg(i)));
+ auto h = HashFunction::create(spec.arg(i));
if(!h)
return nullptr;
hashes.push_back(std::move(h));
diff --git a/src/lib/hash/rmd128/rmd128.cpp b/src/lib/hash/rmd128/rmd128.cpp
index 7138d54d7..394bf2acf 100644
--- a/src/lib/hash/rmd128/rmd128.cpp
+++ b/src/lib/hash/rmd128/rmd128.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/rmd128.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(RIPEMD_128, "RIPEMD-128");
-
namespace RIPEMD_128_F {
/*
diff --git a/src/lib/hash/rmd160/rmd160.cpp b/src/lib/hash/rmd160/rmd160.cpp
index dad1d367a..56d063338 100644
--- a/src/lib/hash/rmd160/rmd160.cpp
+++ b/src/lib/hash/rmd160/rmd160.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/rmd160.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(RIPEMD_160, "RIPEMD-160");
-
namespace {
/*
diff --git a/src/lib/hash/sha1/sha160.cpp b/src/lib/hash/sha1/sha160.cpp
index 96bc2c682..39d14f486 100644
--- a/src/lib/hash/sha1/sha160.cpp
+++ b/src/lib/hash/sha1/sha160.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/sha160.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_160, "SHA-160");
-
namespace SHA1_F {
namespace {
diff --git a/src/lib/hash/sha1_sse2/sha1_sse2.cpp b/src/lib/hash/sha1_sse2/sha1_sse2.cpp
index 7cd457597..2e0688185 100644
--- a/src/lib/hash/sha1_sse2/sha1_sse2.cpp
+++ b/src/lib/hash/sha1_sse2/sha1_sse2.cpp
@@ -7,16 +7,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/sha1_sse2.h>
#include <botan/cpuid.h>
#include <emmintrin.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS_IF(CPUID::has_sse2(), SHA_160_SSE2, "SHA-160",
- "sse2", BOTAN_SIMD_ALGORITHM_PRIO);
-
namespace SHA1_SSE2_F {
namespace {
diff --git a/src/lib/hash/sha2_32/sha2_32.cpp b/src/lib/hash/sha2_32/sha2_32.cpp
index b06d485aa..5215164cf 100644
--- a/src/lib/hash/sha2_32/sha2_32.cpp
+++ b/src/lib/hash/sha2_32/sha2_32.cpp
@@ -6,14 +6,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/sha2_32.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_224, "SHA-224");
-BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_256, "SHA-256");
-
namespace {
namespace SHA2_32 {
diff --git a/src/lib/hash/sha2_64/sha2_64.cpp b/src/lib/hash/sha2_64/sha2_64.cpp
index 733cf0f19..d7c3f1325 100644
--- a/src/lib/hash/sha2_64/sha2_64.cpp
+++ b/src/lib/hash/sha2_64/sha2_64.cpp
@@ -5,15 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/sha2_64.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_384, "SHA-384");
-BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_512, "SHA-512");
-BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_512_256, "SHA-512-256");
-
namespace {
namespace SHA2_64 {
diff --git a/src/lib/hash/skein/skein_512.cpp b/src/lib/hash/skein/skein_512.cpp
index 5e186b996..fe95dd7a5 100644
--- a/src/lib/hash/skein/skein_512.cpp
+++ b/src/lib/hash/skein/skein_512.cpp
@@ -5,17 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/skein_512.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
-#include <botan/internal/xor_buf.h>
#include <algorithm>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(HashFunction, "Skein-512", Skein_512, Skein_512::make);
-
Skein_512* Skein_512::make(const Spec& spec)
{
return new Skein_512(spec.arg_as_integer(0, 512), spec.arg(1, ""));
diff --git a/src/lib/hash/tiger/tiger.cpp b/src/lib/hash/tiger/tiger.cpp
index c6dec2f33..79708a902 100644
--- a/src/lib/hash/tiger/tiger.cpp
+++ b/src/lib/hash/tiger/tiger.cpp
@@ -5,15 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/tiger.h>
#include <botan/exceptn.h>
#include <botan/parsing.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T_2LEN(HashFunction, Tiger, "Tiger", "base", 24, 3);
-
namespace {
/*
diff --git a/src/lib/hash/whirlpool/whirlpool.cpp b/src/lib/hash/whirlpool/whirlpool.cpp
index 573c49f91..9bebdfa7c 100644
--- a/src/lib/hash/whirlpool/whirlpool.cpp
+++ b/src/lib/hash/whirlpool/whirlpool.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
#include <botan/whrlpool.h>
namespace Botan {
-BOTAN_REGISTER_HASH_NOARGS(Whirlpool);
-
/*
* Whirlpool Compression Function
*/
diff --git a/src/lib/kdf/hkdf/hkdf.cpp b/src/lib/kdf/hkdf/hkdf.cpp
index b643db6d9..6f83853f9 100644
--- a/src/lib/kdf/hkdf/hkdf.cpp
+++ b/src/lib/kdf/hkdf/hkdf.cpp
@@ -5,20 +5,17 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/hkdf.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(KDF, "HKDF", HKDF, HKDF::make);
-
HKDF* HKDF::make(const Spec& spec)
{
- if(auto mac = get_mac(spec.arg(0)))
- return new HKDF(mac);
+ if(auto mac = MessageAuthenticationCode::create(spec.arg(0)))
+ return new HKDF(mac.release());
- if(auto mac = get_mac("HMAC(" + spec.arg(0) + ")"))
- return new HKDF(mac);
+ if(auto mac = MessageAuthenticationCode::create("HMAC(" + spec.arg(0) + ")"))
+ return new HKDF(mac.release());
return nullptr;
}
diff --git a/src/lib/kdf/info.txt b/src/lib/kdf/info.txt
index 35032e159..68aa46895 100644
--- a/src/lib/kdf/info.txt
+++ b/src/lib/kdf/info.txt
@@ -7,7 +7,3 @@ base
<header:public>
kdf.h
</header:public>
-
-<header:internal>
-kdf_utils.h
-</header:internal>
diff --git a/src/lib/kdf/kdf.cpp b/src/lib/kdf/kdf.cpp
index 793cd3d62..3eba8a5cd 100644
--- a/src/lib/kdf/kdf.cpp
+++ b/src/lib/kdf/kdf.cpp
@@ -7,10 +7,54 @@
#include <botan/kdf.h>
#include <botan/internal/algo_registry.h>
-#include <botan/exceptn.h>
+
+#if defined(BOTAN_HAS_HKDF)
+#include <botan/hkdf.h>
+#endif
+
+#if defined(BOTAN_HAS_KDF1)
+#include <botan/kdf1.h>
+#endif
+
+#if defined(BOTAN_HAS_KDF2)
+#include <botan/kdf2.h>
+#endif
+
+#if defined(BOTAN_HAS_TLS_V10_PRF)
+#include <botan/prf_tls.h>
+#endif
+
+#if defined(BOTAN_HAS_TLS_V12_PRF)
+#include <botan/prf_tls.h>
+#endif
+
+#if defined(BOTAN_HAS_X942_PRF)
+#include <botan/prf_x942.h>
+#endif
+
+#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>))
namespace Botan {
+KDF::~KDF() {}
+
+std::unique_ptr<KDF> KDF::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<KDF>(make_a<KDF>(algo_spec, provider));
+ }
+
+std::vector<std::string> KDF::providers(const std::string& algo_spec)
+ {
+ return providers_of<KDF>(KDF::Spec(algo_spec));
+ }
+
KDF* get_kdf(const std::string& algo_spec)
{
SCAN_Name request(algo_spec);
@@ -18,9 +62,34 @@ KDF* get_kdf(const std::string& algo_spec)
if(request.algo_name() == "Raw")
return nullptr; // No KDF
- if(KDF* kdf = make_a<KDF>(algo_spec))
- return kdf;
- throw Algorithm_Not_Found(algo_spec);
+ auto kdf = KDF::create(algo_spec);
+ if(!kdf)
+ throw Algorithm_Not_Found(algo_spec);
+ return kdf.release();
}
+#if defined(BOTAN_HAS_HKDF)
+BOTAN_REGISTER_NAMED_T(KDF, "HKDF", HKDF, HKDF::make);
+#endif
+
+#if defined(BOTAN_HAS_KDF1)
+BOTAN_REGISTER_KDF_1HASH(KDF1, "KDF1");
+#endif
+
+#if defined(BOTAN_HAS_KDF2)
+BOTAN_REGISTER_KDF_1HASH(KDF2, "KDF2");
+#endif
+
+#if defined(BOTAN_HAS_TLS_V10_PRF)
+BOTAN_REGISTER_KDF_NOARGS(TLS_PRF, "TLS-PRF");
+#endif
+
+#if defined(BOTAN_HAS_TLS_V12_PRF)
+BOTAN_REGISTER_NAMED_T(KDF, "TLS-12-PRF", TLS_12_PRF, TLS_12_PRF::make);
+#endif
+
+#if defined(BOTAN_HAS_X942_PRF)
+BOTAN_REGISTER_KDF_NAMED_1STR(X942_PRF, "X9.42-PRF");
+#endif
+
}
diff --git a/src/lib/kdf/kdf.h b/src/lib/kdf/kdf.h
index d69c1ece5..88b50c8b8 100644
--- a/src/lib/kdf/kdf.h
+++ b/src/lib/kdf/kdf.h
@@ -21,7 +21,20 @@ namespace Botan {
class BOTAN_DLL KDF
{
public:
- virtual ~KDF() {}
+ virtual ~KDF();
+
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<KDF> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
virtual std::string name() const = 0;
diff --git a/src/lib/kdf/kdf1/kdf1.cpp b/src/lib/kdf/kdf1/kdf1.cpp
index fa3432467..c7ea3c37e 100644
--- a/src/lib/kdf/kdf1/kdf1.cpp
+++ b/src/lib/kdf/kdf1/kdf1.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/kdf1.h>
namespace Botan {
-BOTAN_REGISTER_KDF_1HASH(KDF1, "KDF1");
-
size_t KDF1::kdf(byte key[], size_t key_len,
const byte secret[], size_t secret_len,
const byte salt[], size_t salt_len) const
diff --git a/src/lib/kdf/kdf2/kdf2.cpp b/src/lib/kdf/kdf2/kdf2.cpp
index 9deb1a22f..df2b7a91c 100644
--- a/src/lib/kdf/kdf2/kdf2.cpp
+++ b/src/lib/kdf/kdf2/kdf2.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/kdf2.h>
namespace Botan {
-BOTAN_REGISTER_KDF_1HASH(KDF2, "KDF2");
-
size_t KDF2::kdf(byte key[], size_t key_len,
const byte secret[], size_t secret_len,
const byte salt[], size_t salt_len) const
diff --git a/src/lib/kdf/kdf_utils.h b/src/lib/kdf/kdf_utils.h
deleted file mode 100644
index f67892437..000000000
--- a/src/lib/kdf/kdf_utils.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
-* KDF Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_KDF_UTILS_H__
-#define BOTAN_KDF_UTILS_H__
-
-#include <botan/kdf.h>
-#include <botan/internal/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/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp
index 4fdec8fef..547b0c9c8 100644
--- a/src/lib/kdf/prf_tls/prf_tls.cpp
+++ b/src/lib/kdf/prf_tls/prf_tls.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/prf_tls.h>
#include <botan/hmac.h>
@@ -13,20 +12,21 @@ namespace Botan {
TLS_12_PRF* TLS_12_PRF::make(const Spec& spec)
{
- if(auto mac = get_mac(spec.arg(0)))
- return new TLS_12_PRF(mac);
- if(auto hash = get_hash_function(spec.arg(0)))
- return new TLS_12_PRF(new HMAC(hash));
+ if(auto mac = MessageAuthenticationCode::create(spec.arg(0)))
+ return new TLS_12_PRF(mac.release());
+
+ if(auto mac = MessageAuthenticationCode::create("HMAC(" + spec.arg(0) + ")"))
+ return new TLS_12_PRF(mac.release());
+
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(KDF, "TLS-12-PRF", TLS_12_PRF, TLS_12_PRF::make);
-BOTAN_REGISTER_KDF_NOARGS(TLS_PRF, "TLS-PRF");
-
TLS_PRF::TLS_PRF() :
- m_hmac_md5(make_message_auth("HMAC(MD5)")),
- m_hmac_sha1(make_message_auth("HMAC(SHA-1)"))
+ m_hmac_md5(MessageAuthenticationCode::create("HMAC(MD5)")),
+ m_hmac_sha1(MessageAuthenticationCode::create("HMAC(SHA-1)"))
{
+ if(!m_hmac_md5 || !m_hmac_sha1)
+ throw Algorithm_Not_Found("TLS_PRF HMACs not available");
}
namespace {
diff --git a/src/lib/kdf/prf_x942/prf_x942.cpp b/src/lib/kdf/prf_x942/prf_x942.cpp
index 622d68c1a..fb8de1e85 100644
--- a/src/lib/kdf/prf_x942/prf_x942.cpp
+++ b/src/lib/kdf/prf_x942/prf_x942.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/prf_x942.h>
#include <botan/der_enc.h>
#include <botan/oids.h>
@@ -15,8 +14,6 @@
namespace Botan {
-BOTAN_REGISTER_KDF_NAMED_1STR(X942_PRF, "X9.42-PRF");
-
namespace {
/*
@@ -35,7 +32,7 @@ size_t X942_PRF::kdf(byte key[], size_t key_len,
const byte secret[], size_t secret_len,
const byte salt[], size_t salt_len) const
{
- std::unique_ptr<HashFunction> hash(make_hash_function("SHA-160"));
+ std::unique_ptr<HashFunction> hash(HashFunction::create("SHA-160"));
const OID kek_algo(m_key_wrap_oid);
secure_vector<byte> h;
diff --git a/src/lib/mac/cbc_mac/cbc_mac.cpp b/src/lib/mac/cbc_mac/cbc_mac.cpp
index b58372c78..449865255 100644
--- a/src/lib/mac/cbc_mac/cbc_mac.cpp
+++ b/src/lib/mac/cbc_mac/cbc_mac.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/cbc_mac.h>
namespace Botan {
@@ -14,14 +13,12 @@ CBC_MAC* CBC_MAC::make(const Spec& spec)
{
if(spec.arg_count() == 1)
{
- if(auto bc = make_block_cipher(spec.arg(0)))
+ if(auto bc = BlockCipher::create(spec.arg(0)))
return new CBC_MAC(bc.release());
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CBC-MAC", CBC_MAC, CBC_MAC::make);
-
/*
* Update an CBC-MAC Calculation
*/
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp
index 1621079dc..27edda233 100644
--- a/src/lib/mac/cmac/cmac.cpp
+++ b/src/lib/mac/cmac/cmac.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/cmac.h>
namespace Botan {
@@ -14,14 +13,12 @@ CMAC* CMAC::make(const Spec& spec)
{
if(spec.arg_count() == 1)
{
- if(BlockCipher* bc = get_block_cipher(spec.arg(0)))
- return new CMAC(bc);
+ if(auto bc = BlockCipher::create(spec.arg(0)))
+ return new CMAC(bc.release());
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CMAC", CMAC, CMAC::make);
-
/*
* Perform CMAC's multiplication in GF(2^n)
*/
diff --git a/src/lib/mac/hmac/hmac.cpp b/src/lib/mac/hmac/hmac.cpp
index 1c6821a54..f445ab0cf 100644
--- a/src/lib/mac/hmac/hmac.cpp
+++ b/src/lib/mac/hmac/hmac.cpp
@@ -6,7 +6,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/hmac.h>
namespace Botan {
@@ -15,14 +14,12 @@ HMAC* HMAC::make(const Spec& spec)
{
if(spec.arg_count() == 1)
{
- if(HashFunction* h = get_hash_function(spec.arg(0)))
- return new HMAC(h);
+ if(auto h = HashFunction::create(spec.arg(0)))
+ return new HMAC(h.release());
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "HMAC", HMAC, HMAC::make);
-
/*
* Update a HMAC Calculation
*/
diff --git a/src/lib/mac/info.txt b/src/lib/mac/info.txt
index 3faa16c11..ab7833857 100644
--- a/src/lib/mac/info.txt
+++ b/src/lib/mac/info.txt
@@ -3,7 +3,3 @@ define MAC 20150626
<header:public>
mac.h
</header:public>
-
-<header:internal>
-mac_utils.h
-</header:internal>
diff --git a/src/lib/mac/mac.cpp b/src/lib/mac/mac.cpp
index 0bb1939c7..8c1185c55 100644
--- a/src/lib/mac/mac.cpp
+++ b/src/lib/mac/mac.cpp
@@ -6,10 +6,48 @@
*/
#include <botan/mac.h>
+#include <botan/internal/algo_registry.h>
#include <botan/mem_ops.h>
+#if defined(BOTAN_HAS_CBC_MAC)
+ #include <botan/cbc_mac.h>
+#endif
+
+#if defined(BOTAN_HAS_CMAC)
+ #include <botan/cmac.h>
+#endif
+
+#if defined(BOTAN_HAS_HMAC)
+ #include <botan/hmac.h>
+#endif
+
+#if defined(BOTAN_HAS_POLY1305)
+ #include <botan/poly1305.h>
+#endif
+
+#if defined(BOTAN_HAS_SIPHASH)
+ #include <botan/siphash.h>
+#endif
+
+#if defined(BOTAN_HAS_ANSI_X919_MAC)
+ #include <botan/x919_mac.h>
+#endif
+
namespace Botan {
+std::unique_ptr<MessageAuthenticationCode> MessageAuthenticationCode::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<MessageAuthenticationCode>(make_a<MessageAuthenticationCode>(algo_spec, provider));
+ }
+
+std::vector<std::string> MessageAuthenticationCode::providers(const std::string& algo_spec)
+ {
+ return providers_of<MessageAuthenticationCode>(MessageAuthenticationCode::Spec(algo_spec));
+ }
+
+MessageAuthenticationCode::~MessageAuthenticationCode() {}
+
/*
* Default (deterministic) MAC verification operation
*/
@@ -23,4 +61,28 @@ bool MessageAuthenticationCode::verify_mac(const byte mac[], size_t length)
return same_mem(our_mac.data(), mac, length);
}
+#if defined(BOTAN_HAS_CBC_MAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CBC-MAC", CBC_MAC, CBC_MAC::make);
+#endif
+
+#if defined(BOTAN_HAS_CMAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CMAC", CMAC, CMAC::make);
+#endif
+
+#if defined(BOTAN_HAS_HMAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "HMAC", HMAC, HMAC::make);
+#endif
+
+#if defined(BOTAN_HAS_POLY1305)
+BOTAN_REGISTER_T_NOARGS(MessageAuthenticationCode, Poly1305);
+#endif
+
+#if defined(BOTAN_HAS_SIPHASH)
+BOTAN_REGISTER_NAMED_T_2LEN(MessageAuthenticationCode, SipHash, "SipHash", "base", 2, 4);
+#endif
+
+#if defined(BOTAN_HAS_ANSI_X919_MAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "X9.19-MAC", ANSI_X919_MAC, make_new_T<ANSI_X919_MAC>);
+#endif
+
}
diff --git a/src/lib/mac/mac.h b/src/lib/mac/mac.h
index 8ad2d1e99..90ef4db15 100644
--- a/src/lib/mac/mac.h
+++ b/src/lib/mac/mac.h
@@ -22,6 +22,23 @@ class BOTAN_DLL MessageAuthenticationCode : public Buffered_Computation,
public SymmetricAlgorithm
{
public:
+ typedef SCAN_Name Spec;
+
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<MessageAuthenticationCode> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
+
+ virtual ~MessageAuthenticationCode();
+
/**
* Verify a MAC.
* @param in the MAC to verify as a byte array
@@ -34,8 +51,6 @@ class BOTAN_DLL MessageAuthenticationCode : public Buffered_Computation,
* Get a new object representing the same algorithm as *this
*/
virtual MessageAuthenticationCode* clone() const = 0;
-
- typedef SCAN_Name Spec;
};
}
diff --git a/src/lib/mac/mac_utils.h b/src/lib/mac/mac_utils.h
deleted file mode 100644
index 5b22da4a3..000000000
--- a/src/lib/mac/mac_utils.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-* Authentication Code Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_MAC_UTILS_H__
-#define BOTAN_MAC_UTILS_H__
-
-#include <botan/internal/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/mac/poly1305/poly1305.cpp b/src/lib/mac/poly1305/poly1305.cpp
index 659667baf..0a62808f6 100644
--- a/src/lib/mac/poly1305/poly1305.cpp
+++ b/src/lib/mac/poly1305/poly1305.cpp
@@ -8,7 +8,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/poly1305.h>
#include <botan/loadstor.h>
#include <botan/mul128.h>
@@ -16,8 +15,6 @@
namespace Botan {
-BOTAN_REGISTER_MAC_NOARGS(Poly1305);
-
namespace {
void poly1305_init(secure_vector<u64bit>& X, const byte key[32])
diff --git a/src/lib/mac/siphash/siphash.cpp b/src/lib/mac/siphash/siphash.cpp
index f8ed28a84..4a9ffe8ea 100644
--- a/src/lib/mac/siphash/siphash.cpp
+++ b/src/lib/mac/siphash/siphash.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/siphash.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T_2LEN(MessageAuthenticationCode, SipHash, "SipHash", "base", 2, 4);
-
namespace {
void SipRounds(u64bit M, secure_vector<u64bit>& V, size_t r)
diff --git a/src/lib/mac/x919_mac/x919_mac.cpp b/src/lib/mac/x919_mac/x919_mac.cpp
index 542f9040a..205d812c2 100644
--- a/src/lib/mac/x919_mac/x919_mac.cpp
+++ b/src/lib/mac/x919_mac/x919_mac.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/x919_mac.h>
namespace Botan {
-BOTAN_REGISTER_MAC_NAMED_NOARGS(ANSI_X919_MAC, "X9.19-MAC");
-
/*
* Update an ANSI X9.19 MAC Calculation
*/
@@ -88,10 +85,11 @@ MessageAuthenticationCode* ANSI_X919_MAC::clone() const
/*
* ANSI X9.19 MAC Constructor
*/
-ANSI_X919_MAC::ANSI_X919_MAC() : m_state(8), m_position(0)
+ANSI_X919_MAC::ANSI_X919_MAC() :
+ m_des1(BlockCipher::create("DES")),
+ m_des2(BlockCipher::create("DES")),
+ m_state(8), m_position(0)
{
- m_des1.reset(get_block_cipher("DES"));
- m_des2.reset(m_des1->clone());
}
}
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index 0a068c53e..2acfabb99 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -7,7 +7,7 @@
#include <botan/bigint.h>
#include <botan/internal/mp_core.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/internal/rounding.h>
#include <botan/internal/bit_ops.h>
diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h
index e3200ca9d..2963ba35d 100644
--- a/src/lib/math/bigint/bigint.h
+++ b/src/lib/math/bigint/bigint.h
@@ -12,7 +12,7 @@
#include <botan/rng.h>
#include <botan/secmem.h>
#include <botan/mp_types.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <iosfwd>
namespace Botan {
diff --git a/src/lib/math/numbertheory/dsa_gen.cpp b/src/lib/math/numbertheory/dsa_gen.cpp
index bd3c0e4a1..60151355a 100644
--- a/src/lib/math/numbertheory/dsa_gen.cpp
+++ b/src/lib/math/numbertheory/dsa_gen.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/numthry.h>
-#include <botan/lookup.h>
#include <botan/hash.h>
#include <botan/parsing.h>
#include <algorithm>
@@ -52,7 +51,10 @@ 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(make_hash_function("SHA-" + std::to_string(qbits)));
+ const std::string hash_name = "SHA-" + std::to_string(qbits);
+ std::unique_ptr<HashFunction> hash(HashFunction::create(hash_name));
+ if(!hash)
+ throw Algorithm_Not_Found(hash_name);
const size_t HASH_SIZE = hash->output_length();
diff --git a/src/lib/misc/aont/package.cpp b/src/lib/misc/aont/package.cpp
index 125b3842e..a3be898d8 100644
--- a/src/lib/misc/aont/package.cpp
+++ b/src/lib/misc/aont/package.cpp
@@ -9,8 +9,7 @@
#include <botan/package.h>
#include <botan/filters.h>
#include <botan/ctr.h>
-#include <botan/get_byte.h>
-#include <botan/internal/xor_buf.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/lib/misc/benchmark/benchmark.cpp b/src/lib/misc/benchmark/benchmark.cpp
index 152b45d37..d5e3694b5 100644
--- a/src/lib/misc/benchmark/benchmark.cpp
+++ b/src/lib/misc/benchmark/benchmark.cpp
@@ -7,7 +7,6 @@
#include <botan/benchmark.h>
#include <botan/exceptn.h>
-#include <botan/lookup.h>
#include <botan/buf_comp.h>
#include <botan/cipher_mode.h>
#include <botan/block_cipher.h>
@@ -56,10 +55,8 @@ time_algorithm_ops(const std::string& name,
const double mb_mult = buffer.size() / static_cast<double>(Mebibyte);
- if(BlockCipher* p = get_block_cipher(name, provider))
+ if(auto bc = BlockCipher::create(name, provider))
{
- std::unique_ptr<BlockCipher> bc(p);
-
const SymmetricKey key(rng, bc->maximum_keylength());
return std::map<std::string, double>({
@@ -68,10 +65,8 @@ time_algorithm_ops(const std::string& name,
{ "decrypt", mb_mult * time_op(runtime / 2, [&]() { bc->decrypt(buffer); }) },
});
}
- else if(StreamCipher* p = get_stream_cipher(name, provider))
+ else if(auto sc = StreamCipher::create(name, provider))
{
- std::unique_ptr<StreamCipher> sc(p);
-
const SymmetricKey key(rng, sc->maximum_keylength());
return std::map<std::string, double>({
@@ -79,18 +74,14 @@ time_algorithm_ops(const std::string& name,
{ "", mb_mult * time_op(runtime, [&]() { sc->encipher(buffer); }) },
});
}
- else if(HashFunction* p = get_hash_function(name, provider))
+ else if(auto h = HashFunction::create(name, provider))
{
- std::unique_ptr<HashFunction> h(p);
-
return std::map<std::string, double>({
{ "", mb_mult * time_op(runtime, [&]() { h->update(buffer); }) },
});
}
- else if(MessageAuthenticationCode* p = get_mac(name, provider))
+ else if(auto mac = MessageAuthenticationCode::create(name, provider))
{
- std::unique_ptr<MessageAuthenticationCode> mac(p);
-
const SymmetricKey key(rng, mac->maximum_keylength());
return std::map<std::string, double>({
@@ -137,10 +128,10 @@ std::set<std::string> get_all_providers_of(const std::string& algo)
auto add_to_set = [&provs](const std::vector<std::string>& str) { for(auto&& s : str) { provs.insert(s); } };
- add_to_set(get_block_cipher_providers(algo));
- add_to_set(get_stream_cipher_providers(algo));
- add_to_set(get_hash_function_providers(algo));
- add_to_set(get_mac_providers(algo));
+ add_to_set(BlockCipher::providers(algo));
+ add_to_set(StreamCipher::providers(algo));
+ add_to_set(HashFunction::providers(algo));
+ add_to_set(MessageAuthenticationCode::providers(algo));
return provs;
}
diff --git a/src/lib/misc/cryptobox/cryptobox.cpp b/src/lib/misc/cryptobox/cryptobox.cpp
index d7e7bb72b..c0fc9b777 100644
--- a/src/lib/misc/cryptobox/cryptobox.cpp
+++ b/src/lib/misc/cryptobox/cryptobox.cpp
@@ -8,12 +8,11 @@
#include <botan/cryptobox.h>
#include <botan/filters.h>
#include <botan/pipe.h>
-#include <botan/lookup.h>
#include <botan/sha2_64.h>
#include <botan/hmac.h>
#include <botan/pbkdf2.h>
#include <botan/pem.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <botan/mem_ops.h>
namespace Botan {
diff --git a/src/lib/misc/pbes2/pbes2.cpp b/src/lib/misc/pbes2/pbes2.cpp
index 89af01e9d..ab740ff5d 100644
--- a/src/lib/misc/pbes2/pbes2.cpp
+++ b/src/lib/misc/pbes2/pbes2.cpp
@@ -7,7 +7,6 @@
#include <botan/pbes2.h>
#include <botan/cipher_mode.h>
-#include <botan/lookup.h>
#include <botan/pbkdf.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
diff --git a/src/lib/misc/rfc3394/rfc3394.cpp b/src/lib/misc/rfc3394/rfc3394.cpp
index a199cc599..582e8c92d 100644
--- a/src/lib/misc/rfc3394/rfc3394.cpp
+++ b/src/lib/misc/rfc3394/rfc3394.cpp
@@ -6,11 +6,9 @@
*/
#include <botan/rfc3394.h>
-#include <botan/lookup.h>
#include <botan/block_cipher.h>
#include <botan/loadstor.h>
#include <botan/exceptn.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
@@ -23,7 +21,10 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key,
if(kek.size() != 16 && kek.size() != 24 && kek.size() != 32)
throw std::invalid_argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key wrap");
- std::unique_ptr<BlockCipher> aes(make_block_cipher("AES-" + std::to_string(8*kek.size())));
+ const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create(cipher_name));
+ if(!aes)
+ throw Algorithm_Not_Found(cipher_name);
aes->set_key(kek);
const size_t n = key.size() / 8;
@@ -67,7 +68,10 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key,
if(kek.size() != 16 && kek.size() != 24 && kek.size() != 32)
throw std::invalid_argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key unwrap");
- std::unique_ptr<BlockCipher> aes(make_block_cipher("AES-" + std::to_string(8*kek.size())));
+ const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create(cipher_name));
+ if(!aes)
+ throw Algorithm_Not_Found(cipher_name);
aes->set_key(kek);
const size_t n = (key.size() - 8) / 8;
diff --git a/src/lib/misc/srp6/srp6.cpp b/src/lib/misc/srp6/srp6.cpp
index d3f7338bd..f567db875 100644
--- a/src/lib/misc/srp6/srp6.cpp
+++ b/src/lib/misc/srp6/srp6.cpp
@@ -8,7 +8,6 @@
#include <botan/srp6.h>
#include <botan/dl_group.h>
#include <botan/numthry.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -19,7 +18,10 @@ BigInt hash_seq(const std::string& hash_id,
const BigInt& in1,
const BigInt& in2)
{
- std::unique_ptr<HashFunction> hash_fn(get_hash(hash_id));
+ std::unique_ptr<HashFunction> hash_fn(HashFunction::create(hash_id));
+
+ if(!hash_fn)
+ throw Algorithm_Not_Found(hash_id);
hash_fn->update(BigInt::encode_1363(in1, pad_to));
hash_fn->update(BigInt::encode_1363(in2, pad_to));
@@ -32,7 +34,10 @@ BigInt compute_x(const std::string& hash_id,
const std::string& password,
const std::vector<byte>& salt)
{
- std::unique_ptr<HashFunction> hash_fn(get_hash(hash_id));
+ std::unique_ptr<HashFunction> hash_fn(HashFunction::create(hash_id));
+
+ if(!hash_fn)
+ throw Algorithm_Not_Found(hash_id);
hash_fn->update(identifier);
hash_fn->update(":");
diff --git a/src/lib/modes/aead/aead.cpp b/src/lib/modes/aead/aead.cpp
index 1f2099d2e..61918c310 100644
--- a/src/lib/modes/aead/aead.cpp
+++ b/src/lib/modes/aead/aead.cpp
@@ -7,8 +7,59 @@
#include <botan/internal/mode_utils.h>
#include <botan/aead.h>
+#if defined(BOTAN_HAS_AEAD_CCM)
+ #include <botan/ccm.h>
+#endif
+
+#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
+ #include <botan/chacha20poly1305.h>
+#endif
+
+#if defined(BOTAN_HAS_AEAD_EAX)
+ #include <botan/eax.h>
+#endif
+
+#if defined(BOTAN_HAS_AEAD_GCM)
+ #include <botan/gcm.h>
+#endif
+
+#if defined(BOTAN_HAS_AEAD_OCB)
+ #include <botan/ocb.h>
+#endif
+
+#if defined(BOTAN_HAS_AEAD_SIV)
+ #include <botan/siv.h>
+#endif
+
namespace Botan {
+AEAD_Mode::~AEAD_Mode() {}
+
+#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_TRANSFORM_NOARGS(ChaCha20Poly1305_Encryption);
+BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Decryption);
+#endif
+
+#if defined(BOTAN_HAS_AEAD_EAX)
+BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(EAX_Encryption, EAX_Decryption, 0);
+#endif
+
+#if defined(BOTAN_HAS_AEAD_GCM)
+BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(GCM_Encryption, GCM_Decryption, 16);
+#endif
+
+#if defined(BOTAN_HAS_AEAD_OCB)
+BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(OCB_Encryption, OCB_Decryption, 16);
+#endif
+
+#if defined(BOTAN_HAS_AEAD_SIV)
+BOTAN_REGISTER_BLOCK_CIPHER_MODE(SIV_Encryption, SIV_Decryption);
+#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));
diff --git a/src/lib/modes/aead/aead.h b/src/lib/modes/aead/aead.h
index 1fff41f97..3214187db 100644
--- a/src/lib/modes/aead/aead.h
+++ b/src/lib/modes/aead/aead.h
@@ -55,6 +55,8 @@ class BOTAN_DLL AEAD_Mode : public Cipher_Mode
* modes, and large enough that random collisions are unlikely).
*/
size_t default_nonce_length() const override { return 12; }
+
+ virtual ~AEAD_Mode();
};
/**
diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp
index b40e6e62b..bd4e0f4be 100644
--- a/src/lib/modes/aead/ccm/ccm.cpp
+++ b/src/lib/modes/aead/ccm/ccm.cpp
@@ -11,8 +11,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN2(CCM_Encryption, CCM_Decryption, 16, 3);
-
/*
* CCM_Mode Constructor
*/
diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp
index 3dc9d7f6d..0aef6a747 100644
--- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp
+++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp
@@ -10,13 +10,13 @@
namespace Botan {
-BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Encryption);
-BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Decryption);
-
ChaCha20Poly1305_Mode::ChaCha20Poly1305_Mode() :
- m_chacha(make_stream_cipher("ChaCha")),
- m_poly1305(make_message_auth("Poly1305"))
- {}
+ m_chacha(StreamCipher::create("ChaCha")),
+ m_poly1305(MessageAuthenticationCode::create("Poly1305"))
+ {
+ if(!m_chacha || !m_poly1305)
+ throw Algorithm_Not_Found("ChaCha20Poly1305");
+ }
bool ChaCha20Poly1305_Mode::valid_nonce_length(size_t n) const
{
diff --git a/src/lib/modes/aead/eax/eax.cpp b/src/lib/modes/aead/eax/eax.cpp
index 22e772d75..4b928cd31 100644
--- a/src/lib/modes/aead/eax/eax.cpp
+++ b/src/lib/modes/aead/eax/eax.cpp
@@ -13,8 +13,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(EAX_Encryption, EAX_Decryption, 0);
-
namespace {
/*
diff --git a/src/lib/modes/aead/gcm/gcm.cpp b/src/lib/modes/aead/gcm/gcm.cpp
index 130ff6aad..7dcdd0d31 100644
--- a/src/lib/modes/aead/gcm/gcm.cpp
+++ b/src/lib/modes/aead/gcm/gcm.cpp
@@ -16,8 +16,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(GCM_Encryption, GCM_Decryption, 16);
-
void GHASH::gcm_multiply(secure_vector<byte>& x) const
{
#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 ee5583bea..ff3317dd9 100644
--- a/src/lib/modes/aead/ocb/ocb.cpp
+++ b/src/lib/modes/aead/ocb/ocb.cpp
@@ -11,8 +11,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(OCB_Encryption, OCB_Decryption, 16);
-
// Has to be in Botan namespace so unique_ptr can reference it
class L_computer
{
diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp
index 5b22216cf..a4cb65a94 100644
--- a/src/lib/modes/aead/siv/siv.cpp
+++ b/src/lib/modes/aead/siv/siv.cpp
@@ -13,8 +13,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE(SIV_Encryption, SIV_Decryption);
-
SIV_Mode::SIV_Mode(BlockCipher* cipher) :
m_name(cipher->name() + "/SIV"),
m_ctr(new CTR_BE(cipher->clone())),
diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp
index 85241cf53..1e3c6d6e3 100644
--- a/src/lib/modes/cbc/cbc.cpp
+++ b/src/lib/modes/cbc/cbc.cpp
@@ -11,27 +11,6 @@
namespace Botan {
-template<typename CBC_T, typename CTS_T>
-Transform* make_cbc_mode(const Transform::Spec& spec)
- {
- std::unique_ptr<BlockCipher> bc(get_block_cipher(spec.arg(0)));
-
- if(bc)
- {
- const std::string padding = spec.arg(1, "PKCS7");
-
- if(padding == "CTS")
- return new CTS_T(bc.release());
- else
- return new CBC_T(bc.release(), get_bc_pad(padding));
- }
-
- return nullptr;
- }
-
-BOTAN_REGISTER_TRANSFORM(CBC_Encryption, (make_cbc_mode<CBC_Encryption,CTS_Encryption>));
-BOTAN_REGISTER_TRANSFORM(CBC_Decryption, (make_cbc_mode<CBC_Decryption,CTS_Decryption>));
-
CBC_Mode::CBC_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
m_cipher(cipher),
m_padding(padding),
diff --git a/src/lib/modes/cfb/cfb.cpp b/src/lib/modes/cfb/cfb.cpp
index e98d10cb3..7c7ed1865 100644
--- a/src/lib/modes/cfb/cfb.cpp
+++ b/src/lib/modes/cfb/cfb.cpp
@@ -11,8 +11,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(CFB_Encryption, CFB_Decryption, 0);
-
CFB_Mode::CFB_Mode(BlockCipher* cipher, size_t feedback_bits) :
m_cipher(cipher),
m_feedback_bytes(feedback_bits ? feedback_bits / 8 : cipher->block_size())
diff --git a/src/lib/modes/cipher_mode.cpp b/src/lib/modes/cipher_mode.cpp
index 095ef9008..27ee26327 100644
--- a/src/lib/modes/cipher_mode.cpp
+++ b/src/lib/modes/cipher_mode.cpp
@@ -7,11 +7,75 @@
#include <botan/cipher_mode.h>
#include <botan/stream_mode.h>
-#include <botan/lookup.h>
+#include <botan/internal/mode_utils.h>
#include <sstream>
+#if defined(BOTAN_HAS_MODE_ECB)
+ #include <botan/ecb.h>
+#endif
+
+#if defined(BOTAN_HAS_MODE_CBC)
+ #include <botan/cbc.h>
+#endif
+
+#if defined(BOTAN_HAS_MODE_CFB)
+ #include <botan/cfb.h>
+#endif
+
+#if defined(BOTAN_HAS_MODE_XTS)
+ #include <botan/xts.h>
+#endif
+
namespace Botan {
+#if defined(BOTAN_HAS_MODE_ECB)
+
+template<typename T>
+Transform* make_ecb_mode(const Transform::Spec& spec)
+ {
+ std::unique_ptr<BlockCipher> bc(BlockCipher::create(spec.arg(0)));
+ std::unique_ptr<BlockCipherModePaddingMethod> pad(get_bc_pad(spec.arg(1, "NoPadding")));
+ if(bc && pad)
+ return new T(bc.release(), pad.release());
+ return nullptr;
+ }
+
+BOTAN_REGISTER_TRANSFORM(ECB_Encryption, make_ecb_mode<ECB_Encryption>);
+BOTAN_REGISTER_TRANSFORM(ECB_Decryption, make_ecb_mode<ECB_Decryption>);
+#endif
+
+#if defined(BOTAN_HAS_MODE_CBC)
+
+template<typename CBC_T, typename CTS_T>
+Transform* make_cbc_mode(const Transform::Spec& spec)
+ {
+ std::unique_ptr<BlockCipher> bc(BlockCipher::create(spec.arg(0)));
+
+ if(bc)
+ {
+ const std::string padding = spec.arg(1, "PKCS7");
+
+ if(padding == "CTS")
+ return new CTS_T(bc.release());
+ else
+ return new CBC_T(bc.release(), get_bc_pad(padding));
+ }
+
+ return nullptr;
+ }
+
+BOTAN_REGISTER_TRANSFORM(CBC_Encryption, (make_cbc_mode<CBC_Encryption,CTS_Encryption>));
+BOTAN_REGISTER_TRANSFORM(CBC_Decryption, (make_cbc_mode<CBC_Decryption,CTS_Decryption>));
+#endif
+
+#if defined(BOTAN_HAS_MODE_CFB)
+BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(CFB_Encryption, CFB_Decryption, 0);
+#endif
+
+#if defined(BOTAN_HAS_MODE_XTS)
+BOTAN_REGISTER_BLOCK_CIPHER_MODE(XTS_Encryption, XTS_Decryption);
+#endif
+
Cipher_Mode* get_cipher_mode(const std::string& algo_spec, Cipher_Dir direction)
{
const std::string provider = "";
@@ -66,8 +130,8 @@ Cipher_Mode* get_cipher_mode(const std::string& algo_spec, Cipher_Dir direction)
return cipher;
}
- if(StreamCipher* stream_cipher = get_stream_cipher(mode_name, provider))
- return new Stream_Cipher_Mode(stream_cipher);
+ if(auto sc = StreamCipher::create(mode_name, provider))
+ return new Stream_Cipher_Mode(sc.release());
return nullptr;
}
diff --git a/src/lib/modes/ecb/ecb.cpp b/src/lib/modes/ecb/ecb.cpp
index e5794d8e1..14e72e20b 100644
--- a/src/lib/modes/ecb/ecb.cpp
+++ b/src/lib/modes/ecb/ecb.cpp
@@ -10,19 +10,6 @@
namespace Botan {
-template<typename T>
-Transform* make_ecb_mode(const Transform::Spec& spec)
- {
- std::unique_ptr<BlockCipher> bc(get_block_cipher(spec.arg(0)));
- std::unique_ptr<BlockCipherModePaddingMethod> pad(get_bc_pad(spec.arg(1, "NoPadding")));
- if(bc && pad)
- return new T(bc.release(), pad.release());
- return nullptr;
- }
-
-BOTAN_REGISTER_TRANSFORM(ECB_Encryption, make_ecb_mode<ECB_Encryption>);
-BOTAN_REGISTER_TRANSFORM(ECB_Decryption, make_ecb_mode<ECB_Decryption>);
-
ECB_Mode::ECB_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
m_cipher(cipher),
m_padding(padding)
diff --git a/src/lib/modes/mode_utils.h b/src/lib/modes/mode_utils.h
index 53aa41745..a61c22a4f 100644
--- a/src/lib/modes/mode_utils.h
+++ b/src/lib/modes/mode_utils.h
@@ -12,7 +12,6 @@
#include <botan/internal/algo_registry.h>
#include <botan/block_cipher.h>
#include <botan/loadstor.h>
-#include <botan/internal/xor_buf.h>
#include <botan/internal/rounding.h>
#include <botan/internal/bit_ops.h>
#include <algorithm>
@@ -22,18 +21,18 @@ namespace Botan {
template<typename T>
T* make_block_cipher_mode(const Transform::Spec& spec)
{
- if(BlockCipher* bc = get_block_cipher(spec.arg(0)))
- return new T(bc);
+ if(std::unique_ptr<BlockCipher> bc = BlockCipher::create(spec.arg(0)))
+ return new T(bc.release());
return nullptr;
}
template<typename T, size_t LEN1>
T* make_block_cipher_mode_len(const Transform::Spec& spec)
{
- if(BlockCipher* bc = get_block_cipher(spec.arg(0)))
+ if(std::unique_ptr<BlockCipher> bc = BlockCipher::create(spec.arg(0)))
{
const size_t len1 = spec.arg_as_integer(1, LEN1);
- return new T(bc, len1);
+ return new T(bc.release(), len1);
}
return nullptr;
@@ -42,11 +41,11 @@ T* make_block_cipher_mode_len(const Transform::Spec& spec)
template<typename T, size_t LEN1, size_t LEN2>
T* make_block_cipher_mode_len2(const Transform::Spec& spec)
{
- if(BlockCipher* bc = get_block_cipher(spec.arg(0)))
+ if(std::unique_ptr<BlockCipher> bc = BlockCipher::create(spec.arg(0)))
{
const size_t len1 = spec.arg_as_integer(1, LEN1);
const size_t len2 = spec.arg_as_integer(2, LEN2);
- return new T(bc, len1, len2);
+ return new T(bc.release(), len1, len2);
}
return nullptr;
diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp
index 046de216f..c42988d10 100644
--- a/src/lib/modes/xts/xts.cpp
+++ b/src/lib/modes/xts/xts.cpp
@@ -10,8 +10,6 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_MODE(XTS_Encryption, XTS_Decryption);
-
namespace {
void poly_double_128(byte out[], const byte in[])
diff --git a/src/lib/passhash/passhash9/passhash9.cpp b/src/lib/passhash/passhash9/passhash9.cpp
index f30684ec6..b457fc5c7 100644
--- a/src/lib/passhash/passhash9/passhash9.cpp
+++ b/src/lib/passhash/passhash9/passhash9.cpp
@@ -7,7 +7,6 @@
#include <botan/passhash9.h>
#include <botan/loadstor.h>
-#include <botan/lookup.h>
#include <botan/pbkdf2.h>
#include <botan/base64.h>
@@ -24,18 +23,18 @@ const size_t PASSHASH9_PBKDF_OUTPUT_LEN = 24; // 192 bits output
const size_t WORK_FACTOR_SCALE = 10000;
-MessageAuthenticationCode* get_pbkdf_prf(byte alg_id)
+std::unique_ptr<MessageAuthenticationCode> get_pbkdf_prf(byte alg_id)
{
if(alg_id == 0)
- return get_mac("HMAC(SHA-1)");
+ return MessageAuthenticationCode::create("HMAC(SHA-1)");
else if(alg_id == 1)
- return get_mac("HMAC(SHA-256)");
+ return MessageAuthenticationCode::create("HMAC(SHA-256)");
else if(alg_id == 2)
- return get_mac("CMAC(Blowfish)");
+ return MessageAuthenticationCode::create("CMAC(Blowfish)");
else if(alg_id == 3)
- return get_mac("HMAC(SHA-384)");
+ return MessageAuthenticationCode::create("HMAC(SHA-384)");
else if(alg_id == 4)
- return get_mac("HMAC(SHA-512)");
+ return MessageAuthenticationCode::create("HMAC(SHA-512)");
return nullptr;
}
@@ -46,14 +45,14 @@ std::string generate_passhash9(const std::string& pass,
u16bit work_factor,
byte alg_id)
{
- MessageAuthenticationCode* prf = get_pbkdf_prf(alg_id);
+ std::unique_ptr<MessageAuthenticationCode> prf = get_pbkdf_prf(alg_id);
if(!prf)
throw Invalid_Argument("Passhash9: Algorithm id " +
std::to_string(alg_id) +
" is not defined");
- PKCS5_PBKDF2 kdf(prf); // takes ownership of pointer
+ PKCS5_PBKDF2 kdf(prf.release()); // takes ownership of pointer
secure_vector<byte> salt(SALT_BYTES);
rng.randomize(salt.data(), salt.size());
@@ -110,12 +109,12 @@ bool check_passhash9(const std::string& pass, const std::string& hash)
const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor;
- MessageAuthenticationCode* pbkdf_prf = get_pbkdf_prf(alg_id);
+ std::unique_ptr<MessageAuthenticationCode> pbkdf_prf = get_pbkdf_prf(alg_id);
if(!pbkdf_prf)
return false; // unknown algorithm, reject
- PKCS5_PBKDF2 kdf(pbkdf_prf); // takes ownership of pointer
+ PKCS5_PBKDF2 kdf(pbkdf_prf.release()); // takes ownership of pointer
secure_vector<byte> cmp = kdf.derive_key(
PASSHASH9_PBKDF_OUTPUT_LEN,
diff --git a/src/lib/pbkdf/info.txt b/src/lib/pbkdf/info.txt
index 81f7c1260..3addbdb58 100644
--- a/src/lib/pbkdf/info.txt
+++ b/src/lib/pbkdf/info.txt
@@ -7,7 +7,3 @@ base
<header:public>
pbkdf.h
</header:public>
-
-<header:internal>
-pbkdf_utils.h
-</header:internal>
diff --git a/src/lib/pbkdf/pbkdf.cpp b/src/lib/pbkdf/pbkdf.cpp
index 7f0a68a01..6d7a6542f 100644
--- a/src/lib/pbkdf/pbkdf.cpp
+++ b/src/lib/pbkdf/pbkdf.cpp
@@ -6,10 +6,43 @@
*/
#include <botan/pbkdf.h>
+#include <botan/internal/algo_registry.h>
#include <stdexcept>
+#if defined(BOTAN_HAS_PBKDF1)
+#include <botan/pbkdf1.h>
+#endif
+
+#if defined(BOTAN_HAS_PBKDF2)
+#include <botan/pbkdf2.h>
+#endif
+
namespace Botan {
+#define BOTAN_REGISTER_PBKDF_1HASH(type, name) \
+ BOTAN_REGISTER_NAMED_T(PBKDF, name, type, (make_new_T_1X<type, HashFunction>))
+
+#if defined(BOTAN_HAS_PBKDF1)
+BOTAN_REGISTER_PBKDF_1HASH(PKCS5_PBKDF1, "PBKDF1");
+#endif
+
+#if defined(BOTAN_HAS_PBKDF2)
+BOTAN_REGISTER_NAMED_T(PBKDF, "PBKDF2", PKCS5_PBKDF2, PKCS5_PBKDF2::make);
+#endif
+
+PBKDF::~PBKDF() {}
+
+std::unique_ptr<PBKDF> PBKDF::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<PBKDF>(make_a<PBKDF>(algo_spec, provider));
+ }
+
+std::vector<std::string> PBKDF::providers(const std::string& algo_spec)
+ {
+ return providers_of<PBKDF>(PBKDF::Spec(algo_spec));
+ }
+
void PBKDF::pbkdf_timed(byte out[], size_t out_len,
const std::string& passphrase,
const byte salt[], size_t salt_len,
diff --git a/src/lib/pbkdf/pbkdf.h b/src/lib/pbkdf/pbkdf.h
index 5f6cd904c..495da0ac9 100644
--- a/src/lib/pbkdf/pbkdf.h
+++ b/src/lib/pbkdf/pbkdf.h
@@ -10,6 +10,8 @@
#include <botan/symkey.h>
#include <botan/scan_name.h>
+#include <botan/scan_name.h>
+#include <botan/exceptn.h>
#include <chrono>
namespace Botan {
@@ -22,8 +24,18 @@ namespace Botan {
class BOTAN_DLL PBKDF
{
public:
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<PBKDF> create(const std::string& algo_spec,
+ const std::string& provider = "");
- virtual ~PBKDF() {}
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
typedef SCAN_Name Spec;
@@ -34,6 +46,8 @@ class BOTAN_DLL PBKDF
virtual std::string name() const = 0;
+ virtual ~PBKDF();
+
/**
* Derive a key from a passphrase for a number of iterations
* specified by either iterations or if iterations == 0 then
@@ -147,6 +161,20 @@ class BOTAN_DLL PBKDF
}
};
+/**
+* Password based key derivation function factory method
+* @param algo_spec the name of the desired PBKDF algorithm
+* @return pointer to newly allocated object of that type
+*/
+inline PBKDF* get_pbkdf(const std::string& algo_spec,
+ const std::string& provider = "")
+ {
+ std::unique_ptr<PBKDF> p(PBKDF::create(algo_spec, provider));
+ if(p)
+ return p.release();
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
}
#endif
diff --git a/src/lib/pbkdf/pbkdf1/pbkdf1.cpp b/src/lib/pbkdf/pbkdf1/pbkdf1.cpp
index 28bac9572..49e1cf268 100644
--- a/src/lib/pbkdf/pbkdf1/pbkdf1.cpp
+++ b/src/lib/pbkdf/pbkdf1/pbkdf1.cpp
@@ -5,14 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pbkdf_utils.h>
#include <botan/pbkdf1.h>
#include <botan/exceptn.h>
namespace Botan {
-BOTAN_REGISTER_PBKDF_1HASH(PKCS5_PBKDF1, "PBKDF1");
-
size_t PKCS5_PBKDF1::pbkdf(byte output_buf[], size_t output_len,
const std::string& passphrase,
const byte salt[], size_t salt_len,
diff --git a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
index a27b9b15c..c1ac2c534 100644
--- a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
+++ b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
@@ -5,23 +5,19 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pbkdf_utils.h>
#include <botan/pbkdf2.h>
-#include <botan/get_byte.h>
-#include <botan/internal/xor_buf.h>
+#include <botan/loadstor.h>
#include <botan/internal/rounding.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(PBKDF, "PBKDF2", PKCS5_PBKDF2, PKCS5_PBKDF2::make);
-
PKCS5_PBKDF2* PKCS5_PBKDF2::make(const Spec& spec)
{
- if(auto mac = get_mac(spec.arg(0)))
- return new PKCS5_PBKDF2(mac);
+ if(auto mac = MessageAuthenticationCode::create(spec.arg(0)))
+ return new PKCS5_PBKDF2(mac.release());
- if(auto mac = get_mac("HMAC(" + spec.arg(0) + ")"))
- return new PKCS5_PBKDF2(mac);
+ if(auto mac = MessageAuthenticationCode::create("HMAC(" + spec.arg(0) + ")"))
+ return new PKCS5_PBKDF2(mac.release());
return nullptr;
}
diff --git a/src/lib/pbkdf/pbkdf_utils.h b/src/lib/pbkdf/pbkdf_utils.h
deleted file mode 100644
index 480fc70eb..000000000
--- a/src/lib/pbkdf/pbkdf_utils.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
-* PBKDF Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_PBKDF_UTILS_H__
-#define BOTAN_PBKDF_UTILS_H__
-
-#include <botan/pbkdf.h>
-#include <botan/internal/algo_registry.h>
-
-namespace Botan {
-
-#define BOTAN_REGISTER_PBKDF_1HASH(type, name) \
- BOTAN_REGISTER_NAMED_T(PBKDF, name, type, (make_new_T_1X<type, HashFunction>))
-#define BOTAN_REGISTER_PBKDF_1MAC(type, name) \
- BOTAN_REGISTER_NAMED_T(PBKDF, name, type, (make_new_T_1X<type, MessageAuthenticationCode>))
-
-}
-
-#endif
diff --git a/src/lib/pk_pad/eme.cpp b/src/lib/pk_pad/eme.cpp
index 9398b4c83..4804a8a81 100644
--- a/src/lib/pk_pad/eme.cpp
+++ b/src/lib/pk_pad/eme.cpp
@@ -6,9 +6,53 @@
*/
#include <botan/eme.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_EME_OAEP)
+#include <botan/oaep.h>
+#endif
+
+#if defined(BOTAN_HAS_EME_PKCS1v15)
+#include <botan/eme_pkcs.h>
+#endif
+
+#if defined(BOTAN_HAS_EME_RAW)
+#include <botan/eme_raw.h>
+#endif
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>)
+
+#if defined(BOTAN_HAS_EME_OAEP)
+BOTAN_REGISTER_NAMED_T(EME, "OAEP", OAEP, OAEP::make);
+#endif
+
+#if defined(BOTAN_HAS_EME_PKCS1v15)
+BOTAN_REGISTER_EME_NAMED_NOARGS(EME_PKCS1v15, "PKCS1v15");
+#endif
+
+#if defined(BOTAN_HAS_EME_RAW)
+BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw");
+#endif
+
+EME* get_eme(const std::string& algo_spec)
+ {
+ SCAN_Name request(algo_spec);
+
+ if(EME* eme = make_a<EME>(algo_spec))
+ return eme;
+
+ if(request.algo_name() == "Raw")
+ return nullptr; // No padding
+
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
/*
* Encode a message
*/
diff --git a/src/lib/pk_pad/eme_oaep/oaep.cpp b/src/lib/pk_pad/eme_oaep/oaep.cpp
index 871f40142..f214c25d2 100644
--- a/src/lib/pk_pad/eme_oaep/oaep.cpp
+++ b/src/lib/pk_pad/eme_oaep/oaep.cpp
@@ -5,12 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/oaep.h>
#include <botan/mgf1.h>
#include <botan/mem_ops.h>
-
namespace Botan {
OAEP* OAEP::make(const Spec& request)
@@ -20,17 +18,14 @@ OAEP* OAEP::make(const Spec& request)
if(request.arg_count() == 1 ||
(request.arg_count() == 2 && request.arg(1) == "MGF1"))
{
- if(HashFunction* hash = get_hash_function(request.arg(0)))
- return new OAEP(hash);
+ if(auto hash = HashFunction::create(request.arg(0)))
+ return new OAEP(hash.release());
}
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(EME, "OAEP", OAEP, OAEP::make);
-
-
/*
* OAEP Pad Operation
*/
diff --git a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
index 90af17565..65d29cd59 100644
--- a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
+++ b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/eme_pkcs.h>
namespace Botan {
-BOTAN_REGISTER_EME_NAMED_NOARGS(EME_PKCS1v15, "PKCS1v15");
-
/*
* PKCS1 Pad Operation
*/
diff --git a/src/lib/pk_pad/eme_raw/eme_raw.cpp b/src/lib/pk_pad/eme_raw/eme_raw.cpp
index 9ae894c70..78b670b65 100644
--- a/src/lib/pk_pad/eme_raw/eme_raw.cpp
+++ b/src/lib/pk_pad/eme_raw/eme_raw.cpp
@@ -4,14 +4,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/internal/bit_ops.h>
#include <botan/eme_raw.h>
namespace Botan {
-BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw");
-
secure_vector<byte> EME_Raw::pad(const byte in[], size_t in_length,
size_t key_bits,
RandomNumberGenerator&) const
diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp
new file mode 100644
index 000000000..e20286a7d
--- /dev/null
+++ b/src/lib/pk_pad/emsa.cpp
@@ -0,0 +1,83 @@
+/*
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/emsa.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_EMSA1)
+ #include <botan/emsa1.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA1_BSI)
+ #include <botan/emsa1_bsi.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_X931)
+ #include <botan/emsa_x931.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PKCS1)
+ #include <botan/emsa_pkcs1.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PSSR)
+ #include <botan/pssr.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_RAW)
+ #include <botan/emsa_raw.h>
+#endif
+
+namespace Botan {
+
+EMSA::~EMSA() {}
+
+EMSA* get_emsa(const std::string& algo_spec)
+ {
+ SCAN_Name request(algo_spec);
+
+ if(EMSA* emsa = make_a<EMSA>(algo_spec))
+ return emsa;
+
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
+#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>))
+
+#if defined(BOTAN_HAS_EMSA1)
+BOTAN_REGISTER_EMSA_1HASH(EMSA1, "EMSA1");
+#endif
+
+#if defined(BOTAN_HAS_EMSA1_BSI)
+BOTAN_REGISTER_EMSA_1HASH(EMSA1_BSI, "EMSA1_BSI");
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PKCS1)
+BOTAN_REGISTER_NAMED_T(EMSA, "EMSA_PKCS1", EMSA_PCS1v15, EMSA_PKCS1v15::make);
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PSSR)
+BOTAN_REGISTER_NAMED_T(EMSA, "PSSR", PSSR, PSSR::make);
+#endif
+
+#if defined(BOTAN_HAS_EMSA_X931)
+BOTAN_REGISTER_EMSA_1HASH(EMSA_X931, "EMSA_X931");
+#endif
+
+#if defined(BOTAN_HAS_EMSA_RAW)
+BOTAN_REGISTER_EMSA_NAMED_NOARGS(EMSA_Raw, "Raw");
+#endif
+
+}
+
+
diff --git a/src/lib/pk_pad/emsa.h b/src/lib/pk_pad/emsa.h
index b0295636c..d4fd146da 100644
--- a/src/lib/pk_pad/emsa.h
+++ b/src/lib/pk_pad/emsa.h
@@ -15,7 +15,9 @@
namespace Botan {
/**
-* Encoding Method for Signatures, Appendix
+* EMSA, from IEEE 1363s Encoding Method for Signatures, Appendix
+*
+* Any way of encoding/padding signatures
*/
class BOTAN_DLL EMSA
{
@@ -55,7 +57,8 @@ class BOTAN_DLL EMSA
virtual bool verify(const secure_vector<byte>& coded,
const secure_vector<byte>& raw,
size_t key_bits) = 0;
- virtual ~EMSA() {}
+
+ virtual ~EMSA();
};
/**
diff --git a/src/lib/pk_pad/emsa1/emsa1.cpp b/src/lib/pk_pad/emsa1/emsa1.cpp
index 89f0d244a..0031bf263 100644
--- a/src/lib/pk_pad/emsa1/emsa1.cpp
+++ b/src/lib/pk_pad/emsa1/emsa1.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa1.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_1HASH(EMSA1, "EMSA1");
-
namespace {
secure_vector<byte> emsa1_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp b/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
index 81a168b7d..5fc96da8d 100644
--- a/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
+++ b/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
@@ -6,13 +6,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa1_bsi.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_1HASH(EMSA1_BSI, "EMSA1_BSI");
-
/*
* EMSA1 BSI Encode Operation
*/
diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
index e6ce5ec2f..940f91c9a 100644
--- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
+++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
@@ -5,30 +5,23 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa_pkcs1.h>
#include <botan/hash_id.h>
namespace Botan {
-namespace {
-
-EMSA* make_pkcs1v15(const EMSA::Spec& spec)
+EMSA* EMSA_PKCS1v15::make(const EMSA::Spec& spec)
{
if(spec.arg(0) == "Raw")
return new EMSA_PKCS1v15_Raw;
else
{
- if(HashFunction* h = get_hash_function(spec.arg(0)))
- return new EMSA_PKCS1v15(h);
+ if(auto h = HashFunction::create(spec.arg(0)))
+ return new EMSA_PKCS1v15(h.release());
}
return nullptr;
}
-}
-
-BOTAN_REGISTER_NAMED_T(EMSA, "EMSA_PKCS1", EMSA_PCS1v15, make_pkcs1v15);
-
namespace {
secure_vector<byte> emsa3_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
index 7bcae3bd1..19886f80c 100644
--- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
+++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
@@ -21,6 +21,8 @@ namespace Botan {
class BOTAN_DLL EMSA_PKCS1v15 : public EMSA
{
public:
+ static EMSA* make(const EMSA::Spec& spec);
+
/**
* @param hash the hash object to use
*/
diff --git a/src/lib/pk_pad/emsa_pssr/pssr.cpp b/src/lib/pk_pad/emsa_pssr/pssr.cpp
index a4744f8f4..36b0ab64c 100644
--- a/src/lib/pk_pad/emsa_pssr/pssr.cpp
+++ b/src/lib/pk_pad/emsa_pssr/pssr.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/pssr.h>
#include <botan/mgf1.h>
#include <botan/internal/bit_ops.h>
@@ -17,17 +16,15 @@ PSSR* PSSR::make(const Spec& request)
if(request.arg(1, "MGF1") != "MGF1")
return nullptr;
- if(HashFunction* hash = get_hash_function(request.arg(0)))
+ if(auto h = HashFunction::create(request.arg(0)))
{
- const size_t salt_size = request.arg_as_integer(2, hash->output_length());
- return new PSSR(hash, salt_size);
+ const size_t salt_size = request.arg_as_integer(2, h->output_length());
+ return new PSSR(h.release(), salt_size);
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(EMSA, "PSSR", PSSR, PSSR::make);
-
/*
* PSSR Update Operation
*/
diff --git a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
index dcce888f2..4560bd3c3 100644
--- a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
+++ b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa_raw.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_NAMED_NOARGS(EMSA_Raw, "Raw");
-
/*
* EMSA-Raw Encode Operation
*/
diff --git a/src/lib/pk_pad/emsa_x931/emsa_x931.cpp b/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
index fb1e4343a..2feedee1c 100644
--- a/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
+++ b/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
@@ -5,14 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa_x931.h>
#include <botan/hash_id.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_1HASH(EMSA_X931, "EMSA_X931");
-
namespace {
secure_vector<byte> emsa2_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/get_pk_pad.cpp b/src/lib/pk_pad/get_pk_pad.cpp
deleted file mode 100644
index 691de23e2..000000000
--- a/src/lib/pk_pad/get_pk_pad.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-* EMSA/EME Retrieval
-* (C) 1999-2007 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#include <botan/emsa.h>
-#include <botan/eme.h>
-#include <botan/scan_name.h>
-#include <botan/internal/algo_registry.h>
-
-namespace Botan {
-
-EMSA* get_emsa(const std::string& algo_spec)
- {
- SCAN_Name request(algo_spec);
-
- if(EMSA* emsa = make_a<EMSA>(algo_spec))
- return emsa;
-
- throw Algorithm_Not_Found(algo_spec);
- }
-
-EME* get_eme(const std::string& algo_spec)
- {
- SCAN_Name request(algo_spec);
-
- if(EME* eme = make_a<EME>(algo_spec))
- return eme;
-
- if(request.algo_name() == "Raw")
- return nullptr; // No padding
-
- throw Algorithm_Not_Found(algo_spec);
- }
-
-}
diff --git a/src/lib/pk_pad/info.txt b/src/lib/pk_pad/info.txt
index cc3a3fb3b..8cb935faa 100644
--- a/src/lib/pk_pad/info.txt
+++ b/src/lib/pk_pad/info.txt
@@ -10,7 +10,3 @@ rng
eme.h
emsa.h
</header:public>
-
-<header:internal>
-pad_utils.h
-</header:internal>
diff --git a/src/lib/pk_pad/mgf1/mgf1.cpp b/src/lib/pk_pad/mgf1/mgf1.cpp
index 950961f89..34bc4a9a9 100644
--- a/src/lib/pk_pad/mgf1/mgf1.cpp
+++ b/src/lib/pk_pad/mgf1/mgf1.cpp
@@ -7,7 +7,6 @@
#include <botan/mgf1.h>
#include <botan/exceptn.h>
-#include <botan/internal/xor_buf.h>
#include <algorithm>
namespace Botan {
diff --git a/src/lib/pk_pad/pad_utils.h b/src/lib/pk_pad/pad_utils.h
deleted file mode 100644
index 3918e133a..000000000
--- a/src/lib/pk_pad/pad_utils.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-* Public Key Padding Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_PK_PAD_UTILS_H__
-#define BOTAN_PK_PAD_UTILS_H__
-
-#include <botan/internal/algo_registry.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/dlies/dlies.cpp b/src/lib/pubkey/dlies/dlies.cpp
index 4b1a63f2c..708064d27 100644
--- a/src/lib/pubkey/dlies/dlies.cpp
+++ b/src/lib/pubkey/dlies/dlies.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/dlies.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/lib/pubkey/ecdh/ecdh.cpp b/src/lib/pubkey/ecdh/ecdh.cpp
index bad0f2c0b..6b589df9b 100644
--- a/src/lib/pubkey/ecdh/ecdh.cpp
+++ b/src/lib/pubkey/ecdh/ecdh.cpp
@@ -12,6 +12,8 @@
namespace Botan {
+ECDH_PublicKey::ECDH_PublicKey() {}
+
namespace {
/**
diff --git a/src/lib/pubkey/ecdh/ecdh.h b/src/lib/pubkey/ecdh/ecdh.h
index ef3e8ef7a..2f892436c 100644
--- a/src/lib/pubkey/ecdh/ecdh.h
+++ b/src/lib/pubkey/ecdh/ecdh.h
@@ -56,7 +56,7 @@ class BOTAN_DLL ECDH_PublicKey : public virtual EC_PublicKey
{ return unlock(EC2OSP(public_point(), PointGFp::UNCOMPRESSED)); }
protected:
- ECDH_PublicKey() {}
+ ECDH_PublicKey();
};
/**
diff --git a/src/lib/pubkey/mce/binary_matrix.cpp b/src/lib/pubkey/mce/binary_matrix.cpp
index 12c842669..45c9aab13 100644
--- a/src/lib/pubkey/mce/binary_matrix.cpp
+++ b/src/lib/pubkey/mce/binary_matrix.cpp
@@ -10,7 +10,6 @@
*/
#include <botan/internal/binary_matrix.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/lib/pubkey/mce/mceliece.cpp b/src/lib/pubkey/mce/mceliece.cpp
index 6bbe93ce3..08b3f13a3 100644
--- a/src/lib/pubkey/mce/mceliece.cpp
+++ b/src/lib/pubkey/mce/mceliece.cpp
@@ -16,7 +16,6 @@
#include <botan/code_based_util.h>
#include <botan/goppa_code.h>
#include <botan/internal/bit_ops.h>
-#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/lib/pubkey/rfc6979/rfc6979.cpp b/src/lib/pubkey/rfc6979/rfc6979.cpp
index 5f606891d..f749b039f 100644
--- a/src/lib/pubkey/rfc6979/rfc6979.cpp
+++ b/src/lib/pubkey/rfc6979/rfc6979.cpp
@@ -7,8 +7,8 @@
#include <botan/rfc6979.h>
#include <botan/hmac_drbg.h>
+#include <botan/mac.h>
#include <botan/scan_name.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -31,7 +31,7 @@ RFC6979_Nonce_Generator::RFC6979_Nonce_Generator(const std::string& hash,
m_order(order),
m_qlen(m_order.bits()),
m_rlen(m_qlen / 8 + (m_qlen % 8 ? 1 : 0)),
- m_hmac_drbg(new HMAC_DRBG(make_message_auth("HMAC(" + hash + ")").release())),
+ m_hmac_drbg(new HMAC_DRBG(MessageAuthenticationCode::create("HMAC(" + hash + ")").release())),
m_rng_in(m_rlen * 2),
m_rng_out(m_rlen)
{
diff --git a/src/lib/rng/hmac_rng/hmac_rng.cpp b/src/lib/rng/hmac_rng/hmac_rng.cpp
index 36003385a..5456b3bac 100644
--- a/src/lib/rng/hmac_rng/hmac_rng.cpp
+++ b/src/lib/rng/hmac_rng/hmac_rng.cpp
@@ -6,9 +6,7 @@
*/
#include <botan/hmac_rng.h>
-#include <botan/get_byte.h>
#include <botan/entropy_src.h>
-#include <botan/internal/xor_buf.h>
#include <algorithm>
#include <chrono>
diff --git a/src/lib/rng/rng.cpp b/src/lib/rng/rng.cpp
index 76e868b93..d4fd5fb10 100644
--- a/src/lib/rng/rng.cpp
+++ b/src/lib/rng/rng.cpp
@@ -7,14 +7,16 @@
#include <botan/rng.h>
#include <botan/hmac_rng.h>
-#include <botan/lookup.h>
namespace Botan {
RandomNumberGenerator* RandomNumberGenerator::make_rng()
{
- std::unique_ptr<MessageAuthenticationCode> h1(make_message_auth("HMAC(SHA-512)"));
- std::unique_ptr<MessageAuthenticationCode> h2(h1->clone());
+ std::unique_ptr<MessageAuthenticationCode> h1(MessageAuthenticationCode::create("HMAC(SHA-512)"));
+ std::unique_ptr<MessageAuthenticationCode> h2(MessageAuthenticationCode::create("HMAC(SHA-512)"));
+
+ if(!h1 || !h2)
+ throw Algorithm_Not_Found("HMAC_RNG HMACs");
std::unique_ptr<RandomNumberGenerator> rng(new HMAC_RNG(h1.release(), h2.release()));
rng->reseed(256);
diff --git a/src/lib/rng/x931_rng/x931_rng.cpp b/src/lib/rng/x931_rng/x931_rng.cpp
index 976e324c3..d531cf4a9 100644
--- a/src/lib/rng/x931_rng/x931_rng.cpp
+++ b/src/lib/rng/x931_rng/x931_rng.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/x931_rng.h>
-#include <botan/internal/xor_buf.h>
#include <algorithm>
namespace Botan {
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp
index 9841f99a2..0a32c720b 100644
--- a/src/lib/stream/chacha/chacha.cpp
+++ b/src/lib/stream/chacha/chacha.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/chacha.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_STREAM_CIPHER_NOARGS(ChaCha);
-
void ChaCha::chacha(byte output[64], const u32bit input[16])
{
u32bit x00 = input[ 0], x01 = input[ 1], x02 = input[ 2], x03 = input[ 3],
diff --git a/src/lib/stream/ctr/ctr.cpp b/src/lib/stream/ctr/ctr.cpp
index f1cdc7c42..e90bb43a4 100644
--- a/src/lib/stream/ctr/ctr.cpp
+++ b/src/lib/stream/ctr/ctr.cpp
@@ -5,19 +5,16 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/ctr.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(StreamCipher, "CTR-BE", CTR_BE, CTR_BE::make);
-
CTR_BE* CTR_BE::make(const Spec& spec)
{
if(spec.algo_name() == "CTR-BE" && spec.arg_count() == 1)
{
- if(BlockCipher* c = get_block_cipher(spec.arg(0)))
- return new CTR_BE(c);
+ if(auto c = BlockCipher::create(spec.arg(0)))
+ return new CTR_BE(c.release());
}
return nullptr;
}
diff --git a/src/lib/stream/info.txt b/src/lib/stream/info.txt
index 8dc30936d..59b5d577a 100644
--- a/src/lib/stream/info.txt
+++ b/src/lib/stream/info.txt
@@ -3,7 +3,3 @@ define STREAM_CIPHER 20131128
<header:public>
stream_cipher.h
</header:public>
-
-<header:internal>
-stream_utils.h
-</header:internal>
diff --git a/src/lib/stream/ofb/ofb.cpp b/src/lib/stream/ofb/ofb.cpp
index b98f81be3..e8cb463db 100644
--- a/src/lib/stream/ofb/ofb.cpp
+++ b/src/lib/stream/ofb/ofb.cpp
@@ -5,19 +5,16 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/ofb.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(StreamCipher, "OFB", OFB, OFB::make);
-
OFB* OFB::make(const Spec& spec)
{
if(spec.algo_name() == "OFB" && spec.arg_count() == 1)
{
- if(BlockCipher* c = get_block_cipher(spec.arg(0)))
- return new OFB(c);
+ if(auto c = BlockCipher::create(spec.arg(0)))
+ return new OFB(c.release());
}
return nullptr;
}
diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp
index 3fd0d2276..6146e2818 100644
--- a/src/lib/stream/rc4/rc4.cpp
+++ b/src/lib/stream/rc4/rc4.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/rc4.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(StreamCipher, "RC4", RC4, RC4::make);
-
RC4* RC4::make(const Spec& spec)
{
if(spec.algo_name() == "RC4")
diff --git a/src/lib/stream/salsa20/salsa20.cpp b/src/lib/stream/salsa20/salsa20.cpp
index daf01dd0a..1d3fe3d28 100644
--- a/src/lib/stream/salsa20/salsa20.cpp
+++ b/src/lib/stream/salsa20/salsa20.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/salsa20.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_STREAM_CIPHER_NOARGS(Salsa20);
-
namespace {
#define SALSA20_QUARTER_ROUND(x1, x2, x3, x4) \
diff --git a/src/lib/stream/stream_cipher.cpp b/src/lib/stream/stream_cipher.cpp
new file mode 100644
index 000000000..060e65d86
--- /dev/null
+++ b/src/lib/stream/stream_cipher.cpp
@@ -0,0 +1,73 @@
+/*
+* Stream Ciphers
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/stream_cipher.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_CHACHA)
+ #include <botan/chacha.h>
+#endif
+
+#if defined(BOTAN_HAS_SALSA20)
+ #include <botan/salsa20.h>
+#endif
+
+#if defined(BOTAN_HAS_CTR_BE)
+ #include <botan/ctr.h>
+#endif
+
+#if defined(BOTAN_HAS_OFB)
+ #include <botan/ofb.h>
+#endif
+
+#if defined(BOTAN_HAS_RC4)
+ #include <botan/rc4.h>
+#endif
+
+namespace Botan {
+
+std::unique_ptr<StreamCipher> StreamCipher::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<StreamCipher>(make_a<StreamCipher>(algo_spec, provider));
+ }
+
+std::vector<std::string> StreamCipher::providers(const std::string& algo_spec)
+ {
+ return providers_of<StreamCipher>(StreamCipher::Spec(algo_spec));
+ }
+
+StreamCipher::StreamCipher() {}
+StreamCipher::~StreamCipher() {}
+
+void StreamCipher::set_iv(const byte[], size_t iv_len)
+ {
+ if(!valid_iv_length(iv_len))
+ throw Invalid_IV_Length(name(), iv_len);
+ }
+
+#if defined(BOTAN_HAS_CHACHA)
+BOTAN_REGISTER_T_NOARGS(StreamCipher, ChaCha);
+#endif
+
+#if defined(BOTAN_HAS_SALSA20)
+BOTAN_REGISTER_T_NOARGS(StreamCipher, Salsa20);
+#endif
+
+#if defined(BOTAN_HAS_CTR_BE)
+BOTAN_REGISTER_NAMED_T(StreamCipher, "CTR-BE", CTR_BE, CTR_BE::make);
+#endif
+
+#if defined(BOTAN_HAS_OFB)
+BOTAN_REGISTER_NAMED_T(StreamCipher, "OFB", OFB, OFB::make);
+#endif
+
+#if defined(BOTAN_HAS_RC4)
+BOTAN_REGISTER_NAMED_T(StreamCipher, "RC4", RC4, RC4::make);
+#endif
+
+}
diff --git a/src/lib/stream/stream_cipher.h b/src/lib/stream/stream_cipher.h
index bfdd152a7..8c9b28147 100644
--- a/src/lib/stream/stream_cipher.h
+++ b/src/lib/stream/stream_cipher.h
@@ -20,6 +20,21 @@ namespace Botan {
class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
{
public:
+ typedef SCAN_Name Spec;
+
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<StreamCipher> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
+
/**
* Encrypt or decrypt a message
* @param in the plaintext
@@ -53,11 +68,7 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
* @param iv the initialization vector
* @param iv_len the length of the IV in bytes
*/
- virtual void set_iv(const byte[], size_t iv_len)
- {
- if(iv_len)
- throw Invalid_IV_Length(name(), iv_len);
- }
+ virtual void set_iv(const byte[], size_t iv_len);
/**
* @param iv_len the length of the IV in bytes
@@ -70,7 +81,8 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
*/
virtual StreamCipher* clone() const = 0;
- typedef SCAN_Name Spec;
+ StreamCipher();
+ virtual ~StreamCipher();
};
}
diff --git a/src/lib/stream/stream_utils.h b/src/lib/stream/stream_utils.h
deleted file mode 100644
index 8ba8d4b01..000000000
--- a/src/lib/stream/stream_utils.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-* Stream Cipher Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_STREAM_CIPHER_UTILS_H__
-#define BOTAN_STREAM_CIPHER_UTILS_H__
-
-#include <botan/stream_cipher.h>
-#include <botan/internal/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>))
-
-}
-
-#endif
diff --git a/src/lib/tls/msg_hello_verify.cpp b/src/lib/tls/msg_hello_verify.cpp
index a3c439750..c1dc574d4 100644
--- a/src/lib/tls/msg_hello_verify.cpp
+++ b/src/lib/tls/msg_hello_verify.cpp
@@ -7,7 +7,6 @@
#include <botan/internal/tls_messages.h>
#include <botan/mac.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -36,7 +35,7 @@ Hello_Verify_Request::Hello_Verify_Request(const std::vector<byte>& client_hello
const std::string& client_identity,
const SymmetricKey& secret_key)
{
- std::unique_ptr<MessageAuthenticationCode> hmac(get_mac("HMAC(SHA-256)"));
+ std::unique_ptr<MessageAuthenticationCode> hmac(MessageAuthenticationCode::create("HMAC(SHA-256)"));
hmac->set_key(secret_key);
hmac->update_be(client_hello_bits.size());
diff --git a/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp b/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp
index 508f8ff2f..ed207972e 100644
--- a/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp
+++ b/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp
@@ -8,7 +8,6 @@
#include <botan/tls_session_manager_sql.h>
#include <botan/database.h>
#include <botan/pbkdf.h>
-#include <botan/lookup.h>
#include <botan/hex.h>
#include <botan/loadstor.h>
#include <chrono>
diff --git a/src/lib/tls/tls_ciphersuite.cpp b/src/lib/tls/tls_ciphersuite.cpp
index c0f9dbf76..4fdf33811 100644
--- a/src/lib/tls/tls_ciphersuite.cpp
+++ b/src/lib/tls/tls_ciphersuite.cpp
@@ -7,7 +7,6 @@
#include <botan/tls_ciphersuite.h>
#include <botan/parsing.h>
-#include <botan/lookup.h>
#include <botan/block_cipher.h>
#include <botan/stream_cipher.h>
#include <botan/hash.h>
@@ -104,16 +103,13 @@ namespace {
bool have_hash(const std::string& prf)
{
- return (!get_hash_function_providers(prf).empty());
+ return (HashFunction::providers(prf).size() > 0);
}
bool have_cipher(const std::string& cipher)
{
- if(!get_block_cipher_providers(cipher).empty())
- return true;
- if(!get_stream_cipher_providers(cipher).empty())
- return true;
- return false;
+ return (BlockCipher::providers(cipher).size() > 0) ||
+ (StreamCipher::providers(cipher).size() > 0);
}
}
diff --git a/src/lib/tls/tls_handshake_hash.cpp b/src/lib/tls/tls_handshake_hash.cpp
index 94c2774c5..615767cc2 100644
--- a/src/lib/tls/tls_handshake_hash.cpp
+++ b/src/lib/tls/tls_handshake_hash.cpp
@@ -7,7 +7,6 @@
#include <botan/internal/tls_handshake_hash.h>
#include <botan/tls_exceptn.h>
-#include <botan/lookup.h>
#include <botan/hash.h>
namespace Botan {
@@ -29,7 +28,7 @@ secure_vector<byte> Handshake_Hash::final(Protocol_Version version,
return mac_algo.c_str();
};
- std::unique_ptr<HashFunction> hash(make_hash_function(choose_hash()));
+ std::unique_ptr<HashFunction> hash(HashFunction::create(choose_hash()));
hash->update(data);
return hash->final();
}
diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp
index 3ba02f039..71542de16 100644
--- a/src/lib/tls/tls_record.cpp
+++ b/src/lib/tls/tls_record.cpp
@@ -12,8 +12,6 @@
#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>
#include <botan/rng.h>
namespace Botan {
@@ -63,20 +61,17 @@ Connection_Cipher_State::Connection_Cipher_State(Protocol_Version version,
return;
}
- if(BlockCipher* bc = get_block_cipher(cipher_algo))
- {
- m_block_cipher.reset(bc);
- m_block_cipher->set_key(cipher_key);
- m_block_cipher_cbc_state = iv.bits_of();
- m_block_size = bc->block_size();
-
- if(version.supports_explicit_cbc_ivs())
- m_iv_size = m_block_size;
- }
- else
+ m_block_cipher = BlockCipher::create(cipher_algo);
+ m_mac = MessageAuthenticationCode::create("HMAC(" + mac_algo + ")");
+ if(!m_block_cipher)
throw Invalid_Argument("Unknown TLS cipher " + cipher_algo);
- m_mac.reset(get_mac("HMAC(" + mac_algo + ")"));
+ m_block_cipher->set_key(cipher_key);
+ m_block_cipher_cbc_state = iv.bits_of();
+ m_block_size = m_block_cipher->block_size();
+
+ if(version.supports_explicit_cbc_ivs())
+ m_iv_size = m_block_size;
m_mac->set_key(mac_key);
}
diff --git a/src/lib/tls/tls_version.h b/src/lib/tls/tls_version.h
index a025b27ba..73968bb8c 100644
--- a/src/lib/tls/tls_version.h
+++ b/src/lib/tls/tls_version.h
@@ -8,7 +8,7 @@
#ifndef BOTAN_TLS_PROTOCOL_VERSION_H__
#define BOTAN_TLS_PROTOCOL_VERSION_H__
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <string>
namespace Botan {
diff --git a/src/lib/utils/cpuid.cpp b/src/lib/utils/cpuid.cpp
index 817bf4f52..218b6553c 100644
--- a/src/lib/utils/cpuid.cpp
+++ b/src/lib/utils/cpuid.cpp
@@ -7,7 +7,7 @@
#include <botan/cpuid.h>
#include <botan/types.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <botan/mem_ops.h>
#include <ostream>
diff --git a/src/lib/utils/get_byte.h b/src/lib/utils/get_byte.h
index 0846befbd..14f55b97b 100644
--- a/src/lib/utils/get_byte.h
+++ b/src/lib/utils/get_byte.h
@@ -12,18 +12,6 @@
namespace Botan {
-/**
-* Byte extraction
-* @param byte_num which byte to extract, 0 == highest byte
-* @param input the value to extract from
-* @return byte byte_num of input
-*/
-template<typename T> inline byte get_byte(size_t byte_num, T input)
- {
- return static_cast<byte>(
- input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)
- );
- }
}
diff --git a/src/lib/utils/info.txt b/src/lib/utils/info.txt
index b8c7b85d2..7d3216b1c 100644
--- a/src/lib/utils/info.txt
+++ b/src/lib/utils/info.txt
@@ -1,4 +1,4 @@
-define UTIL_FUNCTIONS 20140123
+define UTIL_FUNCTIONS 20150919
load_on always
@@ -10,7 +10,6 @@ charset.h
cpuid.h
database.h
exceptn.h
-get_byte.h
loadstor.h
mem_ops.h
mul128.h
@@ -29,5 +28,4 @@ rounding.h
semaphore.h
stl_util.h
ta_utils.h
-xor_buf.h
</header:internal>
diff --git a/src/lib/utils/loadstor.h b/src/lib/utils/loadstor.h
index d3871480c..53700fc86 100644
--- a/src/lib/utils/loadstor.h
+++ b/src/lib/utils/loadstor.h
@@ -11,7 +11,6 @@
#include <botan/types.h>
#include <botan/bswap.h>
-#include <botan/get_byte.h>
#include <botan/mem_ops.h>
#include <vector>
@@ -40,6 +39,19 @@
namespace Botan {
/**
+* Byte extraction
+* @param byte_num which byte to extract, 0 == highest byte
+* @param input the value to extract from
+* @return byte byte_num of input
+*/
+template<typename T> inline byte get_byte(size_t byte_num, T input)
+ {
+ return static_cast<byte>(
+ input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)
+ );
+ }
+
+/**
* Make a u16bit from two bytes
* @param i0 the first byte
* @param i1 the second byte
diff --git a/src/lib/utils/mem_ops.h b/src/lib/utils/mem_ops.h
index f9e39fa31..6ea7bdafe 100644
--- a/src/lib/utils/mem_ops.h
+++ b/src/lib/utils/mem_ops.h
@@ -10,6 +10,7 @@
#include <botan/types.h>
#include <cstring>
+#include <vector>
namespace Botan {
@@ -70,6 +71,132 @@ template<typename T> inline bool same_mem(const T* p1, const T* p2, size_t n)
return difference == 0;
}
+/**
+* XOR arrays. Postcondition out[i] = in[i] ^ out[i] forall i = 0...length
+* @param out the input/output buffer
+* @param in the read-only input buffer
+* @param length the length of the buffers
+*/
+template<typename T>
+void xor_buf(T out[], const T in[], size_t length)
+ {
+ while(length >= 8)
+ {
+ out[0] ^= in[0]; out[1] ^= in[1];
+ out[2] ^= in[2]; out[3] ^= in[3];
+ out[4] ^= in[4]; out[5] ^= in[5];
+ out[6] ^= in[6]; out[7] ^= in[7];
+
+ out += 8; in += 8; length -= 8;
+ }
+
+ for(size_t i = 0; i != length; ++i)
+ out[i] ^= in[i];
+ }
+
+/**
+* XOR arrays. Postcondition out[i] = in[i] ^ in2[i] forall i = 0...length
+* @param out the output buffer
+* @param in the first input buffer
+* @param in2 the second output buffer
+* @param length the length of the three buffers
+*/
+template<typename T> void xor_buf(T out[],
+ const T in[],
+ const T in2[],
+ size_t length)
+ {
+ while(length >= 8)
+ {
+ out[0] = in[0] ^ in2[0];
+ out[1] = in[1] ^ in2[1];
+ out[2] = in[2] ^ in2[2];
+ out[3] = in[3] ^ in2[3];
+ out[4] = in[4] ^ in2[4];
+ out[5] = in[5] ^ in2[5];
+ out[6] = in[6] ^ in2[6];
+ out[7] = in[7] ^ in2[7];
+
+ in += 8; in2 += 8; out += 8; length -= 8;
+ }
+
+ for(size_t i = 0; i != length; ++i)
+ out[i] = in[i] ^ in2[i];
+ }
+
+#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK
+
+template<>
+inline void xor_buf<byte>(byte out[], const byte in[], size_t length)
+ {
+ while(length >= 8)
+ {
+ *reinterpret_cast<u64bit*>(out) ^= *reinterpret_cast<const u64bit*>(in);
+ out += 8; in += 8; length -= 8;
+ }
+
+ for(size_t i = 0; i != length; ++i)
+ out[i] ^= in[i];
+ }
+
+template<>
+inline void xor_buf<byte>(byte out[],
+ const byte in[],
+ const byte in2[],
+ size_t length)
+ {
+ while(length >= 8)
+ {
+ *reinterpret_cast<u64bit*>(out) =
+ *reinterpret_cast<const u64bit*>(in) ^
+ *reinterpret_cast<const u64bit*>(in2);
+
+ in += 8; in2 += 8; out += 8; length -= 8;
+ }
+
+ for(size_t i = 0; i != length; ++i)
+ out[i] = in[i] ^ in2[i];
+ }
+
+#endif
+
+template<typename Alloc, typename Alloc2>
+void xor_buf(std::vector<byte, Alloc>& out,
+ const std::vector<byte, Alloc2>& in,
+ size_t n)
+ {
+ xor_buf(out.data(), in.data(), n);
+ }
+
+template<typename Alloc>
+void xor_buf(std::vector<byte, Alloc>& out,
+ const byte* in,
+ size_t n)
+ {
+ xor_buf(out.data(), in, n);
+ }
+
+template<typename Alloc, typename Alloc2>
+void xor_buf(std::vector<byte, Alloc>& out,
+ const byte* in,
+ const std::vector<byte, Alloc2>& in2,
+ size_t n)
+ {
+ xor_buf(out.data(), in, in2.data(), n);
+ }
+
+template<typename T, typename Alloc, typename Alloc2>
+std::vector<T, Alloc>&
+operator^=(std::vector<T, Alloc>& out,
+ const std::vector<T, Alloc2>& in)
+ {
+ if(out.size() < in.size())
+ out.resize(in.size());
+
+ xor_buf(out.data(), in.data(), in.size());
+ return out;
+ }
+
}
#endif
diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp
index 4feea8d60..ea89c8e5f 100644
--- a/src/lib/utils/parsing.cpp
+++ b/src/lib/utils/parsing.cpp
@@ -9,7 +9,7 @@
#include <botan/parsing.h>
#include <botan/exceptn.h>
#include <botan/charset.h>
-#include <botan/get_byte.h>
+#include <botan/loadstor.h>
#include <limits>
#include <set>
#include <stdexcept>
diff --git a/src/lib/vendor/openssl/openssl_block.cpp b/src/lib/vendor/openssl/openssl_block.cpp
index b74f184c7..5c28f46b1 100644
--- a/src/lib/vendor/openssl/openssl_block.cpp
+++ b/src/lib/vendor/openssl/openssl_block.cpp
@@ -1,11 +1,12 @@
/*
-* OpenSSL Block Cipher
+* Block Ciphers via OpenSSL
* (C) 1999-2010,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/block_utils.h>
+#include <botan/block_cipher.h>
+#include <botan/internal/algo_registry.h>
#include <botan/internal/openssl.h>
#include <openssl/evp.h>
diff --git a/src/lib/vendor/openssl/openssl_hash.cpp b/src/lib/vendor/openssl/openssl_hash.cpp
index 6e055c0e6..c89dd777d 100644
--- a/src/lib/vendor/openssl/openssl_hash.cpp
+++ b/src/lib/vendor/openssl/openssl_hash.cpp
@@ -5,8 +5,9 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/hash_utils.h>
+#include <botan/hash.h>
#include <botan/internal/openssl.h>
+#include <botan/internal/algo_registry.h>
#include <openssl/evp.h>
namespace Botan {
diff --git a/src/lib/vendor/openssl/openssl_rc4.cpp b/src/lib/vendor/openssl/openssl_rc4.cpp
index ac30cd288..1f5675095 100644
--- a/src/lib/vendor/openssl/openssl_rc4.cpp
+++ b/src/lib/vendor/openssl/openssl_rc4.cpp
@@ -5,7 +5,8 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
+#include <botan/stream_cipher.h>
+#include <botan/internal/algo_registry.h>
#include <botan/internal/openssl.h>
#include <botan/parsing.h>
#include <openssl/rc4.h>