Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRC32 in simulation #5

Open
kkkKaiser opened this issue Apr 22, 2024 · 1 comment
Open

CRC32 in simulation #5

kkkKaiser opened this issue Apr 22, 2024 · 1 comment

Comments

@kkkKaiser
Copy link

Hello, may I ask what is the polynomial of CRC32? I couldn't find it through Google search, and I tried using IEEE802 but failed. Meanwhile, I don't quite understand the meaning of your coding in fun calculate_crc, which is quite different from what I saw online. Can you briefly explain how coding work, or are there any similar blogs that can be recommended? Thank you very much for your help.

@WangXuan95
Copy link
Owner

WangXuan95 commented Nov 22, 2024

Hello, my CRC32 implementation is written according to the C language below.
Note that the CRC polynomial of Gzip is fixed, and the different implementations you see are essentially the same polynomial.

uint32_t calcCrc32 (uint8_t *p_src, uint32_t len) {
    static const uint32_t TABLE_CRC32 [] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
    uint32_t crc = 0xFFFFFFFF;
    uint8_t *p_end = p_src + len;
    for (; p_src<p_end; p_src++) {
        crc ^= *p_src;
        crc = TABLE_CRC32[crc & 0x0f] ^ (crc >> 4);
        crc = TABLE_CRC32[crc & 0x0f] ^ (crc >> 4);
    }
    return ~crc;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants