ROHC compression/decompression library
Functions | Variables
crc.c File Reference

ROHC CRC routines. More...

#include "crc.h"
#include "protocols/ip_numbers.h"
#include "protocols/udp.h"
#include "protocols/rtp.h"
#include "protocols/esp.h"
#include "protocols/tcp.h"
#include <stdlib.h>
#include <assert.h>
Include dependency graph for crc.c:

Functions

static uint8_t ipv6_ext_calc_crc_static (const uint8_t *const ip, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of IPv6 extensions.
static uint8_t ipv6_ext_calc_crc_dyn (const uint8_t *const ip, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of IPv6 extensions.
static uint8_t * ipv6_get_first_extension (const uint8_t *const ip, uint8_t *const type)
 Get the first extension in an IPv6 packet.
static bool rohc_crc_get_polynom (const rohc_crc_type_t crc_type, uint8_t *const polynom)
 Get the polynom for the given CRC type.
static uint8_t crc_calc_8 (const uint8_t *const buf, const size_t size, const uint8_t init_val, const uint8_t *const crc_table)
 Optimized CRC-8 calculation using a table.
static uint8_t crc_calc_7 (const uint8_t *const buf, const size_t size, const uint8_t init_val, const uint8_t *const crc_table)
 Optimized CRC-7 calculation using a table.
static uint8_t crc_calc_3 (const uint8_t *const buf, const size_t size, const uint8_t init_val, const uint8_t *const crc_table)
 Optimized CRC-3 calculation using a table.
int crc_get_polynom (int type)
 Get the polynom for the given CRC type.
void crc_init_table (unsigned char *table, unsigned char poly)
 Initialize a CRC table given a 256-byte table and the polynom to use.
bool rohc_crc_init_table (uint8_t *const table, const rohc_crc_type_t crc_type)
 Initialize a CRC table given a 256-byte table and the CRC type to use.
uint8_t crc_calculate (const rohc_crc_type_t crc_type, const uint8_t *const data, const size_t length, const uint8_t init_val, const uint8_t *const crc_table)
 Calculate the checksum for the given data.
uint32_t crc_calc_fcs32 (const uint8_t *const data, const size_t length, const uint32_t init_val)
 Optimized CRC FCS-32 calculation using a table.
uint8_t compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an IP header.
uint8_t compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an IP header.
uint8_t udp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an UDP or UDP-Lite header.
uint8_t udp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an UDP or UDP-Lite header.
uint8_t esp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an ESP header.
uint8_t esp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an ESP header.
uint8_t rtp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of a RTP header.
uint8_t rtp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of a RTP header.
uint8_t tcp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an TCP header.
uint8_t tcp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an TCP header.

Variables

unsigned char crc_table_8 [256]
unsigned char crc_table_7 [256]
unsigned char crc_table_6 [256]
unsigned char crc_table_3 [256]
unsigned char crc_table_2 [256]
static const uint32_t crc_table_fcs32 [256]
 The pre-computed table for 32-bit Frame Check Sequence (FCS)

Detailed Description

ROHC CRC routines.

Author:
Didier Barvaux <didier.barvaux@toulouse.viveris.com>
Didier Barvaux <didier@barvaux.org>
FWX <rohc_team@dialine.fr>

Function Documentation

uint8_t compute_crc_dynamic ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-DYNAMIC part of an IP header.

Concerned fields are:

  • bytes 3-4, 5-6, 11-12 in original IPv4 header
  • bytes 5-6 in original IPv6 header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t compute_crc_static ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-STATIC part of an IP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-2, 7-10, 13-20 in original IPv4 header
  • bytes 1-4, 7-40 in original IPv6 header

This function is one of the functions that must exist in one profile for the framework to work.

Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
static uint8_t crc_calc_3 ( const uint8_t *const  buf,
const size_t  size,
const uint8_t  init_val,
const uint8_t *const  crc_table 
) [inline, static]

Optimized CRC-3 calculation using a table.

Parameters:
bufThe data to compute the CRC for
sizeThe size of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The CRC byte
static uint8_t crc_calc_7 ( const uint8_t *const  buf,
const size_t  size,
const uint8_t  init_val,
const uint8_t *const  crc_table 
) [inline, static]

Optimized CRC-7 calculation using a table.

Parameters:
bufThe data to compute the CRC for
sizeThe size of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The CRC byte
static uint8_t crc_calc_8 ( const uint8_t *const  buf,
const size_t  size,
const uint8_t  init_val,
const uint8_t *const  crc_table 
) [inline, static]

Optimized CRC-8 calculation using a table.

Parameters:
bufThe data to compute the CRC for
sizeThe size of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The CRC byte
uint32_t crc_calc_fcs32 ( const uint8_t *const  data,
const size_t  length,
const uint32_t  init_val 
)

Optimized CRC FCS-32 calculation using a table.

Parameters:
dataThe data to compute the CRC for
lengthThe size of the data
init_valThe initial value of the CRC
Returns:
The 32-bit CRC
uint8_t crc_calculate ( const rohc_crc_type_t  crc_type,
const uint8_t *const  data,
const size_t  length,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Calculate the checksum for the given data.

Parameters:
crc_typeThe CRC type
dataThe data to calculate the checksum on
lengthThe length of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t esp_compute_crc_dynamic ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-DYNAMIC part of an ESP header.

Concerned fields are:

  • bytes 5-8 in original ESP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t esp_compute_crc_static ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-STATIC part of an ESP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-4 in original ESP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
static uint8_t ipv6_ext_calc_crc_dyn ( const uint8_t *const  ip,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
) [static]

Compute the CRC-DYNAMIC part of IPv6 extensions.

Only entire AH header is concerned.

Parameters:
ipThe IPv6 packet
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
static uint8_t ipv6_ext_calc_crc_static ( const uint8_t *const  ip,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
) [static]

Compute the CRC-STATIC part of IPv6 extensions.

Prototypes of private functions

Private functions All extensions are concerned except entire AH header.

Parameters:
ipThe IPv6 packet
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
static uint8_t * ipv6_get_first_extension ( const uint8_t *const  ip,
uint8_t *const  type 
) [static]

Get the first extension in an IPv6 packet.

Parameters:
ipThe IPv6 packet
typeThe type of the extension
Returns:
The extension, NULL if there is no extension
static bool rohc_crc_get_polynom ( const rohc_crc_type_t  crc_type,
uint8_t *const  polynom 
) [static]

Get the polynom for the given CRC type.

Parameters:
crc_typeThe CRC type
polynomIN/OUT: the polynom for the requested CRC type
Returns:
true in case of success, false otherwise
bool rohc_crc_init_table ( uint8_t *const  table,
const rohc_crc_type_t  crc_type 
)

Initialize a CRC table given a 256-byte table and the CRC type to use.

Parameters:
tableIN/OUT: The 256-byte table to initialize
crc_typeThe type of CRC to initialize the table for
Returns:
true in case of success, false in case of failure
uint8_t rtp_compute_crc_dynamic ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-DYNAMIC part of a RTP header.

Concerned fields are:

  • bytes 2, 3-4, 5-8 in original RTP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t rtp_compute_crc_static ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-STATIC part of a RTP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1, 9-12 (and CSRC list) in original RTP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t tcp_compute_crc_dynamic ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-DYNAMIC part of an TCP header.

Concerned fields are:

  • bytes 5-20 in original TCP header
  • TCP options
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t tcp_compute_crc_static ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-STATIC part of an TCP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-4 in original TCP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t udp_compute_crc_dynamic ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-DYNAMIC part of an UDP or UDP-Lite header.

Concerned fields are:

  • bytes 5-6, 7-8 in original UDP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum
uint8_t udp_compute_crc_static ( const uint8_t *const  ip,
const uint8_t *const  ip2,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-STATIC part of an UDP or UDP-Lite header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-4 in original UDP header
Parameters:
ipThe outer IP packet
ip2The inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns:
The checksum

Variable Documentation

unsigned char crc_table_2[256]

The table to enable fast CRC-2 computation

Deprecated:
please do not use this variable anymore
unsigned char crc_table_3[256]

The table to enable fast CRC-3 computation

Deprecated:
please do not use this variable anymore
unsigned char crc_table_6[256]

The table to enable fast CRC-6 computation

Deprecated:
please do not use this variable anymore
unsigned char crc_table_7[256]

The table to enable fast CRC-7 computation

Deprecated:
please do not use this variable anymore
unsigned char crc_table_8[256]

The table to enable fast CRC-8 computation

Deprecated:
please do not use this variable anymore
const uint32_t crc_table_fcs32[256] [static]

The pre-computed table for 32-bit Frame Check Sequence (FCS)

x**0 + x**1 + x**2 + x**4 + x**5 + x**7 + x**8 + x**10 + x**11 + x**12 + x**16 + x**22 + x**23 + x**26 + x**32

Copied from RFC 1662, appendix C.3