From 1b4760c4476fe9ad380cb485bee972d83efc756e Mon Sep 17 00:00:00 2001 From: r4mos Date: Mon, 3 Mar 2025 17:15:26 +0100 Subject: [PATCH] Add Custom CRC --- src/core/operations/CRCChecksum.mjs | 922 ++++++++++++++++++++----- tests/operations/tests/CRCChecksum.mjs | 55 ++ 2 files changed, 805 insertions(+), 172 deletions(-) diff --git a/src/core/operations/CRCChecksum.mjs b/src/core/operations/CRCChecksum.mjs index 8a24d303..09ccadbe 100644 --- a/src/core/operations/CRCChecksum.mjs +++ b/src/core/operations/CRCChecksum.mjs @@ -27,180 +27,731 @@ class CRCChecksum extends Operation { this.args = [ { name: "Algorithm", - type: "option", + type: "argSelector", value: [ - "CRC-3/GSM", - "CRC-3/ROHC", - "CRC-4/G-704", - "CRC-4/INTERLAKEN", - "CRC-4/ITU", - "CRC-5/EPC", - "CRC-5/EPC-C1G2", - "CRC-5/G-704", - "CRC-5/ITU", - "CRC-5/USB", - "CRC-6/CDMA2000-A", - "CRC-6/CDMA2000-B", - "CRC-6/DARC", - "CRC-6/G-704", - "CRC-6/GSM", - "CRC-6/ITU", - "CRC-7/MMC", - "CRC-7/ROHC", - "CRC-7/UMTS", - "CRC-8", - "CRC-8/8H2F", - "CRC-8/AES", - "CRC-8/AUTOSAR", - "CRC-8/BLUETOOTH", - "CRC-8/CDMA2000", - "CRC-8/DARC", - "CRC-8/DVB-S2", - "CRC-8/EBU", - "CRC-8/GSM-A", - "CRC-8/GSM-B", - "CRC-8/HITAG", - "CRC-8/I-432-1", - "CRC-8/I-CODE", - "CRC-8/ITU", - "CRC-8/LTE", - "CRC-8/MAXIM", - "CRC-8/MAXIM-DOW", - "CRC-8/MIFARE-MAD", - "CRC-8/NRSC-5", - "CRC-8/OPENSAFETY", - "CRC-8/ROHC", - "CRC-8/SAE-J1850", - "CRC-8/SAE-J1850-ZERO", - "CRC-8/SMBUS", - "CRC-8/TECH-3250", - "CRC-8/WCDMA", - "CRC-10/ATM", - "CRC-10/CDMA2000", - "CRC-10/GSM", - "CRC-10/I-610", - "CRC-11/FLEXRAY", - "CRC-11/UMTS", - "CRC-12/3GPP", - "CRC-12/CDMA2000", - "CRC-12/DECT", - "CRC-12/GSM", - "CRC-12/UMTS", - "CRC-13/BBC", - "CRC-14/DARC", - "CRC-14/GSM", - "CRC-15/CAN", - "CRC-15/MPT1327", - "CRC-16", - "CRC-16/A", - "CRC-16/ACORN", - "CRC-16/ARC", - "CRC-16/AUG-CCITT", - "CRC-16/AUTOSAR", - "CRC-16/B", - "CRC-16/BLUETOOTH", - "CRC-16/BUYPASS", - "CRC-16/CCITT", - "CRC-16/CCITT-FALSE", - "CRC-16/CCITT-TRUE", - "CRC-16/CCITT-ZERO", - "CRC-16/CDMA2000", - "CRC-16/CMS", - "CRC-16/DARC", - "CRC-16/DDS-110", - "CRC-16/DECT-R", - "CRC-16/DECT-X", - "CRC-16/DNP", - "CRC-16/EN-13757", - "CRC-16/EPC", - "CRC-16/EPC-C1G2", - "CRC-16/GENIBUS", - "CRC-16/GSM", - "CRC-16/I-CODE", - "CRC-16/IBM", - "CRC-16/IBM-3740", - "CRC-16/IBM-SDLC", - "CRC-16/IEC-61158-2", - "CRC-16/ISO-HDLC", - "CRC-16/ISO-IEC-14443-3-A", - "CRC-16/ISO-IEC-14443-3-B", - "CRC-16/KERMIT", - "CRC-16/LHA", - "CRC-16/LJ1200", - "CRC-16/LTE", - "CRC-16/M17", - "CRC-16/MAXIM", - "CRC-16/MAXIM-DOW", - "CRC-16/MCRF4XX", - "CRC-16/MODBUS", - "CRC-16/NRSC-5", - "CRC-16/OPENSAFETY-A", - "CRC-16/OPENSAFETY-B", - "CRC-16/PROFIBUS", - "CRC-16/RIELLO", - "CRC-16/SPI-FUJITSU", - "CRC-16/T10-DIF", - "CRC-16/TELEDISK", - "CRC-16/TMS37157", - "CRC-16/UMTS", - "CRC-16/USB", - "CRC-16/V-41-LSB", - "CRC-16/V-41-MSB", - "CRC-16/VERIFONE", - "CRC-16/X-25", - "CRC-16/XMODEM", - "CRC-16/ZMODEM", - "CRC-17/CAN-FD", - "CRC-21/CAN-FD", - "CRC-24/BLE", - "CRC-24/FLEXRAY-A", - "CRC-24/FLEXRAY-B", - "CRC-24/INTERLAKEN", - "CRC-24/LTE-A", - "CRC-24/LTE-B", - "CRC-24/OPENPGP", - "CRC-24/OS-9", - "CRC-30/CDMA", - "CRC-31/PHILIPS", - "CRC-32", - "CRC-32/AAL5", - "CRC-32/ADCCP", - "CRC-32/AIXM", - "CRC-32/AUTOSAR", - "CRC-32/BASE91-C", - "CRC-32/BASE91-D", - "CRC-32/BZIP2", - "CRC-32/C", - "CRC-32/CASTAGNOLI", - "CRC-32/CD-ROM-EDC", - "CRC-32/CKSUM", - "CRC-32/D", - "CRC-32/DECT-B", - "CRC-32/INTERLAKEN", - "CRC-32/ISCSI", - "CRC-32/ISO-HDLC", - "CRC-32/JAMCRC", - "CRC-32/MEF", - "CRC-32/MPEG-2", - "CRC-32/NVME", - "CRC-32/PKZIP", - "CRC-32/POSIX", - "CRC-32/Q", - "CRC-32/SATA", - "CRC-32/V-42", - "CRC-32/XFER", - "CRC-32/XZ", - "CRC-40/GSM", - "CRC-64/ECMA-182", - "CRC-64/GO-ECMA", - "CRC-64/GO-ISO", - "CRC-64/MS", - "CRC-64/NVME", - "CRC-64/REDIS", - "CRC-64/WE", - "CRC-64/XZ", - "CRC-82/DARC" + { + name: "Custom", + on: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-3/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-3/ROHC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-4/G-704", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-4/INTERLAKEN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-4/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/EPC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/EPC-C1G2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/G-704", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/USB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/CDMA2000-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/CDMA2000-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/G-704", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-7/MMC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-7/ROHC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-7/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/8H2F", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/AES", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/AUTOSAR", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/BLUETOOTH", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/DVB-S2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/EBU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/GSM-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/GSM-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/HITAG", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/I-432-1", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/I-CODE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/LTE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/MAXIM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/MAXIM-DOW", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/MIFARE-MAD", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/NRSC-5", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/OPENSAFETY", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/ROHC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/SAE-J1850", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/SAE-J1850-ZERO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/SMBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/TECH-3250", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/WCDMA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/ATM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/I-610", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-11/FLEXRAY", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-11/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/3GPP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/DECT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-13/BBC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-14/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-14/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-15/CAN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-15/MPT1327", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ACORN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/AUG-CCITT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/AUTOSAR", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/BLUETOOTH", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/BUYPASS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT-FALSE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT-TRUE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT-ZERO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CMS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DDS-110", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DECT-R", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DECT-X", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DNP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/EN-13757", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/EPC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/EPC-C1G2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/GENIBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/I-CODE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IBM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IBM-3740", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IBM-SDLC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IEC-61158-2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ISO-HDLC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ISO-IEC-14443-3-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ISO-IEC-14443-3-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/KERMIT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/LHA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/LJ1200", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/LTE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/M17", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MAXIM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MAXIM-DOW", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MCRF4XX", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MODBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/NRSC-5", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/OPENSAFETY-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/OPENSAFETY-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/PROFIBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/RIELLO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/SPI-FUJITSU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/T10-DIF", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/TELEDISK", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/TMS37157", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/USB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/V-41-LSB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/V-41-MSB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/VERIFONE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/X-25", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/XMODEM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ZMODEM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-17/CAN-FD", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-21/CAN-FD", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/BLE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/FLEXRAY-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/FLEXRAY-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/INTERLAKEN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/LTE-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/LTE-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/OPENPGP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/OS-9", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-30/CDMA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-31/PHILIPS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/AAL5", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/ADCCP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/AIXM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/AUTOSAR", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/BASE91-C", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/BASE91-D", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/BZIP2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/C", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/CASTAGNOLI", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/CD-ROM-EDC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/CKSUM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/D", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/DECT-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/INTERLAKEN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/ISCSI", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/ISO-HDLC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/JAMCRC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/MEF", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/MPEG-2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/NVME", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/PKZIP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/POSIX", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/Q", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/SATA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/V-42", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/XFER", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/XZ", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-40/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/ECMA-182", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/GO-ECMA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/GO-ISO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/MS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/NVME", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/REDIS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/WE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/XZ", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-82/DARC", + off: [1, 2, 3, 4, 5, 6] + } ] + }, + { + name: "Width (bits)", + type: "toggleString", + value: "0", + toggleValues: ["Decimal"] + }, + { + name: "Polynomial", + type: "toggleString", + value: "0", + toggleValues: ["Hex"] + }, + { + name: "Initialization", + type: "toggleString", + value: "0", + toggleValues: ["Hex"] + }, + { + name: "Reflect input", + type: "option", + value: ["True", "False"] + }, + { + name: "Reflect output", + type: "option", + value: ["True", "False"] + }, + { + name: "Xor Output", + type: "toggleString", + value: "0", + toggleValues: ["Hex"] } ]; } @@ -340,6 +891,32 @@ class CRCChecksum extends Operation { return VALUE.toString(16).padStart(Math.ceil(Number(width) / 4), "0"); } + /** + * Validates user input to perform a custom CRC + * + * @param {Object} widthObject + * @param {ArrayBuffer} input + * @param {Object} polyObject + * @param {Object} initObject + * @param {Object} reflectInObject + * @param {Object} reflectOutObject + * @param {Object} xorOutObject + */ + custom(widthObject, input, polyObject, initObject, reflectInObject, reflectOutObject, xorOutObject) { + try { + const width = BigInt(widthObject.string); + const poly = BigInt("0x" + polyObject.string); + const init = BigInt("0x" + initObject.string); + const reflectIn = reflectInObject.string === "True"; + const reflectOut = reflectOutObject.string === "True"; + const xorOut = BigInt("0x" + xorOutObject.string); + + return this.crc(width, input, poly, init, reflectIn, reflectOut, xorOut); + } catch (error) { + throw new OperationError("Invalid custom CRC arguments"); + } + } + /** * Calculation of all known CRCs. Names and constants extracted from https://reveng.sourceforge.io/crc-catalogue/all.htm * @@ -352,6 +929,7 @@ class CRCChecksum extends Operation { input = new Uint8Array(input); switch (algorithm) { + case "Custom": return this.custom(args[1], input, args[2], args[3], args[4], args[5], args[6]); case "CRC-3/GSM": return this.crc(3n, input, 0x3n, 0x0n, false, false, 0x7n); case "CRC-3/ROHC": return this.crc(3n, input, 0x3n, 0x7n, true, true, 0x0n); case "CRC-4/G-704": return this.crc(4n, input, 0x3n, 0x0n, true, true, 0x0n); diff --git a/tests/operations/tests/CRCChecksum.mjs b/tests/operations/tests/CRCChecksum.mjs index 403340dc..af21ba7f 100644 --- a/tests/operations/tests/CRCChecksum.mjs +++ b/tests/operations/tests/CRCChecksum.mjs @@ -1995,5 +1995,60 @@ TestRegister.addTests([ "args": ["CRC-82/DARC"] } ] + }, + { + name: "Custom. CRC-32", + input: "123456789", + expectedOutput: "cbf43926", + recipeConfig: [ + { + "op": "CRC Checksum", + "args": ["Custom", "32", "04C11DB7", "FFFFFFFF", "True", "True", "FFFFFFFF"] + } + ] + }, + { + name: "Custom. Invalid Width", + input: "123456789", + expectedOutput: "Invalid custom CRC arguments", + recipeConfig: [ + { + "op": "CRC Checksum", + "args": ["Custom", "ABC", "04C11DB7", "FFFFFFFF", "True", "True", "FFFFFFFF"] + } + ] + }, + { + name: "Custom. Invalid Poly", + input: "123456789", + expectedOutput: "Invalid custom CRC arguments", + recipeConfig: [ + { + "op": "CRC Checksum", + "args": ["Custom", "32", "", "FFFFFFFF", "True", "True", "FFFFFFFF"] + } + ] + }, + { + name: "Custom. Invalid Init", + input: "123456789", + expectedOutput: "Invalid custom CRC arguments", + recipeConfig: [ + { + "op": "CRC Checksum", + "args": ["Custom", "32", "04C11DB7", "", "True", "True", "FFFFFFFF"] + } + ] + }, + { + name: "Custom. Invalid Xor Out", + input: "123456789", + expectedOutput: "Invalid custom CRC arguments", + recipeConfig: [ + { + "op": "CRC Checksum", + "args": ["Custom", "32", "04C11DB7", "FFFFFFFF", "True", "True", ""] + } + ] } ]);