mirror of
https://github.com/SabreTools/SabreTools.Hashing.git
synced 2026-09-23 23:35:05 +00:00
Add CRC-8 implementations
This commit is contained in:
@@ -21,6 +21,28 @@ namespace SabreTools.Hashing.Test
|
||||
{HashType.BLAKE3, "d4bd7ca6f1ebea9580d9381106b248eb5b6069170d0bfd00b17d659fcd10dcdc"},
|
||||
#endif
|
||||
|
||||
{HashType.CRC8, "fc"},
|
||||
{HashType.CRC8_AUTOSAR, "ca"},
|
||||
{HashType.CRC8_BLUETOOTH, "00"},
|
||||
{HashType.CRC8_CDMA2000, "2d"},
|
||||
{HashType.CRC8_DARC, "35"},
|
||||
{HashType.CRC8_DVBS2, "5c"},
|
||||
{HashType.CRC8_GSMA, "d8"},
|
||||
{HashType.CRC8_GSMB, "f3"},
|
||||
{HashType.CRC8_HITAG, "aa"},
|
||||
{HashType.CRC8_I4321, "a9"},
|
||||
{HashType.CRC8_ICODE, "61"},
|
||||
{HashType.CRC8_LTE, "d7"},
|
||||
{HashType.CRC8_MAXIMDOW, "bd"},
|
||||
{HashType.CRC8_MIFAREMAD, "9b"},
|
||||
{HashType.CRC8_NRSC5, "e2"},
|
||||
{HashType.CRC8_OPENSAFETY, "fc"},
|
||||
{HashType.CRC8_ROHC, "17"},
|
||||
{HashType.CRC8_SAEJ1850, "55"},
|
||||
{HashType.CRC8_SMBUS, "fc"},
|
||||
{HashType.CRC8_TECH3250, "7d"},
|
||||
{HashType.CRC8_WCDMA, "c6"},
|
||||
|
||||
{HashType.CRC10_ATM, "26b"},
|
||||
{HashType.CRC10_CDMA2000, "14f"},
|
||||
{HashType.CRC10_GSM, "0e7"},
|
||||
|
||||
@@ -3,6 +3,290 @@ namespace SabreTools.Hashing.Crc
|
||||
/// <see href="https://reveng.sourceforge.io/crc-catalogue/all.htm#crc.legend"/>
|
||||
internal static class StandardDefinitions
|
||||
{
|
||||
#region CRC-8
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/AUTOSAR
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_AUTOSAR = new()
|
||||
{
|
||||
Name = "CRC-8/AUTOSAR",
|
||||
Width = 8,
|
||||
Poly = 0x2f,
|
||||
Init = 0xff,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0xff,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/BLUETOOTH
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_BLUETOOTH = new()
|
||||
{
|
||||
Name = "CRC-8/BLUETOOTH",
|
||||
Width = 8,
|
||||
Poly = 0xa7,
|
||||
Init = 0x00,
|
||||
ReflectIn = true,
|
||||
ReflectOut = true,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/CDMA2000
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_CDMA2000 = new()
|
||||
{
|
||||
Name = "CRC-8/CDMA2000",
|
||||
Width = 8,
|
||||
Poly = 0x9b,
|
||||
Init = 0xff,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/DARC
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_DARC = new()
|
||||
{
|
||||
Name = "CRC-8/DARC",
|
||||
Width = 8,
|
||||
Poly = 0x39,
|
||||
Init = 0x00,
|
||||
ReflectIn = true,
|
||||
ReflectOut = true,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/DVB-S2
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_DVBS2 = new()
|
||||
{
|
||||
Name = "CRC-8/DVB-S2",
|
||||
Width = 8,
|
||||
Poly = 0xd5,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/GSM-A
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_GSMA = new()
|
||||
{
|
||||
Name = "CRC-8/GSM-A",
|
||||
Width = 8,
|
||||
Poly = 0x1d,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/GSM-B
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_GSMB = new()
|
||||
{
|
||||
Name = "CRC-8/GSM-B",
|
||||
Width = 8,
|
||||
Poly = 0x49,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0xff,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/HITAG
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_HITAG = new()
|
||||
{
|
||||
Name = "CRC-8/HITAG",
|
||||
Width = 8,
|
||||
Poly = 0x1d,
|
||||
Init = 0xff,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/I-432-1 [CRC-8/ITU]
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_I4321 = new()
|
||||
{
|
||||
Name = "CRC-8/I-432-1",
|
||||
Width = 8,
|
||||
Poly = 0x07,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x55,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/I-CODE
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_ICODE = new()
|
||||
{
|
||||
Name = "CRC-8/I-CODE",
|
||||
Width = 8,
|
||||
Poly = 0x1d,
|
||||
Init = 0xfd,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/LTE
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_LTE = new()
|
||||
{
|
||||
Name = "CRC-8/LTE",
|
||||
Width = 8,
|
||||
Poly = 0x9b,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/MAXIM-DOW [CRC-8/MAXIM, DOW-CRC]
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_MAXIMDOW = new()
|
||||
{
|
||||
Name = "CRC-8/MAXIM-DOW",
|
||||
Width = 8,
|
||||
Poly = 0x31,
|
||||
Init = 0x00,
|
||||
ReflectIn = true,
|
||||
ReflectOut = true,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/MIFARE-MAD
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_MIFAREMAD = new()
|
||||
{
|
||||
Name = "CRC-8/MIFARE-MAD",
|
||||
Width = 8,
|
||||
Poly = 0x1d,
|
||||
Init = 0xc7,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/NRSC-5
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_NRSC5 = new()
|
||||
{
|
||||
Name = "CRC-8/NRSC-5",
|
||||
Width = 8,
|
||||
Poly = 0x31,
|
||||
Init = 0xff,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/OPENSAFETY
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_OPENSAFETY = new()
|
||||
{
|
||||
Name = "CRC-8/OPENSAFETY",
|
||||
Width = 8,
|
||||
Poly = 0x2f,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/ROHC
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_ROHC = new()
|
||||
{
|
||||
Name = "CRC-8/ROHC",
|
||||
Width = 8,
|
||||
Poly = 0x07,
|
||||
Init = 0xff,
|
||||
ReflectIn = true,
|
||||
ReflectOut = true,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/SAE-J1850
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_SAEJ1850 = new()
|
||||
{
|
||||
Name = "CRC-8/SAE-J1850",
|
||||
Width = 8,
|
||||
Poly = 0x1d,
|
||||
Init = 0xff,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0xff,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/SMBUS [CRC-8]
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_SMBUS = new()
|
||||
{
|
||||
Name = "CRC-8/SMBUS",
|
||||
Width = 8,
|
||||
Poly = 0x07,
|
||||
Init = 0x00,
|
||||
ReflectIn = false,
|
||||
ReflectOut = false,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/TECH-3250 [CRC-8/AES, CRC-8/EBU]
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_TECH3250 = new()
|
||||
{
|
||||
Name = "CRC-8/TECH-3250",
|
||||
Width = 8,
|
||||
Poly = 0x1d,
|
||||
Init = 0xff,
|
||||
ReflectIn = true,
|
||||
ReflectOut = true,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// CRC-8/WCDMA
|
||||
/// </summary>
|
||||
public static readonly CrcDefinition CRC8_WCDMA = new()
|
||||
{
|
||||
Name = "CRC-8/WCDMA",
|
||||
Width = 8,
|
||||
Poly = 0x9b,
|
||||
Init = 0x00,
|
||||
ReflectIn = true,
|
||||
ReflectOut = true,
|
||||
XorOut = 0x00,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region CRC-10
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -17,6 +17,116 @@ namespace SabreTools.Hashing
|
||||
BLAKE3,
|
||||
#endif
|
||||
|
||||
#region CRC-8
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum
|
||||
/// </summary>
|
||||
/// <remarks>Identical to <see cref="CRC8_SMBUS"/>
|
||||
CRC8,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/AUTOSAR)
|
||||
/// </summary>
|
||||
CRC8_AUTOSAR,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/BLUETOOTH)
|
||||
/// </summary>
|
||||
CRC8_BLUETOOTH,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/CDMA2000)
|
||||
/// </summary>
|
||||
CRC8_CDMA2000,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/DARC)
|
||||
/// </summary>
|
||||
CRC8_DARC,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/DVB-S2)
|
||||
/// </summary>
|
||||
CRC8_DVBS2,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/GSM-A)
|
||||
/// </summary>
|
||||
CRC8_GSMA,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/GSM-B)
|
||||
/// </summary>
|
||||
CRC8_GSMB,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/HITAG)
|
||||
/// </summary>
|
||||
CRC8_HITAG,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/I-432-1 [CRC-8/ITU])
|
||||
/// </summary>
|
||||
CRC8_I4321,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/I-CODE)
|
||||
/// </summary>
|
||||
CRC8_ICODE,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/LTE)
|
||||
/// </summary>
|
||||
CRC8_LTE,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/MAXIM-DOW [CRC-8/MAXIM, DOW-CRC])
|
||||
/// </summary>
|
||||
CRC8_MAXIMDOW,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/MIFARE-MAD)
|
||||
/// </summary>
|
||||
CRC8_MIFAREMAD,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/NRSC-5)
|
||||
/// </summary>
|
||||
CRC8_NRSC5,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/OPENSAFETY)
|
||||
/// </summary>
|
||||
CRC8_OPENSAFETY,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/ROHC)
|
||||
/// </summary>
|
||||
CRC8_ROHC,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/SAE-J1850)
|
||||
/// </summary>
|
||||
CRC8_SAEJ1850,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/SMBUS [CRC-8])
|
||||
/// </summary>
|
||||
CRC8_SMBUS,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/TECH-3250 [CRC-8/AES, CRC-8/EBU])
|
||||
/// </summary>
|
||||
CRC8_TECH3250,
|
||||
|
||||
/// <summary>
|
||||
/// CRC 8-bit checksum (CRC-8/WCDMA)
|
||||
/// </summary>
|
||||
CRC8_WCDMA,
|
||||
|
||||
#endregion
|
||||
|
||||
#region CRC-10
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -119,6 +119,28 @@ namespace SabreTools.Hashing
|
||||
HashType.BLAKE3 => new Blake3HashAlgorithm(),
|
||||
#endif
|
||||
|
||||
HashType.CRC8 => new CrcRunner(StandardDefinitions.CRC8_SMBUS),
|
||||
HashType.CRC8_AUTOSAR => new CrcRunner(StandardDefinitions.CRC8_AUTOSAR),
|
||||
HashType.CRC8_BLUETOOTH => new CrcRunner(StandardDefinitions.CRC8_BLUETOOTH),
|
||||
HashType.CRC8_CDMA2000 => new CrcRunner(StandardDefinitions.CRC8_CDMA2000),
|
||||
HashType.CRC8_DARC => new CrcRunner(StandardDefinitions.CRC8_DARC),
|
||||
HashType.CRC8_DVBS2 => new CrcRunner(StandardDefinitions.CRC8_DVBS2),
|
||||
HashType.CRC8_GSMA => new CrcRunner(StandardDefinitions.CRC8_GSMA),
|
||||
HashType.CRC8_GSMB => new CrcRunner(StandardDefinitions.CRC8_GSMB),
|
||||
HashType.CRC8_HITAG => new CrcRunner(StandardDefinitions.CRC8_HITAG),
|
||||
HashType.CRC8_I4321 => new CrcRunner(StandardDefinitions.CRC8_I4321),
|
||||
HashType.CRC8_ICODE => new CrcRunner(StandardDefinitions.CRC8_ICODE),
|
||||
HashType.CRC8_LTE => new CrcRunner(StandardDefinitions.CRC8_LTE),
|
||||
HashType.CRC8_MAXIMDOW => new CrcRunner(StandardDefinitions.CRC8_MAXIMDOW),
|
||||
HashType.CRC8_MIFAREMAD => new CrcRunner(StandardDefinitions.CRC8_MIFAREMAD),
|
||||
HashType.CRC8_NRSC5 => new CrcRunner(StandardDefinitions.CRC8_NRSC5),
|
||||
HashType.CRC8_OPENSAFETY => new CrcRunner(StandardDefinitions.CRC8_OPENSAFETY),
|
||||
HashType.CRC8_ROHC => new CrcRunner(StandardDefinitions.CRC8_ROHC),
|
||||
HashType.CRC8_SAEJ1850 => new CrcRunner(StandardDefinitions.CRC8_SAEJ1850),
|
||||
HashType.CRC8_SMBUS => new CrcRunner(StandardDefinitions.CRC8_SMBUS),
|
||||
HashType.CRC8_TECH3250 => new CrcRunner(StandardDefinitions.CRC8_TECH3250),
|
||||
HashType.CRC8_WCDMA => new CrcRunner(StandardDefinitions.CRC8_WCDMA),
|
||||
|
||||
HashType.CRC10_ATM => new CrcRunner(StandardDefinitions.CRC10_ATM),
|
||||
HashType.CRC10_CDMA2000 => new CrcRunner(StandardDefinitions.CRC10_CDMA2000),
|
||||
HashType.CRC10_GSM => new CrcRunner(StandardDefinitions.CRC10_GSM),
|
||||
|
||||
Reference in New Issue
Block a user