diff options
author | Rob Landley <rob@landley.net> | 2006-04-10 17:07:15 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-04-10 17:07:15 +0000 |
commit | c57ec37959390ff2e43faa5e4dd5281b2923ced3 (patch) | |
tree | 8325e7bd6a9a270e931b383d33b5901751dd2a5e /archival/libunarchive | |
parent | 998f4493756423877217239d2cc42eb8b83d50b3 (diff) | |
download | busybox-w32-c57ec37959390ff2e43faa5e4dd5281b2923ced3.tar.gz busybox-w32-c57ec37959390ff2e43faa5e4dd5281b2923ced3.tar.bz2 busybox-w32-c57ec37959390ff2e43faa5e4dd5281b2923ced3.zip |
Patch from Rob Sullivan to consolidate crc32 table generation.
Diffstat (limited to 'archival/libunarchive')
-rw-r--r-- | archival/libunarchive/decompress_bunzip2.c | 15 | ||||
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 42 |
2 files changed, 12 insertions, 45 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c index 3d07d9e03..1879f7255 100644 --- a/archival/libunarchive/decompress_bunzip2.c +++ b/archival/libunarchive/decompress_bunzip2.c | |||
@@ -84,8 +84,8 @@ typedef struct { | |||
84 | 84 | ||
85 | /* The CRC values stored in the block header and calculated from the data */ | 85 | /* The CRC values stored in the block header and calculated from the data */ |
86 | 86 | ||
87 | unsigned int crc32Table[256],headerCRC, totalCRC, writeCRC; | 87 | uint32_t headerCRC, totalCRC, writeCRC; |
88 | 88 | uint32_t *crc32Table; | |
89 | /* Intermediate buffer and its size (in bytes) */ | 89 | /* Intermediate buffer and its size (in bytes) */ |
90 | 90 | ||
91 | unsigned int *dbuf, dbufSize; | 91 | unsigned int *dbuf, dbufSize; |
@@ -620,7 +620,7 @@ decode_next_byte: | |||
620 | bd->writeCount=previous; | 620 | bd->writeCount=previous; |
621 | return (previous!=RETVAL_LAST_BLOCK) ? previous : gotcount; | 621 | return (previous!=RETVAL_LAST_BLOCK) ? previous : gotcount; |
622 | } | 622 | } |
623 | bd->writeCRC=0xffffffffUL; | 623 | bd->writeCRC=~0; |
624 | pos=bd->writePos; | 624 | pos=bd->writePos; |
625 | current=bd->writeCurrent; | 625 | current=bd->writeCurrent; |
626 | goto decode_next_byte; | 626 | goto decode_next_byte; |
@@ -634,7 +634,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf, | |||
634 | int len) | 634 | int len) |
635 | { | 635 | { |
636 | bunzip_data *bd; | 636 | bunzip_data *bd; |
637 | unsigned int i,j,c; | 637 | unsigned int i; |
638 | const unsigned int BZh0=(((unsigned int)'B')<<24)+(((unsigned int)'Z')<<16) | 638 | const unsigned int BZh0=(((unsigned int)'B')<<24)+(((unsigned int)'Z')<<16) |
639 | +(((unsigned int)'h')<<8)+(unsigned int)'0'; | 639 | +(((unsigned int)'h')<<8)+(unsigned int)'0'; |
640 | 640 | ||
@@ -657,12 +657,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf, | |||
657 | 657 | ||
658 | /* Init the CRC32 table (big endian) */ | 658 | /* Init the CRC32 table (big endian) */ |
659 | 659 | ||
660 | for(i=0;i<256;i++) { | 660 | bd->crc32Table = bb_crc32_filltable(1); |
661 | c=i<<24; | ||
662 | for(j=8;j;j--) | ||
663 | c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1); | ||
664 | bd->crc32Table[i]=c; | ||
665 | } | ||
666 | 661 | ||
667 | /* Setup for I/O error handling via longjmp */ | 662 | /* Setup for I/O error handling via longjmp */ |
668 | 663 | ||
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 3215697aa..a589bdcd4 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -95,8 +95,8 @@ static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ | |||
95 | enum { gunzip_wsize = 0x8000 }; | 95 | enum { gunzip_wsize = 0x8000 }; |
96 | static unsigned char *gunzip_window; | 96 | static unsigned char *gunzip_window; |
97 | 97 | ||
98 | static unsigned int *gunzip_crc_table; | 98 | static uint32_t *gunzip_crc_table; |
99 | unsigned int gunzip_crc; | 99 | uint32_t gunzip_crc; |
100 | 100 | ||
101 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ | 101 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ |
102 | #define BMAX 16 /* maximum bit length of any code (16 for explode) */ | 102 | #define BMAX 16 /* maximum bit length of any code (16 for explode) */ |
@@ -168,35 +168,6 @@ static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current | |||
168 | return(bitbuffer); | 168 | return(bitbuffer); |
169 | } | 169 | } |
170 | 170 | ||
171 | static void make_gunzip_crc_table(void) | ||
172 | { | ||
173 | const unsigned int poly = 0xedb88320; /* polynomial exclusive-or pattern */ | ||
174 | unsigned short i; /* counter for all possible eight bit values */ | ||
175 | |||
176 | /* initial shift register value */ | ||
177 | gunzip_crc = 0xffffffffL; | ||
178 | gunzip_crc_table = (unsigned int *) xmalloc(256 * sizeof(unsigned int)); | ||
179 | |||
180 | /* Compute and print table of CRC's, five per line */ | ||
181 | for (i = 0; i < 256; i++) { | ||
182 | unsigned int table_entry; /* crc shift register */ | ||
183 | unsigned char k; /* byte being shifted into crc apparatus */ | ||
184 | |||
185 | table_entry = i; | ||
186 | /* The idea to initialize the register with the byte instead of | ||
187 | * zero was stolen from Haruhiko Okumura's ar002 | ||
188 | */ | ||
189 | for (k = 8; k; k--) { | ||
190 | if (table_entry & 1) { | ||
191 | table_entry = (table_entry >> 1) ^ poly; | ||
192 | } else { | ||
193 | table_entry >>= 1; | ||
194 | } | ||
195 | } | ||
196 | gunzip_crc_table[i] = table_entry; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /* | 171 | /* |
201 | * Free the malloc'ed tables built by huft_build(), which makes a linked | 172 | * Free the malloc'ed tables built by huft_build(), which makes a linked |
202 | * list of the tables it made, with the links in a dummy first entry of | 173 | * list of the tables it made, with the links in a dummy first entry of |
@@ -922,8 +893,9 @@ int inflate_unzip(int in, int out) | |||
922 | gunzip_bb = 0; | 893 | gunzip_bb = 0; |
923 | 894 | ||
924 | /* Create the crc table */ | 895 | /* Create the crc table */ |
925 | make_gunzip_crc_table(); | 896 | gunzip_crc_table = bb_crc32_filltable(0); |
926 | 897 | gunzip_crc = ~0; | |
898 | |||
927 | /* Allocate space for buffer */ | 899 | /* Allocate space for buffer */ |
928 | bytebuffer = xmalloc(bytebuffer_max); | 900 | bytebuffer = xmalloc(bytebuffer_max); |
929 | 901 | ||
@@ -955,7 +927,7 @@ int inflate_unzip(int in, int out) | |||
955 | 927 | ||
956 | int inflate_gunzip(int in, int out) | 928 | int inflate_gunzip(int in, int out) |
957 | { | 929 | { |
958 | unsigned int stored_crc = 0; | 930 | uint32_t stored_crc = 0; |
959 | unsigned int count; | 931 | unsigned int count; |
960 | 932 | ||
961 | inflate_unzip(in, out); | 933 | inflate_unzip(in, out); |
@@ -972,7 +944,7 @@ int inflate_gunzip(int in, int out) | |||
972 | } | 944 | } |
973 | 945 | ||
974 | /* Validate decompression - crc */ | 946 | /* Validate decompression - crc */ |
975 | if (stored_crc != (gunzip_crc ^ 0xffffffffL)) { | 947 | if (stored_crc != (~gunzip_crc)) { |
976 | bb_error_msg("crc error"); | 948 | bb_error_msg("crc error"); |
977 | return -1; | 949 | return -1; |
978 | } | 950 | } |