diff --git a/package-lock.json b/package-lock.json index 406818f2..f73845b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4198,6 +4198,11 @@ "integrity": "sha1-8OgK4DmkvWVLXygfyT8EqRSn/M4=", "dev": true }, + "js-crc": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/js-crc/-/js-crc-0.2.0.tgz", + "integrity": "sha1-9yxcdhgXa/91zIEqHO2949jraDk=" + }, "js-sha3": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.6.1.tgz", diff --git a/package.json b/package.json index 976d902e..a096b9e0 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "exif-parser": "^0.1.12", "google-code-prettify": "^1.0.5", "jquery": "^3.1.1", + "js-crc": "^0.2.0", "js-sha3": "^0.6.1", "jsbn": "^1.1.0", "jsonpath": "^0.2.12", diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index b9bd990e..e59570e2 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -261,6 +261,7 @@ const Categories = [ "Fletcher-32 Checksum", "Fletcher-64 Checksum", "Adler-32 Checksum", + "CRC-16 Checksum", "CRC-32 Checksum", "TCP/IP Checksum", ] diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 2c98c4c5..38c86758 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3040,7 +3040,14 @@ const OperationConfig = { "CRC-32 Checksum": { description: "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.

The CRC was invented by W. Wesley Peterson in 1961; the 32-bit CRC function of Ethernet and many other standards is the work of several researchers and was published in 1975.", run: Checksum.runCRC32, - inputType: "byteArray", + inputType: "string", + outputType: "string", + args: [] + }, + "CRC-16 Checksum": { + description: "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.

The CRC was invented by W. Wesley Peterson in 1961.", + run: Checksum.runCRC16, + inputType: "string", outputType: "string", args: [] }, diff --git a/src/core/operations/Checksum.js b/src/core/operations/Checksum.js index f71e535d..58aac4bd 100755 --- a/src/core/operations/Checksum.js +++ b/src/core/operations/Checksum.js @@ -1,3 +1,4 @@ +import * as CRC from "js-crc"; import Utils from "../Utils.js"; @@ -119,19 +120,24 @@ const Checksum = { /** * CRC-32 Checksum operation. * - * @param {byteArray} input + * @param {string} input * @param {Object[]} args * @returns {string} */ runCRC32: function(input, args) { - let crcTable = global.crcTable || (global.crcTable = Checksum._genCRCTable()), - crc = 0 ^ (-1); + return CRC.crc32(input); + }, - for (let i = 0; i < input.length; i++) { - crc = (crc >>> 8) ^ crcTable[(crc ^ input[i]) & 0xff]; - } - return Utils.hex((crc ^ (-1)) >>> 0); + /** + * CRC-16 Checksum operation. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + runCRC16: function(input, args) { + return CRC.crc16(input); }, @@ -168,28 +174,6 @@ const Checksum = { return Utils.hex(0xffff - csum); }, - - /** - * Generates a CRC table for use with CRC checksums. - * - * @private - * @returns {array} - */ - _genCRCTable: function() { - let c, - crcTable = []; - - for (let n = 0; n < 256; n++) { - c = n; - for (let k = 0; k < 8; k++) { - c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); - } - crcTable[n] = c; - } - - return crcTable; - }, - }; export default Checksum; diff --git a/src/core/operations/Hash.js b/src/core/operations/Hash.js index 909950ad..261689c5 100755 --- a/src/core/operations/Hash.js +++ b/src/core/operations/Hash.js @@ -346,7 +346,8 @@ const Hash = { "\nFletcher-32: " + Checksum.runFletcher32(byteArray, []) + "\nFletcher-64: " + Checksum.runFletcher64(byteArray, []) + "\nAdler-32: " + Checksum.runAdler32(byteArray, []) + - "\nCRC-32: " + Checksum.runCRC32(byteArray, []); + "\nCRC-16: " + Checksum.runCRC16(input, []) + + "\nCRC-32: " + Checksum.runCRC32(input, []); return output; },