Convert wsutil/crc*.[ch] to C99 types

This commit is contained in:
Gerald Combs 2023-06-28 15:39:16 -07:00
parent 1d3aed32b1
commit 000ebcb00a
18 changed files with 137 additions and 137 deletions

View File

@ -19,7 +19,7 @@
* his "gen_byte_crc10_table()" routine, rather than by calling that
* routine at run time, and with various data type cleanups.
*/
static const guint16 byte_crc10_table[256] = {
static const uint16_t byte_crc10_table[256] = {
0x0000, 0x0233, 0x0255, 0x0066, 0x0299, 0x00aa, 0x00cc, 0x02ff,
0x0301, 0x0132, 0x0154, 0x0367, 0x0198, 0x03ab, 0x03cd, 0x01fe,
0x0031, 0x0202, 0x0264, 0x0057, 0x02a8, 0x009b, 0x00fd, 0x02ce,
@ -55,8 +55,8 @@ static const guint16 byte_crc10_table[256] = {
};
/* Update the data block's CRC-10 remainder one byte at a time */
guint16
update_crc10_by_bytes(guint16 crc10_accum, const guint8 *data_blk_ptr,
uint16_t
update_crc10_by_bytes(uint16_t crc10_accum, const uint8_t *data_blk_ptr,
int data_blk_size)
{
register int i;

View File

@ -13,6 +13,6 @@
#include <wireshark.h>
/* Update the data block's CRC-10 remainder one byte at a time */
WS_DLL_PUBLIC guint16 update_crc10_by_bytes(guint16 crc10, const guint8 *data_blk_ptr, int data_blk_size);
WS_DLL_PUBLIC uint16_t update_crc10_by_bytes(uint16_t crc10, const uint8_t *data_blk_ptr, int data_blk_size);
#endif /* __CRC10_H__ */

View File

@ -27,7 +27,7 @@
/**
* Static table used for the table_driven implementation.
*****************************************************************************/
static const guint16 crc11_table_307_noreflect_noxor[256] = {
static const uint16_t crc11_table_307_noreflect_noxor[256] = {
0x000, 0x307, 0x60e, 0x509, 0x71b, 0x41c, 0x115, 0x212, 0x531, 0x636, 0x33f, 0x038, 0x22a, 0x12d, 0x424, 0x723,
0x165, 0x262, 0x76b, 0x46c, 0x67e, 0x579, 0x070, 0x377, 0x454, 0x753, 0x25a, 0x15d, 0x34f, 0x048, 0x541, 0x646,
0x2ca, 0x1cd, 0x4c4, 0x7c3, 0x5d1, 0x6d6, 0x3df, 0x0d8, 0x7fb, 0x4fc, 0x1f5, 0x2f2, 0x0e0, 0x3e7, 0x6ee, 0x5e9,
@ -52,10 +52,10 @@ static const guint16 crc11_table_307_noreflect_noxor[256] = {
* \param data_len Number of bytes in the \a data buffer.
* \return The updated crc value.
*****************************************************************************/
guint16 crc11_307_noreflect_noxor(const guint8 *data, guint64 data_len)
uint16_t crc11_307_noreflect_noxor(const uint8_t *data, uint64_t data_len)
{
guint16 crc = 0;
guint tbl_idx;
uint16_t crc = 0;
unsigned tbl_idx;
while (data_len--) {
tbl_idx = ((crc >> 3) ^ *data) & 0xff;

View File

@ -10,7 +10,7 @@
#ifndef __CRC11_____H__
#include <glib.h>
#include <stdint.h>
#include "ws_symbol_export.h"
@ -32,7 +32,7 @@ extern "C" {
* Algorithm = table-driven
*****************************************************************************/
WS_DLL_PUBLIC
guint16 crc11_307_noreflect_noxor(const guint8 *data, guint64 data_len);
uint16_t crc11_307_noreflect_noxor(const uint8_t *data, uint64_t data_len);
#ifdef __cplusplus
} /* closing brace for extern "C" */

View File

@ -27,9 +27,9 @@
*
* Modified 2009-03-16 not to include <stdint.h> as our Win32 environment
* appears not to have it; we're using GLib types, instead.
* Modified 2023-06-28 to use C99 types.
*****************************************************************************/
#include "wsutil/crc16-plain.h"
#include <stdlib.h>
/**
* Static table used for the table_driven implementation.
@ -123,7 +123,7 @@ crc16_plain_t crc16_plain_update(crc16_plain_t crc, const unsigned char *data, s
* ReflectOut = False
* Algorithm = table-driven
*****************************************************************************/
static const guint16 crc16_table_8005_noreflect_noxor[256] = {
static const uint16_t crc16_table_8005_noreflect_noxor[256] = {
0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
@ -166,10 +166,10 @@ static const guint16 crc16_table_8005_noreflect_noxor[256] = {
* \param data_len Number of bytes in the \a data buffer.
* \return The crc value.
*****************************************************************************/
guint16 crc16_8005_noreflect_noxor(const guint8 *data, guint64 data_len)
uint16_t crc16_8005_noreflect_noxor(const uint8_t *data, uint64_t data_len)
{
guint tbl_idx;
guint16 crc = 0;
unsigned tbl_idx;
uint16_t crc = 0;
while (data_len--) {
tbl_idx = ((crc >> 8) ^ *data) & 0xff;

View File

@ -30,10 +30,10 @@
#ifndef __CRC____PLAIN_H__
#define __CRC____PLAIN_H__
#include "ws_symbol_export.h"
#include <stddef.h>
#include <stdint.h>
#include <glib.h>
#include <stdlib.h>
#include "ws_symbol_export.h"
#ifdef __cplusplus
extern "C" {
@ -49,7 +49,7 @@ extern "C" {
*
* This type must be big enough to contain at least 16 bits.
*****************************************************************************/
typedef guint16 crc16_plain_t;
typedef uint16_t crc16_plain_t;
/**
* Reflect all bits of a \a data word of \a data_len bytes.
@ -111,7 +111,7 @@ static inline crc16_plain_t crc16_plain_finalize(crc16_plain_t crc)
* \return The crc value.
*****************************************************************************/
WS_DLL_PUBLIC
guint16 crc16_8005_noreflect_noxor(const guint8 *data, guint64 data_len);
uint16_t crc16_8005_noreflect_noxor(const uint8_t *data, uint64_t data_len);
#ifdef __cplusplus

View File

@ -58,7 +58,7 @@
/* */
/*****************************************************************/
static const guint crc16_ccitt_table_reverse[256] =
static const unsigned crc16_ccitt_table_reverse[256] =
{
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
@ -94,8 +94,8 @@ static const guint crc16_ccitt_table_reverse[256] =
0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
};
/* Same as above, only without reverse (Reverse=FALSE) */
static const guint crc16_ccitt_table[256] =
/* Same as above, only without reverse (Reverse=false) */
static const unsigned crc16_ccitt_table[256] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
@ -132,7 +132,7 @@ static const guint crc16_ccitt_table[256] =
};
/* This table was compiled using the polynom 0x5935 */
static const guint crc16_precompiled_5935[256] =
static const unsigned crc16_precompiled_5935[256] =
{
0x0000, 0x5935, 0xB26A, 0xEB5F, 0x3DE1, 0x64D4, 0x8F8B, 0xD6BE,
0x7BC2, 0x22F7, 0xC9A8, 0x909D, 0x4623, 0x1F16, 0xF449, 0xAD7C,
@ -169,7 +169,7 @@ static const guint crc16_precompiled_5935[256] =
};
/* This table was compiled using the polynom 0x755B */
static const guint crc16_precompiled_755B[] =
static const unsigned crc16_precompiled_755B[] =
{
0x0000, 0x755b, 0xeab6, 0x9fed, 0xa037, 0xd56c, 0x4a81, 0x3fda, /* 0x00 */
0x3535, 0x406e, 0xdf83, 0xaad8, 0x9502, 0xe059, 0x7fb4, 0x0aef, /* 0x08 */
@ -206,7 +206,7 @@ static const guint crc16_precompiled_755B[] =
};
/* This table was compiled using the polynom: 0x9949 */
static const guint crc16_precompiled_9949_reverse[] =
static const unsigned crc16_precompiled_9949_reverse[] =
{
0x0000, 0x0ED2, 0x1DA4, 0x1376, 0x3B48, 0x359A, 0x26EC, 0x283E,
0x7690, 0x7842, 0x6B34, 0x65E6, 0x4DD8, 0x430A, 0x507C, 0x5EAE,
@ -243,7 +243,7 @@ static const guint crc16_precompiled_9949_reverse[] =
};
/* This table was compiled using the polynom: 0x3D65 */
static const guint crc16_precompiled_3D65_reverse[] =
static const unsigned crc16_precompiled_3D65_reverse[] =
{
0x0000, 0x365E, 0x6CBC, 0x5AE2, 0xD978, 0xEF26, 0xB5C4, 0x839A,
0xFF89, 0xC9D7, 0x9335, 0xA56B, 0x26F1, 0x10AF, 0x4A4D, 0x7C13,
@ -280,7 +280,7 @@ static const guint crc16_precompiled_3D65_reverse[] =
};
/* This table was compiled using the polynom: 0x080F */
static const guint crc16_precompiled_080F[] =
static const unsigned crc16_precompiled_080F[] =
{
0x0000, 0x080F, 0x101E, 0x1811, 0x203C, 0x2833, 0x3022, 0x382D,
0x4078, 0x4877, 0x5066, 0x5869, 0x6044, 0x684B, 0x705A, 0x7855,
@ -328,7 +328,7 @@ static const guint crc16_precompiled_080F[] =
* - ReflectOut = True
* - Algorithm = table-driven
*/
static const guint crc16_usb_table[] = {
static const unsigned crc16_usb_table[] = {
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
@ -363,57 +363,57 @@ static const guint crc16_usb_table[] = {
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
};
static const guint16 crc16_ccitt_start = 0xFFFF;
static const guint16 crc16_ccitt_xorout = 0xFFFF;
static const uint16_t crc16_ccitt_start = 0xFFFF;
static const uint16_t crc16_ccitt_xorout = 0xFFFF;
static const guint16 crc16_usb_start = 0xFFFF;
static const guint16 crc16_usb_xorout = 0xFFFF;
static const uint16_t crc16_usb_start = 0xFFFF;
static const uint16_t crc16_usb_xorout = 0xFFFF;
/* two types of crcs are possible: unreflected (bits shift left) and
* reflected (bits shift right).
*/
static guint16 crc16_unreflected(const guint8 *buf, guint len,
guint16 crc_in, const guint table[])
static uint16_t crc16_unreflected(const uint8_t *buf, unsigned len,
uint16_t crc_in, const unsigned table[])
{
/* we use guints, rather than guint16s, as they are likely to be
faster. We just ignore the top 16 bits and let them do what they want.
*/
guint crc16 = (guint)crc_in;
unsigned crc16 = (unsigned)crc_in;
while( len-- != 0 )
crc16 = table[((crc16 >> 8) ^ *buf++) & 0xff] ^ (crc16 << 8);
return (guint16)crc16;
return (uint16_t)crc16;
}
static guint16 crc16_reflected(const guint8 *buf, guint len,
guint16 crc_in, const guint table[])
static uint16_t crc16_reflected(const uint8_t *buf, unsigned len,
uint16_t crc_in, const unsigned table[])
{
/* we use guints, rather than guint16s, as they are likely to be
faster. We just ignore the top 16 bits and let them do what they want.
XXX - does any time saved not zero-extending guint16's to 32 bits
XXX - does any time saved not zero-extending uint16_t's to 32 bits
into a register outweigh any increased cache footprint from the
larger CRC table? */
guint crc16 = (guint)crc_in;
unsigned crc16 = (unsigned)crc_in;
while( len-- != 0 )
crc16 = table[(crc16 ^ *buf++) & 0xff] ^ (crc16 >> 8);
return (guint16)crc16;
return (uint16_t)crc16;
}
guint16 crc16_ccitt(const guint8 *buf, guint len)
uint16_t crc16_ccitt(const uint8_t *buf, unsigned len)
{
return crc16_reflected(buf,len,crc16_ccitt_start,crc16_ccitt_table_reverse)
^ crc16_ccitt_xorout;
}
guint16 crc16_x25_ccitt_seed(const guint8 *buf, guint len, guint16 seed)
uint16_t crc16_x25_ccitt_seed(const uint8_t *buf, unsigned len, uint16_t seed)
{
return crc16_unreflected(buf,len,seed,crc16_ccitt_table);
}
guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed)
uint16_t crc16_ccitt_seed(const uint8_t *buf, unsigned len, uint16_t seed)
{
return crc16_reflected(buf,len,seed,crc16_ccitt_table_reverse)
^ crc16_ccitt_xorout;
@ -422,46 +422,46 @@ guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed)
/* ISO14443-3, section 6.2.4: For ISO14443-A, the polynomial 0x1021 is
used, the initial register value shall be 0x6363, the final register
value is not XORed with anything. */
guint16 crc16_iso14443a(const guint8 *buf, guint len)
uint16_t crc16_iso14443a(const uint8_t *buf, unsigned len)
{
return crc16_reflected(buf,len, 0x6363 ,crc16_ccitt_table_reverse);
}
guint16 crc16_usb(const guint8 *buf, guint len)
uint16_t crc16_usb(const uint8_t *buf, unsigned len)
{
return crc16_reflected(buf, len, crc16_usb_start, crc16_usb_table)
^ crc16_usb_xorout;
}
guint16 crc16_0x5935(const guint8 *buf, guint32 len, guint16 seed)
uint16_t crc16_0x5935(const uint8_t *buf, uint32_t len, uint16_t seed)
{
return crc16_unreflected(buf, len, seed, crc16_precompiled_5935);
}
guint16 crc16_0x755B(const guint8 *buf, guint32 len, guint16 seed)
uint16_t crc16_0x755B(const uint8_t *buf, uint32_t len, uint16_t seed)
{
return crc16_unreflected(buf, len, seed, crc16_precompiled_755B);
}
guint16 crc16_0x9949_seed(const guint8 *buf, guint len, guint16 seed)
uint16_t crc16_0x9949_seed(const uint8_t *buf, unsigned len, uint16_t seed)
{
return crc16_reflected(buf, len, seed, crc16_precompiled_9949_reverse);
}
guint16 crc16_0x3D65_seed(const guint8 *buf, guint len, guint16 seed)
uint16_t crc16_0x3D65_seed(const uint8_t *buf, unsigned len, uint16_t seed)
{
return crc16_reflected(buf, len, seed, crc16_precompiled_3D65_reverse);
}
guint16 crc16_0x080F_seed(const guint8 *buf, guint len, guint16 seed)
uint16_t crc16_0x080F_seed(const uint8_t *buf, unsigned len, uint16_t seed)
{
guint16 crc = seed;
uint16_t crc = seed;
if (len > 0)
{
while (len-- > 0)
{
guint8 data = *buf++;
uint8_t data = *buf++;
crc = crc16_precompiled_080F[((crc >> 8) ^ data)] ^ (crc << 8);
}
}

View File

@ -32,13 +32,13 @@ extern "C" {
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return The CRC16 CCITT checksum. */
WS_DLL_PUBLIC guint16 crc16_ccitt(const guint8 *buf, guint len);
WS_DLL_PUBLIC uint16_t crc16_ccitt(const uint8_t *buf, unsigned len);
/** Compute CRC16 X.25 CCITT checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return The CRC16 X.25 CCITT checksum. */
WS_DLL_PUBLIC guint16 crc16_x25_ccitt_seed(const guint8 *buf, guint len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_x25_ccitt_seed(const uint8_t *buf, unsigned len, uint16_t seed);
/** Compute CRC16 CCITT checksum of a buffer of data. If computing the
* checksum over multiple buffers and you want to feed the partial CRC16
@ -47,19 +47,19 @@ WS_DLL_PUBLIC guint16 crc16_x25_ccitt_seed(const guint8 *buf, guint len, guint16
@param len The number of bytes to include in the computation.
@param seed The seed to use.
@return The CRC16 CCITT checksum (using the given seed). */
WS_DLL_PUBLIC guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_ccitt_seed(const uint8_t *buf, unsigned len, uint16_t seed);
/** Compute the 16bit CRC_A value of a buffer as defined in ISO14443-3.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return the CRC16 checksum for the buffer */
WS_DLL_PUBLIC guint16 crc16_iso14443a(const guint8 *buf, guint len);
WS_DLL_PUBLIC uint16_t crc16_iso14443a(const uint8_t *buf, unsigned len);
/** Compute the 16bit CRC value of a buffer as defined in USB Specification.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return the CRC16 checksum for the buffer */
WS_DLL_PUBLIC guint16 crc16_usb(const guint8 *buf, guint len);
WS_DLL_PUBLIC uint16_t crc16_usb(const uint8_t *buf, unsigned len);
/** Calculates a CRC16 checksum for the given buffer with the polynom
* 0x5935 using a precompiled CRC table
@ -68,7 +68,7 @@ WS_DLL_PUBLIC guint16 crc16_usb(const guint8 *buf, guint len);
* @param seed The seed to use.
* @return the CRC16 checksum for the buffer
*/
WS_DLL_PUBLIC guint16 crc16_0x5935(const guint8 *buf, guint32 len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_0x5935(const uint8_t *buf, uint32_t len, uint16_t seed);
/** Calculates a CRC16 checksum for the given buffer with the polynom
* 0x755B using a precompiled CRC table
@ -77,7 +77,7 @@ WS_DLL_PUBLIC guint16 crc16_0x5935(const guint8 *buf, guint32 len, guint16 seed)
* @param seed The seed to use.
* @return the CRC16 checksum for the buffer
*/
WS_DLL_PUBLIC guint16 crc16_0x755B(const guint8 *buf, guint32 len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_0x755B(const uint8_t *buf, uint32_t len, uint16_t seed);
/** Computes CRC16 checksum for the given data with the polynom 0x9949 using
* precompiled CRC table
@ -86,7 +86,7 @@ WS_DLL_PUBLIC guint16 crc16_0x755B(const guint8 *buf, guint32 len, guint16 seed)
* @param seed The seed to use.
* @return the CRC16 checksum for the buffer
*/
WS_DLL_PUBLIC guint16 crc16_0x9949_seed(const guint8 *buf, guint len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_0x9949_seed(const uint8_t *buf, unsigned len, uint16_t seed);
/** Computes CRC16 checksum for the given data with the polynom 0x3D65 using
* precompiled CRC table
@ -95,7 +95,7 @@ WS_DLL_PUBLIC guint16 crc16_0x9949_seed(const guint8 *buf, guint len, guint16 se
* @param seed The seed to use.
* @return the CRC16 checksum for the buffer
*/
WS_DLL_PUBLIC guint16 crc16_0x3D65_seed(const guint8 *buf, guint len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_0x3D65_seed(const uint8_t *buf, unsigned len, uint16_t seed);
/** Computes CRC16 checksum for the given data with the polynom 0x080F using
* precompiled CRC table
@ -104,7 +104,7 @@ WS_DLL_PUBLIC guint16 crc16_0x3D65_seed(const guint8 *buf, guint len, guint16 se
* @param seed The seed to use.
* @return the CRC16 checksum for the buffer
*/
WS_DLL_PUBLIC guint16 crc16_0x080F_seed(const guint8 *buf, guint len, guint16 seed);
WS_DLL_PUBLIC uint16_t crc16_0x080F_seed(const uint8_t *buf, unsigned len, uint16_t seed);
#ifdef __cplusplus
}

View File

@ -40,7 +40,7 @@
/*****************************************************************/
#define CRC32C(c,d) CRC32_ACCUMULATE(c,d,crc32c_table)
static const guint32 crc32c_table[256] = {
static const uint32_t crc32c_table[256] = {
0x00000000U, 0xF26B8303U, 0xE13B70F7U, 0x1350F3F4U, 0xC79A971FU,
0x35F1141CU, 0x26A1E7E8U, 0xD4CA64EBU, 0x8AD958CFU, 0x78B2DBCCU,
0x6BE22838U, 0x9989AB3BU, 0x4D43CFD0U, 0xBF284CD3U, 0xAC78BF27U,
@ -102,7 +102,7 @@ static const guint32 crc32c_table[256] = {
* x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 +
* x^7 + x^5 + x^4 + x^2 + x + 1
*/
static const guint32 crc32_ccitt_table[256] = {
static const uint32_t crc32_ccitt_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
@ -169,7 +169,7 @@ static const guint32 crc32_ccitt_table[256] = {
*
* NOTE: this is also used for ATM AAL5.
*/
static const guint32 crc32_mpeg2_table[256] = {
static const uint32_t crc32_mpeg2_table[256] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
@ -216,7 +216,7 @@ static const guint32 crc32_mpeg2_table[256] = {
};
/* This table was compiled using the polynom: 0x0AA725CF*/
static const guint32 crc32_0AA725CF_reverse[] = {
static const uint32_t crc32_0AA725CF_reverse[] = {
0x00000000U, 0xCEAA95CEU, 0x7A1CE13DU, 0xB4B674F3U,
0xF439C27AU, 0x3A9357B4U, 0x8E252347U, 0x408FB689U,
0x0F3A4E55U, 0xC190DB9BU, 0x7526AF68U, 0xBB8C3AA6U,
@ -284,7 +284,7 @@ static const guint32 crc32_0AA725CF_reverse[] = {
};
/* This table was compiled using the polynom: 0x5D6DCB */
static const guint32 crc32_5D6DCB[] =
static const uint32_t crc32_5D6DCB[] =
{
0x00000000, 0x005d6dcb, 0x00badb96, 0x00e7b65d,
0x0028dae7, 0x0075b72c, 0x00920171, 0x00cf6cba,
@ -352,22 +352,22 @@ static const guint32 crc32_5D6DCB[] =
0x0098206c, 0x00c54da7, 0x0022fbfa, 0x007f9631
};
guint32
crc32c_table_lookup (guchar pos)
uint32_t
crc32c_table_lookup (unsigned char pos)
{
return crc32c_table[pos];
}
guint32
crc32_ccitt_table_lookup (guchar pos)
uint32_t
crc32_ccitt_table_lookup (unsigned char pos)
{
return crc32_ccitt_table[pos];
}
guint32
crc32c_calculate(const void *buf, int len, guint32 crc)
uint32_t
crc32c_calculate(const void *buf, int len, uint32_t crc)
{
const guint8 *p = (const guint8 *)buf;
const uint8_t *p = (const uint8_t *)buf;
crc = CRC32C_SWAP(crc);
while (len-- > 0) {
CRC32C(crc, *p++);
@ -375,10 +375,10 @@ crc32c_calculate(const void *buf, int len, guint32 crc)
return CRC32C_SWAP(crc);
}
guint32
crc32c_calculate_no_swap(const void *buf, int len, guint32 crc)
uint32_t
crc32c_calculate_no_swap(const void *buf, int len, uint32_t crc)
{
const guint8 *p = (const guint8 *)buf;
const uint8_t *p = (const uint8_t *)buf;
while (len-- > 0) {
CRC32C(crc, *p++);
}
@ -386,17 +386,17 @@ crc32c_calculate_no_swap(const void *buf, int len, guint32 crc)
return crc;
}
guint32
crc32_ccitt(const guint8 *buf, guint len)
uint32_t
crc32_ccitt(const uint8_t *buf, unsigned len)
{
return (crc32_ccitt_seed(buf, len, CRC32_CCITT_SEED));
}
guint32
crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed)
uint32_t
crc32_ccitt_seed(const uint8_t *buf, unsigned len, uint32_t seed)
{
guint i;
guint32 crc32 = seed;
unsigned i;
uint32_t crc32 = seed;
for (i = 0; i < len; i++)
CRC32_ACCUMULATE(crc32, buf[i], crc32_ccitt_table);
@ -404,11 +404,11 @@ crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed)
return ( ~crc32 );
}
guint32
crc32_mpeg2_seed(const guint8 *buf, guint len, guint32 seed)
uint32_t
crc32_mpeg2_seed(const uint8_t *buf, unsigned len, uint32_t seed)
{
guint i;
guint32 crc32;
unsigned i;
uint32_t crc32;
crc32 = seed;
@ -418,27 +418,27 @@ crc32_mpeg2_seed(const guint8 *buf, guint len, guint32 seed)
return ( crc32 );
}
guint32
crc32_0x0AA725CF_seed(const guint8 *buf, guint len, guint32 seed)
uint32_t
crc32_0x0AA725CF_seed(const uint8_t *buf, unsigned len, uint32_t seed)
{
guint crc32;
unsigned crc32;
crc32 = (guint)seed;
crc32 = (unsigned)seed;
while( len-- != 0 )
CRC32_ACCUMULATE(crc32, *buf++, crc32_0AA725CF_reverse);
return (guint32)crc32;
return (uint32_t)crc32;
}
guint32
crc32_0x5D6DCB_seed(const guint8 *buf, guint len, guint32 seed)
uint32_t
crc32_0x5D6DCB_seed(const uint8_t *buf, unsigned len, uint32_t seed)
{
guint32 crc = seed;
uint32_t crc = seed;
if (len > 0)
{
while (len-- > 0)
{
guint8 data = *buf++;
uint8_t data = *buf++;
/* XOR data with CRC2, look up result, then XOR that with CRC; */
crc = crc32_5D6DCB[((crc >> 16) ^ data) & 0xff] ^ (crc << 8);
}

View File

@ -32,18 +32,18 @@ extern "C" {
/** Lookup the crc value in the crc32_ccitt_table
@param pos Position in the table. */
WS_DLL_PUBLIC guint32 crc32_ccitt_table_lookup (guchar pos);
WS_DLL_PUBLIC uint32_t crc32_ccitt_table_lookup (unsigned char pos);
/** Lookup the crc value in the crc32c_table
@param pos Position in the table. */
WS_DLL_PUBLIC guint32 crc32c_table_lookup (guchar pos);
WS_DLL_PUBLIC uint32_t crc32c_table_lookup (unsigned char pos);
/** Compute CRC32C checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@param crc The preload value for the CRC32C computation.
@return The CRC32C checksum. */
WS_DLL_PUBLIC guint32 crc32c_calculate(const void *buf, int len, guint32 crc);
WS_DLL_PUBLIC uint32_t crc32c_calculate(const void *buf, int len, uint32_t crc);
/** Compute CRC32C checksum of a buffer of data without swapping seed crc
or completed checksum
@ -51,13 +51,13 @@ WS_DLL_PUBLIC guint32 crc32c_calculate(const void *buf, int len, guint32 crc);
@param len The number of bytes to include in the computation.
@param crc The preload value for the CRC32C computation.
@return The CRC32C checksum. */
WS_DLL_PUBLIC guint32 crc32c_calculate_no_swap(const void *buf, int len, guint32 crc);
WS_DLL_PUBLIC uint32_t crc32c_calculate_no_swap(const void *buf, int len, uint32_t crc);
/** Compute CRC32 CCITT checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return The CRC32 CCITT checksum. */
WS_DLL_PUBLIC guint32 crc32_ccitt(const guint8 *buf, guint len);
WS_DLL_PUBLIC uint32_t crc32_ccitt(const uint8_t *buf, unsigned len);
/** Compute CRC32 CCITT checksum of a buffer of data. If computing the
* checksum over multiple buffers and you want to feed the partial CRC32
@ -66,14 +66,14 @@ WS_DLL_PUBLIC guint32 crc32_ccitt(const guint8 *buf, guint len);
@param len The number of bytes to include in the computation.
@param seed The seed to use.
@return The CRC32 CCITT checksum (using the given seed). */
WS_DLL_PUBLIC guint32 crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed);
WS_DLL_PUBLIC uint32_t crc32_ccitt_seed(const uint8_t *buf, unsigned len, uint32_t seed);
/** Compute MPEG-2 CRC32 checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@param seed The seed to use.
@return The CRC32 MPEG-2 checksum (using the given seed). */
WS_DLL_PUBLIC guint32 crc32_mpeg2_seed(const guint8 *buf, guint len, guint32 seed);
WS_DLL_PUBLIC uint32_t crc32_mpeg2_seed(const uint8_t *buf, unsigned len, uint32_t seed);
/** Computes CRC32 checksum for the given data with the polynom 0x0AA725CF using
* precompiled CRC table
@ -82,7 +82,7 @@ WS_DLL_PUBLIC guint32 crc32_mpeg2_seed(const guint8 *buf, guint len, guint32 see
* @param seed The seed to use.
* @return the CRC32 checksum for the buffer
*/
WS_DLL_PUBLIC guint32 crc32_0x0AA725CF_seed(const guint8 *buf, guint len, guint32 seed);
WS_DLL_PUBLIC uint32_t crc32_0x0AA725CF_seed(const uint8_t *buf, unsigned len, uint32_t seed);
/** Computes CRC32 checksum for the given data with the polynom 0x5D6DCB using
* precompiled CRC table
@ -91,12 +91,12 @@ WS_DLL_PUBLIC guint32 crc32_0x0AA725CF_seed(const guint8 *buf, guint len, guint3
* @param seed The seed to use.
* @return the CRC32 checksum for the buffer
*/
WS_DLL_PUBLIC guint32 crc32_0x5D6DCB_seed(const guint8 *buf, guint len, guint32 seed);
WS_DLL_PUBLIC uint32_t crc32_0x5D6DCB_seed(const uint8_t *buf, unsigned len, uint32_t seed);
WS_DLL_PUBLIC int Dot11DecryptWepDecrypt(
const guchar *seed,
const unsigned char *seed,
const size_t seed_len,
guchar *cypher_text,
unsigned char *cypher_text,
const size_t data_len);
#ifdef __cplusplus

View File

@ -14,7 +14,7 @@
#include <wsutil/crc5.h>
static guint8 crc5_usb_bits(guint32 v, int vl, guint8 ival)
static uint8_t crc5_usb_bits(uint32_t v, int vl, uint8_t ival)
{
/* This function is based on code posted by John Sullivan to Wireshark-dev
* mailing list on Jul 21, 2019.
@ -28,8 +28,8 @@ static guint8 crc5_usb_bits(guint32 v, int vl, guint8 ival)
* In USB 2.0, the CRC5 is calculated on either 11 or 19 bits inputs,
* and thus this approach is viable.
*/
guint8 rv = ival;
static const guint8 bvals[19] = {
uint8_t rv = ival;
static const uint8_t bvals[19] = {
0x1e, 0x15, 0x03, 0x06, 0x0c, 0x18, 0x19, 0x1b,
0x1f, 0x17, 0x07, 0x0e, 0x1c, 0x11, 0x0b, 0x16,
0x05, 0x0a, 0x14
@ -43,12 +43,12 @@ static guint8 crc5_usb_bits(guint32 v, int vl, guint8 ival)
return rv;
}
guint8 crc5_usb_11bit_input(guint16 input)
uint8_t crc5_usb_11bit_input(uint16_t input)
{
return crc5_usb_bits(input, 11, 0x02);
}
guint8 crc5_usb_19bit_input(guint32 input)
uint8_t crc5_usb_19bit_input(uint32_t input)
{
return crc5_usb_bits(input, 19, 0x1d);
}

View File

@ -24,14 +24,14 @@ extern "C" {
on low 11 bits of the input value. High bits are ignored.
@param input Source data for which the CRC-5 should be calculated.
@return the CRC5 checksum for input value */
WS_DLL_PUBLIC guint8 crc5_usb_11bit_input(guint16 input);
WS_DLL_PUBLIC uint8_t crc5_usb_11bit_input(uint16_t input);
/** Compute the 5-bit CRC value of a input value matching the CRC-5
defined in USB 2.0 Specification. This function calculates the CRC
on low 19 bits of the input value. High bits are ignored.
@param input Source data for which the CRC-5 should be calculated.
@return the CRC5 checksum for input value */
WS_DLL_PUBLIC guint8 crc5_usb_19bit_input(guint32 input);
WS_DLL_PUBLIC uint8_t crc5_usb_19bit_input(uint32_t input);
#ifdef __cplusplus
}

View File

@ -30,7 +30,7 @@
* XorOut = 0
* ReflectOut = False
*/
static const guint8 crc6_table[256] = {
static const uint8_t crc6_table[256] = {
0x00, 0x2f, 0x31, 0x1e, 0x0d, 0x22, 0x3c, 0x13, 0x1a, 0x35, 0x2b, 0x04, 0x17, 0x38, 0x26, 0x09,
0x34, 0x1b, 0x05, 0x2a, 0x39, 0x16, 0x08, 0x27, 0x2e, 0x01, 0x1f, 0x30, 0x23, 0x0c, 0x12, 0x3d,
0x07, 0x28, 0x36, 0x19, 0x0a, 0x25, 0x3b, 0x14, 0x1d, 0x32, 0x2c, 0x03, 0x10, 0x3f, 0x21, 0x0e,
@ -56,9 +56,9 @@ static const guint8 crc6_table[256] = {
* TS 25.415 docs: https://www.etsi.org/deliver/etsi_ts/125400_125499/125415/04.06.00_60/ts_125415v040600p.pdf
* TS 25.446 docs: https://www.etsi.org/deliver/etsi_ts/125400_125499/125446/10.01.00_60/ts_125446v100100p.pdf
*/
guint16 crc6_0X6F(guint16 crc, const guint8 *data, int data_len)
uint16_t crc6_0X6F(uint16_t crc, const uint8_t *data, int data_len)
{
guint8 tbl_idx;
uint8_t tbl_idx;
while (data_len--) {
tbl_idx = (crc << 2) ^ *data;

View File

@ -12,6 +12,6 @@
#include <wireshark.h>
WS_DLL_PUBLIC guint16 crc6_0X6F(guint16 crc6, const guint8 *data_blk_ptr, int data_blk_size);
WS_DLL_PUBLIC uint16_t crc6_0X6F(uint16_t crc6, const uint8_t *data_blk_ptr, int data_blk_size);
#endif /* __CRC6_H__ */

View File

@ -28,7 +28,7 @@
/**
* Static table used for the table_driven implementation.
*****************************************************************************/
static const guint8 crc_table[256] = {
static const uint8_t crc_table[256] = {
0x00, 0x8a, 0x9e, 0x14, 0xb6, 0x3c, 0x28, 0xa2, 0xe6, 0x6c, 0x78, 0xf2, 0x50, 0xda, 0xce, 0x44,
0x46, 0xcc, 0xd8, 0x52, 0xf0, 0x7a, 0x6e, 0xe4, 0xa0, 0x2a, 0x3e, 0xb4, 0x16, 0x9c, 0x88, 0x02,
0x8c, 0x06, 0x12, 0x98, 0x3a, 0xb0, 0xa4, 0x2e, 0x6a, 0xe0, 0xf4, 0x7e, 0xdc, 0x56, 0x42, 0xc8,
@ -57,7 +57,7 @@ static const guint8 crc_table[256] = {
* \param data_len Number of bytes in the \a data buffer.
* \return The updated crc value.
*****************************************************************************/
guint8 crc7update(guint8 crc, const unsigned char *data, int data_len)
uint8_t crc7update(uint8_t crc, const unsigned char *data, int data_len)
{
unsigned int tbl_idx;

View File

@ -40,7 +40,7 @@ extern "C" {
*
* \return The initial crc value.
*****************************************************************************/
static inline guint8 crc7init(void)
static inline uint8_t crc7init(void)
{
return 0x00 << 1;
}
@ -54,7 +54,7 @@ static inline guint8 crc7init(void)
* \param data_len Number of bytes in the \a data buffer.
* \return The updated crc value.
*****************************************************************************/
WS_DLL_PUBLIC guint8 crc7update(guint8 crc, const unsigned char *data, int data_len);
WS_DLL_PUBLIC uint8_t crc7update(uint8_t crc, const unsigned char *data, int data_len);
/**
@ -63,7 +63,7 @@ WS_DLL_PUBLIC guint8 crc7update(guint8 crc, const unsigned char *data, int data_
* \param crc The current crc value.
* \return The final crc value.
*****************************************************************************/
static inline guint8 crc7finalize(guint8 crc)
static inline uint8_t crc7finalize(uint8_t crc)
{
return (crc >> 1) ^ 0x00;
}

View File

@ -16,7 +16,7 @@
#include <wsutil/crc8.h>
/* @brief Precompiled table for CRC8 values for the polynom 0x2F */
static const guint8 crc8_precompiled_2F[256] =
static const uint8_t crc8_precompiled_2F[256] =
{
0x00, 0x2F, 0x5E, 0x71, 0xBC, 0x93, 0xE2, 0xCD,
0x57, 0x78, 0x09, 0x26, 0xEB, 0xC4, 0xB5, 0x9A,
@ -133,13 +133,13 @@ static const unsigned char crc8_precompiled_3b[256] =
* @param crc_table a table storing 256 entries for crc8 checksums
* @return the CRC8 checksum for the buffer
*/
static guint8 crc8_precompiled(const guint8 *buf, guint32 len, guint8 seed, const guint8 crc_table[])
static uint8_t crc8_precompiled(const uint8_t *buf, uint32_t len, uint8_t seed, const uint8_t crc_table[])
{
guint8 crc;
uint8_t crc;
crc = seed;
while(len-- > 0)
crc = crc_table[(guint8)(*buf++) ^ crc];
crc = crc_table[(uint8_t)(*buf++) ^ crc];
return crc;
}
@ -151,7 +151,7 @@ static guint8 crc8_precompiled(const guint8 *buf, guint32 len, guint8 seed, cons
* @param seed The seed to use.
* @return the CRC8 checksum for the buffer
*/
guint8 crc8_0x2F(const guint8 *buf, guint32 len, guint8 seed)
uint8_t crc8_0x2F(const uint8_t *buf, uint32_t len, uint8_t seed)
{
return crc8_precompiled(buf, len, seed, crc8_precompiled_2F);
}
@ -163,9 +163,9 @@ guint8 crc8_0x2F(const guint8 *buf, guint32 len, guint8 seed)
* @param seed The seed to use.
* @return the CRC8 checksum for the buffer
*/
guint8 crc8_0x37(const guint8 *buf, guint32 len, guint8 seed)
uint8_t crc8_0x37(const uint8_t *buf, uint32_t len, uint8_t seed)
{
guint8 crc = seed;
uint8_t crc = seed;
while (len-- > 0)
{
crc = crc8_precompiled_37[(crc ^ *buf++)];
@ -180,9 +180,9 @@ guint8 crc8_0x37(const guint8 *buf, guint32 len, guint8 seed)
* @param seed The seed to use.
* @return the CRC8 checksum for the buffer
*/
guint8 crc8_0x3B(const guint8 *buf, guint32 len, guint8 seed)
uint8_t crc8_0x3B(const uint8_t *buf, uint32_t len, uint8_t seed)
{
guint8 crc = seed;
uint8_t crc = seed;
while (len-- > 0)
{
crc = crc8_precompiled_3b[(crc ^ *buf++)];

View File

@ -26,7 +26,7 @@ extern "C" {
* @param seed The seed to use.
* @return the CRC8 checksum for the buffer
*/
WS_DLL_PUBLIC guint8 crc8_0x2F(const guint8 *buf, guint32 len, guint8 seed);
WS_DLL_PUBLIC uint8_t crc8_0x2F(const uint8_t *buf, uint32_t len, uint8_t seed);
/** Calculates a CRC8 checksum for the given buffer with the polynom
* 0x37 using the precompiled CRC table
@ -35,7 +35,7 @@ WS_DLL_PUBLIC guint8 crc8_0x2F(const guint8 *buf, guint32 len, guint8 seed);
* @param seed The seed to use.
* @return the CRC8 checksum for the buffer
*/
WS_DLL_PUBLIC guint8 crc8_0x37(const guint8 *buf, guint32 len, guint8 seed);
WS_DLL_PUBLIC uint8_t crc8_0x37(const uint8_t *buf, uint32_t len, uint8_t seed);
/** Calculates a CRC8 checksum for the given buffer with the polynom
* 0x3B using the precompiled CRC table
@ -44,7 +44,7 @@ WS_DLL_PUBLIC guint8 crc8_0x37(const guint8 *buf, guint32 len, guint8 seed);
* @param seed The seed to use.
* @return the CRC8 checksum for the buffer
*/
WS_DLL_PUBLIC guint8 crc8_0x3B(const guint8 *buf, guint32 len, guint8 seed);
WS_DLL_PUBLIC uint8_t crc8_0x3B(const uint8_t *buf, uint32_t len, uint8_t seed);
#ifdef __cplusplus
}