LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
crc.h File Reference

CRC update routines (ARC, BinHex, CCITT, CCITT32, Kermit, ZIP). More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for crc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define JUNO_ARC_CRC_INIT   (0)
 Initial seed for CRC-16/ARC (IBM-16) computations.
 
#define JUNO_BINHEX_CRC_INIT   (0)
 Initial seed for BinHex 16-bit CRC computations.
 
#define JUNO_CCITT_CRC_INIT   (-1)
 Initial seed for CRC-16/CCITT computations (0xFFFF).
 
#define JUNO_CCITT32_CRC_INIT   (-1)
 Initial seed for 32-bit CCITT-style CRC computations (0xFFFFFFFF).
 
#define JUNO_KERMIT_CRC_INIT   (0)
 Initial seed for CRC-16/KERMIT computations.
 
#define JUNO_ZIP_CRC_INIT   (-1)
 Initial seed for ZIP/PKZIP CRC-32 computations (0xFFFFFFFF).
 
Internal masks (implementation detail)

Bit masks used by table-driven CRC update routines.

#define M1_16   0xff
 
#define M2_16   0xff00
 
#define M1_32   0xffffffff
 
#define M2_32   0xffffff00
 

Functions

uint16_t Juno_CrcArcUpdate (uint16_t iCrc, const void *pcData, size_t zDataSize)
 Update ARC CRC with new data.
 
uint16_t Juno_CrcBinhexUpdate (uint16_t iCrc, const void *pcData, size_t zDataSize)
 Update BinHex CRC with new data.
 
uint16_t Juno_CrcCcittUpdate (uint16_t iCrc, const void *pcData, size_t zDataSize)
 Update CCITT CRC (16-bit) with new data.
 
uint32_t Juno_CrcCcitt32Update (uint32_t iCrc, const void *pcData, size_t zDataSize)
 Update CCITT32 CRC (32-bit) with new data.
 
uint16_t Juno_CrcKermitUpdate (uint16_t iCrc, const void *pcData, size_t zDataSize)
 Update Kermit CRC with new data.
 
uint32_t Juno_CrcZipUpdate (uint32_t iCrc, const void *pcData, size_t zDataSize)
 Update ZIP CRC (CRC-32) with new data.
 

Detailed Description

CRC update routines (ARC, BinHex, CCITT, CCITT32, Kermit, ZIP).

Macro Definition Documentation

◆ JUNO_ARC_CRC_INIT

#define JUNO_ARC_CRC_INIT   (0)

Initial seed for CRC-16/ARC (IBM-16) computations.

Expands to 0 (all zeros). Use as the first iCrc value when starting a new ARC CRC computation.

◆ JUNO_BINHEX_CRC_INIT

#define JUNO_BINHEX_CRC_INIT   (0)

Initial seed for BinHex 16-bit CRC computations.

Expands to 0 (all zeros). Use as the first iCrc value for BinHex.

◆ JUNO_CCITT32_CRC_INIT

#define JUNO_CCITT32_CRC_INIT   (-1)

Initial seed for 32-bit CCITT-style CRC computations (0xFFFFFFFF).

Expands to -1 (all ones) as a C integer literal; when passed to the 32-bit function parameter it yields 0xFFFFFFFF. Use as the first iCrc value when starting a new CCITT32 computation.

◆ JUNO_CCITT_CRC_INIT

#define JUNO_CCITT_CRC_INIT   (-1)

Initial seed for CRC-16/CCITT computations (0xFFFF).

Expands to -1 (all ones) as a C integer literal; when passed to the 16-bit function parameter it yields 0xFFFF. Use as the first iCrc value when starting a new CCITT CRC computation.

◆ JUNO_KERMIT_CRC_INIT

#define JUNO_KERMIT_CRC_INIT   (0)

Initial seed for CRC-16/KERMIT computations.

Expands to 0 (all zeros). Use as the first iCrc value for Kermit.

◆ JUNO_ZIP_CRC_INIT

#define JUNO_ZIP_CRC_INIT   (-1)

Initial seed for ZIP/PKZIP CRC-32 computations (0xFFFFFFFF).

Expands to -1 (all ones) as a C integer literal; when passed to the 32-bit function parameter it yields 0xFFFFFFFF. Use as the first iCrc value when starting a new ZIP CRC computation.

◆ M1_16

#define M1_16   0xff

Low byte mask for 16-bit CRC.

◆ M1_32

#define M1_32   0xffffffff

Low word mask for 32-bit CRC.

◆ M2_16

#define M2_16   0xff00

High byte mask for 16-bit CRC.

◆ M2_32

#define M2_32   0xffffff00

High word mask for 32-bit CRC.

Function Documentation

◆ Juno_CrcArcUpdate()

uint16_t Juno_CrcArcUpdate ( uint16_t  iCrc,
const void *  pcData,
size_t  zDataSize 
)

Update ARC CRC with new data.

Parameters
iCrcRunning CRC value (use JUNO_ARC_CRC_INIT for first chunk).
pcDataPointer to data buffer (can be NULL when zDataSize is 0).
zDataSizeSize of data buffer in bytes.
Returns
Updated CRC value; returns 0 when pcData is NULL or zDataSize is 0.

◆ Juno_CrcBinhexUpdate()

uint16_t Juno_CrcBinhexUpdate ( uint16_t  iCrc,
const void *  pcData,
size_t  zDataSize 
)

Update BinHex CRC with new data.

Parameters
iCrcRunning CRC value (use JUNO_BINHEX_CRC_INIT initially).
pcDataPointer to data buffer (can be NULL when zDataSize is 0).
zDataSizeSize of data buffer in bytes.
Returns
Updated CRC value; returns 0 when pcData is NULL or zDataSize is 0.

◆ Juno_CrcCcitt32Update()

uint32_t Juno_CrcCcitt32Update ( uint32_t  iCrc,
const void *  pcData,
size_t  zDataSize 
)

Update CCITT32 CRC (32-bit) with new data.

Parameters
iCrcRunning CRC value (use JUNO_CCITT32_CRC_INIT initially).
pcDataPointer to data buffer (can be NULL when zDataSize is 0).
zDataSizeSize of data buffer in bytes.
Returns
Updated CRC value; returns 0 when pcData is NULL or zDataSize is 0.

◆ Juno_CrcCcittUpdate()

uint16_t Juno_CrcCcittUpdate ( uint16_t  iCrc,
const void *  pcData,
size_t  zDataSize 
)

Update CCITT CRC (16-bit) with new data.

Parameters
iCrcRunning CRC value (use JUNO_CCITT_CRC_INIT initially).
pcDataPointer to data buffer (can be NULL when zDataSize is 0).
zDataSizeSize of data buffer in bytes.
Returns
Updated CRC value; returns 0 when pcData is NULL or zDataSize is 0.

◆ Juno_CrcKermitUpdate()

uint16_t Juno_CrcKermitUpdate ( uint16_t  iCrc,
const void *  pcData,
size_t  zDataSize 
)

Update Kermit CRC with new data.

Parameters
iCrcRunning CRC value (use JUNO_KERMIT_CRC_INIT initially).
pcDataPointer to data buffer (can be NULL when zDataSize is 0).
zDataSizeSize of data buffer in bytes.
Returns
Updated CRC value; returns 0 when pcData is NULL or zDataSize is 0.

◆ Juno_CrcZipUpdate()

uint32_t Juno_CrcZipUpdate ( uint32_t  iCrc,
const void *  pcData,
size_t  zDataSize 
)

Update ZIP CRC (CRC-32) with new data.

Applies a final XOR (0xFFFFFFFF) to the computed value before returning when data is processed. If streaming across multiple chunks, undo the XOR on the returned value before using it as the next iCrc. When pcData is NULL or zDataSize is 0, the function returns 0 (no XOR is applied in that case).

Parameters
iCrcRunning CRC value (use JUNO_ZIP_CRC_INIT initially).
pcDataPointer to data buffer (can be NULL when zDataSize is 0).
zDataSizeSize of data buffer in bytes.
Returns
Updated CRC-32 value; returns 0 when pcData is NULL or zDataSize is 0.