Rizin
unix-like reverse engineering framework and cli tools
parity.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include "parity.h"
5 #include <rz_util.h>
6 
9  *ctx = 0;
10  return true;
11 }
12 
13 bool rz_parity_update(RzParity *ctx, const ut8 *data, size_t len) {
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 }
24 
25 bool rz_parity_final(ut8 *digest, RzParity *ctx) {
26  rz_return_val_if_fail(digest && ctx, false);
27  *digest = (*ctx) & 1;
28  return true;
29 }
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
bool rz_parity_update(RzParity *ctx, const ut8 *data, size_t len)
Definition: parity.c:13
bool rz_parity_init(RzParity *ctx)
Definition: parity.c:7
bool rz_parity_final(ut8 *digest, RzParity *ctx)
Definition: parity.c:25
ut32 RzParity
Definition: parity.h:12
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108