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

Go to the source code of this file.

Macros

#define RZ_HASH_PARITY_DIGEST_SIZE   1
 
#define RZ_HASH_PARITY_BLOCK_LENGTH   0
 

Typedefs

typedef ut32 RzParity
 

Functions

bool rz_parity_init (RzParity *ctx)
 
bool rz_parity_update (RzParity *ctx, const ut8 *data, size_t len)
 
bool rz_parity_final (ut8 *digest, RzParity *ctx)
 

Macro Definition Documentation

◆ RZ_HASH_PARITY_BLOCK_LENGTH

#define RZ_HASH_PARITY_BLOCK_LENGTH   0

Definition at line 10 of file parity.h.

◆ RZ_HASH_PARITY_DIGEST_SIZE

#define RZ_HASH_PARITY_DIGEST_SIZE   1

Definition at line 9 of file parity.h.

Typedef Documentation

◆ RzParity

typedef ut32 RzParity

Definition at line 12 of file parity.h.

Function Documentation

◆ rz_parity_final()

bool rz_parity_final ( ut8 digest,
RzParity ctx 
)

Definition at line 25 of file parity.c.

25  {
26  rz_return_val_if_fail(digest && ctx, false);
27  *digest = (*ctx) & 1;
28  return true;
29 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References rz_return_val_if_fail.

Referenced by plugin_parity_final(), and plugin_parity_small_block().

◆ rz_parity_init()

bool rz_parity_init ( RzParity ctx)

Definition at line 7 of file parity.c.

7  {
9  *ctx = 0;
10  return true;
11 }

References rz_return_val_if_fail.

Referenced by plugin_parity_init(), and plugin_parity_small_block().

◆ rz_parity_update()

bool rz_parity_update ( RzParity ctx,
const ut8 data,
size_t  len 
)

Definition at line 13 of file parity.c.

13  {
14  rz_return_val_if_fail(ctx && data, false);
15  ut32 ones = *ctx;
16  for (size_t i = 0; i < len; ++i) {
17  ut8 x = data[i];
18  ones += ((x & 128) ? 1 : 0) + ((x & 64) ? 1 : 0) + ((x & 32) ? 1 : 0) + ((x & 16) ? 1 : 0) +
19  ((x & 8) ? 1 : 0) + ((x & 4) ? 1 : 0) + ((x & 2) ? 1 : 0) + ((x & 1) ? 1 : 0);
20  }
21  *ctx = ones;
22  return true;
23 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
int x
Definition: mipsasm.c:20

References i, len, rz_return_val_if_fail, and x.

Referenced by plugin_parity_small_block(), and plugin_parity_update().