aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-30 05:41:04 +0000
committerlloyd <[email protected]>2008-09-30 05:41:04 +0000
commit75ef07ee5378341adf054bd729232167c73e9e47 (patch)
tree7c84c43a431f0313b4f08b4267ff066650948bb0 /src
parentbc9e881d7c7a569664b5e753c12e4c8cbde06d2d (diff)
Remove lookup/libstate dependency on Lion, KDF1, KDF2, EMSA[1-4]
Diffstat (limited to 'src')
-rw-r--r--src/cipher/lion/lion.cpp14
-rw-r--r--src/cipher/lion/lion.h5
-rw-r--r--src/core/libstate/def_alg.cpp4
-rw-r--r--src/core/libstate/get_enc.cpp24
-rw-r--r--src/kdf/kdf1/kdf1.cpp13
-rw-r--r--src/kdf/kdf1/kdf1.h13
-rw-r--r--src/kdf/kdf2/kdf2.cpp12
-rw-r--r--src/kdf/kdf2/kdf2.h7
-rw-r--r--src/pk_pad/emsa1/emsa1.cpp8
-rw-r--r--src/pk_pad/emsa1/emsa1.h2
-rw-r--r--src/pk_pad/emsa2/emsa2.cpp4
-rw-r--r--src/pk_pad/emsa2/emsa2.h2
-rw-r--r--src/pk_pad/emsa3/emsa3.cpp4
-rw-r--r--src/pk_pad/emsa3/emsa3.h2
-rw-r--r--src/pk_pad/emsa4/emsa4.cpp16
-rw-r--r--src/pk_pad/emsa4/emsa4.h7
16 files changed, 55 insertions, 82 deletions
diff --git a/src/cipher/lion/lion.cpp b/src/cipher/lion/lion.cpp
index 009e98408..c5d6fc9de 100644
--- a/src/cipher/lion/lion.cpp
+++ b/src/cipher/lion/lion.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/lion.h>
-#include <botan/lookup.h>
#include <botan/xor_buf.h>
#include <botan/parsing.h>
@@ -76,7 +75,7 @@ std::string Lion::name() const
*************************************************/
BlockCipher* Lion::clone() const
{
- return new Lion(hash->name(), cipher->name(), BLOCK_SIZE);
+ return new Lion(hash->clone(), cipher->clone(), BLOCK_SIZE);
}
/*************************************************
@@ -93,14 +92,11 @@ void Lion::clear() throw()
/*************************************************
* Lion Constructor *
*************************************************/
-Lion::Lion(const std::string& hash_name, const std::string& sc_name,
- u32bit block_len) :
- BlockCipher(block_len, 2, 2*output_length_of(hash_name), 2),
- LEFT_SIZE(output_length_of(hash_name)), RIGHT_SIZE(BLOCK_SIZE - LEFT_SIZE)
+Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, u32bit block_len) :
+ BlockCipher(block_len, 2, 2*hash_in->OUTPUT_LENGTH, 2),
+ LEFT_SIZE(hash->OUTPUT_LENGTH), RIGHT_SIZE(BLOCK_SIZE - LEFT_SIZE),
+ hash(hash_in), cipher(sc_in)
{
- hash = get_hash(hash_name);
- cipher = get_stream_cipher(sc_name);
-
if(2*LEFT_SIZE + 1 > BLOCK_SIZE)
throw Invalid_Argument(name() + ": Chosen block size is too small");
if(!cipher->valid_keylength(LEFT_SIZE))
diff --git a/src/cipher/lion/lion.h b/src/cipher/lion/lion.h
index 70018838a..445682987 100644
--- a/src/cipher/lion/lion.h
+++ b/src/cipher/lion/lion.h
@@ -19,13 +19,16 @@ class BOTAN_DLL Lion : public BlockCipher
void clear() throw();
std::string name() const;
BlockCipher* clone() const;
- Lion(const std::string&, const std::string&, u32bit);
+
+ Lion(HashFunction*, StreamCipher*, u32bit);
~Lion() { delete hash; delete cipher; }
private:
void enc(const byte[], byte[]) const;
void dec(const byte[], byte[]) const;
void key(const byte[], u32bit);
+
const u32bit LEFT_SIZE, RIGHT_SIZE;
+
HashFunction* hash;
StreamCipher* cipher;
SecureVector<byte> key1, key2;
diff --git a/src/core/libstate/def_alg.cpp b/src/core/libstate/def_alg.cpp
index cad5dca5a..6a12f79f2 100644
--- a/src/core/libstate/def_alg.cpp
+++ b/src/core/libstate/def_alg.cpp
@@ -397,7 +397,9 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const
{
if(name.size() != 4)
throw Invalid_Algorithm_Name(algo_spec);
- return new Lion(name[1], name[2], to_u32bit(name[3]));
+
+ return new Lion(find_hash(name[1]), find_stream_cipher(name[2]),
+ to_u32bit(name[3]));
}
#endif
diff --git a/src/core/libstate/get_enc.cpp b/src/core/libstate/get_enc.cpp
index 5f54be199..2459ef0a6 100644
--- a/src/core/libstate/get_enc.cpp
+++ b/src/core/libstate/get_enc.cpp
@@ -82,7 +82,7 @@ EMSA* get_emsa(const std::string& algo_spec)
if(emsa_name == "EMSA1")
{
if(name.size() == 2)
- return new EMSA1(name[1]);
+ return new EMSA1(get_hash(name[1]));
}
#endif
@@ -90,7 +90,7 @@ EMSA* get_emsa(const std::string& algo_spec)
if(emsa_name == "EMSA2")
{
if(name.size() == 2)
- return new EMSA2(name[1]);
+ return new EMSA2(get_hash(name[1]));
}
#endif
@@ -98,19 +98,21 @@ EMSA* get_emsa(const std::string& algo_spec)
if(emsa_name == "EMSA3")
{
if(name.size() == 2)
- return new EMSA3(name[1]);
+ return new EMSA3(get_hash(name[1]));
}
#endif
#if defined(BOTAN_HAS_EMSA4)
if(emsa_name == "EMSA4")
{
- if(name.size() == 2)
- return new EMSA4(name[1], "MGF1");
- if(name.size() == 3)
- return new EMSA4(name[1], name[2]);
- if(name.size() == 4)
- return new EMSA4(name[1], name[2], to_u32bit(name[3]));
+ // EMSA4 is hardcoded to use MGF1
+ if(name.size() >= 3 && name[2] != "MGF1")
+ throw Algorithm_Not_Found(algo_spec);
+
+ if(name.size() == 2 || name.size() == 3)
+ return new EMSA4(get_hash(name[1]));
+ else if(name.size() == 4)
+ return new EMSA4(get_hash(name[1]), to_u32bit(name[3]));
}
#endif
@@ -165,7 +167,7 @@ KDF* get_kdf(const std::string& algo_spec)
if(kdf_name == "KDF1")
{
if(name.size() == 2)
- return new KDF1(name[1]);
+ return new KDF1(get_hash(name[1]));
}
#endif
@@ -173,7 +175,7 @@ KDF* get_kdf(const std::string& algo_spec)
if(kdf_name == "KDF2")
{
if(name.size() == 2)
- return new KDF2(name[1]);
+ return new KDF2(get_hash(name[1]));
}
#endif
diff --git a/src/kdf/kdf1/kdf1.cpp b/src/kdf/kdf1/kdf1.cpp
index aac32db80..0ea375b30 100644
--- a/src/kdf/kdf1/kdf1.cpp
+++ b/src/kdf/kdf1/kdf1.cpp
@@ -4,8 +4,6 @@
*************************************************/
#include <botan/kdf1.h>
-#include <botan/lookup.h>
-#include <memory>
namespace Botan {
@@ -16,20 +14,9 @@ SecureVector<byte> KDF1::derive(u32bit,
const byte secret[], u32bit secret_len,
const byte P[], u32bit P_len) const
{
- std::auto_ptr<HashFunction> hash(get_hash(hash_name));
-
hash->update(secret, secret_len);
hash->update(P, P_len);
return hash->final();
}
-/*************************************************
-* KDF1 Constructor *
-*************************************************/
-KDF1::KDF1(const std::string& h_name) : hash_name(h_name)
- {
- if(!have_hash(hash_name))
- throw Algorithm_Not_Found(hash_name);
- }
-
}
diff --git a/src/kdf/kdf1/kdf1.h b/src/kdf/kdf1/kdf1.h
index 9aaa81d2b..6a4b0f113 100644
--- a/src/kdf/kdf1/kdf1.h
+++ b/src/kdf/kdf1/kdf1.h
@@ -7,6 +7,7 @@
#define BOTAN_KDF1_H__
#include <botan/kdf.h>
+#include <botan/base.h>
namespace Botan {
@@ -16,12 +17,16 @@ namespace Botan {
class BOTAN_DLL KDF1 : public KDF
{
public:
- SecureVector<byte> derive(u32bit, const byte[], u32bit,
- const byte[], u32bit) const;
+ SecureVector<byte> derive(u32bit,
+ const byte secret[], u32bit secret_len,
+ const byte P[], u32bit P_len) const;
- KDF1(const std::string&);
+ KDF1(HashFunction* h) : hash(h) {}
+ KDF1(const KDF1& other) : hash(other.hash->clone()) {}
+
+ ~KDF1() { delete hash; }
private:
- const std::string hash_name;
+ HashFunction* hash;
};
}
diff --git a/src/kdf/kdf2/kdf2.cpp b/src/kdf/kdf2/kdf2.cpp
index fa975ccb9..fdeb09869 100644
--- a/src/kdf/kdf2/kdf2.cpp
+++ b/src/kdf/kdf2/kdf2.cpp
@@ -4,9 +4,7 @@
*************************************************/
#include <botan/kdf2.h>
-#include <botan/lookup.h>
#include <botan/loadstor.h>
-#include <memory>
namespace Botan {
@@ -20,7 +18,6 @@ SecureVector<byte> KDF2::derive(u32bit out_len,
SecureVector<byte> output;
u32bit counter = 1;
- std::auto_ptr<HashFunction> hash(get_hash(hash_name));
while(out_len && counter)
{
hash->update(secret, secret_len);
@@ -39,13 +36,4 @@ SecureVector<byte> KDF2::derive(u32bit out_len,
return output;
}
-/*************************************************
-* KDF2 Constructor *
-*************************************************/
-KDF2::KDF2(const std::string& h_name) : hash_name(h_name)
- {
- if(!have_hash(hash_name))
- throw Algorithm_Not_Found(hash_name);
- }
-
}
diff --git a/src/kdf/kdf2/kdf2.h b/src/kdf/kdf2/kdf2.h
index f3768f15f..33db36ad4 100644
--- a/src/kdf/kdf2/kdf2.h
+++ b/src/kdf/kdf2/kdf2.h
@@ -7,6 +7,7 @@
#define BOTAN_KDF2_H__
#include <botan/kdf.h>
+#include <botan/base.h>
namespace Botan {
@@ -19,9 +20,11 @@ class BOTAN_DLL KDF2 : public KDF
SecureVector<byte> derive(u32bit, const byte[], u32bit,
const byte[], u32bit) const;
- KDF2(const std::string&);
+ KDF2(HashFunction* h) : hash(h) {}
+ KDF2(const KDF2& other) : hash(other.hash->clone()) {}
+ ~KDF2() { delete hash; }
private:
- const std::string hash_name;
+ HashFunction* hash;
};
}
diff --git a/src/pk_pad/emsa1/emsa1.cpp b/src/pk_pad/emsa1/emsa1.cpp
index 15d53f6e5..b0c505939 100644
--- a/src/pk_pad/emsa1/emsa1.cpp
+++ b/src/pk_pad/emsa1/emsa1.cpp
@@ -101,12 +101,4 @@ bool EMSA1::verify(const MemoryRegion<byte>& coded,
}
}
-/*************************************************
-* EMSA1 Constructor *
-*************************************************/
-EMSA1::EMSA1(const std::string& hash_name) :
- hash(get_hash(hash_name))
- {
- }
-
}
diff --git a/src/pk_pad/emsa1/emsa1.h b/src/pk_pad/emsa1/emsa1.h
index c0eec8d17..2de2d325e 100644
--- a/src/pk_pad/emsa1/emsa1.h
+++ b/src/pk_pad/emsa1/emsa1.h
@@ -16,7 +16,7 @@ namespace Botan {
class BOTAN_DLL EMSA1 : public EMSA
{
public:
- EMSA1(const std::string&);
+ EMSA1(HashFunction* h) : hash(h) {}
~EMSA1() { delete hash; }
private:
void update(const byte[], u32bit);
diff --git a/src/pk_pad/emsa2/emsa2.cpp b/src/pk_pad/emsa2/emsa2.cpp
index 9f5f4b277..5ecbf005c 100644
--- a/src/pk_pad/emsa2/emsa2.cpp
+++ b/src/pk_pad/emsa2/emsa2.cpp
@@ -5,7 +5,6 @@
#include <botan/emsa2.h>
#include <botan/hash_id.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -94,9 +93,8 @@ bool EMSA2::verify(const MemoryRegion<byte>& coded,
/*************************************************
* EMSA2 Constructor *
*************************************************/
-EMSA2::EMSA2(const std::string& hash_name)
+EMSA2::EMSA2(HashFunction* hash_in) : hash(hash_in)
{
- hash = get_hash(hash_name);
empty_hash = hash->final();
hash_id = ieee1363_hash_id(hash->name());
diff --git a/src/pk_pad/emsa2/emsa2.h b/src/pk_pad/emsa2/emsa2.h
index 79e21a8f8..d35cfe1aa 100644
--- a/src/pk_pad/emsa2/emsa2.h
+++ b/src/pk_pad/emsa2/emsa2.h
@@ -16,7 +16,7 @@ namespace Botan {
class BOTAN_DLL EMSA2 : public EMSA
{
public:
- EMSA2(const std::string&);
+ EMSA2(HashFunction* hash);
~EMSA2() { delete hash; }
private:
void update(const byte[], u32bit);
diff --git a/src/pk_pad/emsa3/emsa3.cpp b/src/pk_pad/emsa3/emsa3.cpp
index 255366503..060dd40d8 100644
--- a/src/pk_pad/emsa3/emsa3.cpp
+++ b/src/pk_pad/emsa3/emsa3.cpp
@@ -5,7 +5,6 @@
#include <botan/emsa3.h>
#include <botan/hash_id.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -88,9 +87,8 @@ bool EMSA3::verify(const MemoryRegion<byte>& coded,
/*************************************************
* EMSA3 Constructor *
*************************************************/
-EMSA3::EMSA3(const std::string& hash_name)
+EMSA3::EMSA3(HashFunction* hash_in) : hash(hash_in)
{
- hash = get_hash(hash_name);
hash_id = pkcs_hash_id(hash->name());
}
diff --git a/src/pk_pad/emsa3/emsa3.h b/src/pk_pad/emsa3/emsa3.h
index bdaec5c42..7c0d87147 100644
--- a/src/pk_pad/emsa3/emsa3.h
+++ b/src/pk_pad/emsa3/emsa3.h
@@ -16,7 +16,7 @@ namespace Botan {
class BOTAN_DLL EMSA3 : public EMSA
{
public:
- EMSA3(const std::string&);
+ EMSA3(HashFunction* hash);
~EMSA3() { delete hash; }
private:
void update(const byte[], u32bit);
diff --git a/src/pk_pad/emsa4/emsa4.cpp b/src/pk_pad/emsa4/emsa4.cpp
index e41b0d2fa..038489e15 100644
--- a/src/pk_pad/emsa4/emsa4.cpp
+++ b/src/pk_pad/emsa4/emsa4.cpp
@@ -4,7 +4,7 @@
*************************************************/
#include <botan/emsa4.h>
-#include <botan/lookup.h>
+#include <botan/mgf1.h>
#include <botan/bit_ops.h>
namespace Botan {
@@ -123,21 +123,19 @@ bool EMSA4::verify(const MemoryRegion<byte>& const_coded,
/*************************************************
* EMSA4 Constructor *
*************************************************/
-EMSA4::EMSA4(const std::string& hash_name, const std::string& mgf_name) :
- SALT_SIZE(output_length_of(hash_name))
+EMSA4::EMSA4(HashFunction* h) :
+ SALT_SIZE(h->OUTPUT_LENGTH), hash(h)
{
- hash = get_hash(hash_name);
- mgf = get_mgf(mgf_name + "(" + hash_name + ")");
+ mgf = new MGF1(hash->clone());
}
/*************************************************
* EMSA4 Constructor *
*************************************************/
-EMSA4::EMSA4(const std::string& hash_name, const std::string& mgf_name,
- u32bit salt_size) : SALT_SIZE(salt_size)
+EMSA4::EMSA4(HashFunction* h, u32bit salt_size) :
+ SALT_SIZE(salt_size), hash(h)
{
- hash = get_hash(hash_name);
- mgf = get_mgf(mgf_name + "(" + hash_name + ")");
+ mgf = new MGF1(hash->clone());
}
}
diff --git a/src/pk_pad/emsa4/emsa4.h b/src/pk_pad/emsa4/emsa4.h
index 8f2505281..dded20ec3 100644
--- a/src/pk_pad/emsa4/emsa4.h
+++ b/src/pk_pad/emsa4/emsa4.h
@@ -17,8 +17,9 @@ namespace Botan {
class BOTAN_DLL EMSA4 : public EMSA
{
public:
- EMSA4(const std::string&, const std::string&);
- EMSA4(const std::string&, const std::string&, u32bit);
+ EMSA4(HashFunction*);
+ EMSA4(HashFunction*, u32bit);
+
~EMSA4() { delete hash; delete mgf; }
private:
void update(const byte[], u32bit);
@@ -29,7 +30,7 @@ class BOTAN_DLL EMSA4 : public EMSA
bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
u32bit) throw();
- const u32bit SALT_SIZE;
+ u32bit SALT_SIZE;
HashFunction* hash;
const MGF* mgf;
};