// Copyright (c) 2026 Duplicati Inc. All rights reserved. namespace Duplicati.Proprietary.DiskImage.Partition; /// /// Provides CRC32 calculation utilities for partition table operations. /// internal static class Crc32 { /// /// Calculates the CRC32 checksum for the given data. /// /// The data buffer. /// The offset in the buffer to start calculation. /// The number of bytes to include in the CRC32 calculation. /// The calculated CRC32 checksum. public static uint Calculate(byte[] buffer, int offset, int count) { uint crc = 0xFFFFFFFF; for (int i = 0; i < count; i++) { byte b = buffer[offset + i]; crc ^= b; for (int j = 0; j < 8; j++) { if ((crc & 1) != 0) crc = (crc >> 1) ^ 0xEDB88320; else crc >>= 1; } } return ~crc; } }