Rizin
unix-like reverse engineering framework and cli tools
crca.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Classes

struct  RzCrc
 

Macros

#define UTCRC_C(x)   ((utcrc)(x))
 

Typedefs

typedef ut64 utcrc
 

Enumerations

enum  RzCrcPresets {
  CRC_PRESET_8_SMBUS = 0 , CRC_PRESET_CRC8_CDMA2000 , CRC_PRESET_CRC8_DARC , CRC_PRESET_CRC8_DVB_S2 ,
  CRC_PRESET_CRC8_EBU , CRC_PRESET_CRC8_ICODE , CRC_PRESET_CRC8_ITU , CRC_PRESET_CRC8_MAXIM ,
  CRC_PRESET_CRC8_ROHC , CRC_PRESET_CRC8_WCDMA , CRC_PRESET_15_CAN , CRC_PRESET_16 ,
  CRC_PRESET_16_CITT , CRC_PRESET_16_USB , CRC_PRESET_16_HDLC , CRC_PRESET_CRC16_AUG_CCITT ,
  CRC_PRESET_CRC16_BUYPASS , CRC_PRESET_CRC16_CDMA2000 , CRC_PRESET_CRC16_DDS110 , CRC_PRESET_CRC16_DECT_R ,
  CRC_PRESET_CRC16_DECT_X , CRC_PRESET_CRC16_DNP , CRC_PRESET_CRC16_EN13757 , CRC_PRESET_CRC16_GENIBUS ,
  CRC_PRESET_CRC16_MAXIM , CRC_PRESET_CRC16_MCRF4XX , CRC_PRESET_CRC16_RIELLO , CRC_PRESET_CRC16_T10_DIF ,
  CRC_PRESET_CRC16_TELEDISK , CRC_PRESET_CRC16_TMS37157 , CRC_PRESET_CRCA , CRC_PRESET_CRC16_KERMIT ,
  CRC_PRESET_CRC16_MODBUS , CRC_PRESET_CRC16_X25 , CRC_PRESET_CRC16_XMODEM , CRC_PRESET_24 ,
  CRC_PRESET_32 , CRC_PRESET_32_ECMA_267 , CRC_PRESET_32C , CRC_PRESET_CRC32_BZIP2 ,
  CRC_PRESET_CRC32D , CRC_PRESET_CRC32_MPEG2 , CRC_PRESET_CRC32_POSIX , CRC_PRESET_CRC32Q ,
  CRC_PRESET_CRC32_JAMCRC , CRC_PRESET_CRC32_XFER , CRC_PRESET_CRC64 , CRC_PRESET_CRC64_ECMA182 ,
  CRC_PRESET_CRC64_WE , CRC_PRESET_CRC64_XZ , CRC_PRESET_CRC64_ISO , CRC_PRESET_SIZE
}
 

Functions

void crc_init_preset (RzCrc *ctx, RzCrcPresets preset)
 
void crc_init_custom (RzCrc *ctx, utcrc crc, ut32 size, int reflect, utcrc poly, utcrc xout)
 
void crc_update (RzCrc *ctx, const ut8 *data, ut32 sz)
 
void crc_final (RzCrc *ctx, utcrc *r)
 

Macro Definition Documentation

◆ UTCRC_C

#define UTCRC_C (   x)    ((utcrc)(x))

Definition at line 10 of file crca.h.

Typedef Documentation

◆ utcrc

typedef ut64 utcrc

Definition at line 9 of file crca.h.

Enumeration Type Documentation

◆ RzCrcPresets

Enumerator
CRC_PRESET_8_SMBUS 
CRC_PRESET_CRC8_CDMA2000 
CRC_PRESET_CRC8_DARC 
CRC_PRESET_CRC8_DVB_S2 
CRC_PRESET_CRC8_EBU 
CRC_PRESET_CRC8_ICODE 
CRC_PRESET_CRC8_ITU 
CRC_PRESET_CRC8_MAXIM 
CRC_PRESET_CRC8_ROHC 
CRC_PRESET_CRC8_WCDMA 
CRC_PRESET_15_CAN 
CRC_PRESET_16 
CRC_PRESET_16_CITT 
CRC_PRESET_16_USB 
CRC_PRESET_16_HDLC 
CRC_PRESET_CRC16_AUG_CCITT 
CRC_PRESET_CRC16_BUYPASS 
CRC_PRESET_CRC16_CDMA2000 
CRC_PRESET_CRC16_DDS110 
CRC_PRESET_CRC16_DECT_R 
CRC_PRESET_CRC16_DECT_X 
CRC_PRESET_CRC16_DNP 
CRC_PRESET_CRC16_EN13757 
CRC_PRESET_CRC16_GENIBUS 
CRC_PRESET_CRC16_MAXIM 
CRC_PRESET_CRC16_MCRF4XX 
CRC_PRESET_CRC16_RIELLO 
CRC_PRESET_CRC16_T10_DIF 
CRC_PRESET_CRC16_TELEDISK 
CRC_PRESET_CRC16_TMS37157 
CRC_PRESET_CRCA 
CRC_PRESET_CRC16_KERMIT 
CRC_PRESET_CRC16_MODBUS 
CRC_PRESET_CRC16_X25 
CRC_PRESET_CRC16_XMODEM 
CRC_PRESET_24 
CRC_PRESET_32 
CRC_PRESET_32_ECMA_267 
CRC_PRESET_32C 
CRC_PRESET_CRC32_BZIP2 
CRC_PRESET_CRC32D 
CRC_PRESET_CRC32_MPEG2 
CRC_PRESET_CRC32_POSIX 
CRC_PRESET_CRC32Q 
CRC_PRESET_CRC32_JAMCRC 
CRC_PRESET_CRC32_XFER 
CRC_PRESET_CRC64 
CRC_PRESET_CRC64_ECMA182 
CRC_PRESET_CRC64_WE 
CRC_PRESET_CRC64_XZ 
CRC_PRESET_CRC64_ISO 
CRC_PRESET_SIZE 

Definition at line 12 of file crca.h.

12  {
64 
66 } RzCrcPresets;
RzCrcPresets
Definition: crca.h:12
@ CRC_PRESET_32
Definition: crca.h:49
@ CRC_PRESET_CRC32_MPEG2
Definition: crca.h:54
@ CRC_PRESET_CRC16_RIELLO
Definition: crca.h:39
@ CRC_PRESET_CRC16_TELEDISK
Definition: crca.h:41
@ CRC_PRESET_24
Definition: crca.h:48
@ CRC_PRESET_16_HDLC
Definition: crca.h:27
@ CRC_PRESET_CRC16_CDMA2000
Definition: crca.h:30
@ CRC_PRESET_CRC32_BZIP2
Definition: crca.h:52
@ CRC_PRESET_CRC8_ROHC
Definition: crca.h:21
@ CRC_PRESET_CRC16_X25
Definition: crca.h:46
@ CRC_PRESET_32C
Definition: crca.h:51
@ CRC_PRESET_CRC8_DVB_S2
Definition: crca.h:16
@ CRC_PRESET_CRC8_CDMA2000
Definition: crca.h:14
@ CRC_PRESET_CRC8_WCDMA
Definition: crca.h:22
@ CRC_PRESET_15_CAN
Definition: crca.h:23
@ CRC_PRESET_CRC16_AUG_CCITT
Definition: crca.h:28
@ CRC_PRESET_CRC16_MCRF4XX
Definition: crca.h:38
@ CRC_PRESET_16_USB
Definition: crca.h:26
@ CRC_PRESET_8_SMBUS
Definition: crca.h:13
@ CRC_PRESET_CRC16_GENIBUS
Definition: crca.h:36
@ CRC_PRESET_CRC32_JAMCRC
Definition: crca.h:57
@ CRC_PRESET_CRC32_XFER
Definition: crca.h:58
@ CRC_PRESET_CRCA
Definition: crca.h:43
@ CRC_PRESET_CRC16_DECT_R
Definition: crca.h:32
@ CRC_PRESET_16
Definition: crca.h:24
@ CRC_PRESET_CRC16_MAXIM
Definition: crca.h:37
@ CRC_PRESET_CRC64_XZ
Definition: crca.h:62
@ CRC_PRESET_CRC16_DDS110
Definition: crca.h:31
@ CRC_PRESET_16_CITT
Definition: crca.h:25
@ CRC_PRESET_32_ECMA_267
Definition: crca.h:50
@ CRC_PRESET_CRC8_DARC
Definition: crca.h:15
@ CRC_PRESET_CRC64_ISO
Definition: crca.h:63
@ CRC_PRESET_CRC64
Definition: crca.h:59
@ CRC_PRESET_CRC16_DECT_X
Definition: crca.h:33
@ CRC_PRESET_CRC8_ITU
Definition: crca.h:19
@ CRC_PRESET_SIZE
Definition: crca.h:65
@ CRC_PRESET_CRC16_MODBUS
Definition: crca.h:45
@ CRC_PRESET_CRC16_KERMIT
Definition: crca.h:44
@ CRC_PRESET_CRC8_EBU
Definition: crca.h:17
@ CRC_PRESET_CRC64_ECMA182
Definition: crca.h:60
@ CRC_PRESET_CRC16_BUYPASS
Definition: crca.h:29
@ CRC_PRESET_CRC32Q
Definition: crca.h:56
@ CRC_PRESET_CRC8_ICODE
Definition: crca.h:18
@ CRC_PRESET_CRC16_DNP
Definition: crca.h:34
@ CRC_PRESET_CRC16_TMS37157
Definition: crca.h:42
@ CRC_PRESET_CRC16_T10_DIF
Definition: crca.h:40
@ CRC_PRESET_CRC32_POSIX
Definition: crca.h:55
@ CRC_PRESET_CRC8_MAXIM
Definition: crca.h:20
@ CRC_PRESET_CRC16_XMODEM
Definition: crca.h:47
@ CRC_PRESET_CRC32D
Definition: crca.h:53
@ CRC_PRESET_CRC16_EN13757
Definition: crca.h:35
@ CRC_PRESET_CRC64_WE
Definition: crca.h:61

Function Documentation

◆ crc_final()

void crc_final ( RzCrc ctx,
utcrc r 
)

Definition at line 38 of file crca.c.

38  {
39  utcrc crc;
40  int i;
41 
42  crc = ctx->crc;
43  crc &= (((UTCRC_C(1) << (ctx->size - 1)) - 1) << 1) | 1;
44  if (ctx->reflect) {
45  for (i = 0; i < (ctx->size >> 1); i++) {
46  if (((crc >> i) ^ (crc >> (ctx->size - 1 - i))) & 1) {
47  crc ^= (UTCRC_C(1) << i) ^ (UTCRC_C(1) << (ctx->size - 1 - i));
48  }
49  }
50  }
51 
52  *r = crc ^ ctx->xout;
53 }
lzma_index ** i
Definition: index.h:629
ut64 utcrc
Definition: crca.h:9
#define UTCRC_C(x)
Definition: crca.h:10
#define r
Definition: crypto_rc6.c:12

References i, r, and UTCRC_C.

Referenced by plugin_crca_final(), and rz_hash_crc_preset().

◆ crc_init_custom()

void crc_init_custom ( RzCrc ctx,
utcrc  crc,
ut32  size,
int  reflect,
utcrc  poly,
utcrc  xout 
)

Definition at line 8 of file crca.c.

8  {
9  ctx->crc = crc;
10  ctx->size = size;
11  ctx->reflect = reflect;
12  ctx->poly = poly;
13  ctx->xout = xout;
14 }
voidpf void uLong size
Definition: ioapi.h:138

◆ crc_init_preset()

void crc_init_preset ( RzCrc ctx,
RzCrcPresets  preset 
)

Definition at line 114 of file crca.c.

114  {
115  ctx->crc = crc_presets[preset].crc;
116  ctx->size = crc_presets[preset].size;
117  ctx->reflect = crc_presets[preset].reflect;
118  ctx->poly = crc_presets[preset].poly;
119  ctx->xout = crc_presets[preset].xout;
120 }
uint32_t preset
Definition: container.h:259
RzCrc crc_presets[]
Definition: crca.c:60
int reflect
Definition: crca.h:71
utcrc poly
Definition: crca.h:72
utcrc crc
Definition: crca.h:69
ut32 size
Definition: crca.h:70
utcrc xout
Definition: crca.h:73

References RzCrc::crc, crc_presets, RzCrc::poly, preset, RzCrc::reflect, RzCrc::size, and RzCrc::xout.

Referenced by rz_hash_crc_preset().

◆ crc_update()

void crc_update ( RzCrc ctx,
const ut8 data,
ut32  sz 
)

Definition at line 16 of file crca.c.

16  {
17  utcrc crc, d;
18  int i, j;
19 
20  crc = ctx->crc;
21  for (i = 0; i < sz; i++) {
22  d = data[i];
23  if (ctx->reflect) {
24  for (j = 0; j < 4; j++) {
25  if (((d >> j) ^ (d >> (7 - j))) & 1) {
26  d ^= (1 << j) ^ (1 << (7 - j));
27  }
28  }
29  }
30  crc ^= d << (ctx->size - 8);
31  for (j = 0; j < 8; j++) {
32  crc = ((crc >> (ctx->size - 1)) & 1 ? ctx->poly : 0) ^ (crc << 1);
33  }
34  }
35  ctx->crc = crc;
36 }
#define d(i)
Definition: sha256.c:44

References d, and i.

Referenced by plugin_crca_update(), and rz_hash_crc_preset().