ulg bits_sent; /* bit length of the compressed data */
#endif
- uint32_t *crc_32_tab;
+ /*uint32_t *crc_32_tab;*/
uint32_t crc; /* shift register contents */
};
* pointer, then initialize the crc shift register contents instead.
* Return the current crc in either case.
*/
-static uint32_t updcrc(uch * s, unsigned n)
+static void updcrc(uch * s, unsigned n)
{
- uint32_t c = G1.crc;
- while (n) {
- c = G1.crc_32_tab[(uch)(c ^ *s++)] ^ (c >> 8);
- n--;
- }
- G1.crc = c;
- return c;
+ G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
}
ALLOC(uch, G1.window, 2L * WSIZE);
ALLOC(ush, G1.prev, 1L << BITS);
- /* Initialise the CRC32 table */
- G1.crc_32_tab = crc32_filltable(NULL, 0);
+ /* Initialize the CRC32 table */
+ global_crc32_table = crc32_filltable(NULL, 0);
return bbunpack(argv, pack_gzip, append_ext, "gz");
}
/* We use our own crc32 function */
#define XZ_INTERNAL_CRC32 0
-static uint32_t *crc32_table;
static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
{
- crc = ~crc;
-
- while (size != 0) {
- crc = crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
- --size;
- }
-
- return ~crc;
+ return ~crc32_block_endian0(~crc, buf, size, global_crc32_table);
}
/* We use arch-optimized unaligned accessors */
unsigned char *membuf;
IF_DESKTOP(long long) int total = 0;
- if (!crc32_table)
- crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
+ if (!global_crc32_table)
+ global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
memset(&iobuf, 0, sizeof(iobuf));
/* Preload XZ file signature */
/* Two callsites, both in inflate_get_next_window */
static void calculate_gunzip_crc(STATE_PARAM_ONLY)
{
- unsigned n;
- for (n = 0; n < gunzip_outbuf_count; n++) {
- gunzip_crc = gunzip_crc_table[((int) gunzip_crc ^ (gunzip_window[n])) & 0xff] ^ (gunzip_crc >> 8);
- }
+ gunzip_crc = crc32_block_endian0(gunzip_crc, gunzip_window, gunzip_outbuf_count, gunzip_crc_table);
gunzip_bytes_out += gunzip_outbuf_count;
}
} header_t;
struct globals {
- const uint32_t *lzo_crc32_table;
+ /*const uint32_t *lzo_crc32_table;*/
chksum_t chksum_in;
chksum_t chksum_out;
} FIX_ALIASING;
static FAST_FUNC uint32_t
lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
{
- uint32_t crc;
+ //if (buf == NULL) - impossible
+ // return 0;
- if (buf == NULL)
- return 0;
-
- crc = ~c;
- if (len != 0) do {
- crc = G.lzo_crc32_table[(uint8_t)((int)crc ^ *buf)] ^ (crc >> 8);
- buf += 1;
- len -= 1;
- } while (len > 0);
-
- return ~crc;
+ return ~crc32_block_endian0(~c, buf, len, global_crc32_table);
}
/**********************************************************************/
if (dst_len < src_len) {
/* write checksum of compressed block */
if (h->flags & F_ADLER32_C)
- write32(lzo_adler32(ADLER32_INIT_VALUE, b2,
- dst_len));
+ write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
if (h->flags & F_CRC32_C)
write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
/* write compressed block data */
if (applet_name[0] == 'u')
option_mask32 |= OPT_DECOMPRESS;
- G.lzo_crc32_table = crc32_filltable(NULL, 0);
+ global_crc32_table = crc32_filltable(NULL, 0);
return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);
}
off_t length, filesize;
int bytes_read;
int exit_code = EXIT_SUCCESS;
- uint8_t *cp;
#if ENABLE_DESKTOP
getopt32(argv, ""); /* coreutils 6.9 compat */
#define read_buf bb_common_bufsiz1
while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
- cp = (uint8_t *) read_buf;
- length += bytes_read;
- do {
- crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *cp++];
- } while (--bytes_read);
+ crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
}
close(fd);
void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
-/* TODO: add global crc32_table pointer and create
- * LE and BE functions to calculate crc32 over given bytes.
- * Currently we have about five reimplementations...
- */
+extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
+uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
+uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
typedef struct masks_labels_t {
const char *labels;
#include "libbb.h"
+uint32_t *global_crc32_table;
+
uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian)
{
uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320;
return crc_table - 256;
}
+
+uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table)
+{
+ const void *end = (uint8_t*)buf + len;
+
+ while (buf != end) {
+ val = (val << 8) ^ crc_table[(val >> 24) ^ *(uint8_t*)buf];
+ buf = (uint8_t*)buf + 1;
+ }
+ return val;
+}
+
+uint32_t FAST_FUNC crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table)
+{
+ const void *end = (uint8_t*)buf + len;
+
+ while (buf != end) {
+ val = crc_table [(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8);
+ buf = (uint8_t*)buf + 1;
+ }
+ return val;
+}
#define cpu_to_je16(v) ((jint16_t){(v)})
#define cpu_to_je32(v) ((jint32_t){(v)})
-static uint32_t crc32(uint32_t val, const void *ss, int len,
- uint32_t *crc32_table)
-{
- const unsigned char *s = ss;
- while (--len >= 0)
- val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
- return val;
-}
-
static void show_progress(mtd_info_t *meminfo, erase_info_t *erase)
{
printf("\rErasing %u Kibyte @ %x - %2u%% complete.",
cleanmarker.totlen = cpu_to_je32(8);
}
- cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, sizeof(struct jffs2_unknown_node) - 4,
- crc32_table));
+ cleanmarker.hdr_crc = cpu_to_je32(
+ crc32_block_endian0(0, &cleanmarker, sizeof(struct jffs2_unknown_node) - 4, crc32_table)
+ );
}
/* Don't want to destroy progress indicator by bb_error_msg's */
static unsigned int part_array_len;
static unsigned int part_entry_len;
-static uint32_t *crc32_table;
-
static inline gpt_partition *
gpt_part(int i)
{
static uint32_t
gpt_crc32(void *buf, int len)
{
- uint32_t crc = 0xffffffff;
-
- for (; len > 0; len--, buf++) {
- crc = crc32_table[(crc ^ *((char *)buf)) & 0xff] ^ (crc >> 8);
- }
- return crc ^ 0xffffffff;
+ return 0xffffffff ^ crc32_block_endian0(0xffffffff, buf, len, global_crc32_table);
}
static void
return 0;
}
- if (!crc32_table) {
- crc32_table = crc32_filltable(NULL, 0);
+ if (!global_crc32_table) {
+ global_crc32_table = crc32_filltable(NULL, 0);
}
crc = SWAP_LE32(gpt_hdr->hdr_crc32);