* Added authors and licenses and plugin access to crypto related files * removed `rz_hash` and related files * introduced `rz_msg_digest_*` with plugins * updated all old methods with newer ones. * added HMAC support to `rz-hash` (moved key option under `-K`) * removed wrong algorithms on `woD`/`woE` * fixed parity digest size * fixed the behaviour on all hash functions * added unit test for hash * optimized code for HMAC key calculation * removed hash legacy tests
29 lines
777 B
C
29 lines
777 B
C
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
#include "parity.h"
|
|
#include <rz_util.h>
|
|
|
|
bool rz_parity_init(RzParity *ctx) {
|
|
rz_return_val_if_fail(ctx, false);
|
|
*ctx = 0;
|
|
return true;
|
|
}
|
|
|
|
bool rz_parity_update(RzParity *ctx, const ut8 *data, size_t len) {
|
|
rz_return_val_if_fail(ctx && data, false);
|
|
ut32 ones = *ctx;
|
|
for (size_t i = 0; i < len; ++i) {
|
|
ut8 x = data[i];
|
|
ones += ((x & 128) ? 1 : 0) + ((x & 64) ? 1 : 0) + ((x & 32) ? 1 : 0) + ((x & 16) ? 1 : 0) +
|
|
((x & 8) ? 1 : 0) + ((x & 4) ? 1 : 0) + ((x & 2) ? 1 : 0) + ((x & 1) ? 1 : 0);
|
|
}
|
|
*ctx = ones;
|
|
return true;
|
|
}
|
|
|
|
bool rz_parity_final(ut8 *digest, RzParity *ctx) {
|
|
rz_return_val_if_fail(digest && ctx, false);
|
|
*digest = (*ctx) & 1;
|
|
return true;
|
|
}
|