Is it possible to do CRC-32 calculation in splits?

后端 未结 4 548
粉色の甜心
粉色の甜心 2021-02-04 06:22

I use this trivial function to calculate the CRC checksum of a given file:

long i, j = 0;
int k = 0;
uint crc = 0xFFFFFFFF;
FileInfo file_info = new FileInfo(fil         


        
4条回答
  •  别跟我提以往
    2021-02-04 06:54

    This equation is key:

    CRC(a XOR b) == CRC(a) XOR CRC(b)
    

    Suppose you want to compute the CRC of the following message:

    "Always desire to learn something useful."
    

    There exist functions to compute the CRC as:

    crc_join(crc_part1("Always desire to lea"),
             crc_part2("rn something useful."))
    

    If crc_part1 and crc_part2 zeros pad (\0) their arguments as shown, crc_join is just XOR.

    crc_part1 = crc("Always desire to lea\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
    crc_part2 = crc("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0rn something useful.")
    

    The trailing zeros can be accounted for in crc_part1 with lookup tables. The leading zeros can be ignored in crc_part2.

    References:

    1. High-speed Parallel Architecture for Software-based CRC
      Youngju. Do, Sung-Rok. Yoon, Taekyu. Kim, Kwang Eui. Pyun and Sin-Chong. Park
    2. https://en.wikipedia.org/wiki/Cyclic_redundancy_check

提交回复
热议问题