Add CRC-10/11/12/13/14/15 implementations

This commit is contained in:
Matt Nadareski
2024-11-07 14:28:08 -05:00
parent a7f8e0664a
commit 0e8694cc90
4 changed files with 356 additions and 2 deletions

View File

@@ -21,6 +21,26 @@ namespace SabreTools.Hashing.Test
{HashType.BLAKE3, "d4bd7ca6f1ebea9580d9381106b248eb5b6069170d0bfd00b17d659fcd10dcdc"},
#endif
{HashType.CRC10_ATM, "26b"},
{HashType.CRC10_CDMA2000, "14f"},
{HashType.CRC10_GSM, "0e7"},
{HashType.CRC11_FLEXRAY, "18b"},
{HashType.CRC11_UMTS, "347"},
{HashType.CRC12_CDMA2000, "f9c"},
{HashType.CRC12_DECT, "d62"},
{HashType.CRC12_GSM, "975"},
{HashType.CRC12_UMTS, "46b"},
{HashType.CRC13_BBC, "074f"},
{HashType.CRC14_DARC, "0add"},
{HashType.CRC14_GSM, "0c7d"},
{HashType.CRC15_CAN, "66c3"},
{HashType.CRC15_MPT1327, "013b"},
{HashType.CRC16, "7573"},
{HashType.CRC16_ARC, "7573"},
{HashType.CRC16_CDMA2000, "8b5f"},

View File

@@ -3,6 +3,226 @@ namespace SabreTools.Hashing.Crc
/// <see href="https://reveng.sourceforge.io/crc-catalogue/all.htm#crc.legend"/>
internal static class StandardDefinitions
{
#region CRC-10
/// <summary>
/// CRC-10/ATM [CRC-10, CRC-10/I-610]
/// </summary>
public static readonly CrcDefinition CRC10_ATM = new()
{
Name = "CRC-10/ATM",
Width = 10,
Poly = 0x233,
Init = 0x000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x000,
};
/// <summary>
/// CRC-10/CDMA2000
/// </summary>
public static readonly CrcDefinition CRC10_CDMA2000 = new()
{
Name = "CRC-10/CDMA2000",
Width = 10,
Poly = 0x3d9,
Init = 0x3ff,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x000,
};
/// <summary>
/// CRC-10/GSM
/// </summary>
public static readonly CrcDefinition CRC10_GSM = new()
{
Name = "CRC-10/GSM",
Width = 10,
Poly = 0x175,
Init = 0x000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x3ff,
};
#endregion
#region CRC-11
/// <summary>
/// CRC-11/FLEXRAY [CRC-11]
/// </summary>
public static readonly CrcDefinition CRC11_FLEXRAY = new()
{
Name = "CRC-11/FLEXRAY",
Width = 11,
Poly = 0x385,
Init = 0x01a,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x000,
};
/// <summary>
/// CRC-11/UMTS
/// </summary>
public static readonly CrcDefinition CRC11_UMTS = new()
{
Name = "CRC-11/UMTS",
Width = 11,
Poly = 0x307,
Init = 0x000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x000,
};
#endregion
#region CRC-12
/// <summary>
/// CRC-12/CDMA2000
/// </summary>
public static readonly CrcDefinition CRC12_CDMA2000 = new()
{
Name = "CRC-12/CDMA2000",
Width = 12,
Poly = 0xf13,
Init = 0xfff,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x000,
};
/// <summary>
/// CRC-12/DECT [X-CRC-12]
/// </summary>
public static readonly CrcDefinition CRC12_DECT = new()
{
Name = "CRC-12/DECT",
Width = 12,
Poly = 0x80f,
Init = 0x000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x000,
};
/// <summary>
/// CRC-12/GSM
/// </summary>
public static readonly CrcDefinition CRC12_GSM = new()
{
Name = "CRC-12/GSM",
Width = 12,
Poly = 0xd31,
Init = 0x000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0xfff,
};
/// <summary>
/// CRC-12/UMTS [CRC-12/3GPP]
/// </summary>
public static readonly CrcDefinition CRC12_UMTS = new()
{
Name = "CRC-12/UMTS",
Width = 12,
Poly = 0x80f,
Init = 0x000,
ReflectIn = false,
ReflectOut = true,
XorOut = 0x000,
};
#endregion
#region CRC-13
/// <summary>
/// CRC-13/BBC
/// </summary>
public static readonly CrcDefinition CRC13_BBC = new()
{
Name = "CRC-13/BBC",
Width = 13,
Poly = 0x1cf5,
Init = 0x0000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x0000,
};
#endregion
#region CRC-14
/// <summary>
/// CRC-14/DARC
/// </summary>
public static readonly CrcDefinition CRC14_DARC = new()
{
Name = "CRC-14/DARC",
Width = 14,
Poly = 0x0805,
Init = 0x0000,
ReflectIn = true,
ReflectOut = true,
XorOut = 0x0000,
};
/// <summary>
/// CRC-14/GSM
/// </summary>
public static readonly CrcDefinition CRC14_GSM = new()
{
Name = "CRC-14/GSM",
Width = 14,
Poly = 0x202d,
Init = 0x0000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x3fff,
};
#endregion
#region CRC-15
/// <summary>
/// CRC-15/CAN [CRC-15]
/// </summary>
public static readonly CrcDefinition CRC15_CAN = new()
{
Name = "CRC-15/CAN",
Width = 15,
Poly = 0x4599,
Init = 0x0000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x0000,
};
/// <summary>
/// CRC-15/MPT1327
/// </summary>
public static readonly CrcDefinition CRC15_MPT1327 = new()
{
Name = "CRC-15/MPT1327",
Width = 15,
Poly = 0x6815,
Init = 0x0000,
ReflectIn = false,
ReflectOut = false,
XorOut = 0x0001,
};
#endregion
#region CRC-16
/// <summary>
@@ -458,7 +678,7 @@ namespace SabreTools.Hashing.Crc
};
#endregion
#region CRC-21
/// <summary>
@@ -476,7 +696,7 @@ namespace SabreTools.Hashing.Crc
};
#endregion
#region CRC-24
/// <summary>

View File

@@ -17,6 +17,100 @@ namespace SabreTools.Hashing
BLAKE3,
#endif
#region CRC-10
/// <summary>
/// CRC 10-bit checksum (CRC-10/ATM [CRC-10, CRC-10/I-610])
/// </summary>
CRC10_ATM,
/// <summary>
/// CRC 10-bit checksum (CRC-10/CDMA2000)
/// </summary>
CRC10_CDMA2000,
/// <summary>
/// CRC 10-bit checksum (CRC-10/GSM)
/// </summary>
CRC10_GSM,
#endregion
#region CRC-11
/// <summary>
/// CRC 11-bit checksum (CRC-11/FLEXRAY [CRC-11])
/// </summary>
CRC11_FLEXRAY,
/// <summary>
/// CRC 11-bit checksum (CRC-11/UMTS)
/// </summary>
CRC11_UMTS,
#endregion
#region CRC-12
/// <summary>
/// CRC 12-bit checksum (CRC-12/CDMA2000)
/// </summary>
CRC12_CDMA2000,
/// <summary>
/// CRC 12-bit checksum (CRC-12/DECT [X-CRC-12])
/// </summary>
CRC12_DECT,
/// <summary>
/// CRC 12-bit checksum (CRC-12/GSM)
/// </summary>
CRC12_GSM,
/// <summary>
/// CRC 12-bit checksum (CRC-12/UMTS [CRC-12/3GPP])
/// </summary>
CRC12_UMTS,
#endregion
#region CRC-13
/// <summary>
/// CRC 13-bit checksum (CRC-13/BBC)
/// </summary>
CRC13_BBC,
#endregion
#region CRC-14
/// <summary>
/// CRC 14-bit checksum (CRC-14/DARC)
/// </summary>
CRC14_DARC,
/// <summary>
/// CRC 14-bit checksum (CRC-14/GSM)
/// </summary>
CRC14_GSM,
#endregion
#region CRC-15
/// <summary>
/// CRC 15-bit checksum (CRC-15/CAN [CRC-15])
/// </summary>
CRC15_CAN,
/// <summary>
/// CRC 15-bit checksum (CRC-15/MPT1327)
/// </summary>
CRC15_MPT1327,
#endregion
#region CRC-16
/// <summary>

View File

@@ -119,6 +119,26 @@ namespace SabreTools.Hashing
HashType.BLAKE3 => new Blake3HashAlgorithm(),
#endif
HashType.CRC10_ATM => new CrcRunner(StandardDefinitions.CRC10_ATM),
HashType.CRC10_CDMA2000 => new CrcRunner(StandardDefinitions.CRC10_CDMA2000),
HashType.CRC10_GSM => new CrcRunner(StandardDefinitions.CRC10_GSM),
HashType.CRC11_FLEXRAY => new CrcRunner(StandardDefinitions.CRC11_FLEXRAY),
HashType.CRC11_UMTS => new CrcRunner(StandardDefinitions.CRC11_UMTS),
HashType.CRC12_CDMA2000 => new CrcRunner(StandardDefinitions.CRC12_CDMA2000),
HashType.CRC12_DECT => new CrcRunner(StandardDefinitions.CRC12_DECT),
HashType.CRC12_GSM => new CrcRunner(StandardDefinitions.CRC12_GSM),
HashType.CRC12_UMTS => new CrcRunner(StandardDefinitions.CRC12_UMTS),
HashType.CRC13_BBC => new CrcRunner(StandardDefinitions.CRC13_BBC),
HashType.CRC14_DARC => new CrcRunner(StandardDefinitions.CRC14_DARC),
HashType.CRC14_GSM => new CrcRunner(StandardDefinitions.CRC14_GSM),
HashType.CRC15_CAN => new CrcRunner(StandardDefinitions.CRC15_CAN),
HashType.CRC15_MPT1327 => new CrcRunner(StandardDefinitions.CRC15_MPT1327),
HashType.CRC16 => new CrcRunner(StandardDefinitions.CRC16_ARC),
HashType.CRC16_ARC => new CrcRunner(StandardDefinitions.CRC16_ARC),
HashType.CRC16_CDMA2000 => new CrcRunner(StandardDefinitions.CRC16_CDMA2000),