Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

adler32.cpp

00001 // adler32.cpp - written and placed in the public domain by Wei Dai
00002 
00003 #include "pch.h"
00004 #include "adler32.h"
00005 
00006 NAMESPACE_BEGIN(CryptoPP)
00007 
00008 void Adler32::Update(const byte *input, unsigned int length)
00009 {
00010         const unsigned long BASE = 65521;
00011 
00012         unsigned long s1 = m_s1;
00013         unsigned long s2 = m_s2;
00014 
00015         while (length % 8 != 0)
00016         {
00017                 s1 += *input++;
00018                 s2 += s1;
00019                 length--;
00020         }
00021 
00022         while (length > 0)
00023         {
00024                 s1 += input[0]; s2 += s1;
00025                 s1 += input[1]; s2 += s1;
00026                 s1 += input[2]; s2 += s1;
00027                 s1 += input[3]; s2 += s1;
00028                 s1 += input[4]; s2 += s1;
00029                 s1 += input[5]; s2 += s1;
00030                 s1 += input[6]; s2 += s1;
00031                 s1 += input[7]; s2 += s1;
00032 
00033                 length -= 8;
00034                 input += 8;
00035 
00036                 if (s1 >= BASE)
00037                         s1 -= BASE;
00038                 if (length % 0x8000 == 0)
00039                         s2 %= BASE;
00040         }
00041 
00042         m_s1 = (word16)s1;
00043         m_s2 = (word16)s2;
00044 }
00045 
00046 void Adler32::Final(byte *hash)
00047 {
00048         hash[0] = byte(m_s2 >> 8);
00049         hash[1] = byte(m_s2);
00050         hash[2] = byte(m_s1 >> 8);
00051         hash[3] = byte(m_s1);
00052 
00053         Reset();
00054 }
00055 
00056 NAMESPACE_END

Generated at Mon Jan 15 01:16:29 2001 for Crypto++ by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000