aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/base/lookup.h28
-rw-r--r--src/lib/kdf/kdf.cpp2
-rw-r--r--src/lib/kdf/prf_tls/prf_tls.cpp6
-rw-r--r--src/lib/misc/rfc3394/rfc3394.cpp8
-rw-r--r--src/lib/misc/srp6/srp6.cpp10
-rw-r--r--src/lib/pubkey/ecies/ecies.cpp21
-rw-r--r--src/lib/pubkey/ecies/ecies.h7
-rw-r--r--src/lib/tls/tls_cbc/tls_cbc.cpp9
-rw-r--r--src/lib/tls/tls_handshake_hash.cpp6
-rw-r--r--src/lib/x509/x509_ca.cpp4
10 files changed, 26 insertions, 75 deletions
diff --git a/src/lib/base/lookup.h b/src/lib/base/lookup.h
index 391891d09..5237ec77a 100644
--- a/src/lib/base/lookup.h
+++ b/src/lib/base/lookup.h
@@ -44,14 +44,11 @@ inline BlockCipher* get_block_cipher(const std::string& algo_spec,
return BlockCipher::create(algo_spec, provider).release();
}
-BOTAN_DEPRECATED("Use BlockCipher::create")
+BOTAN_DEPRECATED("Use BlockCipher::create_or_throw")
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);
+ return BlockCipher::create_or_throw(algo_spec, provider);
}
BOTAN_DEPRECATED("Use BlockCipher::providers")
@@ -74,14 +71,11 @@ inline StreamCipher* get_stream_cipher(const std::string& algo_spec,
return StreamCipher::create(algo_spec, provider).release();
}
-BOTAN_DEPRECATED("Use StreamCipher::create")
+BOTAN_DEPRECATED("Use StreamCipher::create_or_throw")
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);
+ return StreamCipher::create_or_throw(algo_spec, provider));
}
BOTAN_DEPRECATED("Use StreamCipher::providers")
@@ -104,14 +98,11 @@ inline HashFunction* get_hash_function(const std::string& algo_spec,
return HashFunction::create(algo_spec, provider).release();
}
-BOTAN_DEPRECATED("Use HashFunction::create")
+BOTAN_DEPRECATED("Use HashFunction::create_or_throw")
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);
+ return HashFunction::create_or_throw(algo_spec, provider));
}
BOTAN_DEPRECATED("Use HashFunction::create")
@@ -141,14 +132,11 @@ inline MessageAuthenticationCode* get_mac(const std::string& algo_spec,
return MessageAuthenticationCode::create(algo_spec, provider).release();
}
-BOTAN_DEPRECATED("MessageAuthenticationCode::create")
+BOTAN_DEPRECATED("MessageAuthenticationCode::create_or_throw")
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);
+ return MessageAuthenticationCode::create(algo_spec, provider);
}
BOTAN_DEPRECATED("MessageAuthenticationCode::providers")
diff --git a/src/lib/kdf/kdf.cpp b/src/lib/kdf/kdf.cpp
index f8f822809..94694c70c 100644
--- a/src/lib/kdf/kdf.cpp
+++ b/src/lib/kdf/kdf.cpp
@@ -195,7 +195,7 @@ KDF::create_or_throw(const std::string& algo,
{
return bc;
}
- throw Lookup_Error("Block cipher", algo, provider);
+ throw Lookup_Error("KDF", algo, provider);
}
std::vector<std::string> KDF::providers(const std::string& algo_spec)
diff --git a/src/lib/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp
index e83d07692..6f247ab6e 100644
--- a/src/lib/kdf/prf_tls/prf_tls.cpp
+++ b/src/lib/kdf/prf_tls/prf_tls.cpp
@@ -11,11 +11,9 @@
namespace Botan {
TLS_PRF::TLS_PRF() :
- m_hmac_md5(MessageAuthenticationCode::create("HMAC(MD5)")),
- m_hmac_sha1(MessageAuthenticationCode::create("HMAC(SHA-1)"))
+ m_hmac_md5(MessageAuthenticationCode::create_or_throw("HMAC(MD5)")),
+ m_hmac_sha1(MessageAuthenticationCode::create_or_throw("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/misc/rfc3394/rfc3394.cpp b/src/lib/misc/rfc3394/rfc3394.cpp
index 1044e4de4..9ec053ef3 100644
--- a/src/lib/misc/rfc3394/rfc3394.cpp
+++ b/src/lib/misc/rfc3394/rfc3394.cpp
@@ -22,9 +22,7 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key,
throw Invalid_Argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key wrap");
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);
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(cipher_name));
aes->set_key(kek);
const size_t n = key.size() / 8;
@@ -69,9 +67,7 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key,
throw Invalid_Argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key unwrap");
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);
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(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 7fca6461f..f54726151 100644
--- a/src/lib/misc/srp6/srp6.cpp
+++ b/src/lib/misc/srp6/srp6.cpp
@@ -18,10 +18,7 @@ BigInt hash_seq(const std::string& hash_id,
const BigInt& in1,
const BigInt& in2)
{
- std::unique_ptr<HashFunction> hash_fn(HashFunction::create(hash_id));
-
- if(!hash_fn)
- throw Algorithm_Not_Found(hash_id);
+ std::unique_ptr<HashFunction> hash_fn(HashFunction::create_or_throw(hash_id));
hash_fn->update(BigInt::encode_1363(in1, pad_to));
hash_fn->update(BigInt::encode_1363(in2, pad_to));
@@ -34,10 +31,7 @@ BigInt compute_x(const std::string& hash_id,
const std::string& password,
const std::vector<byte>& salt)
{
- std::unique_ptr<HashFunction> hash_fn(HashFunction::create(hash_id));
-
- if(!hash_fn)
- throw Algorithm_Not_Found(hash_id);
+ std::unique_ptr<HashFunction> hash_fn(HashFunction::create_or_throw(hash_id));
hash_fn->update(identifier);
hash_fn->update(":");
diff --git a/src/lib/pubkey/ecies/ecies.cpp b/src/lib/pubkey/ecies/ecies.cpp
index ba7140bd0..fbf98cbad 100644
--- a/src/lib/pubkey/ecies/ecies.cpp
+++ b/src/lib/pubkey/ecies/ecies.cpp
@@ -143,8 +143,7 @@ SymmetricKey ECIES_KA_Operation::derive_secret(const std::vector<byte>& eph_publ
throw Invalid_Argument("ECIES: other public key point is zero");
}
- std::unique_ptr<KDF> kdf = m_params.create_kdf();
- BOTAN_ASSERT(kdf != nullptr, "KDF is found");
+ std::unique_ptr<KDF> kdf = Botan::KDF::create_or_throw(m_params.kdf_spec());
PointGFp other_point = other_public_key_point;
@@ -184,17 +183,6 @@ ECIES_KA_Params::ECIES_KA_Params(const EC_Group& domain, const std::string& kdf_
{
}
-std::unique_ptr<KDF> ECIES_KA_Params::create_kdf() const
- {
- std::unique_ptr<KDF> kdf = Botan::KDF::create(m_kdf_spec);
- if(kdf == nullptr)
- {
- throw Algorithm_Not_Found(m_kdf_spec);
- }
- return kdf;
- }
-
-
ECIES_System_Params::ECIES_System_Params(const EC_Group& domain, const std::string& kdf_spec,
const std::string& dem_algo_spec, size_t dem_key_len,
const std::string& mac_spec, size_t mac_key_len,
@@ -222,12 +210,7 @@ ECIES_System_Params::ECIES_System_Params(const EC_Group& domain, const std::stri
std::unique_ptr<MessageAuthenticationCode> ECIES_System_Params::create_mac() const
{
- std::unique_ptr<MessageAuthenticationCode> mac = Botan::MessageAuthenticationCode::create(m_mac_spec);
- if(mac == nullptr)
- {
- throw Algorithm_Not_Found(m_mac_spec);
- }
- return mac;
+ return Botan::MessageAuthenticationCode::create_or_throw(m_mac_spec);
}
std::unique_ptr<Cipher_Mode> ECIES_System_Params::create_cipher(Botan::Cipher_Dir direction) const
diff --git a/src/lib/pubkey/ecies/ecies.h b/src/lib/pubkey/ecies/ecies.h
index 94b0bd576..3f7a2e48b 100644
--- a/src/lib/pubkey/ecies/ecies.h
+++ b/src/lib/pubkey/ecies/ecies.h
@@ -70,8 +70,6 @@ class BOTAN_DLL ECIES_KA_Params
virtual ~ECIES_KA_Params() = default;
- std::unique_ptr<KDF> create_kdf() const;
-
inline const EC_Group& domain() const
{
return m_domain;
@@ -107,6 +105,11 @@ class BOTAN_DLL ECIES_KA_Params
return m_compression_mode;
}
+ const std::string& kdf_spec() const
+ {
+ return m_kdf_spec;
+ }
+
private:
const EC_Group m_domain;
const std::string m_kdf_spec;
diff --git a/src/lib/tls/tls_cbc/tls_cbc.cpp b/src/lib/tls/tls_cbc/tls_cbc.cpp
index 71ad41114..ef397e44d 100644
--- a/src/lib/tls/tls_cbc/tls_cbc.cpp
+++ b/src/lib/tls/tls_cbc/tls_cbc.cpp
@@ -33,13 +33,8 @@ TLS_CBC_HMAC_AEAD_Mode::TLS_CBC_HMAC_AEAD_Mode(const std::string& cipher_name,
m_mac_keylen(mac_keylen),
m_use_encrypt_then_mac(use_encrypt_then_mac)
{
- m_cipher = BlockCipher::create(m_cipher_name);
- if(!m_cipher)
- throw Algorithm_Not_Found(m_cipher_name);
-
- m_mac = MessageAuthenticationCode::create("HMAC(" + m_mac_name + ")");
- if(!m_mac)
- throw Algorithm_Not_Found("HMAC(" + m_mac_name + ")");
+ m_cipher = BlockCipher::create_or_throw(m_cipher_name);
+ m_mac = MessageAuthenticationCode::create_or_throw("HMAC(" + m_mac_name + ")");
m_tag_size = m_mac->output_length();
m_block_size = m_cipher->block_size();
diff --git a/src/lib/tls/tls_handshake_hash.cpp b/src/lib/tls/tls_handshake_hash.cpp
index 4f78bebbc..540f1de14 100644
--- a/src/lib/tls/tls_handshake_hash.cpp
+++ b/src/lib/tls/tls_handshake_hash.cpp
@@ -29,11 +29,7 @@ secure_vector<byte> Handshake_Hash::final(Protocol_Version version,
};
const std::string hash_algo = choose_hash();
- std::unique_ptr<HashFunction> hash(HashFunction::create(hash_algo));
- if(!hash)
- {
- throw Algorithm_Not_Found(hash_algo);
- }
+ std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw(hash_algo));
hash->update(m_data);
return hash->final();
}
diff --git a/src/lib/x509/x509_ca.cpp b/src/lib/x509/x509_ca.cpp
index 179d903c4..bc3763c5a 100644
--- a/src/lib/x509/x509_ca.cpp
+++ b/src/lib/x509/x509_ca.cpp
@@ -232,9 +232,7 @@ PK_Signer* choose_sig_format(const Private_Key& key,
{
const std::string algo_name = key.algo_name();
- std::unique_ptr<HashFunction> hash(HashFunction::create(hash_fn));
- if(!hash)
- throw Algorithm_Not_Found(hash_fn);
+ std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw(hash_fn));
if(key.max_input_bits() < hash->output_length() * 8)
throw Invalid_Argument("Key is too small for chosen hash function");