diff --git a/common/zlib/ChangeLog b/common/zlib/ChangeLog index b9965157e..f22aabaef 100644 --- a/common/zlib/ChangeLog +++ b/common/zlib/ChangeLog @@ -1,15 +1,6 @@ ChangeLog file for zlib -Changes in 1.2.8.f-Proxmark3 (for Proxmark3 project only) (26 May 2015) -- disable decoding of fixed code blocks in deflate (eliminates the need - to store the fixed tree in RAM or ROM) -- disable generating fixed code blocks in inflate -- look harder for local optimum of consecutive matches and single literals - in inflate. -- stripped down version - unnecessary files from original distribution - are not included - Changes in 1.2.8 (28 Apr 2013) - Update contrib/minizip/iowin32.c for Windows RT [Vollant] - Do not force Z_CONST for C++ diff --git a/common/zlib/README b/common/zlib/README index ace67a512..5ca9d127e 100644 --- a/common/zlib/README +++ b/common/zlib/README @@ -1,12 +1,3 @@ -//----------------------------------------------------------------------------- -// This version of zlib is modified for use within the Proxmark3 project. -// Files from the original distribution which are not required for this -// purpose are not included. All modifications can easily be found -// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED. -// -// The rest of this file consists of the original README content -//----------------------------------------------------------------------------- - ZLIB DATA COMPRESSION LIBRARY zlib 1.2.8 is a general purpose data compression library. All the code is diff --git a/common/zlib/README_proxmark3 b/common/zlib/README_proxmark3 new file mode 100644 index 000000000..d3192f199 --- /dev/null +++ b/common/zlib/README_proxmark3 @@ -0,0 +1,19 @@ +This version of zlib is modified for use within the Proxmark3 project. +Files from the original distribution which are not required for this +purpose are not included. All modifications can easily be found +by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED. + +Current zlib base version is 1.2.8 + + +ChangeLog for Proxmark3 project only +------------------------------------ + +Changes in 1.2.8.f-Proxmark3 (26 May 2015) +- disable decoding of fixed code blocks in deflate (eliminates the need + to store the fixed tree in RAM or ROM) +- disable generating fixed code blocks in inflate +- look harder for local optimum of consecutive matches and single literals + in inflate. +- stripped down version - unnecessary files from original distribution + are not included diff --git a/common/zlib/adler32.c b/common/zlib/adler32.c index f18f4566c..a3e96f949 100644 --- a/common/zlib/adler32.c +++ b/common/zlib/adler32.c @@ -177,3 +177,4 @@ z_off64_t len2; { return adler32_combine_(adler1, adler2, len2); } + diff --git a/common/zlib/deflate.c b/common/zlib/deflate.c index 013f92150..7445d5907 100644 --- a/common/zlib/deflate.c +++ b/common/zlib/deflate.c @@ -52,7 +52,11 @@ #include "deflate.h" const char deflate_copyright[] = +#ifdef ZLIB_PM3_TUNED " deflate 1.2.8.f-Proxmark3 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; +#else + " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; +#endif /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -60,15 +64,6 @@ const char deflate_copyright[] = copyright string in the executable of your product. */ -//----------------------------------------------------------------------------- -// This version of zlib is modified for use within the Proxmark3 project. -// Files from the original distribution which are not required for this -// purpose are not included. All modifications can easily be found -// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED. -//----------------------------------------------------------------------------- - - - /* =========================================================================== * Function prototypes. */ @@ -190,14 +185,14 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ */ #ifdef FASTEST #define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) #else #define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) #endif /* =========================================================================== @@ -1155,7 +1150,7 @@ IPos cur_match; /* current match */ { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ + register Bytef *match; /* matched string */ register int len; /* length of current match */ #ifdef ZLIB_PM3_TUNED int best_len = MIN_MATCH - 1; /* lift the restriction on prev-length */ @@ -1544,21 +1539,21 @@ deflate_state *s; * IN assertion: strstart is set to the end of the current match. */ #define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ - } + _tr_flush_block(s, (s->block_start >= 0L ? \ + (charf *)&s->window[(unsigned)s->block_start] : \ + (charf *)Z_NULL), \ + (ulg)((long)s->strstart - s->block_start), \ + (last)); \ + s->block_start = s->strstart; \ + flush_pending(s->strm); \ + Tracev((stderr,"[FLUSH]")); \ +} /* Same but force premature exit if necessary. */ #define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ - } + FLUSH_BLOCK_ONLY(s, last); \ + if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ +} /* =========================================================================== * Copy without compression as much as possible from the input stream, return @@ -1840,7 +1835,8 @@ int flush; INSERT_STRING(s, s->strstart, hash_head); } - /* Find the longest match, discarding those <= prev_length. */ + /* Find the longest match, discarding those <= prev_length. + */ s->prev_length = s->match_length, s->prev_match = s->match_start; s->match_length = MIN_MATCH - 1; @@ -2054,3 +2050,4 @@ int flush; FLUSH_BLOCK(s, 0); return block_done; } + diff --git a/common/zlib/deflate.h b/common/zlib/deflate.h index 50760d226..1e17b476d 100644 --- a/common/zlib/deflate.h +++ b/common/zlib/deflate.h @@ -303,7 +303,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, int last)); #define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) /* Mapping from a distance to a distance code. dist is the distance - 1 and * must not have side effects. _dist_code[256] and _dist_code[257] are never * used. @@ -321,26 +321,27 @@ extern const uch ZLIB_INTERNAL _dist_code[]; #endif # define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } # define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (length); \ - ush dist = (distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) + flush = _tr_tally(s, distance, length) #endif #endif /* DEFLATE_H */ + diff --git a/common/zlib/inffast.c b/common/zlib/inffast.c index 0cd59d49b..63f3f7d80 100644 --- a/common/zlib/inffast.c +++ b/common/zlib/inffast.c @@ -329,3 +329,4 @@ dodist: */ #endif /* !ASMINF */ + diff --git a/common/zlib/inffast.h b/common/zlib/inffast.h index e5c1aa4ca..131f157a1 100644 --- a/common/zlib/inffast.h +++ b/common/zlib/inffast.h @@ -9,3 +9,4 @@ */ void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); + diff --git a/common/zlib/inffixed.h b/common/zlib/inffixed.h index 35d010097..fec0606fd 100644 --- a/common/zlib/inffixed.h +++ b/common/zlib/inffixed.h @@ -92,3 +92,4 @@ static const code distfix[32] = { {16, 5, 4}, {24, 5, 769}, {20, 5, 49}, {28, 5, 12289}, {18, 5, 13}, {26, 5, 3073}, {22, 5, 193}, {64, 5, 0} }; + diff --git a/common/zlib/inflate.c b/common/zlib/inflate.c index 9e320be27..a5aee5a33 100644 --- a/common/zlib/inflate.c +++ b/common/zlib/inflate.c @@ -80,15 +80,6 @@ * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. */ -//----------------------------------------------------------------------------- -// This version of zlib is modified for use within the Proxmark3 project. -// Files from the original distribution which are not required for this -// purpose are not included. All modifications can easily be found -// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED. -//----------------------------------------------------------------------------- - - - #include "zutil.h" #include "inftrees.h" #include "inflate.h" @@ -1520,3 +1511,4 @@ z_streamp strm; (state->mode == COPY ? state->length : (state->mode == MATCH ? state->was - state->length : 0)); } + diff --git a/common/zlib/inflate.h b/common/zlib/inflate.h index 81e7aadd6..399ccc521 100644 --- a/common/zlib/inflate.h +++ b/common/zlib/inflate.h @@ -120,3 +120,4 @@ struct inflate_state { int back; /* bits back of last unprocessed length/lit */ unsigned was; /* initial length of match */ }; + diff --git a/common/zlib/inftrees.c b/common/zlib/inftrees.c index a3724254f..e5e4f8c4f 100644 --- a/common/zlib/inftrees.c +++ b/common/zlib/inftrees.c @@ -9,7 +9,11 @@ #define MAXBITS 15 const char inflate_copyright[] = +#ifdef ZLIB_PM3_TUNED " inflate 1.2.8.f-Proxmark3 Copyright 1995-2013 Mark Adler "; +#else + " inflate 1.2.8 Copyright 1995-2013 Mark Adler "; +#endif /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -300,3 +304,4 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, *bits = root; return 0; } + diff --git a/common/zlib/inftrees.h b/common/zlib/inftrees.h index 01b1a5d75..33584c58d 100644 --- a/common/zlib/inftrees.h +++ b/common/zlib/inftrees.h @@ -60,3 +60,4 @@ typedef enum { int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)); + diff --git a/common/zlib/trees.c b/common/zlib/trees.c index cc2d477cf..8ffab9c8e 100644 --- a/common/zlib/trees.c +++ b/common/zlib/trees.c @@ -32,16 +32,8 @@ /* @(#) $Id$ */ -//----------------------------------------------------------------------------- -// This version of zlib is modified for use within the Proxmark3 project. -// Files from the original distribution which are not required for this -// purpose are not included. All modifications can easily be found -// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED. -//----------------------------------------------------------------------------- - /* #define GEN_TREES_H */ - #include "deflate.h" #ifdef DEBUG @@ -173,8 +165,8 @@ local void gen_trees_header OF((void)); #else /* DEBUG */ # define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(s, tree[c].Code, tree[c].Len); } #endif /* =========================================================================== @@ -182,9 +174,9 @@ local void gen_trees_header OF((void)); * IN assertion: there is enough room in pendingBuf. */ #define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ - } + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} /* =========================================================================== * Send a value on a given number of bits. @@ -219,18 +211,18 @@ int length; /* number of bits */ #else /* !DEBUG */ #define send_bits(s, value, length) \ - { int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ - } +{ int len = length;\ + if (s->bi_valid > (int)Buf_size - len) {\ + int val = value;\ + s->bi_buf |= (ush)val << s->bi_valid;\ + put_short(s, s->bi_buf);\ + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_valid += len - Buf_size;\ + } else {\ + s->bi_buf |= (ush)(value) << s->bi_valid;\ + s->bi_valid += len;\ + }\ +} #endif /* DEBUG */ @@ -329,8 +321,8 @@ local void tr_static_init() { # endif # define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width)-1 ? ",\n" : ", ")) + ((i) == (last)? "\n};\n\n" : \ + ((i) % (width) == (width)-1 ? ",\n" : ", ")) void gen_trees_header() { FILE *header = fopen("trees.h", "w"); @@ -436,19 +428,19 @@ deflate_state *s; * one less element. Updates heap and heap_len. */ #define pqremove(s, tree, top) \ - {\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ - } +{\ + top = s->heap[SMALLEST]; \ + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ + pqdownheap(s, tree, SMALLEST); \ +} /* =========================================================================== * Compares to subtrees, using the tree depth as tie breaker when * the subtrees have equal frequency. This minimizes the worst case length. */ #define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) /* =========================================================================== * Restore the heap property by moving down the tree starting at node k, @@ -1021,7 +1013,8 @@ int last; /* one if this is the last block for a file */ s->compressed_len += 7; /* align on byte boundary */ #endif } - Tracev((stderr, "\ncomprlen %lu(%lu) ", s->compressed_len >> 3, s->compressed_len - 7 * last)); + Tracev((stderr, "\ncomprlen %lu(%lu) ", s->compressed_len >> 3, + s->compressed_len - 7 * last)); } /* =========================================================================== @@ -1245,3 +1238,4 @@ int header; /* true if block header must be written */ put_byte(s, *buf++); } } + diff --git a/common/zlib/trees.h b/common/zlib/trees.h index a02c374a7..74383d7c2 100644 --- a/common/zlib/trees.h +++ b/common/zlib/trees.h @@ -126,3 +126,4 @@ local const int base_dist[D_CODES] = { 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 }; + diff --git a/common/zlib/zconf.h b/common/zlib/zconf.h index d9bf35455..5230fc94b 100644 --- a/common/zlib/zconf.h +++ b/common/zlib/zconf.h @@ -509,3 +509,4 @@ typedef unsigned long z_crc_t; #endif #endif /* ZCONF_H */ + diff --git a/common/zlib/zlib.h b/common/zlib/zlib.h index 9a8bcce1d..b88bac965 100644 --- a/common/zlib/zlib.h +++ b/common/zlib/zlib.h @@ -28,13 +28,6 @@ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). */ -//----------------------------------------------------------------------------- -// This version of zlib is modified for use within the Proxmark3 project. -// Files from the original distribution which are not required for this -// purpose are not included. All modifications can easily be found -// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED. -//----------------------------------------------------------------------------- - #ifndef ZLIB_H #define ZLIB_H @@ -1663,18 +1656,18 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, const char *version, int stream_size)); #define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) #define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) #define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) #define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) #ifndef Z_SOLO @@ -1694,10 +1687,10 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define z_gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) #else # define gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) #endif /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or @@ -1784,3 +1777,4 @@ ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, #endif #endif /* ZLIB_H */ + diff --git a/common/zlib/zutil.c b/common/zlib/zutil.c index 72d373982..30f453872 100644 --- a/common/zlib/zutil.c +++ b/common/zlib/zutil.c @@ -341,3 +341,4 @@ voidpf ptr; #endif /* MY_ZCALLOC */ #endif /* !Z_SOLO */ + diff --git a/common/zlib/zutil.h b/common/zlib/zutil.h index 1f6bee84e..a421df882 100644 --- a/common/zlib/zutil.h +++ b/common/zlib/zutil.h @@ -50,7 +50,7 @@ extern z_const char *const z_errmsg[10]; /* indexed by 2-zlib_error */ #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_RETURN(strm,err) \ - return (strm->msg = ERR_MSG(err), (err)) + return (strm->msg = ERR_MSG(err), (err)) /* To be used only when the state is known to be valid */ /* common constants */ @@ -104,7 +104,7 @@ void *_Cdecl farmalloc(unsigned long nbytes); #if defined(VAXC) || defined(VMS) # define OS_CODE 0x02 # define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") #endif #if defined(ATARI) || defined(atarist) @@ -242,7 +242,7 @@ void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); #endif #define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) + (*((strm)->zalloc))((strm)->opaque, (items), (size)) #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} @@ -251,3 +251,4 @@ void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) #endif /* ZUTIL_H */ +