Rizin
unix-like reverse engineering framework and cli tools
crc64_fast.c
Go to the documentation of this file.
1 //
9 //
10 // Author: Lasse Collin
11 //
12 // This file has been put into the public domain.
13 // You can do whatever you want with this file.
14 //
16 
17 #include "check.h"
18 #include "crc_macros.h"
19 
20 
21 #ifdef WORDS_BIGENDIAN
22 # define A1(x) ((x) >> 56)
23 #else
24 # define A1 A
25 #endif
26 
27 
28 // See the comments in crc32_fast.c. They aren't duplicated here.
30 lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
31 {
32  crc = ~crc;
33 
34 #ifdef WORDS_BIGENDIAN
35  crc = bswap64(crc);
36 #endif
37 
38  if (size > 4) {
39  while ((uintptr_t)(buf) & 3) {
40  crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
41  --size;
42  }
43 
44  const uint8_t *const limit = buf + (size & ~(size_t)(3));
45  size &= (size_t)(3);
46 
47  while (buf < limit) {
48 #ifdef WORDS_BIGENDIAN
49  const uint32_t tmp = (crc >> 32)
51 #else
52  const uint32_t tmp = crc ^ aligned_read32ne(buf);
53 #endif
54  buf += 4;
55 
56  crc = lzma_crc64_table[3][A(tmp)]
57  ^ lzma_crc64_table[2][B(tmp)]
58  ^ S32(crc)
59  ^ lzma_crc64_table[1][C(tmp)]
60  ^ lzma_crc64_table[0][D(tmp)];
61  }
62  }
63 
64  while (size-- != 0)
65  crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
66 
67 #ifdef WORDS_BIGENDIAN
68  crc = bswap64(crc);
69 #endif
70 
71  return ~crc;
72 }
#define A(x)
Definition: arc.h:165
#define B(x)
Definition: arc.h:166
#define C(x)
Definition: arc.h:167
#define D
Definition: block.c:38
Internal API to different integrity check functions.
const uint64_t lzma_crc64_table[4][256]
Definition: crc64_table_be.h:3
LZMA_API(uint64_t)
Calculate approximate memory usage of easy encoder.
Definition: crc64_fast.c:29
#define A1
Definition: crc64_fast.c:24
Some endian-dependent macros for CRC32 and CRC64.
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
#define S8(val)
int size_t
Definition: sftypes.h:40
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
#define S32(b, x)
Definition: sha2.c:148
_W64 unsigned int uintptr_t
#define bswap64(n)
static uint32_t aligned_read32ne(const uint8_t *buf)