CRC32C Interface
Interface Description
Computes the CRC32C checksum for a character array.
Interface Format
uint32_t KsalCrc32c(uint32_t seed, uint8_t *data, uint64_t len);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
seed |
32-bit integer |
Indicates the CRC seed. |
Input |
data |
Character array |
Indicates the character array for CRC. |
Input |
len |
64-bit integer |
Indicates the array length. |
Input |
crc |
32-bit integer |
Outputs the CRC checksum. |
Output |
Dependency
ksal/ksal_crc.h
Example
- Write the CRC32C test code.
- Create a test.c file.
vi test.c
- Press i to enter the insert mode and add the following test code to the file:
#include <stdio.h> #include <stdlib.h> #include <ksal/ksal_crc.h> int main(int argc, char **argv) { uint8_t buf[4096]; for (size_t i = 0; i < sizeof(buf); ++i) { buf[i] = (int8_t)i & 0xff; } uint32_t crc = KsalCrc32c(0x123, buf, sizeof(buf)); printf("crc = 0x%x\r\n", crc); return 0; } - Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
- Create a test.c file.
- Compile the test.c file into an executable file test.
gcc test.c -lksal -o test
- Run the test executable file.
./test
The command output is as follows:crc = 0x4ee4ecc1
Parent topic: KSAL Development Reference