Rizin
unix-like reverse engineering framework and cli tools
algo_crca.c File Reference
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/crc/crca.h"

Go to the source code of this file.

Macros

#define plugin_crca_preset_context_new(crcalgo, preset)
 
#define plugin_crca_preset_init(crcalgo, preset)
 
#define plugin_crca_preset_small_block(crcalgo, preset)
 
#define rz_hash_plugin_crca_preset(crcalgo, preset)
 
#define rz_lib_plugin_crca_preset(crcalgo)
 
#define rz_plugin_crca_preset_definition(crcalgo, preset)
 

Functions

static void plugin_crca_context_free (void *context)
 
static RzHashSize plugin_crca_digest_size (void *context)
 
static RzHashSize plugin_crca_block_size (void *context)
 
static bool plugin_crca_update (void *context, const ut8 *data, ut64 size)
 
static bool plugin_crca_final (void *context, ut8 *digest)
 
 rz_plugin_crca_preset_definition (crc8smbus, CRC_PRESET_8_SMBUS)
 
 rz_plugin_crca_preset_definition (crc8cdma2000, CRC_PRESET_CRC8_CDMA2000)
 
 rz_plugin_crca_preset_definition (crc8darc, CRC_PRESET_CRC8_DARC)
 
 rz_plugin_crca_preset_definition (crc8dvbs2, CRC_PRESET_CRC8_DVB_S2)
 
 rz_plugin_crca_preset_definition (crc8ebu, CRC_PRESET_CRC8_EBU)
 
 rz_plugin_crca_preset_definition (crc8icode, CRC_PRESET_CRC8_ICODE)
 
 rz_plugin_crca_preset_definition (crc8itu, CRC_PRESET_CRC8_ITU)
 
 rz_plugin_crca_preset_definition (crc8maxim, CRC_PRESET_CRC8_MAXIM)
 
 rz_plugin_crca_preset_definition (crc8rohc, CRC_PRESET_CRC8_ROHC)
 
 rz_plugin_crca_preset_definition (crc8wcdma, CRC_PRESET_CRC8_WCDMA)
 
 rz_plugin_crca_preset_definition (crc15can, CRC_PRESET_15_CAN)
 
 rz_plugin_crca_preset_definition (crc16, CRC_PRESET_16)
 
 rz_plugin_crca_preset_definition (crc16citt, CRC_PRESET_16_CITT)
 
 rz_plugin_crca_preset_definition (crc16usb, CRC_PRESET_16_USB)
 
 rz_plugin_crca_preset_definition (crc16hdlc, CRC_PRESET_16_HDLC)
 
 rz_plugin_crca_preset_definition (crc16augccitt, CRC_PRESET_CRC16_AUG_CCITT)
 
 rz_plugin_crca_preset_definition (crc16buypass, CRC_PRESET_CRC16_BUYPASS)
 
 rz_plugin_crca_preset_definition (crc16cdma2000, CRC_PRESET_CRC16_CDMA2000)
 
 rz_plugin_crca_preset_definition (crc16dds110, CRC_PRESET_CRC16_DDS110)
 
 rz_plugin_crca_preset_definition (crc16dectr, CRC_PRESET_CRC16_DECT_R)
 
 rz_plugin_crca_preset_definition (crc16dectx, CRC_PRESET_CRC16_DECT_X)
 
 rz_plugin_crca_preset_definition (crc16dnp, CRC_PRESET_CRC16_DNP)
 
 rz_plugin_crca_preset_definition (crc16en13757, CRC_PRESET_CRC16_EN13757)
 
 rz_plugin_crca_preset_definition (crc16genibus, CRC_PRESET_CRC16_GENIBUS)
 
 rz_plugin_crca_preset_definition (crc16maxim, CRC_PRESET_CRC16_MAXIM)
 
 rz_plugin_crca_preset_definition (crc16mcrf4xx, CRC_PRESET_CRC16_MCRF4XX)
 
 rz_plugin_crca_preset_definition (crc16riello, CRC_PRESET_CRC16_RIELLO)
 
 rz_plugin_crca_preset_definition (crc16t10dif, CRC_PRESET_CRC16_T10_DIF)
 
 rz_plugin_crca_preset_definition (crc16teledisk, CRC_PRESET_CRC16_TELEDISK)
 
 rz_plugin_crca_preset_definition (crc16tms37157, CRC_PRESET_CRC16_TMS37157)
 
 rz_plugin_crca_preset_definition (crca, CRC_PRESET_CRCA)
 
 rz_plugin_crca_preset_definition (crc16kermit, CRC_PRESET_CRC16_KERMIT)
 
 rz_plugin_crca_preset_definition (crc16modbus, CRC_PRESET_CRC16_MODBUS)
 
 rz_plugin_crca_preset_definition (crc16x25, CRC_PRESET_CRC16_X25)
 
 rz_plugin_crca_preset_definition (crc16xmodem, CRC_PRESET_CRC16_XMODEM)
 
 rz_plugin_crca_preset_definition (crc24, CRC_PRESET_24)
 
 rz_plugin_crca_preset_definition (crc32, CRC_PRESET_32)
 
 rz_plugin_crca_preset_definition (crc32ecma267, CRC_PRESET_32_ECMA_267)
 
 rz_plugin_crca_preset_definition (crc32c, CRC_PRESET_32C)
 
 rz_plugin_crca_preset_definition (crc32bzip2, CRC_PRESET_CRC32_BZIP2)
 
 rz_plugin_crca_preset_definition (crc32d, CRC_PRESET_CRC32D)
 
 rz_plugin_crca_preset_definition (crc32mpeg2, CRC_PRESET_CRC32_MPEG2)
 
 rz_plugin_crca_preset_definition (crc32posix, CRC_PRESET_CRC32_POSIX)
 
 rz_plugin_crca_preset_definition (crc32q, CRC_PRESET_CRC32Q)
 
 rz_plugin_crca_preset_definition (crc32jamcrc, CRC_PRESET_CRC32_JAMCRC)
 
 rz_plugin_crca_preset_definition (crc32xfer, CRC_PRESET_CRC32_XFER)
 
 rz_plugin_crca_preset_definition (crc64, CRC_PRESET_CRC64)
 
 rz_plugin_crca_preset_definition (crc64ecma182, CRC_PRESET_CRC64_ECMA182)
 
 rz_plugin_crca_preset_definition (crc64we, CRC_PRESET_CRC64_WE)
 
 rz_plugin_crca_preset_definition (crc64xz, CRC_PRESET_CRC64_XZ)
 
 rz_plugin_crca_preset_definition (crc64iso, CRC_PRESET_CRC64_ISO)
 

Macro Definition Documentation

◆ plugin_crca_preset_context_new

#define plugin_crca_preset_context_new (   crcalgo,
  preset 
)
Value:
static void *plugin_crca_##crcalgo##_context_new() { \
RzCrc *crc = RZ_NEW0(RzCrc); \
if (!crc) { \
return NULL; \
} \
crc_init_preset(crc, preset); \
return crc; \
}
uint32_t preset
Definition: container.h:259
#define NULL
Definition: cris-opc.c:27
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: crca.h:68

Definition at line 9 of file algo_crca.c.

◆ plugin_crca_preset_init

#define plugin_crca_preset_init (   crcalgo,
  preset 
)
Value:
static bool plugin_crca_##crcalgo##_init(void *context) { \
rz_return_val_if_fail(context, false); \
crc_init_preset((RzCrc *)context, preset); \
return true; \
}

Definition at line 19 of file algo_crca.c.

◆ plugin_crca_preset_small_block

#define plugin_crca_preset_small_block (   crcalgo,
  preset 
)
Value:
static bool plugin_crca_##crcalgo##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) { \
rz_return_val_if_fail(data &&digest, false); \
RzCrc ctx; \
crc_init_preset(&ctx, preset); \
if (!dgst) { \
return false; \
} \
crc_update(&ctx, data, size); \
plugin_crca_final((void *)&ctx, dgst); \
*digest = dgst; \
if (digest_size) { \
*digest_size = plugin_crca_digest_size(&ctx); \
} \
return true; \
}
static RzHashSize plugin_crca_digest_size(void *context)
Definition: algo_crca.c:48
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
ut32 RzHashSize
Definition: rz_hash.h:24
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

Definition at line 26 of file algo_crca.c.

◆ rz_hash_plugin_crca_preset

#define rz_hash_plugin_crca_preset (   crcalgo,
  preset 
)
Value:
plugin_crca_preset_init(crcalgo, preset); \
plugin_crca_preset_small_block(crcalgo, preset); \
RzHashPlugin rz_hash_plugin_crca_##crcalgo = { \
.name = #crcalgo, \
.license = "LGPL3", \
.author = "deroad", \
.support_hmac = false, \
.context_new = plugin_crca_##crcalgo##_context_new, \
.context_free = plugin_crca_context_free, \
.digest_size = plugin_crca_digest_size, \
.block_size = plugin_crca_block_size, \
.init = plugin_crca_##crcalgo##_init, \
.update = plugin_crca_update, \
.final = plugin_crca_final, \
.small_block = plugin_crca_##crcalgo##_small_block, \
}
#define plugin_crca_preset_context_new(crcalgo, preset)
Definition: algo_crca.c:9
static bool plugin_crca_final(void *context, ut8 *digest)
Definition: algo_crca.c:75
static void plugin_crca_context_free(void *context)
Definition: algo_crca.c:44
static RzHashSize plugin_crca_block_size(void *context)
Definition: algo_crca.c:64
static bool plugin_crca_update(void *context, const ut8 *data, ut64 size)
Definition: algo_crca.c:68

Definition at line 94 of file algo_crca.c.

◆ rz_lib_plugin_crca_preset

#define rz_lib_plugin_crca_preset (   crcalgo)
Value:
.data = &rz_hash_plugin_crca_##crcalgo, \
.version = RZ_VERSION \
}
RZ_API RzLibStruct rizin_plugin
#define RZ_API
@ RZ_LIB_TYPE_HASH
Definition: rz_lib.h:82
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 114 of file algo_crca.c.

◆ rz_plugin_crca_preset_definition

#define rz_plugin_crca_preset_definition (   crcalgo,
  preset 
)
Value:
rz_lib_plugin_crca_preset(crcalgo)
#define rz_hash_plugin_crca_preset(crcalgo, preset)
Definition: algo_crca.c:94

Definition at line 124 of file algo_crca.c.

Function Documentation

◆ plugin_crca_block_size()

static RzHashSize plugin_crca_block_size ( void *  context)
static

Definition at line 64 of file algo_crca.c.

64  {
65  return 0;
66 }

◆ plugin_crca_context_free()

static void plugin_crca_context_free ( void *  context)
static

Definition at line 44 of file algo_crca.c.

44  {
45  free(context);
46 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free().

◆ plugin_crca_digest_size()

static RzHashSize plugin_crca_digest_size ( void *  context)
static

Definition at line 48 of file algo_crca.c.

48  {
50  RzCrc *ctx = (RzCrc *)context;
51  if (ctx->size <= 8) {
52  return 1;
53  } else if (ctx->size > 8 && ctx->size <= 16) {
54  return 2;
55  } else if (ctx->size > 16 && ctx->size <= 32) {
56  return 4;
57  } else if (ctx->size > 32 && ctx->size <= 64) {
58  return 8;
59  }
60  RZ_LOG_ERROR("msg digest: unknown size %d.\n", ctx->size);
61  return 0;
62 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58

References RZ_LOG_ERROR, and rz_return_val_if_fail.

◆ plugin_crca_final()

static bool plugin_crca_final ( void *  context,
ut8 digest 
)
static

Definition at line 75 of file algo_crca.c.

75  {
76  rz_return_val_if_fail(context && digest, false);
77  RzCrc *ctx = (RzCrc *)context;
78  utcrc r;
79  crc_final(ctx, &r);
80  if (ctx->size <= 8) {
81  rz_write_be8(digest, (ut8)r);
82  } else if (ctx->size > 8 && ctx->size <= 16) {
83  rz_write_be16(digest, (ut16)r);
84  } else if (ctx->size > 16 && ctx->size <= 32) {
85  rz_write_be32(digest, (ut32)r);
86  } else if (ctx->size > 32 && ctx->size <= 64) {
87  rz_write_be64(digest, r);
88  } else {
89  RZ_LOG_ERROR("msg digest: unknown size %d.\n", ctx->size);
90  }
91  return true;
92 }
void crc_final(RzCrc *ctx, utcrc *r)
Definition: crca.c:38
ut64 utcrc
Definition: crca.h:9
#define r
Definition: crypto_rc6.c:12
uint16_t ut16
uint32_t ut32
static void rz_write_be16(void *dest, ut16 val)
Definition: rz_endian.h:60
static void rz_write_be64(void *dest, ut64 val)
Definition: rz_endian.h:119
static void rz_write_be8(void *dest, ut8 val)
Definition: rz_endian.h:42
static void rz_write_be32(void *dest, ut32 val)
Definition: rz_endian.h:98

References crc_final(), r, RZ_LOG_ERROR, rz_return_val_if_fail, rz_write_be16(), rz_write_be32(), rz_write_be64(), and rz_write_be8().

◆ plugin_crca_update()

static bool plugin_crca_update ( void *  context,
const ut8 data,
ut64  size 
)
static

Definition at line 68 of file algo_crca.c.

68  {
69  rz_return_val_if_fail(context && data, false);
70 
71  crc_update((RzCrc *)context, data, size);
72  return true;
73 }
void crc_update(RzCrc *ctx, const ut8 *data, ut32 sz)
Definition: crca.c:16

References crc_update(), and rz_return_val_if_fail.

◆ rz_plugin_crca_preset_definition() [1/51]

rz_plugin_crca_preset_definition ( crc15can  ,
CRC_PRESET_15_CAN   
)

◆ rz_plugin_crca_preset_definition() [2/51]

rz_plugin_crca_preset_definition ( crc16  ,
CRC_PRESET_16   
)

◆ rz_plugin_crca_preset_definition() [3/51]

rz_plugin_crca_preset_definition ( crc16augccitt  ,
CRC_PRESET_CRC16_AUG_CCITT   
)

◆ rz_plugin_crca_preset_definition() [4/51]

rz_plugin_crca_preset_definition ( crc16buypass  ,
CRC_PRESET_CRC16_BUYPASS   
)

◆ rz_plugin_crca_preset_definition() [5/51]

rz_plugin_crca_preset_definition ( crc16cdma2000  ,
CRC_PRESET_CRC16_CDMA2000   
)

◆ rz_plugin_crca_preset_definition() [6/51]

rz_plugin_crca_preset_definition ( crc16citt  ,
CRC_PRESET_16_CITT   
)

◆ rz_plugin_crca_preset_definition() [7/51]

rz_plugin_crca_preset_definition ( crc16dds110  ,
CRC_PRESET_CRC16_DDS110   
)

◆ rz_plugin_crca_preset_definition() [8/51]

rz_plugin_crca_preset_definition ( crc16dectr  ,
CRC_PRESET_CRC16_DECT_R   
)

◆ rz_plugin_crca_preset_definition() [9/51]

rz_plugin_crca_preset_definition ( crc16dectx  ,
CRC_PRESET_CRC16_DECT_X   
)

◆ rz_plugin_crca_preset_definition() [10/51]

rz_plugin_crca_preset_definition ( crc16dnp  ,
CRC_PRESET_CRC16_DNP   
)

◆ rz_plugin_crca_preset_definition() [11/51]

rz_plugin_crca_preset_definition ( crc16en13757  ,
CRC_PRESET_CRC16_EN13757   
)

◆ rz_plugin_crca_preset_definition() [12/51]

rz_plugin_crca_preset_definition ( crc16genibus  ,
CRC_PRESET_CRC16_GENIBUS   
)

◆ rz_plugin_crca_preset_definition() [13/51]

rz_plugin_crca_preset_definition ( crc16hdlc  ,
CRC_PRESET_16_HDLC   
)

◆ rz_plugin_crca_preset_definition() [14/51]

rz_plugin_crca_preset_definition ( crc16kermit  ,
CRC_PRESET_CRC16_KERMIT   
)

◆ rz_plugin_crca_preset_definition() [15/51]

rz_plugin_crca_preset_definition ( crc16maxim  ,
CRC_PRESET_CRC16_MAXIM   
)

◆ rz_plugin_crca_preset_definition() [16/51]

rz_plugin_crca_preset_definition ( crc16mcrf4xx  ,
CRC_PRESET_CRC16_MCRF4XX   
)

◆ rz_plugin_crca_preset_definition() [17/51]

rz_plugin_crca_preset_definition ( crc16modbus  ,
CRC_PRESET_CRC16_MODBUS   
)

◆ rz_plugin_crca_preset_definition() [18/51]

rz_plugin_crca_preset_definition ( crc16riello  ,
CRC_PRESET_CRC16_RIELLO   
)

◆ rz_plugin_crca_preset_definition() [19/51]

rz_plugin_crca_preset_definition ( crc16t10dif  ,
CRC_PRESET_CRC16_T10_DIF   
)

◆ rz_plugin_crca_preset_definition() [20/51]

rz_plugin_crca_preset_definition ( crc16teledisk  ,
CRC_PRESET_CRC16_TELEDISK   
)

◆ rz_plugin_crca_preset_definition() [21/51]

rz_plugin_crca_preset_definition ( crc16tms37157  ,
CRC_PRESET_CRC16_TMS37157   
)

◆ rz_plugin_crca_preset_definition() [22/51]

rz_plugin_crca_preset_definition ( crc16usb  ,
CRC_PRESET_16_USB   
)

◆ rz_plugin_crca_preset_definition() [23/51]

rz_plugin_crca_preset_definition ( crc16x25  ,
CRC_PRESET_CRC16_X25   
)

◆ rz_plugin_crca_preset_definition() [24/51]

rz_plugin_crca_preset_definition ( crc16xmodem  ,
CRC_PRESET_CRC16_XMODEM   
)

◆ rz_plugin_crca_preset_definition() [25/51]

rz_plugin_crca_preset_definition ( crc24  ,
CRC_PRESET_24   
)

◆ rz_plugin_crca_preset_definition() [26/51]

rz_plugin_crca_preset_definition ( crc32  ,
CRC_PRESET_32   
)

◆ rz_plugin_crca_preset_definition() [27/51]

rz_plugin_crca_preset_definition ( crc32bzip2  ,
CRC_PRESET_CRC32_BZIP2   
)

◆ rz_plugin_crca_preset_definition() [28/51]

rz_plugin_crca_preset_definition ( crc32c  ,
CRC_PRESET_32C   
)

◆ rz_plugin_crca_preset_definition() [29/51]

rz_plugin_crca_preset_definition ( crc32d  ,
CRC_PRESET_CRC32D   
)

◆ rz_plugin_crca_preset_definition() [30/51]

rz_plugin_crca_preset_definition ( crc32ecma267  ,
CRC_PRESET_32_ECMA_267   
)

◆ rz_plugin_crca_preset_definition() [31/51]

rz_plugin_crca_preset_definition ( crc32jamcrc  ,
CRC_PRESET_CRC32_JAMCRC   
)

◆ rz_plugin_crca_preset_definition() [32/51]

rz_plugin_crca_preset_definition ( crc32mpeg2  ,
CRC_PRESET_CRC32_MPEG2   
)

◆ rz_plugin_crca_preset_definition() [33/51]

rz_plugin_crca_preset_definition ( crc32posix  ,
CRC_PRESET_CRC32_POSIX   
)

◆ rz_plugin_crca_preset_definition() [34/51]

rz_plugin_crca_preset_definition ( crc32q  ,
CRC_PRESET_CRC32Q   
)

◆ rz_plugin_crca_preset_definition() [35/51]

rz_plugin_crca_preset_definition ( crc32xfer  ,
CRC_PRESET_CRC32_XFER   
)

◆ rz_plugin_crca_preset_definition() [36/51]

rz_plugin_crca_preset_definition ( crc64  ,
CRC_PRESET_CRC64   
)

◆ rz_plugin_crca_preset_definition() [37/51]

rz_plugin_crca_preset_definition ( crc64ecma182  ,
CRC_PRESET_CRC64_ECMA182   
)

◆ rz_plugin_crca_preset_definition() [38/51]

rz_plugin_crca_preset_definition ( crc64iso  ,
CRC_PRESET_CRC64_ISO   
)

◆ rz_plugin_crca_preset_definition() [39/51]

rz_plugin_crca_preset_definition ( crc64we  ,
CRC_PRESET_CRC64_WE   
)

◆ rz_plugin_crca_preset_definition() [40/51]

rz_plugin_crca_preset_definition ( crc64xz  ,
CRC_PRESET_CRC64_XZ   
)

◆ rz_plugin_crca_preset_definition() [41/51]

rz_plugin_crca_preset_definition ( crc8cdma2000  ,
CRC_PRESET_CRC8_CDMA2000   
)

◆ rz_plugin_crca_preset_definition() [42/51]

rz_plugin_crca_preset_definition ( crc8darc  ,
CRC_PRESET_CRC8_DARC   
)

◆ rz_plugin_crca_preset_definition() [43/51]

rz_plugin_crca_preset_definition ( crc8dvbs2  ,
CRC_PRESET_CRC8_DVB_S2   
)

◆ rz_plugin_crca_preset_definition() [44/51]

rz_plugin_crca_preset_definition ( crc8ebu  ,
CRC_PRESET_CRC8_EBU   
)

◆ rz_plugin_crca_preset_definition() [45/51]

rz_plugin_crca_preset_definition ( crc8icode  ,
CRC_PRESET_CRC8_ICODE   
)

◆ rz_plugin_crca_preset_definition() [46/51]

rz_plugin_crca_preset_definition ( crc8itu  ,
CRC_PRESET_CRC8_ITU   
)

◆ rz_plugin_crca_preset_definition() [47/51]

rz_plugin_crca_preset_definition ( crc8maxim  ,
CRC_PRESET_CRC8_MAXIM   
)

◆ rz_plugin_crca_preset_definition() [48/51]

rz_plugin_crca_preset_definition ( crc8rohc  ,
CRC_PRESET_CRC8_ROHC   
)

◆ rz_plugin_crca_preset_definition() [49/51]

rz_plugin_crca_preset_definition ( crc8smbus  ,
CRC_PRESET_8_SMBUS   
)

◆ rz_plugin_crca_preset_definition() [50/51]

rz_plugin_crca_preset_definition ( crc8wcdma  ,
CRC_PRESET_CRC8_WCDMA   
)

◆ rz_plugin_crca_preset_definition() [51/51]

rz_plugin_crca_preset_definition ( crca  ,
CRC_PRESET_CRCA   
)