summaryrefslogtreecommitdiffstats
path: root/botan/src/checksum/adler32/adler32.cpp
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/checksum/adler32/adler32.cpp
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/checksum/adler32/adler32.cpp')
-rw-r--r--botan/src/checksum/adler32/adler32.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/botan/src/checksum/adler32/adler32.cpp b/botan/src/checksum/adler32/adler32.cpp
new file mode 100644
index 0000000..c66943b
--- /dev/null
+++ b/botan/src/checksum/adler32/adler32.cpp
@@ -0,0 +1,74 @@
+/*
+* Adler32
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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();
+ }
+
+}