aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/hash/comb4p/comb4p.cpp28
-rw-r--r--src/hash/comb4p/comb4p.h2
-rw-r--r--src/hash/gost_3411/gost_3411.cpp2
-rw-r--r--src/hash/gost_3411/gost_3411.h2
-rw-r--r--src/hash/hash.h23
-rw-r--r--src/hash/md2/md2.h4
-rw-r--r--src/hash/mdx_hash/mdx_hash.cpp13
-rw-r--r--src/hash/mdx_hash/mdx_hash.h2
-rw-r--r--src/hash/skein/skein_512.cpp2
-rw-r--r--src/hash/skein/skein_512.h2
10 files changed, 44 insertions, 36 deletions
diff --git a/src/hash/comb4p/comb4p.cpp b/src/hash/comb4p/comb4p.cpp
index 5e336e98b..19e23879f 100644
--- a/src/hash/comb4p/comb4p.cpp
+++ b/src/hash/comb4p/comb4p.cpp
@@ -13,19 +13,6 @@ namespace Botan {
namespace {
-size_t comb4p_block_size(const HashFunction* h1,
- const HashFunction* h2)
- {
- if(h1->hash_block_size() == h2->hash_block_size())
- return h1->hash_block_size();
-
- /*
- * Return LCM of the block sizes? This would probably be OK for
- * HMAC, which is the main thing relying on knowing the block size.
- */
- return 0;
- }
-
void comb4p_round(MemoryRegion<byte>& out,
const MemoryRegion<byte>& in,
byte round_no,
@@ -48,8 +35,7 @@ void comb4p_round(MemoryRegion<byte>& out,
}
Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
- HashFunction(h1->output_length() + h2->output_length(),
- comb4p_block_size(h1, h2)),
+ HashFunction(h1->output_length() + h2->output_length()),
hash1(h1), hash2(h2)
{
if(hash1->name() == hash2->name())
@@ -63,6 +49,18 @@ Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
clear();
}
+size_t Comb4P::hash_block_size() const
+ {
+ if(hash1->hash_block_size() == hash2->hash_block_size())
+ return hash1->hash_block_size();
+
+ /*
+ * Return LCM of the block sizes? This would probably be OK for
+ * HMAC, which is the main thing relying on knowing the block size.
+ */
+ return 0;
+ }
+
void Comb4P::clear()
{
hash1->clear();
diff --git a/src/hash/comb4p/comb4p.h b/src/hash/comb4p/comb4p.h
index b09f2976b..67547f979 100644
--- a/src/hash/comb4p/comb4p.h
+++ b/src/hash/comb4p/comb4p.h
@@ -27,6 +27,8 @@ class BOTAN_DLL Comb4P : public HashFunction
~Comb4P() { delete hash1; delete hash2; }
+ size_t hash_block_size() const;
+
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 47e073e1f..fd47ba2c7 100644
--- a/src/hash/gost_3411/gost_3411.cpp
+++ b/src/hash/gost_3411/gost_3411.cpp
@@ -16,7 +16,7 @@ namespace Botan {
* GOST 34.11 Constructor
*/
GOST_34_11::GOST_34_11() :
- HashFunction(32, 32),
+ 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 1e9f3189d..64ea0f40c 100644
--- a/src/hash/gost_3411/gost_3411.h
+++ b/src/hash/gost_3411/gost_3411.h
@@ -23,6 +23,8 @@ class BOTAN_DLL GOST_34_11 : public HashFunction
std::string name() const { return "GOST-R-34.11-94" ; }
HashFunction* clone() const { return new GOST_34_11; }
+ size_t hash_block_size() const { return 32; }
+
GOST_34_11();
private:
void compress_n(const byte input[], size_t blocks);
diff --git a/src/hash/hash.h b/src/hash/hash.h
index b331debc2..95d12806f 100644
--- a/src/hash/hash.h
+++ b/src/hash/hash.h
@@ -18,16 +18,14 @@ namespace Botan {
*/
class BOTAN_DLL HashFunction : public BufferedComputation
{
- /**
- * The hash block size as defined for this algorithm.
- */
- const u32bit HASH_BLOCK_SIZE;
-
public:
/**
- * The hash block size as defined for this algorithm
+ * @param hash_len the output length
+ * @param block_len the internal block size (if applicable)
*/
- virtual size_t hash_block_size() const { return HASH_BLOCK_SIZE; }
+ HashFunction(u32bit hash_len) : BufferedComputation(hash_len) {}
+
+ virtual ~HashFunction() {}
/**
* Get a new object representing the same algorithm as *this
@@ -41,18 +39,15 @@ class BOTAN_DLL HashFunction : public BufferedComputation
virtual std::string name() const = 0;
/**
- * Reset the internal state of this object.
+ * The hash block size as defined for this algorithm
*/
- virtual void clear() = 0;
+ virtual size_t hash_block_size() const { return 0; }
/**
- * @param hash_len the output length
- * @param block_len the internal block size (if applicable)
+ * Reset the internal state of this object.
*/
- HashFunction(u32bit hash_len, u32bit block_len = 0) :
- BufferedComputation(hash_len), HASH_BLOCK_SIZE(block_len) {}
+ virtual void clear() = 0;
- virtual ~HashFunction() {}
private:
HashFunction& operator=(const HashFunction&);
};
diff --git a/src/hash/md2/md2.h b/src/hash/md2/md2.h
index 86e0d3c80..84f213811 100644
--- a/src/hash/md2/md2.h
+++ b/src/hash/md2/md2.h
@@ -22,7 +22,9 @@ class BOTAN_DLL MD2 : public HashFunction
std::string name() const { return "MD2"; }
HashFunction* clone() const { return new MD2; }
- MD2() : HashFunction(16, 16), X(48), checksum(16), buffer(16)
+ size_t hash_block_size() const { return 16; }
+
+ MD2() : HashFunction(16), X(48), checksum(16), buffer(16)
{ clear(); }
private:
void add_data(const byte[], size_t);
diff --git a/src/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp
index 930f9a938..84b97fd7f 100644
--- a/src/hash/mdx_hash/mdx_hash.cpp
+++ b/src/hash/mdx_hash/mdx_hash.cpp
@@ -14,11 +14,16 @@ namespace Botan {
/*
* MDx_HashFunction Constructor
*/
-MDx_HashFunction::MDx_HashFunction(size_t hash_len, size_t block_len,
- bool byte_end, bool bit_end,
+MDx_HashFunction::MDx_HashFunction(size_t hash_len,
+ size_t block_len,
+ bool byte_end,
+ bool bit_end,
size_t cnt_size) :
- HashFunction(hash_len, block_len), buffer(block_len),
- BIG_BYTE_ENDIAN(byte_end), BIG_BIT_ENDIAN(bit_end), COUNT_SIZE(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");
diff --git a/src/hash/mdx_hash/mdx_hash.h b/src/hash/mdx_hash/mdx_hash.h
index 6603f54bc..5591f2b80 100644
--- a/src/hash/mdx_hash/mdx_hash.h
+++ b/src/hash/mdx_hash/mdx_hash.h
@@ -31,6 +31,8 @@ class BOTAN_DLL MDx_HashFunction : public HashFunction
bool big_bit_endian,
size_t counter_size = 8);
+ size_t hash_block_size() const { return buffer.size(); }
+
virtual ~MDx_HashFunction() {}
protected:
void add_data(const byte input[], size_t length);
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index 665dd7248..cda8e3f56 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -168,7 +168,7 @@ void initial_block(MemoryRegion<u64bit>& H,
Skein_512::Skein_512(u32bit arg_output_bits,
const std::string& arg_personalization) :
- HashFunction(arg_output_bits / 8, 64),
+ 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 803f1c916..fce02c1f6 100644
--- a/src/hash/skein/skein_512.h
+++ b/src/hash/skein/skein_512.h
@@ -28,6 +28,8 @@ class BOTAN_DLL Skein_512 : public HashFunction
Skein_512(u32bit output_bits = 512,
const std::string& personalization = "");
+ size_t hash_block_size() const { return 64; }
+
HashFunction* clone() const;
std::string name() const;
void clear();