1
0
mirror of synced 2025-01-19 01:24:15 +01:00

feat: Added additional CRC hash types (#991)

This adds some common CRC types.

---------

Signed-off-by: Jacob Creedon <jcreedon@gmail.com>
This commit is contained in:
Jacob Creedon 2023-03-22 02:53:57 -07:00 committed by GitHub
parent cec62d23b0
commit 3cfec69020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -73,6 +73,9 @@
"hex.builtin.hash.crc.xor_out", "hex.builtin.hash.crc.xor_out",
"hex.builtin.hash.crc16", "hex.builtin.hash.crc16",
"hex.builtin.hash.crc32", "hex.builtin.hash.crc32",
"hex.builtin.hash.crc32c",
"hex.builtin.hash.crc32mpeg",
"hex.builtin.hash.crc32posix",
"hex.builtin.hash.crc8", "hex.builtin.hash.crc8",
"hex.builtin.hash.md5", "hex.builtin.hash.md5",
"hex.builtin.hash.sha1", "hex.builtin.hash.sha1",

View File

@ -80,9 +80,12 @@
"hex.builtin.hash.crc.refl_in": "Reflect In", "hex.builtin.hash.crc.refl_in": "Reflect In",
"hex.builtin.hash.crc.refl_out": "Reflect Out", "hex.builtin.hash.crc.refl_out": "Reflect Out",
"hex.builtin.hash.crc.xor_out": "XOR Out", "hex.builtin.hash.crc.xor_out": "XOR Out",
"hex.builtin.hash.crc16": "CRC16", "hex.builtin.hash.crc16": "CRC-16",
"hex.builtin.hash.crc32": "CRC32", "hex.builtin.hash.crc32": "CRC-32",
"hex.builtin.hash.crc8": "CRC8", "hex.builtin.hash.crc32c": "CRC-32C",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC-8",
"hex.builtin.hash.md5": "MD5", "hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1", "hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224", "hex.builtin.hash.sha224": "SHA224",

View File

@ -108,8 +108,8 @@ namespace hex::plugin::builtin {
class HashCRC : public ContentRegistry::Hashes::Hash { class HashCRC : public ContentRegistry::Hashes::Hash {
public: public:
using CRCFunction = T(*)(prv::Provider*&, u64, size_t, u32, u32, u32, bool, bool); using CRCFunction = T(*)(prv::Provider*&, u64, size_t, u32, u32, u32, bool, bool);
HashCRC(const std::string &name, const CRCFunction &crcFunction, u32 polynomial, u32 initialValue, u32 xorOut) HashCRC(const std::string &name, const CRCFunction &crcFunction, u32 polynomial, u32 initialValue, u32 xorOut, bool reflectIn = false, bool reflectOut = false)
: Hash(name), m_crcFunction(crcFunction), m_polynomial(polynomial), m_initialValue(initialValue), m_xorOut(xorOut) {} : Hash(name), m_crcFunction(crcFunction), m_polynomial(polynomial), m_initialValue(initialValue), m_xorOut(xorOut), m_reflectIn(reflectIn), m_reflectOut(reflectOut) {}
void draw() override { void draw() override {
ImGui::InputHexadecimal("hex.builtin.hash.crc.poly"_lang, &this->m_polynomial); ImGui::InputHexadecimal("hex.builtin.hash.crc.poly"_lang, &this->m_polynomial);
@ -176,7 +176,9 @@ namespace hex::plugin::builtin {
ContentRegistry::Hashes::add<HashCRC<u8>>("hex.builtin.hash.crc8", crypt::crc8, 0x07, 0x0000, 0x0000); ContentRegistry::Hashes::add<HashCRC<u8>>("hex.builtin.hash.crc8", crypt::crc8, 0x07, 0x0000, 0x0000);
ContentRegistry::Hashes::add<HashCRC<u16>>("hex.builtin.hash.crc16", crypt::crc16, 0x8005, 0x0000, 0x0000); ContentRegistry::Hashes::add<HashCRC<u16>>("hex.builtin.hash.crc16", crypt::crc16, 0x8005, 0x0000, 0x0000);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0xFFFF'FFFF); ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0xFFFF'FFFF);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32mpeg", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0x0000'0000, false, false);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32posix", crypt::crc32, 0x04C1'1DB7, 0x0000'0000, 0xFFFF'FFFF, false, false);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32c", crypt::crc32, 0x1EDC'6F41, 0xFFFF'FFFF, 0xFFFF'FFFF, true, true);
} }
} }