Files
OpenRCT2-Web/src/openrct2/core/ChecksumStream.cpp
T

46 lines
1.3 KiB
C++
Raw Normal View History

2021-05-09 19:12:44 +01:00
/*****************************************************************************
2024-12-31 20:30:04 +01:00
* Copyright (c) 2014-2025 OpenRCT2 developers
2021-05-09 19:12:44 +01:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "ChecksumStream.h"
#include "Endianness.h"
namespace OpenRCT2
{
#ifndef DISABLE_NETWORK
ChecksumStream::ChecksumStream(std::array<std::byte, 20>& buf)
: _checksum(buf)
{
uint64_t* hash = reinterpret_cast<uint64_t*>(_checksum.data());
2025-01-19 16:59:45 +01:00
*hash = kSeed;
2021-05-09 19:12:44 +01:00
}
void ChecksumStream::Write(const void* buffer, uint64_t length)
{
for (size_t i = 0; i < length; i += sizeof(uint64_t))
{
const auto maxLen = std::min<size_t>(sizeof(uint64_t), length - i);
uint64_t value{};
std::memcpy(&value, reinterpret_cast<const std::byte*>(buffer) + i, maxLen);
2021-05-09 19:12:44 +01:00
Step(value);
2021-05-09 19:12:44 +01:00
}
}
void ChecksumStream::Step(uint64_t value)
{
uint64_t* hash = reinterpret_cast<uint64_t*>(_checksum.data());
*hash ^= value;
*hash *= kPrime;
}
2021-05-09 19:12:44 +01:00
#endif
} // namespace OpenRCT2