Rizin
unix-like reverse engineering framework and cli tools
crc32_small.c
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #include "check.h"
14 
15 
17 
18 
19 static void
21 {
22  static const uint32_t poly32 = UINT32_C(0xEDB88320);
23 
24  for (size_t b = 0; b < 256; ++b) {
25  uint32_t r = b;
26  for (size_t i = 0; i < 8; ++i) {
27  if (r & 1)
28  r = (r >> 1) ^ poly32;
29  else
30  r >>= 1;
31  }
32 
33  lzma_crc32_table[0][b] = r;
34  }
35 
36  return;
37 }
38 
39 
40 extern void
42 {
44  return;
45 }
46 
47 
49 lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
50 {
52 
53  crc = ~crc;
54 
55  while (size != 0) {
56  crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
57  --size;
58  }
59 
60  return ~crc;
61 }
lzma_index ** i
Definition: index.h:629
Internal API to different integrity check functions.
void lzma_crc32_init(void)
Definition: crc32_small.c:41
LZMA_API(uint32_t)
Definition: crc32_small.c:48
static void crc32_init(void)
Definition: crc32_small.c:20
uint32_t lzma_crc32_table[1][256]
Definition: crc32_small.c:16
#define r
Definition: crypto_rc6.c:12
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
#define mythread_once(func)
Definition: mythread.h:72
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define b(i)
Definition: sha256.c:42
#define UINT32_C(val)