diff options
author | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
commit | 9bcfe627321ddc81691b835dffaa6324ac4684a4 (patch) | |
tree | fe5e8ae9813b853549558b59833022e87e83981b /src/checksum/adler32 | |
parent | 9822a701516396b7de4e41339faecd48ff8dc8ff (diff) |
Move all modules into src/ directory
Diffstat (limited to 'src/checksum/adler32')
-rw-r--r-- | src/checksum/adler32/adler32.cpp | 72 | ||||
-rw-r--r-- | src/checksum/adler32/adler32.h | 33 | ||||
-rw-r--r-- | src/checksum/adler32/modinfo.txt | 10 |
3 files changed, 115 insertions, 0 deletions
diff --git a/src/checksum/adler32/adler32.cpp b/src/checksum/adler32/adler32.cpp new file mode 100644 index 000000000..b808e3e67 --- /dev/null +++ b/src/checksum/adler32/adler32.cpp @@ -0,0 +1,72 @@ +/************************************************* +* Adler32 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/adler32.h> +#include <botan/loadstor.h> + +namespace Botan { + +/************************************************* +* Adler32 Checksum * +*************************************************/ +void Adler32::hash(const byte input[], u32bit length) + { + u32bit S1x = S1, S2x = S2; + while(length >= 16) + { + S1x += input[ 0]; S2x += S1x; + S1x += input[ 1]; S2x += S1x; + S1x += input[ 2]; S2x += S1x; + S1x += input[ 3]; S2x += S1x; + S1x += input[ 4]; S2x += S1x; + S1x += input[ 5]; S2x += S1x; + S1x += input[ 6]; S2x += S1x; + S1x += input[ 7]; S2x += S1x; + S1x += input[ 8]; S2x += S1x; + S1x += input[ 9]; S2x += S1x; + S1x += input[10]; S2x += S1x; + S1x += input[11]; S2x += S1x; + S1x += input[12]; S2x += S1x; + S1x += input[13]; S2x += S1x; + S1x += input[14]; S2x += S1x; + S1x += input[15]; S2x += S1x; + input += 16; + length -= 16; + } + for(u32bit j = 0; j != length; ++j) + { + S1x += input[j]; S2x += S1x; + } + S1x %= 65521; + S2x %= 65521; + S1 = S1x; + S2 = S2x; + } + +/************************************************* +* 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); + input += PROCESS_AMOUNT; + length -= PROCESS_AMOUNT; + } + hash(input, length); + } + +/************************************************* +* Finalize an Adler32 Checksum * +*************************************************/ +void Adler32::final_result(byte output[]) + { + store_be(output, S2, S1); + clear(); + } + +} diff --git a/src/checksum/adler32/adler32.h b/src/checksum/adler32/adler32.h new file mode 100644 index 000000000..1abce690c --- /dev/null +++ b/src/checksum/adler32/adler32.h @@ -0,0 +1,33 @@ +/************************************************* +* Adler32 Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_ADLER32_H__ +#define BOTAN_ADLER32_H__ + +#include <botan/base.h> + +namespace Botan { + +/************************************************* +* Adler32 * +*************************************************/ +class BOTAN_DLL Adler32 : public HashFunction + { + public: + void clear() throw() { S1 = 1; S2 = 0; } + std::string name() const { return "Adler32"; } + HashFunction* clone() const { return new Adler32; } + Adler32() : HashFunction(4) { clear(); } + ~Adler32() { clear(); } + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void hash(const byte[], u32bit); + u16bit S1, S2; + }; + +} + +#endif diff --git a/src/checksum/adler32/modinfo.txt b/src/checksum/adler32/modinfo.txt new file mode 100644 index 000000000..fb0f3c9cb --- /dev/null +++ b/src/checksum/adler32/modinfo.txt @@ -0,0 +1,10 @@ +realname "Adler32" + +define ADLER32 + +load_on auto + +<add> +adler32.cpp +adler32.h +</add> |