diff options
-rw-r--r-- | archival/gzip.c | 16 | ||||
-rw-r--r-- | archival/libunarchive/decompress_unxz.c | 14 | ||||
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 5 | ||||
-rw-r--r-- | archival/lzop.c | 22 | ||||
-rw-r--r-- | coreutils/cksum.c | 7 | ||||
-rw-r--r-- | include/libbb.h | 7 | ||||
-rw-r--r-- | libbb/crc32.c | 24 | ||||
-rw-r--r-- | miscutils/flash_eraseall.c | 14 | ||||
-rw-r--r-- | util-linux/fdisk_gpt.c | 13 |
9 files changed, 49 insertions, 73 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 32528d96b..4d399063d 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -340,7 +340,7 @@ struct globals { | |||
340 | ulg bits_sent; /* bit length of the compressed data */ | 340 | ulg bits_sent; /* bit length of the compressed data */ |
341 | #endif | 341 | #endif |
342 | 342 | ||
343 | uint32_t *crc_32_tab; | 343 | /*uint32_t *crc_32_tab;*/ |
344 | uint32_t crc; /* shift register contents */ | 344 | uint32_t crc; /* shift register contents */ |
345 | }; | 345 | }; |
346 | 346 | ||
@@ -393,15 +393,9 @@ static void put_32bit(ulg n) | |||
393 | * pointer, then initialize the crc shift register contents instead. | 393 | * pointer, then initialize the crc shift register contents instead. |
394 | * Return the current crc in either case. | 394 | * Return the current crc in either case. |
395 | */ | 395 | */ |
396 | static uint32_t updcrc(uch * s, unsigned n) | 396 | static void updcrc(uch * s, unsigned n) |
397 | { | 397 | { |
398 | uint32_t c = G1.crc; | 398 | G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/); |
399 | while (n) { | ||
400 | c = G1.crc_32_tab[(uch)(c ^ *s++)] ^ (c >> 8); | ||
401 | n--; | ||
402 | } | ||
403 | G1.crc = c; | ||
404 | return c; | ||
405 | } | 399 | } |
406 | 400 | ||
407 | 401 | ||
@@ -2104,8 +2098,8 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) | |||
2104 | ALLOC(uch, G1.window, 2L * WSIZE); | 2098 | ALLOC(uch, G1.window, 2L * WSIZE); |
2105 | ALLOC(ush, G1.prev, 1L << BITS); | 2099 | ALLOC(ush, G1.prev, 1L << BITS); |
2106 | 2100 | ||
2107 | /* Initialise the CRC32 table */ | 2101 | /* Initialize the CRC32 table */ |
2108 | G1.crc_32_tab = crc32_filltable(NULL, 0); | 2102 | global_crc32_table = crc32_filltable(NULL, 0); |
2109 | 2103 | ||
2110 | return bbunpack(argv, pack_gzip, append_ext, "gz"); | 2104 | return bbunpack(argv, pack_gzip, append_ext, "gz"); |
2111 | } | 2105 | } |
diff --git a/archival/libunarchive/decompress_unxz.c b/archival/libunarchive/decompress_unxz.c index faba9ca82..ca427231e 100644 --- a/archival/libunarchive/decompress_unxz.c +++ b/archival/libunarchive/decompress_unxz.c | |||
@@ -22,17 +22,9 @@ | |||
22 | 22 | ||
23 | /* We use our own crc32 function */ | 23 | /* We use our own crc32 function */ |
24 | #define XZ_INTERNAL_CRC32 0 | 24 | #define XZ_INTERNAL_CRC32 0 |
25 | static uint32_t *crc32_table; | ||
26 | static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc) | 25 | static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc) |
27 | { | 26 | { |
28 | crc = ~crc; | 27 | return ~crc32_block_endian0(~crc, buf, size, global_crc32_table); |
29 | |||
30 | while (size != 0) { | ||
31 | crc = crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8); | ||
32 | --size; | ||
33 | } | ||
34 | |||
35 | return ~crc; | ||
36 | } | 28 | } |
37 | 29 | ||
38 | /* We use arch-optimized unaligned accessors */ | 30 | /* We use arch-optimized unaligned accessors */ |
@@ -53,8 +45,8 @@ unpack_xz_stream(int src_fd, int dst_fd) | |||
53 | unsigned char *membuf; | 45 | unsigned char *membuf; |
54 | IF_DESKTOP(long long) int total = 0; | 46 | IF_DESKTOP(long long) int total = 0; |
55 | 47 | ||
56 | if (!crc32_table) | 48 | if (!global_crc32_table) |
57 | crc32_table = crc32_filltable(NULL, /*endian:*/ 0); | 49 | global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0); |
58 | 50 | ||
59 | memset(&iobuf, 0, sizeof(iobuf)); | 51 | memset(&iobuf, 0, sizeof(iobuf)); |
60 | /* Preload XZ file signature */ | 52 | /* Preload XZ file signature */ |
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 20fda9d26..cb8a3d737 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -925,10 +925,7 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
925 | /* Two callsites, both in inflate_get_next_window */ | 925 | /* Two callsites, both in inflate_get_next_window */ |
926 | static void calculate_gunzip_crc(STATE_PARAM_ONLY) | 926 | static void calculate_gunzip_crc(STATE_PARAM_ONLY) |
927 | { | 927 | { |
928 | unsigned n; | 928 | gunzip_crc = crc32_block_endian0(gunzip_crc, gunzip_window, gunzip_outbuf_count, gunzip_crc_table); |
929 | for (n = 0; n < gunzip_outbuf_count; n++) { | ||
930 | gunzip_crc = gunzip_crc_table[((int) gunzip_crc ^ (gunzip_window[n])) & 0xff] ^ (gunzip_crc >> 8); | ||
931 | } | ||
932 | gunzip_bytes_out += gunzip_outbuf_count; | 929 | gunzip_bytes_out += gunzip_outbuf_count; |
933 | } | 930 | } |
934 | 931 | ||
diff --git a/archival/lzop.c b/archival/lzop.c index c6e718ad7..acb34fe14 100644 --- a/archival/lzop.c +++ b/archival/lzop.c | |||
@@ -393,7 +393,7 @@ typedef struct header_t { | |||
393 | } header_t; | 393 | } header_t; |
394 | 394 | ||
395 | struct globals { | 395 | struct globals { |
396 | const uint32_t *lzo_crc32_table; | 396 | /*const uint32_t *lzo_crc32_table;*/ |
397 | chksum_t chksum_in; | 397 | chksum_t chksum_in; |
398 | chksum_t chksum_out; | 398 | chksum_t chksum_out; |
399 | } FIX_ALIASING; | 399 | } FIX_ALIASING; |
@@ -468,19 +468,10 @@ lzo_adler32(uint32_t adler, const uint8_t* buf, unsigned len) | |||
468 | static FAST_FUNC uint32_t | 468 | static FAST_FUNC uint32_t |
469 | lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len) | 469 | lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len) |
470 | { | 470 | { |
471 | uint32_t crc; | 471 | //if (buf == NULL) - impossible |
472 | // return 0; | ||
472 | 473 | ||
473 | if (buf == NULL) | 474 | return ~crc32_block_endian0(~c, buf, len, global_crc32_table); |
474 | return 0; | ||
475 | |||
476 | crc = ~c; | ||
477 | if (len != 0) do { | ||
478 | crc = G.lzo_crc32_table[(uint8_t)((int)crc ^ *buf)] ^ (crc >> 8); | ||
479 | buf += 1; | ||
480 | len -= 1; | ||
481 | } while (len > 0); | ||
482 | |||
483 | return ~crc; | ||
484 | } | 475 | } |
485 | 476 | ||
486 | /**********************************************************************/ | 477 | /**********************************************************************/ |
@@ -679,8 +670,7 @@ static NOINLINE smallint lzo_compress(const header_t *h) | |||
679 | if (dst_len < src_len) { | 670 | if (dst_len < src_len) { |
680 | /* write checksum of compressed block */ | 671 | /* write checksum of compressed block */ |
681 | if (h->flags & F_ADLER32_C) | 672 | if (h->flags & F_ADLER32_C) |
682 | write32(lzo_adler32(ADLER32_INIT_VALUE, b2, | 673 | write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len)); |
683 | dst_len)); | ||
684 | if (h->flags & F_CRC32_C) | 674 | if (h->flags & F_CRC32_C) |
685 | write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len)); | 675 | write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len)); |
686 | /* write compressed block data */ | 676 | /* write compressed block data */ |
@@ -1080,6 +1070,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv) | |||
1080 | if (applet_name[0] == 'u') | 1070 | if (applet_name[0] == 'u') |
1081 | option_mask32 |= OPT_DECOMPRESS; | 1071 | option_mask32 |= OPT_DECOMPRESS; |
1082 | 1072 | ||
1083 | G.lzo_crc32_table = crc32_filltable(NULL, 0); | 1073 | global_crc32_table = crc32_filltable(NULL, 0); |
1084 | return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL); | 1074 | return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL); |
1085 | } | 1075 | } |
diff --git a/coreutils/cksum.c b/coreutils/cksum.c index 7bf383e2d..7a37e6add 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c | |||
@@ -18,7 +18,6 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) | |||
18 | off_t length, filesize; | 18 | off_t length, filesize; |
19 | int bytes_read; | 19 | int bytes_read; |
20 | int exit_code = EXIT_SUCCESS; | 20 | int exit_code = EXIT_SUCCESS; |
21 | uint8_t *cp; | ||
22 | 21 | ||
23 | #if ENABLE_DESKTOP | 22 | #if ENABLE_DESKTOP |
24 | getopt32(argv, ""); /* coreutils 6.9 compat */ | 23 | getopt32(argv, ""); /* coreutils 6.9 compat */ |
@@ -39,11 +38,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) | |||
39 | 38 | ||
40 | #define read_buf bb_common_bufsiz1 | 39 | #define read_buf bb_common_bufsiz1 |
41 | while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) { | 40 | while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) { |
42 | cp = (uint8_t *) read_buf; | 41 | crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); |
43 | length += bytes_read; | ||
44 | do { | ||
45 | crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *cp++]; | ||
46 | } while (--bytes_read); | ||
47 | } | 42 | } |
48 | close(fd); | 43 | close(fd); |
49 | 44 | ||
diff --git a/include/libbb.h b/include/libbb.h index d14728ed0..587a5f952 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1543,11 +1543,10 @@ void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; | |||
1543 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1543 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1544 | void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1544 | void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1545 | 1545 | ||
1546 | /* TODO: add global crc32_table pointer and create | 1546 | extern uint32_t *global_crc32_table; |
1547 | * LE and BE functions to calculate crc32 over given bytes. | ||
1548 | * Currently we have about five reimplementations... | ||
1549 | */ | ||
1550 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 1547 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |
1548 | uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC; | ||
1549 | uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC; | ||
1551 | 1550 | ||
1552 | typedef struct masks_labels_t { | 1551 | typedef struct masks_labels_t { |
1553 | const char *labels; | 1552 | const char *labels; |
diff --git a/libbb/crc32.c b/libbb/crc32.c index 520b1ffb9..2cc6ea779 100644 --- a/libbb/crc32.c +++ b/libbb/crc32.c | |||
@@ -18,6 +18,8 @@ | |||
18 | 18 | ||
19 | #include "libbb.h" | 19 | #include "libbb.h" |
20 | 20 | ||
21 | uint32_t *global_crc32_table; | ||
22 | |||
21 | uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) | 23 | uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) |
22 | { | 24 | { |
23 | uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; | 25 | uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; |
@@ -40,3 +42,25 @@ uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) | |||
40 | 42 | ||
41 | return crc_table - 256; | 43 | return crc_table - 256; |
42 | } | 44 | } |
45 | |||
46 | uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) | ||
47 | { | ||
48 | const void *end = (uint8_t*)buf + len; | ||
49 | |||
50 | while (buf != end) { | ||
51 | val = (val << 8) ^ crc_table[(val >> 24) ^ *(uint8_t*)buf]; | ||
52 | buf = (uint8_t*)buf + 1; | ||
53 | } | ||
54 | return val; | ||
55 | } | ||
56 | |||
57 | uint32_t FAST_FUNC crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) | ||
58 | { | ||
59 | const void *end = (uint8_t*)buf + len; | ||
60 | |||
61 | while (buf != end) { | ||
62 | val = crc_table [(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); | ||
63 | buf = (uint8_t*)buf + 1; | ||
64 | } | ||
65 | return val; | ||
66 | } | ||
diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c index 53aad3d52..b832cc1dd 100644 --- a/miscutils/flash_eraseall.c +++ b/miscutils/flash_eraseall.c | |||
@@ -42,15 +42,6 @@ but mtd/jffs2-user.h is gone now (at least 2.6.31.6 does not have it anymore) | |||
42 | #define cpu_to_je16(v) ((jint16_t){(v)}) | 42 | #define cpu_to_je16(v) ((jint16_t){(v)}) |
43 | #define cpu_to_je32(v) ((jint32_t){(v)}) | 43 | #define cpu_to_je32(v) ((jint32_t){(v)}) |
44 | 44 | ||
45 | static uint32_t crc32(uint32_t val, const void *ss, int len, | ||
46 | uint32_t *crc32_table) | ||
47 | { | ||
48 | const unsigned char *s = ss; | ||
49 | while (--len >= 0) | ||
50 | val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8); | ||
51 | return val; | ||
52 | } | ||
53 | |||
54 | static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) | 45 | static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) |
55 | { | 46 | { |
56 | printf("\rErasing %u Kibyte @ %x - %2u%% complete.", | 47 | printf("\rErasing %u Kibyte @ %x - %2u%% complete.", |
@@ -131,8 +122,9 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv) | |||
131 | cleanmarker.totlen = cpu_to_je32(8); | 122 | cleanmarker.totlen = cpu_to_je32(8); |
132 | } | 123 | } |
133 | 124 | ||
134 | cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, sizeof(struct jffs2_unknown_node) - 4, | 125 | cleanmarker.hdr_crc = cpu_to_je32( |
135 | crc32_table)); | 126 | crc32_block_endian0(0, &cleanmarker, sizeof(struct jffs2_unknown_node) - 4, crc32_table) |
127 | ); | ||
136 | } | 128 | } |
137 | 129 | ||
138 | /* Don't want to destroy progress indicator by bb_error_msg's */ | 130 | /* Don't want to destroy progress indicator by bb_error_msg's */ |
diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index 98803ec88..4dfb5b227 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c | |||
@@ -46,8 +46,6 @@ static unsigned int n_parts; | |||
46 | static unsigned int part_array_len; | 46 | static unsigned int part_array_len; |
47 | static unsigned int part_entry_len; | 47 | static unsigned int part_entry_len; |
48 | 48 | ||
49 | static uint32_t *crc32_table; | ||
50 | |||
51 | static inline gpt_partition * | 49 | static inline gpt_partition * |
52 | gpt_part(int i) | 50 | gpt_part(int i) |
53 | { | 51 | { |
@@ -61,12 +59,7 @@ gpt_part(int i) | |||
61 | static uint32_t | 59 | static uint32_t |
62 | gpt_crc32(void *buf, int len) | 60 | gpt_crc32(void *buf, int len) |
63 | { | 61 | { |
64 | uint32_t crc = 0xffffffff; | 62 | return 0xffffffff ^ crc32_block_endian0(0xffffffff, buf, len, global_crc32_table); |
65 | |||
66 | for (; len > 0; len--, buf++) { | ||
67 | crc = crc32_table[(crc ^ *((char *)buf)) & 0xff] ^ (crc >> 8); | ||
68 | } | ||
69 | return crc ^ 0xffffffff; | ||
70 | } | 63 | } |
71 | 64 | ||
72 | static void | 65 | static void |
@@ -160,8 +153,8 @@ check_gpt_label(void) | |||
160 | return 0; | 153 | return 0; |
161 | } | 154 | } |
162 | 155 | ||
163 | if (!crc32_table) { | 156 | if (!global_crc32_table) { |
164 | crc32_table = crc32_filltable(NULL, 0); | 157 | global_crc32_table = crc32_filltable(NULL, 0); |
165 | } | 158 | } |
166 | 159 | ||
167 | crc = SWAP_LE32(gpt_hdr->hdr_crc32); | 160 | crc = SWAP_LE32(gpt_hdr->hdr_crc32); |