From 21d94214fda80487b6119b15f530608ece5f597d Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 12 Oct 2010 20:29:01 +0000 Subject: Remove Alder32::hash, replace by anon namespace function --- src/checksum/adler32/adler32.cpp | 33 ++++++++++++++++++++------------- src/checksum/adler32/adler32.h | 1 - 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/checksum') diff --git a/src/checksum/adler32/adler32.cpp b/src/checksum/adler32/adler32.cpp index c66943b88..09e42b8db 100644 --- a/src/checksum/adler32/adler32.cpp +++ b/src/checksum/adler32/adler32.cpp @@ -10,12 +10,14 @@ namespace Botan { -/* -* Adler32 Checksum -*/ -void Adler32::hash(const byte input[], u32bit length) +namespace { + +void adler32_update(const byte input[], size_t length, + u16bit& S1, u16bit& S2) { - u32bit S1x = S1, S2x = S2; + u32bit S1x = S1; + u32bit S2x = S2; + while(length >= 16) { S1x += input[ 0]; S2x += S1x; @@ -37,29 +39,34 @@ void Adler32::hash(const byte input[], u32bit length) input += 16; length -= 16; } - for(u32bit j = 0; j != length; ++j) + + for(size_t j = 0; j != length; ++j) { - S1x += input[j]; S2x += S1x; + S1x += input[j]; + S2x += S1x; } - S1x %= 65521; - S2x %= 65521; - S1 = S1x; - S2 = S2x; + + S1 = S1x % 65521; + S2 = S2x % 65521; } +} + /* * Update an Adler32 Checksum */ void Adler32::add_data(const byte input[], u32bit length) { const u32bit PROCESS_AMOUNT = 5552; + while(length >= PROCESS_AMOUNT) { - hash(input, PROCESS_AMOUNT); + adler32_update(input, PROCESS_AMOUNT, S1, S2); input += PROCESS_AMOUNT; length -= PROCESS_AMOUNT; } - hash(input, length); + + adler32_update(input, length, S1, S2); } /* diff --git a/src/checksum/adler32/adler32.h b/src/checksum/adler32/adler32.h index 8cbd67f10..4993e601b 100644 --- a/src/checksum/adler32/adler32.h +++ b/src/checksum/adler32/adler32.h @@ -26,7 +26,6 @@ class BOTAN_DLL Adler32 : public HashFunction private: void add_data(const byte[], u32bit); void final_result(byte[]); - void hash(const byte[], u32bit); u16bit S1, S2; }; -- cgit v1.2.3