aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--checks/dolook2.cpp10
-rw-r--r--src/core/libstate/def_alg.cpp31
-rw-r--r--src/core/rng.cpp2
-rw-r--r--src/kdf/pbkdf1/pbkdf1.cpp16
-rw-r--r--src/kdf/pbkdf1/pbkdf1.h11
-rw-r--r--src/mac/ssl3mac/ssl3_mac.cpp16
-rw-r--r--src/mac/ssl3mac/ssl3_mac.h4
-rw-r--r--src/mac/x919_mac/x919_mac.cpp25
-rw-r--r--src/mac/x919_mac/x919_mac.h8
-rw-r--r--src/rng/x931_rng/x931_rng.cpp13
-rw-r--r--src/rng/x931_rng/x931_rng.h2
11 files changed, 87 insertions, 51 deletions
diff --git a/checks/dolook2.cpp b/checks/dolook2.cpp
index 708d5d2ef..13b14a114 100644
--- a/checks/dolook2.cpp
+++ b/checks/dolook2.cpp
@@ -121,13 +121,13 @@ Filter* lookup_rng(const std::string& algname,
#if defined(BOTAN_HAS_X931_RNG)
if(algname == "X9.31-RNG(TripleDES)")
- prng = new ANSI_X931_RNG("TripleDES", new Fixed_Output_RNG(decode_hex(key)));
+ prng = new ANSI_X931_RNG(get_block_cipher("TripleDES"), new Fixed_Output_RNG(decode_hex(key)));
else if(algname == "X9.31-RNG(AES-128)")
- prng = new ANSI_X931_RNG("AES-128", new Fixed_Output_RNG(decode_hex(key)));
+ prng = new ANSI_X931_RNG(get_block_cipher("AES-128"), new Fixed_Output_RNG(decode_hex(key)));
else if(algname == "X9.31-RNG(AES-192)")
- prng = new ANSI_X931_RNG("AES-192", new Fixed_Output_RNG(decode_hex(key)));
+ prng = new ANSI_X931_RNG(get_block_cipher("AES-192"), new Fixed_Output_RNG(decode_hex(key)));
else if(algname == "X9.31-RNG(AES-256)")
- prng = new ANSI_X931_RNG("AES-256", new Fixed_Output_RNG(decode_hex(key)));
+ prng = new ANSI_X931_RNG(get_block_cipher("AES-256"), new Fixed_Output_RNG(decode_hex(key)));
#endif
#if defined(BOTAN_HAS_X931_RNG) and defined(BOTAN_HAS_RANDPOOL)
@@ -143,7 +143,7 @@ Filter* lookup_rng(const std::string& algname,
if(algname == "Randpool")
prng = randpool;
else
- prng = new ANSI_X931_RNG("AES-256", randpool);
+ prng = new ANSI_X931_RNG(get_block_cipher("AES-256"), randpool);
}
#endif
diff --git a/src/core/libstate/def_alg.cpp b/src/core/libstate/def_alg.cpp
index ea58bd06f..475b56225 100644
--- a/src/core/libstate/def_alg.cpp
+++ b/src/core/libstate/def_alg.cpp
@@ -538,33 +538,49 @@ Default_Engine::find_mac(const std::string& algo_spec) const
return 0;
const std::string algo_name = global_state().deref_alias(name[0]);
+#if defined(BOTAN_HAS_CBC_MAC)
if(algo_name == "CBC-MAC")
{
if(name.size() == 2)
return new CBC_MAC(find_block_cipher(name[1]));
throw Invalid_Algorithm_Name(algo_spec);
}
+#endif
+#if defined(BOTAN_HAS_CMAC)
if(algo_name == "CMAC")
{
if(name.size() == 2)
return new CMAC(find_block_cipher(name[1]));
throw Invalid_Algorithm_Name(algo_spec);
}
+#endif
+#if defined(BOTAN_HAS_HMAC)
if(algo_name == "HMAC")
{
if(name.size() == 2)
return new HMAC(find_hash(name[1]));
throw Invalid_Algorithm_Name(algo_spec);
}
+#endif
#if defined(BOTAN_HAS_SSL3_MAC)
- HANDLE_TYPE_ONE_STRING("SSL3-MAC", SSL3_MAC);
+ if(algo_name == "SSL3-MAC")
+ {
+ if(name.size() == 2)
+ return new SSL3_MAC(find_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
#endif
#if defined(BOTAN_HAS_ANSI_X919_MAC)
- HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC);
+ if(algo_name == "X9.19-MAC")
+ {
+ if(name.size() == 1)
+ return new ANSI_X919_MAC(find_block_cipher("DES"));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
#endif
return 0;
@@ -581,11 +597,14 @@ S2K* Default_Engine::find_s2k(const std::string& algo_spec) const
const std::string algo_name = global_state().deref_alias(name[0]);
-#if defined(BOTAN_HAS_PBKDF1)
- HANDLE_TYPE_ONE_STRING("PBKDF1", PKCS5_PBKDF1);
-#endif
+ if(algo_name == "PBKDF1")
+ {
+ if(name.size() == 2)
+ return new PKCS5_PBKDF1(find_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
- if(algo_spec == "PBKDF2")
+ if(algo_name == "PBKDF2")
{
if(name.size() == 2)
return new PKCS5_PBKDF2(find_mac("HMAC(" + name[1] + ")"));
diff --git a/src/core/rng.cpp b/src/core/rng.cpp
index 37b03684c..16c87f563 100644
--- a/src/core/rng.cpp
+++ b/src/core/rng.cpp
@@ -87,7 +87,7 @@ RandomNumberGenerator* RandomNumberGenerator::make_rng()
get_mac("HMAC(SHA-256)"));
#if defined(BOTAN_HAS_X931_RNG)
- rng = new ANSI_X931_RNG("AES-256", rng);
+ rng = new ANSI_X931_RNG(get_block_cipher("AES-256"), rng);
#endif
#if defined(BOTAN_HAS_TIMER_HARDWARE)
diff --git a/src/kdf/pbkdf1/pbkdf1.cpp b/src/kdf/pbkdf1/pbkdf1.cpp
index 70cff9eee..00d1ea9ab 100644
--- a/src/kdf/pbkdf1/pbkdf1.cpp
+++ b/src/kdf/pbkdf1/pbkdf1.cpp
@@ -4,8 +4,6 @@
*************************************************/
#include <botan/pbkdf1.h>
-#include <botan/lookup.h>
-#include <memory>
namespace Botan {
@@ -20,7 +18,6 @@ OctetString PKCS5_PBKDF1::derive(u32bit key_len,
if(iterations == 0)
throw Invalid_Argument("PKCS#5 PBKDF1: Invalid iteration count");
- std::auto_ptr<HashFunction> hash(get_hash(hash_name));
if(key_len > hash->OUTPUT_LENGTH)
throw Exception("PKCS#5 PBKDF1: Requested output length too long");
@@ -38,20 +35,19 @@ OctetString PKCS5_PBKDF1::derive(u32bit key_len,
}
/*************************************************
-* Return the name of this type *
+* Clone this type *
*************************************************/
-std::string PKCS5_PBKDF1::name() const
+S2K* PKCS5_PBKDF1::clone() const
{
- return "PBKDF1(" + hash_name + ")";
+ return new PKCS5_PBKDF1(hash->clone());
}
/*************************************************
-* PKCS5_PBKDF1 Constructor *
+* Return the name of this type *
*************************************************/
-PKCS5_PBKDF1::PKCS5_PBKDF1(const std::string& h_name) : hash_name(h_name)
+std::string PKCS5_PBKDF1::name() const
{
- if(!have_hash(hash_name))
- throw Algorithm_Not_Found(hash_name);
+ return "PBKDF1(" + hash->name() + ")";
}
}
diff --git a/src/kdf/pbkdf1/pbkdf1.h b/src/kdf/pbkdf1/pbkdf1.h
index 3608bb470..e5fd66db8 100644
--- a/src/kdf/pbkdf1/pbkdf1.h
+++ b/src/kdf/pbkdf1/pbkdf1.h
@@ -7,6 +7,7 @@
#define BOTAN_PBKDF1_H__
#include <botan/s2k.h>
+#include <botan/base.h>
namespace Botan {
@@ -17,12 +18,16 @@ class BOTAN_DLL PKCS5_PBKDF1 : public S2K
{
public:
std::string name() const;
- S2K* clone() const { return new PKCS5_PBKDF1(hash_name); }
- PKCS5_PBKDF1(const std::string&);
+ S2K* clone() const;
+
+ PKCS5_PBKDF1(HashFunction* hash_in) : hash(hash_in) {}
+ PKCS5_PBKDF1(const PKCS5_PBKDF1& other) : hash(other.hash->clone()) {}
+ ~PKCS5_PBKDF1() { delete hash; }
private:
OctetString derive(u32bit, const std::string&,
const byte[], u32bit, u32bit) const;
- const std::string hash_name;
+
+ HashFunction* hash;
};
}
diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp
index ceb04bf44..d2aec7825 100644
--- a/src/mac/ssl3mac/ssl3_mac.cpp
+++ b/src/mac/ssl3mac/ssl3_mac.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/ssl3_mac.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -65,21 +64,22 @@ std::string SSL3_MAC::name() const
*************************************************/
MessageAuthenticationCode* SSL3_MAC::clone() const
{
- return new SSL3_MAC(hash->name());
+ return new SSL3_MAC(hash->clone());
}
/*************************************************
* SSL3-MAC Constructor *
*************************************************/
-SSL3_MAC::SSL3_MAC(const std::string& hash_name) :
- MessageAuthenticationCode(output_length_of(hash_name),
- output_length_of(hash_name)),
- hash(get_hash(hash_name))
+SSL3_MAC::SSL3_MAC(HashFunction* hash_in) :
+ MessageAuthenticationCode(hash_in->OUTPUT_LENGTH,
+ hash_in->OUTPUT_LENGTH),
+ hash(hash_in)
{
- if(hash->name() != "MD5" && hash->name() != "SHA-160")
+ if(hash->HASH_BLOCK_SIZE == 0)
throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name());
- const u32bit INNER_HASH_LENGTH = (hash->name() == "MD5") ? 64 : 60;
+ u32bit INNER_HASH_LENGTH =
+ (hash->name() == "SHA-160") ? 60 : hash->HASH_BLOCK_SIZE;
i_key.create(INNER_HASH_LENGTH);
o_key.create(INNER_HASH_LENGTH);
diff --git a/src/mac/ssl3mac/ssl3_mac.h b/src/mac/ssl3mac/ssl3_mac.h
index 8ab08c97d..9b4be4e2f 100644
--- a/src/mac/ssl3mac/ssl3_mac.h
+++ b/src/mac/ssl3mac/ssl3_mac.h
@@ -19,12 +19,14 @@ class SSL3_MAC : public MessageAuthenticationCode
void clear() throw();
std::string name() const;
MessageAuthenticationCode* clone() const;
- SSL3_MAC(const std::string&);
+
+ SSL3_MAC(HashFunction*);
~SSL3_MAC() { delete hash; }
private:
void add_data(const byte[], u32bit);
void final_result(byte[]);
void key(const byte[], u32bit);
+
HashFunction* hash;
SecureVector<byte> i_key, o_key;
};
diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp
index 92ec7b7b8..5e03b2e6c 100644
--- a/src/mac/x919_mac/x919_mac.cpp
+++ b/src/mac/x919_mac/x919_mac.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/x919_mac.h>
-#include <botan/lookup.h>
#include <botan/xor_buf.h>
#include <algorithm>
@@ -70,19 +69,33 @@ void ANSI_X919_MAC::clear() throw()
position = 0;
}
+std::string ANSI_X919_MAC::name() const
+ {
+ return "X9.19-MAC";
+ }
+
+MessageAuthenticationCode* ANSI_X919_MAC::clone() const
+ {
+ return new ANSI_X919_MAC(e->clone());
+ }
+
/*************************************************
* ANSI X9.19 MAC Constructor *
*************************************************/
-ANSI_X919_MAC::ANSI_X919_MAC() : MessageAuthenticationCode(8, 8, 16, 8)
+ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) :
+ MessageAuthenticationCode(e_in->BLOCK_SIZE,
+ e_in->MINIMUM_KEYLENGTH,
+ 2*e_in->MAXIMUM_KEYLENGTH,
+ 2*e_in->KEYLENGTH_MULTIPLE),
+ e(e_in), d(e->clone()), position(0)
{
- e = get_block_cipher("DES");
- d = get_block_cipher("DES");
- position = 0;
+ if(e->name() != "DES")
+ throw Invalid_Argument("ANSI X9.19 MAC only supports DES");
}
/*************************************************
* ANSI X9.19 MAC Destructor *
-*************************************************/
+le*************************************************/
ANSI_X919_MAC::~ANSI_X919_MAC()
{
delete e;
diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h
index bedb2cf58..4909e554a 100644
--- a/src/mac/x919_mac/x919_mac.h
+++ b/src/mac/x919_mac/x919_mac.h
@@ -17,14 +17,16 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode
{
public:
void clear() throw();
- std::string name() const { return "X9.19-MAC"; }
- MessageAuthenticationCode* clone() const { return new ANSI_X919_MAC; }
- ANSI_X919_MAC();
+ std::string name() const;
+ MessageAuthenticationCode* clone() const;
+
+ ANSI_X919_MAC(BlockCipher*);
~ANSI_X919_MAC();
private:
void add_data(const byte[], u32bit);
void final_result(byte[]);
void key(const byte[], u32bit);
+
BlockCipher* e;
BlockCipher* d;
SecureBuffer<byte, 8> state;
diff --git a/src/rng/x931_rng/x931_rng.cpp b/src/rng/x931_rng/x931_rng.cpp
index f4b0f71a9..72ddb51c5 100644
--- a/src/rng/x931_rng/x931_rng.cpp
+++ b/src/rng/x931_rng/x931_rng.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/x931_rng.h>
-#include <botan/lookup.h>
#include <botan/xor_buf.h>
#include <algorithm>
@@ -117,14 +116,14 @@ std::string ANSI_X931_RNG::name() const
/*************************************************
* ANSI X931 RNG Constructor *
*************************************************/
-ANSI_X931_RNG::ANSI_X931_RNG(const std::string& cipher_name,
- RandomNumberGenerator* prng_ptr)
+ANSI_X931_RNG::ANSI_X931_RNG(BlockCipher* cipher_in,
+ RandomNumberGenerator* prng_in)
{
- if(!prng_ptr)
- throw Invalid_Argument("ANSI_X931_RNG constructor: NULL prng");
+ if(!prng_in || !cipher_in)
+ throw Invalid_Argument("ANSI_X931_RNG constructor: NULL arguments");
- prng = prng_ptr;
- cipher = get_block_cipher(cipher_name);
+ cipher = cipher_in;
+ prng = prng_in;
R.create(cipher->BLOCK_SIZE);
position = 0;
diff --git a/src/rng/x931_rng/x931_rng.h b/src/rng/x931_rng/x931_rng.h
index 7914b605d..220b47ab8 100644
--- a/src/rng/x931_rng/x931_rng.h
+++ b/src/rng/x931_rng/x931_rng.h
@@ -26,7 +26,7 @@ class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator
void add_entropy_source(EntropySource*);
void add_entropy(const byte[], u32bit);
- ANSI_X931_RNG(const std::string&, RandomNumberGenerator*);
+ ANSI_X931_RNG(BlockCipher*, RandomNumberGenerator*);
~ANSI_X931_RNG();
private:
void update_buffer();