Rizin
unix-like reverse engineering framework and cli tools
adler32.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 "adler32.h"
5 #include <rz_util.h>
6 
9  ctx->low = 1;
10  ctx->high = 0;
11  return true;
12 }
13 
14 bool rz_adler32_update(RzAdler32 *ctx, const ut8 *data, size_t len) {
15  rz_return_val_if_fail(ctx && data, false);
16  for (size_t index = 0; index < len; index++) {
17  ctx->low = (ctx->low + data[index]) % 65521;
18  ctx->high = (ctx->high + ctx->low) % 65521;
19  }
20  return true;
21 }
22 
23 bool rz_adler32_final(ut8 *digest, RzAdler32 *ctx) {
24  rz_return_val_if_fail(digest && ctx, false);
25  rz_write_le32(digest, ctx->high << 16 | ctx->low);
26  return true;
27 }
size_t len
Definition: 6502dis.c:15
uint8_t ut8
Definition: lh5801.h:11
bool rz_adler32_init(RzAdler32 *ctx)
Definition: adler32.c:7
bool rz_adler32_update(RzAdler32 *ctx, const ut8 *data, size_t len)
Definition: adler32.c:14
bool rz_adler32_final(ut8 *digest, RzAdler32 *ctx)
Definition: adler32.c:23
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
static void rz_write_le32(void *dest, ut32 val)
Definition: rz_endian.h:256