summaryrefslogtreecommitdiffstats
path: root/lib/cryptopp/adler32.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-11-27 09:23:17 +0100
committerMattes D <github@xoft.cz>2013-11-27 09:23:17 +0100
commit49760db89d94ede5d123d927141a6cd60dbaaf07 (patch)
tree6c6cf99e4cf3128311a93cd187947b502f3732a0 /lib/cryptopp/adler32.cpp
parentcWorld::SpawnExperienceOrb() now returns the entity ID of the spawned orb. (diff)
parentFixed VC2008 compilation, normalized include paths. (diff)
downloadcuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.gz
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.bz2
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.lz
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.xz
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.zst
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.zip
Diffstat (limited to 'lib/cryptopp/adler32.cpp')
-rw-r--r--lib/cryptopp/adler32.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/cryptopp/adler32.cpp b/lib/cryptopp/adler32.cpp
new file mode 100644
index 000000000..0d52c0838
--- /dev/null
+++ b/lib/cryptopp/adler32.cpp
@@ -0,0 +1,77 @@
+// adler32.cpp - written and placed in the public domain by Wei Dai
+
+#include "pch.h"
+#include "adler32.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+void Adler32::Update(const byte *input, size_t length)
+{
+ const unsigned long BASE = 65521;
+
+ unsigned long s1 = m_s1;
+ unsigned long s2 = m_s2;
+
+ if (length % 8 != 0)
+ {
+ do
+ {
+ s1 += *input++;
+ s2 += s1;
+ length--;
+ } while (length % 8 != 0);
+
+ if (s1 >= BASE)
+ s1 -= BASE;
+ s2 %= BASE;
+ }
+
+ while (length > 0)
+ {
+ s1 += input[0]; s2 += s1;
+ s1 += input[1]; s2 += s1;
+ s1 += input[2]; s2 += s1;
+ s1 += input[3]; s2 += s1;
+ s1 += input[4]; s2 += s1;
+ s1 += input[5]; s2 += s1;
+ s1 += input[6]; s2 += s1;
+ s1 += input[7]; s2 += s1;
+
+ length -= 8;
+ input += 8;
+
+ if (s1 >= BASE)
+ s1 -= BASE;
+ if (length % 0x8000 == 0)
+ s2 %= BASE;
+ }
+
+ assert(s1 < BASE);
+ assert(s2 < BASE);
+
+ m_s1 = (word16)s1;
+ m_s2 = (word16)s2;
+}
+
+void Adler32::TruncatedFinal(byte *hash, size_t size)
+{
+ ThrowIfInvalidTruncatedSize(size);
+
+ switch (size)
+ {
+ default:
+ hash[3] = byte(m_s1);
+ case 3:
+ hash[2] = byte(m_s1 >> 8);
+ case 2:
+ hash[1] = byte(m_s2);
+ case 1:
+ hash[0] = byte(m_s2 >> 8);
+ case 0:
+ ;
+ }
+
+ Reset();
+}
+
+NAMESPACE_END