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

CRC64 calculation (size-optimized) More...

#include "check.h"

Go to the source code of this file.

Functions

static void crc64_init (void)
 
 LZMA_API (uint64_t)
 Calculate approximate memory usage of easy encoder. More...
 

Variables

static uint64_t crc64_table [256]
 

Detailed Description

CRC64 calculation (size-optimized)

Definition in file crc64_small.c.

Function Documentation

◆ crc64_init()

static void crc64_init ( void  )
static

Definition at line 20 of file crc64_small.c.

21 {
22  static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
23 
24  for (size_t b = 0; b < 256; ++b) {
25  uint64_t r = b;
26  for (size_t i = 0; i < 8; ++i) {
27  if (r & 1)
28  r = (r >> 1) ^ poly64;
29  else
30  r >>= 1;
31  }
32 
33  crc64_table[b] = r;
34  }
35 
36  return;
37 }
lzma_index ** i
Definition: index.h:629
static uint64_t crc64_table[256]
Definition: crc64_small.c:16
#define r
Definition: crypto_rc6.c:12
unsigned long uint64_t
Definition: sftypes.h:28
#define b(i)
Definition: sha256.c:42
#define UINT64_C(val)

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

Referenced by LZMA_API().

◆ LZMA_API()

LZMA_API ( uint64_t  )

Calculate approximate memory usage of easy encoder.

Get the total amount of physical memory (RAM) in bytes.

Calculate approximate memory usage of multithreaded .xz encoder.

Calculate approximate decoder memory usage of a preset.

This function is a wrapper for lzma_raw_encoder_memusage().

Parameters
presetCompression preset (level and possible flags)
Returns
Number of bytes of memory required for the given preset when encoding. If an error occurs, for example due to unsupported preset, UINT64_MAX is returned.

This function is a wrapper for lzma_raw_decoder_memusage().

Parameters
presetCompression preset (level and possible flags)
Returns
Number of bytes of memory required to decompress a file that was compressed using the given preset. If an error occurs, for example due to unsupported preset, UINT64_MAX is returned.

Since doing the encoding in threaded mode doesn't affect the memory requirements of single-threaded decompressor, you can use lzma_easy_decoder_memusage(options->preset) or lzma_raw_decoder_memusage(options->filters) to calculate the decompressor memory requirements.

Parameters
optionsCompression options
Returns
Number of bytes of memory required for encoding with the given options. If an error occurs, for example due to unsupported preset or filter chain, UINT64_MAX is returned.

Calculate approximate memory usage of easy encoder.

Get the uncompressed size of the file.

Get the total size of the file.

Get the total size of the Blocks.

Get the total size of the Stream.

Get the size of the Index field as bytes.

Get the number of Blocks.

Get the number of Streams.

Calculate the memory usage of an existing lzma_index.

On disk, the size of the Index field depends on both the number of Records stored and how big values the Records store (due to variable-length integer encoding). When the Index is kept in lzma_index structure, the memory usage depends only on the number of Records/Blocks stored in the Index(es), and in case of concatenated lzma_indexes, the number of Streams. The size in RAM is almost always significantly bigger than in the encoded form on disk.

This function calculates an approximate amount of memory needed hold the given number of Streams and Blocks in lzma_index structure. This value may vary between CPU architectures and also between liblzma versions if the internal implementation is modified.

This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), lzma_index_block_count(i)).

This returns the total number of Blocks in lzma_index. To get number of Blocks in individual Streams, use lzma_index_iter.

This is needed to verify the Backward Size field in the Stream Footer.

If multiple lzma_indexes have been combined, this works as if the Blocks were in a single Stream. This is useful if you are going to combine Blocks from multiple Streams into a single new Stream.

This doesn't include the Stream Header, Stream Footer, Stream Padding, or Index fields.

When no lzma_indexes have been combined with lzma_index_cat() and there is no Stream Padding, this function is identical to lzma_index_stream_size(). If multiple lzma_indexes have been combined, this includes also the headers of each separate Stream and the possible Stream Padding fields.

Definition at line 40 of file crc64_small.c.

42 {
44 
45  crc = ~crc;
46 
47  while (size != 0) {
48  crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
49  --size;
50  }
51 
52  return ~crc;
53 }
static void crc64_init(void)
Definition: crc64_small.c:20
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
#define mythread_once(func)
Definition: mythread.h:72

References crc64_init(), crc64_table, and mythread_once.

Variable Documentation

◆ crc64_table

uint64_t crc64_table[256]
static

Definition at line 16 of file crc64_small.c.

Referenced by crc64_init(), and LZMA_API().