Rizin
unix-like reverse engineering framework and cli tools
fletcher.c File Reference
#include "fletcher.h"
#include <rz_util.h>

Go to the source code of this file.

Functions

bool rz_fletcher8_init (RzFletcher8 *ctx)
 
bool rz_fletcher8_update (RzFletcher8 *ctx, const ut8 *data, size_t len)
 
bool rz_fletcher8_final (ut8 *digest, RzFletcher8 *ctx)
 
bool rz_fletcher16_init (RzFletcher16 *ctx)
 
bool rz_fletcher16_update (RzFletcher16 *ctx, const ut8 *data, size_t len)
 
bool rz_fletcher16_final (ut8 *digest, RzFletcher16 *ctx)
 
bool rz_fletcher32_init (RzFletcher32 *ctx)
 
bool rz_fletcher32_update (RzFletcher32 *ctx, const ut8 *data, size_t len)
 
bool rz_fletcher32_final (ut8 *digest, RzFletcher32 *ctx)
 
bool rz_fletcher64_init (RzFletcher64 *ctx)
 
bool rz_fletcher64_update (RzFletcher64 *ctx, const ut8 *data, size_t len)
 
bool rz_fletcher64_final (ut8 *digest, RzFletcher64 *ctx)
 

Function Documentation

◆ rz_fletcher16_final()

bool rz_fletcher16_final ( ut8 digest,
RzFletcher16 ctx 
)

Definition at line 58 of file fletcher.c.

58  {
59  rz_return_val_if_fail(ctx && digest, false);
60  ctx->low %= 0xff;
61  ctx->high %= 0xff;
62  rz_write_le16(digest, (ctx->high << 8 | ctx->low));
63  return true;
64 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
static void rz_write_le16(void *dest, ut16 val)
Definition: rz_endian.h:222

References rz_return_val_if_fail, and rz_write_le16().

◆ rz_fletcher16_init()

bool rz_fletcher16_init ( RzFletcher16 ctx)

Definition at line 34 of file fletcher.c.

34  {
35  rz_return_val_if_fail(ctx, false);
36  memset(ctx, 0, sizeof(RzFletcher16));
37  return true;
38 }
return memset(p, 0, total)

References memset(), and rz_return_val_if_fail.

◆ rz_fletcher16_update()

bool rz_fletcher16_update ( RzFletcher16 ctx,
const ut8 data,
size_t  len 
)

Definition at line 40 of file fletcher.c.

40  {
41  rz_return_val_if_fail(ctx && data, false);
42  size_t i;
43  for (; len >= 5802; len -= 5802) {
44  for (i = 0; i < 5802; i++) {
45  ctx->low = ctx->low + *data++;
46  ctx->high = ctx->high + ctx->low;
47  }
48  ctx->low %= 0xff;
49  ctx->high %= 0xff;
50  }
51  for (i = 0; i < len; i++) {
52  ctx->low += *data++;
53  ctx->high += ctx->low;
54  }
55  return true;
56 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629

References i, len, and rz_return_val_if_fail.

◆ rz_fletcher32_final()

bool rz_fletcher32_final ( ut8 digest,
RzFletcher32 ctx 
)

Definition at line 101 of file fletcher.c.

101  {
102  rz_return_val_if_fail(ctx && digest, false);
103  ctx->low %= UT16_MAX;
104  ctx->high %= UT16_MAX;
105  rz_write_le32(digest, ctx->high << 16 | ctx->low);
106  return true;
107 }
static void rz_write_le32(void *dest, ut32 val)
Definition: rz_endian.h:256
#define UT16_MAX

References rz_return_val_if_fail, rz_write_le32(), and UT16_MAX.

◆ rz_fletcher32_init()

bool rz_fletcher32_init ( RzFletcher32 ctx)

Definition at line 68 of file fletcher.c.

68  {
69  rz_return_val_if_fail(ctx, false);
70  memset(ctx, 0, sizeof(RzFletcher32));
71  return true;
72 }

References memset(), and rz_return_val_if_fail.

◆ rz_fletcher32_update()

bool rz_fletcher32_update ( RzFletcher32 ctx,
const ut8 data,
size_t  len 
)

Definition at line 74 of file fletcher.c.

74  {
75  rz_return_val_if_fail(ctx && data, false);
76  size_t i;
77  ut8 word[sizeof(ut16)];
78  for (; len >= 360; len -= 360) {
79  for (i = 0; i < 360; i += 2) {
80  size_t left = 360 - i;
81  memset(word, 0, sizeof(word));
82  memcpy(word, data, RZ_MIN(sizeof(word), left));
83  ctx->low += rz_read_le16(word);
84  ctx->high += ctx->low;
85  data += 2;
86  }
87  ctx->low %= UT16_MAX;
88  ctx->high %= UT16_MAX;
89  }
90  for (i = 0; i < len; i += 2) {
91  size_t left = len - i;
92  memset(word, 0, sizeof(word));
93  memcpy(word, data, RZ_MIN(sizeof(word), left));
94  ctx->low += rz_read_le16(word);
95  ctx->high += ctx->low;
96  data += 2;
97  }
98  return true;
99 }
uint16_t ut16
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206
#define RZ_MIN(x, y)

References i, len, memcpy(), memset(), RZ_MIN, rz_read_le16(), rz_return_val_if_fail, and UT16_MAX.

◆ rz_fletcher64_final()

bool rz_fletcher64_final ( ut8 digest,
RzFletcher64 ctx 
)

Definition at line 132 of file fletcher.c.

132  {
133  rz_return_val_if_fail(ctx && digest, false);
134  rz_write_le64(digest, ((ut64)ctx->high << 32) | ctx->low);
135  return true;
136 }
static void rz_write_le64(void *dest, ut64 val)
Definition: rz_endian.h:277
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_return_val_if_fail, rz_write_le64(), and ut64().

◆ rz_fletcher64_init()

bool rz_fletcher64_init ( RzFletcher64 ctx)

Definition at line 111 of file fletcher.c.

111  {
112  rz_return_val_if_fail(ctx, false);
113  memset(ctx, 0, sizeof(RzFletcher64));
114  return true;
115 }

References memset(), and rz_return_val_if_fail.

◆ rz_fletcher64_update()

bool rz_fletcher64_update ( RzFletcher64 ctx,
const ut8 data,
size_t  len 
)

Definition at line 117 of file fletcher.c.

117  {
118  rz_return_val_if_fail(ctx && data, false);
119 
120  ut8 word[sizeof(ut32)];
121  for (size_t i = 0; i < len; i += sizeof(ut32)) {
122  size_t left = RZ_MIN(sizeof(ut32), len - i);
123  memset(word, 0, sizeof(word));
124  memcpy(word, &data[i], left);
125  ut32 value = rz_read_le32(word);
126  ctx->low += value;
127  ctx->high += ctx->low;
128  }
129  return true;
130 }
static int value
Definition: cmd_api.c:93
uint32_t ut32
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239

References i, len, memcpy(), memset(), RZ_MIN, rz_read_le32(), rz_return_val_if_fail, and value.

◆ rz_fletcher8_final()

bool rz_fletcher8_final ( ut8 digest,
RzFletcher8 ctx 
)

Definition at line 26 of file fletcher.c.

26  {
27  rz_return_val_if_fail(ctx && digest, false);
28  rz_write_le8(digest, (ctx->low & 0xff));
29  return true;
30 }
static void rz_write_le8(void *dest, ut8 val)
Definition: rz_endian.h:198

References rz_return_val_if_fail, and rz_write_le8().

◆ rz_fletcher8_init()

bool rz_fletcher8_init ( RzFletcher8 ctx)

Definition at line 9 of file fletcher.c.

9  {
10  rz_return_val_if_fail(ctx, false);
11  memset(ctx, 0, sizeof(RzFletcher8));
12  return true;
13 }

References memset(), and rz_return_val_if_fail.

◆ rz_fletcher8_update()

bool rz_fletcher8_update ( RzFletcher8 ctx,
const ut8 data,
size_t  len 
)

Definition at line 15 of file fletcher.c.

15  {
16  rz_return_val_if_fail(ctx && data, false);
17  for (size_t i = 0; i < len; i++) {
18  ctx->low += data[i];
19  ctx->low = (ctx->low & 0xff) + (ctx->low >> 8);
20  ctx->high += ctx->low;
21  ctx->high = (ctx->high & 0xff) + (ctx->high >> 8);
22  }
23  return true;
24 }

References i, len, and rz_return_val_if_fail.