diff options
author | lloyd <[email protected]> | 2010-10-13 02:59:43 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 02:59:43 +0000 |
commit | 61ed0d4d90164675396feb7c7cecdd3bc5012f91 (patch) | |
tree | 31f48086086c78c6f0ce5fd533d819c8463be822 | |
parent | 3697dcff8b5e9765b41114281ce10e7ed3d3abb4 (diff) |
Remove most uses of HASH_BLOCK_SIZE
-rw-r--r-- | src/hash/bmw/bmw_512.cpp | 2 | ||||
-rw-r--r-- | src/hash/comb4p/comb4p.cpp | 4 | ||||
-rw-r--r-- | src/hash/gost_3411/gost_3411.cpp | 12 | ||||
-rw-r--r-- | src/hash/has160/has160.cpp | 2 | ||||
-rw-r--r-- | src/hash/hash.h | 7 | ||||
-rw-r--r-- | src/hash/md2/md2.cpp | 22 | ||||
-rw-r--r-- | src/hash/md4/md4.cpp | 2 | ||||
-rw-r--r-- | src/hash/md4_ia32/md4_ia32.cpp | 2 | ||||
-rw-r--r-- | src/hash/md5/md5.cpp | 2 | ||||
-rw-r--r-- | src/hash/md5_ia32/md5_ia32.cpp | 2 | ||||
-rw-r--r-- | src/hash/mdx_hash/mdx_hash.cpp | 20 | ||||
-rw-r--r-- | src/hash/rmd128/rmd128.cpp | 2 | ||||
-rw-r--r-- | src/hash/rmd160/rmd160.cpp | 2 | ||||
-rw-r--r-- | src/hash/sha1/sha160.cpp | 2 | ||||
-rw-r--r-- | src/hash/sha1_amd64/sha1_amd64.cpp | 2 | ||||
-rw-r--r-- | src/hash/sha1_ia32/sha1_ia32.cpp | 2 | ||||
-rw-r--r-- | src/hash/sha1_sse2/sha1_sse2.cpp | 2 | ||||
-rw-r--r-- | src/hash/tiger/tiger.cpp | 2 | ||||
-rw-r--r-- | src/hash/whirlpool/whrlpool.cpp | 2 | ||||
-rw-r--r-- | src/libstate/lookup.cpp | 2 | ||||
-rw-r--r-- | src/mac/hmac/hmac.cpp | 10 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.cpp | 4 |
22 files changed, 57 insertions, 52 deletions
diff --git a/src/hash/bmw/bmw_512.cpp b/src/hash/bmw/bmw_512.cpp index 3999cb95c..40338fdf0 100644 --- a/src/hash/bmw/bmw_512.cpp +++ b/src/hash/bmw/bmw_512.cpp @@ -147,7 +147,7 @@ void BMW_512::compress_n(const byte input[], size_t blocks) BMW_512_compress(&H[0], &M[0], &Q[0]); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/comb4p/comb4p.cpp b/src/hash/comb4p/comb4p.cpp index c4cd1cc79..5e336e98b 100644 --- a/src/hash/comb4p/comb4p.cpp +++ b/src/hash/comb4p/comb4p.cpp @@ -16,8 +16,8 @@ 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; + 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 diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp index dbd6335bd..47e073e1f 100644 --- a/src/hash/gost_3411/gost_3411.cpp +++ b/src/hash/gost_3411/gost_3411.cpp @@ -46,22 +46,22 @@ void GOST_34_11::add_data(const byte input[], size_t length) { buffer.copy(position, input, length); - if(position + length >= HASH_BLOCK_SIZE) + if(position + length >= hash_block_size()) { compress_n(&buffer[0], 1); - input += (HASH_BLOCK_SIZE - position); - length -= (HASH_BLOCK_SIZE - position); + input += (hash_block_size() - position); + length -= (hash_block_size() - position); position = 0; } } - const size_t full_blocks = length / HASH_BLOCK_SIZE; - const size_t remaining = length % HASH_BLOCK_SIZE; + const size_t full_blocks = length / hash_block_size(); + const size_t remaining = length % hash_block_size(); if(full_blocks) compress_n(input, full_blocks); - buffer.copy(position, input + full_blocks * HASH_BLOCK_SIZE, remaining); + buffer.copy(position, input + full_blocks * hash_block_size(), remaining); position += remaining; } diff --git a/src/hash/has160/has160.cpp b/src/hash/has160/has160.cpp index 72246a845..6890ccb85 100644 --- a/src/hash/has160/has160.cpp +++ b/src/hash/has160/has160.cpp @@ -135,7 +135,7 @@ void HAS_160::compress_n(const byte input[], size_t blocks) D = (digest[3] += D); E = (digest[4] += E); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/hash.h b/src/hash/hash.h index cdf90f184..b331debc2 100644 --- a/src/hash/hash.h +++ b/src/hash/hash.h @@ -18,12 +18,17 @@ namespace Botan { */ class BOTAN_DLL HashFunction : public BufferedComputation { - public: /** * The hash block size as defined for this algorithm. */ const u32bit HASH_BLOCK_SIZE; + public: + /** + * The hash block size as defined for this algorithm + */ + virtual size_t hash_block_size() const { return HASH_BLOCK_SIZE; } + /** * Get a new object representing the same algorithm as *this */ diff --git a/src/hash/md2/md2.cpp b/src/hash/md2/md2.cpp index f2d6d800b..195c0843e 100644 --- a/src/hash/md2/md2.cpp +++ b/src/hash/md2/md2.cpp @@ -39,8 +39,8 @@ void MD2::hash(const byte input[]) 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14 }; - X.copy(16, input, HASH_BLOCK_SIZE); - xor_buf(&X[32], &X[0], &X[16], HASH_BLOCK_SIZE); + X.copy(16, input, hash_block_size()); + xor_buf(&X[32], &X[0], &X[16], hash_block_size()); byte T = 0; for(size_t i = 0; i != 18; ++i) @@ -56,7 +56,7 @@ void MD2::hash(const byte input[]) } T = checksum[15]; - for(size_t i = 0; i != HASH_BLOCK_SIZE; ++i) + for(size_t i = 0; i != hash_block_size(); ++i) T = checksum[i] ^= SBOX[input[i] ^ T]; } @@ -67,16 +67,16 @@ void MD2::add_data(const byte input[], size_t length) { buffer.copy(position, input, length); - if(position + length >= HASH_BLOCK_SIZE) + if(position + length >= hash_block_size()) { hash(&buffer[0]); - input += (HASH_BLOCK_SIZE - position); - length -= (HASH_BLOCK_SIZE - position); - while(length >= HASH_BLOCK_SIZE) + input += (hash_block_size() - position); + length -= (hash_block_size() - position); + while(length >= hash_block_size()) { hash(input); - input += HASH_BLOCK_SIZE; - length -= HASH_BLOCK_SIZE; + input += hash_block_size(); + length -= hash_block_size(); } buffer.copy(input, length); position = 0; @@ -89,8 +89,8 @@ void MD2::add_data(const byte input[], size_t length) */ void MD2::final_result(byte output[]) { - for(size_t i = position; i != HASH_BLOCK_SIZE; ++i) - buffer[i] = static_cast<byte>(HASH_BLOCK_SIZE - position); + for(size_t i = position; i != hash_block_size(); ++i) + buffer[i] = static_cast<byte>(hash_block_size() - position); hash(&buffer[0]); hash(&checksum[0]); diff --git a/src/hash/md4/md4.cpp b/src/hash/md4/md4.cpp index 2b24d10fd..9b9ebab36 100644 --- a/src/hash/md4/md4.cpp +++ b/src/hash/md4/md4.cpp @@ -85,7 +85,7 @@ void MD4::compress_n(const byte input[], size_t blocks) C = (digest[2] += C); D = (digest[3] += D); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/md4_ia32/md4_ia32.cpp b/src/hash/md4_ia32/md4_ia32.cpp index 8983995fc..1e3cd64c3 100644 --- a/src/hash/md4_ia32/md4_ia32.cpp +++ b/src/hash/md4_ia32/md4_ia32.cpp @@ -19,7 +19,7 @@ void MD4_IA32::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { botan_md4_ia32_compress(digest, input, M); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/md5/md5.cpp b/src/hash/md5/md5.cpp index 9a5f95ca8..948f4e73b 100644 --- a/src/hash/md5/md5.cpp +++ b/src/hash/md5/md5.cpp @@ -107,7 +107,7 @@ void MD5::compress_n(const byte input[], size_t blocks) C = (digest[2] += C); D = (digest[3] += D); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/md5_ia32/md5_ia32.cpp b/src/hash/md5_ia32/md5_ia32.cpp index 66a18e6f5..6ae235d2b 100644 --- a/src/hash/md5_ia32/md5_ia32.cpp +++ b/src/hash/md5_ia32/md5_ia32.cpp @@ -24,7 +24,7 @@ void MD5_IA32::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { botan_md5_ia32_compress(digest, input, M); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp index 9bf6b573a..930f9a938 100644 --- a/src/hash/mdx_hash/mdx_hash.cpp +++ b/src/hash/mdx_hash/mdx_hash.cpp @@ -20,7 +20,7 @@ MDx_HashFunction::MDx_HashFunction(size_t hash_len, size_t block_len, HashFunction(hash_len, block_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) + if(COUNT_SIZE >= output_length() || COUNT_SIZE >= hash_block_size()) throw Invalid_Argument("MDx_HashFunction: COUNT_SIZE is too big"); count = position = 0; } @@ -45,22 +45,22 @@ void MDx_HashFunction::add_data(const byte input[], size_t length) { buffer.copy(position, input, length); - if(position + length >= HASH_BLOCK_SIZE) + if(position + length >= hash_block_size()) { compress_n(&buffer[0], 1); - input += (HASH_BLOCK_SIZE - position); - length -= (HASH_BLOCK_SIZE - position); + input += (hash_block_size() - position); + length -= (hash_block_size() - position); position = 0; } } - const size_t full_blocks = length / HASH_BLOCK_SIZE; - const size_t remaining = length % HASH_BLOCK_SIZE; + const size_t full_blocks = length / hash_block_size(); + const size_t remaining = length % hash_block_size(); if(full_blocks) compress_n(input, full_blocks); - buffer.copy(position, input + full_blocks * HASH_BLOCK_SIZE, remaining); + buffer.copy(position, input + full_blocks * hash_block_size(), remaining); position += remaining; } @@ -70,16 +70,16 @@ void MDx_HashFunction::add_data(const byte input[], size_t length) void MDx_HashFunction::final_result(byte output[]) { buffer[position] = (BIG_BIT_ENDIAN ? 0x80 : 0x01); - for(size_t i = position+1; i != HASH_BLOCK_SIZE; ++i) + for(size_t i = position+1; i != hash_block_size(); ++i) buffer[i] = 0; - if(position >= HASH_BLOCK_SIZE - COUNT_SIZE) + if(position >= hash_block_size() - COUNT_SIZE) { compress_n(&buffer[0], 1); zeroise(buffer); } - write_count(&buffer[HASH_BLOCK_SIZE - COUNT_SIZE]); + write_count(&buffer[hash_block_size() - COUNT_SIZE]); compress_n(&buffer[0], 1); copy_out(output); diff --git a/src/hash/rmd128/rmd128.cpp b/src/hash/rmd128/rmd128.cpp index edbe9fa84..cab4adf8b 100644 --- a/src/hash/rmd128/rmd128.cpp +++ b/src/hash/rmd128/rmd128.cpp @@ -147,7 +147,7 @@ void RIPEMD_128::compress_n(const byte input[], size_t blocks) digest[3] = digest[0] + B1 + C2; digest[0] = D2; - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/rmd160/rmd160.cpp b/src/hash/rmd160/rmd160.cpp index c3ae7119b..ff1c1c4ec 100644 --- a/src/hash/rmd160/rmd160.cpp +++ b/src/hash/rmd160/rmd160.cpp @@ -180,7 +180,7 @@ void RIPEMD_160::compress_n(const byte input[], size_t blocks) digest[4] = digest[0] + B1 + C2; digest[0] = C1; - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp index 4778e5765..aa6a066e8 100644 --- a/src/hash/sha1/sha160.cpp +++ b/src/hash/sha1/sha160.cpp @@ -125,7 +125,7 @@ void SHA_160::compress_n(const byte input[], size_t blocks) D = (digest[3] += D); E = (digest[4] += E); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/sha1_amd64/sha1_amd64.cpp b/src/hash/sha1_amd64/sha1_amd64.cpp index 00b1788cb..d32b44901 100644 --- a/src/hash/sha1_amd64/sha1_amd64.cpp +++ b/src/hash/sha1_amd64/sha1_amd64.cpp @@ -24,7 +24,7 @@ void SHA_160_AMD64::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { botan_sha160_amd64_compress(&digest[0], input, &W[0]); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/sha1_ia32/sha1_ia32.cpp b/src/hash/sha1_ia32/sha1_ia32.cpp index 6bc9f31ec..3e9cff047 100644 --- a/src/hash/sha1_ia32/sha1_ia32.cpp +++ b/src/hash/sha1_ia32/sha1_ia32.cpp @@ -24,7 +24,7 @@ void SHA_160_IA32::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { botan_sha160_ia32_compress(&digest[0], input, &W[0]); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/sha1_sse2/sha1_sse2.cpp b/src/hash/sha1_sse2/sha1_sse2.cpp index 8270f9ac4..e890967c6 100644 --- a/src/hash/sha1_sse2/sha1_sse2.cpp +++ b/src/hash/sha1_sse2/sha1_sse2.cpp @@ -317,7 +317,7 @@ void SHA_160_SSE2::compress_n(const byte input_bytes[], size_t blocks) D = (digest[3] += D); E = (digest[4] += E); - input += (HASH_BLOCK_SIZE / 16); + input += (hash_block_size() / 16); } #undef GET_P_32 diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp index 67baf8d19..7f95267aa 100644 --- a/src/hash/tiger/tiger.cpp +++ b/src/hash/tiger/tiger.cpp @@ -66,7 +66,7 @@ void Tiger::compress_n(const byte input[], size_t blocks) B = digest[1] = B - digest[1]; C = (digest[2] += C); - input += HASH_BLOCK_SIZE; + input += hash_block_size(); } } diff --git a/src/hash/whirlpool/whrlpool.cpp b/src/hash/whirlpool/whrlpool.cpp index bff4b27ad..5356252b2 100644 --- a/src/hash/whirlpool/whrlpool.cpp +++ b/src/hash/whirlpool/whrlpool.cpp @@ -120,7 +120,7 @@ void Whirlpool::compress_n(const byte in[], size_t blocks) digest[6] ^= B6 ^ M[6]; digest[7] ^= B7 ^ M[7]; - in += HASH_BLOCK_SIZE; + in += hash_block_size(); } } diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp index ad0362264..d971618c2 100644 --- a/src/libstate/lookup.cpp +++ b/src/libstate/lookup.cpp @@ -40,7 +40,7 @@ u32bit block_size_of(const std::string& name) return cipher->block_size(); if(const HashFunction* hash = af.prototype_hash_function(name)) - return hash->HASH_BLOCK_SIZE; + return hash->hash_block_size(); throw Algorithm_Not_Found(name); } diff --git a/src/mac/hmac/hmac.cpp b/src/mac/hmac/hmac.cpp index 90da24eaf..06923138a 100644 --- a/src/mac/hmac/hmac.cpp +++ b/src/mac/hmac/hmac.cpp @@ -40,7 +40,7 @@ void HMAC::key_schedule(const byte key[], size_t length) std::fill(i_key.begin(), i_key.end(), 0x36); std::fill(o_key.begin(), o_key.end(), 0x5C); - if(length > hash->HASH_BLOCK_SIZE) + if(length > hash->hash_block_size()) { SecureVector<byte> hmac_key = hash->process(key, length); xor_buf(i_key, hmac_key, hmac_key.size()); @@ -86,14 +86,14 @@ MessageAuthenticationCode* HMAC::clone() const */ HMAC::HMAC(HashFunction* hash_in) : MessageAuthenticationCode(hash_in->output_length(), - 0, 2*hash_in->HASH_BLOCK_SIZE), + 0, 2*hash_in->hash_block_size()), hash(hash_in) { - if(hash->HASH_BLOCK_SIZE == 0) + if(hash->hash_block_size() == 0) throw Invalid_Argument("HMAC cannot be used with " + hash->name()); - i_key.resize(hash->HASH_BLOCK_SIZE); - o_key.resize(hash->HASH_BLOCK_SIZE); + i_key.resize(hash->hash_block_size()); + o_key.resize(hash->hash_block_size()); } } diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp index e29770bde..fcbccc06e 100644 --- a/src/mac/ssl3mac/ssl3_mac.cpp +++ b/src/mac/ssl3mac/ssl3_mac.cpp @@ -77,11 +77,11 @@ SSL3_MAC::SSL3_MAC(HashFunction* hash_in) : hash_in->output_length()), hash(hash_in) { - if(hash->HASH_BLOCK_SIZE == 0) + if(hash->hash_block_size() == 0) throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name()); size_t INNER_HASH_LENGTH = - (hash->name() == "SHA-160") ? 60 : hash->HASH_BLOCK_SIZE; + (hash->name() == "SHA-160") ? 60 : hash->hash_block_size(); i_key.resize(INNER_HASH_LENGTH); o_key.resize(INNER_HASH_LENGTH); |