CRC-32

Calculates the CRC-32 value of a byte sequence.  This 32bit cyclic redundancy check value is used to determine errors caused by noise in I/O channels.  The input data data is considered a large binary number is divided by a certain value which is called the “generator polynomial”.  The remainder with some adaption made to it is considered the result.

Summary
CRC-32Calculates the CRC-32 value of a byte sequence.
CopyrightThis program is free software.
Files
C-kern/api/math/hash/crc32.hHeader file CRC-32.
C-kern/math/hash/crc32.cImplementation file CRC-32 impl.
Types
struct crc32_tExport crc32_t into global namespace.
Functions
CRC-32
calculate_crc32Calculates the CRC-32 checkusm of a data block.
test
unittest_math_hash_crc32Test crc32_t functionality.
crc32_tType which captures the partially calculated checksum.
valueThe crc32 value calculated from a sequence of bytes.
lifetime
crc32_INITStatic initializer.
init_crc32Initializes object of type crc32_t.
calculate
update_crc32Udates the CRC-32 checksum with the next chunk of data.
update2_crc32Internally used function from update_crc32 and calculate_crc32.
query
value_crc32Return the CRC32 checksum.
inline implementation
Functions
define calculate_crc32Implements calculate_crc32.
crc32_t
init_crc32Implements crc32_t.init_crc32.
value_crc32Implements crc32_t.value_crc32.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2013 Jörg Seebohn

Files

C-kern/api/math/hash/crc32.h

Header file CRC-32.

C-kern/math/hash/crc32.c

Implementation file CRC-32 impl.

Types

struct crc32_t

typedef struct crc32_t crc32_t

Export crc32_t into global namespace.

Functions

Summary
CRC-32
calculate_crc32Calculates the CRC-32 checkusm of a data block.
test
unittest_math_hash_crc32Test crc32_t functionality.

CRC-32

calculate_crc32

uint32_t calculate_crc32(size_t blocksize,
const void *datablock/*[blocksize]*/)

Calculates the CRC-32 checkusm of a data block.  Use type crc32_t if data bytes are not stored in consecutive memory addresses.

test

unittest_math_hash_crc32

int unittest_math_hash_crc32(void)

Test crc32_t functionality.

crc32_t

struct crc32_t

Type which captures the partially calculated checksum.

Usage

Use init_crc32 to initialize it.  Call update_crc32 either once or if your data is splitted over several blocks for every block once.  Call value_crc32 to get the computed CRC-32 checksum value.

Summary
valueThe crc32 value calculated from a sequence of bytes.
lifetime
crc32_INITStatic initializer.
init_crc32Initializes object of type crc32_t.
calculate
update_crc32Udates the CRC-32 checksum with the next chunk of data.
update2_crc32Internally used function from update_crc32 and calculate_crc32.
query
value_crc32Return the CRC32 checksum.

value

uint32_t value

The crc32 value calculated from a sequence of bytes.  The value will be updated every time update_crc32 is called.

lifetime

crc32_INIT

#define crc32_INIT { (uint32_t)-1 }

Static initializer.

init_crc32

void init_crc32(/*out*/crc32_t *crc)

Initializes object of type crc32_t.

calculate

update_crc32

void update_crc32(crc32_t *crc,
size_t blocksize,
const void *datablock/*[blocksize]*/)

Udates the CRC-32 checksum with the next chunk of data.

update2_crc32

uint32_t update2_crc32(uint32_t crcvalue,
size_t blocksize,
const void *datablock/*[blocksize]*/)

Internally used function from update_crc32 and calculate_crc32.

query

value_crc32

uint32_t value_crc32(const crc32_t *crc)

Return the CRC32 checksum.  The calculated value is the checksum of the concatenated byte sequence of successive calls to update_crc32.  To start a new computation call init_crc32 before calling update_crc32.  But calling init_crc32 also sets the CRC value to 0 which is returned by this function.

Functions

define calculate_crc32

Implements calculate_crc32.

crc32_t

init_crc32

Implements crc32_t.init_crc32.

value_crc32

Calculates the CRC-32 value of a byte sequence.
Implements CRC-32.
typedef struct crc32_t crc32_t
Export crc32_t into global namespace.
struct crc32_t
Type which captures the partially calculated checksum.
uint32_t calculate_crc32(size_t blocksize,
const void *datablock/*[blocksize]*/)
Calculates the CRC-32 checkusm of a data block.
int unittest_math_hash_crc32(void)
Test crc32_t functionality.
uint32_t value
The crc32 value calculated from a sequence of bytes.
#define crc32_INIT { (uint32_t)-1 }
Static initializer.
void init_crc32(/*out*/crc32_t *crc)
Initializes object of type crc32_t.
void update_crc32(crc32_t *crc,
size_t blocksize,
const void *datablock/*[blocksize]*/)
Udates the CRC-32 checksum with the next chunk of data.
uint32_t update2_crc32(uint32_t crcvalue,
size_t blocksize,
const void *datablock/*[blocksize]*/)
Internally used function from update_crc32 and calculate_crc32.
uint32_t value_crc32(const crc32_t *crc)
Return the CRC32 checksum.
Close