aboutsummaryrefslogtreecommitdiffstats
path: root/src/hash
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-29 13:51:27 +0000
committerlloyd <[email protected]>2010-10-29 13:51:27 +0000
commit633175a57a03ed9bf5a5e3577bfc26068c62b688 (patch)
tree086eb3a931d39fb35f8a3896a25a5cb38736a696 /src/hash
parentdf0dfeb904485bacb8034d0468b4498130939acc (diff)
Remove BufferedComputation::OUTPUT_LENGTH
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/bmw/bmw_512.h6
-rw-r--r--src/hash/comb4p/comb4p.cpp1
-rw-r--r--src/hash/comb4p/comb4p.h5
-rw-r--r--src/hash/gost_3411/gost_3411.cpp1
-rw-r--r--src/hash/gost_3411/gost_3411.h5
-rw-r--r--src/hash/has160/has160.h6
-rw-r--r--src/hash/hash.h10
-rw-r--r--src/hash/md2/md2.h7
-rw-r--r--src/hash/md4/md4.h6
-rw-r--r--src/hash/md5/md5.h6
-rw-r--r--src/hash/mdx_hash/mdx_hash.cpp8
-rw-r--r--src/hash/mdx_hash/mdx_hash.h3
-rw-r--r--src/hash/par_hash/par_hash.cpp30
-rw-r--r--src/hash/par_hash/par_hash.h2
-rw-r--r--src/hash/rmd128/rmd128.h6
-rw-r--r--src/hash/rmd160/rmd160.h6
-rw-r--r--src/hash/sha1/sha160.cpp18
-rw-r--r--src/hash/sha1/sha160.h15
-rw-r--r--src/hash/sha2_32/sha2_32.h12
-rw-r--r--src/hash/sha2_64/sha2_64.h13
-rw-r--r--src/hash/skein/skein_512.cpp1
-rw-r--r--src/hash/skein/skein_512.h1
-rw-r--r--src/hash/tiger/tiger.cpp16
-rw-r--r--src/hash/tiger/tiger.h8
-rw-r--r--src/hash/whirlpool/whrlpool.h6
25 files changed, 103 insertions, 95 deletions
diff --git a/src/hash/bmw/bmw_512.h b/src/hash/bmw/bmw_512.h
index aa527c142..474b607bb 100644
--- a/src/hash/bmw/bmw_512.h
+++ b/src/hash/bmw/bmw_512.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL BMW_512 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "BMW512"; }
+ size_t output_length() const { return 64; }
HashFunction* clone() const { return new BMW_512; }
- BMW_512() : MDx_HashFunction(64, 128, false, true), H(16), M(16), Q(32)
+ void clear();
+
+ BMW_512() : MDx_HashFunction(128, false, true), H(16), M(16), Q(32)
{ clear(); }
private:
void compress_n(const byte input[], size_t blocks);
diff --git a/src/hash/comb4p/comb4p.cpp b/src/hash/comb4p/comb4p.cpp
index 19e23879f..1ea64a5cb 100644
--- a/src/hash/comb4p/comb4p.cpp
+++ b/src/hash/comb4p/comb4p.cpp
@@ -35,7 +35,6 @@ void comb4p_round(MemoryRegion<byte>& out,
}
Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
- HashFunction(h1->output_length() + h2->output_length()),
hash1(h1), hash2(h2)
{
if(hash1->name() == hash2->name())
diff --git a/src/hash/comb4p/comb4p.h b/src/hash/comb4p/comb4p.h
index 67547f979..73e06c379 100644
--- a/src/hash/comb4p/comb4p.h
+++ b/src/hash/comb4p/comb4p.h
@@ -29,6 +29,11 @@ class BOTAN_DLL Comb4P : public HashFunction
size_t hash_block_size() const;
+ size_t output_length() const
+ {
+ return hash1->output_length() + hash2->output_length();
+ }
+
HashFunction* clone() const
{
return new Comb4P(hash1->clone(), hash2->clone());
diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp
index fd47ba2c7..075f26889 100644
--- a/src/hash/gost_3411/gost_3411.cpp
+++ b/src/hash/gost_3411/gost_3411.cpp
@@ -16,7 +16,6 @@ namespace Botan {
* GOST 34.11 Constructor
*/
GOST_34_11::GOST_34_11() :
- HashFunction(32),
cipher(GOST_28147_89_Params("R3411_CryptoPro")),
buffer(32),
sum(32),
diff --git a/src/hash/gost_3411/gost_3411.h b/src/hash/gost_3411/gost_3411.h
index 64ea0f40c..fbbcb7a89 100644
--- a/src/hash/gost_3411/gost_3411.h
+++ b/src/hash/gost_3411/gost_3411.h
@@ -19,11 +19,12 @@ namespace Botan {
class BOTAN_DLL GOST_34_11 : public HashFunction
{
public:
- void clear();
std::string name() const { return "GOST-R-34.11-94" ; }
+ size_t output_length() const { return 32; }
+ size_t hash_block_size() const { return 32; }
HashFunction* clone() const { return new GOST_34_11; }
- size_t hash_block_size() const { return 32; }
+ void clear();
GOST_34_11();
private:
diff --git a/src/hash/has160/has160.h b/src/hash/has160/has160.h
index 83ed5ab56..d32361601 100644
--- a/src/hash/has160/has160.h
+++ b/src/hash/has160/has160.h
@@ -19,11 +19,13 @@ namespace Botan {
class BOTAN_DLL HAS_160 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "HAS-160"; }
+ size_t output_length() const { return 20; }
HashFunction* clone() const { return new HAS_160; }
- HAS_160() : MDx_HashFunction(20, 64, false, true), X(20), digest(5)
+ void clear();
+
+ HAS_160() : MDx_HashFunction(64, false, true), X(20), digest(5)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
diff --git a/src/hash/hash.h b/src/hash/hash.h
index 881e23817..af411fb87 100644
--- a/src/hash/hash.h
+++ b/src/hash/hash.h
@@ -14,20 +14,12 @@
namespace Botan {
/**
-* This class represents hash function (message digest) objects.
+* This class represents hash function (message digest) objects
*/
class BOTAN_DLL HashFunction : public BufferedComputation
{
public:
/**
- * @param hash_len the output length
- * @param block_len the internal block size (if applicable)
- */
- HashFunction(size_t hash_len) : BufferedComputation(hash_len) {}
-
- virtual ~HashFunction() {}
-
- /**
* Get a new object representing the same algorithm as *this
*/
virtual HashFunction* clone() const = 0;
diff --git a/src/hash/md2/md2.h b/src/hash/md2/md2.h
index 84f213811..84e0323f7 100644
--- a/src/hash/md2/md2.h
+++ b/src/hash/md2/md2.h
@@ -18,13 +18,14 @@ namespace Botan {
class BOTAN_DLL MD2 : public HashFunction
{
public:
- void clear();
std::string name() const { return "MD2"; }
+ size_t output_length() const { return 16; }
+ size_t hash_block_size() const { return 16; }
HashFunction* clone() const { return new MD2; }
- size_t hash_block_size() const { return 16; }
+ void clear();
- MD2() : HashFunction(16), X(48), checksum(16), buffer(16)
+ MD2() : X(48), checksum(16), buffer(16)
{ clear(); }
private:
void add_data(const byte[], size_t);
diff --git a/src/hash/md4/md4.h b/src/hash/md4/md4.h
index 07467fdfc..182954834 100644
--- a/src/hash/md4/md4.h
+++ b/src/hash/md4/md4.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL MD4 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "MD4"; }
+ size_t output_length() const { return 16; }
HashFunction* clone() const { return new MD4; }
- MD4() : MDx_HashFunction(16, 64, false, true), M(16), digest(4)
+ void clear();
+
+ MD4() : MDx_HashFunction(64, false, true), M(16), digest(4)
{ clear(); }
protected:
void compress_n(const byte input[], size_t blocks);
diff --git a/src/hash/md5/md5.h b/src/hash/md5/md5.h
index f79a3ec65..b54beeec4 100644
--- a/src/hash/md5/md5.h
+++ b/src/hash/md5/md5.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL MD5 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "MD5"; }
+ size_t output_length() const { return 16; }
HashFunction* clone() const { return new MD5; }
- MD5() : MDx_HashFunction(16, 64, false, true), M(16), digest(4)
+ void clear();
+
+ MD5() : MDx_HashFunction(64, false, true), M(16), digest(4)
{ clear(); }
protected:
void compress_n(const byte[], size_t blocks);
diff --git a/src/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp
index f82c971f8..7bfcf6592 100644
--- a/src/hash/mdx_hash/mdx_hash.cpp
+++ b/src/hash/mdx_hash/mdx_hash.cpp
@@ -14,19 +14,15 @@ namespace Botan {
/*
* MDx_HashFunction Constructor
*/
-MDx_HashFunction::MDx_HashFunction(size_t hash_len,
- size_t block_len,
+MDx_HashFunction::MDx_HashFunction(size_t block_len,
bool byte_end,
bool bit_end,
size_t cnt_size) :
- HashFunction(hash_len),
buffer(block_len),
BIG_BYTE_ENDIAN(byte_end),
BIG_BIT_ENDIAN(bit_end),
COUNT_SIZE(cnt_size)
{
- if(COUNT_SIZE >= output_length() || COUNT_SIZE >= hash_block_size())
- throw Invalid_Argument("MDx_HashFunction: COUNT_SIZE is too big");
count = position = 0;
}
@@ -98,6 +94,8 @@ void MDx_HashFunction::write_count(byte out[])
{
if(COUNT_SIZE < 8)
throw Invalid_State("MDx_HashFunction::write_count: COUNT_SIZE < 8");
+ if(COUNT_SIZE >= output_length() || COUNT_SIZE >= hash_block_size())
+ throw Invalid_Argument("MDx_HashFunction: COUNT_SIZE is too big");
const u64bit bit_count = count * 8;
diff --git a/src/hash/mdx_hash/mdx_hash.h b/src/hash/mdx_hash/mdx_hash.h
index d1260180e..0dfc16b31 100644
--- a/src/hash/mdx_hash/mdx_hash.h
+++ b/src/hash/mdx_hash/mdx_hash.h
@@ -25,8 +25,7 @@ class BOTAN_DLL MDx_HashFunction : public HashFunction
* @param big_bit_endian specifies if the hash uses big-endian bits
* @param counter_size specifies the size of the counter var in bytes
*/
- MDx_HashFunction(size_t hash_length,
- size_t block_length,
+ MDx_HashFunction(size_t block_length,
bool big_byte_endian,
bool big_bit_endian,
size_t counter_size = 8);
diff --git a/src/hash/par_hash/par_hash.cpp b/src/hash/par_hash/par_hash.cpp
index aef5f8247..328be6a11 100644
--- a/src/hash/par_hash/par_hash.cpp
+++ b/src/hash/par_hash/par_hash.cpp
@@ -9,23 +9,6 @@
namespace Botan {
-namespace {
-
-/*
-* Return the sum of the hash sizes
-*/
-size_t sum_of_hash_lengths(const std::vector<HashFunction*>& hashes)
- {
- size_t sum = 0;
-
- for(size_t i = 0; i != hashes.size(); ++i)
- sum += hashes[i]->output_length();
-
- return sum;
- }
-
-}
-
/*
* Update the hash
*/
@@ -49,6 +32,17 @@ void Parallel::final_result(byte hash[])
}
/*
+* Return output size
+*/
+size_t Parallel::output_length() const
+ {
+ size_t sum = 0;
+ for(size_t i = 0; i != hashes.size(); ++i)
+ sum += hashes[i]->output_length();
+ return sum;
+ }
+
+/*
* Return the name of this type
*/
std::string Parallel::name() const
@@ -87,7 +81,7 @@ void Parallel::clear()
* Parallel Constructor
*/
Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
- HashFunction(sum_of_hash_lengths(hash_in)), hashes(hash_in)
+ hashes(hash_in)
{
}
diff --git a/src/hash/par_hash/par_hash.h b/src/hash/par_hash/par_hash.h
index 35154dde4..4f5395c23 100644
--- a/src/hash/par_hash/par_hash.h
+++ b/src/hash/par_hash/par_hash.h
@@ -23,6 +23,8 @@ class BOTAN_DLL Parallel : public HashFunction
std::string name() const;
HashFunction* clone() const;
+ size_t output_length() const;
+
/**
* @param hashes a set of hashes to compute in parallel
*/
diff --git a/src/hash/rmd128/rmd128.h b/src/hash/rmd128/rmd128.h
index faead3245..d64cf3c84 100644
--- a/src/hash/rmd128/rmd128.h
+++ b/src/hash/rmd128/rmd128.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL RIPEMD_128 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "RIPEMD-128"; }
+ size_t output_length() const { return 16; }
HashFunction* clone() const { return new RIPEMD_128; }
- RIPEMD_128() : MDx_HashFunction(16, 64, false, true), M(16), digest(4)
+ void clear();
+
+ RIPEMD_128() : MDx_HashFunction(64, false, true), M(16), digest(4)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
diff --git a/src/hash/rmd160/rmd160.h b/src/hash/rmd160/rmd160.h
index 69c6b4a40..5df4ad490 100644
--- a/src/hash/rmd160/rmd160.h
+++ b/src/hash/rmd160/rmd160.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL RIPEMD_160 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "RIPEMD-160"; }
+ size_t output_length() const { return 20; }
HashFunction* clone() const { return new RIPEMD_160; }
- RIPEMD_160() : MDx_HashFunction(20, 64, false, true), M(16), digest(5)
+ void clear();
+
+ RIPEMD_160() : MDx_HashFunction(64, false, true), M(16), digest(5)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp
index aa6a066e8..7a42ca867 100644
--- a/src/hash/sha1/sha160.cpp
+++ b/src/hash/sha1/sha160.cpp
@@ -152,22 +152,4 @@ void SHA_160::clear()
digest[4] = 0xC3D2E1F0;
}
-/*
-* SHA_160 Constructor
-*/
-SHA_160::SHA_160() :
- MDx_HashFunction(20, 64, true, true), digest(5), W(80)
- {
- clear();
- }
-
-/*
-* SHA_160 Constructor
-*/
-SHA_160::SHA_160(size_t W_size) :
- MDx_HashFunction(20, 64, true, true), digest(5), W(W_size)
- {
- clear();
- }
-
}
diff --git a/src/hash/sha1/sha160.h b/src/hash/sha1/sha160.h
index d420f8f94..3038039cf 100644
--- a/src/hash/sha1/sha160.h
+++ b/src/hash/sha1/sha160.h
@@ -18,11 +18,16 @@ namespace Botan {
class BOTAN_DLL SHA_160 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "SHA-160"; }
+ size_t output_length() const { return 20; }
HashFunction* clone() const { return new SHA_160; }
- SHA_160();
+ void clear();
+
+ SHA_160() : MDx_HashFunction(64, true, true), digest(5), W(80)
+ {
+ clear();
+ }
protected:
/**
* Set a custom size for the W array. Normally 80, but some
@@ -30,7 +35,11 @@ class BOTAN_DLL SHA_160 : public MDx_HashFunction
* constraints
* @param W_size how big to make W
*/
- SHA_160(size_t W_size);
+ SHA_160(size_t W_size) :
+ MDx_HashFunction(64, true, true), digest(5), W(W_size)
+ {
+ clear();
+ }
void compress_n(const byte[], size_t blocks);
void copy_out(byte[]);
diff --git a/src/hash/sha2_32/sha2_32.h b/src/hash/sha2_32/sha2_32.h
index 3b95812b8..ffda11772 100644
--- a/src/hash/sha2_32/sha2_32.h
+++ b/src/hash/sha2_32/sha2_32.h
@@ -19,11 +19,13 @@ namespace Botan {
class BOTAN_DLL SHA_224 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "SHA-224"; }
+ size_t output_length() const { return 28; }
HashFunction* clone() const { return new SHA_224; }
- SHA_224() : MDx_HashFunction(28, 64, true, true), W(64), digest(8)
+ void clear();
+
+ SHA_224() : MDx_HashFunction(64, true, true), W(64), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
@@ -38,11 +40,13 @@ class BOTAN_DLL SHA_224 : public MDx_HashFunction
class BOTAN_DLL SHA_256 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "SHA-256"; }
+ size_t output_length() const { return 32; }
HashFunction* clone() const { return new SHA_256; }
- SHA_256() : MDx_HashFunction(32, 64, true, true), W(64), digest(8)
+ void clear();
+
+ SHA_256() : MDx_HashFunction(64, true, true), W(64), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
diff --git a/src/hash/sha2_64/sha2_64.h b/src/hash/sha2_64/sha2_64.h
index 59e2c4c83..dcfb7224c 100644
--- a/src/hash/sha2_64/sha2_64.h
+++ b/src/hash/sha2_64/sha2_64.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL SHA_384 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "SHA-384"; }
+ size_t output_length() const { return 48; }
HashFunction* clone() const { return new SHA_384; }
- SHA_384() : MDx_HashFunction(48, 128, true, true, 16), W(80), digest(8)
+ void clear();
+
+ SHA_384() : MDx_HashFunction(128, true, true, 16), W(80), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
@@ -37,10 +39,13 @@ class BOTAN_DLL SHA_384 : public MDx_HashFunction
class BOTAN_DLL SHA_512 : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "SHA-512"; }
+ size_t output_length() const { return 64; }
HashFunction* clone() const { return new SHA_512; }
- SHA_512() : MDx_HashFunction(64, 128, true, true, 16), W(80), digest(8)
+
+ void clear();
+
+ SHA_512() : MDx_HashFunction(128, true, true, 16), W(80), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index 37aed4357..1434f0b3e 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -168,7 +168,6 @@ void initial_block(MemoryRegion<u64bit>& H,
Skein_512::Skein_512(size_t arg_output_bits,
const std::string& arg_personalization) :
- HashFunction(arg_output_bits / 8),
personalization(arg_personalization),
output_bits(arg_output_bits),
H(9), T(3), buffer(64), buf_pos(0)
diff --git a/src/hash/skein/skein_512.h b/src/hash/skein/skein_512.h
index 54cdd002c..8605e5991 100644
--- a/src/hash/skein/skein_512.h
+++ b/src/hash/skein/skein_512.h
@@ -29,6 +29,7 @@ class BOTAN_DLL Skein_512 : public HashFunction
const std::string& personalization = "");
size_t hash_block_size() const { return 64; }
+ size_t output_length() const { return output_bits / 8; }
HashFunction* clone() const;
std::string name() const;
diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp
index 7f95267aa..6f40f84c8 100644
--- a/src/hash/tiger/tiger.cpp
+++ b/src/hash/tiger/tiger.cpp
@@ -55,7 +55,7 @@ void Tiger::compress_n(const byte input[], size_t blocks)
pass(C, A, B, X, 7); mix(X);
pass(B, C, A, X, 9);
- for(size_t j = 3; j != PASS; ++j)
+ for(size_t j = 3; j != passes; ++j)
{
mix(X);
pass(A, B, C, X, 9);
@@ -160,24 +160,26 @@ void Tiger::clear()
*/
std::string Tiger::name() const
{
- return "Tiger(" + to_string(output_length()) + "," + to_string(PASS) + ")";
+ return "Tiger(" + to_string(output_length()) + "," + to_string(passes) + ")";
}
/*
* Tiger Constructor
*/
-Tiger::Tiger(size_t hashlen, size_t pass) :
- MDx_HashFunction(hashlen, 64, false, false),
+Tiger::Tiger(size_t hash_len, size_t passes) :
+ MDx_HashFunction(64, false, false),
X(8),
digest(3),
- PASS(pass)
+ hash_len(hash_len),
+ passes(passes)
{
if(output_length() != 16 && output_length() != 20 && output_length() != 24)
throw Invalid_Argument("Tiger: Illegal hash output size: " +
to_string(output_length()));
- if(PASS < 3)
+
+ if(passes < 3)
throw Invalid_Argument("Tiger: Invalid number of passes: "
- + to_string(PASS));
+ + to_string(passes));
clear();
}
diff --git a/src/hash/tiger/tiger.h b/src/hash/tiger/tiger.h
index 7d753c237..09c9947fb 100644
--- a/src/hash/tiger/tiger.h
+++ b/src/hash/tiger/tiger.h
@@ -18,14 +18,16 @@ namespace Botan {
class BOTAN_DLL Tiger : public MDx_HashFunction
{
public:
- void clear();
std::string name() const;
+ size_t output_length() const { return hash_len; }
HashFunction* clone() const
{
- return new Tiger(output_length(), PASS);
+ return new Tiger(output_length(), passes);
}
+ void clear();
+
/**
* @param out_size specifies the output length; can be 16, 20, or 24
* @param passes to make in the algorithm
@@ -45,7 +47,7 @@ class BOTAN_DLL Tiger : public MDx_HashFunction
static const u64bit SBOX4[256];
SecureVector<u64bit> X, digest;
- const size_t PASS;
+ const size_t hash_len, passes;
};
}
diff --git a/src/hash/whirlpool/whrlpool.h b/src/hash/whirlpool/whrlpool.h
index 30bf91a34..ab7a78bc8 100644
--- a/src/hash/whirlpool/whrlpool.h
+++ b/src/hash/whirlpool/whrlpool.h
@@ -18,11 +18,13 @@ namespace Botan {
class BOTAN_DLL Whirlpool : public MDx_HashFunction
{
public:
- void clear();
std::string name() const { return "Whirlpool"; }
+ size_t output_length() const { return 64; }
HashFunction* clone() const { return new Whirlpool; }
- Whirlpool() : MDx_HashFunction(64, 64, true, true, 32), M(8), digest(8)
+ void clear();
+
+ Whirlpool() : MDx_HashFunction(64, true, true, 32), M(8), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);