-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.IO.Hashing
Milestone
Description
Background and motivation
There are many variants of CRC32 algorithm that differ only in polynomials used. The current implementation only supports IEEE 802.3 polynomial externally. It would be ideal if class would allow for defining custom polynomial thus supporting other CRC-32 variants (e.g. ISCSI, MPEG-2, etc.)
Looking at source, there is a Generate method in Crc32ReflectedTable so basic plumbing for custom polynomials seems to be there already.
As different polynomials use different initial and output XOR values, that would need to be added.
API Proposal
namespace namespace System.IO.Hashing
public sealed partial class Crc32 : NonCryptographicHashAlgorithm
{
public Crc32(ReadOnlySpan<byte> reflectedPolynomial);
public Crc32(ReadOnlySpan<byte> reflectedPolynomial,
ReadOnlySpan<byte> initialValue,
ReadOnlySpan<byte> xorValue,
bool reflectIn,
bool reflectOut);
}API Usage
var crc = new Crc32(new byte[] { 0x8F, 0x6E, 0x37, 0xA0 });
crc.Append(Encoding.ASCII.GetBytes("123456789"));
var result = crc.GetCurrentHash();Alternative Designs
No response
Risks
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.IO.Hashing