Rizin
unix-like reverse engineering framework and cli tools
crc64_tablegen.c File Reference

Generate crc64_table_le.h and crc64_table_be.h. More...

#include <stdio.h>
#include "../../common/tuklib_integer.h"

Go to the source code of this file.

Functions

void init_crc64_table (void)
 
static void print_crc64_table (void)
 
int main (void)
 

Variables

static uint64_t crc64_table [4][256]
 

Detailed Description

Generate crc64_table_le.h and crc64_table_be.h.

Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c Add -DWORDS_BIGENDIAN to generate big endian table.

Definition in file crc64_tablegen.c.

Function Documentation

◆ init_crc64_table()

void init_crc64_table ( void  )

Definition at line 24 of file crc64_tablegen.c.

25 {
26  static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
27 
28  for (size_t s = 0; s < 4; ++s) {
29  for (size_t b = 0; b < 256; ++b) {
30  uint64_t r = s == 0 ? b : crc64_table[s - 1][b];
31 
32  for (size_t i = 0; i < 8; ++i) {
33  if (r & 1)
34  r = (r >> 1) ^ poly64;
35  else
36  r >>= 1;
37  }
38 
39  crc64_table[s][b] = r;
40  }
41  }
42 
43 #ifdef WORDS_BIGENDIAN
44  for (size_t s = 0; s < 4; ++s)
45  for (size_t b = 0; b < 256; ++b)
47 #endif
48 
49  return;
50 }
lzma_index ** i
Definition: index.h:629
static uint64_t crc64_table[4][256]
#define r
Definition: crypto_rc6.c:12
static RzSocket * s
Definition: rtr.c:28
unsigned long uint64_t
Definition: sftypes.h:28
#define b(i)
Definition: sha256.c:42
#define UINT64_C(val)
#define bswap64(n)

References b, bswap64, crc64_table, i, r, s, and UINT64_C.

Referenced by main().

◆ main()

int main ( void  )

Definition at line 83 of file crc64_tablegen.c.

84 {
87  return 0;
88 }
static void print_crc64_table(void)
void init_crc64_table(void)

References init_crc64_table(), and print_crc64_table().

◆ print_crc64_table()

static void print_crc64_table ( void  )
static

Definition at line 54 of file crc64_tablegen.c.

55 {
56  printf("/* This file has been automatically generated by "
57  "crc64_tablegen.c. */\n\n"
58  "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
59 
60  for (size_t s = 0; s < 4; ++s) {
61  for (size_t b = 0; b < 256; ++b) {
62  if ((b % 2) == 0)
63  printf("\n\t\t");
64 
65  printf("UINT64_C(0x%016" PRIX64 ")",
66  crc64_table[s][b]);
67 
68  if (b != 255)
69  printf(",%s", (b+1) % 2 == 0 ? "" : " ");
70  }
71 
72  if (s == 3)
73  printf("\n\t}\n};\n");
74  else
75  printf("\n\t}, {");
76  }
77 
78  return;
79 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
#define PRIX64
Definition: sysdefs.h:97

References b, crc64_table, printf(), PRIX64, and s.

Referenced by main().

Variable Documentation

◆ crc64_table

uint64_t crc64_table[4][256]
static

Definition at line 20 of file crc64_tablegen.c.

Referenced by init_crc64_table(), and print_crc64_table().