summaryrefslogtreecommitdiffabout
path: root/pwmanager/libcrypt/zlib
authorzautrix <zautrix>2004-10-19 20:16:14 (UTC)
committer zautrix <zautrix>2004-10-19 20:16:14 (UTC)
commiteca49bb06a71980ef61d078904573f25890fc7f2 (patch) (unidiff)
treec5338e3b12430248979a9ac2c1c7e6646ea9ecdf /pwmanager/libcrypt/zlib
parent53cc32b6e7b1f672bf91b2baf2df6c1e8baf3e0a (diff)
downloadkdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.zip
kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.tar.gz
kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.tar.bz2
Initial revision
Diffstat (limited to 'pwmanager/libcrypt/zlib') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/libcrypt/zlib/ChangeLog505
-rw-r--r--pwmanager/libcrypt/zlib/README148
-rw-r--r--pwmanager/libcrypt/zlib/adler32.c48
-rw-r--r--pwmanager/libcrypt/zlib/algorithm.doc105
-rw-r--r--pwmanager/libcrypt/zlib/compress.c68
-rw-r--r--pwmanager/libcrypt/zlib/crc32.c163
-rw-r--r--pwmanager/libcrypt/zlib/deflate.c1350
-rw-r--r--pwmanager/libcrypt/zlib/deflate.h318
-rw-r--r--pwmanager/libcrypt/zlib/infblock.c403
-rw-r--r--pwmanager/libcrypt/zlib/infblock.h39
-rw-r--r--pwmanager/libcrypt/zlib/infcodes.c251
-rw-r--r--pwmanager/libcrypt/zlib/infcodes.h27
-rw-r--r--pwmanager/libcrypt/zlib/inffast.c183
-rw-r--r--pwmanager/libcrypt/zlib/inffast.h17
-rw-r--r--pwmanager/libcrypt/zlib/inffixed.h151
-rw-r--r--pwmanager/libcrypt/zlib/inflate.c366
-rw-r--r--pwmanager/libcrypt/zlib/inftrees.c454
-rw-r--r--pwmanager/libcrypt/zlib/inftrees.h58
-rw-r--r--pwmanager/libcrypt/zlib/infutil.c87
-rw-r--r--pwmanager/libcrypt/zlib/infutil.h98
-rw-r--r--pwmanager/libcrypt/zlib/trees.c1214
-rw-r--r--pwmanager/libcrypt/zlib/trees.h128
-rw-r--r--pwmanager/libcrypt/zlib/uncompr.c58
-rw-r--r--pwmanager/libcrypt/zlib/zconf.h279
-rw-r--r--pwmanager/libcrypt/zlib/zlib.h893
-rw-r--r--pwmanager/libcrypt/zlib/zlib.pro36
-rw-r--r--pwmanager/libcrypt/zlib/zutil.c225
-rw-r--r--pwmanager/libcrypt/zlib/zutil.h220
28 files changed, 7892 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/zlib/ChangeLog b/pwmanager/libcrypt/zlib/ChangeLog
new file mode 100644
index 0000000..5f06bcc
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/ChangeLog
@@ -0,0 +1,505 @@
12002-03-12 Werner Koch <wk@gnupg.org>
2
3 Merged changes from zlib 1.1.4.
4
5Sat Feb 13 12:04:43 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
6
7 * Makefile.am: Removed -Wall
8
9Wed Jan 20 21:40:21 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
10
11 * Makefile.am: Corrected the list of sources
12
13Wed Jan 13 14:10:15 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
14
15 Merged version 1.1.3 with the previousy used 1.0.4
16
17Thu Feb 12 12:20:45 1998 Werner Koch (wk@frodo)
18
19 Removed a couple of files, as this is only used if zlib is
20 missing on a system. Added automake stuff
21
22
23 ChangeLog file for zlib
24
25
26Changes in 1.1.4 (11 March 2002)
27- ZFREE was repeated on same allocation on some error conditions.
28 This creates a security problem described in
29 http://www.zlib.org/advisory-2002-03-11.txt
30- Returned incorrect error (Z_MEM_ERROR) on some invalid data
31- Avoid accesses before window for invalid distances with inflate window
32 less than 32K.
33- force windowBits > 8 to avoid a bug in the encoder for a window size
34 of 256 bytes. (A complete fix will be available in 1.1.5).
35
36Changes in 1.1.3 (9 July 1998)
37- fix "an inflate input buffer bug that shows up on rare but persistent
38 occasions" (Mark)
39- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
40- fix gzseek(..., SEEK_SET) in write mode
41- fix crc check after a gzeek (Frank Faubert)
42- fix miniunzip when the last entry in a zip file is itself a zip file
43 (J Lillge)
44- add contrib/asm586 and contrib/asm686 (Brian Raiter)
45 See http://www.muppetlabs.com/~breadbox/software/assembly.html
46- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
47- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
48- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
49- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
50- added a FAQ file
51
52- Support gzdopen on Mac with Metrowerks (Jason Linhart)
53- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
54- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
55- avoid some warnings with Borland C (Tom Tanner)
56- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
57- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
58- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
59- use libdir and includedir in Makefile.in (Tim Mooney)
60- support shared libraries on OSF1 V4 (Tim Mooney)
61- remove so_locations in "make clean" (Tim Mooney)
62- fix maketree.c compilation error (Glenn, Mark)
63- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
64- new Makefile.riscos (Rich Walker)
65- initialize static descriptors in trees.c for embedded targets (Nick Smith)
66- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
67- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
68- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
69- fix maketree.c to allow clean compilation of inffixed.h (Mark)
70- fix parameter check in deflateCopy (Gunther Nikl)
71- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
72- Many portability patches by Christian Spieler:
73 . zutil.c, zutil.h: added "const" for zmem*
74 . Make_vms.com: fixed some typos
75 . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
76 . msdos/Makefile.msc: remove "default rtl link library" info from obj files
77 . msdos/Makefile.*: use model-dependent name for the built zlib library
78 . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
79 new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
80- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
81- replace __far with _far for better portability (Christian Spieler, Tom Lane)
82- fix test for errno.h in configure (Tim Newsham)
83
84Changes in 1.1.2 (19 March 98)
85- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
86 See http://www.winimage.com/zLibDll/unzip.html
87- preinitialize the inflate tables for fixed codes, to make the code
88 completely thread safe (Mark)
89- some simplifications and slight speed-up to the inflate code (Mark)
90- fix gzeof on non-compressed files (Allan Schrum)
91- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
92- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
93- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
94- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
95- do not wrap extern "C" around system includes (Tom Lane)
96- mention zlib binding for TCL in README (Andreas Kupries)
97- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
98- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
99- allow "configure --prefix $HOME" (Tim Mooney)
100- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
101- move Makefile.sas to amiga/Makefile.sas
102
103Changes in 1.1.1 (27 Feb 98)
104- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
105- remove block truncation heuristic which had very marginal effect for zlib
106 (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
107 compression ratio on some files. This also allows inlining _tr_tally for
108 matches in deflate_slow.
109- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
110
111Changes in 1.1.0 (24 Feb 98)
112- do not return STREAM_END prematurely in inflate (John Bowler)
113- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
114- compile with -DFASTEST to get compression code optimized for speed only
115- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
116- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
117 on Sun but significant on HP)
118
119- add a pointer to experimental unzip library in README (Gilles Vollant)
120- initialize variable gcc in configure (Chris Herborth)
121
122Changes in 1.0.9 (17 Feb 1998)
123- added gzputs and gzgets functions
124- do not clear eof flag in gzseek (Mark Diekhans)
125- fix gzseek for files in transparent mode (Mark Diekhans)
126- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
127- replace EXPORT with ZEXPORT to avoid conflict with other programs
128- added compress2 in zconf.h, zlib.def, zlib.dnt
129- new asm code from Gilles Vollant in contrib/asm386
130- simplify the inflate code (Mark):
131 . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
132 . ZALLOC the length list in inflate_trees_fixed() instead of using stack
133 . ZALLOC the value area for huft_build() instead of using stack
134 . Simplify Z_FINISH check in inflate()
135
136- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
137- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
138- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
139 the declaration of FAR (Gilles VOllant)
140- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
141- read_buf buf parameter of type Bytef* instead of charf*
142- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
143- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
144- fix check for presence of directories in "make install" (Ian Willis)
145
146Changes in 1.0.8 (27 Jan 1998)
147- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
148- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
149- added compress2() to allow setting the compression level
150- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
151- use constant arrays for the static trees in trees.c instead of computing
152 them at run time (thanks to Ken Raeburn for this suggestion). To create
153 trees.h, compile with GEN_TREES_H and run "make test".
154- check return code of example in "make test" and display result
155- pass minigzip command line options to file_compress
156- simplifying code of inflateSync to avoid gcc 2.8 bug
157
158- support CC="gcc -Wall" in configure -s (QingLong)
159- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
160- fix test for shared library support to avoid compiler warnings
161- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
162- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
163- do not use fdopen for Metrowerks on Mac (Brad Pettit))
164- add checks for gzputc and gzputc in example.c
165- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
166- use const for the CRC table (Ken Raeburn)
167- fixed "make uninstall" for shared libraries
168- use Tracev instead of Trace in infblock.c
169- in example.c use correct compressed length for test_sync
170- suppress +vnocompatwarnings in configure for HPUX (not always supported)
171
172Changes in 1.0.7 (20 Jan 1998)
173- fix gzseek which was broken in write mode
174- return error for gzseek to negative absolute position
175- fix configure for Linux (Chun-Chung Chen)
176- increase stack space for MSC (Tim Wegner)
177- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
178- define EXPORTVA for gzprintf (Gilles Vollant)
179- added man page zlib.3 (Rick Rodgers)
180- for contrib/untgz, fix makedir() and improve Makefile
181
182- check gzseek in write mode in example.c
183- allocate extra buffer for seeks only if gzseek is actually called
184- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
185- add inflateSyncPoint in zconf.h
186- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
187
188Changes in 1.0.6 (19 Jan 1998)
189- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
190 gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
191- Fix a deflate bug occuring only with compression level 0 (thanks to
192 Andy Buckler for finding this one).
193- In minigzip, pass transparently also the first byte for .Z files.
194- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
195- check Z_FINISH in inflate (thanks to Marc Schluper)
196- Implement deflateCopy (thanks to Adam Costello)
197- make static libraries by default in configure, add --shared option.
198- move MSDOS or Windows specific files to directory msdos
199- suppress the notion of partial flush to simplify the interface
200 (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
201- suppress history buffer provided by application to simplify the interface
202 (this feature was not implemented anyway in 1.0.4)
203- next_in and avail_in must be initialized before calling inflateInit or
204 inflateInit2
205- add EXPORT in all exported functions (for Windows DLL)
206- added Makefile.nt (thanks to Stephen Williams)
207- added the unsupported "contrib" directory:
208 contrib/asm386/ by Gilles Vollant <info@winimage.com>
209 386 asm code replacing longest_match().
210 contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
211 A C++ I/O streams interface to the zlib gz* functions
212 contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
213 Another C++ I/O streams interface
214 contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
215 A very simple tar.gz file extractor using zlib
216 contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
217 How to use compress(), uncompress() and the gz* functions from VB.
218- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
219 level) in minigzip (thanks to Tom Lane)
220
221- use const for rommable constants in deflate
222- added test for gzseek and gztell in example.c
223- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
224- add undocumented function zError to convert error code to string
225 (for Tim Smithers)
226- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
227- Use default memcpy for Symantec MSDOS compiler.
228- Add EXPORT keyword for check_func (needed for Windows DLL)
229- add current directory to LD_LIBRARY_PATH for "make test"
230- create also a link for libz.so.1
231- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
232- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
233- added -soname for Linux in configure (Chun-Chung Chen,
234- assign numbers to the exported functions in zlib.def (for Windows DLL)
235- add advice in zlib.h for best usage of deflateSetDictionary
236- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
237- allow compilation with ANSI keywords only enabled for TurboC in large model
238- avoid "versionString"[0] (Borland bug)
239- add NEED_DUMMY_RETURN for Borland
240- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
241- allow compilation with CC
242- defined STDC for OS/2 (David Charlap)
243- limit external names to 8 chars for MVS (Thomas Lund)
244- in minigzip.c, use static buffers only for 16-bit systems
245- fix suffix check for "minigzip -d foo.gz"
246- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
247- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
248- added makelcc.bat for lcc-win32 (Tom St Denis)
249- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
250- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
251- check for unistd.h in configure (for off_t)
252- remove useless check parameter in inflate_blocks_free
253- avoid useless assignment of s->check to itself in inflate_blocks_new
254- do not flush twice in gzclose (thanks to Ken Raeburn)
255- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
256- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
257- work around buggy fclose on pipes for HP/UX
258- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
259- fix configure if CC is already equal to gcc
260
261Changes in 1.0.5 (3 Jan 98)
262- Fix inflate to terminate gracefully when fed corrupted or invalid data
263- Use const for rommable constants in inflate
264- Eliminate memory leaks on error conditions in inflate
265- Removed some vestigial code in inflate
266- Update web address in README
267
268Changes in 1.0.4 (24 Jul 96)
269- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
270 bit, so the decompressor could decompress all the correct data but went
271 on to attempt decompressing extra garbage data. This affected minigzip too.
272- zlibVersion and gzerror return const char* (needed for DLL)
273- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
274- use z_error only for DEBUG (avoid problem with DLLs)
275
276Changes in 1.0.3 (2 Jul 96)
277- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
278 small and medium models; this makes the library incompatible with previous
279 versions for these models. (No effect in large model or on other systems.)
280- return OK instead of BUF_ERROR if previous deflate call returned with
281 avail_out as zero but there is nothing to do
282- added memcmp for non STDC compilers
283- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
284- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
285- better check for 16-bit mode MSC (avoids problem with Symantec)
286
287Changes in 1.0.2 (23 May 96)
288- added Windows DLL support
289- added a function zlibVersion (for the DLL support)
290- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
291- Bytef is define's instead of typedef'd only for Borland C
292- avoid reading uninitialized memory in example.c
293- mention in README that the zlib format is now RFC1950
294- updated Makefile.dj2
295- added algorithm.doc
296
297Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
298- fix array overlay in deflate.c which sometimes caused bad compressed data
299- fix inflate bug with empty stored block
300- fix MSDOS medium model which was broken in 0.99
301- fix deflateParams() which could generated bad compressed data.
302- Bytef is define'd instead of typedef'ed (work around Borland bug)
303- added an INDEX file
304- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
305 Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
306- speed up adler32 for modern machines without auto-increment
307- added -ansi for IRIX in configure
308- static_init_done in trees.c is an int
309- define unlink as delete for VMS
310- fix configure for QNX
311- add configure branch for SCO and HPUX
312- avoid many warnings (unused variables, dead assignments, etc...)
313- no fdopen for BeOS
314- fix the Watcom fix for 32 bit mode (define FAR as empty)
315- removed redefinition of Byte for MKWERKS
316- work around an MWKERKS bug (incorrect merge of all .h files)
317
318Changes in 0.99 (27 Jan 96)
319- allow preset dictionary shared between compressor and decompressor
320- allow compression level 0 (no compression)
321- add deflateParams in zlib.h: allow dynamic change of compression level
322 and compression strategy.
323- test large buffers and deflateParams in example.c
324- add optional "configure" to build zlib as a shared library
325- suppress Makefile.qnx, use configure instead
326- fixed deflate for 64-bit systems (detected on Cray)
327- fixed inflate_blocks for 64-bit systems (detected on Alpha)
328- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
329- always return Z_BUF_ERROR when deflate() has nothing to do
330- deflateInit and inflateInit are now macros to allow version checking
331- prefix all global functions and types with z_ with -DZ_PREFIX
332- make falloc completely reentrant (inftrees.c)
333- fixed very unlikely race condition in ct_static_init
334- free in reverse order of allocation to help memory manager
335- use zlib-1.0/* instead of zlib/* inside the tar.gz
336- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
337 -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
338- allow gzread on concatenated .gz files
339- deflateEnd now returns Z_DATA_ERROR if it was premature
340- deflate is finally (?) fully deterministic (no matches beyond end of input)
341- Document Z_SYNC_FLUSH
342- add uninstall in Makefile
343- Check for __cpluplus in zlib.h
344- Better test in ct_align for partial flush
345- avoid harmless warnings for Borland C++
346- initialize hash_head in deflate.c
347- avoid warning on fdopen (gzio.c) for HP cc -Aa
348- include stdlib.h for STDC compilers
349- include errno.h for Cray
350- ignore error if ranlib doesn't exist
351- call ranlib twice for NeXTSTEP
352- use exec_prefix instead of prefix for libz.a
353- renamed ct_* as _tr_* to avoid conflict with applications
354- clear z->msg in inflateInit2 before any error return
355- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
356- fixed typo in zconf.h (_GNUC__ => __GNUC__)
357- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
358- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
359- in fcalloc, normalize pointer if size > 65520 bytes
360- don't use special fcalloc for 32 bit Borland C++
361- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
362- use Z_BINARY instead of BINARY
363- document that gzclose after gzdopen will close the file
364- allow "a" as mode in gzopen.
365- fix error checking in gzread
366- allow skipping .gz extra-field on pipes
367- added reference to Perl interface in README
368- put the crc table in FAR data (I dislike more and more the medium model :)
369- added get_crc_table
370- added a dimension to all arrays (Borland C can't count).
371- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
372- guard against multiple inclusion of *.h (for precompiled header on Mac)
373- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
374- don't use unsized arrays to avoid silly warnings by Visual C++:
375 warning C4746: 'inflate_mask' : unsized array treated as '__far'
376 (what's wrong with far data in far model?).
377- define enum out of inflate_blocks_state to allow compilation with C++
378
379Changes in 0.95 (16 Aug 95)
380- fix MSDOS small and medium model (now easier to adapt to any compiler)
381- inlined send_bits
382- fix the final (:-) bug for deflate with flush (output was correct but
383 not completely flushed in rare occasions).
384- default window size is same for compression and decompression
385 (it's now sufficient to set MAX_WBITS in zconf.h).
386- voidp -> voidpf and voidnp -> voidp (for consistency with other
387 typedefs and because voidnp was not near in large model).
388
389Changes in 0.94 (13 Aug 95)
390- support MSDOS medium model
391- fix deflate with flush (could sometimes generate bad output)
392- fix deflateReset (zlib header was incorrectly suppressed)
393- added support for VMS
394- allow a compression level in gzopen()
395- gzflush now calls fflush
396- For deflate with flush, flush even if no more input is provided.
397- rename libgz.a as libz.a
398- avoid complex expression in infcodes.c triggering Turbo C bug
399- work around a problem with gcc on Alpha (in INSERT_STRING)
400- don't use inline functions (problem with some gcc versions)
401- allow renaming of Byte, uInt, etc... with #define.
402- avoid warning about (unused) pointer before start of array in deflate.c
403- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
404- avoid reserved word 'new' in trees.c
405
406Changes in 0.93 (25 June 95)
407- temporarily disable inline functions
408- make deflate deterministic
409- give enough lookahead for PARTIAL_FLUSH
410- Set binary mode for stdin/stdout in minigzip.c for OS/2
411- don't even use signed char in inflate (not portable enough)
412- fix inflate memory leak for segmented architectures
413
414Changes in 0.92 (3 May 95)
415- don't assume that char is signed (problem on SGI)
416- Clear bit buffer when starting a stored block
417- no memcpy on Pyramid
418- suppressed inftest.c
419- optimized fill_window, put longest_match inline for gcc
420- optimized inflate on stored blocks.
421- untabify all sources to simplify patches
422
423Changes in 0.91 (2 May 95)
424- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
425- Document the memory requirements in zconf.h
426- added "make install"
427- fix sync search logic in inflateSync
428- deflate(Z_FULL_FLUSH) now works even if output buffer too short
429- after inflateSync, don't scare people with just "lo world"
430- added support for DJGPP
431
432Changes in 0.9 (1 May 95)
433- don't assume that zalloc clears the allocated memory (the TurboC bug
434 was Mark's bug after all :)
435- let again gzread copy uncompressed data unchanged (was working in 0.71)
436- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
437- added a test of inflateSync in example.c
438- moved MAX_WBITS to zconf.h because users might want to change that.
439- document explicitly that zalloc(64K) on MSDOS must return a normalized
440 pointer (zero offset)
441- added Makefiles for Microsoft C, Turbo C, Borland C++
442- faster crc32()
443
444Changes in 0.8 (29 April 95)
445- added fast inflate (inffast.c)
446- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
447 is incompatible with previous versions of zlib which returned Z_OK.
448- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
449 (actually that was not a compiler bug, see 0.81 above)
450- gzread no longer reads one extra byte in certain cases
451- In gzio destroy(), don't reference a freed structure
452- avoid many warnings for MSDOS
453- avoid the ERROR symbol which is used by MS Windows
454
455Changes in 0.71 (14 April 95)
456- Fixed more MSDOS compilation problems :( There is still a bug with
457 TurboC large model.
458
459Changes in 0.7 (14 April 95)
460- Added full inflate support.
461- Simplified the crc32() interface. The pre- and post-conditioning
462 (one's complement) is now done inside crc32(). WARNING: this is
463 incompatible with previous versions; see zlib.h for the new usage.
464
465Changes in 0.61 (12 April 95)
466- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
467
468Changes in 0.6 (11 April 95)
469- added minigzip.c
470- added gzdopen to reopen a file descriptor as gzFile
471- added transparent reading of non-gziped files in gzread.
472- fixed bug in gzread (don't read crc as data)
473- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
474- don't allocate big arrays in the stack (for MSDOS)
475- fix some MSDOS compilation problems
476
477Changes in 0.5:
478- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
479 not yet Z_FULL_FLUSH.
480- support decompression but only in a single step (forced Z_FINISH)
481- added opaque object for zalloc and zfree.
482- added deflateReset and inflateReset
483- added a variable zlib_version for consistency checking.
484- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
485 Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
486
487Changes in 0.4:
488- avoid "zip" everywhere, use zlib instead of ziplib.
489- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
490 if compression method == 8.
491- added adler32 and crc32
492- renamed deflateOptions as deflateInit2, call one or the other but not both
493- added the method parameter for deflateInit2.
494- added inflateInit2
495- simplied considerably deflateInit and inflateInit by not supporting
496 user-provided history buffer. This is supported only in deflateInit2
497 and inflateInit2.
498
499Changes in 0.3:
500- prefix all macro names with Z_
501- use Z_FINISH instead of deflateEnd to finish compression.
502- added Z_HUFFMAN_ONLY
503- added gzerror()
504
505
diff --git a/pwmanager/libcrypt/zlib/README b/pwmanager/libcrypt/zlib/README
new file mode 100644
index 0000000..8ff4587
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/README
@@ -0,0 +1,148 @@
1zlib 1.1.3 is a general purpose data compression library. All the code
2is thread safe. The data format used by the zlib library
3is described by RFCs (Request for Comments) 1950 to 1952 in the files
4ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
5format) and rfc1952.txt (gzip format). These documents are also available in
6other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
7
8All functions of the compression library are documented in the file zlib.h
9(volunteer to write man pages welcome, contact jloup@gzip.org). A usage
10example of the library is given in the file example.c which also tests that
11the library is working correctly. Another example is given in the file
12minigzip.c. The compression library itself is composed of all source files
13except example.c and minigzip.c.
14
15To compile all files and run the test program, follow the instructions
16given at the top of Makefile. In short "make test; make install"
17should work for most machines. For Unix: "configure; make test; make install"
18For MSDOS, use one of the special makefiles such as Makefile.msc.
19For VMS, use Make_vms.com or descrip.mms.
20
21Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov>, or to
22Gilles Vollant <info@winimage.com> for the Windows DLL version.
23The zlib home page is http://www.cdrom.com/pub/infozip/zlib/
24The official zlib ftp site is ftp://ftp.cdrom.com/pub/infozip/zlib/
25Before reporting a problem, please check those sites to verify that
26you have the latest version of zlib; otherwise get the latest version and
27check whether the problem still exists or not.
28
29Mark Nelson <markn@tiny.com> wrote an article about zlib for the Jan. 1997
30issue of Dr. Dobb's Journal; a copy of the article is available in
31http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
32
33The changes made in version 1.1.3 are documented in the file ChangeLog.
34The main changes since 1.1.2 are:
35
36- fix "an inflate input buffer bug that shows up on rare but persistent
37 occasions" (Mark)
38- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
39- fix gzseek(..., SEEK_SET) in write mode
40- fix crc check after a gzeek (Frank Faubert)
41- fix miniunzip when the last entry in a zip file is itself a zip file
42 (J Lillge)
43- add contrib/asm586 and contrib/asm686 (Brian Raiter)
44 See http://www.muppetlabs.com/~breadbox/software/assembly.html
45- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
46- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
47- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
48- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
49- added a FAQ file
50
51plus many changes for portability.
52
53Unsupported third party contributions are provided in directory "contrib".
54
55A Java implementation of zlib is available in the Java Development Kit 1.1
56http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
57See the zlib home page http://www.cdrom.com/pub/infozip/zlib/ for details.
58
59A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk>
60is in the CPAN (Comprehensive Perl Archive Network) sites, such as:
61ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
62
63A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
64is available in Python 1.5 and later versions, see
65http://www.python.org/doc/lib/module-zlib.html
66
67A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com>
68is availlable at http://www.westend.com/~kupries/doc/trf/man/man.html
69
70An experimental package to read and write files in .zip format,
71written on top of zlib by Gilles Vollant <info@winimage.com>, is
72available at http://www.winimage.com/zLibDll/unzip.html
73and also in the contrib/minizip directory of zlib.
74
75
76Notes for some targets:
77
78- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
79 and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL
80 The zlib DLL support was initially done by Alessandro Iacopetti and is
81 now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL
82 home page at http://www.winimage.com/zLibDll
83
84 From Visual Basic, you can call the DLL functions which do not take
85 a structure as argument: compress, uncompress and all gz* functions.
86 See contrib/visual-basic.txt for more information, or get
87 http://www.tcfb.com/dowseware/cmp-z-it.zip
88
89- For 64-bit Irix, deflate.c must be compiled without any optimization.
90 With -O, one libpng test fails. The test works in 32 bit mode (with
91 the -n32 compiler flag). The compiler bug has been reported to SGI.
92
93- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1
94 it works when compiled with cc.
95
96- on Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1
97 is necessary to get gzprintf working correctly. This is done by configure.
98
99- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works
100 with other compilers. Use "make test" to check your compiler.
101
102- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
103
104- For Turbo C the small model is supported only with reduced performance to
105 avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
106
107- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html
108 Per Harald Myrvang <perm@stud.cs.uit.no>
109
110
111Acknowledgments:
112
113 The deflate format used by zlib was defined by Phil Katz. The deflate
114 and zlib specifications were written by L. Peter Deutsch. Thanks to all the
115 people who reported problems and suggested various improvements in zlib;
116 they are too numerous to cite here.
117
118Copyright notice:
119
120 (C) 1995-1998 Jean-loup Gailly and Mark Adler
121
122 This software is provided 'as-is', without any express or implied
123 warranty. In no event will the authors be held liable for any damages
124 arising from the use of this software.
125
126 Permission is granted to anyone to use this software for any purpose,
127 including commercial applications, and to alter it and redistribute it
128 freely, subject to the following restrictions:
129
130 1. The origin of this software must not be misrepresented; you must not
131 claim that you wrote the original software. If you use this software
132 in a product, an acknowledgment in the product documentation would be
133 appreciated but is not required.
134 2. Altered source versions must be plainly marked as such, and must not be
135 misrepresented as being the original software.
136 3. This notice may not be removed or altered from any source distribution.
137
138 Jean-loup Gailly Mark Adler
139 jloup@gzip.org madler@alumni.caltech.edu
140
141If you use the zlib library in a product, we would appreciate *not*
142receiving lengthy legal documents to sign. The sources are provided
143for free but without warranty of any kind. The library has been
144entirely written by Jean-loup Gailly and Mark Adler; it does not
145include third-party code.
146
147If you redistribute modified sources, we would appreciate that you include
148in the file ChangeLog history information documenting your changes.
diff --git a/pwmanager/libcrypt/zlib/adler32.c b/pwmanager/libcrypt/zlib/adler32.c
new file mode 100644
index 0000000..fae88b6
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/adler32.c
@@ -0,0 +1,48 @@
1/* adler32.c -- compute the Adler-32 checksum of a data stream
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zlib.h"
9
10#define BASE 65521L /* largest prime smaller than 65536 */
11#define NMAX 5552
12/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
13
14#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
15#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
16#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
17#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
18#define DO16(buf) DO8(buf,0); DO8(buf,8);
19
20/* ========================================================================= */
21uLong ZEXPORT adler32(adler, buf, len)
22 uLong adler;
23 const Bytef *buf;
24 uInt len;
25{
26 unsigned long s1 = adler & 0xffff;
27 unsigned long s2 = (adler >> 16) & 0xffff;
28 int k;
29
30 if (buf == Z_NULL) return 1L;
31
32 while (len > 0) {
33 k = len < NMAX ? len : NMAX;
34 len -= k;
35 while (k >= 16) {
36 DO16(buf);
37 buf += 16;
38 k -= 16;
39 }
40 if (k != 0) do {
41 s1 += *buf++;
42 s2 += s1;
43 } while (--k);
44 s1 %= BASE;
45 s2 %= BASE;
46 }
47 return (s2 << 16) | s1;
48}
diff --git a/pwmanager/libcrypt/zlib/algorithm.doc b/pwmanager/libcrypt/zlib/algorithm.doc
new file mode 100644
index 0000000..01902af
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/algorithm.doc
@@ -0,0 +1,105 @@
11. Compression algorithm (deflate)
2
3The deflation algorithm used by zlib (also zip and gzip) is a variation of
4LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
5the input data. The second occurrence of a string is replaced by a
6pointer to the previous string, in the form of a pair (distance,
7length). Distances are limited to 32K bytes, and lengths are limited
8to 258 bytes. When a string does not occur anywhere in the previous
932K bytes, it is emitted as a sequence of literal bytes. (In this
10description, `string' must be taken as an arbitrary sequence of bytes,
11and is not restricted to printable characters.)
12
13Literals or match lengths are compressed with one Huffman tree, and
14match distances are compressed with another tree. The trees are stored
15in a compact form at the start of each block. The blocks can have any
16size (except that the compressed data for one block must fit in
17available memory). A block is terminated when deflate() determines that
18it would be useful to start another block with fresh trees. (This is
19somewhat similar to the behavior of LZW-based _compress_.)
20
21Duplicated strings are found using a hash table. All input strings of
22length 3 are inserted in the hash table. A hash index is computed for
23the next 3 bytes. If the hash chain for this index is not empty, all
24strings in the chain are compared with the current input string, and
25the longest match is selected.
26
27The hash chains are searched starting with the most recent strings, to
28favor small distances and thus take advantage of the Huffman encoding.
29The hash chains are singly linked. There are no deletions from the
30hash chains, the algorithm simply discards matches that are too old.
31
32To avoid a worst-case situation, very long hash chains are arbitrarily
33truncated at a certain length, determined by a runtime option (level
34parameter of deflateInit). So deflate() does not always find the longest
35possible match but generally finds a match which is long enough.
36
37deflate() also defers the selection of matches with a lazy evaluation
38mechanism. After a match of length N has been found, deflate() searches for a
39longer match at the next input byte. If a longer match is found, the
40previous match is truncated to a length of one (thus producing a single
41literal byte) and the longer match is emitted afterwards. Otherwise,
42the original match is kept, and the next match search is attempted only
43N steps later.
44
45The lazy match evaluation is also subject to a runtime parameter. If
46the current match is long enough, deflate() reduces the search for a longer
47match, thus speeding up the whole process. If compression ratio is more
48important than speed, deflate() attempts a complete second search even if
49the first match is already long enough.
50
51The lazy match evaluation is not performed for the fastest compression
52modes (level parameter 1 to 3). For these fast modes, new strings
53are inserted in the hash table only when no match was found, or
54when the match is not too long. This degrades the compression ratio
55but saves time since there are both fewer insertions and fewer searches.
56
57
582. Decompression algorithm (inflate)
59
60The real question is, given a Huffman tree, how to decode fast. The most
61important realization is that shorter codes are much more common than
62longer codes, so pay attention to decoding the short codes fast, and let
63the long codes take longer to decode.
64
65inflate() sets up a first level table that covers some number of bits of
66input less than the length of longest code. It gets that many bits from the
67stream, and looks it up in the table. The table will tell if the next
68code is that many bits or less and how many, and if it is, it will tell
69the value, else it will point to the next level table for which inflate()
70grabs more bits and tries to decode a longer code.
71
72How many bits to make the first lookup is a tradeoff between the time it
73takes to decode and the time it takes to build the table. If building the
74table took no time (and if you had infinite memory), then there would only
75be a first level table to cover all the way to the longest code. However,
76building the table ends up taking a lot longer for more bits since short
77codes are replicated many times in such a table. What inflate() does is
78simply to make the number of bits in the first table a variable, and set it
79for the maximum speed.
80
81inflate() sends new trees relatively often, so it is possibly set for a
82smaller first level table than an application that has only one tree for
83all the data. For inflate, which has 286 possible codes for the
84literal/length tree, the size of the first table is nine bits. Also the
85distance trees have 30 possible values, and the size of the first table is
86six bits. Note that for each of those cases, the table ended up one bit
87longer than the ``average'' code length, i.e. the code length of an
88approximately flat code which would be a little more than eight bits for
89286 symbols and a little less than five bits for 30 symbols. It would be
90interesting to see if optimizing the first level table for other
91applications gave values within a bit or two of the flat code size.
92
93
94Jean-loup Gailly Mark Adler
95gzip@prep.ai.mit.edu madler@alumni.caltech.edu
96
97
98References:
99
100[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
101Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
102pp. 337-343.
103
104``DEFLATE Compressed Data Format Specification'' available in
105ftp://ds.internic.net/rfc/rfc1951.txt
diff --git a/pwmanager/libcrypt/zlib/compress.c b/pwmanager/libcrypt/zlib/compress.c
new file mode 100644
index 0000000..814bd9d
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/compress.c
@@ -0,0 +1,68 @@
1/* compress.c -- compress a memory buffer
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zlib.h"
9
10/* ===========================================================================
11 Compresses the source buffer into the destination buffer. The level
12 parameter has the same meaning as in deflateInit. sourceLen is the byte
13 length of the source buffer. Upon entry, destLen is the total size of the
14 destination buffer, which must be at least 0.1% larger than sourceLen plus
15 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
16
17 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
18 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
19 Z_STREAM_ERROR if the level parameter is invalid.
20*/
21int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
22 Bytef *dest;
23 uLongf *destLen;
24 const Bytef *source;
25 uLong sourceLen;
26 int level;
27{
28 z_stream stream;
29 int err;
30
31 stream.next_in = (Bytef*)source;
32 stream.avail_in = (uInt)sourceLen;
33#ifdef MAXSEG_64K
34 /* Check for source > 64K on 16-bit machine: */
35 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
36#endif
37 stream.next_out = dest;
38 stream.avail_out = (uInt)*destLen;
39 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
40
41 stream.zalloc = (alloc_func)0;
42 stream.zfree = (free_func)0;
43 stream.opaque = (voidpf)0;
44
45 err = deflateInit(&stream, level);
46 if (err != Z_OK) return err;
47
48 err = deflate(&stream, Z_FINISH);
49 if (err != Z_STREAM_END) {
50 deflateEnd(&stream);
51 return err == Z_OK ? Z_BUF_ERROR : err;
52 }
53 *destLen = stream.total_out;
54
55 err = deflateEnd(&stream);
56 return err;
57}
58
59/* ===========================================================================
60 */
61int ZEXPORT compress (dest, destLen, source, sourceLen)
62 Bytef *dest;
63 uLongf *destLen;
64 const Bytef *source;
65 uLong sourceLen;
66{
67 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
68}
diff --git a/pwmanager/libcrypt/zlib/crc32.c b/pwmanager/libcrypt/zlib/crc32.c
new file mode 100644
index 0000000..81edc19
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/crc32.c
@@ -0,0 +1,163 @@
1/* crc32.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zlib.h"
9
10#define local static
11
12#ifdef DYNAMIC_CRC_TABLE
13
14local int crc_table_empty = 1;
15local uLongf crc_table[256];
16local void make_crc_table OF((void));
17
18/*
19 Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
20 x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
21
22 Polynomials over GF(2) are represented in binary, one bit per coefficient,
23 with the lowest powers in the most significant bit. Then adding polynomials
24 is just exclusive-or, and multiplying a polynomial by x is a right shift by
25 one. If we call the above polynomial p, and represent a byte as the
26 polynomial q, also with the lowest power in the most significant bit (so the
27 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
28 where a mod b means the remainder after dividing a by b.
29
30 This calculation is done using the shift-register method of multiplying and
31 taking the remainder. The register is initialized to zero, and for each
32 incoming bit, x^32 is added mod p to the register if the bit is a one (where
33 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
34 x (which is shifting right by one and adding x^32 mod p if the bit shifted
35 out is a one). We start with the highest power (least significant bit) of
36 q and repeat for all eight bits of q.
37
38 The table is simply the CRC of all possible eight bit values. This is all
39 the information needed to generate CRC's on data a byte at a time for all
40 combinations of CRC register values and incoming bytes.
41*/
42local void make_crc_table()
43{
44 uLong c;
45 int n, k;
46 uLong poly; /* polynomial exclusive-or pattern */
47 /* terms of polynomial defining this crc (except x^32): */
48 static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
49
50 /* make exclusive-or pattern from polynomial (0xedb88320L) */
51 poly = 0L;
52 for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
53 poly |= 1L << (31 - p[n]);
54
55 for (n = 0; n < 256; n++)
56 {
57 c = (uLong)n;
58 for (k = 0; k < 8; k++)
59 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
60 crc_table[n] = c;
61 }
62 crc_table_empty = 0;
63}
64#else
65/* ========================================================================
66 * Table of CRC-32's of all single-byte values (made by make_crc_table)
67 */
68local const uLongf crc_table[256] = {
69 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
70 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
71 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
72 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
73 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
74 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
75 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
76 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
77 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
78 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
79 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
80 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
81 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
82 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
83 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
84 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
85 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
86 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
87 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
88 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
89 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
90 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
91 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
92 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
93 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
94 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
95 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
96 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
97 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
98 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
99 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
100 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
101 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
102 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
103 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
104 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
105 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
106 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
107 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
108 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
109 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
110 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
111 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
112 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
113 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
114 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
115 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
116 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
117 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
118 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
119 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
120 0x2d02ef8dL
121};
122#endif
123
124/* =========================================================================
125 * This function can be used by asm versions of crc32()
126 */
127const uLongf * ZEXPORT get_crc_table()
128{
129#ifdef DYNAMIC_CRC_TABLE
130 if (crc_table_empty) make_crc_table();
131#endif
132 return (const uLongf *)crc_table;
133}
134
135/* ========================================================================= */
136#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
137#define DO2(buf) DO1(buf); DO1(buf);
138#define DO4(buf) DO2(buf); DO2(buf);
139#define DO8(buf) DO4(buf); DO4(buf);
140
141/* ========================================================================= */
142uLong ZEXPORT crc32(crc, buf, len)
143 uLong crc;
144 const Bytef *buf;
145 uInt len;
146{
147 if (buf == Z_NULL) return 0L;
148#ifdef DYNAMIC_CRC_TABLE
149 if (crc_table_empty)
150 make_crc_table();
151#endif
152 crc = crc ^ 0xffffffffL;
153 while (len >= 8)
154 {
155 DO8(buf);
156 len -= 8;
157 }
158 if (len) do {
159 DO1(buf);
160 } while (--len);
161 return crc ^ 0xffffffffL;
162}
163
diff --git a/pwmanager/libcrypt/zlib/deflate.c b/pwmanager/libcrypt/zlib/deflate.c
new file mode 100644
index 0000000..16ebdad
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/deflate.c
@@ -0,0 +1,1350 @@
1/* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * ALGORITHM
8 *
9 * The "deflation" process depends on being able to identify portions
10 * of the input text which are identical to earlier input (within a
11 * sliding window trailing behind the input currently being processed).
12 *
13 * The most straightforward technique turns out to be the fastest for
14 * most input files: try all possible matches and select the longest.
15 * The key feature of this algorithm is that insertions into the string
16 * dictionary are very simple and thus fast, and deletions are avoided
17 * completely. Insertions are performed at each input character, whereas
18 * string matches are performed only when the previous match ends. So it
19 * is preferable to spend more time in matches to allow very fast string
20 * insertions and avoid deletions. The matching algorithm for small
21 * strings is inspired from that of Rabin & Karp. A brute force approach
22 * is used to find longer strings when a small match has been found.
23 * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
24 * (by Leonid Broukhis).
25 * A previous version of this file used a more sophisticated algorithm
26 * (by Fiala and Greene) which is guaranteed to run in linear amortized
27 * time, but has a larger average cost, uses more memory and is patented.
28 * However the F&G algorithm may be faster for some highly redundant
29 * files if the parameter max_chain_length (described below) is too large.
30 *
31 * ACKNOWLEDGEMENTS
32 *
33 * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
34 * I found it in 'freeze' written by Leonid Broukhis.
35 * Thanks to many people for bug reports and testing.
36 *
37 * REFERENCES
38 *
39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
40 * Available in ftp://ds.internic.net/rfc/rfc1951.txt
41 *
42 * A description of the Rabin and Karp algorithm is given in the book
43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
44 *
45 * Fiala,E.R., and Greene,D.H.
46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
47 *
48 */
49
50/* @(#) $Id$ */
51
52#include "deflate.h"
53
54const char deflate_copyright[] =
55 " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly ";
56/*
57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot
59 include such an acknowledgment, I would appreciate that you keep this
60 copyright string in the executable of your product.
61 */
62
63/* ===========================================================================
64 * Function prototypes.
65 */
66typedef enum {
67 need_more, /* block not completed, need more input or more output */
68 block_done, /* block flush performed */
69 finish_started, /* finish started, need only more output at next deflate */
70 finish_done /* finish done, accept no more input or output */
71} block_state;
72
73typedef block_state (*compress_func) OF((deflate_state *s, int flush));
74/* Compression function. Returns the block state after the call. */
75
76local void fill_window OF((deflate_state *s));
77local block_state deflate_stored OF((deflate_state *s, int flush));
78local block_state deflate_fast OF((deflate_state *s, int flush));
79local block_state deflate_slow OF((deflate_state *s, int flush));
80local void lm_init OF((deflate_state *s));
81local void putShortMSB OF((deflate_state *s, uInt b));
82local void flush_pending OF((z_streamp strm));
83local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
84#ifdef ASMV
85 void match_init OF((void)); /* asm code initialization */
86 uInt longest_match OF((deflate_state *s, IPos cur_match));
87#else
88local uInt longest_match OF((deflate_state *s, IPos cur_match));
89#endif
90
91#ifdef DEBUG
92local void check_match OF((deflate_state *s, IPos start, IPos match,
93 int length));
94#endif
95
96/* ===========================================================================
97 * Local data
98 */
99
100#define NIL 0
101/* Tail of hash chains */
102
103#ifndef TOO_FAR
104# define TOO_FAR 4096
105#endif
106/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
107
108#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
109/* Minimum amount of lookahead, except at the end of the input file.
110 * See deflate.c for comments about the MIN_MATCH+1.
111 */
112
113/* Values for max_lazy_match, good_match and max_chain_length, depending on
114 * the desired pack level (0..9). The values given below have been tuned to
115 * exclude worst case performance for pathological files. Better values may be
116 * found for specific files.
117 */
118typedef struct config_s {
119 ush good_length; /* reduce lazy search above this match length */
120 ush max_lazy; /* do not perform lazy search above this match length */
121 ush nice_length; /* quit search above this match length */
122 ush max_chain;
123 compress_func func;
124} config;
125
126local const config configuration_table[10] = {
127/* good lazy nice chain */
128/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
129/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */
130/* 2 */ {4, 5, 16, 8, deflate_fast},
131/* 3 */ {4, 6, 32, 32, deflate_fast},
132
133/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
134/* 5 */ {8, 16, 32, 32, deflate_slow},
135/* 6 */ {8, 16, 128, 128, deflate_slow},
136/* 7 */ {8, 32, 128, 256, deflate_slow},
137/* 8 */ {32, 128, 258, 1024, deflate_slow},
138/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
139
140/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
141 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
142 * meaning.
143 */
144
145#define EQUAL 0
146/* result of memcmp for equal strings */
147
148struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
149
150/* ===========================================================================
151 * Update a hash value with the given input byte
152 * IN assertion: all calls to to UPDATE_HASH are made with consecutive
153 * input characters, so that a running hash key can be computed from the
154 * previous key instead of complete recalculation each time.
155 */
156#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
157
158
159/* ===========================================================================
160 * Insert string str in the dictionary and set match_head to the previous head
161 * of the hash chain (the most recent string with same hash key). Return
162 * the previous length of the hash chain.
163 * If this file is compiled with -DFASTEST, the compression level is forced
164 * to 1, and no hash chains are maintained.
165 * IN assertion: all calls to to INSERT_STRING are made with consecutive
166 * input characters and the first MIN_MATCH bytes of str are valid
167 * (except for the last MIN_MATCH-1 bytes of the input file).
168 */
169#ifdef FASTEST
170#define INSERT_STRING(s, str, match_head) \
171 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
172 match_head = s->head[s->ins_h], \
173 s->head[s->ins_h] = (Pos)(str))
174#else
175#define INSERT_STRING(s, str, match_head) \
176 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
177 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
178 s->head[s->ins_h] = (Pos)(str))
179#endif
180
181/* ===========================================================================
182 * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
183 * prev[] will be initialized on the fly.
184 */
185#define CLEAR_HASH(s) \
186 s->head[s->hash_size-1] = NIL; \
187 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
188
189/* ========================================================================= */
190int ZEXPORT deflateInit_(strm, level, version, stream_size)
191 z_streamp strm;
192 int level;
193 const char *version;
194 int stream_size;
195{
196 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
197 Z_DEFAULT_STRATEGY, version, stream_size);
198 /* To do: ignore strm->next_in if we use it as window */
199}
200
201/* ========================================================================= */
202int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
203 version, stream_size)
204 z_streamp strm;
205 int level;
206 int method;
207 int windowBits;
208 int memLevel;
209 int strategy;
210 const char *version;
211 int stream_size;
212{
213 deflate_state *s;
214 int noheader = 0;
215 static const char* my_version = ZLIB_VERSION;
216
217 ushf *overlay;
218 /* We overlay pending_buf and d_buf+l_buf. This works since the average
219 * output size for (length,distance) codes is <= 24 bits.
220 */
221
222 if (version == Z_NULL || version[0] != my_version[0] ||
223 stream_size != sizeof(z_stream)) {
224 return Z_VERSION_ERROR;
225 }
226 if (strm == Z_NULL) return Z_STREAM_ERROR;
227
228 strm->msg = Z_NULL;
229 if (strm->zalloc == Z_NULL) {
230 strm->zalloc = zcalloc;
231 strm->opaque = (voidpf)0;
232 }
233 if (strm->zfree == Z_NULL) strm->zfree = zcfree;
234
235 if (level == Z_DEFAULT_COMPRESSION) level = 6;
236#ifdef FASTEST
237 level = 1;
238#endif
239
240 if (windowBits < 0) { /* undocumented feature: suppress zlib header */
241 noheader = 1;
242 windowBits = -windowBits;
243 }
244 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
245 windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
246 strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
247 return Z_STREAM_ERROR;
248 }
249 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
250 if (s == Z_NULL) return Z_MEM_ERROR;
251 strm->state = (struct internal_state FAR *)s;
252 s->strm = strm;
253
254 s->noheader = noheader;
255 s->w_bits = windowBits;
256 s->w_size = 1 << s->w_bits;
257 s->w_mask = s->w_size - 1;
258
259 s->hash_bits = memLevel + 7;
260 s->hash_size = 1 << s->hash_bits;
261 s->hash_mask = s->hash_size - 1;
262 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
263
264 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
265 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
266 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
267
268 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
269
270 overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
271 s->pending_buf = (uchf *) overlay;
272 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
273
274 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
275 s->pending_buf == Z_NULL) {
276 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
277 deflateEnd (strm);
278 return Z_MEM_ERROR;
279 }
280 s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
281 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
282
283 s->level = level;
284 s->strategy = strategy;
285 s->method = (Byte)method;
286
287 return deflateReset(strm);
288}
289
290/* ========================================================================= */
291int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
292 z_streamp strm;
293 const Bytef *dictionary;
294 uInt dictLength;
295{
296 deflate_state *s;
297 uInt length = dictLength;
298 uInt n;
299 IPos hash_head = 0;
300
301 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
302 strm->state->status != INIT_STATE) return Z_STREAM_ERROR;
303
304 s = strm->state;
305 strm->adler = adler32(strm->adler, dictionary, dictLength);
306
307 if (length < MIN_MATCH) return Z_OK;
308 if (length > MAX_DIST(s)) {
309 length = MAX_DIST(s);
310#ifndef USE_DICT_HEAD
311 dictionary += dictLength - length; /* use the tail of the dictionary */
312#endif
313 }
314 zmemcpy(s->window, dictionary, length);
315 s->strstart = length;
316 s->block_start = (long)length;
317
318 /* Insert all strings in the hash table (except for the last two bytes).
319 * s->lookahead stays null, so s->ins_h will be recomputed at the next
320 * call of fill_window.
321 */
322 s->ins_h = s->window[0];
323 UPDATE_HASH(s, s->ins_h, s->window[1]);
324 for (n = 0; n <= length - MIN_MATCH; n++) {
325 INSERT_STRING(s, n, hash_head);
326 }
327 if (hash_head) hash_head = 0; /* to make compiler happy */
328 return Z_OK;
329}
330
331/* ========================================================================= */
332int ZEXPORT deflateReset (strm)
333 z_streamp strm;
334{
335 deflate_state *s;
336
337 if (strm == Z_NULL || strm->state == Z_NULL ||
338 strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
339
340 strm->total_in = strm->total_out = 0;
341 strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
342 strm->data_type = Z_UNKNOWN;
343
344 s = (deflate_state *)strm->state;
345 s->pending = 0;
346 s->pending_out = s->pending_buf;
347
348 if (s->noheader < 0) {
349 s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
350 }
351 s->status = s->noheader ? BUSY_STATE : INIT_STATE;
352 strm->adler = 1;
353 s->last_flush = Z_NO_FLUSH;
354
355 _tr_init(s);
356 lm_init(s);
357
358 return Z_OK;
359}
360
361/* ========================================================================= */
362int ZEXPORT deflateParams(strm, level, strategy)
363 z_streamp strm;
364 int level;
365 int strategy;
366{
367 deflate_state *s;
368 compress_func func;
369 int err = Z_OK;
370
371 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
372 s = strm->state;
373
374 if (level == Z_DEFAULT_COMPRESSION) {
375 level = 6;
376 }
377 if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
378 return Z_STREAM_ERROR;
379 }
380 func = configuration_table[s->level].func;
381
382 if (func != configuration_table[level].func && strm->total_in != 0) {
383 /* Flush the last buffer: */
384 err = deflate(strm, Z_PARTIAL_FLUSH);
385 }
386 if (s->level != level) {
387 s->level = level;
388 s->max_lazy_match = configuration_table[level].max_lazy;
389 s->good_match = configuration_table[level].good_length;
390 s->nice_match = configuration_table[level].nice_length;
391 s->max_chain_length = configuration_table[level].max_chain;
392 }
393 s->strategy = strategy;
394 return err;
395}
396
397/* =========================================================================
398 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
399 * IN assertion: the stream state is correct and there is enough room in
400 * pending_buf.
401 */
402local void putShortMSB (s, b)
403 deflate_state *s;
404 uInt b;
405{
406 put_byte(s, (Byte)(b >> 8));
407 put_byte(s, (Byte)(b & 0xff));
408}
409
410/* =========================================================================
411 * Flush as much pending output as possible. All deflate() output goes
412 * through this function so some applications may wish to modify it
413 * to avoid allocating a large strm->next_out buffer and copying into it.
414 * (See also read_buf()).
415 */
416local void flush_pending(strm)
417 z_streamp strm;
418{
419 unsigned len = strm->state->pending;
420
421 if (len > strm->avail_out) len = strm->avail_out;
422 if (len == 0) return;
423
424 zmemcpy(strm->next_out, strm->state->pending_out, len);
425 strm->next_out += len;
426 strm->state->pending_out += len;
427 strm->total_out += len;
428 strm->avail_out -= len;
429 strm->state->pending -= len;
430 if (strm->state->pending == 0) {
431 strm->state->pending_out = strm->state->pending_buf;
432 }
433}
434
435/* ========================================================================= */
436int ZEXPORT deflate (strm, flush)
437 z_streamp strm;
438 int flush;
439{
440 int old_flush; /* value of flush param for previous deflate call */
441 deflate_state *s;
442
443 if (strm == Z_NULL || strm->state == Z_NULL ||
444 flush > Z_FINISH || flush < 0) {
445 return Z_STREAM_ERROR;
446 }
447 s = strm->state;
448
449 if (strm->next_out == Z_NULL ||
450 (strm->next_in == Z_NULL && strm->avail_in != 0) ||
451 (s->status == FINISH_STATE && flush != Z_FINISH)) {
452 ERR_RETURN(strm, Z_STREAM_ERROR);
453 }
454 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
455
456 s->strm = strm; /* just in case */
457 old_flush = s->last_flush;
458 s->last_flush = flush;
459
460 /* Write the zlib header */
461 if (s->status == INIT_STATE) {
462
463 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
464 uInt level_flags = (s->level-1) >> 1;
465
466 if (level_flags > 3) level_flags = 3;
467 header |= (level_flags << 6);
468 if (s->strstart != 0) header |= PRESET_DICT;
469 header += 31 - (header % 31);
470
471 s->status = BUSY_STATE;
472 putShortMSB(s, header);
473
474 /* Save the adler32 of the preset dictionary: */
475 if (s->strstart != 0) {
476 putShortMSB(s, (uInt)(strm->adler >> 16));
477 putShortMSB(s, (uInt)(strm->adler & 0xffff));
478 }
479 strm->adler = 1L;
480 }
481
482 /* Flush as much pending output as possible */
483 if (s->pending != 0) {
484 flush_pending(strm);
485 if (strm->avail_out == 0) {
486 /* Since avail_out is 0, deflate will be called again with
487 * more output space, but possibly with both pending and
488 * avail_in equal to zero. There won't be anything to do,
489 * but this is not an error situation so make sure we
490 * return OK instead of BUF_ERROR at next call of deflate:
491 */
492 s->last_flush = -1;
493 return Z_OK;
494 }
495
496 /* Make sure there is something to do and avoid duplicate consecutive
497 * flushes. For repeated and useless calls with Z_FINISH, we keep
498 * returning Z_STREAM_END instead of Z_BUFF_ERROR.
499 */
500 } else if (strm->avail_in == 0 && flush <= old_flush &&
501 flush != Z_FINISH) {
502 ERR_RETURN(strm, Z_BUF_ERROR);
503 }
504
505 /* User must not provide more input after the first FINISH: */
506 if (s->status == FINISH_STATE && strm->avail_in != 0) {
507 ERR_RETURN(strm, Z_BUF_ERROR);
508 }
509
510 /* Start a new block or continue the current one.
511 */
512 if (strm->avail_in != 0 || s->lookahead != 0 ||
513 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
514 block_state bstate;
515
516 bstate = (*(configuration_table[s->level].func))(s, flush);
517
518 if (bstate == finish_started || bstate == finish_done) {
519 s->status = FINISH_STATE;
520 }
521 if (bstate == need_more || bstate == finish_started) {
522 if (strm->avail_out == 0) {
523 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
524 }
525 return Z_OK;
526 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
527 * of deflate should use the same flush parameter to make sure
528 * that the flush is complete. So we don't have to output an
529 * empty block here, this will be done at next call. This also
530 * ensures that for a very small output buffer, we emit at most
531 * one empty block.
532 */
533 }
534 if (bstate == block_done) {
535 if (flush == Z_PARTIAL_FLUSH) {
536 _tr_align(s);
537 } else { /* FULL_FLUSH or SYNC_FLUSH */
538 _tr_stored_block(s, (char*)0, 0L, 0);
539 /* For a full flush, this empty block will be recognized
540 * as a special marker by inflate_sync().
541 */
542 if (flush == Z_FULL_FLUSH) {
543 CLEAR_HASH(s); /* forget history */
544 }
545 }
546 flush_pending(strm);
547 if (strm->avail_out == 0) {
548 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
549 return Z_OK;
550 }
551 }
552 }
553 Assert(strm->avail_out > 0, "bug2");
554
555 if (flush != Z_FINISH) return Z_OK;
556 if (s->noheader) return Z_STREAM_END;
557
558 /* Write the zlib trailer (adler32) */
559 putShortMSB(s, (uInt)(strm->adler >> 16));
560 putShortMSB(s, (uInt)(strm->adler & 0xffff));
561 flush_pending(strm);
562 /* If avail_out is zero, the application will call deflate again
563 * to flush the rest.
564 */
565 s->noheader = -1; /* write the trailer only once! */
566 return s->pending != 0 ? Z_OK : Z_STREAM_END;
567}
568
569/* ========================================================================= */
570int ZEXPORT deflateEnd (strm)
571 z_streamp strm;
572{
573 int status;
574
575 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
576
577 status = strm->state->status;
578 if (status != INIT_STATE && status != BUSY_STATE &&
579 status != FINISH_STATE) {
580 return Z_STREAM_ERROR;
581 }
582
583 /* Deallocate in reverse order of allocations: */
584 TRY_FREE(strm, strm->state->pending_buf);
585 TRY_FREE(strm, strm->state->head);
586 TRY_FREE(strm, strm->state->prev);
587 TRY_FREE(strm, strm->state->window);
588
589 ZFREE(strm, strm->state);
590 strm->state = Z_NULL;
591
592 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
593}
594
595/* =========================================================================
596 * Copy the source state to the destination state.
597 * To simplify the source, this is not supported for 16-bit MSDOS (which
598 * doesn't have enough memory anyway to duplicate compression states).
599 */
600int ZEXPORT deflateCopy (dest, source)
601 z_streamp dest;
602 z_streamp source;
603{
604#ifdef MAXSEG_64K
605 return Z_STREAM_ERROR;
606#else
607 deflate_state *ds;
608 deflate_state *ss;
609 ushf *overlay;
610
611
612 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
613 return Z_STREAM_ERROR;
614 }
615
616 ss = source->state;
617
618 *dest = *source;
619
620 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
621 if (ds == Z_NULL) return Z_MEM_ERROR;
622 dest->state = (struct internal_state FAR *) ds;
623 *ds = *ss;
624 ds->strm = dest;
625
626 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
627 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
628 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
629 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
630 ds->pending_buf = (uchf *) overlay;
631
632 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
633 ds->pending_buf == Z_NULL) {
634 deflateEnd (dest);
635 return Z_MEM_ERROR;
636 }
637 /* following zmemcpy do not work for 16-bit MSDOS */
638 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
639 zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
640 zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
641 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
642
643 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
644 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
645 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
646
647 ds->l_desc.dyn_tree = ds->dyn_ltree;
648 ds->d_desc.dyn_tree = ds->dyn_dtree;
649 ds->bl_desc.dyn_tree = ds->bl_tree;
650
651 return Z_OK;
652#endif
653}
654
655/* ===========================================================================
656 * Read a new buffer from the current input stream, update the adler32
657 * and total number of bytes read. All deflate() input goes through
658 * this function so some applications may wish to modify it to avoid
659 * allocating a large strm->next_in buffer and copying from it.
660 * (See also flush_pending()).
661 */
662local int read_buf(strm, buf, size)
663 z_streamp strm;
664 Bytef *buf;
665 unsigned size;
666{
667 unsigned len = strm->avail_in;
668
669 if (len > size) len = size;
670 if (len == 0) return 0;
671
672 strm->avail_in -= len;
673
674 if (!strm->state->noheader) {
675 strm->adler = adler32(strm->adler, strm->next_in, len);
676 }
677 zmemcpy(buf, strm->next_in, len);
678 strm->next_in += len;
679 strm->total_in += len;
680
681 return (int)len;
682}
683
684/* ===========================================================================
685 * Initialize the "longest match" routines for a new zlib stream
686 */
687local void lm_init (s)
688 deflate_state *s;
689{
690 s->window_size = (ulg)2L*s->w_size;
691
692 CLEAR_HASH(s);
693
694 /* Set the default configuration parameters:
695 */
696 s->max_lazy_match = configuration_table[s->level].max_lazy;
697 s->good_match = configuration_table[s->level].good_length;
698 s->nice_match = configuration_table[s->level].nice_length;
699 s->max_chain_length = configuration_table[s->level].max_chain;
700
701 s->strstart = 0;
702 s->block_start = 0L;
703 s->lookahead = 0;
704 s->match_length = s->prev_length = MIN_MATCH-1;
705 s->match_available = 0;
706 s->ins_h = 0;
707#ifdef ASMV
708 match_init(); /* initialize the asm code */
709#endif
710}
711
712/* ===========================================================================
713 * Set match_start to the longest match starting at the given string and
714 * return its length. Matches shorter or equal to prev_length are discarded,
715 * in which case the result is equal to prev_length and match_start is
716 * garbage.
717 * IN assertions: cur_match is the head of the hash chain for the current
718 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
719 * OUT assertion: the match length is not greater than s->lookahead.
720 */
721#ifndef ASMV
722/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
723 * match.S. The code will be functionally equivalent.
724 */
725#ifndef FASTEST
726local uInt longest_match(s, cur_match)
727 deflate_state *s;
728 IPos cur_match; /* current match */
729{
730 unsigned chain_length = s->max_chain_length;/* max hash chain length */
731 register Bytef *scan = s->window + s->strstart; /* current string */
732 register Bytef *match; /* matched string */
733 register int len; /* length of current match */
734 int best_len = s->prev_length; /* best match length so far */
735 int nice_match = s->nice_match; /* stop if match long enough */
736 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
737 s->strstart - (IPos)MAX_DIST(s) : NIL;
738 /* Stop when cur_match becomes <= limit. To simplify the code,
739 * we prevent matches with the string of window index 0.
740 */
741 Posf *prev = s->prev;
742 uInt wmask = s->w_mask;
743
744#ifdef UNALIGNED_OK
745 /* Compare two bytes at a time. Note: this is not always beneficial.
746 * Try with and without -DUNALIGNED_OK to check.
747 */
748 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
749 register ush scan_start = *(ushf*)scan;
750 register ush scan_end = *(ushf*)(scan+best_len-1);
751#else
752 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
753 register Byte scan_end1 = scan[best_len-1];
754 register Byte scan_end = scan[best_len];
755#endif
756
757 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
758 * It is easy to get rid of this optimization if necessary.
759 */
760 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
761
762 /* Do not waste too much time if we already have a good match: */
763 if (s->prev_length >= s->good_match) {
764 chain_length >>= 2;
765 }
766 /* Do not look for matches beyond the end of the input. This is necessary
767 * to make deflate deterministic.
768 */
769 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
770
771 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
772
773 do {
774 Assert(cur_match < s->strstart, "no future");
775 match = s->window + cur_match;
776
777 /* Skip to next match if the match length cannot increase
778 * or if the match length is less than 2:
779 */
780#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
781 /* This code assumes sizeof(unsigned short) == 2. Do not use
782 * UNALIGNED_OK if your compiler uses a different size.
783 */
784 if (*(ushf*)(match+best_len-1) != scan_end ||
785 *(ushf*)match != scan_start) continue;
786
787 /* It is not necessary to compare scan[2] and match[2] since they are
788 * always equal when the other bytes match, given that the hash keys
789 * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
790 * strstart+3, +5, ... up to strstart+257. We check for insufficient
791 * lookahead only every 4th comparison; the 128th check will be made
792 * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
793 * necessary to put more guard bytes at the end of the window, or
794 * to check more often for insufficient lookahead.
795 */
796 Assert(scan[2] == match[2], "scan[2]?");
797 scan++, match++;
798 do {
799 } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
800 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
801 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
802 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
803 scan < strend);
804 /* The funny "do {}" generates better code on most compilers */
805
806 /* Here, scan <= window+strstart+257 */
807 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
808 if (*scan == *match) scan++;
809
810 len = (MAX_MATCH - 1) - (int)(strend-scan);
811 scan = strend - (MAX_MATCH-1);
812
813#else /* UNALIGNED_OK */
814
815 if (match[best_len] != scan_end ||
816 match[best_len-1] != scan_end1 ||
817 *match != *scan ||
818 *++match != scan[1]) continue;
819
820 /* The check at best_len-1 can be removed because it will be made
821 * again later. (This heuristic is not always a win.)
822 * It is not necessary to compare scan[2] and match[2] since they
823 * are always equal when the other bytes match, given that
824 * the hash keys are equal and that HASH_BITS >= 8.
825 */
826 scan += 2, match++;
827 Assert(*scan == *match, "match[2]?");
828
829 /* We check for insufficient lookahead only every 8th comparison;
830 * the 256th check will be made at strstart+258.
831 */
832 do {
833 } while (*++scan == *++match && *++scan == *++match &&
834 *++scan == *++match && *++scan == *++match &&
835 *++scan == *++match && *++scan == *++match &&
836 *++scan == *++match && *++scan == *++match &&
837 scan < strend);
838
839 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
840
841 len = MAX_MATCH - (int)(strend - scan);
842 scan = strend - MAX_MATCH;
843
844#endif /* UNALIGNED_OK */
845
846 if (len > best_len) {
847 s->match_start = cur_match;
848 best_len = len;
849 if (len >= nice_match) break;
850#ifdef UNALIGNED_OK
851 scan_end = *(ushf*)(scan+best_len-1);
852#else
853 scan_end1 = scan[best_len-1];
854 scan_end = scan[best_len];
855#endif
856 }
857 } while ((cur_match = prev[cur_match & wmask]) > limit
858 && --chain_length != 0);
859
860 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
861 return s->lookahead;
862}
863
864#else /* FASTEST */
865/* ---------------------------------------------------------------------------
866 * Optimized version for level == 1 only
867 */
868local uInt longest_match(s, cur_match)
869 deflate_state *s;
870 IPos cur_match; /* current match */
871{
872 register Bytef *scan = s->window + s->strstart; /* current string */
873 register Bytef *match; /* matched string */
874 register int len; /* length of current match */
875 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
876
877 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
878 * It is easy to get rid of this optimization if necessary.
879 */
880 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
881
882 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
883
884 Assert(cur_match < s->strstart, "no future");
885
886 match = s->window + cur_match;
887
888 /* Return failure if the match length is less than 2:
889 */
890 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
891
892 /* The check at best_len-1 can be removed because it will be made
893 * again later. (This heuristic is not always a win.)
894 * It is not necessary to compare scan[2] and match[2] since they
895 * are always equal when the other bytes match, given that
896 * the hash keys are equal and that HASH_BITS >= 8.
897 */
898 scan += 2, match += 2;
899 Assert(*scan == *match, "match[2]?");
900
901 /* We check for insufficient lookahead only every 8th comparison;
902 * the 256th check will be made at strstart+258.
903 */
904 do {
905 } while (*++scan == *++match && *++scan == *++match &&
906 *++scan == *++match && *++scan == *++match &&
907 *++scan == *++match && *++scan == *++match &&
908 *++scan == *++match && *++scan == *++match &&
909 scan < strend);
910
911 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
912
913 len = MAX_MATCH - (int)(strend - scan);
914
915 if (len < MIN_MATCH) return MIN_MATCH - 1;
916
917 s->match_start = cur_match;
918 return len <= s->lookahead ? len : s->lookahead;
919}
920#endif /* FASTEST */
921#endif /* ASMV */
922
923#ifdef DEBUG
924/* ===========================================================================
925 * Check that the match at match_start is indeed a match.
926 */
927local void check_match(s, start, match, length)
928 deflate_state *s;
929 IPos start, match;
930 int length;
931{
932 /* check that the match is indeed a match */
933 if (zmemcmp(s->window + match,
934 s->window + start, length) != EQUAL) {
935 fprintf(stderr, " start %u, match %u, length %d\n",
936 start, match, length);
937 do {
938 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
939 } while (--length != 0);
940 z_error("invalid match");
941 }
942 if (z_verbose > 1) {
943 fprintf(stderr,"\\[%d,%d]", start-match, length);
944 do { putc(s->window[start++], stderr); } while (--length != 0);
945 }
946}
947#else
948# define check_match(s, start, match, length)
949#endif
950
951/* ===========================================================================
952 * Fill the window when the lookahead becomes insufficient.
953 * Updates strstart and lookahead.
954 *
955 * IN assertion: lookahead < MIN_LOOKAHEAD
956 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
957 * At least one byte has been read, or avail_in == 0; reads are
958 * performed for at least two bytes (required for the zip translate_eol
959 * option -- not supported here).
960 */
961local void fill_window(s)
962 deflate_state *s;
963{
964 register unsigned n, m;
965 register Posf *p;
966 unsigned more; /* Amount of free space at the end of the window. */
967 uInt wsize = s->w_size;
968
969 do {
970 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
971
972 /* Deal with !@#$% 64K limit: */
973 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
974 more = wsize;
975
976 } else if (more == (unsigned)(-1)) {
977 /* Very unlikely, but possible on 16 bit machine if strstart == 0
978 * and lookahead == 1 (input done one byte at time)
979 */
980 more--;
981
982 /* If the window is almost full and there is insufficient lookahead,
983 * move the upper half to the lower one to make room in the upper half.
984 */
985 } else if (s->strstart >= wsize+MAX_DIST(s)) {
986
987 zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
988 s->match_start -= wsize;
989 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
990 s->block_start -= (long) wsize;
991
992 /* Slide the hash table (could be avoided with 32 bit values
993 at the expense of memory usage). We slide even when level == 0
994 to keep the hash table consistent if we switch back to level > 0
995 later. (Using level 0 permanently is not an optimal usage of
996 zlib, so we don't care about this pathological case.)
997 */
998 n = s->hash_size;
999 p = &s->head[n];
1000 do {
1001 m = *--p;
1002 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1003 } while (--n);
1004
1005 n = wsize;
1006#ifndef FASTEST
1007 p = &s->prev[n];
1008 do {
1009 m = *--p;
1010 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1011 /* If n is not on any hash chain, prev[n] is garbage but
1012 * its value will never be used.
1013 */
1014 } while (--n);
1015#endif
1016 more += wsize;
1017 }
1018 if (s->strm->avail_in == 0) return;
1019
1020 /* If there was no sliding:
1021 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
1022 * more == window_size - lookahead - strstart
1023 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
1024 * => more >= window_size - 2*WSIZE + 2
1025 * In the BIG_MEM or MMAP case (not yet supported),
1026 * window_size == input_size + MIN_LOOKAHEAD &&
1027 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
1028 * Otherwise, window_size == 2*WSIZE so more >= 2.
1029 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
1030 */
1031 Assert(more >= 2, "more < 2");
1032
1033 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1034 s->lookahead += n;
1035
1036 /* Initialize the hash value now that we have some input: */
1037 if (s->lookahead >= MIN_MATCH) {
1038 s->ins_h = s->window[s->strstart];
1039 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1040#if MIN_MATCH != 3
1041 Call UPDATE_HASH() MIN_MATCH-3 more times
1042#endif
1043 }
1044 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1045 * but this is not important since only literal bytes will be emitted.
1046 */
1047
1048 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1049}
1050
1051/* ===========================================================================
1052 * Flush the current block, with given end-of-file flag.
1053 * IN assertion: strstart is set to the end of the current match.
1054 */
1055#define FLUSH_BLOCK_ONLY(s, eof) { \
1056 _tr_flush_block(s, (s->block_start >= 0L ? \
1057 (charf *)&s->window[(unsigned)s->block_start] : \
1058 (charf *)Z_NULL), \
1059 (ulg)((long)s->strstart - s->block_start), \
1060 (eof)); \
1061 s->block_start = s->strstart; \
1062 flush_pending(s->strm); \
1063 Tracev((stderr,"[FLUSH]")); \
1064}
1065
1066/* Same but force premature exit if necessary. */
1067#define FLUSH_BLOCK(s, eof) { \
1068 FLUSH_BLOCK_ONLY(s, eof); \
1069 if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
1070}
1071
1072/* ===========================================================================
1073 * Copy without compression as much as possible from the input stream, return
1074 * the current block state.
1075 * This function does not insert new strings in the dictionary since
1076 * uncompressible data is probably not useful. This function is used
1077 * only for the level=0 compression option.
1078 * NOTE: this function should be optimized to avoid extra copying from
1079 * window to pending_buf.
1080 */
1081local block_state deflate_stored(s, flush)
1082 deflate_state *s;
1083 int flush;
1084{
1085 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
1086 * to pending_buf_size, and each stored block has a 5 byte header:
1087 */
1088 ulg max_block_size = 0xffff;
1089 ulg max_start;
1090
1091 if (max_block_size > s->pending_buf_size - 5) {
1092 max_block_size = s->pending_buf_size - 5;
1093 }
1094
1095 /* Copy as much as possible from input to output: */
1096 for (;;) {
1097 /* Fill the window as much as possible: */
1098 if (s->lookahead <= 1) {
1099
1100 Assert(s->strstart < s->w_size+MAX_DIST(s) ||
1101 s->block_start >= (long)s->w_size, "slide too late");
1102
1103 fill_window(s);
1104 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
1105
1106 if (s->lookahead == 0) break; /* flush the current block */
1107 }
1108 Assert(s->block_start >= 0L, "block gone");
1109
1110 s->strstart += s->lookahead;
1111 s->lookahead = 0;
1112
1113 /* Emit a stored block if pending_buf will be full: */
1114 max_start = s->block_start + max_block_size;
1115 if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
1116 /* strstart == 0 is possible when wraparound on 16-bit machine */
1117 s->lookahead = (uInt)(s->strstart - max_start);
1118 s->strstart = (uInt)max_start;
1119 FLUSH_BLOCK(s, 0);
1120 }
1121 /* Flush if we may have to slide, otherwise block_start may become
1122 * negative and the data will be gone:
1123 */
1124 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
1125 FLUSH_BLOCK(s, 0);
1126 }
1127 }
1128 FLUSH_BLOCK(s, flush == Z_FINISH);
1129 return flush == Z_FINISH ? finish_done : block_done;
1130}
1131
1132/* ===========================================================================
1133 * Compress as much as possible from the input stream, return the current
1134 * block state.
1135 * This function does not perform lazy evaluation of matches and inserts
1136 * new strings in the dictionary only for unmatched strings or for short
1137 * matches. It is used only for the fast compression options.
1138 */
1139local block_state deflate_fast(s, flush)
1140 deflate_state *s;
1141 int flush;
1142{
1143 IPos hash_head = NIL; /* head of the hash chain */
1144 int bflush; /* set if current block must be flushed */
1145
1146 for (;;) {
1147 /* Make sure that we always have enough lookahead, except
1148 * at the end of the input file. We need MAX_MATCH bytes
1149 * for the next match, plus MIN_MATCH bytes to insert the
1150 * string following the next match.
1151 */
1152 if (s->lookahead < MIN_LOOKAHEAD) {
1153 fill_window(s);
1154 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1155 return need_more;
1156 }
1157 if (s->lookahead == 0) break; /* flush the current block */
1158 }
1159
1160 /* Insert the string window[strstart .. strstart+2] in the
1161 * dictionary, and set hash_head to the head of the hash chain:
1162 */
1163 if (s->lookahead >= MIN_MATCH) {
1164 INSERT_STRING(s, s->strstart, hash_head);
1165 }
1166
1167 /* Find the longest match, discarding those <= prev_length.
1168 * At this point we have always match_length < MIN_MATCH
1169 */
1170 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1171 /* To simplify the code, we prevent matches with the string
1172 * of window index 0 (in particular we have to avoid a match
1173 * of the string with itself at the start of the input file).
1174 */
1175 if (s->strategy != Z_HUFFMAN_ONLY) {
1176 s->match_length = longest_match (s, hash_head);
1177 }
1178 /* longest_match() sets match_start */
1179 }
1180 if (s->match_length >= MIN_MATCH) {
1181 check_match(s, s->strstart, s->match_start, s->match_length);
1182
1183 _tr_tally_dist(s, s->strstart - s->match_start,
1184 s->match_length - MIN_MATCH, bflush);
1185
1186 s->lookahead -= s->match_length;
1187
1188 /* Insert new strings in the hash table only if the match length
1189 * is not too large. This saves time but degrades compression.
1190 */
1191#ifndef FASTEST
1192 if (s->match_length <= s->max_insert_length &&
1193 s->lookahead >= MIN_MATCH) {
1194 s->match_length--; /* string at strstart already in hash table */
1195 do {
1196 s->strstart++;
1197 INSERT_STRING(s, s->strstart, hash_head);
1198 /* strstart never exceeds WSIZE-MAX_MATCH, so there are
1199 * always MIN_MATCH bytes ahead.
1200 */
1201 } while (--s->match_length != 0);
1202 s->strstart++;
1203 } else
1204#endif
1205 {
1206 s->strstart += s->match_length;
1207 s->match_length = 0;
1208 s->ins_h = s->window[s->strstart];
1209 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1210#if MIN_MATCH != 3
1211 Call UPDATE_HASH() MIN_MATCH-3 more times
1212#endif
1213 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
1214 * matter since it will be recomputed at next deflate call.
1215 */
1216 }
1217 } else {
1218 /* No match, output a literal byte */
1219 Tracevv((stderr,"%c", s->window[s->strstart]));
1220 _tr_tally_lit (s, s->window[s->strstart], bflush);
1221 s->lookahead--;
1222 s->strstart++;
1223 }
1224 if (bflush) FLUSH_BLOCK(s, 0);
1225 }
1226 FLUSH_BLOCK(s, flush == Z_FINISH);
1227 return flush == Z_FINISH ? finish_done : block_done;
1228}
1229
1230/* ===========================================================================
1231 * Same as above, but achieves better compression. We use a lazy
1232 * evaluation for matches: a match is finally adopted only if there is
1233 * no better match at the next window position.
1234 */
1235local block_state deflate_slow(s, flush)
1236 deflate_state *s;
1237 int flush;
1238{
1239 IPos hash_head = NIL; /* head of hash chain */
1240 int bflush; /* set if current block must be flushed */
1241
1242 /* Process the input block. */
1243 for (;;) {
1244 /* Make sure that we always have enough lookahead, except
1245 * at the end of the input file. We need MAX_MATCH bytes
1246 * for the next match, plus MIN_MATCH bytes to insert the
1247 * string following the next match.
1248 */
1249 if (s->lookahead < MIN_LOOKAHEAD) {
1250 fill_window(s);
1251 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1252 return need_more;
1253 }
1254 if (s->lookahead == 0) break; /* flush the current block */
1255 }
1256
1257 /* Insert the string window[strstart .. strstart+2] in the
1258 * dictionary, and set hash_head to the head of the hash chain:
1259 */
1260 if (s->lookahead >= MIN_MATCH) {
1261 INSERT_STRING(s, s->strstart, hash_head);
1262 }
1263
1264 /* Find the longest match, discarding those <= prev_length.
1265 */
1266 s->prev_length = s->match_length, s->prev_match = s->match_start;
1267 s->match_length = MIN_MATCH-1;
1268
1269 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
1270 s->strstart - hash_head <= MAX_DIST(s)) {
1271 /* To simplify the code, we prevent matches with the string
1272 * of window index 0 (in particular we have to avoid a match
1273 * of the string with itself at the start of the input file).
1274 */
1275 if (s->strategy != Z_HUFFMAN_ONLY) {
1276 s->match_length = longest_match (s, hash_head);
1277 }
1278 /* longest_match() sets match_start */
1279
1280 if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
1281 (s->match_length == MIN_MATCH &&
1282 s->strstart - s->match_start > TOO_FAR))) {
1283
1284 /* If prev_match is also MIN_MATCH, match_start is garbage
1285 * but we will ignore the current match anyway.
1286 */
1287 s->match_length = MIN_MATCH-1;
1288 }
1289 }
1290 /* If there was a match at the previous step and the current
1291 * match is not better, output the previous match:
1292 */
1293 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
1294 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
1295 /* Do not insert strings in hash table beyond this. */
1296
1297 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
1298
1299 _tr_tally_dist(s, s->strstart -1 - s->prev_match,
1300 s->prev_length - MIN_MATCH, bflush);
1301
1302 /* Insert in hash table all strings up to the end of the match.
1303 * strstart-1 and strstart are already inserted. If there is not
1304 * enough lookahead, the last two strings are not inserted in
1305 * the hash table.
1306 */
1307 s->lookahead -= s->prev_length-1;
1308 s->prev_length -= 2;
1309 do {
1310 if (++s->strstart <= max_insert) {
1311 INSERT_STRING(s, s->strstart, hash_head);
1312 }
1313 } while (--s->prev_length != 0);
1314 s->match_available = 0;
1315 s->match_length = MIN_MATCH-1;
1316 s->strstart++;
1317
1318 if (bflush) FLUSH_BLOCK(s, 0);
1319
1320 } else if (s->match_available) {
1321 /* If there was no match at the previous position, output a
1322 * single literal. If there was a match but the current match
1323 * is longer, truncate the previous match to a single literal.
1324 */
1325 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1326 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1327 if (bflush) {
1328 FLUSH_BLOCK_ONLY(s, 0);
1329 }
1330 s->strstart++;
1331 s->lookahead--;
1332 if (s->strm->avail_out == 0) return need_more;
1333 } else {
1334 /* There is no previous match to compare with, wait for
1335 * the next step to decide.
1336 */
1337 s->match_available = 1;
1338 s->strstart++;
1339 s->lookahead--;
1340 }
1341 }
1342 Assert (flush != Z_NO_FLUSH, "no flush?");
1343 if (s->match_available) {
1344 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1345 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1346 s->match_available = 0;
1347 }
1348 FLUSH_BLOCK(s, flush == Z_FINISH);
1349 return flush == Z_FINISH ? finish_done : block_done;
1350}
diff --git a/pwmanager/libcrypt/zlib/deflate.h b/pwmanager/libcrypt/zlib/deflate.h
new file mode 100644
index 0000000..b99a48a
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/deflate.h
@@ -0,0 +1,318 @@
1/* deflate.h -- internal compression state
2 * Copyright (C) 1995-2002 Jean-loup Gailly
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* @(#) $Id$ */
12
13#ifndef _DEFLATE_H
14#define _DEFLATE_H
15
16#include "zutil.h"
17
18/* ===========================================================================
19 * Internal compression state.
20 */
21
22#define LENGTH_CODES 29
23/* number of length codes, not counting the special END_BLOCK code */
24
25#define LITERALS 256
26/* number of literal bytes 0..255 */
27
28#define L_CODES (LITERALS+1+LENGTH_CODES)
29/* number of Literal or Length codes, including the END_BLOCK code */
30
31#define D_CODES 30
32/* number of distance codes */
33
34#define BL_CODES 19
35/* number of codes used to transfer the bit lengths */
36
37#define HEAP_SIZE (2*L_CODES+1)
38/* maximum heap size */
39
40#define MAX_BITS 15
41/* All codes must not exceed MAX_BITS bits */
42
43#define INIT_STATE 42
44#define BUSY_STATE 113
45#define FINISH_STATE 666
46/* Stream status */
47
48
49/* Data structure describing a single value and its code string. */
50typedef struct ct_data_s {
51 union {
52 ush freq; /* frequency count */
53 ush code; /* bit string */
54 } fc;
55 union {
56 ush dad; /* father node in Huffman tree */
57 ush len; /* length of bit string */
58 } dl;
59} FAR ct_data;
60
61#define Freq fc.freq
62#define Code fc.code
63#define Dad dl.dad
64#define Len dl.len
65
66typedef struct static_tree_desc_s static_tree_desc;
67
68typedef struct tree_desc_s {
69 ct_data *dyn_tree; /* the dynamic tree */
70 int max_code; /* largest code with non zero frequency */
71 static_tree_desc *stat_desc; /* the corresponding static tree */
72} FAR tree_desc;
73
74typedef ush Pos;
75typedef Pos FAR Posf;
76typedef unsigned IPos;
77
78/* A Pos is an index in the character window. We use short instead of int to
79 * save space in the various tables. IPos is used only for parameter passing.
80 */
81
82typedef struct internal_state {
83 z_streamp strm; /* pointer back to this zlib stream */
84 int status; /* as the name implies */
85 Bytef *pending_buf; /* output still pending */
86 ulg pending_buf_size; /* size of pending_buf */
87 Bytef *pending_out; /* next pending byte to output to the stream */
88 int pending; /* nb of bytes in the pending buffer */
89 int noheader; /* suppress zlib header and adler32 */
90 Byte data_type; /* UNKNOWN, BINARY or ASCII */
91 Byte method; /* STORED (for zip only) or DEFLATED */
92 int last_flush; /* value of flush param for previous deflate call */
93
94 /* used by deflate.c: */
95
96 uInt w_size; /* LZ77 window size (32K by default) */
97 uInt w_bits; /* log2(w_size) (8..16) */
98 uInt w_mask; /* w_size - 1 */
99
100 Bytef *window;
101 /* Sliding window. Input bytes are read into the second half of the window,
102 * and move to the first half later to keep a dictionary of at least wSize
103 * bytes. With this organization, matches are limited to a distance of
104 * wSize-MAX_MATCH bytes, but this ensures that IO is always
105 * performed with a length multiple of the block size. Also, it limits
106 * the window size to 64K, which is quite useful on MSDOS.
107 * To do: use the user input buffer as sliding window.
108 */
109
110 ulg window_size;
111 /* Actual size of window: 2*wSize, except when the user input buffer
112 * is directly used as sliding window.
113 */
114
115 Posf *prev;
116 /* Link to older string with same hash index. To limit the size of this
117 * array to 64K, this link is maintained only for the last 32K strings.
118 * An index in this array is thus a window index modulo 32K.
119 */
120
121 Posf *head; /* Heads of the hash chains or NIL. */
122
123 uInt ins_h; /* hash index of string to be inserted */
124 uInt hash_size; /* number of elements in hash table */
125 uInt hash_bits; /* log2(hash_size) */
126 uInt hash_mask; /* hash_size-1 */
127
128 uInt hash_shift;
129 /* Number of bits by which ins_h must be shifted at each input
130 * step. It must be such that after MIN_MATCH steps, the oldest
131 * byte no longer takes part in the hash key, that is:
132 * hash_shift * MIN_MATCH >= hash_bits
133 */
134
135 long block_start;
136 /* Window position at the beginning of the current output block. Gets
137 * negative when the window is moved backwards.
138 */
139
140 uInt match_length; /* length of best match */
141 IPos prev_match; /* previous match */
142 int match_available; /* set if previous match exists */
143 uInt strstart; /* start of string to insert */
144 uInt match_start; /* start of matching string */
145 uInt lookahead; /* number of valid bytes ahead in window */
146
147 uInt prev_length;
148 /* Length of the best match at previous step. Matches not greater than this
149 * are discarded. This is used in the lazy match evaluation.
150 */
151
152 uInt max_chain_length;
153 /* To speed up deflation, hash chains are never searched beyond this
154 * length. A higher limit improves compression ratio but degrades the
155 * speed.
156 */
157
158 uInt max_lazy_match;
159 /* Attempt to find a better match only when the current match is strictly
160 * smaller than this value. This mechanism is used only for compression
161 * levels >= 4.
162 */
163# define max_insert_length max_lazy_match
164 /* Insert new strings in the hash table only if the match length is not
165 * greater than this length. This saves time but degrades compression.
166 * max_insert_length is used only for compression levels <= 3.
167 */
168
169 int level; /* compression level (1..9) */
170 int strategy; /* favor or force Huffman coding*/
171
172 uInt good_match;
173 /* Use a faster search when the previous match is longer than this */
174
175 int nice_match; /* Stop searching when current match exceeds this */
176
177 /* used by trees.c: */
178 /* Didn't use ct_data typedef below to supress compiler warning */
179 struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
180 struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
181 struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
182
183 struct tree_desc_s l_desc; /* desc. for literal tree */
184 struct tree_desc_s d_desc; /* desc. for distance tree */
185 struct tree_desc_s bl_desc; /* desc. for bit length tree */
186
187 ush bl_count[MAX_BITS+1];
188 /* number of codes at each bit length for an optimal tree */
189
190 int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
191 int heap_len; /* number of elements in the heap */
192 int heap_max; /* element of largest frequency */
193 /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
194 * The same heap array is used to build all trees.
195 */
196
197 uch depth[2*L_CODES+1];
198 /* Depth of each subtree used as tie breaker for trees of equal frequency
199 */
200
201 uchf *l_buf; /* buffer for literals or lengths */
202
203 uInt lit_bufsize;
204 /* Size of match buffer for literals/lengths. There are 4 reasons for
205 * limiting lit_bufsize to 64K:
206 * - frequencies can be kept in 16 bit counters
207 * - if compression is not successful for the first block, all input
208 * data is still in the window so we can still emit a stored block even
209 * when input comes from standard input. (This can also be done for
210 * all blocks if lit_bufsize is not greater than 32K.)
211 * - if compression is not successful for a file smaller than 64K, we can
212 * even emit a stored file instead of a stored block (saving 5 bytes).
213 * This is applicable only for zip (not gzip or zlib).
214 * - creating new Huffman trees less frequently may not provide fast
215 * adaptation to changes in the input data statistics. (Take for
216 * example a binary file with poorly compressible code followed by
217 * a highly compressible string table.) Smaller buffer sizes give
218 * fast adaptation but have of course the overhead of transmitting
219 * trees more frequently.
220 * - I can't count above 4
221 */
222
223 uInt last_lit; /* running index in l_buf */
224
225 ushf *d_buf;
226 /* Buffer for distances. To simplify the code, d_buf and l_buf have
227 * the same number of elements. To use different lengths, an extra flag
228 * array would be necessary.
229 */
230
231 ulg opt_len; /* bit length of current block with optimal trees */
232 ulg static_len; /* bit length of current block with static trees */
233 uInt matches; /* number of string matches in current block */
234 int last_eob_len; /* bit length of EOB code for last block */
235
236#ifdef DEBUG
237 ulg compressed_len; /* total bit length of compressed file mod 2^32 */
238 ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
239#endif
240
241 ush bi_buf;
242 /* Output buffer. bits are inserted starting at the bottom (least
243 * significant bits).
244 */
245 int bi_valid;
246 /* Number of valid bits in bi_buf. All bits above the last valid bit
247 * are always zero.
248 */
249
250} FAR deflate_state;
251
252/* Output a byte on the stream.
253 * IN assertion: there is enough room in pending_buf.
254 */
255#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
256
257
258#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
259/* Minimum amount of lookahead, except at the end of the input file.
260 * See deflate.c for comments about the MIN_MATCH+1.
261 */
262
263#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
264/* In order to simplify the code, particularly on 16 bit machines, match
265 * distances are limited to MAX_DIST instead of WSIZE.
266 */
267
268 /* in trees.c */
269void _tr_init OF((deflate_state *s));
270int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
271void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
272 int eof));
273void _tr_align OF((deflate_state *s));
274void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
275 int eof));
276
277#define d_code(dist) \
278 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
279/* Mapping from a distance to a distance code. dist is the distance - 1 and
280 * must not have side effects. _dist_code[256] and _dist_code[257] are never
281 * used.
282 */
283
284#ifndef DEBUG
285/* Inline versions of _tr_tally for speed: */
286
287#if defined(GEN_TREES_H) || !defined(STDC)
288 extern uch _length_code[];
289 extern uch _dist_code[];
290#else
291 extern const uch _length_code[];
292 extern const uch _dist_code[];
293#endif
294
295# define _tr_tally_lit(s, c, flush) \
296 { uch cc = (c); \
297 s->d_buf[s->last_lit] = 0; \
298 s->l_buf[s->last_lit++] = cc; \
299 s->dyn_ltree[cc].Freq++; \
300 flush = (s->last_lit == s->lit_bufsize-1); \
301 }
302# define _tr_tally_dist(s, distance, length, flush) \
303 { uch len = (length); \
304 ush dist = (distance); \
305 s->d_buf[s->last_lit] = dist; \
306 s->l_buf[s->last_lit++] = len; \
307 dist--; \
308 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
309 s->dyn_dtree[d_code(dist)].Freq++; \
310 flush = (s->last_lit == s->lit_bufsize-1); \
311 }
312#else
313# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
314# define _tr_tally_dist(s, distance, length, flush) \
315 flush = _tr_tally(s, distance, length)
316#endif
317
318#endif
diff --git a/pwmanager/libcrypt/zlib/infblock.c b/pwmanager/libcrypt/zlib/infblock.c
new file mode 100644
index 0000000..dd7a6d4
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/infblock.c
@@ -0,0 +1,403 @@
1/* infblock.c -- interpret and process block types to last block
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "infblock.h"
8#include "inftrees.h"
9#include "infcodes.h"
10#include "infutil.h"
11
12struct inflate_codes_state {int dummy;}; /* for buggy compilers */
13
14/* simplify the use of the inflate_huft type with some defines */
15#define exop word.what.Exop
16#define bits word.what.Bits
17
18/* Table for deflate from PKZIP's appnote.txt. */
19local const uInt border[] = { /* Order of the bit length code lengths */
20 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
21
22/*
23 Notes beyond the 1.93a appnote.txt:
24
25 1. Distance pointers never point before the beginning of the output
26 stream.
27 2. Distance pointers can point back across blocks, up to 32k away.
28 3. There is an implied maximum of 7 bits for the bit length table and
29 15 bits for the actual data.
30 4. If only one code exists, then it is encoded using one bit. (Zero
31 would be more efficient, but perhaps a little confusing.) If two
32 codes exist, they are coded using one bit each (0 and 1).
33 5. There is no way of sending zero distance codes--a dummy must be
34 sent if there are none. (History: a pre 2.0 version of PKZIP would
35 store blocks with no distance codes, but this was discovered to be
36 too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
37 zero distance codes, which is sent as one code of zero bits in
38 length.
39 6. There are up to 286 literal/length codes. Code 256 represents the
40 end-of-block. Note however that the static length tree defines
41 288 codes just to fill out the Huffman codes. Codes 286 and 287
42 cannot be used though, since there is no length base or extra bits
43 defined for them. Similarily, there are up to 30 distance codes.
44 However, static trees define 32 codes (all 5 bits) to fill out the
45 Huffman codes, but the last two had better not show up in the data.
46 7. Unzip can check dynamic Huffman blocks for complete code sets.
47 The exception is that a single code would not be complete (see #4).
48 8. The five bits following the block type is really the number of
49 literal codes sent minus 257.
50 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
51 (1+6+6). Therefore, to output three times the length, you output
52 three codes (1+1+1), whereas to output four times the same length,
53 you only need two codes (1+3). Hmm.
54 10. In the tree reconstruction algorithm, Code = Code + Increment
55 only if BitLength(i) is not zero. (Pretty obvious.)
56 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
57 12. Note: length code 284 can represent 227-258, but length code 285
58 really is 258. The last length deserves its own, short code
59 since it gets used a lot in very redundant files. The length
60 258 is special since 258 - 3 (the min match length) is 255.
61 13. The literal/length and distance code bit lengths are read as a
62 single stream of lengths. It is possible (and advantageous) for
63 a repeat code (16, 17, or 18) to go across the boundary between
64 the two sets of lengths.
65 */
66
67
68void inflate_blocks_reset(s, z, c)
69inflate_blocks_statef *s;
70z_streamp z;
71uLongf *c;
72{
73 if (c != Z_NULL)
74 *c = s->check;
75 if (s->mode == BTREE || s->mode == DTREE)
76 ZFREE(z, s->sub.trees.blens);
77 if (s->mode == CODES)
78 inflate_codes_free(s->sub.decode.codes, z);
79 s->mode = TYPE;
80 s->bitk = 0;
81 s->bitb = 0;
82 s->read = s->write = s->window;
83 if (s->checkfn != Z_NULL)
84 z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
85 Tracev((stderr, "inflate: blocks reset\n"));
86}
87
88
89inflate_blocks_statef *inflate_blocks_new(z, c, w)
90z_streamp z;
91check_func c;
92uInt w;
93{
94 inflate_blocks_statef *s;
95
96 if ((s = (inflate_blocks_statef *)ZALLOC
97 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
98 return s;
99 if ((s->hufts =
100 (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
101 {
102 ZFREE(z, s);
103 return Z_NULL;
104 }
105 if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
106 {
107 ZFREE(z, s->hufts);
108 ZFREE(z, s);
109 return Z_NULL;
110 }
111 s->end = s->window + w;
112 s->checkfn = c;
113 s->mode = TYPE;
114 Tracev((stderr, "inflate: blocks allocated\n"));
115 inflate_blocks_reset(s, z, Z_NULL);
116 return s;
117}
118
119
120int inflate_blocks(s, z, r)
121inflate_blocks_statef *s;
122z_streamp z;
123int r;
124{
125 uInt t; /* temporary storage */
126 uLong b; /* bit buffer */
127 uInt k; /* bits in bit buffer */
128 Bytef *p; /* input data pointer */
129 uInt n; /* bytes available there */
130 Bytef *q; /* output window write pointer */
131 uInt m; /* bytes to end of window or read pointer */
132
133 /* copy input/output information to locals (UPDATE macro restores) */
134 LOAD
135
136 /* process input based on current state */
137 while (1) switch (s->mode)
138 {
139 case TYPE:
140 NEEDBITS(3)
141 t = (uInt)b & 7;
142 s->last = t & 1;
143 switch (t >> 1)
144 {
145 case 0: /* stored */
146 Tracev((stderr, "inflate: stored block%s\n",
147 s->last ? " (last)" : ""));
148 DUMPBITS(3)
149 t = k & 7; /* go to byte boundary */
150 DUMPBITS(t)
151 s->mode = LENS; /* get length of stored block */
152 break;
153 case 1: /* fixed */
154 Tracev((stderr, "inflate: fixed codes block%s\n",
155 s->last ? " (last)" : ""));
156 {
157 uInt bl, bd;
158 inflate_huft *tl, *td;
159
160 inflate_trees_fixed(&bl, &bd, &tl, &td, z);
161 s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
162 if (s->sub.decode.codes == Z_NULL)
163 {
164 r = Z_MEM_ERROR;
165 LEAVE
166 }
167 }
168 DUMPBITS(3)
169 s->mode = CODES;
170 break;
171 case 2: /* dynamic */
172 Tracev((stderr, "inflate: dynamic codes block%s\n",
173 s->last ? " (last)" : ""));
174 DUMPBITS(3)
175 s->mode = TABLE;
176 break;
177 case 3: /* illegal */
178 DUMPBITS(3)
179 s->mode = BAD;
180 z->msg = (char*)"invalid block type";
181 r = Z_DATA_ERROR;
182 LEAVE
183 }
184 break;
185 case LENS:
186 NEEDBITS(32)
187 if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
188 {
189 s->mode = BAD;
190 z->msg = (char*)"invalid stored block lengths";
191 r = Z_DATA_ERROR;
192 LEAVE
193 }
194 s->sub.left = (uInt)b & 0xffff;
195 b = k = 0; /* dump bits */
196 Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
197 s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
198 break;
199 case STORED:
200 if (n == 0)
201 LEAVE
202 NEEDOUT
203 t = s->sub.left;
204 if (t > n) t = n;
205 if (t > m) t = m;
206 zmemcpy(q, p, t);
207 p += t; n -= t;
208 q += t; m -= t;
209 if ((s->sub.left -= t) != 0)
210 break;
211 Tracev((stderr, "inflate: stored end, %lu total out\n",
212 z->total_out + (q >= s->read ? q - s->read :
213 (s->end - s->read) + (q - s->window))));
214 s->mode = s->last ? DRY : TYPE;
215 break;
216 case TABLE:
217 NEEDBITS(14)
218 s->sub.trees.table = t = (uInt)b & 0x3fff;
219#ifndef PKZIP_BUG_WORKAROUND
220 if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
221 {
222 s->mode = BAD;
223 z->msg = (char*)"too many length or distance symbols";
224 r = Z_DATA_ERROR;
225 LEAVE
226 }
227#endif
228 t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
229 if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
230 {
231 r = Z_MEM_ERROR;
232 LEAVE
233 }
234 DUMPBITS(14)
235 s->sub.trees.index = 0;
236 Tracev((stderr, "inflate: table sizes ok\n"));
237 s->mode = BTREE;
238 case BTREE:
239 while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
240 {
241 NEEDBITS(3)
242 s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
243 DUMPBITS(3)
244 }
245 while (s->sub.trees.index < 19)
246 s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
247 s->sub.trees.bb = 7;
248 t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
249 &s->sub.trees.tb, s->hufts, z);
250 if (t != Z_OK)
251 {
252 r = t;
253 if (r == Z_DATA_ERROR)
254 {
255 ZFREE(z, s->sub.trees.blens);
256 s->mode = BAD;
257 }
258 LEAVE
259 }
260 s->sub.trees.index = 0;
261 Tracev((stderr, "inflate: bits tree ok\n"));
262 s->mode = DTREE;
263 case DTREE:
264 while (t = s->sub.trees.table,
265 s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
266 {
267 inflate_huft *h;
268 uInt i, j, c;
269
270 t = s->sub.trees.bb;
271 NEEDBITS(t)
272 h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
273 t = h->bits;
274 c = h->base;
275 if (c < 16)
276 {
277 DUMPBITS(t)
278 s->sub.trees.blens[s->sub.trees.index++] = c;
279 }
280 else /* c == 16..18 */
281 {
282 i = c == 18 ? 7 : c - 14;
283 j = c == 18 ? 11 : 3;
284 NEEDBITS(t + i)
285 DUMPBITS(t)
286 j += (uInt)b & inflate_mask[i];
287 DUMPBITS(i)
288 i = s->sub.trees.index;
289 t = s->sub.trees.table;
290 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
291 (c == 16 && i < 1))
292 {
293 ZFREE(z, s->sub.trees.blens);
294 s->mode = BAD;
295 z->msg = (char*)"invalid bit length repeat";
296 r = Z_DATA_ERROR;
297 LEAVE
298 }
299 c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
300 do {
301 s->sub.trees.blens[i++] = c;
302 } while (--j);
303 s->sub.trees.index = i;
304 }
305 }
306 s->sub.trees.tb = Z_NULL;
307 {
308 uInt bl, bd;
309 inflate_huft *tl, *td;
310 inflate_codes_statef *c;
311
312 bl = 9; /* must be <= 9 for lookahead assumptions */
313 bd = 6; /* must be <= 9 for lookahead assumptions */
314 t = s->sub.trees.table;
315 t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
316 s->sub.trees.blens, &bl, &bd, &tl, &td,
317 s->hufts, z);
318 if (t != Z_OK)
319 {
320 if (t == (uInt)Z_DATA_ERROR)
321 {
322 ZFREE(z, s->sub.trees.blens);
323 s->mode = BAD;
324 }
325 r = t;
326 LEAVE
327 }
328 Tracev((stderr, "inflate: trees ok\n"));
329 if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
330 {
331 r = Z_MEM_ERROR;
332 LEAVE
333 }
334 s->sub.decode.codes = c;
335 }
336 ZFREE(z, s->sub.trees.blens);
337 s->mode = CODES;
338 case CODES:
339 UPDATE
340 if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
341 return inflate_flush(s, z, r);
342 r = Z_OK;
343 inflate_codes_free(s->sub.decode.codes, z);
344 LOAD
345 Tracev((stderr, "inflate: codes end, %lu total out\n",
346 z->total_out + (q >= s->read ? q - s->read :
347 (s->end - s->read) + (q - s->window))));
348 if (!s->last)
349 {
350 s->mode = TYPE;
351 break;
352 }
353 s->mode = DRY;
354 case DRY:
355 FLUSH
356 if (s->read != s->write)
357 LEAVE
358 s->mode = DONE;
359 case DONE:
360 r = Z_STREAM_END;
361 LEAVE
362 case BAD:
363 r = Z_DATA_ERROR;
364 LEAVE
365 default:
366 r = Z_STREAM_ERROR;
367 LEAVE
368 }
369}
370
371
372int inflate_blocks_free(s, z)
373inflate_blocks_statef *s;
374z_streamp z;
375{
376 inflate_blocks_reset(s, z, Z_NULL);
377 ZFREE(z, s->window);
378 ZFREE(z, s->hufts);
379 ZFREE(z, s);
380 Tracev((stderr, "inflate: blocks freed\n"));
381 return Z_OK;
382}
383
384
385void inflate_set_dictionary(s, d, n)
386inflate_blocks_statef *s;
387const Bytef *d;
388uInt n;
389{
390 zmemcpy(s->window, d, n);
391 s->read = s->write = s->window + n;
392}
393
394
395/* Returns true if inflate is currently at the end of a block generated
396 * by Z_SYNC_FLUSH or Z_FULL_FLUSH.
397 * IN assertion: s != Z_NULL
398 */
399int inflate_blocks_sync_point(s)
400inflate_blocks_statef *s;
401{
402 return s->mode == LENS;
403}
diff --git a/pwmanager/libcrypt/zlib/infblock.h b/pwmanager/libcrypt/zlib/infblock.h
new file mode 100644
index 0000000..173b226
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/infblock.h
@@ -0,0 +1,39 @@
1/* infblock.h -- header to use infblock.c
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11struct inflate_blocks_state;
12typedef struct inflate_blocks_state FAR inflate_blocks_statef;
13
14extern inflate_blocks_statef * inflate_blocks_new OF((
15 z_streamp z,
16 check_func c, /* check function */
17 uInt w)); /* window size */
18
19extern int inflate_blocks OF((
20 inflate_blocks_statef *,
21 z_streamp ,
22 int)); /* initial return code */
23
24extern void inflate_blocks_reset OF((
25 inflate_blocks_statef *,
26 z_streamp ,
27 uLongf *)); /* check value on output */
28
29extern int inflate_blocks_free OF((
30 inflate_blocks_statef *,
31 z_streamp));
32
33extern void inflate_set_dictionary OF((
34 inflate_blocks_statef *s,
35 const Bytef *d, /* dictionary */
36 uInt n)); /* dictionary length */
37
38extern int inflate_blocks_sync_point OF((
39 inflate_blocks_statef *s));
diff --git a/pwmanager/libcrypt/zlib/infcodes.c b/pwmanager/libcrypt/zlib/infcodes.c
new file mode 100644
index 0000000..9abe541
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/infcodes.c
@@ -0,0 +1,251 @@
1/* infcodes.c -- process literals and length/distance pairs
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8#include "infblock.h"
9#include "infcodes.h"
10#include "infutil.h"
11#include "inffast.h"
12
13/* simplify the use of the inflate_huft type with some defines */
14#define exop word.what.Exop
15#define bits word.what.Bits
16
17typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
18 START, /* x: set up for LEN */
19 LEN, /* i: get length/literal/eob next */
20 LENEXT, /* i: getting length extra (have base) */
21 DIST, /* i: get distance next */
22 DISTEXT, /* i: getting distance extra */
23 COPY, /* o: copying bytes in window, waiting for space */
24 LIT, /* o: got literal, waiting for output space */
25 WASH, /* o: got eob, possibly still output waiting */
26 END, /* x: got eob and all data flushed */
27 BADCODE} /* x: got error */
28inflate_codes_mode;
29
30/* inflate codes private state */
31struct inflate_codes_state {
32
33 /* mode */
34 inflate_codes_mode mode; /* current inflate_codes mode */
35
36 /* mode dependent information */
37 uInt len;
38 union {
39 struct {
40 inflate_huft *tree; /* pointer into tree */
41 uInt need; /* bits needed */
42 } code; /* if LEN or DIST, where in tree */
43 uInt lit; /* if LIT, literal */
44 struct {
45 uInt get; /* bits to get for extra */
46 uInt dist; /* distance back to copy from */
47 } copy; /* if EXT or COPY, where and how much */
48 } sub; /* submode */
49
50 /* mode independent information */
51 Byte lbits; /* ltree bits decoded per branch */
52 Byte dbits; /* dtree bits decoder per branch */
53 inflate_huft *ltree; /* literal/length/eob tree */
54 inflate_huft *dtree; /* distance tree */
55
56};
57
58
59inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
60uInt bl, bd;
61inflate_huft *tl;
62inflate_huft *td; /* need separate declaration for Borland C++ */
63z_streamp z;
64{
65 inflate_codes_statef *c;
66
67 if ((c = (inflate_codes_statef *)
68 ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
69 {
70 c->mode = START;
71 c->lbits = (Byte)bl;
72 c->dbits = (Byte)bd;
73 c->ltree = tl;
74 c->dtree = td;
75 Tracev((stderr, "inflate: codes new\n"));
76 }
77 return c;
78}
79
80
81int inflate_codes(s, z, r)
82inflate_blocks_statef *s;
83z_streamp z;
84int r;
85{
86 uInt j; /* temporary storage */
87 inflate_huft *t; /* temporary pointer */
88 uInt e; /* extra bits or operation */
89 uLong b; /* bit buffer */
90 uInt k; /* bits in bit buffer */
91 Bytef *p; /* input data pointer */
92 uInt n; /* bytes available there */
93 Bytef *q; /* output window write pointer */
94 uInt m; /* bytes to end of window or read pointer */
95 Bytef *f; /* pointer to copy strings from */
96 inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
97
98 /* copy input/output information to locals (UPDATE macro restores) */
99 LOAD
100
101 /* process input and output based on current state */
102 while (1) switch (c->mode)
103 { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
104 case START: /* x: set up for LEN */
105#ifndef SLOW
106 if (m >= 258 && n >= 10)
107 {
108 UPDATE
109 r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
110 LOAD
111 if (r != Z_OK)
112 {
113 c->mode = r == Z_STREAM_END ? WASH : BADCODE;
114 break;
115 }
116 }
117#endif /* !SLOW */
118 c->sub.code.need = c->lbits;
119 c->sub.code.tree = c->ltree;
120 c->mode = LEN;
121 case LEN: /* i: get length/literal/eob next */
122 j = c->sub.code.need;
123 NEEDBITS(j)
124 t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
125 DUMPBITS(t->bits)
126 e = (uInt)(t->exop);
127 if (e == 0) /* literal */
128 {
129 c->sub.lit = t->base;
130 Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
131 "inflate: literal '%c'\n" :
132 "inflate: literal 0x%02x\n", t->base));
133 c->mode = LIT;
134 break;
135 }
136 if (e & 16) /* length */
137 {
138 c->sub.copy.get = e & 15;
139 c->len = t->base;
140 c->mode = LENEXT;
141 break;
142 }
143 if ((e & 64) == 0) /* next table */
144 {
145 c->sub.code.need = e;
146 c->sub.code.tree = t + t->base;
147 break;
148 }
149 if (e & 32) /* end of block */
150 {
151 Tracevv((stderr, "inflate: end of block\n"));
152 c->mode = WASH;
153 break;
154 }
155 c->mode = BADCODE; /* invalid code */
156 z->msg = (char*)"invalid literal/length code";
157 r = Z_DATA_ERROR;
158 LEAVE
159 case LENEXT: /* i: getting length extra (have base) */
160 j = c->sub.copy.get;
161 NEEDBITS(j)
162 c->len += (uInt)b & inflate_mask[j];
163 DUMPBITS(j)
164 c->sub.code.need = c->dbits;
165 c->sub.code.tree = c->dtree;
166 Tracevv((stderr, "inflate: length %u\n", c->len));
167 c->mode = DIST;
168 case DIST: /* i: get distance next */
169 j = c->sub.code.need;
170 NEEDBITS(j)
171 t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
172 DUMPBITS(t->bits)
173 e = (uInt)(t->exop);
174 if (e & 16) /* distance */
175 {
176 c->sub.copy.get = e & 15;
177 c->sub.copy.dist = t->base;
178 c->mode = DISTEXT;
179 break;
180 }
181 if ((e & 64) == 0) /* next table */
182 {
183 c->sub.code.need = e;
184 c->sub.code.tree = t + t->base;
185 break;
186 }
187 c->mode = BADCODE; /* invalid code */
188 z->msg = (char*)"invalid distance code";
189 r = Z_DATA_ERROR;
190 LEAVE
191 case DISTEXT: /* i: getting distance extra */
192 j = c->sub.copy.get;
193 NEEDBITS(j)
194 c->sub.copy.dist += (uInt)b & inflate_mask[j];
195 DUMPBITS(j)
196 Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
197 c->mode = COPY;
198 case COPY: /* o: copying bytes in window, waiting for space */
199 f = q - c->sub.copy.dist;
200 while (f < s->window) /* modulo window size-"while" instead */
201 f += s->end - s->window; /* of "if" handles invalid distances */
202 while (c->len)
203 {
204 NEEDOUT
205 OUTBYTE(*f++)
206 if (f == s->end)
207 f = s->window;
208 c->len--;
209 }
210 c->mode = START;
211 break;
212 case LIT: /* o: got literal, waiting for output space */
213 NEEDOUT
214 OUTBYTE(c->sub.lit)
215 c->mode = START;
216 break;
217 case WASH: /* o: got eob, possibly more output */
218 if (k > 7) /* return unused byte, if any */
219 {
220 Assert(k < 16, "inflate_codes grabbed too many bytes")
221 k -= 8;
222 n++;
223 p--; /* can always return one */
224 }
225 FLUSH
226 if (s->read != s->write)
227 LEAVE
228 c->mode = END;
229 case END:
230 r = Z_STREAM_END;
231 LEAVE
232 case BADCODE: /* x: got error */
233 r = Z_DATA_ERROR;
234 LEAVE
235 default:
236 r = Z_STREAM_ERROR;
237 LEAVE
238 }
239#ifdef NEED_DUMMY_RETURN
240 return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
241#endif
242}
243
244
245void inflate_codes_free(c, z)
246inflate_codes_statef *c;
247z_streamp z;
248{
249 ZFREE(z, c);
250 Tracev((stderr, "inflate: codes free\n"));
251}
diff --git a/pwmanager/libcrypt/zlib/infcodes.h b/pwmanager/libcrypt/zlib/infcodes.h
new file mode 100644
index 0000000..46821a0
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/infcodes.h
@@ -0,0 +1,27 @@
1/* infcodes.h -- header to use infcodes.c
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11struct inflate_codes_state;
12typedef struct inflate_codes_state FAR inflate_codes_statef;
13
14extern inflate_codes_statef *inflate_codes_new OF((
15 uInt, uInt,
16 inflate_huft *, inflate_huft *,
17 z_streamp ));
18
19extern int inflate_codes OF((
20 inflate_blocks_statef *,
21 z_streamp ,
22 int));
23
24extern void inflate_codes_free OF((
25 inflate_codes_statef *,
26 z_streamp ));
27
diff --git a/pwmanager/libcrypt/zlib/inffast.c b/pwmanager/libcrypt/zlib/inffast.c
new file mode 100644
index 0000000..aa7f1d4
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/inffast.c
@@ -0,0 +1,183 @@
1/* inffast.c -- process literals and length/distance pairs fast
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8#include "infblock.h"
9#include "infcodes.h"
10#include "infutil.h"
11#include "inffast.h"
12
13struct inflate_codes_state {int dummy;}; /* for buggy compilers */
14
15/* simplify the use of the inflate_huft type with some defines */
16#define exop word.what.Exop
17#define bits word.what.Bits
18
19/* macros for bit input with no checking and for returning unused bytes */
20#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
21#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
22
23/* Called with number of bytes left to write in window at least 258
24 (the maximum string length) and number of input bytes available
25 at least ten. The ten bytes are six bytes for the longest length/
26 distance pair plus four bytes for overloading the bit buffer. */
27
28int inflate_fast(bl, bd, tl, td, s, z)
29uInt bl, bd;
30inflate_huft *tl;
31inflate_huft *td; /* need separate declaration for Borland C++ */
32inflate_blocks_statef *s;
33z_streamp z;
34{
35 inflate_huft *t; /* temporary pointer */
36 uInt e; /* extra bits or operation */
37 uLong b; /* bit buffer */
38 uInt k; /* bits in bit buffer */
39 Bytef *p; /* input data pointer */
40 uInt n; /* bytes available there */
41 Bytef *q; /* output window write pointer */
42 uInt m; /* bytes to end of window or read pointer */
43 uInt ml; /* mask for literal/length tree */
44 uInt md; /* mask for distance tree */
45 uInt c; /* bytes to copy */
46 uInt d; /* distance back to copy from */
47 Bytef *r; /* copy source pointer */
48
49 /* load input, output, bit values */
50 LOAD
51
52 /* initialize masks */
53 ml = inflate_mask[bl];
54 md = inflate_mask[bd];
55
56 /* do until not enough input or output space for fast loop */
57 do { /* assume called with m >= 258 && n >= 10 */
58 /* get literal/length code */
59 GRABBITS(20) /* max bits for literal/length code */
60 if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
61 {
62 DUMPBITS(t->bits)
63 Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
64 "inflate: * literal '%c'\n" :
65 "inflate: * literal 0x%02x\n", t->base));
66 *q++ = (Byte)t->base;
67 m--;
68 continue;
69 }
70 do {
71 DUMPBITS(t->bits)
72 if (e & 16)
73 {
74 /* get extra bits for length */
75 e &= 15;
76 c = t->base + ((uInt)b & inflate_mask[e]);
77 DUMPBITS(e)
78 Tracevv((stderr, "inflate: * length %u\n", c));
79
80 /* decode distance base of block to copy */
81 GRABBITS(15); /* max bits for distance code */
82 e = (t = td + ((uInt)b & md))->exop;
83 do {
84 DUMPBITS(t->bits)
85 if (e & 16)
86 {
87 /* get extra bits to add to distance base */
88 e &= 15;
89 GRABBITS(e) /* get extra bits (up to 13) */
90 d = t->base + ((uInt)b & inflate_mask[e]);
91 DUMPBITS(e)
92 Tracevv((stderr, "inflate: * distance %u\n", d));
93
94 /* do the copy */
95 m -= c;
96 r = q - d;
97 if (r < s->window) /* wrap if needed */
98 {
99 do {
100 r += s->end - s->window; /* force pointer in window */
101 } while (r < s->window); /* covers invalid distances */
102 e = s->end - r;
103 if (c > e)
104 {
105 c -= e; /* wrapped copy */
106 do {
107 *q++ = *r++;
108 } while (--e);
109 r = s->window;
110 do {
111 *q++ = *r++;
112 } while (--c);
113 }
114 else /* normal copy */
115 {
116 *q++ = *r++; c--;
117 *q++ = *r++; c--;
118 do {
119 *q++ = *r++;
120 } while (--c);
121 }
122 }
123 else /* normal copy */
124 {
125 *q++ = *r++; c--;
126 *q++ = *r++; c--;
127 do {
128 *q++ = *r++;
129 } while (--c);
130 }
131 break;
132 }
133 else if ((e & 64) == 0)
134 {
135 t += t->base;
136 e = (t += ((uInt)b & inflate_mask[e]))->exop;
137 }
138 else
139 {
140 z->msg = (char*)"invalid distance code";
141 UNGRAB
142 UPDATE
143 return Z_DATA_ERROR;
144 }
145 } while (1);
146 break;
147 }
148 if ((e & 64) == 0)
149 {
150 t += t->base;
151 if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
152 {
153 DUMPBITS(t->bits)
154 Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
155 "inflate: * literal '%c'\n" :
156 "inflate: * literal 0x%02x\n", t->base));
157 *q++ = (Byte)t->base;
158 m--;
159 break;
160 }
161 }
162 else if (e & 32)
163 {
164 Tracevv((stderr, "inflate: * end of block\n"));
165 UNGRAB
166 UPDATE
167 return Z_STREAM_END;
168 }
169 else
170 {
171 z->msg = (char*)"invalid literal/length code";
172 UNGRAB
173 UPDATE
174 return Z_DATA_ERROR;
175 }
176 } while (1);
177 } while (m >= 258 && n >= 10);
178
179 /* not enough input or output--restore pointers and return */
180 UNGRAB
181 UPDATE
182 return Z_OK;
183}
diff --git a/pwmanager/libcrypt/zlib/inffast.h b/pwmanager/libcrypt/zlib/inffast.h
new file mode 100644
index 0000000..a31a4bb
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/inffast.h
@@ -0,0 +1,17 @@
1/* inffast.h -- header to use inffast.c
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11extern int inflate_fast OF((
12 uInt,
13 uInt,
14 inflate_huft *,
15 inflate_huft *,
16 inflate_blocks_statef *,
17 z_streamp ));
diff --git a/pwmanager/libcrypt/zlib/inffixed.h b/pwmanager/libcrypt/zlib/inffixed.h
new file mode 100644
index 0000000..77f7e76
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/inffixed.h
@@ -0,0 +1,151 @@
1/* inffixed.h -- table for decoding fixed codes
2 * Generated automatically by the maketree.c program
3 */
4
5/* WARNING: this file should *not* be used by applications. It is
6 part of the implementation of the compression library and is
7 subject to change. Applications should only use zlib.h.
8 */
9
10local uInt fixed_bl = 9;
11local uInt fixed_bd = 5;
12local inflate_huft fixed_tl[] = {
13 {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
14 {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
15 {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
16 {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
17 {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
18 {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
19 {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
20 {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
21 {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
22 {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
23 {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
24 {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
25 {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
26 {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
27 {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
28 {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
29 {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
30 {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
31 {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
32 {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
33 {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
34 {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
35 {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
36 {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
37 {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
38 {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
39 {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
40 {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
41 {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
42 {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
43 {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
44 {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
45 {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
46 {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
47 {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
48 {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
49 {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
50 {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
51 {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
52 {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
53 {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
54 {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
55 {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
56 {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
57 {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
58 {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
59 {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
60 {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
61 {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
62 {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
63 {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
64 {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
65 {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
66 {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
67 {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
68 {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
69 {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
70 {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
71 {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
72 {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
73 {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
74 {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
75 {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
76 {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
77 {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
78 {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
79 {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
80 {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
81 {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
82 {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
83 {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
84 {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
85 {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
86 {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
87 {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
88 {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
89 {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
90 {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
91 {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
92 {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
93 {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
94 {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
95 {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
96 {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
97 {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
98 {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
99 {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
100 {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
101 {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
102 {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
103 {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
104 {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
105 {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
106 {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
107 {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
108 {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
109 {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
110 {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
111 {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
112 {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
113 {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
114 {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
115 {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
116 {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
117 {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
118 {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
119 {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
120 {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
121 {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
122 {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
123 {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
124 {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
125 {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
126 {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
127 {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
128 {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
129 {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
130 {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
131 {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
132 {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
133 {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
134 {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
135 {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
136 {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
137 {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
138 {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
139 {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
140 {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
141 };
142local inflate_huft fixed_td[] = {
143 {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
144 {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
145 {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
146 {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
147 {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
148 {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
149 {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
150 {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
151 };
diff --git a/pwmanager/libcrypt/zlib/inflate.c b/pwmanager/libcrypt/zlib/inflate.c
new file mode 100644
index 0000000..dfb2e86
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/inflate.c
@@ -0,0 +1,366 @@
1/* inflate.c -- zlib interface to inflate modules
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "infblock.h"
8
9struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
10
11typedef enum {
12 METHOD, /* waiting for method byte */
13 FLAG, /* waiting for flag byte */
14 DICT4, /* four dictionary check bytes to go */
15 DICT3, /* three dictionary check bytes to go */
16 DICT2, /* two dictionary check bytes to go */
17 DICT1, /* one dictionary check byte to go */
18 DICT0, /* waiting for inflateSetDictionary */
19 BLOCKS, /* decompressing blocks */
20 CHECK4, /* four check bytes to go */
21 CHECK3, /* three check bytes to go */
22 CHECK2, /* two check bytes to go */
23 CHECK1, /* one check byte to go */
24 DONE, /* finished check, done */
25 BAD} /* got an error--stay here */
26inflate_mode;
27
28/* inflate private state */
29struct internal_state {
30
31 /* mode */
32 inflate_mode mode; /* current inflate mode */
33
34 /* mode dependent information */
35 union {
36 uInt method; /* if FLAGS, method byte */
37 struct {
38 uLong was; /* computed check value */
39 uLong need; /* stream check value */
40 } check; /* if CHECK, check values to compare */
41 uInt marker; /* if BAD, inflateSync's marker bytes count */
42 } sub; /* submode */
43
44 /* mode independent information */
45 int nowrap; /* flag for no wrapper */
46 uInt wbits; /* log2(window size) (8..15, defaults to 15) */
47 inflate_blocks_statef
48 *blocks; /* current inflate_blocks state */
49
50};
51
52
53int ZEXPORT inflateReset(z)
54z_streamp z;
55{
56 if (z == Z_NULL || z->state == Z_NULL)
57 return Z_STREAM_ERROR;
58 z->total_in = z->total_out = 0;
59 z->msg = Z_NULL;
60 z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
61 inflate_blocks_reset(z->state->blocks, z, Z_NULL);
62 Tracev((stderr, "inflate: reset\n"));
63 return Z_OK;
64}
65
66
67int ZEXPORT inflateEnd(z)
68z_streamp z;
69{
70 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
71 return Z_STREAM_ERROR;
72 if (z->state->blocks != Z_NULL)
73 inflate_blocks_free(z->state->blocks, z);
74 ZFREE(z, z->state);
75 z->state = Z_NULL;
76 Tracev((stderr, "inflate: end\n"));
77 return Z_OK;
78}
79
80
81int ZEXPORT inflateInit2_(z, w, version, stream_size)
82z_streamp z;
83int w;
84const char *version;
85int stream_size;
86{
87 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
88 stream_size != sizeof(z_stream))
89 return Z_VERSION_ERROR;
90
91 /* initialize state */
92 if (z == Z_NULL)
93 return Z_STREAM_ERROR;
94 z->msg = Z_NULL;
95 if (z->zalloc == Z_NULL)
96 {
97 z->zalloc = zcalloc;
98 z->opaque = (voidpf)0;
99 }
100 if (z->zfree == Z_NULL) z->zfree = zcfree;
101 if ((z->state = (struct internal_state FAR *)
102 ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
103 return Z_MEM_ERROR;
104 z->state->blocks = Z_NULL;
105
106 /* handle undocumented nowrap option (no zlib header or check) */
107 z->state->nowrap = 0;
108 if (w < 0)
109 {
110 w = - w;
111 z->state->nowrap = 1;
112 }
113
114 /* set window size */
115 if (w < 8 || w > 15)
116 {
117 inflateEnd(z);
118 return Z_STREAM_ERROR;
119 }
120 z->state->wbits = (uInt)w;
121
122 /* create inflate_blocks state */
123 if ((z->state->blocks =
124 inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
125 == Z_NULL)
126 {
127 inflateEnd(z);
128 return Z_MEM_ERROR;
129 }
130 Tracev((stderr, "inflate: allocated\n"));
131
132 /* reset state */
133 inflateReset(z);
134 return Z_OK;
135}
136
137
138int ZEXPORT inflateInit_(z, version, stream_size)
139z_streamp z;
140const char *version;
141int stream_size;
142{
143 return inflateInit2_(z, DEF_WBITS, version, stream_size);
144}
145
146
147#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
148#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
149
150int ZEXPORT inflate(z, f)
151z_streamp z;
152int f;
153{
154 int r;
155 uInt b;
156
157 if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
158 return Z_STREAM_ERROR;
159 f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
160 r = Z_BUF_ERROR;
161 while (1) switch (z->state->mode)
162 {
163 case METHOD:
164 NEEDBYTE
165 if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
166 {
167 z->state->mode = BAD;
168 z->msg = (char*)"unknown compression method";
169 z->state->sub.marker = 5; /* can't try inflateSync */
170 break;
171 }
172 if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
173 {
174 z->state->mode = BAD;
175 z->msg = (char*)"invalid window size";
176 z->state->sub.marker = 5; /* can't try inflateSync */
177 break;
178 }
179 z->state->mode = FLAG;
180 case FLAG:
181 NEEDBYTE
182 b = NEXTBYTE;
183 if (((z->state->sub.method << 8) + b) % 31)
184 {
185 z->state->mode = BAD;
186 z->msg = (char*)"incorrect header check";
187 z->state->sub.marker = 5; /* can't try inflateSync */
188 break;
189 }
190 Tracev((stderr, "inflate: zlib header ok\n"));
191 if (!(b & PRESET_DICT))
192 {
193 z->state->mode = BLOCKS;
194 break;
195 }
196 z->state->mode = DICT4;
197 case DICT4:
198 NEEDBYTE
199 z->state->sub.check.need = (uLong)NEXTBYTE << 24;
200 z->state->mode = DICT3;
201 case DICT3:
202 NEEDBYTE
203 z->state->sub.check.need += (uLong)NEXTBYTE << 16;
204 z->state->mode = DICT2;
205 case DICT2:
206 NEEDBYTE
207 z->state->sub.check.need += (uLong)NEXTBYTE << 8;
208 z->state->mode = DICT1;
209 case DICT1:
210 NEEDBYTE
211 z->state->sub.check.need += (uLong)NEXTBYTE;
212 z->adler = z->state->sub.check.need;
213 z->state->mode = DICT0;
214 return Z_NEED_DICT;
215 case DICT0:
216 z->state->mode = BAD;
217 z->msg = (char*)"need dictionary";
218 z->state->sub.marker = 0; /* can try inflateSync */
219 return Z_STREAM_ERROR;
220 case BLOCKS:
221 r = inflate_blocks(z->state->blocks, z, r);
222 if (r == Z_DATA_ERROR)
223 {
224 z->state->mode = BAD;
225 z->state->sub.marker = 0; /* can try inflateSync */
226 break;
227 }
228 if (r == Z_OK)
229 r = f;
230 if (r != Z_STREAM_END)
231 return r;
232 r = f;
233 inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
234 if (z->state->nowrap)
235 {
236 z->state->mode = DONE;
237 break;
238 }
239 z->state->mode = CHECK4;
240 case CHECK4:
241 NEEDBYTE
242 z->state->sub.check.need = (uLong)NEXTBYTE << 24;
243 z->state->mode = CHECK3;
244 case CHECK3:
245 NEEDBYTE
246 z->state->sub.check.need += (uLong)NEXTBYTE << 16;
247 z->state->mode = CHECK2;
248 case CHECK2:
249 NEEDBYTE
250 z->state->sub.check.need += (uLong)NEXTBYTE << 8;
251 z->state->mode = CHECK1;
252 case CHECK1:
253 NEEDBYTE
254 z->state->sub.check.need += (uLong)NEXTBYTE;
255
256 if (z->state->sub.check.was != z->state->sub.check.need)
257 {
258 z->state->mode = BAD;
259 z->msg = (char*)"incorrect data check";
260 z->state->sub.marker = 5; /* can't try inflateSync */
261 break;
262 }
263 Tracev((stderr, "inflate: zlib check ok\n"));
264 z->state->mode = DONE;
265 case DONE:
266 return Z_STREAM_END;
267 case BAD:
268 return Z_DATA_ERROR;
269 default:
270 return Z_STREAM_ERROR;
271 }
272#ifdef NEED_DUMMY_RETURN
273 return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
274#endif
275}
276
277
278int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
279z_streamp z;
280const Bytef *dictionary;
281uInt dictLength;
282{
283 uInt length = dictLength;
284
285 if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
286 return Z_STREAM_ERROR;
287
288 if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
289 z->adler = 1L;
290
291 if (length >= ((uInt)1<<z->state->wbits))
292 {
293 length = (1<<z->state->wbits)-1;
294 dictionary += dictLength - length;
295 }
296 inflate_set_dictionary(z->state->blocks, dictionary, length);
297 z->state->mode = BLOCKS;
298 return Z_OK;
299}
300
301
302int ZEXPORT inflateSync(z)
303z_streamp z;
304{
305 uInt n; /* number of bytes to look at */
306 Bytef *p; /* pointer to bytes */
307 uInt m; /* number of marker bytes found in a row */
308 uLong r, w; /* temporaries to save total_in and total_out */
309
310 /* set up */
311 if (z == Z_NULL || z->state == Z_NULL)
312 return Z_STREAM_ERROR;
313 if (z->state->mode != BAD)
314 {
315 z->state->mode = BAD;
316 z->state->sub.marker = 0;
317 }
318 if ((n = z->avail_in) == 0)
319 return Z_BUF_ERROR;
320 p = z->next_in;
321 m = z->state->sub.marker;
322
323 /* search */
324 while (n && m < 4)
325 {
326 static const Byte mark[4] = {0, 0, 0xff, 0xff};
327 if (*p == mark[m])
328 m++;
329 else if (*p)
330 m = 0;
331 else
332 m = 4 - m;
333 p++, n--;
334 }
335
336 /* restore */
337 z->total_in += p - z->next_in;
338 z->next_in = p;
339 z->avail_in = n;
340 z->state->sub.marker = m;
341
342 /* return no joy or set up to restart on a new block */
343 if (m != 4)
344 return Z_DATA_ERROR;
345 r = z->total_in; w = z->total_out;
346 inflateReset(z);
347 z->total_in = r; z->total_out = w;
348 z->state->mode = BLOCKS;
349 return Z_OK;
350}
351
352
353/* Returns true if inflate is currently at the end of a block generated
354 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
355 * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
356 * but removes the length bytes of the resulting empty stored block. When
357 * decompressing, PPP checks that at the end of input packet, inflate is
358 * waiting for these length bytes.
359 */
360int ZEXPORT inflateSyncPoint(z)
361z_streamp z;
362{
363 if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
364 return Z_STREAM_ERROR;
365 return inflate_blocks_sync_point(z->state->blocks);
366}
diff --git a/pwmanager/libcrypt/zlib/inftrees.c b/pwmanager/libcrypt/zlib/inftrees.c
new file mode 100644
index 0000000..4c32ca3
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/inftrees.c
@@ -0,0 +1,454 @@
1/* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8
9#if !defined(BUILDFIXED) && !defined(STDC)
10# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
11#endif
12
13const char inflate_copyright[] =
14 " inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
15/*
16 If you use the zlib library in a product, an acknowledgment is welcome
17 in the documentation of your product. If for some reason you cannot
18 include such an acknowledgment, I would appreciate that you keep this
19 copyright string in the executable of your product.
20 */
21struct internal_state {int dummy;}; /* for buggy compilers */
22
23/* simplify the use of the inflate_huft type with some defines */
24#define exop word.what.Exop
25#define bits word.what.Bits
26
27
28local int huft_build OF((
29 uIntf *, /* code lengths in bits */
30 uInt, /* number of codes */
31 uInt, /* number of "simple" codes */
32 const uIntf *, /* list of base values for non-simple codes */
33 const uIntf *, /* list of extra bits for non-simple codes */
34 inflate_huft * FAR*,/* result: starting table */
35 uIntf *, /* maximum lookup bits (returns actual) */
36 inflate_huft *, /* space for trees */
37 uInt *, /* hufts used in space */
38 uIntf * )); /* space for values */
39
40/* Tables for deflate from PKZIP's appnote.txt. */
41local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
42 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
43 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
44 /* see note #13 above about 258 */
45local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
46 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
47 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
48local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
49 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
50 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
51 8193, 12289, 16385, 24577};
52local const uInt cpdext[30] = { /* Extra bits for distance codes */
53 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
54 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
55 12, 12, 13, 13};
56
57/*
58 Huffman code decoding is performed using a multi-level table lookup.
59 The fastest way to decode is to simply build a lookup table whose
60 size is determined by the longest code. However, the time it takes
61 to build this table can also be a factor if the data being decoded
62 is not very long. The most common codes are necessarily the
63 shortest codes, so those codes dominate the decoding time, and hence
64 the speed. The idea is you can have a shorter table that decodes the
65 shorter, more probable codes, and then point to subsidiary tables for
66 the longer codes. The time it costs to decode the longer codes is
67 then traded against the time it takes to make longer tables.
68
69 This results of this trade are in the variables lbits and dbits
70 below. lbits is the number of bits the first level table for literal/
71 length codes can decode in one step, and dbits is the same thing for
72 the distance codes. Subsequent tables are also less than or equal to
73 those sizes. These values may be adjusted either when all of the
74 codes are shorter than that, in which case the longest code length in
75 bits is used, or when the shortest code is *longer* than the requested
76 table size, in which case the length of the shortest code in bits is
77 used.
78
79 There are two different values for the two tables, since they code a
80 different number of possibilities each. The literal/length table
81 codes 286 possible values, or in a flat code, a little over eight
82 bits. The distance table codes 30 possible values, or a little less
83 than five bits, flat. The optimum values for speed end up being
84 about one bit more than those, so lbits is 8+1 and dbits is 5+1.
85 The optimum values may differ though from machine to machine, and
86 possibly even between compilers. Your mileage may vary.
87 */
88
89
90/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
91#define BMAX 15 /* maximum bit length of any code */
92
93local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
94uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
95uInt n; /* number of codes (assumed <= 288) */
96uInt s; /* number of simple-valued codes (0..s-1) */
97const uIntf *d; /* list of base values for non-simple codes */
98const uIntf *e; /* list of extra bits for non-simple codes */
99inflate_huft * FAR *t; /* result: starting table */
100uIntf *m; /* maximum lookup bits, returns actual */
101inflate_huft *hp; /* space for trees */
102uInt *hn; /* hufts used in space */
103uIntf *v; /* working area: values in order of bit length */
104/* Given a list of code lengths and a maximum table size, make a set of
105 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
106 if the given code set is incomplete (the tables are still built in this
107 case), or Z_DATA_ERROR if the input is invalid. */
108{
109
110 uInt a; /* counter for codes of length k */
111 uInt c[BMAX+1]; /* bit length count table */
112 uInt f; /* i repeats in table every f entries */
113 int g; /* maximum code length */
114 int h; /* table level */
115 register uInt i; /* counter, current code */
116 register uInt j; /* counter */
117 register int k; /* number of bits in current code */
118 int l; /* bits per table (returned in m) */
119 uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
120 register uIntf *p; /* pointer into c[], b[], or v[] */
121 inflate_huft *q; /* points to current table */
122 struct inflate_huft_s r; /* table entry for structure assignment */
123 inflate_huft *u[BMAX]; /* table stack */
124 register int w; /* bits before this table == (l * h) */
125 uInt x[BMAX+1]; /* bit offsets, then code stack */
126 uIntf *xp; /* pointer into x */
127 int y; /* number of dummy codes added */
128 uInt z; /* number of entries in current table */
129
130
131 /* Generate counts for each bit length */
132 p = c;
133#define C0 *p++ = 0;
134#define C2 C0 C0 C0 C0
135#define C4 C2 C2 C2 C2
136 C4 /* clear c[]--assume BMAX+1 is 16 */
137 p = b; i = n;
138 do {
139 c[*p++]++; /* assume all entries <= BMAX */
140 } while (--i);
141 if (c[0] == n) /* null input--all zero length codes */
142 {
143 *t = (inflate_huft *)Z_NULL;
144 *m = 0;
145 return Z_OK;
146 }
147
148
149 /* Find minimum and maximum length, bound *m by those */
150 l = *m;
151 for (j = 1; j <= BMAX; j++)
152 if (c[j])
153 break;
154 k = j; /* minimum code length */
155 if ((uInt)l < j)
156 l = j;
157 for (i = BMAX; i; i--)
158 if (c[i])
159 break;
160 g = i; /* maximum code length */
161 if ((uInt)l > i)
162 l = i;
163 *m = l;
164
165
166 /* Adjust last length count to fill out codes, if needed */
167 for (y = 1 << j; j < i; j++, y <<= 1)
168 if ((y -= c[j]) < 0)
169 return Z_DATA_ERROR;
170 if ((y -= c[i]) < 0)
171 return Z_DATA_ERROR;
172 c[i] += y;
173
174
175 /* Generate starting offsets into the value table for each length */
176 x[1] = j = 0;
177 p = c + 1; xp = x + 2;
178 while (--i) { /* note that i == g from above */
179 *xp++ = (j += *p++);
180 }
181
182
183 /* Make a table of values in order of bit lengths */
184 p = b; i = 0;
185 do {
186 if ((j = *p++) != 0)
187 v[x[j]++] = i;
188 } while (++i < n);
189 n = x[g]; /* set n to length of v */
190
191
192 /* Generate the Huffman codes and for each, make the table entries */
193 x[0] = i = 0; /* first Huffman code is zero */
194 p = v; /* grab values in bit order */
195 h = -1; /* no tables yet--level -1 */
196 w = -l; /* bits decoded == (l * h) */
197 u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
198 q = (inflate_huft *)Z_NULL; /* ditto */
199 z = 0; /* ditto */
200
201 /* go through the bit lengths (k already is bits in shortest code) */
202 for (; k <= g; k++)
203 {
204 a = c[k];
205 while (a--)
206 {
207 /* here i is the Huffman code of length k bits for value *p */
208 /* make tables up to required level */
209 while (k > w + l)
210 {
211 h++;
212 w += l; /* previous table always l bits */
213
214 /* compute minimum size table less than or equal to l bits */
215 z = g - w;
216 z = z > (uInt)l ? l : z; /* table size upper limit */
217 if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
218 { /* too few codes for k-w bit table */
219 f -= a + 1; /* deduct codes from patterns left */
220 xp = c + k;
221 if (j < z)
222 while (++j < z) /* try smaller tables up to z bits */
223 {
224 if ((f <<= 1) <= *++xp)
225 break; /* enough codes to use up j bits */
226 f -= *xp; /* else deduct codes from patterns */
227 }
228 }
229 z = 1 << j; /* table entries for j-bit table */
230
231 /* allocate new table */
232 if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
233 return Z_DATA_ERROR; /* overflow of MANY */
234 u[h] = q = hp + *hn;
235 *hn += z;
236
237 /* connect to last table, if there is one */
238 if (h)
239 {
240 x[h] = i; /* save pattern for backing up */
241 r.bits = (Byte)l; /* bits to dump before this table */
242 r.exop = (Byte)j; /* bits in this table */
243 j = i >> (w - l);
244 r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
245 u[h-1][j] = r; /* connect to last table */
246 }
247 else
248 *t = q; /* first table is returned result */
249 }
250
251 /* set up table entry in r */
252 r.bits = (Byte)(k - w);
253 if (p >= v + n)
254 r.exop = 128 + 64; /* out of values--invalid code */
255 else if (*p < s)
256 {
257 r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
258 r.base = *p++; /* simple code is just the value */
259 }
260 else
261 {
262 r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
263 r.base = d[*p++ - s];
264 }
265
266 /* fill code-like entries with r */
267 f = 1 << (k - w);
268 for (j = i >> w; j < z; j += f)
269 q[j] = r;
270
271 /* backwards increment the k-bit code i */
272 for (j = 1 << (k - 1); i & j; j >>= 1)
273 i ^= j;
274 i ^= j;
275
276 /* backup over finished tables */
277 mask = (1 << w) - 1; /* needed on HP, cc -O bug */
278 while ((i & mask) != x[h])
279 {
280 h--; /* don't need to update q */
281 w -= l;
282 mask = (1 << w) - 1;
283 }
284 }
285 }
286
287
288 /* Return Z_BUF_ERROR if we were given an incomplete table */
289 return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
290}
291
292
293int inflate_trees_bits(c, bb, tb, hp, z)
294uIntf *c; /* 19 code lengths */
295uIntf *bb; /* bits tree desired/actual depth */
296inflate_huft * FAR *tb; /* bits tree result */
297inflate_huft *hp; /* space for trees */
298z_streamp z; /* for messages */
299{
300 int r;
301 uInt hn = 0; /* hufts used in space */
302 uIntf *v; /* work area for huft_build */
303
304 if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
305 return Z_MEM_ERROR;
306 r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
307 tb, bb, hp, &hn, v);
308 if (r == Z_DATA_ERROR)
309 z->msg = (char*)"oversubscribed dynamic bit lengths tree";
310 else if (r == Z_BUF_ERROR || *bb == 0)
311 {
312 z->msg = (char*)"incomplete dynamic bit lengths tree";
313 r = Z_DATA_ERROR;
314 }
315 ZFREE(z, v);
316 return r;
317}
318
319
320int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
321uInt nl; /* number of literal/length codes */
322uInt nd; /* number of distance codes */
323uIntf *c; /* that many (total) code lengths */
324uIntf *bl; /* literal desired/actual bit depth */
325uIntf *bd; /* distance desired/actual bit depth */
326inflate_huft * FAR *tl; /* literal/length tree result */
327inflate_huft * FAR *td; /* distance tree result */
328inflate_huft *hp; /* space for trees */
329z_streamp z; /* for messages */
330{
331 int r;
332 uInt hn = 0; /* hufts used in space */
333 uIntf *v; /* work area for huft_build */
334
335 /* allocate work area */
336 if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
337 return Z_MEM_ERROR;
338
339 /* build literal/length tree */
340 r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
341 if (r != Z_OK || *bl == 0)
342 {
343 if (r == Z_DATA_ERROR)
344 z->msg = (char*)"oversubscribed literal/length tree";
345 else if (r != Z_MEM_ERROR)
346 {
347 z->msg = (char*)"incomplete literal/length tree";
348 r = Z_DATA_ERROR;
349 }
350 ZFREE(z, v);
351 return r;
352 }
353
354 /* build distance tree */
355 r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
356 if (r != Z_OK || (*bd == 0 && nl > 257))
357 {
358 if (r == Z_DATA_ERROR)
359 z->msg = (char*)"oversubscribed distance tree";
360 else if (r == Z_BUF_ERROR) {
361#ifdef PKZIP_BUG_WORKAROUND
362 r = Z_OK;
363 }
364#else
365 z->msg = (char*)"incomplete distance tree";
366 r = Z_DATA_ERROR;
367 }
368 else if (r != Z_MEM_ERROR)
369 {
370 z->msg = (char*)"empty distance tree with lengths";
371 r = Z_DATA_ERROR;
372 }
373 ZFREE(z, v);
374 return r;
375#endif
376 }
377
378 /* done */
379 ZFREE(z, v);
380 return Z_OK;
381}
382
383
384/* build fixed tables only once--keep them here */
385#ifdef BUILDFIXED
386local int fixed_built = 0;
387#define FIXEDH 544 /* number of hufts used by fixed tables */
388local inflate_huft fixed_mem[FIXEDH];
389local uInt fixed_bl;
390local uInt fixed_bd;
391local inflate_huft *fixed_tl;
392local inflate_huft *fixed_td;
393#else
394#include "inffixed.h"
395#endif
396
397
398int inflate_trees_fixed(bl, bd, tl, td, z)
399uIntf *bl; /* literal desired/actual bit depth */
400uIntf *bd; /* distance desired/actual bit depth */
401inflate_huft * FAR *tl; /* literal/length tree result */
402inflate_huft * FAR *td; /* distance tree result */
403z_streamp z; /* for memory allocation */
404{
405#ifdef BUILDFIXED
406 /* build fixed tables if not already */
407 if (!fixed_built)
408 {
409 int k; /* temporary variable */
410 uInt f = 0; /* number of hufts used in fixed_mem */
411 uIntf *c; /* length list for huft_build */
412 uIntf *v; /* work area for huft_build */
413
414 /* allocate memory */
415 if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
416 return Z_MEM_ERROR;
417 if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
418 {
419 ZFREE(z, c);
420 return Z_MEM_ERROR;
421 }
422
423 /* literal table */
424 for (k = 0; k < 144; k++)
425 c[k] = 8;
426 for (; k < 256; k++)
427 c[k] = 9;
428 for (; k < 280; k++)
429 c[k] = 7;
430 for (; k < 288; k++)
431 c[k] = 8;
432 fixed_bl = 9;
433 huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
434 fixed_mem, &f, v);
435
436 /* distance table */
437 for (k = 0; k < 30; k++)
438 c[k] = 5;
439 fixed_bd = 5;
440 huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
441 fixed_mem, &f, v);
442
443 /* done */
444 ZFREE(z, v);
445 ZFREE(z, c);
446 fixed_built = 1;
447 }
448#endif
449 *bl = fixed_bl;
450 *bd = fixed_bd;
451 *tl = fixed_tl;
452 *td = fixed_td;
453 return Z_OK;
454}
diff --git a/pwmanager/libcrypt/zlib/inftrees.h b/pwmanager/libcrypt/zlib/inftrees.h
new file mode 100644
index 0000000..04b73b7
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/inftrees.h
@@ -0,0 +1,58 @@
1/* inftrees.h -- header to use inftrees.c
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* Huffman code lookup table entry--this entry is four bytes for machines
12 that have 16-bit pointers (e.g. PC's in the small or medium model). */
13
14typedef struct inflate_huft_s FAR inflate_huft;
15
16struct inflate_huft_s {
17 union {
18 struct {
19 Byte Exop; /* number of extra bits or operation */
20 Byte Bits; /* number of bits in this code or subcode */
21 } what;
22 uInt pad; /* pad structure to a power of 2 (4 bytes for */
23 } word; /* 16-bit, 8 bytes for 32-bit int's) */
24 uInt base; /* literal, length base, distance base,
25 or table offset */
26};
27
28/* Maximum size of dynamic tree. The maximum found in a long but non-
29 exhaustive search was 1004 huft structures (850 for length/literals
30 and 154 for distances, the latter actually the result of an
31 exhaustive search). The actual maximum is not known, but the
32 value below is more than safe. */
33#define MANY 1440
34
35extern int inflate_trees_bits OF((
36 uIntf *, /* 19 code lengths */
37 uIntf *, /* bits tree desired/actual depth */
38 inflate_huft * FAR *, /* bits tree result */
39 inflate_huft *, /* space for trees */
40 z_streamp)); /* for messages */
41
42extern int inflate_trees_dynamic OF((
43 uInt, /* number of literal/length codes */
44 uInt, /* number of distance codes */
45 uIntf *, /* that many (total) code lengths */
46 uIntf *, /* literal desired/actual bit depth */
47 uIntf *, /* distance desired/actual bit depth */
48 inflate_huft * FAR *, /* literal/length tree result */
49 inflate_huft * FAR *, /* distance tree result */
50 inflate_huft *, /* space for trees */
51 z_streamp)); /* for messages */
52
53extern int inflate_trees_fixed OF((
54 uIntf *, /* literal desired/actual bit depth */
55 uIntf *, /* distance desired/actual bit depth */
56 inflate_huft * FAR *, /* literal/length tree result */
57 inflate_huft * FAR *, /* distance tree result */
58 z_streamp)); /* for memory allocation */
diff --git a/pwmanager/libcrypt/zlib/infutil.c b/pwmanager/libcrypt/zlib/infutil.c
new file mode 100644
index 0000000..9a07622
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/infutil.c
@@ -0,0 +1,87 @@
1/* inflate_util.c -- data and routines common to blocks and codes
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "infblock.h"
8#include "inftrees.h"
9#include "infcodes.h"
10#include "infutil.h"
11
12struct inflate_codes_state {int dummy;}; /* for buggy compilers */
13
14/* And'ing with mask[n] masks the lower n bits */
15uInt inflate_mask[17] = {
16 0x0000,
17 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
18 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
19};
20
21
22/* copy as much as possible from the sliding window to the output area */
23int inflate_flush(s, z, r)
24inflate_blocks_statef *s;
25z_streamp z;
26int r;
27{
28 uInt n;
29 Bytef *p;
30 Bytef *q;
31
32 /* local copies of source and destination pointers */
33 p = z->next_out;
34 q = s->read;
35
36 /* compute number of bytes to copy as far as end of window */
37 n = (uInt)((q <= s->write ? s->write : s->end) - q);
38 if (n > z->avail_out) n = z->avail_out;
39 if (n && r == Z_BUF_ERROR) r = Z_OK;
40
41 /* update counters */
42 z->avail_out -= n;
43 z->total_out += n;
44
45 /* update check information */
46 if (s->checkfn != Z_NULL)
47 z->adler = s->check = (*s->checkfn)(s->check, q, n);
48
49 /* copy as far as end of window */
50 zmemcpy(p, q, n);
51 p += n;
52 q += n;
53
54 /* see if more to copy at beginning of window */
55 if (q == s->end)
56 {
57 /* wrap pointers */
58 q = s->window;
59 if (s->write == s->end)
60 s->write = s->window;
61
62 /* compute bytes to copy */
63 n = (uInt)(s->write - q);
64 if (n > z->avail_out) n = z->avail_out;
65 if (n && r == Z_BUF_ERROR) r = Z_OK;
66
67 /* update counters */
68 z->avail_out -= n;
69 z->total_out += n;
70
71 /* update check information */
72 if (s->checkfn != Z_NULL)
73 z->adler = s->check = (*s->checkfn)(s->check, q, n);
74
75 /* copy */
76 zmemcpy(p, q, n);
77 p += n;
78 q += n;
79 }
80
81 /* update pointers */
82 z->next_out = p;
83 s->read = q;
84
85 /* done */
86 return r;
87}
diff --git a/pwmanager/libcrypt/zlib/infutil.h b/pwmanager/libcrypt/zlib/infutil.h
new file mode 100644
index 0000000..4401df8
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/infutil.h
@@ -0,0 +1,98 @@
1/* infutil.h -- types and macros common to blocks and codes
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11#ifndef _INFUTIL_H
12#define _INFUTIL_H
13
14typedef enum {
15 TYPE, /* get type bits (3, including end bit) */
16 LENS, /* get lengths for stored */
17 STORED, /* processing stored block */
18 TABLE, /* get table lengths */
19 BTREE, /* get bit lengths tree for a dynamic block */
20 DTREE, /* get length, distance trees for a dynamic block */
21 CODES, /* processing fixed or dynamic block */
22 DRY, /* output remaining window bytes */
23 DONE, /* finished last block, done */
24 BAD} /* got a data error--stuck here */
25inflate_block_mode;
26
27/* inflate blocks semi-private state */
28struct inflate_blocks_state {
29
30 /* mode */
31 inflate_block_mode mode; /* current inflate_block mode */
32
33 /* mode dependent information */
34 union {
35 uInt left; /* if STORED, bytes left to copy */
36 struct {
37 uInt table; /* table lengths (14 bits) */
38 uInt index; /* index into blens (or border) */
39 uIntf *blens; /* bit lengths of codes */
40 uInt bb; /* bit length tree depth */
41 inflate_huft *tb; /* bit length decoding tree */
42 } trees; /* if DTREE, decoding info for trees */
43 struct {
44 inflate_codes_statef
45 *codes;
46 } decode; /* if CODES, current state */
47 } sub; /* submode */
48 uInt last; /* true if this block is the last block */
49
50 /* mode independent information */
51 uInt bitk; /* bits in bit buffer */
52 uLong bitb; /* bit buffer */
53 inflate_huft *hufts; /* single malloc for tree space */
54 Bytef *window; /* sliding window */
55 Bytef *end; /* one byte after sliding window */
56 Bytef *read; /* window read pointer */
57 Bytef *write; /* window write pointer */
58 check_func checkfn; /* check function */
59 uLong check; /* check on output */
60
61};
62
63
64/* defines for inflate input/output */
65/* update pointers and return */
66#define UPDBITS {s->bitb=b;s->bitk=k;}
67#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
68#define UPDOUT {s->write=q;}
69#define UPDATE {UPDBITS UPDIN UPDOUT}
70#define LEAVE {UPDATE return inflate_flush(s,z,r);}
71/* get bytes and bits */
72#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
73#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
74#define NEXTBYTE (n--,*p++)
75#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
76#define DUMPBITS(j) {b>>=(j);k-=(j);}
77/* output bytes */
78#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
79#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
80#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
81#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
82#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
83#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
84/* load local pointers */
85#define LOAD {LOADIN LOADOUT}
86
87/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
88extern uInt inflate_mask[17];
89
90/* copy as much as possible from the sliding window to the output area */
91extern int inflate_flush OF((
92 inflate_blocks_statef *,
93 z_streamp ,
94 int));
95
96struct internal_state {int dummy;}; /* for buggy compilers */
97
98#endif
diff --git a/pwmanager/libcrypt/zlib/trees.c b/pwmanager/libcrypt/zlib/trees.c
new file mode 100644
index 0000000..0a98405
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/trees.c
@@ -0,0 +1,1214 @@
1/* trees.c -- output deflated data using Huffman coding
2 * Copyright (C) 1995-2002 Jean-loup Gailly
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * ALGORITHM
8 *
9 * The "deflation" process uses several Huffman trees. The more
10 * common source values are represented by shorter bit sequences.
11 *
12 * Each code tree is stored in a compressed form which is itself
13 * a Huffman encoding of the lengths of all the code strings (in
14 * ascending order by source values). The actual code strings are
15 * reconstructed from the lengths in the inflate process, as described
16 * in the deflate specification.
17 *
18 * REFERENCES
19 *
20 * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
21 * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
22 *
23 * Storer, James A.
24 * Data Compression: Methods and Theory, pp. 49-50.
25 * Computer Science Press, 1988. ISBN 0-7167-8156-5.
26 *
27 * Sedgewick, R.
28 * Algorithms, p290.
29 * Addison-Wesley, 1983. ISBN 0-201-06672-6.
30 */
31
32/* @(#) $Id$ */
33
34/* #define GEN_TREES_H */
35
36#include "deflate.h"
37
38#ifdef DEBUG
39# include <ctype.h>
40#endif
41
42/* ===========================================================================
43 * Constants
44 */
45
46#define MAX_BL_BITS 7
47/* Bit length codes must not exceed MAX_BL_BITS bits */
48
49#define END_BLOCK 256
50/* end of block literal code */
51
52#define REP_3_6 16
53/* repeat previous bit length 3-6 times (2 bits of repeat count) */
54
55#define REPZ_3_10 17
56/* repeat a zero length 3-10 times (3 bits of repeat count) */
57
58#define REPZ_11_138 18
59/* repeat a zero length 11-138 times (7 bits of repeat count) */
60
61local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
62 = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
63
64local const int extra_dbits[D_CODES] /* extra bits for each distance code */
65 = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
66
67local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
68 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
69
70local const uch bl_order[BL_CODES]
71 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
72/* The lengths of the bit length codes are sent in order of decreasing
73 * probability, to avoid transmitting the lengths for unused bit length codes.
74 */
75
76#define Buf_size (8 * 2*sizeof(char))
77/* Number of bits used within bi_buf. (bi_buf might be implemented on
78 * more than 16 bits on some systems.)
79 */
80
81/* ===========================================================================
82 * Local data. These are initialized only once.
83 */
84
85#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
86
87#if defined(GEN_TREES_H) || !defined(STDC)
88/* non ANSI compilers may not accept trees.h */
89
90local ct_data static_ltree[L_CODES+2];
91/* The static literal tree. Since the bit lengths are imposed, there is no
92 * need for the L_CODES extra codes used during heap construction. However
93 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
94 * below).
95 */
96
97local ct_data static_dtree[D_CODES];
98/* The static distance tree. (Actually a trivial tree since all codes use
99 * 5 bits.)
100 */
101
102uch _dist_code[DIST_CODE_LEN];
103/* Distance codes. The first 256 values correspond to the distances
104 * 3 .. 258, the last 256 values correspond to the top 8 bits of
105 * the 15 bit distances.
106 */
107
108uch _length_code[MAX_MATCH-MIN_MATCH+1];
109/* length code for each normalized match length (0 == MIN_MATCH) */
110
111local int base_length[LENGTH_CODES];
112/* First normalized length for each code (0 = MIN_MATCH) */
113
114local int base_dist[D_CODES];
115/* First normalized distance for each code (0 = distance of 1) */
116
117#else
118# include "trees.h"
119#endif /* GEN_TREES_H */
120
121struct static_tree_desc_s {
122 const ct_data *static_tree; /* static tree or NULL */
123 const intf *extra_bits; /* extra bits for each code or NULL */
124 int extra_base; /* base index for extra_bits */
125 int elems; /* max number of elements in the tree */
126 int max_length; /* max bit length for the codes */
127};
128
129local static_tree_desc static_l_desc =
130{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
131
132local static_tree_desc static_d_desc =
133{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
134
135local static_tree_desc static_bl_desc =
136{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
137
138/* ===========================================================================
139 * Local (static) routines in this file.
140 */
141
142local void tr_static_init OF((void));
143local void init_block OF((deflate_state *s));
144local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
145local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
146local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
147local void build_tree OF((deflate_state *s, tree_desc *desc));
148local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
149local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
150local int build_bl_tree OF((deflate_state *s));
151local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
152 int blcodes));
153local void compress_block OF((deflate_state *s, ct_data *ltree,
154 ct_data *dtree));
155local void set_data_type OF((deflate_state *s));
156local unsigned bi_reverse OF((unsigned value, int length));
157local void bi_windup OF((deflate_state *s));
158local void bi_flush OF((deflate_state *s));
159local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
160 int header));
161
162#ifdef GEN_TREES_H
163local void gen_trees_header OF((void));
164#endif
165
166#ifndef DEBUG
167# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
168 /* Send a code of the given tree. c and tree must not have side effects */
169
170#else /* DEBUG */
171# define send_code(s, c, tree) \
172 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
173 send_bits(s, tree[c].Code, tree[c].Len); }
174#endif
175
176/* ===========================================================================
177 * Output a short LSB first on the stream.
178 * IN assertion: there is enough room in pendingBuf.
179 */
180#define put_short(s, w) { \
181 put_byte(s, (uch)((w) & 0xff)); \
182 put_byte(s, (uch)((ush)(w) >> 8)); \
183}
184
185/* ===========================================================================
186 * Send a value on a given number of bits.
187 * IN assertion: length <= 16 and value fits in length bits.
188 */
189#ifdef DEBUG
190local void send_bits OF((deflate_state *s, int value, int length));
191
192local void send_bits(s, value, length)
193 deflate_state *s;
194 int value; /* value to send */
195 int length; /* number of bits */
196{
197 Tracevv((stderr," l %2d v %4x ", length, value));
198 Assert(length > 0 && length <= 15, "invalid length");
199 s->bits_sent += (ulg)length;
200
201 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
202 * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
203 * unused bits in value.
204 */
205 if (s->bi_valid > (int)Buf_size - length) {
206 s->bi_buf |= (value << s->bi_valid);
207 put_short(s, s->bi_buf);
208 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
209 s->bi_valid += length - Buf_size;
210 } else {
211 s->bi_buf |= value << s->bi_valid;
212 s->bi_valid += length;
213 }
214}
215#else /* !DEBUG */
216
217#define send_bits(s, value, length) \
218{ int len = length;\
219 if (s->bi_valid > (int)Buf_size - len) {\
220 int val = value;\
221 s->bi_buf |= (val << s->bi_valid);\
222 put_short(s, s->bi_buf);\
223 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
224 s->bi_valid += len - Buf_size;\
225 } else {\
226 s->bi_buf |= (value) << s->bi_valid;\
227 s->bi_valid += len;\
228 }\
229}
230#endif /* DEBUG */
231
232
233#define MAX(a,b) (a >= b ? a : b)
234/* the arguments must not have side effects */
235
236/* ===========================================================================
237 * Initialize the various 'constant' tables.
238 */
239local void tr_static_init()
240{
241#if defined(GEN_TREES_H) || !defined(STDC)
242 static int static_init_done = 0;
243 int n; /* iterates over tree elements */
244 int bits; /* bit counter */
245 int length; /* length value */
246 int code; /* code value */
247 int dist; /* distance index */
248 ush bl_count[MAX_BITS+1];
249 /* number of codes at each bit length for an optimal tree */
250
251 if (static_init_done) return;
252
253 /* For some embedded targets, global variables are not initialized: */
254 static_l_desc.static_tree = static_ltree;
255 static_l_desc.extra_bits = extra_lbits;
256 static_d_desc.static_tree = static_dtree;
257 static_d_desc.extra_bits = extra_dbits;
258 static_bl_desc.extra_bits = extra_blbits;
259
260 /* Initialize the mapping length (0..255) -> length code (0..28) */
261 length = 0;
262 for (code = 0; code < LENGTH_CODES-1; code++) {
263 base_length[code] = length;
264 for (n = 0; n < (1<<extra_lbits[code]); n++) {
265 _length_code[length++] = (uch)code;
266 }
267 }
268 Assert (length == 256, "tr_static_init: length != 256");
269 /* Note that the length 255 (match length 258) can be represented
270 * in two different ways: code 284 + 5 bits or code 285, so we
271 * overwrite length_code[255] to use the best encoding:
272 */
273 _length_code[length-1] = (uch)code;
274
275 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
276 dist = 0;
277 for (code = 0 ; code < 16; code++) {
278 base_dist[code] = dist;
279 for (n = 0; n < (1<<extra_dbits[code]); n++) {
280 _dist_code[dist++] = (uch)code;
281 }
282 }
283 Assert (dist == 256, "tr_static_init: dist != 256");
284 dist >>= 7; /* from now on, all distances are divided by 128 */
285 for ( ; code < D_CODES; code++) {
286 base_dist[code] = dist << 7;
287 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
288 _dist_code[256 + dist++] = (uch)code;
289 }
290 }
291 Assert (dist == 256, "tr_static_init: 256+dist != 512");
292
293 /* Construct the codes of the static literal tree */
294 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
295 n = 0;
296 while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
297 while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
298 while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
299 while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
300 /* Codes 286 and 287 do not exist, but we must include them in the
301 * tree construction to get a canonical Huffman tree (longest code
302 * all ones)
303 */
304 gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
305
306 /* The static distance tree is trivial: */
307 for (n = 0; n < D_CODES; n++) {
308 static_dtree[n].Len = 5;
309 static_dtree[n].Code = bi_reverse((unsigned)n, 5);
310 }
311 static_init_done = 1;
312
313# ifdef GEN_TREES_H
314 gen_trees_header();
315# endif
316#endif /* defined(GEN_TREES_H) || !defined(STDC) */
317}
318
319/* ===========================================================================
320 * Genererate the file trees.h describing the static trees.
321 */
322#ifdef GEN_TREES_H
323# ifndef DEBUG
324# include <stdio.h>
325# endif
326
327# define SEPARATOR(i, last, width) \
328 ((i) == (last)? "\n};\n\n" : \
329 ((i) % (width) == (width)-1 ? ",\n" : ", "))
330
331void gen_trees_header()
332{
333 FILE *header = fopen("trees.h", "w");
334 int i;
335
336 Assert (header != NULL, "Can't open trees.h");
337 fprintf(header,
338 "/* header created automatically with -DGEN_TREES_H */\n\n");
339
340 fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
341 for (i = 0; i < L_CODES+2; i++) {
342 fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
343 static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
344 }
345
346 fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
347 for (i = 0; i < D_CODES; i++) {
348 fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
349 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
350 }
351
352 fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
353 for (i = 0; i < DIST_CODE_LEN; i++) {
354 fprintf(header, "%2u%s", _dist_code[i],
355 SEPARATOR(i, DIST_CODE_LEN-1, 20));
356 }
357
358 fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
359 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
360 fprintf(header, "%2u%s", _length_code[i],
361 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
362 }
363
364 fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
365 for (i = 0; i < LENGTH_CODES; i++) {
366 fprintf(header, "%1u%s", base_length[i],
367 SEPARATOR(i, LENGTH_CODES-1, 20));
368 }
369
370 fprintf(header, "local const int base_dist[D_CODES] = {\n");
371 for (i = 0; i < D_CODES; i++) {
372 fprintf(header, "%5u%s", base_dist[i],
373 SEPARATOR(i, D_CODES-1, 10));
374 }
375
376 fclose(header);
377}
378#endif /* GEN_TREES_H */
379
380/* ===========================================================================
381 * Initialize the tree data structures for a new zlib stream.
382 */
383void _tr_init(s)
384 deflate_state *s;
385{
386 tr_static_init();
387
388 s->l_desc.dyn_tree = s->dyn_ltree;
389 s->l_desc.stat_desc = &static_l_desc;
390
391 s->d_desc.dyn_tree = s->dyn_dtree;
392 s->d_desc.stat_desc = &static_d_desc;
393
394 s->bl_desc.dyn_tree = s->bl_tree;
395 s->bl_desc.stat_desc = &static_bl_desc;
396
397 s->bi_buf = 0;
398 s->bi_valid = 0;
399 s->last_eob_len = 8; /* enough lookahead for inflate */
400#ifdef DEBUG
401 s->compressed_len = 0L;
402 s->bits_sent = 0L;
403#endif
404
405 /* Initialize the first block of the first file: */
406 init_block(s);
407}
408
409/* ===========================================================================
410 * Initialize a new block.
411 */
412local void init_block(s)
413 deflate_state *s;
414{
415 int n; /* iterates over tree elements */
416
417 /* Initialize the trees. */
418 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
419 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
420 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
421
422 s->dyn_ltree[END_BLOCK].Freq = 1;
423 s->opt_len = s->static_len = 0L;
424 s->last_lit = s->matches = 0;
425}
426
427#define SMALLEST 1
428/* Index within the heap array of least frequent node in the Huffman tree */
429
430
431/* ===========================================================================
432 * Remove the smallest element from the heap and recreate the heap with
433 * one less element. Updates heap and heap_len.
434 */
435#define pqremove(s, tree, top) \
436{\
437 top = s->heap[SMALLEST]; \
438 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
439 pqdownheap(s, tree, SMALLEST); \
440}
441
442/* ===========================================================================
443 * Compares to subtrees, using the tree depth as tie breaker when
444 * the subtrees have equal frequency. This minimizes the worst case length.
445 */
446#define smaller(tree, n, m, depth) \
447 (tree[n].Freq < tree[m].Freq || \
448 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
449
450/* ===========================================================================
451 * Restore the heap property by moving down the tree starting at node k,
452 * exchanging a node with the smallest of its two sons if necessary, stopping
453 * when the heap property is re-established (each father smaller than its
454 * two sons).
455 */
456local void pqdownheap(s, tree, k)
457 deflate_state *s;
458 ct_data *tree; /* the tree to restore */
459 int k; /* node to move down */
460{
461 int v = s->heap[k];
462 int j = k << 1; /* left son of k */
463 while (j <= s->heap_len) {
464 /* Set j to the smallest of the two sons: */
465 if (j < s->heap_len &&
466 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
467 j++;
468 }
469 /* Exit if v is smaller than both sons */
470 if (smaller(tree, v, s->heap[j], s->depth)) break;
471
472 /* Exchange v with the smallest son */
473 s->heap[k] = s->heap[j]; k = j;
474
475 /* And continue down the tree, setting j to the left son of k */
476 j <<= 1;
477 }
478 s->heap[k] = v;
479}
480
481/* ===========================================================================
482 * Compute the optimal bit lengths for a tree and update the total bit length
483 * for the current block.
484 * IN assertion: the fields freq and dad are set, heap[heap_max] and
485 * above are the tree nodes sorted by increasing frequency.
486 * OUT assertions: the field len is set to the optimal bit length, the
487 * array bl_count contains the frequencies for each bit length.
488 * The length opt_len is updated; static_len is also updated if stree is
489 * not null.
490 */
491local void gen_bitlen(s, desc)
492 deflate_state *s;
493 tree_desc *desc; /* the tree descriptor */
494{
495 ct_data *tree = desc->dyn_tree;
496 int max_code = desc->max_code;
497 const ct_data *stree = desc->stat_desc->static_tree;
498 const intf *extra = desc->stat_desc->extra_bits;
499 int base = desc->stat_desc->extra_base;
500 int max_length = desc->stat_desc->max_length;
501 int h; /* heap index */
502 int n, m; /* iterate over the tree elements */
503 int bits; /* bit length */
504 int xbits; /* extra bits */
505 ush f; /* frequency */
506 int overflow = 0; /* number of elements with bit length too large */
507
508 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
509
510 /* In a first pass, compute the optimal bit lengths (which may
511 * overflow in the case of the bit length tree).
512 */
513 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
514
515 for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
516 n = s->heap[h];
517 bits = tree[tree[n].Dad].Len + 1;
518 if (bits > max_length) bits = max_length, overflow++;
519 tree[n].Len = (ush)bits;
520 /* We overwrite tree[n].Dad which is no longer needed */
521
522 if (n > max_code) continue; /* not a leaf node */
523
524 s->bl_count[bits]++;
525 xbits = 0;
526 if (n >= base) xbits = extra[n-base];
527 f = tree[n].Freq;
528 s->opt_len += (ulg)f * (bits + xbits);
529 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
530 }
531 if (overflow == 0) return;
532
533 Trace((stderr,"\nbit length overflow\n"));
534 /* This happens for example on obj2 and pic of the Calgary corpus */
535
536 /* Find the first bit length which could increase: */
537 do {
538 bits = max_length-1;
539 while (s->bl_count[bits] == 0) bits--;
540 s->bl_count[bits]--; /* move one leaf down the tree */
541 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
542 s->bl_count[max_length]--;
543 /* The brother of the overflow item also moves one step up,
544 * but this does not affect bl_count[max_length]
545 */
546 overflow -= 2;
547 } while (overflow > 0);
548
549 /* Now recompute all bit lengths, scanning in increasing frequency.
550 * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
551 * lengths instead of fixing only the wrong ones. This idea is taken
552 * from 'ar' written by Haruhiko Okumura.)
553 */
554 for (bits = max_length; bits != 0; bits--) {
555 n = s->bl_count[bits];
556 while (n != 0) {
557 m = s->heap[--h];
558 if (m > max_code) continue;
559 if (tree[m].Len != (unsigned) bits) {
560 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
561 s->opt_len += ((long)bits - (long)tree[m].Len)
562 *(long)tree[m].Freq;
563 tree[m].Len = (ush)bits;
564 }
565 n--;
566 }
567 }
568}
569
570/* ===========================================================================
571 * Generate the codes for a given tree and bit counts (which need not be
572 * optimal).
573 * IN assertion: the array bl_count contains the bit length statistics for
574 * the given tree and the field len is set for all tree elements.
575 * OUT assertion: the field code is set for all tree elements of non
576 * zero code length.
577 */
578local void gen_codes (tree, max_code, bl_count)
579 ct_data *tree; /* the tree to decorate */
580 int max_code; /* largest code with non zero frequency */
581 ushf *bl_count; /* number of codes at each bit length */
582{
583 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
584 ush code = 0; /* running code value */
585 int bits; /* bit index */
586 int n; /* code index */
587
588 /* The distribution counts are first used to generate the code values
589 * without bit reversal.
590 */
591 for (bits = 1; bits <= MAX_BITS; bits++) {
592 next_code[bits] = code = (code + bl_count[bits-1]) << 1;
593 }
594 /* Check that the bit counts in bl_count are consistent. The last code
595 * must be all ones.
596 */
597 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
598 "inconsistent bit counts");
599 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
600
601 for (n = 0; n <= max_code; n++) {
602 int len = tree[n].Len;
603 if (len == 0) continue;
604 /* Now reverse the bits */
605 tree[n].Code = bi_reverse(next_code[len]++, len);
606
607 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
608 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
609 }
610}
611
612/* ===========================================================================
613 * Construct one Huffman tree and assigns the code bit strings and lengths.
614 * Update the total bit length for the current block.
615 * IN assertion: the field freq is set for all tree elements.
616 * OUT assertions: the fields len and code are set to the optimal bit length
617 * and corresponding code. The length opt_len is updated; static_len is
618 * also updated if stree is not null. The field max_code is set.
619 */
620local void build_tree(s, desc)
621 deflate_state *s;
622 tree_desc *desc; /* the tree descriptor */
623{
624 ct_data *tree = desc->dyn_tree;
625 const ct_data *stree = desc->stat_desc->static_tree;
626 int elems = desc->stat_desc->elems;
627 int n, m; /* iterate over heap elements */
628 int max_code = -1; /* largest code with non zero frequency */
629 int node; /* new node being created */
630
631 /* Construct the initial heap, with least frequent element in
632 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
633 * heap[0] is not used.
634 */
635 s->heap_len = 0, s->heap_max = HEAP_SIZE;
636
637 for (n = 0; n < elems; n++) {
638 if (tree[n].Freq != 0) {
639 s->heap[++(s->heap_len)] = max_code = n;
640 s->depth[n] = 0;
641 } else {
642 tree[n].Len = 0;
643 }
644 }
645
646 /* The pkzip format requires that at least one distance code exists,
647 * and that at least one bit should be sent even if there is only one
648 * possible code. So to avoid special checks later on we force at least
649 * two codes of non zero frequency.
650 */
651 while (s->heap_len < 2) {
652 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
653 tree[node].Freq = 1;
654 s->depth[node] = 0;
655 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
656 /* node is 0 or 1 so it does not have extra bits */
657 }
658 desc->max_code = max_code;
659
660 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
661 * establish sub-heaps of increasing lengths:
662 */
663 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
664
665 /* Construct the Huffman tree by repeatedly combining the least two
666 * frequent nodes.
667 */
668 node = elems; /* next internal node of the tree */
669 do {
670 pqremove(s, tree, n); /* n = node of least frequency */
671 m = s->heap[SMALLEST]; /* m = node of next least frequency */
672
673 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
674 s->heap[--(s->heap_max)] = m;
675
676 /* Create a new node father of n and m */
677 tree[node].Freq = tree[n].Freq + tree[m].Freq;
678 s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
679 tree[n].Dad = tree[m].Dad = (ush)node;
680#ifdef DUMP_BL_TREE
681 if (tree == s->bl_tree) {
682 fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
683 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
684 }
685#endif
686 /* and insert the new node in the heap */
687 s->heap[SMALLEST] = node++;
688 pqdownheap(s, tree, SMALLEST);
689
690 } while (s->heap_len >= 2);
691
692 s->heap[--(s->heap_max)] = s->heap[SMALLEST];
693
694 /* At this point, the fields freq and dad are set. We can now
695 * generate the bit lengths.
696 */
697 gen_bitlen(s, (tree_desc *)desc);
698
699 /* The field len is now set, we can generate the bit codes */
700 gen_codes ((ct_data *)tree, max_code, s->bl_count);
701}
702
703/* ===========================================================================
704 * Scan a literal or distance tree to determine the frequencies of the codes
705 * in the bit length tree.
706 */
707local void scan_tree (s, tree, max_code)
708 deflate_state *s;
709 ct_data *tree; /* the tree to be scanned */
710 int max_code; /* and its largest code of non zero frequency */
711{
712 int n; /* iterates over all tree elements */
713 int prevlen = -1; /* last emitted length */
714 int curlen; /* length of current code */
715 int nextlen = tree[0].Len; /* length of next code */
716 int count = 0; /* repeat count of the current code */
717 int max_count = 7; /* max repeat count */
718 int min_count = 4; /* min repeat count */
719
720 if (nextlen == 0) max_count = 138, min_count = 3;
721 tree[max_code+1].Len = (ush)0xffff; /* guard */
722
723 for (n = 0; n <= max_code; n++) {
724 curlen = nextlen; nextlen = tree[n+1].Len;
725 if (++count < max_count && curlen == nextlen) {
726 continue;
727 } else if (count < min_count) {
728 s->bl_tree[curlen].Freq += count;
729 } else if (curlen != 0) {
730 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
731 s->bl_tree[REP_3_6].Freq++;
732 } else if (count <= 10) {
733 s->bl_tree[REPZ_3_10].Freq++;
734 } else {
735 s->bl_tree[REPZ_11_138].Freq++;
736 }
737 count = 0; prevlen = curlen;
738 if (nextlen == 0) {
739 max_count = 138, min_count = 3;
740 } else if (curlen == nextlen) {
741 max_count = 6, min_count = 3;
742 } else {
743 max_count = 7, min_count = 4;
744 }
745 }
746}
747
748/* ===========================================================================
749 * Send a literal or distance tree in compressed form, using the codes in
750 * bl_tree.
751 */
752local void send_tree (s, tree, max_code)
753 deflate_state *s;
754 ct_data *tree; /* the tree to be scanned */
755 int max_code; /* and its largest code of non zero frequency */
756{
757 int n; /* iterates over all tree elements */
758 int prevlen = -1; /* last emitted length */
759 int curlen; /* length of current code */
760 int nextlen = tree[0].Len; /* length of next code */
761 int count = 0; /* repeat count of the current code */
762 int max_count = 7; /* max repeat count */
763 int min_count = 4; /* min repeat count */
764
765 /* tree[max_code+1].Len = -1; */ /* guard already set */
766 if (nextlen == 0) max_count = 138, min_count = 3;
767
768 for (n = 0; n <= max_code; n++) {
769 curlen = nextlen; nextlen = tree[n+1].Len;
770 if (++count < max_count && curlen == nextlen) {
771 continue;
772 } else if (count < min_count) {
773 do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
774
775 } else if (curlen != 0) {
776 if (curlen != prevlen) {
777 send_code(s, curlen, s->bl_tree); count--;
778 }
779 Assert(count >= 3 && count <= 6, " 3_6?");
780 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
781
782 } else if (count <= 10) {
783 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
784
785 } else {
786 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
787 }
788 count = 0; prevlen = curlen;
789 if (nextlen == 0) {
790 max_count = 138, min_count = 3;
791 } else if (curlen == nextlen) {
792 max_count = 6, min_count = 3;
793 } else {
794 max_count = 7, min_count = 4;
795 }
796 }
797}
798
799/* ===========================================================================
800 * Construct the Huffman tree for the bit lengths and return the index in
801 * bl_order of the last bit length code to send.
802 */
803local int build_bl_tree(s)
804 deflate_state *s;
805{
806 int max_blindex; /* index of last bit length code of non zero freq */
807
808 /* Determine the bit length frequencies for literal and distance trees */
809 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
810 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
811
812 /* Build the bit length tree: */
813 build_tree(s, (tree_desc *)(&(s->bl_desc)));
814 /* opt_len now includes the length of the tree representations, except
815 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
816 */
817
818 /* Determine the number of bit length codes to send. The pkzip format
819 * requires that at least 4 bit length codes be sent. (appnote.txt says
820 * 3 but the actual value used is 4.)
821 */
822 for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
823 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
824 }
825 /* Update opt_len to include the bit length tree and counts */
826 s->opt_len += 3*(max_blindex+1) + 5+5+4;
827 Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
828 s->opt_len, s->static_len));
829
830 return max_blindex;
831}
832
833/* ===========================================================================
834 * Send the header for a block using dynamic Huffman trees: the counts, the
835 * lengths of the bit length codes, the literal tree and the distance tree.
836 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
837 */
838local void send_all_trees(s, lcodes, dcodes, blcodes)
839 deflate_state *s;
840 int lcodes, dcodes, blcodes; /* number of codes for each tree */
841{
842 int rank; /* index in bl_order */
843
844 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
845 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
846 "too many codes");
847 Tracev((stderr, "\nbl counts: "));
848 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
849 send_bits(s, dcodes-1, 5);
850 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
851 for (rank = 0; rank < blcodes; rank++) {
852 Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
853 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
854 }
855 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
856
857 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
858 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
859
860 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
861 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
862}
863
864/* ===========================================================================
865 * Send a stored block
866 */
867void _tr_stored_block(s, buf, stored_len, eof)
868 deflate_state *s;
869 charf *buf; /* input block */
870 ulg stored_len; /* length of input block */
871 int eof; /* true if this is the last block for a file */
872{
873 send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
874#ifdef DEBUG
875 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
876 s->compressed_len += (stored_len + 4) << 3;
877#endif
878 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
879}
880
881/* ===========================================================================
882 * Send one empty static block to give enough lookahead for inflate.
883 * This takes 10 bits, of which 7 may remain in the bit buffer.
884 * The current inflate code requires 9 bits of lookahead. If the
885 * last two codes for the previous block (real code plus EOB) were coded
886 * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
887 * the last real code. In this case we send two empty static blocks instead
888 * of one. (There are no problems if the previous block is stored or fixed.)
889 * To simplify the code, we assume the worst case of last real code encoded
890 * on one bit only.
891 */
892void _tr_align(s)
893 deflate_state *s;
894{
895 send_bits(s, STATIC_TREES<<1, 3);
896 send_code(s, END_BLOCK, static_ltree);
897#ifdef DEBUG
898 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
899#endif
900 bi_flush(s);
901 /* Of the 10 bits for the empty block, we have already sent
902 * (10 - bi_valid) bits. The lookahead for the last real code (before
903 * the EOB of the previous block) was thus at least one plus the length
904 * of the EOB plus what we have just sent of the empty static block.
905 */
906 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
907 send_bits(s, STATIC_TREES<<1, 3);
908 send_code(s, END_BLOCK, static_ltree);
909#ifdef DEBUG
910 s->compressed_len += 10L;
911#endif
912 bi_flush(s);
913 }
914 s->last_eob_len = 7;
915}
916
917/* ===========================================================================
918 * Determine the best encoding for the current block: dynamic trees, static
919 * trees or store, and output the encoded block to the zip file.
920 */
921void _tr_flush_block(s, buf, stored_len, eof)
922 deflate_state *s;
923 charf *buf; /* input block, or NULL if too old */
924 ulg stored_len; /* length of input block */
925 int eof; /* true if this is the last block for a file */
926{
927 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
928 int max_blindex = 0; /* index of last bit length code of non zero freq */
929
930 /* Build the Huffman trees unless a stored block is forced */
931 if (s->level > 0) {
932
933 /* Check if the file is ascii or binary */
934 if (s->data_type == Z_UNKNOWN) set_data_type(s);
935
936 /* Construct the literal and distance trees */
937 build_tree(s, (tree_desc *)(&(s->l_desc)));
938 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
939 s->static_len));
940
941 build_tree(s, (tree_desc *)(&(s->d_desc)));
942 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
943 s->static_len));
944 /* At this point, opt_len and static_len are the total bit lengths of
945 * the compressed block data, excluding the tree representations.
946 */
947
948 /* Build the bit length tree for the above two trees, and get the index
949 * in bl_order of the last bit length code to send.
950 */
951 max_blindex = build_bl_tree(s);
952
953 /* Determine the best encoding. Compute first the block length in bytes*/
954 opt_lenb = (s->opt_len+3+7)>>3;
955 static_lenb = (s->static_len+3+7)>>3;
956
957 Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
958 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
959 s->last_lit));
960
961 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
962
963 } else {
964 Assert(buf != (char*)0, "lost buf");
965 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
966 }
967
968#ifdef FORCE_STORED
969 if (buf != (char*)0) { /* force stored block */
970#else
971 if (stored_len+4 <= opt_lenb && buf != (char*)0) {
972 /* 4: two words for the lengths */
973#endif
974 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
975 * Otherwise we can't have processed more than WSIZE input bytes since
976 * the last block flush, because compression would have been
977 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
978 * transform a block into a stored block.
979 */
980 _tr_stored_block(s, buf, stored_len, eof);
981
982#ifdef FORCE_STATIC
983 } else if (static_lenb >= 0) { /* force static trees */
984#else
985 } else if (static_lenb == opt_lenb) {
986#endif
987 send_bits(s, (STATIC_TREES<<1)+eof, 3);
988 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
989#ifdef DEBUG
990 s->compressed_len += 3 + s->static_len;
991#endif
992 } else {
993 send_bits(s, (DYN_TREES<<1)+eof, 3);
994 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
995 max_blindex+1);
996 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
997#ifdef DEBUG
998 s->compressed_len += 3 + s->opt_len;
999#endif
1000 }
1001 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
1002 /* The above check is made mod 2^32, for files larger than 512 MB
1003 * and uLong implemented on 32 bits.
1004 */
1005 init_block(s);
1006
1007 if (eof) {
1008 bi_windup(s);
1009#ifdef DEBUG
1010 s->compressed_len += 7; /* align on byte boundary */
1011#endif
1012 }
1013 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1014 s->compressed_len-7*eof));
1015}
1016
1017/* ===========================================================================
1018 * Save the match info and tally the frequency counts. Return true if
1019 * the current block must be flushed.
1020 */
1021int _tr_tally (s, dist, lc)
1022 deflate_state *s;
1023 unsigned dist; /* distance of matched string */
1024 unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
1025{
1026 s->d_buf[s->last_lit] = (ush)dist;
1027 s->l_buf[s->last_lit++] = (uch)lc;
1028 if (dist == 0) {
1029 /* lc is the unmatched char */
1030 s->dyn_ltree[lc].Freq++;
1031 } else {
1032 s->matches++;
1033 /* Here, lc is the match length - MIN_MATCH */
1034 dist--; /* dist = match distance - 1 */
1035 Assert((ush)dist < (ush)MAX_DIST(s) &&
1036 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1037 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1038
1039 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1040 s->dyn_dtree[d_code(dist)].Freq++;
1041 }
1042
1043#ifdef TRUNCATE_BLOCK
1044 /* Try to guess if it is profitable to stop the current block here */
1045 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
1046 /* Compute an upper bound for the compressed length */
1047 ulg out_length = (ulg)s->last_lit*8L;
1048 ulg in_length = (ulg)((long)s->strstart - s->block_start);
1049 int dcode;
1050 for (dcode = 0; dcode < D_CODES; dcode++) {
1051 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1052 (5L+extra_dbits[dcode]);
1053 }
1054 out_length >>= 3;
1055 Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1056 s->last_lit, in_length, out_length,
1057 100L - out_length*100L/in_length));
1058 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1059 }
1060#endif
1061 return (s->last_lit == s->lit_bufsize-1);
1062 /* We avoid equality with lit_bufsize because of wraparound at 64K
1063 * on 16 bit machines and because stored blocks are restricted to
1064 * 64K-1 bytes.
1065 */
1066}
1067
1068/* ===========================================================================
1069 * Send the block data compressed using the given Huffman trees
1070 */
1071local void compress_block(s, ltree, dtree)
1072 deflate_state *s;
1073 ct_data *ltree; /* literal tree */
1074 ct_data *dtree; /* distance tree */
1075{
1076 unsigned dist; /* distance of matched string */
1077 int lc; /* match length or unmatched char (if dist == 0) */
1078 unsigned lx = 0; /* running index in l_buf */
1079 unsigned code; /* the code to send */
1080 int extra; /* number of extra bits to send */
1081
1082 if (s->last_lit != 0) do {
1083 dist = s->d_buf[lx];
1084 lc = s->l_buf[lx++];
1085 if (dist == 0) {
1086 send_code(s, lc, ltree); /* send a literal byte */
1087 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1088 } else {
1089 /* Here, lc is the match length - MIN_MATCH */
1090 code = _length_code[lc];
1091 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1092 extra = extra_lbits[code];
1093 if (extra != 0) {
1094 lc -= base_length[code];
1095 send_bits(s, lc, extra); /* send the extra length bits */
1096 }
1097 dist--; /* dist is now the match distance - 1 */
1098 code = d_code(dist);
1099 Assert (code < D_CODES, "bad d_code");
1100
1101 send_code(s, code, dtree); /* send the distance code */
1102 extra = extra_dbits[code];
1103 if (extra != 0) {
1104 dist -= base_dist[code];
1105 send_bits(s, dist, extra); /* send the extra distance bits */
1106 }
1107 } /* literal or match pair ? */
1108
1109 /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
1110 Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
1111
1112 } while (lx < s->last_lit);
1113
1114 send_code(s, END_BLOCK, ltree);
1115 s->last_eob_len = ltree[END_BLOCK].Len;
1116}
1117
1118/* ===========================================================================
1119 * Set the data type to ASCII or BINARY, using a crude approximation:
1120 * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
1121 * IN assertion: the fields freq of dyn_ltree are set and the total of all
1122 * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
1123 */
1124local void set_data_type(s)
1125 deflate_state *s;
1126{
1127 int n = 0;
1128 unsigned ascii_freq = 0;
1129 unsigned bin_freq = 0;
1130 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
1131 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
1132 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
1133 s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
1134}
1135
1136/* ===========================================================================
1137 * Reverse the first len bits of a code, using straightforward code (a faster
1138 * method would use a table)
1139 * IN assertion: 1 <= len <= 15
1140 */
1141local unsigned bi_reverse(code, len)
1142 unsigned code; /* the value to invert */
1143 int len; /* its bit length */
1144{
1145 register unsigned res = 0;
1146 do {
1147 res |= code & 1;
1148 code >>= 1, res <<= 1;
1149 } while (--len > 0);
1150 return res >> 1;
1151}
1152
1153/* ===========================================================================
1154 * Flush the bit buffer, keeping at most 7 bits in it.
1155 */
1156local void bi_flush(s)
1157 deflate_state *s;
1158{
1159 if (s->bi_valid == 16) {
1160 put_short(s, s->bi_buf);
1161 s->bi_buf = 0;
1162 s->bi_valid = 0;
1163 } else if (s->bi_valid >= 8) {
1164 put_byte(s, (Byte)s->bi_buf);
1165 s->bi_buf >>= 8;
1166 s->bi_valid -= 8;
1167 }
1168}
1169
1170/* ===========================================================================
1171 * Flush the bit buffer and align the output on a byte boundary
1172 */
1173local void bi_windup(s)
1174 deflate_state *s;
1175{
1176 if (s->bi_valid > 8) {
1177 put_short(s, s->bi_buf);
1178 } else if (s->bi_valid > 0) {
1179 put_byte(s, (Byte)s->bi_buf);
1180 }
1181 s->bi_buf = 0;
1182 s->bi_valid = 0;
1183#ifdef DEBUG
1184 s->bits_sent = (s->bits_sent+7) & ~7;
1185#endif
1186}
1187
1188/* ===========================================================================
1189 * Copy a stored block, storing first the length and its
1190 * one's complement if requested.
1191 */
1192local void copy_block(s, buf, len, header)
1193 deflate_state *s;
1194 charf *buf; /* the input data */
1195 unsigned len; /* its length */
1196 int header; /* true if block header must be written */
1197{
1198 bi_windup(s); /* align on byte boundary */
1199 s->last_eob_len = 8; /* enough lookahead for inflate */
1200
1201 if (header) {
1202 put_short(s, (ush)len);
1203 put_short(s, (ush)~len);
1204#ifdef DEBUG
1205 s->bits_sent += 2*16;
1206#endif
1207 }
1208#ifdef DEBUG
1209 s->bits_sent += (ulg)len<<3;
1210#endif
1211 while (len--) {
1212 put_byte(s, *buf++);
1213 }
1214}
diff --git a/pwmanager/libcrypt/zlib/trees.h b/pwmanager/libcrypt/zlib/trees.h
new file mode 100644
index 0000000..72facf9
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/trees.h
@@ -0,0 +1,128 @@
1/* header created automatically with -DGEN_TREES_H */
2
3local const ct_data static_ltree[L_CODES+2] = {
4{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
5{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
6{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
7{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
8{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
9{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
10{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
11{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
12{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
13{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
14{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
15{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
16{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
17{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
18{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
19{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
20{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
21{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
22{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
23{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
24{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
25{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
26{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
27{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
28{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
29{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
30{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
31{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
32{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
33{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
34{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
35{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
36{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
37{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
38{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
39{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
40{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
41{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
42{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
43{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
44{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
45{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
46{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
47{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
48{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
49{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
50{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
51{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
52{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
53{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
54{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
55{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
56{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
57{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
58{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
59{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
60{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
61{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
62};
63
64local const ct_data static_dtree[D_CODES] = {
65{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
66{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
67{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
68{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
69{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
70{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
71};
72
73const uch _dist_code[DIST_CODE_LEN] = {
74 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
75 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
7610, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7711, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
7812, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
7913, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
8013, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
8114, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
8214, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
8314, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
8415, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
8515, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
8615, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
8718, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
8823, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
8924, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
9026, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
9126, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
9227, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
9327, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
9428, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
9528, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
9628, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
9729, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
9829, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
9929, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
100};
101
102const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
103 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
10413, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
10517, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
10619, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
10721, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
10822, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
10923, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
11024, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
11125, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
11225, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
11326, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
11426, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
11527, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
116};
117
118local const int base_length[LENGTH_CODES] = {
1190, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
12064, 80, 96, 112, 128, 160, 192, 224, 0
121};
122
123local const int base_dist[D_CODES] = {
124 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
125 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
126 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
127};
128
diff --git a/pwmanager/libcrypt/zlib/uncompr.c b/pwmanager/libcrypt/zlib/uncompr.c
new file mode 100644
index 0000000..a287714
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/uncompr.c
@@ -0,0 +1,58 @@
1/* uncompr.c -- decompress a memory buffer
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zlib.h"
9
10/* ===========================================================================
11 Decompresses the source buffer into the destination buffer. sourceLen is
12 the byte length of the source buffer. Upon entry, destLen is the total
13 size of the destination buffer, which must be large enough to hold the
14 entire uncompressed data. (The size of the uncompressed data must have
15 been saved previously by the compressor and transmitted to the decompressor
16 by some mechanism outside the scope of this compression library.)
17 Upon exit, destLen is the actual size of the compressed buffer.
18 This function can be used to decompress a whole file at once if the
19 input file is mmap'ed.
20
21 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
22 enough memory, Z_BUF_ERROR if there was not enough room in the output
23 buffer, or Z_DATA_ERROR if the input data was corrupted.
24*/
25int ZEXPORT uncompress (dest, destLen, source, sourceLen)
26 Bytef *dest;
27 uLongf *destLen;
28 const Bytef *source;
29 uLong sourceLen;
30{
31 z_stream stream;
32 int err;
33
34 stream.next_in = (Bytef*)source;
35 stream.avail_in = (uInt)sourceLen;
36 /* Check for source > 64K on 16-bit machine: */
37 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
38
39 stream.next_out = dest;
40 stream.avail_out = (uInt)*destLen;
41 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
42
43 stream.zalloc = (alloc_func)0;
44 stream.zfree = (free_func)0;
45
46 err = inflateInit(&stream);
47 if (err != Z_OK) return err;
48
49 err = inflate(&stream, Z_FINISH);
50 if (err != Z_STREAM_END) {
51 inflateEnd(&stream);
52 return err == Z_OK ? Z_BUF_ERROR : err;
53 }
54 *destLen = stream.total_out;
55
56 err = inflateEnd(&stream);
57 return err;
58}
diff --git a/pwmanager/libcrypt/zlib/zconf.h b/pwmanager/libcrypt/zlib/zconf.h
new file mode 100644
index 0000000..eb0ae2e
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/zconf.h
@@ -0,0 +1,279 @@
1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#ifndef _ZCONF_H
9#define _ZCONF_H
10
11/*
12 * If you *really* need a unique prefix for all types and library functions,
13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14 */
15#ifdef Z_PREFIX
16 # define deflateInit_z_deflateInit_
17 # define deflatez_deflate
18 # define deflateEndz_deflateEnd
19 # define inflateInit_ z_inflateInit_
20 # define inflatez_inflate
21 # define inflateEndz_inflateEnd
22 # define deflateInit2_z_deflateInit2_
23# define deflateSetDictionary z_deflateSetDictionary
24 # define deflateCopyz_deflateCopy
25 # define deflateResetz_deflateReset
26 # define deflateParamsz_deflateParams
27 # define inflateInit2_z_inflateInit2_
28# define inflateSetDictionary z_inflateSetDictionary
29 # define inflateSyncz_inflateSync
30# define inflateSyncPoint z_inflateSyncPoint
31 # define inflateResetz_inflateReset
32 # define compressz_compress
33 # define compress2z_compress2
34 # define uncompressz_uncompress
35 # define adler32z_adler32
36 # define crc32 z_crc32
37# define get_crc_table z_get_crc_table
38
39 # define Byte z_Byte
40 # define uInt z_uInt
41 # define uLong z_uLong
42 # define Bytef z_Bytef
43 # define charf z_charf
44 # define intf z_intf
45 # define uIntf z_uIntf
46 # define uLongfz_uLongf
47 # define voidpfz_voidpf
48 # define voidp z_voidp
49#endif
50
51#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
52# define WIN32
53#endif
54#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
55# ifndef __32BIT__
56# define __32BIT__
57# endif
58#endif
59#if defined(__MSDOS__) && !defined(MSDOS)
60# define MSDOS
61#endif
62
63/*
64 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
65 * than 64k bytes at a time (needed on systems with 16-bit int).
66 */
67#if defined(MSDOS) && !defined(__32BIT__)
68# define MAXSEG_64K
69#endif
70#ifdef MSDOS
71# define UNALIGNED_OK
72#endif
73
74#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
75# define STDC
76#endif
77#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
78# ifndef STDC
79# define STDC
80# endif
81#endif
82
83#ifndef STDC
84# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
85# define const
86# endif
87#endif
88
89/* Some Mac compilers merge all .h files incorrectly: */
90#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
91# define NO_DUMMY_DECL
92#endif
93
94/* Old Borland C incorrectly complains about missing returns: */
95#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
96# define NEED_DUMMY_RETURN
97#endif
98
99
100/* Maximum value for memLevel in deflateInit2 */
101#ifndef MAX_MEM_LEVEL
102# ifdef MAXSEG_64K
103# define MAX_MEM_LEVEL 8
104# else
105# define MAX_MEM_LEVEL 9
106# endif
107#endif
108
109/* Maximum value for windowBits in deflateInit2 and inflateInit2.
110 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
111 * created by gzip. (Files created by minigzip can still be extracted by
112 * gzip.)
113 */
114#ifndef MAX_WBITS
115# define MAX_WBITS 15 /* 32K LZ77 window */
116#endif
117
118/* The memory requirements for deflate are (in bytes):
119 (1 << (windowBits+2)) + (1 << (memLevel+9))
120 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
121 plus a few kilobytes for small objects. For example, if you want to reduce
122 the default memory requirements from 256K to 128K, compile with
123 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
124 Of course this will generally degrade compression (there's no free lunch).
125
126 The memory requirements for inflate are (in bytes) 1 << windowBits
127 that is, 32K for windowBits=15 (default value) plus a few kilobytes
128 for small objects.
129*/
130
131 /* Type declarations */
132
133#ifndef OF /* function prototypes */
134# ifdef STDC
135# define OF(args) args
136# else
137# define OF(args) ()
138# endif
139#endif
140
141/* The following definitions for FAR are needed only for MSDOS mixed
142 * model programming (small or medium model with some far allocations).
143 * This was tested only with MSC; for other MSDOS compilers you may have
144 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
145 * just define FAR to be empty.
146 */
147#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
148 /* MSC small or medium model */
149# define SMALL_MEDIUM
150# ifdef _MSC_VER
151# define FAR _far
152# else
153# define FAR far
154# endif
155#endif
156#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
157# ifndef __32BIT__
158# define SMALL_MEDIUM
159# define FAR _far
160# endif
161#endif
162
163/* Compile with -DZLIB_DLL for Windows DLL support */
164#if defined(ZLIB_DLL)
165# if defined(_WINDOWS) || defined(WINDOWS)
166# ifdef FAR
167# undef FAR
168# endif
169# include <windows.h>
170# define ZEXPORT WINAPI
171# ifdef WIN32
172# define ZEXPORTVA WINAPIV
173# else
174# define ZEXPORTVA FAR _cdecl _export
175# endif
176# endif
177# if defined (__BORLANDC__)
178# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
179# include <windows.h>
180# define ZEXPORT __declspec(dllexport) WINAPI
181# define ZEXPORTRVA __declspec(dllexport) WINAPIV
182# else
183# if defined (_Windows) && defined (__DLL__)
184# define ZEXPORT _export
185# define ZEXPORTVA _export
186# endif
187# endif
188# endif
189#endif
190
191#if defined (__BEOS__)
192# if defined (ZLIB_DLL)
193# define ZEXTERN extern __declspec(dllexport)
194# else
195# define ZEXTERN extern __declspec(dllimport)
196# endif
197#endif
198
199#ifndef ZEXPORT
200# define ZEXPORT
201#endif
202#ifndef ZEXPORTVA
203# define ZEXPORTVA
204#endif
205#ifndef ZEXTERN
206# define ZEXTERN extern
207#endif
208
209#ifndef FAR
210# define FAR
211#endif
212
213#if !defined(MACOS) && !defined(TARGET_OS_MAC)
214typedef unsigned char Byte; /* 8 bits */
215#endif
216typedef unsigned int uInt; /* 16 bits or more */
217typedef unsigned long uLong; /* 32 bits or more */
218
219#ifdef SMALL_MEDIUM
220 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
221# define Bytef Byte FAR
222#else
223 typedef Byte FAR Bytef;
224#endif
225typedef char FAR charf;
226typedef int FAR intf;
227typedef uInt FAR uIntf;
228typedef uLong FAR uLongf;
229
230#ifdef STDC
231 typedef void FAR *voidpf;
232 typedef void *voidp;
233#else
234 typedef Byte FAR *voidpf;
235 typedef Byte *voidp;
236#endif
237
238#ifdef HAVE_UNISTD_H
239# include <sys/types.h> /* for off_t */
240# include <unistd.h> /* for SEEK_* and off_t */
241# define z_off_t off_t
242#endif
243#ifndef SEEK_SET
244# define SEEK_SET 0 /* Seek from beginning of file. */
245# define SEEK_CUR 1 /* Seek from current position. */
246# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
247#endif
248#ifndef z_off_t
249# define z_off_t long
250#endif
251
252/* MVS linker does not support external names larger than 8 bytes */
253#if defined(__MVS__)
254# pragma map(deflateInit_,"DEIN")
255# pragma map(deflateInit2_,"DEIN2")
256# pragma map(deflateEnd,"DEEND")
257# pragma map(inflateInit_,"ININ")
258# pragma map(inflateInit2_,"ININ2")
259# pragma map(inflateEnd,"INEND")
260# pragma map(inflateSync,"INSY")
261# pragma map(inflateSetDictionary,"INSEDI")
262# pragma map(inflate_blocks,"INBL")
263# pragma map(inflate_blocks_new,"INBLNE")
264# pragma map(inflate_blocks_free,"INBLFR")
265# pragma map(inflate_blocks_reset,"INBLRE")
266# pragma map(inflate_codes_free,"INCOFR")
267# pragma map(inflate_codes,"INCO")
268# pragma map(inflate_fast,"INFA")
269# pragma map(inflate_flush,"INFLU")
270# pragma map(inflate_mask,"INMA")
271# pragma map(inflate_set_dictionary,"INSEDI2")
272# pragma map(inflate_copyright,"INCOPY")
273# pragma map(inflate_trees_bits,"INTRBI")
274# pragma map(inflate_trees_dynamic,"INTRDY")
275# pragma map(inflate_trees_fixed,"INTRFI")
276# pragma map(inflate_trees_free,"INTRFR")
277#endif
278
279#endif /* _ZCONF_H */
diff --git a/pwmanager/libcrypt/zlib/zlib.h b/pwmanager/libcrypt/zlib/zlib.h
new file mode 100644
index 0000000..52cb529
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/zlib.h
@@ -0,0 +1,893 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.1.4, March 11th, 2002
3
4 Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
13
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
21
22 Jean-loup Gailly Mark Adler
23 jloup@gzip.org madler@alumni.caltech.edu
24
25
26 The data format used by the zlib library is described by RFCs (Request for
27 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
28 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29*/
30
31#ifndef _ZLIB_H
32#define _ZLIB_H
33
34#include "zconf.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define ZLIB_VERSION "1.1.4"
41
42/*
43 The 'zlib' compression library provides in-memory compression and
44 decompression functions, including integrity checks of the uncompressed
45 data. This version of the library supports only one compression method
46 (deflation) but other algorithms will be added later and will have the same
47 stream interface.
48
49 Compression can be done in a single step if the buffers are large
50 enough (for example if an input file is mmap'ed), or can be done by
51 repeated calls of the compression function. In the latter case, the
52 application must provide more input and/or consume the output
53 (providing more output space) before each call.
54
55 The library also supports reading and writing files in gzip (.gz) format
56 with an interface similar to that of stdio.
57
58 The library does not install any signal handler. The decoder checks
59 the consistency of the compressed data, so the library should never
60 crash even in case of corrupted input.
61*/
62
63typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
64typedef void (*free_func) OF((voidpf opaque, voidpf address));
65
66struct internal_state;
67
68typedef struct z_stream_s {
69 Bytef *next_in; /* next input byte */
70 uInt avail_in; /* number of bytes available at next_in */
71 uLong total_in; /* total nb of input bytes read so far */
72
73 Bytef *next_out; /* next output byte should be put there */
74 uInt avail_out; /* remaining free space at next_out */
75 uLong total_out; /* total nb of bytes output so far */
76
77 char *msg; /* last error message, NULL if no error */
78 struct internal_state FAR *state; /* not visible by applications */
79
80 alloc_func zalloc; /* used to allocate the internal state */
81 free_func zfree; /* used to free the internal state */
82 voidpf opaque; /* private data object passed to zalloc and zfree */
83
84 int data_type; /* best guess about the data type: ascii or binary */
85 uLong adler; /* adler32 value of the uncompressed data */
86 uLong reserved; /* reserved for future use */
87} z_stream;
88
89typedef z_stream FAR *z_streamp;
90
91/*
92 The application must update next_in and avail_in when avail_in has
93 dropped to zero. It must update next_out and avail_out when avail_out
94 has dropped to zero. The application must initialize zalloc, zfree and
95 opaque before calling the init function. All other fields are set by the
96 compression library and must not be updated by the application.
97
98 The opaque value provided by the application will be passed as the first
99 parameter for calls of zalloc and zfree. This can be useful for custom
100 memory management. The compression library attaches no meaning to the
101 opaque value.
102
103 zalloc must return Z_NULL if there is not enough memory for the object.
104 If zlib is used in a multi-threaded application, zalloc and zfree must be
105 thread safe.
106
107 On 16-bit systems, the functions zalloc and zfree must be able to allocate
108 exactly 65536 bytes, but will not be required to allocate more than this
109 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
110 pointers returned by zalloc for objects of exactly 65536 bytes *must*
111 have their offset normalized to zero. The default allocation function
112 provided by this library ensures this (see zutil.c). To reduce memory
113 requirements and avoid any allocation of 64K objects, at the expense of
114 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
115
116 The fields total_in and total_out can be used for statistics or
117 progress reports. After compression, total_in holds the total size of
118 the uncompressed data and may be saved for use in the decompressor
119 (particularly if the decompressor wants to decompress everything in
120 a single step).
121*/
122
123 /* constants */
124
125#define Z_NO_FLUSH 0
126#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
127#define Z_SYNC_FLUSH 2
128#define Z_FULL_FLUSH 3
129#define Z_FINISH 4
130/* Allowed flush values; see deflate() below for details */
131
132#define Z_OK 0
133#define Z_STREAM_END 1
134#define Z_NEED_DICT 2
135#define Z_ERRNO (-1)
136#define Z_STREAM_ERROR (-2)
137#define Z_DATA_ERROR (-3)
138#define Z_MEM_ERROR (-4)
139#define Z_BUF_ERROR (-5)
140#define Z_VERSION_ERROR (-6)
141/* Return codes for the compression/decompression functions. Negative
142 * values are errors, positive values are used for special but normal events.
143 */
144
145#define Z_NO_COMPRESSION 0
146#define Z_BEST_SPEED 1
147#define Z_BEST_COMPRESSION 9
148#define Z_DEFAULT_COMPRESSION (-1)
149/* compression levels */
150
151#define Z_FILTERED 1
152#define Z_HUFFMAN_ONLY 2
153#define Z_DEFAULT_STRATEGY 0
154/* compression strategy; see deflateInit2() below for details */
155
156#define Z_BINARY 0
157#define Z_ASCII 1
158#define Z_UNKNOWN 2
159/* Possible values of the data_type field */
160
161#define Z_DEFLATED 8
162/* The deflate compression method (the only one supported in this version) */
163
164#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
165
166#define zlib_version zlibVersion()
167/* for compatibility with versions < 1.0.2 */
168
169 /* basic functions */
170
171ZEXTERN const char * ZEXPORT zlibVersion OF((void));
172/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
173 If the first character differs, the library code actually used is
174 not compatible with the zlib.h header file used by the application.
175 This check is automatically made by deflateInit and inflateInit.
176 */
177
178/*
179ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
180
181 Initializes the internal stream state for compression. The fields
182 zalloc, zfree and opaque must be initialized before by the caller.
183 If zalloc and zfree are set to Z_NULL, deflateInit updates them to
184 use default allocation functions.
185
186 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
187 1 gives best speed, 9 gives best compression, 0 gives no compression at
188 all (the input data is simply copied a block at a time).
189 Z_DEFAULT_COMPRESSION requests a default compromise between speed and
190 compression (currently equivalent to level 6).
191
192 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
193 enough memory, Z_STREAM_ERROR if level is not a valid compression level,
194 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
195 with the version assumed by the caller (ZLIB_VERSION).
196 msg is set to null if there is no error message. deflateInit does not
197 perform any compression: this will be done by deflate().
198*/
199
200
201ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
202/*
203 deflate compresses as much data as possible, and stops when the input
204 buffer becomes empty or the output buffer becomes full. It may introduce some
205 output latency (reading input without producing any output) except when
206 forced to flush.
207
208 The detailed semantics are as follows. deflate performs one or both of the
209 following actions:
210
211 - Compress more input starting at next_in and update next_in and avail_in
212 accordingly. If not all input can be processed (because there is not
213 enough room in the output buffer), next_in and avail_in are updated and
214 processing will resume at this point for the next call of deflate().
215
216 - Provide more output starting at next_out and update next_out and avail_out
217 accordingly. This action is forced if the parameter flush is non zero.
218 Forcing flush frequently degrades the compression ratio, so this parameter
219 should be set only when necessary (in interactive applications).
220 Some output may be provided even if flush is not set.
221
222 Before the call of deflate(), the application should ensure that at least
223 one of the actions is possible, by providing more input and/or consuming
224 more output, and updating avail_in or avail_out accordingly; avail_out
225 should never be zero before the call. The application can consume the
226 compressed output when it wants, for example when the output buffer is full
227 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
228 and with zero avail_out, it must be called again after making room in the
229 output buffer because there might be more output pending.
230
231 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
232 flushed to the output buffer and the output is aligned on a byte boundary, so
233 that the decompressor can get all input data available so far. (In particular
234 avail_in is zero after the call if enough output space has been provided
235 before the call.) Flushing may degrade compression for some compression
236 algorithms and so it should be used only when necessary.
237
238 If flush is set to Z_FULL_FLUSH, all output is flushed as with
239 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
240 restart from this point if previous compressed data has been damaged or if
241 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
242 the compression.
243
244 If deflate returns with avail_out == 0, this function must be called again
245 with the same value of the flush parameter and more output space (updated
246 avail_out), until the flush is complete (deflate returns with non-zero
247 avail_out).
248
249 If the parameter flush is set to Z_FINISH, pending input is processed,
250 pending output is flushed and deflate returns with Z_STREAM_END if there
251 was enough output space; if deflate returns with Z_OK, this function must be
252 called again with Z_FINISH and more output space (updated avail_out) but no
253 more input data, until it returns with Z_STREAM_END or an error. After
254 deflate has returned Z_STREAM_END, the only possible operations on the
255 stream are deflateReset or deflateEnd.
256
257 Z_FINISH can be used immediately after deflateInit if all the compression
258 is to be done in a single step. In this case, avail_out must be at least
259 0.1% larger than avail_in plus 12 bytes. If deflate does not return
260 Z_STREAM_END, then it must be called again as described above.
261
262 deflate() sets strm->adler to the adler32 checksum of all input read
263 so far (that is, total_in bytes).
264
265 deflate() may update data_type if it can make a good guess about
266 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
267 binary. This field is only for information purposes and does not affect
268 the compression algorithm in any manner.
269
270 deflate() returns Z_OK if some progress has been made (more input
271 processed or more output produced), Z_STREAM_END if all input has been
272 consumed and all output has been produced (only when flush is set to
273 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
274 if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
275 (for example avail_in or avail_out was zero).
276*/
277
278
279ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
280/*
281 All dynamically allocated data structures for this stream are freed.
282 This function discards any unprocessed input and does not flush any
283 pending output.
284
285 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
286 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
287 prematurely (some input or output was discarded). In the error case,
288 msg may be set but then points to a static string (which must not be
289 deallocated).
290*/
291
292
293/*
294ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
295
296 Initializes the internal stream state for decompression. The fields
297 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
298 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
299 value depends on the compression method), inflateInit determines the
300 compression method from the zlib header and allocates all data structures
301 accordingly; otherwise the allocation will be deferred to the first call of
302 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
303 use default allocation functions.
304
305 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
306 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
307 version assumed by the caller. msg is set to null if there is no error
308 message. inflateInit does not perform any decompression apart from reading
309 the zlib header if present: this will be done by inflate(). (So next_in and
310 avail_in may be modified, but next_out and avail_out are unchanged.)
311*/
312
313
314ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
315/*
316 inflate decompresses as much data as possible, and stops when the input
317 buffer becomes empty or the output buffer becomes full. It may some
318 introduce some output latency (reading input without producing any output)
319 except when forced to flush.
320
321 The detailed semantics are as follows. inflate performs one or both of the
322 following actions:
323
324 - Decompress more input starting at next_in and update next_in and avail_in
325 accordingly. If not all input can be processed (because there is not
326 enough room in the output buffer), next_in is updated and processing
327 will resume at this point for the next call of inflate().
328
329 - Provide more output starting at next_out and update next_out and avail_out
330 accordingly. inflate() provides as much output as possible, until there
331 is no more input data or no more space in the output buffer (see below
332 about the flush parameter).
333
334 Before the call of inflate(), the application should ensure that at least
335 one of the actions is possible, by providing more input and/or consuming
336 more output, and updating the next_* and avail_* values accordingly.
337 The application can consume the uncompressed output when it wants, for
338 example when the output buffer is full (avail_out == 0), or after each
339 call of inflate(). If inflate returns Z_OK and with zero avail_out, it
340 must be called again after making room in the output buffer because there
341 might be more output pending.
342
343 If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
344 output as possible to the output buffer. The flushing behavior of inflate is
345 not specified for values of the flush parameter other than Z_SYNC_FLUSH
346 and Z_FINISH, but the current implementation actually flushes as much output
347 as possible anyway.
348
349 inflate() should normally be called until it returns Z_STREAM_END or an
350 error. However if all decompression is to be performed in a single step
351 (a single call of inflate), the parameter flush should be set to
352 Z_FINISH. In this case all pending input is processed and all pending
353 output is flushed; avail_out must be large enough to hold all the
354 uncompressed data. (The size of the uncompressed data may have been saved
355 by the compressor for this purpose.) The next operation on this stream must
356 be inflateEnd to deallocate the decompression state. The use of Z_FINISH
357 is never required, but can be used to inform inflate that a faster routine
358 may be used for the single inflate() call.
359
360 If a preset dictionary is needed at this point (see inflateSetDictionary
361 below), inflate sets strm-adler to the adler32 checksum of the
362 dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
363 it sets strm->adler to the adler32 checksum of all output produced
364 so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
365 an error code as described below. At the end of the stream, inflate()
366 checks that its computed adler32 checksum is equal to that saved by the
367 compressor and returns Z_STREAM_END only if the checksum is correct.
368
369 inflate() returns Z_OK if some progress has been made (more input processed
370 or more output produced), Z_STREAM_END if the end of the compressed data has
371 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
372 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
373 corrupted (input stream not conforming to the zlib format or incorrect
374 adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
375 (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
376 enough memory, Z_BUF_ERROR if no progress is possible or if there was not
377 enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
378 case, the application may then call inflateSync to look for a good
379 compression block.
380*/
381
382
383ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
384/*
385 All dynamically allocated data structures for this stream are freed.
386 This function discards any unprocessed input and does not flush any
387 pending output.
388
389 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
390 was inconsistent. In the error case, msg may be set but then points to a
391 static string (which must not be deallocated).
392*/
393
394 /* Advanced functions */
395
396/*
397 The following functions are needed only in some special applications.
398*/
399
400/*
401ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
402 int level,
403 int method,
404 int windowBits,
405 int memLevel,
406 int strategy));
407
408 This is another version of deflateInit with more compression options. The
409 fields next_in, zalloc, zfree and opaque must be initialized before by
410 the caller.
411
412 The method parameter is the compression method. It must be Z_DEFLATED in
413 this version of the library.
414
415 The windowBits parameter is the base two logarithm of the window size
416 (the size of the history buffer). It should be in the range 8..15 for this
417 version of the library. Larger values of this parameter result in better
418 compression at the expense of memory usage. The default value is 15 if
419 deflateInit is used instead.
420
421 The memLevel parameter specifies how much memory should be allocated
422 for the internal compression state. memLevel=1 uses minimum memory but
423 is slow and reduces compression ratio; memLevel=9 uses maximum memory
424 for optimal speed. The default value is 8. See zconf.h for total memory
425 usage as a function of windowBits and memLevel.
426
427 The strategy parameter is used to tune the compression algorithm. Use the
428 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
429 filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
430 string match). Filtered data consists mostly of small values with a
431 somewhat random distribution. In this case, the compression algorithm is
432 tuned to compress them better. The effect of Z_FILTERED is to force more
433 Huffman coding and less string matching; it is somewhat intermediate
434 between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
435 the compression ratio but not the correctness of the compressed output even
436 if it is not set appropriately.
437
438 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
439 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
440 method). msg is set to null if there is no error message. deflateInit2 does
441 not perform any compression: this will be done by deflate().
442*/
443
444ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
445 const Bytef *dictionary,
446 uInt dictLength));
447/*
448 Initializes the compression dictionary from the given byte sequence
449 without producing any compressed output. This function must be called
450 immediately after deflateInit, deflateInit2 or deflateReset, before any
451 call of deflate. The compressor and decompressor must use exactly the same
452 dictionary (see inflateSetDictionary).
453
454 The dictionary should consist of strings (byte sequences) that are likely
455 to be encountered later in the data to be compressed, with the most commonly
456 used strings preferably put towards the end of the dictionary. Using a
457 dictionary is most useful when the data to be compressed is short and can be
458 predicted with good accuracy; the data can then be compressed better than
459 with the default empty dictionary.
460
461 Depending on the size of the compression data structures selected by
462 deflateInit or deflateInit2, a part of the dictionary may in effect be
463 discarded, for example if the dictionary is larger than the window size in
464 deflate or deflate2. Thus the strings most likely to be useful should be
465 put at the end of the dictionary, not at the front.
466
467 Upon return of this function, strm->adler is set to the Adler32 value
468 of the dictionary; the decompressor may later use this value to determine
469 which dictionary has been used by the compressor. (The Adler32 value
470 applies to the whole dictionary even if only a subset of the dictionary is
471 actually used by the compressor.)
472
473 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
474 parameter is invalid (such as NULL dictionary) or the stream state is
475 inconsistent (for example if deflate has already been called for this stream
476 or if the compression method is bsort). deflateSetDictionary does not
477 perform any compression: this will be done by deflate().
478*/
479
480ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
481 z_streamp source));
482/*
483 Sets the destination stream as a complete copy of the source stream.
484
485 This function can be useful when several compression strategies will be
486 tried, for example when there are several ways of pre-processing the input
487 data with a filter. The streams that will be discarded should then be freed
488 by calling deflateEnd. Note that deflateCopy duplicates the internal
489 compression state which can be quite large, so this strategy is slow and
490 can consume lots of memory.
491
492 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
493 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
494 (such as zalloc being NULL). msg is left unchanged in both source and
495 destination.
496*/
497
498ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
499/*
500 This function is equivalent to deflateEnd followed by deflateInit,
501 but does not free and reallocate all the internal compression state.
502 The stream will keep the same compression level and any other attributes
503 that may have been set by deflateInit2.
504
505 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
506 stream state was inconsistent (such as zalloc or state being NULL).
507*/
508
509ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
510 int level,
511 int strategy));
512/*
513 Dynamically update the compression level and compression strategy. The
514 interpretation of level and strategy is as in deflateInit2. This can be
515 used to switch between compression and straight copy of the input data, or
516 to switch to a different kind of input data requiring a different
517 strategy. If the compression level is changed, the input available so far
518 is compressed with the old level (and may be flushed); the new level will
519 take effect only at the next call of deflate().
520
521 Before the call of deflateParams, the stream state must be set as for
522 a call of deflate(), since the currently available input may have to
523 be compressed and flushed. In particular, strm->avail_out must be non-zero.
524
525 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
526 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
527 if strm->avail_out was zero.
528*/
529
530/*
531ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
532 int windowBits));
533
534 This is another version of inflateInit with an extra parameter. The
535 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
536 before by the caller.
537
538 The windowBits parameter is the base two logarithm of the maximum window
539 size (the size of the history buffer). It should be in the range 8..15 for
540 this version of the library. The default value is 15 if inflateInit is used
541 instead. If a compressed stream with a larger window size is given as
542 input, inflate() will return with the error code Z_DATA_ERROR instead of
543 trying to allocate a larger window.
544
545 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
546 memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
547 memLevel). msg is set to null if there is no error message. inflateInit2
548 does not perform any decompression apart from reading the zlib header if
549 present: this will be done by inflate(). (So next_in and avail_in may be
550 modified, but next_out and avail_out are unchanged.)
551*/
552
553ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
554 const Bytef *dictionary,
555 uInt dictLength));
556/*
557 Initializes the decompression dictionary from the given uncompressed byte
558 sequence. This function must be called immediately after a call of inflate
559 if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
560 can be determined from the Adler32 value returned by this call of
561 inflate. The compressor and decompressor must use exactly the same
562 dictionary (see deflateSetDictionary).
563
564 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
565 parameter is invalid (such as NULL dictionary) or the stream state is
566 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
567 expected one (incorrect Adler32 value). inflateSetDictionary does not
568 perform any decompression: this will be done by subsequent calls of
569 inflate().
570*/
571
572ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
573/*
574 Skips invalid compressed data until a full flush point (see above the
575 description of deflate with Z_FULL_FLUSH) can be found, or until all
576 available input is skipped. No output is provided.
577
578 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
579 if no more input was provided, Z_DATA_ERROR if no flush point has been found,
580 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
581 case, the application may save the current current value of total_in which
582 indicates where valid compressed data was found. In the error case, the
583 application may repeatedly call inflateSync, providing more input each time,
584 until success or end of the input data.
585*/
586
587ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
588/*
589 This function is equivalent to inflateEnd followed by inflateInit,
590 but does not free and reallocate all the internal decompression state.
591 The stream will keep attributes that may have been set by inflateInit2.
592
593 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
594 stream state was inconsistent (such as zalloc or state being NULL).
595*/
596
597
598 /* utility functions */
599
600/*
601 The following utility functions are implemented on top of the
602 basic stream-oriented functions. To simplify the interface, some
603 default options are assumed (compression level and memory usage,
604 standard memory allocation functions). The source code of these
605 utility functions can easily be modified if you need special options.
606*/
607
608ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
609 const Bytef *source, uLong sourceLen));
610/*
611 Compresses the source buffer into the destination buffer. sourceLen is
612 the byte length of the source buffer. Upon entry, destLen is the total
613 size of the destination buffer, which must be at least 0.1% larger than
614 sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
615 compressed buffer.
616 This function can be used to compress a whole file at once if the
617 input file is mmap'ed.
618 compress returns Z_OK if success, Z_MEM_ERROR if there was not
619 enough memory, Z_BUF_ERROR if there was not enough room in the output
620 buffer.
621*/
622
623ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
624 const Bytef *source, uLong sourceLen,
625 int level));
626/*
627 Compresses the source buffer into the destination buffer. The level
628 parameter has the same meaning as in deflateInit. sourceLen is the byte
629 length of the source buffer. Upon entry, destLen is the total size of the
630 destination buffer, which must be at least 0.1% larger than sourceLen plus
631 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
632
633 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
634 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
635 Z_STREAM_ERROR if the level parameter is invalid.
636*/
637
638ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
639 const Bytef *source, uLong sourceLen));
640/*
641 Decompresses the source buffer into the destination buffer. sourceLen is
642 the byte length of the source buffer. Upon entry, destLen is the total
643 size of the destination buffer, which must be large enough to hold the
644 entire uncompressed data. (The size of the uncompressed data must have
645 been saved previously by the compressor and transmitted to the decompressor
646 by some mechanism outside the scope of this compression library.)
647 Upon exit, destLen is the actual size of the compressed buffer.
648 This function can be used to decompress a whole file at once if the
649 input file is mmap'ed.
650
651 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
652 enough memory, Z_BUF_ERROR if there was not enough room in the output
653 buffer, or Z_DATA_ERROR if the input data was corrupted.
654*/
655
656
657typedef voidp gzFile;
658
659ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
660/*
661 Opens a gzip (.gz) file for reading or writing. The mode parameter
662 is as in fopen ("rb" or "wb") but can also include a compression level
663 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
664 Huffman only compression as in "wb1h". (See the description
665 of deflateInit2 for more information about the strategy parameter.)
666
667 gzopen can be used to read a file which is not in gzip format; in this
668 case gzread will directly read from the file without decompression.
669
670 gzopen returns NULL if the file could not be opened or if there was
671 insufficient memory to allocate the (de)compression state; errno
672 can be checked to distinguish the two cases (if errno is zero, the
673 zlib error is Z_MEM_ERROR). */
674
675ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
676/*
677 gzdopen() associates a gzFile with the file descriptor fd. File
678 descriptors are obtained from calls like open, dup, creat, pipe or
679 fileno (in the file has been previously opened with fopen).
680 The mode parameter is as in gzopen.
681 The next call of gzclose on the returned gzFile will also close the
682 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
683 descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
684 gzdopen returns NULL if there was insufficient memory to allocate
685 the (de)compression state.
686*/
687
688ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
689/*
690 Dynamically update the compression level or strategy. See the description
691 of deflateInit2 for the meaning of these parameters.
692 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
693 opened for writing.
694*/
695
696ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
697/*
698 Reads the given number of uncompressed bytes from the compressed file.
699 If the input file was not in gzip format, gzread copies the given number
700 of bytes into the buffer.
701 gzread returns the number of uncompressed bytes actually read (0 for
702 end of file, -1 for error). */
703
704ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
705 const voidp buf, unsigned len));
706/*
707 Writes the given number of uncompressed bytes into the compressed file.
708 gzwrite returns the number of uncompressed bytes actually written
709 (0 in case of error).
710*/
711
712ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
713/*
714 Converts, formats, and writes the args to the compressed file under
715 control of the format string, as in fprintf. gzprintf returns the number of
716 uncompressed bytes actually written (0 in case of error).
717*/
718
719ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
720/*
721 Writes the given null-terminated string to the compressed file, excluding
722 the terminating null character.
723 gzputs returns the number of characters written, or -1 in case of error.
724*/
725
726ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
727/*
728 Reads bytes from the compressed file until len-1 characters are read, or
729 a newline character is read and transferred to buf, or an end-of-file
730 condition is encountered. The string is then terminated with a null
731 character.
732 gzgets returns buf, or Z_NULL in case of error.
733*/
734
735ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
736/*
737 Writes c, converted to an unsigned char, into the compressed file.
738 gzputc returns the value that was written, or -1 in case of error.
739*/
740
741ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
742/*
743 Reads one byte from the compressed file. gzgetc returns this byte
744 or -1 in case of end of file or error.
745*/
746
747ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
748/*
749 Flushes all pending output into the compressed file. The parameter
750 flush is as in the deflate() function. The return value is the zlib
751 error number (see function gzerror below). gzflush returns Z_OK if
752 the flush parameter is Z_FINISH and all output could be flushed.
753 gzflush should be called only when strictly necessary because it can
754 degrade compression.
755*/
756
757ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
758 z_off_t offset, int whence));
759/*
760 Sets the starting position for the next gzread or gzwrite on the
761 given compressed file. The offset represents a number of bytes in the
762 uncompressed data stream. The whence parameter is defined as in lseek(2);
763 the value SEEK_END is not supported.
764 If the file is opened for reading, this function is emulated but can be
765 extremely slow. If the file is opened for writing, only forward seeks are
766 supported; gzseek then compresses a sequence of zeroes up to the new
767 starting position.
768
769 gzseek returns the resulting offset location as measured in bytes from
770 the beginning of the uncompressed stream, or -1 in case of error, in
771 particular if the file is opened for writing and the new starting position
772 would be before the current position.
773*/
774
775ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
776/*
777 Rewinds the given file. This function is supported only for reading.
778
779 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
780*/
781
782ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
783/*
784 Returns the starting position for the next gzread or gzwrite on the
785 given compressed file. This position represents a number of bytes in the
786 uncompressed data stream.
787
788 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
789*/
790
791ZEXTERN int ZEXPORT gzeof OF((gzFile file));
792/*
793 Returns 1 when EOF has previously been detected reading the given
794 input stream, otherwise zero.
795*/
796
797ZEXTERN int ZEXPORT gzclose OF((gzFile file));
798/*
799 Flushes all pending output if necessary, closes the compressed file
800 and deallocates all the (de)compression state. The return value is the zlib
801 error number (see function gzerror below).
802*/
803
804ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
805/*
806 Returns the error message for the last error which occurred on the
807 given compressed file. errnum is set to zlib error number. If an
808 error occurred in the file system and not in the compression library,
809 errnum is set to Z_ERRNO and the application may consult errno
810 to get the exact error code.
811*/
812
813 /* checksum functions */
814
815/*
816 These functions are not related to compression but are exported
817 anyway because they might be useful in applications using the
818 compression library.
819*/
820
821ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
822
823/*
824 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
825 return the updated checksum. If buf is NULL, this function returns
826 the required initial value for the checksum.
827 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
828 much faster. Usage example:
829
830 uLong adler = adler32(0L, Z_NULL, 0);
831
832 while (read_buffer(buffer, length) != EOF) {
833 adler = adler32(adler, buffer, length);
834 }
835 if (adler != original_adler) error();
836*/
837
838ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
839/*
840 Update a running crc with the bytes buf[0..len-1] and return the updated
841 crc. If buf is NULL, this function returns the required initial value
842 for the crc. Pre- and post-conditioning (one's complement) is performed
843 within this function so it shouldn't be done by the application.
844 Usage example:
845
846 uLong crc = crc32(0L, Z_NULL, 0);
847
848 while (read_buffer(buffer, length) != EOF) {
849 crc = crc32(crc, buffer, length);
850 }
851 if (crc != original_crc) error();
852*/
853
854
855 /* various hacks, don't look :) */
856
857/* deflateInit and inflateInit are macros to allow checking the zlib version
858 * and the compiler's view of z_stream:
859 */
860ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
861 const char *version, int stream_size));
862ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
863 const char *version, int stream_size));
864ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
865 int windowBits, int memLevel,
866 int strategy, const char *version,
867 int stream_size));
868ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
869 const char *version, int stream_size));
870#define deflateInit(strm, level) \
871 deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
872#define inflateInit(strm) \
873 inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
874#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
875 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
876 (strategy), ZLIB_VERSION, sizeof(z_stream))
877#define inflateInit2(strm, windowBits) \
878 inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
879
880
881#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
882 struct internal_state {int dummy;}; /* hack for buggy compilers */
883#endif
884
885ZEXTERN const char * ZEXPORT zError OF((int err));
886ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
887ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
888
889#ifdef __cplusplus
890}
891#endif
892
893#endif /* _ZLIB_H */
diff --git a/pwmanager/libcrypt/zlib/zlib.pro b/pwmanager/libcrypt/zlib/zlib.pro
new file mode 100644
index 0000000..2841aaf
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/zlib.pro
@@ -0,0 +1,36 @@
1######################################################################
2# Automatically generated by qmake (1.07a) Tue Oct 19 14:18:17 2004
3######################################################################
4
5TEMPLATE = lib
6 CONFIG += staticlib
7INCLUDEPATH += .
8TARGET = zlib
9OBJECTS_DIR = obj/$(PLATFORM)
10MOC_DIR = moc/$(PLATFORM)
11DESTDIR= ../$(PLATFORM)
12# Input
13HEADERS += deflate.h \
14 infblock.h \
15 infcodes.h \
16 inffast.h \
17 inffixed.h \
18 inftrees.h \
19 infutil.h \
20 trees.h \
21 zconf.h \
22 zlib.h \
23 zutil.h
24SOURCES += adler32.c \
25 compress.c \
26 crc32.c \
27 deflate.c \
28 infblock.c \
29 infcodes.c \
30 inffast.c \
31 inflate.c \
32 inftrees.c \
33 infutil.c \
34 trees.c \
35 uncompr.c \
36 zutil.c
diff --git a/pwmanager/libcrypt/zlib/zutil.c b/pwmanager/libcrypt/zlib/zutil.c
new file mode 100644
index 0000000..dfc38ec
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/zutil.c
@@ -0,0 +1,225 @@
1/* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zutil.h"
9
10struct internal_state {int dummy;}; /* for buggy compilers */
11
12#ifndef STDC
13extern void exit OF((int));
14#endif
15
16const char *z_errmsg[10] = {
17"need dictionary", /* Z_NEED_DICT 2 */
18"stream end", /* Z_STREAM_END 1 */
19"", /* Z_OK 0 */
20"file error", /* Z_ERRNO (-1) */
21"stream error", /* Z_STREAM_ERROR (-2) */
22"data error", /* Z_DATA_ERROR (-3) */
23"insufficient memory", /* Z_MEM_ERROR (-4) */
24"buffer error", /* Z_BUF_ERROR (-5) */
25"incompatible version",/* Z_VERSION_ERROR (-6) */
26""};
27
28
29const char * ZEXPORT zlibVersion()
30{
31 return ZLIB_VERSION;
32}
33
34#ifdef DEBUG
35
36# ifndef verbose
37# define verbose 0
38# endif
39int z_verbose = verbose;
40
41void z_error (m)
42 char *m;
43{
44 fprintf(stderr, "%s\n", m);
45 exit(1);
46}
47#endif
48
49/* exported to allow conversion of error code to string for compress() and
50 * uncompress()
51 */
52const char * ZEXPORT zError(err)
53 int err;
54{
55 return ERR_MSG(err);
56}
57
58
59#ifndef HAVE_MEMCPY
60
61void zmemcpy(dest, source, len)
62 Bytef* dest;
63 const Bytef* source;
64 uInt len;
65{
66 if (len == 0) return;
67 do {
68 *dest++ = *source++; /* ??? to be unrolled */
69 } while (--len != 0);
70}
71
72int zmemcmp(s1, s2, len)
73 const Bytef* s1;
74 const Bytef* s2;
75 uInt len;
76{
77 uInt j;
78
79 for (j = 0; j < len; j++) {
80 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
81 }
82 return 0;
83}
84
85void zmemzero(dest, len)
86 Bytef* dest;
87 uInt len;
88{
89 if (len == 0) return;
90 do {
91 *dest++ = 0; /* ??? to be unrolled */
92 } while (--len != 0);
93}
94#endif
95
96#ifdef __TURBOC__
97#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
98/* Small and medium model in Turbo C are for now limited to near allocation
99 * with reduced MAX_WBITS and MAX_MEM_LEVEL
100 */
101# define MY_ZCALLOC
102
103/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
104 * and farmalloc(64K) returns a pointer with an offset of 8, so we
105 * must fix the pointer. Warning: the pointer must be put back to its
106 * original form in order to free it, use zcfree().
107 */
108
109#define MAX_PTR 10
110/* 10*64K = 640K */
111
112local int next_ptr = 0;
113
114typedef struct ptr_table_s {
115 voidpf org_ptr;
116 voidpf new_ptr;
117} ptr_table;
118
119local ptr_table table[MAX_PTR];
120/* This table is used to remember the original form of pointers
121 * to large buffers (64K). Such pointers are normalized with a zero offset.
122 * Since MSDOS is not a preemptive multitasking OS, this table is not
123 * protected from concurrent access. This hack doesn't work anyway on
124 * a protected system like OS/2. Use Microsoft C instead.
125 */
126
127voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
128{
129 voidpf buf = opaque; /* just to make some compilers happy */
130 ulg bsize = (ulg)items*size;
131
132 /* If we allocate less than 65520 bytes, we assume that farmalloc
133 * will return a usable pointer which doesn't have to be normalized.
134 */
135 if (bsize < 65520L) {
136 buf = farmalloc(bsize);
137 if (*(ush*)&buf != 0) return buf;
138 } else {
139 buf = farmalloc(bsize + 16L);
140 }
141 if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
142 table[next_ptr].org_ptr = buf;
143
144 /* Normalize the pointer to seg:0 */
145 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
146 *(ush*)&buf = 0;
147 table[next_ptr++].new_ptr = buf;
148 return buf;
149}
150
151void zcfree (voidpf opaque, voidpf ptr)
152{
153 int n;
154 if (*(ush*)&ptr != 0) { /* object < 64K */
155 farfree(ptr);
156 return;
157 }
158 /* Find the original pointer */
159 for (n = 0; n < next_ptr; n++) {
160 if (ptr != table[n].new_ptr) continue;
161
162 farfree(table[n].org_ptr);
163 while (++n < next_ptr) {
164 table[n-1] = table[n];
165 }
166 next_ptr--;
167 return;
168 }
169 ptr = opaque; /* just to make some compilers happy */
170 Assert(0, "zcfree: ptr not found");
171}
172#endif
173#endif /* __TURBOC__ */
174
175
176#if defined(M_I86) && !defined(__32BIT__)
177/* Microsoft C in 16-bit mode */
178
179# define MY_ZCALLOC
180
181#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
182# define _halloc halloc
183# define _hfree hfree
184#endif
185
186voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
187{
188 if (opaque) opaque = 0; /* to make compiler happy */
189 return _halloc((long)items, size);
190}
191
192void zcfree (voidpf opaque, voidpf ptr)
193{
194 if (opaque) opaque = 0; /* to make compiler happy */
195 _hfree(ptr);
196}
197
198#endif /* MSC */
199
200
201#ifndef MY_ZCALLOC /* Any system without a special alloc function */
202
203#ifndef STDC
204extern voidp calloc OF((uInt items, uInt size));
205extern void free OF((voidpf ptr));
206#endif
207
208voidpf zcalloc (opaque, items, size)
209 voidpf opaque;
210 unsigned items;
211 unsigned size;
212{
213 if (opaque) items += size - size; /* make compiler happy */
214 return (voidpf)calloc(items, size);
215}
216
217void zcfree (opaque, ptr)
218 voidpf opaque;
219 voidpf ptr;
220{
221 free(ptr);
222 if (opaque) return; /* make compiler happy */
223}
224
225#endif /* MY_ZCALLOC */
diff --git a/pwmanager/libcrypt/zlib/zutil.h b/pwmanager/libcrypt/zlib/zutil.h
new file mode 100644
index 0000000..718ebc1
--- a/dev/null
+++ b/pwmanager/libcrypt/zlib/zutil.h
@@ -0,0 +1,220 @@
1/* zutil.h -- internal interface and configuration of the compression library
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* @(#) $Id$ */
12
13#ifndef _Z_UTIL_H
14#define _Z_UTIL_H
15
16#include "zlib.h"
17
18#ifdef STDC
19# include <stddef.h>
20# include <string.h>
21# include <stdlib.h>
22#endif
23#ifdef NO_ERRNO_H
24 extern int errno;
25#else
26# include <errno.h>
27#endif
28
29#ifndef local
30# define local static
31#endif
32/* compile with -Dlocal if your debugger can't find static symbols */
33
34typedef unsigned char uch;
35typedef uch FAR uchf;
36typedef unsigned short ush;
37typedef ush FAR ushf;
38typedef unsigned long ulg;
39
40extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
41/* (size given to avoid silly warnings with Visual C++) */
42
43#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
44
45#define ERR_RETURN(strm,err) \
46 return (strm->msg = (char*)ERR_MSG(err), (err))
47/* To be used only when the state is known to be valid */
48
49 /* common constants */
50
51#ifndef DEF_WBITS
52# define DEF_WBITS MAX_WBITS
53#endif
54/* default windowBits for decompression. MAX_WBITS is for compression only */
55
56#if MAX_MEM_LEVEL >= 8
57# define DEF_MEM_LEVEL 8
58#else
59# define DEF_MEM_LEVEL MAX_MEM_LEVEL
60#endif
61/* default memLevel */
62
63#define STORED_BLOCK 0
64#define STATIC_TREES 1
65#define DYN_TREES 2
66/* The three kinds of block type */
67
68#define MIN_MATCH 3
69#define MAX_MATCH 258
70/* The minimum and maximum match lengths */
71
72#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
73
74 /* target dependencies */
75
76#ifdef MSDOS
77# define OS_CODE 0x00
78# if defined(__TURBOC__) || defined(__BORLANDC__)
79# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
80 /* Allow compilation with ANSI keywords only enabled */
81 void _Cdecl farfree( void *block );
82 void *_Cdecl farmalloc( unsigned long nbytes );
83# else
84# include <alloc.h>
85# endif
86# else /* MSC or DJGPP */
87# include <malloc.h>
88# endif
89#endif
90
91#ifdef OS2
92# define OS_CODE 0x06
93#endif
94
95#ifdef WIN32 /* Window 95 & Windows NT */
96# define OS_CODE 0x0b
97#endif
98
99#if defined(VAXC) || defined(VMS)
100# define OS_CODE 0x02
101# define F_OPEN(name, mode) \
102 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
103#endif
104
105#ifdef AMIGA
106# define OS_CODE 0x01
107#endif
108
109#if defined(ATARI) || defined(atarist)
110# define OS_CODE 0x05
111#endif
112
113#if defined(MACOS) || defined(TARGET_OS_MAC)
114# define OS_CODE 0x07
115# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
116# include <unix.h> /* for fdopen */
117# else
118# ifndef fdopen
119# define fdopen(fd,mode) NULL /* No fdopen() */
120# endif
121# endif
122#endif
123
124#ifdef __50SERIES /* Prime/PRIMOS */
125# define OS_CODE 0x0F
126#endif
127
128#ifdef TOPS20
129# define OS_CODE 0x0a
130#endif
131
132#if defined(_BEOS_) || defined(RISCOS)
133# define fdopen(fd,mode) NULL /* No fdopen() */
134#endif
135
136#if (defined(_MSC_VER) && (_MSC_VER > 600))
137# define fdopen(fd,type) _fdopen(fd,type)
138#endif
139
140
141 /* Common defaults */
142
143#ifndef OS_CODE
144# define OS_CODE 0x03 /* assume Unix */
145#endif
146
147#ifndef F_OPEN
148# define F_OPEN(name, mode) fopen((name), (mode))
149#endif
150
151 /* functions */
152
153#ifdef HAVE_STRERROR
154 extern char *strerror OF((int));
155# define zstrerror(errnum) strerror(errnum)
156#else
157# define zstrerror(errnum) ""
158#endif
159
160#if defined(pyr)
161# define NO_MEMCPY
162#endif
163#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
164 /* Use our own functions for small and medium model with MSC <= 5.0.
165 * You may have to use the same strategy for Borland C (untested).
166 * The __SC__ check is for Symantec.
167 */
168# define NO_MEMCPY
169#endif
170#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
171# define HAVE_MEMCPY
172#endif
173#ifdef HAVE_MEMCPY
174# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
175# define zmemcpy _fmemcpy
176# define zmemcmp _fmemcmp
177# define zmemzero(dest, len) _fmemset(dest, 0, len)
178# else
179# define zmemcpy memcpy
180# define zmemcmp memcmp
181# define zmemzero(dest, len) memset(dest, 0, len)
182# endif
183#else
184 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
185 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
186 extern void zmemzero OF((Bytef* dest, uInt len));
187#endif
188
189/* Diagnostic functions */
190#ifdef DEBUG
191# include <stdio.h>
192 extern int z_verbose;
193 extern void z_error OF((char *m));
194# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
195# define Trace(x) {if (z_verbose>=0) fprintf x ;}
196# define Tracev(x) {if (z_verbose>0) fprintf x ;}
197# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
198# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
199# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
200#else
201# define Assert(cond,msg)
202# define Trace(x)
203# define Tracev(x)
204# define Tracevv(x)
205# define Tracec(c,x)
206# define Tracecv(c,x)
207#endif
208
209
210typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
211 uInt len));
212voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
213void zcfree OF((voidpf opaque, voidpf ptr));
214
215#define ZALLOC(strm, items, size) \
216 (*((strm)->zalloc))((strm)->opaque, (items), (size))
217#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
218#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
219
220#endif /* _Z_UTIL_H */