rizin/librz/hash/algorithms/mod255/mod255.c
Giovanni 82e7917294
Refactoring Hash (#1082)
* 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
2021-05-02 20:47:17 +08:00

27 lines
604 B
C

// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include "mod255.h"
#include <rz_util.h>
bool rz_mod255_init(RzMod255 *ctx) {
rz_return_val_if_fail(ctx, false);
*ctx = 0;
return true;
}
bool rz_mod255_update(RzMod255 *ctx, const ut8 *data, size_t len) {
rz_return_val_if_fail(ctx && data, false);
ut8 value = *ctx;
for (size_t i = 0; i < len; ++i) {
value += data[i];
}
*ctx = value;
return true;
}
bool rz_mod255_final(ut8 *digest, RzMod255 *ctx) {
rz_return_val_if_fail(digest && ctx, false);
*digest = (*ctx) % 255;
return true;
}