Path: blob/a-new-beginning/SharedDependencies/Sources/cryptopp/adler32.cpp
2 views
// adler32.cpp - originally written and placed in the public domain by Wei Dai12#include "pch.h"3#include "adler32.h"45NAMESPACE_BEGIN(CryptoPP)67void Adler32::Update(const byte *input, size_t length)8{9const unsigned long BASE = 65521;1011unsigned long s1 = m_s1;12unsigned long s2 = m_s2;1314if (length % 8 != 0)15{16do17{18s1 += *input++;19s2 += s1;20length--;21} while (length % 8 != 0);2223if (s1 >= BASE)24s1 -= BASE;25s2 %= BASE;26}2728while (length > 0)29{30s1 += input[0]; s2 += s1;31s1 += input[1]; s2 += s1;32s1 += input[2]; s2 += s1;33s1 += input[3]; s2 += s1;34s1 += input[4]; s2 += s1;35s1 += input[5]; s2 += s1;36s1 += input[6]; s2 += s1;37s1 += input[7]; s2 += s1;3839length -= 8;40input += 8;4142if (s1 >= BASE)43s1 -= BASE;44if (length % 0x8000 == 0)45s2 %= BASE;46}4748CRYPTOPP_ASSERT(s1 < BASE);49CRYPTOPP_ASSERT(s2 < BASE);5051m_s1 = (word16)s1;52m_s2 = (word16)s2;53}5455void Adler32::TruncatedFinal(byte *hash, size_t size)56{57ThrowIfInvalidTruncatedSize(size);5859switch (size)60{61default:62hash[3] = byte(m_s1);63// fall through64case 3:65hash[2] = byte(m_s1 >> 8);66// fall through67case 2:68hash[1] = byte(m_s2);69// fall through70case 1:71hash[0] = byte(m_s2 >> 8);72// fall through73case 0:74;75// fall through76}7778Reset();79}8081NAMESPACE_END828384