CRC32 API

API Reference


This module provides APIs for computing CRC of a binary buffer.

CRC (Cyclic Redundancy Check) are used to verify the integrity of data, like file, messages, etc...

Computing a CRC32

The CRC32 is computed by the function le_crc_Crc32. It takes a base buffer address, a length and a CRC32. When the CRC32 is expected to be first computed, the value LE_CRC_START_CRC32 needs to be set as crc32 value.

Note
It is possible to compute a "global" CRC32 of a huge amount of data by splitting into small blocks and continue computing the CRC32 on each one.

This code compute the whole CRC32 of amount of data splitted into an array of small blocks:

#define MAX_BLOCKS 4 // Maximum number of blocks
 
typedef struct
{
size_t blockSize; // size of the block
uint8_t *blockPtr; // pointer of the data
}
block_t;
 
uint32_t ComputeArrayCRC32
(
block_t blockArray[]
)
{
uint32_t crc = LE_CRC_START_CRC32; // New CRC initialized
int iBlock;
 
for (iBlock = 0; iBlock < MAX_BLOCKS; iBlock++)
{
if (blockArray[iBlock].blockPtr)
{
crc = le_crc_Crc32(blockArray[iBlock].blockPtr,
blockArray[iBlock].blockSize,
crc);
}
}
return crc;
}