diff -Nru zlib-1.2.13.dfsg/CMakeLists.txt zlib-1.3.1.dfsg/CMakeLists.txt --- zlib-1.2.13.dfsg/CMakeLists.txt 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/CMakeLists.txt 2024-01-22 18:32:37.000000000 +0000 @@ -1,9 +1,11 @@ -cmake_minimum_required(VERSION 2.4.4) +cmake_minimum_required(VERSION 2.4.4...3.15.0) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) project(zlib C) -set(VERSION "1.2.13") +set(VERSION "1.3.1") + +option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") @@ -148,7 +150,9 @@ endif(MINGW) add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) set_target_properties(zlib PROPERTIES SOVERSION 1) @@ -166,7 +170,7 @@ if(UNIX) # On unix-like platforms the library is almost always called libz set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) - if(NOT APPLE) + if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") endif() elseif(BUILD_SHARED_LIBS AND WIN32) @@ -193,21 +197,22 @@ #============================================================================ # Example binaries #============================================================================ - -add_executable(example test/example.c) -target_link_libraries(example zlib) -add_test(example example) - -add_executable(minigzip test/minigzip.c) -target_link_libraries(minigzip zlib) - -if(HAVE_OFF64_T) - add_executable(example64 test/example.c) - target_link_libraries(example64 zlib) - set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") - add_test(example64 example64) - - add_executable(minigzip64 test/minigzip.c) - target_link_libraries(minigzip64 zlib) - set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") +if(ZLIB_BUILD_EXAMPLES) + add_executable(example test/example.c) + target_link_libraries(example zlib) + add_test(example example) + + add_executable(minigzip test/minigzip.c) + target_link_libraries(minigzip zlib) + + if(HAVE_OFF64_T) + add_executable(example64 test/example.c) + target_link_libraries(example64 zlib) + set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + add_test(example64 example64) + + add_executable(minigzip64 test/minigzip.c) + target_link_libraries(minigzip64 zlib) + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + endif() endif() diff -Nru zlib-1.2.13.dfsg/ChangeLog zlib-1.3.1.dfsg/ChangeLog --- zlib-1.2.13.dfsg/ChangeLog 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/ChangeLog 2024-01-22 18:32:37.000000000 +0000 @@ -1,6 +1,34 @@ ChangeLog file for zlib +Changes in 1.3.1 (22 Jan 2024) +- Reject overflows of zip header fields in minizip +- Fix bug in inflateSync() for data held in bit buffer +- Add LIT_MEM define to use more memory for a small deflate speedup +- Fix decision on the emission of Zip64 end records in minizip +- Add bounds checking to ERR_MSG() macro, used by zError() +- Neutralize zip file traversal attacks in miniunz +- Fix a bug in ZLIB_DEBUG compiles in check_match() +- Various portability and appearance improvements + +Changes in 1.3 (18 Aug 2023) +- Remove K&R function definitions and zlib2ansi +- Fix bug in deflateBound() for level 0 and memLevel 9 +- Fix bug when gzungetc() is used immediately after gzopen() +- Fix bug when using gzflush() with a very small buffer +- Fix crash when gzsetparams() attempted for transparent write +- Fix test/example.c to work with FORCE_STORED +- Rewrite of zran in examples (see zran.c version history) +- Fix minizip to allow it to open an empty zip file +- Fix reading disk number start on zip64 files in minizip +- Fix logic error in minizip argument processing +- Add minizip testing to Makefile +- Read multiple bytes instead of byte-by-byte in minizip unzip.c +- Add memory sanitizer to configure (--memory) +- Various portability improvements +- Various documentation improvements +- Various spelling and typo corrections + Changes in 1.2.13 (13 Oct 2022) - Fix configure issue that discarded provided CC definition - Correct incorrect inputs provided to the CRC functions @@ -1445,7 +1473,7 @@ - fix typo in Make_vms.com (f$trnlnm -> f$getsyi) - in fcalloc, normalize pointer if size > 65520 bytes - don't use special fcalloc for 32 bit Borland C++ -- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... +- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc. - use Z_BINARY instead of BINARY - document that gzclose after gzdopen will close the file - allow "a" as mode in gzopen diff -Nru zlib-1.2.13.dfsg/FAQ zlib-1.3.1.dfsg/FAQ --- zlib-1.2.13.dfsg/FAQ 2011-11-27 22:15:32.000000000 +0000 +++ zlib-1.3.1.dfsg/FAQ 2024-01-18 01:19:03.000000000 +0000 @@ -4,7 +4,7 @@ If your question is not there, please check the zlib home page http://zlib.net/ which may have more recent information. -The lastest zlib FAQ is at http://zlib.net/zlib_faq.html +The latest zlib FAQ is at http://zlib.net/zlib_faq.html 1. Is zlib Y2K-compliant? @@ -14,8 +14,7 @@ 2. Where can I get a Windows DLL version? The zlib sources can be compiled without change to produce a DLL. See the - file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the - precompiled DLL are found in the zlib web site at http://zlib.net/ . + file win32/DLL_FAQ.txt in the zlib distribution. 3. Where can I get a Visual Basic interface to zlib? diff -Nru zlib-1.2.13.dfsg/Makefile.in zlib-1.3.1.dfsg/Makefile.in --- zlib-1.2.13.dfsg/Makefile.in 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/Makefile.in 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ # Makefile for zlib -# Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler +# Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler # For conditions of distribution and use, see copyright notice in zlib.h # To compile and test, type: @@ -22,13 +22,13 @@ SFLAGS=-O LDFLAGS= -TEST_LDFLAGS=$(LDFLAGS) -L. libz.a +TEST_LIBS=-L. libz.a LDSHARED=$(CC) CPP=$(CC) -E STATICLIB=libz.a SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.2.13 +SHAREDLIBV=libz.so.1.3.1 SHAREDLIBM=libz.so.1 LIBS=$(STATICLIB) $(SHAREDLIBV) @@ -282,10 +282,10 @@ -@rmdir objs example$(EXE): example.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TEST_LIBS) minigzip$(EXE): minigzip.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(TEST_LIBS) examplesh$(EXE): example.o $(SHAREDLIBV) $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) -L. $(SHAREDLIBV) @@ -294,10 +294,10 @@ $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV) example64$(EXE): example64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS) minigzip64$(EXE): minigzip64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip64.o $(TEST_LIBS) install-libs: $(LIBS) -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi @@ -359,8 +359,14 @@ zconf: $(SRCDIR)zconf.h.in cp -p $(SRCDIR)zconf.h.in zconf.h +minizip-test: static + cd contrib/minizip && { CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; } + +minizip-clean: + cd contrib/minizip && { $(MAKE) clean ; cd ../.. ; } + mostlyclean: clean -clean: +clean: minizip-clean rm -f *.o *.lo *~ \ example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ example64$(EXE) minigzip64$(EXE) \ diff -Nru zlib-1.2.13.dfsg/README zlib-1.3.1.dfsg/README --- zlib-1.2.13.dfsg/README 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/README 2024-01-22 18:32:37.000000000 +0000 @@ -1,6 +1,6 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.2.13 is a general purpose data compression library. All the code is +zlib 1.3.1 is a general purpose data compression library. All the code is thread safe. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and @@ -29,18 +29,17 @@ Mark Nelson wrote an article about zlib for the Jan. 1997 issue of Dr. Dobb's Journal; a copy of the article is available at -http://marknelson.us/1997/01/01/zlib-engine/ . +https://marknelson.us/posts/1997/01/01/zlib-engine.html . -The changes made in version 1.2.13 are documented in the file ChangeLog. +The changes made in version 1.3.1 are documented in the file ChangeLog. Unsupported third party contributions are provided in directory contrib/ . -zlib is available in Java using the java.util.zip package, documented at -http://java.sun.com/developer/technicalArticles/Programming/compression/ . +zlib is available in Java using the java.util.zip package. Follow the API +Documentation link at: https://docs.oracle.com/search/?q=java.util.zip . -A Perl interface to zlib written by Paul Marquess is available -at CPAN (Comprehensive Perl Archive Network) sites, including -http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . +A Perl interface to zlib and bzip2 written by Paul Marquess +can be found at https://github.com/pmqs/IO-Compress . A Python interface to zlib written by A.M. Kuchling is available in Python 1.5 and later versions, see @@ -64,7 +63,7 @@ - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works when compiled with cc. -- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is +- On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is necessary to get gzprintf working correctly. This is done by configure. - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with @@ -84,7 +83,7 @@ Copyright notice: - (C) 1995-2022 Jean-loup Gailly and Mark Adler + (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff -Nru zlib-1.2.13.dfsg/adler32.c zlib-1.3.1.dfsg/adler32.c --- zlib-1.2.13.dfsg/adler32.c 2017-01-01 07:37:10.000000000 +0000 +++ zlib-1.3.1.dfsg/adler32.c 2023-04-16 04:17:31.000000000 +0000 @@ -7,8 +7,6 @@ #include "zutil.h" -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); - #define BASE 65521U /* largest prime smaller than 65536 */ #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ @@ -60,11 +58,7 @@ #endif /* ========================================================================= */ -uLong ZEXPORT adler32_z(adler, buf, len) - uLong adler; - const Bytef *buf; - z_size_t len; -{ +uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { unsigned long sum2; unsigned n; @@ -131,20 +125,12 @@ } /* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { return adler32_z(adler, buf, len); } /* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { unsigned long sum1; unsigned long sum2; unsigned rem; @@ -169,18 +155,10 @@ } /* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ +uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } diff -Nru zlib-1.2.13.dfsg/compress.c zlib-1.3.1.dfsg/compress.c --- zlib-1.2.13.dfsg/compress.c 2022-10-05 22:17:52.000000000 +0000 +++ zlib-1.3.1.dfsg/compress.c 2023-04-16 04:17:31.000000000 +0000 @@ -19,13 +19,8 @@ memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid. */ -int ZEXPORT compress2(dest, destLen, source, sourceLen, level) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; - int level; -{ +int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen, int level) { z_stream stream; int err; const uInt max = (uInt)-1; @@ -65,12 +60,8 @@ /* =========================================================================== */ -int ZEXPORT compress(dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ +int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen) { return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); } @@ -78,9 +69,7 @@ If the default memLevel or windowBits for deflateInit() is changed, then this function needs to be updated. */ -uLong ZEXPORT compressBound(sourceLen) - uLong sourceLen; -{ +uLong ZEXPORT compressBound(uLong sourceLen) { return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13; } diff -Nru zlib-1.2.13.dfsg/configure zlib-1.3.1.dfsg/configure --- zlib-1.2.13.dfsg/configure 2022-10-10 18:11:12.000000000 +0000 +++ zlib-1.3.1.dfsg/configure 2024-01-21 02:29:31.000000000 +0000 @@ -25,7 +25,7 @@ ZINCOUT="-I." SRCDIR="" else - ZINC='-include zconf.h' + ZINC='-I. -include zconf.h' ZINCOUT='-I. -I$(SRCDIR)' SRCDIR="$SRCDIR/" fi @@ -44,9 +44,8 @@ # extract zlib version numbers from zlib.h VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h` -VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h` -VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h` -VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h` +VER3=`echo ${VER}|sed -n -e 's/\([0-9]\{1,\}\(\\.[0-9]\{1,\}\)\{1,2\}\).*/\1/p'` +VER1=`echo ${VER}|sed -n -e 's/\([0-9]\{1,\}\)\\..*/\1/p'` # establish commands for library building if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then @@ -90,7 +89,8 @@ gcc=0 warn=0 debug=0 -sanitize=0 +address=0 +memory=0 old_cc="$CC" old_cflags="$CFLAGS" OBJC='$(OBJZ) $(OBJG)' @@ -102,7 +102,7 @@ if test "$*" != "0"; then echo "** $0 aborting." | tee -a configure.log fi - rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version + rm -rf $test.[co] $test $test$shared_ext $test.gcno $test.dSYM ./--version echo -------------------- >> configure.log echo >> configure.log echo >> configure.log @@ -141,7 +141,9 @@ -c* | --const) zconst=1; shift ;; -w* | --warn) warn=1; shift ;; -d* | --debug) debug=1; shift ;; - --sanitize) sanitize=1; shift ;; + --sanitize) address=1; shift ;; + --address) address=1; shift ;; + --memory) memory=1; shift ;; *) echo "unknown option: $1" | tee -a configure.log echo "$0 --help for help" | tee -a configure.log @@ -211,8 +213,11 @@ CFLAGS="${CFLAGS} -Wall -Wextra" fi fi - if test $sanitize -eq 1; then - CFLAGS="${CFLAGS} -g -fsanitize=address" + if test $address -eq 1; then + CFLAGS="${CFLAGS} -g -fsanitize=address -fno-omit-frame-pointer" + fi + if test $memory -eq 1; then + CFLAGS="${CFLAGS} -g -fsanitize=memory -fno-omit-frame-pointer" fi if test $debug -eq 1; then CFLAGS="${CFLAGS} -DZLIB_DEBUG" @@ -260,7 +265,9 @@ SHAREDLIBV=libz.$VER$shared_ext SHAREDLIBM=libz.$VER1$shared_ext LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} - if libtool -V 2>&1 | grep Apple > /dev/null; then + if "${CROSS_PREFIX}libtool" -V 2>&1 | grep Apple > /dev/null; then + AR="${CROSS_PREFIX}libtool" + elif libtool -V 2>&1 | grep Apple > /dev/null; then AR="libtool" else AR="/usr/bin/libtool" @@ -435,7 +442,7 @@ if test $shared -eq 1; then echo Checking for shared library support... | tee -a configure.log # we must test in two steps (cc then ld), required at least on SunOS 4.x - if try $CC -w -c $SFLAGS $test.c && + if try $CC -c $SFLAGS $test.c && try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log elif test -z "$old_cc" -a -z "$old_cflags"; then @@ -860,7 +867,7 @@ echo sharedlibdir = $sharedlibdir >> configure.log echo uname = $uname >> configure.log -# udpate Makefile with the configure results +# update Makefile with the configure results sed < ${SRCDIR}Makefile.in " /^CC *=/s#=.*#=$CC# /^CFLAGS *=/s#=.*#=$CFLAGS# diff -Nru zlib-1.2.13.dfsg/contrib/minizip/Makefile zlib-1.3.1.dfsg/contrib/minizip/Makefile --- zlib-1.2.13.dfsg/contrib/minizip/Makefile 2022-01-01 22:55:47.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/Makefile 2024-01-21 17:25:44.000000000 +0000 @@ -1,4 +1,4 @@ -CC=cc +CC?=cc CFLAGS := $(CFLAGS) -O -I../.. UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a diff -Nru zlib-1.2.13.dfsg/contrib/minizip/MiniZip64_Changes.txt zlib-1.3.1.dfsg/contrib/minizip/MiniZip64_Changes.txt --- zlib-1.2.13.dfsg/contrib/minizip/MiniZip64_Changes.txt 2010-02-15 11:53:36.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/MiniZip64_Changes.txt 2023-07-30 06:44:25.000000000 +0000 @@ -1,5 +1,5 @@ -MiniZip 1.1 was derrived from MiniZip at version 1.01f +MiniZip 1.1 was derived from MiniZip at version 1.01f Change in 1.0 (Okt 2009) - **TODO - Add history** diff -Nru zlib-1.2.13.dfsg/contrib/minizip/configure.ac zlib-1.3.1.dfsg/contrib/minizip/configure.ac --- zlib-1.2.13.dfsg/contrib/minizip/configure.ac 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/configure.ac 2024-01-22 18:32:37.000000000 +0000 @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([minizip], [1.2.13], [bugzilla.redhat.com]) +AC_INIT([minizip], [1.3.1], [bugzilla.redhat.com]) AC_CONFIG_SRCDIR([minizip.c]) AM_INIT_AUTOMAKE([foreign]) LT_INIT diff -Nru zlib-1.2.13.dfsg/contrib/minizip/crypt.h zlib-1.3.1.dfsg/contrib/minizip/crypt.h --- zlib-1.2.13.dfsg/contrib/minizip/crypt.h 2022-10-10 08:01:38.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/crypt.h 2023-04-16 05:56:37.000000000 +0000 @@ -32,8 +32,7 @@ /*********************************************************************** * Return the next byte in the pseudo-random sequence */ -static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) -{ +static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) { unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an * unpredictable manner on 16-bit systems; not a problem * with any known compiler so far, though */ @@ -46,8 +45,7 @@ /*********************************************************************** * Update the encryption keys with the next byte of plain text */ -static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c) -{ +static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) { (*(pkeys+0)) = CRC32((*(pkeys+0)), c); (*(pkeys+1)) += (*(pkeys+0)) & 0xff; (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; @@ -63,8 +61,7 @@ * Initialize the encryption keys and the random header according to * the given password. */ -static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab) -{ +static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) { *(pkeys+0) = 305419896L; *(pkeys+1) = 591751049L; *(pkeys+2) = 878082192L; @@ -93,8 +90,7 @@ int bufSize, unsigned long* pkeys, const z_crc_t* pcrc_32_tab, - unsigned long crcForCrypting) -{ + unsigned long crcForCrypting) { unsigned n; /* index in random header */ int t; /* temporary */ int c; /* random byte */ diff -Nru zlib-1.2.13.dfsg/contrib/minizip/ioapi.c zlib-1.3.1.dfsg/contrib/minizip/ioapi.c --- zlib-1.2.13.dfsg/contrib/minizip/ioapi.c 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/ioapi.c 2023-08-03 18:17:07.000000000 +0000 @@ -14,7 +14,7 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#if defined(__APPLE__) || defined(IOAPI_NO_64) +#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions #define FOPEN_FUNC(filename, mode) fopen(filename, mode) #define FTELLO_FUNC(stream) ftello(stream) @@ -28,8 +28,7 @@ #include "ioapi.h" -voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) -{ +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void*filename, int mode) { if (pfilefunc->zfile_func64.zopen64_file != NULL) return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); else @@ -38,8 +37,7 @@ } } -long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) -{ +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) { if (pfilefunc->zfile_func64.zseek64_file != NULL) return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); else @@ -52,8 +50,7 @@ } } -ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) -{ +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream) { if (pfilefunc->zfile_func64.zseek64_file != NULL) return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); else @@ -66,11 +63,9 @@ } } -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) -{ +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32) { p_filefunc64_32->zfile_func64.zopen64_file = NULL; p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; p_filefunc64_32->zfile_func64.ztell64_file = NULL; @@ -84,16 +79,7 @@ -static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); -static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); -static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); -static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); -static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); - -static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) -{ +static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) { FILE* file = NULL; const char* mode_fopen = NULL; (void)opaque; @@ -111,8 +97,7 @@ return file; } -static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) -{ +static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void* filename, int mode) { FILE* file = NULL; const char* mode_fopen = NULL; (void)opaque; @@ -131,24 +116,21 @@ } -static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) -{ +static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uLong size) { uLong ret; (void)opaque; ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); return ret; } -static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) -{ +static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) { uLong ret; (void)opaque; ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); return ret; } -static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) -{ +static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) { long ret; (void)opaque; ret = ftell((FILE *)stream); @@ -156,16 +138,14 @@ } -static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) -{ +static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) { ZPOS64_T ret; (void)opaque; ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream); return ret; } -static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) -{ +static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) { int fseek_origin=0; long ret; (void)opaque; @@ -188,8 +168,7 @@ return ret; } -static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) -{ +static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) { int fseek_origin=0; long ret; (void)opaque; @@ -208,32 +187,28 @@ } ret = 0; - if(FSEEKO_FUNC((FILE *)stream, (z_off_t)offset, fseek_origin) != 0) + if(FSEEKO_FUNC((FILE *)stream, (z_off64_t)offset, fseek_origin) != 0) ret = -1; return ret; } -static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) -{ +static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) { int ret; (void)opaque; ret = fclose((FILE *)stream); return ret; } -static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) -{ +static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) { int ret; (void)opaque; ret = ferror((FILE *)stream); return ret; } -void fill_fopen_filefunc (pzlib_filefunc_def) - zlib_filefunc_def* pzlib_filefunc_def; -{ +void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen_file = fopen_file_func; pzlib_filefunc_def->zread_file = fread_file_func; pzlib_filefunc_def->zwrite_file = fwrite_file_func; @@ -244,8 +219,7 @@ pzlib_filefunc_def->opaque = NULL; } -void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) -{ +void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen64_file = fopen64_file_func; pzlib_filefunc_def->zread_file = fread_file_func; pzlib_filefunc_def->zwrite_file = fwrite_file_func; diff -Nru zlib-1.2.13.dfsg/contrib/minizip/ioapi.h zlib-1.3.1.dfsg/contrib/minizip/ioapi.h --- zlib-1.2.13.dfsg/contrib/minizip/ioapi.h 2022-10-10 09:39:33.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/ioapi.h 2023-11-15 02:44:32.000000000 +0000 @@ -50,7 +50,7 @@ #define ftello64 ftell #define fseeko64 fseek #else -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) #define fopen64 fopen #define ftello64 ftello #define fseeko64 fseeko @@ -82,7 +82,7 @@ #include "mz64conf.h" #endif -/* a type choosen by DEFINE */ +/* a type chosen by DEFINE */ #ifdef HAVE_64BIT_INT_CUSTOM typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; #else @@ -134,17 +134,17 @@ -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); +typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char* filename, int mode); +typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size); +typedef uLong (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size); +typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream); +typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream); -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); +typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream); +typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin); -/* here is the "old" 32 bits structure structure */ +/* here is the "old" 32 bits structure */ typedef struct zlib_filefunc_def_s { open_file_func zopen_file; @@ -157,9 +157,9 @@ voidpf opaque; } zlib_filefunc_def; -typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream); +typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin); +typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void* filename, int mode); typedef struct zlib_filefunc64_def_s { @@ -173,8 +173,8 @@ voidpf opaque; } zlib_filefunc64_def; -void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); +void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def); +void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def); /* now internal definition, only for zip.c and unzip.h */ typedef struct zlib_filefunc64_32_def_s @@ -193,11 +193,11 @@ #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) -voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); -long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); -ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); +voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode); +long call_zseek64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin); +ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream); -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) diff -Nru zlib-1.2.13.dfsg/contrib/minizip/iowin32.c zlib-1.3.1.dfsg/contrib/minizip/iowin32.c --- zlib-1.2.13.dfsg/contrib/minizip/iowin32.c 2022-03-29 01:46:59.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/iowin32.c 2023-04-16 05:56:37.000000000 +0000 @@ -38,14 +38,6 @@ #endif #endif -voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); -uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); -long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); -int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); - typedef struct { HANDLE hf; @@ -57,8 +49,7 @@ DWORD* lpdwDesiredAccess, DWORD* lpdwCreationDisposition, DWORD* lpdwShareMode, - DWORD* lpdwFlagsAndAttributes) -{ + DWORD* lpdwFlagsAndAttributes) { *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0; if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) @@ -79,8 +70,7 @@ } } -static voidpf win32_build_iowin(HANDLE hFile) -{ +static voidpf win32_build_iowin(HANDLE hFile) { voidpf ret=NULL; if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) @@ -98,8 +88,7 @@ return ret; } -voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) -{ +voidpf ZCALLBACK win32_open64_file_func(voidpf opaque, const void* filename, int mode) { const char* mode_fopen = NULL; DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; HANDLE hFile = NULL; @@ -127,8 +116,7 @@ } -voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) -{ +voidpf ZCALLBACK win32_open64_file_funcA(voidpf opaque, const void* filename, int mode) { const char* mode_fopen = NULL; DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; HANDLE hFile = NULL; @@ -151,8 +139,7 @@ } -voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) -{ +voidpf ZCALLBACK win32_open64_file_funcW(voidpf opaque, const void* filename, int mode) { const char* mode_fopen = NULL; DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; HANDLE hFile = NULL; @@ -171,8 +158,7 @@ } -voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode) -{ +voidpf ZCALLBACK win32_open_file_func(voidpf opaque, const char* filename, int mode) { const char* mode_fopen = NULL; DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; HANDLE hFile = NULL; @@ -200,8 +186,7 @@ } -uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size) -{ +uLong ZCALLBACK win32_read_file_func(voidpf opaque, voidpf stream, void* buf,uLong size) { uLong ret=0; HANDLE hFile = NULL; if (stream!=NULL) @@ -222,8 +207,7 @@ } -uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size) -{ +uLong ZCALLBACK win32_write_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) { uLong ret=0; HANDLE hFile = NULL; if (stream!=NULL) @@ -243,8 +227,7 @@ return ret; } -static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod) -{ +static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod) { #ifdef IOWIN32_USING_WINRT_API return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod); #else @@ -263,8 +246,7 @@ #endif } -long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) -{ +long ZCALLBACK win32_tell_file_func(voidpf opaque, voidpf stream) { long ret=-1; HANDLE hFile = NULL; if (stream!=NULL) @@ -286,8 +268,7 @@ return ret; } -ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) -{ +ZPOS64_T ZCALLBACK win32_tell64_file_func(voidpf opaque, voidpf stream) { ZPOS64_T ret= (ZPOS64_T)-1; HANDLE hFile = NULL; if (stream!=NULL) @@ -311,8 +292,7 @@ } -long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin) -{ +long ZCALLBACK win32_seek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) { DWORD dwMoveMethod=0xFFFFFFFF; HANDLE hFile = NULL; @@ -349,8 +329,7 @@ return ret; } -long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin) -{ +long ZCALLBACK win32_seek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) { DWORD dwMoveMethod=0xFFFFFFFF; HANDLE hFile = NULL; long ret=-1; @@ -388,8 +367,7 @@ return ret; } -int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream) -{ +int ZCALLBACK win32_close_file_func(voidpf opaque, voidpf stream) { int ret=-1; if (stream!=NULL) @@ -406,8 +384,7 @@ return ret; } -int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) -{ +int ZCALLBACK win32_error_file_func(voidpf opaque, voidpf stream) { int ret=-1; if (stream!=NULL) { @@ -416,8 +393,7 @@ return ret; } -void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def) -{ +void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen_file = win32_open_file_func; pzlib_filefunc_def->zread_file = win32_read_file_func; pzlib_filefunc_def->zwrite_file = win32_write_file_func; @@ -428,8 +404,7 @@ pzlib_filefunc_def->opaque = NULL; } -void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) -{ +void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen64_file = win32_open64_file_func; pzlib_filefunc_def->zread_file = win32_read_file_func; pzlib_filefunc_def->zwrite_file = win32_write_file_func; @@ -441,8 +416,7 @@ } -void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) -{ +void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA; pzlib_filefunc_def->zread_file = win32_read_file_func; pzlib_filefunc_def->zwrite_file = win32_write_file_func; @@ -454,8 +428,7 @@ } -void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) -{ +void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; pzlib_filefunc_def->zread_file = win32_read_file_func; pzlib_filefunc_def->zwrite_file = win32_write_file_func; diff -Nru zlib-1.2.13.dfsg/contrib/minizip/iowin32.h zlib-1.3.1.dfsg/contrib/minizip/iowin32.h --- zlib-1.2.13.dfsg/contrib/minizip/iowin32.h 2010-02-15 11:58:32.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/iowin32.h 2023-04-16 05:56:37.000000000 +0000 @@ -18,10 +18,10 @@ extern "C" { #endif -void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); -void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def); +void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def); +void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def); +void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def); #ifdef __cplusplus } diff -Nru zlib-1.2.13.dfsg/contrib/minizip/miniunz.c zlib-1.3.1.dfsg/contrib/minizip/miniunz.c --- zlib-1.2.13.dfsg/contrib/minizip/miniunz.c 2022-10-07 03:43:19.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/miniunz.c 2024-01-17 23:08:08.000000000 +0000 @@ -27,7 +27,7 @@ #endif #endif -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions #define FOPEN_FUNC(filename, mode) fopen(filename, mode) #define FTELLO_FUNC(stream) ftello(stream) @@ -79,13 +79,9 @@ /* change_file_date : change the date/time of a file filename : the filename of the file where date/time must be modified - dosdate : the new date at the MSDos format (4 bytes) + dosdate : the new date at the MSDOS format (4 bytes) tmu_date : the SAME new date at the tm_unz format */ -static void change_file_date(filename,dosdate,tmu_date) - const char *filename; - uLong dosdate; - tm_unz tmu_date; -{ +static void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date) { #ifdef _WIN32 HANDLE hFile; FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; @@ -115,6 +111,10 @@ ut.actime=ut.modtime=mktime(&newdate); utime(filename,&ut); +#else + (void)filename; + (void)dosdate; + (void)tmu_date; #endif #endif } @@ -123,9 +123,7 @@ /* mymkdir and change_file_date are not 100 % portable As I don't know well Unix, I wait feedback for the unix portion */ -static int mymkdir(dirname) - const char* dirname; -{ +static int mymkdir(const char* dirname) { int ret=0; #ifdef _WIN32 ret = _mkdir(dirname); @@ -133,13 +131,13 @@ ret = mkdir (dirname,0775); #elif __APPLE__ ret = mkdir (dirname,0775); +#else + (void)dirname; #endif return ret; } -static int makedir (newdir) - const char *newdir; -{ +static int makedir(const char *newdir) { char *buffer ; char *p; size_t len = strlen(newdir); @@ -187,14 +185,12 @@ return 1; } -static void do_banner() -{ - printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); +static void do_banner(void) { + printf("MiniUnz 1.1, demo of zLib + Unz package written by Gilles Vollant\n"); printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); } -static void do_help() -{ +static void do_help(void) { printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ " -e Extract without pathname (junk paths)\n" \ " -x Extract with pathname\n" \ @@ -202,11 +198,10 @@ " -l list files\n" \ " -d directory to extract into\n" \ " -o overwrite files without prompting\n" \ - " -p extract crypted file using password\n\n"); + " -p extract encrypted file using password\n\n"); } -static void Display64BitsSize(ZPOS64_T n, int size_char) -{ +static void Display64BitsSize(ZPOS64_T n, int size_char) { /* to avoid compatibility problem , we do here the conversion */ char number[21]; int offset=19; @@ -233,9 +228,7 @@ printf("%s",&number[pos_string]); } -static int do_list(uf) - unzFile uf; -{ +static int do_list(unzFile uf) { uLong i; unz_global_info64 gi; int err; @@ -250,7 +243,7 @@ char filename_inzip[256]; unz_file_info64 file_info; uLong ratio=0; - const char *string_method; + const char *string_method = ""; char charCrypt=' '; err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) @@ -261,7 +254,7 @@ if (file_info.uncompressed_size>0) ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); - /* display a '*' if the file is crypted */ + /* display a '*' if the file is encrypted */ if ((file_info.flag & 1) != 0) charCrypt='*'; @@ -311,12 +304,7 @@ } -static int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) - unzFile uf; - const int* popt_extract_without_path; - int* popt_overwrite; - const char* password; -{ +static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password) { char filename_inzip[256]; char* filename_withoutpath; char* p; @@ -368,6 +356,20 @@ else write_filename = filename_withoutpath; + if (write_filename[0]!='\0') + { + const char* relative_check = write_filename; + while (relative_check[1]!='\0') + { + if (relative_check[0]=='.' && relative_check[1]=='.') + write_filename = relative_check; + relative_check++; + } + } + + while (write_filename[0]=='/' || write_filename[0]=='.') + write_filename++; + err = unzOpenCurrentFilePassword(uf,password); if (err!=UNZ_OK) { @@ -473,12 +475,7 @@ } -static int do_extract(uf,opt_extract_without_path,opt_overwrite,password) - unzFile uf; - int opt_extract_without_path; - int opt_overwrite; - const char* password; -{ +static int do_extract(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password) { uLong i; unz_global_info64 gi; int err; @@ -508,13 +505,7 @@ return 0; } -static int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password) - unzFile uf; - const char* filename; - int opt_extract_without_path; - int opt_overwrite; - const char* password; -{ +static int do_extract_onefile(unzFile uf, const char* filename, int opt_extract_without_path, int opt_overwrite, const char* password) { if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) { printf("file %s not found in the zipfile\n",filename); @@ -530,10 +521,7 @@ } -int main(argc,argv) - int argc; - char *argv[]; -{ +int main(int argc, char *argv[]) { const char *zipfilename=NULL; const char *filename_to_extract=NULL; const char *password=NULL; @@ -606,7 +594,7 @@ # endif strncpy(filename_try, zipfilename,MAXFILENAME-1); - /* strncpy doesnt append the trailing NULL, of the string is too long. */ + /* strncpy doesn't append the trailing NULL, of the string is too long. */ filename_try[ MAXFILENAME ] = '\0'; # ifdef USEWIN32IOAPI diff -Nru zlib-1.2.13.dfsg/contrib/minizip/minizip.c zlib-1.3.1.dfsg/contrib/minizip/minizip.c --- zlib-1.2.13.dfsg/contrib/minizip/minizip.c 2022-10-10 04:26:39.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/minizip.c 2023-08-18 05:35:43.000000000 +0000 @@ -28,7 +28,7 @@ #endif #endif -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions #define FOPEN_FUNC(filename, mode) fopen(filename, mode) #define FTELLO_FUNC(stream) ftello(stream) @@ -71,11 +71,9 @@ #define MAXFILENAME (256) #ifdef _WIN32 -static int filetime(f, tmzip, dt) - const char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ +/* f: name of file to get info on, tmzip: return value: access, + modification and creation times, dt: dostime */ +static int filetime(const char *f, tm_zip *tmzip, uLong *dt) { int ret = 0; { FILETIME ftLocal; @@ -95,11 +93,9 @@ } #else #if defined(unix) || defined(__APPLE__) -static int filetime(f, tmzip, dt) - const char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ +/* f: name of file to get info on, tmzip: return value: access, + modification and creation times, dt: dostime */ +static int filetime(const char *f, tm_zip *tmzip, uLong *dt) { (void)dt; int ret=0; struct stat s; /* results of stat() */ @@ -114,7 +110,7 @@ len = MAXFILENAME; strncpy(name, f,MAXFILENAME-1); - /* strncpy doesnt append the trailing NULL, of the string is too long. */ + /* strncpy doesn't append the trailing NULL, of the string is too long. */ name[ MAXFILENAME ] = '\0'; if (name[len - 1] == '/') @@ -138,11 +134,12 @@ return ret; } #else -uLong filetime(f, tmzip, dt) - const char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ +/* f: name of file to get info on, tmzip: return value: access, + modification and creation times, dt: dostime */ +static int filetime(const char *f, tm_zip *tmzip, uLong *dt) { + (void)f; + (void)tmzip; + (void)dt; return 0; } #endif @@ -151,9 +148,7 @@ -static int check_exist_file(filename) - const char* filename; -{ +static int check_exist_file(const char* filename) { FILE* ftestexist; int ret = 1; ftestexist = FOPEN_FUNC(filename,"rb"); @@ -164,14 +159,12 @@ return ret; } -static void do_banner() -{ +static void do_banner(void) { printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); } -static void do_help() -{ +static void do_help(void) { printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ " -o Overwrite existing file.zip\n" \ " -a Append to existing file.zip\n" \ @@ -183,8 +176,7 @@ /* calculate the CRC32 of a file, because to encrypt a file, we need known the CRC32 of the file before */ -static int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) -{ +static int getFileCrc(const char* filenameinzip, void* buf, unsigned long size_buf, unsigned long* result_crc) { unsigned long calculate_crc=0; int err=ZIP_OK; FILE * fin = FOPEN_FUNC(filenameinzip,"rb"); @@ -222,8 +214,7 @@ return err; } -static int isLargeFile(const char* filename) -{ +static int isLargeFile(const char* filename) { int largeFile = 0; ZPOS64_T pos = 0; FILE* pFile = FOPEN_FUNC(filename, "rb"); @@ -233,7 +224,7 @@ FSEEKO_FUNC(pFile, 0, SEEK_END); pos = (ZPOS64_T)FTELLO_FUNC(pFile); - printf("File : %s is %lld bytes\n", filename, pos); + printf("File : %s is %llu bytes\n", filename, pos); if(pos >= 0xffffffff) largeFile = 1; @@ -244,10 +235,7 @@ return largeFile; } -int main(argc,argv) - int argc; - char *argv[]; -{ +int main(int argc, char *argv[]) { int i; int opt_overwrite=0; int opt_compress_level=Z_DEFAULT_COMPRESSION; @@ -323,7 +311,7 @@ zipok = 1 ; strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); - /* strncpy doesnt append the trailing NULL, of the string is too long. */ + /* strncpy doesn't append the trailing NULL, of the string is too long. */ filename_try[ MAXFILENAME ] = '\0'; len=(int)strlen(filename_try); @@ -393,10 +381,10 @@ ((argv[i][1]=='o') || (argv[i][1]=='O') || (argv[i][1]=='a') || (argv[i][1]=='A') || (argv[i][1]=='p') || (argv[i][1]=='P') || - ((argv[i][1]>='0') || (argv[i][1]<='9'))) && + ((argv[i][1]>='0') && (argv[i][1]<='9'))) && (strlen(argv[i]) == 2))) { - FILE * fin; + FILE * fin = NULL; size_t size_read; const char* filenameinzip = argv[i]; const char *savefilenameinzip; diff -Nru zlib-1.2.13.dfsg/contrib/minizip/mztools.c zlib-1.3.1.dfsg/contrib/minizip/mztools.c --- zlib-1.2.13.dfsg/contrib/minizip/mztools.c 2012-01-21 19:58:45.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/mztools.c 2023-04-16 05:56:37.000000000 +0000 @@ -27,13 +27,7 @@ WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ } while(0) -extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) -const char* file; -const char* fileOut; -const char* fileOutTmp; -uLong* nRecovered; -uLong* bytesRecovered; -{ +extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char* fileOutTmp, uLong* nRecovered, uLong* bytesRecovered) { int err = Z_OK; FILE* fpZip = fopen(file, "rb"); FILE* fpOut = fopen(fileOut, "wb"); diff -Nru zlib-1.2.13.dfsg/contrib/minizip/unzip.c zlib-1.3.1.dfsg/contrib/minizip/unzip.c --- zlib-1.2.13.dfsg/contrib/minizip/unzip.c 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/unzip.c 2024-01-18 00:43:38.000000000 +0000 @@ -49,12 +49,12 @@ Copyright (C) 2007-2008 Even Rouault - Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). + Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G should only read the compressed/uncompressed size from the Zip64 format if the size from normal header was 0xFFFFFFFF - Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant - Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) + Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required) Patch created by Daniel Borca Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer @@ -77,8 +77,6 @@ #ifdef STDC # include -# include -# include #endif #ifdef NO_ERRNO_H extern int errno; @@ -111,9 +109,6 @@ #ifndef ALLOC # define ALLOC(size) (malloc(size)) #endif -#ifndef TRYFREE -# define TRYFREE(p) { free(p);} -#endif #define SIZECENTRALDIRITEM (0x2e) #define SIZEZIPLOCALHEADER (0x1e) @@ -122,7 +117,7 @@ const char unz_copyright[] = " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; -/* unz_file_info_interntal contain internal info about a file in zipfile*/ +/* unz_file_info64_internal contain internal info about a file in zipfile*/ typedef struct unz_file_info64_internal_s { ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ @@ -153,7 +148,7 @@ ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ uLong compression_method; /* compression method (0==store) */ ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ int raw; @@ -166,7 +161,7 @@ { zlib_filefunc64_32_def z_filefunc; int is64bitOpenFunction; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ unz_global_info64 gi; /* public global information */ ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ ZPOS64_T num_file; /* number of the current file in the zipfile*/ @@ -197,29 +192,24 @@ #include "crypt.h" #endif + /* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been successfully opened for reading. + Reads a long in LSB order from the given gz_stream. Sets */ - -local int unz64local_getByte OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) -{ - unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) +local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) { + unsigned char c[2]; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2); + if (err==2) { - *pi = (int)c; + *pX = c[0] | ((uLong)c[1] << 8); return UNZ_OK; } else { + *pX = 0; if (ZERROR64(*pzlib_filefunc_def,filestream)) return UNZ_ERRNO; else @@ -227,127 +217,50 @@ } } - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unz64local_getShort OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, +local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; + uLong *pX) { + unsigned char c[4]; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4); + if (err==4) + { + *pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24); + return UNZ_OK; + } else + { *pX = 0; - return err; + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } } -local int unz64local_getLong64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX)); - - -local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX) -{ - ZPOS64_T x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (ZPOS64_T)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<16; - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<24; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<32; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<40; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<48; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<56; - - if (err==UNZ_OK) - *pX = x; +local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + ZPOS64_T *pX) { + unsigned char c[8]; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8); + if (err==8) + { + *pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24) + | ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56); + return UNZ_OK; + } else + { *pX = 0; - return err; + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } } /* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) -{ +local int strcmpcasenosensitive_internal(const char* fileName1, const char* fileName2) { for (;;) { char c1=*(fileName1++); @@ -379,19 +292,17 @@ #endif /* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + Compare two filenames (fileName1,fileName2). + If iCaseSensitivity = 1, comparison is case sensitive (like strcmp) + If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + If iCaseSensitivity = 0, case sensitivity is default of your operating system (like 1 on Unix, 2 on Windows) */ extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, - const char* fileName2, - int iCaseSensitivity) - -{ + const char* fileName2, + int iCaseSensitivity) { if (iCaseSensitivity==0) iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; @@ -405,21 +316,23 @@ #define BUFREADCOMMENT (0x400) #endif +#ifndef CENTRALDIRINVALID +#define CENTRALDIRINVALID ((ZPOS64_T)(-1)) +#endif + /* Locate the Central directory of a zipfile (at the end, just before the global comment) */ -local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); -local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) { unsigned char* buf; ZPOS64_T uSizeFile; ZPOS64_T uBackRead; ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; + ZPOS64_T uPosFound=CENTRALDIRINVALID; if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; + return CENTRALDIRINVALID; uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); @@ -429,7 +342,7 @@ buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); if (buf==NULL) - return 0; + return CENTRALDIRINVALID; uBackRead = 4; while (uBackReadz_filefunc, s->filestream); - TRYFREE(s); + free(s); return UNZ_OK; } @@ -825,8 +727,7 @@ Write info about the ZipFile in the *pglobal_info structure. No preparation of the structure is needed return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) -{ +extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64* pglobal_info) { unz64_s* s; if (file==NULL) return UNZ_PARAMERROR; @@ -835,8 +736,7 @@ return UNZ_OK; } -extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) -{ +extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32) { unz64_s* s; if (file==NULL) return UNZ_PARAMERROR; @@ -847,10 +747,9 @@ return UNZ_OK; } /* - Translate date/time from Dos format to tm_unz (readable more easilty) + Translate date/time from Dos format to tm_unz (readable more easily) */ -local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) -{ +local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz* ptm) { ZPOS64_T uDate; uDate = (ZPOS64_T)(ulDosDate>>16); ptm->tm_mday = (int)(uDate&0x1f) ; @@ -865,28 +764,16 @@ /* Get Info about the current file in the zipfile, with internal only info */ -local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unz64local_GetCurrentFileInfoInternal (unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize) -{ +local int unz64local_GetCurrentFileInfoInternal(unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) { unz64_s* s; unz_file_info64 file_info; unz_file_info64_internal file_info_internal; @@ -1038,33 +925,31 @@ /* ZIP64 extra fields */ if (headerId == 0x0001) { - uLong uL; - - if(file_info.uncompressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.compressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info_internal.offset_curfile == MAXU32) - { - /* Relative Header offset */ - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.disk_num_start == MAXU32) - { - /* Disk Start Number */ - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info.uncompressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.compressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info_internal.offset_curfile == MAXU32) + { + /* Relative Header offset */ + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.disk_num_start == 0xffff) + { + /* Disk Start Number */ + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + } } else @@ -1121,24 +1006,22 @@ No preparation of the structure is needed return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, - unz_file_info64 * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ +extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, + unz_file_info64 * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) { return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); } -extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, - unz_file_info * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ +extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, + unz_file_info * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) { int err; unz_file_info64 file_info64; err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, @@ -1162,7 +1045,7 @@ pfile_info->internal_fa = file_info64.internal_fa; pfile_info->external_fa = file_info64.external_fa; - pfile_info->tmu_date = file_info64.tmu_date, + pfile_info->tmu_date = file_info64.tmu_date; pfile_info->compressed_size = (uLong)file_info64.compressed_size; @@ -1175,8 +1058,7 @@ Set the current file of the zipfile to the first file. return UNZ_OK if there is no problem */ -extern int ZEXPORT unzGoToFirstFile (unzFile file) -{ +extern int ZEXPORT unzGoToFirstFile(unzFile file) { int err=UNZ_OK; unz64_s* s; if (file==NULL) @@ -1196,8 +1078,7 @@ return UNZ_OK if there is no problem return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. */ -extern int ZEXPORT unzGoToNextFile (unzFile file) -{ +extern int ZEXPORT unzGoToNextFile(unzFile file) { unz64_s* s; int err; @@ -1229,8 +1110,7 @@ UNZ_OK if the file is found. It becomes the current file. UNZ_END_OF_LIST_OF_FILE if the file is not found */ -extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) -{ +extern int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) { unz64_s* s; int err; @@ -1305,8 +1185,7 @@ } unz_file_pos; */ -extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) -{ +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) { unz64_s* s; if (file==NULL || file_pos==NULL) @@ -1321,10 +1200,7 @@ return UNZ_OK; } -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos) -{ +extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos) { unz64_file_pos file_pos64; int err = unzGetFilePos64(file,&file_pos64); if (err==UNZ_OK) @@ -1335,8 +1211,7 @@ return err; } -extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) -{ +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) { unz64_s* s; int err; @@ -1357,10 +1232,7 @@ return err; } -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos) -{ +extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos) { unz64_file_pos file_pos64; if (file_pos == NULL) return UNZ_PARAMERROR; @@ -1382,10 +1254,9 @@ store in *piSizeVar the size of extra info in local header (filename and size of extra field data) */ -local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, - ZPOS64_T * poffset_local_extrafield, - uInt * psize_local_extrafield) -{ +local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar, + ZPOS64_T * poffset_local_extrafield, + uInt * psize_local_extrafield) { uLong uMagic,uData,uFlags; uLong size_filename; uLong size_extra_field; @@ -1469,9 +1340,8 @@ Open for reading data the current file in the zipfile. If there is no error and the file is opened, the return value is UNZ_OK. */ -extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, - int* level, int raw, const char* password) -{ +extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, + int* level, int raw, const char* password) { int err=UNZ_OK; uInt iSizeVar; unz64_s* s; @@ -1509,7 +1379,7 @@ if (pfile_in_zip_read_info->read_buffer==NULL) { - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info); return UNZ_INTERNALERROR; } @@ -1566,8 +1436,8 @@ pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; else { - TRYFREE(pfile_in_zip_read_info->read_buffer); - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info->read_buffer); + free(pfile_in_zip_read_info); return err; } #else @@ -1587,8 +1457,8 @@ pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; else { - TRYFREE(pfile_in_zip_read_info->read_buffer); - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info->read_buffer); + free(pfile_in_zip_read_info); return err; } /* windowBits is passed < 0 to tell that there is no zlib header. @@ -1640,25 +1510,21 @@ return UNZ_OK; } -extern int ZEXPORT unzOpenCurrentFile (unzFile file) -{ +extern int ZEXPORT unzOpenCurrentFile(unzFile file) { return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); } -extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) -{ +extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char* password) { return unzOpenCurrentFile3(file, NULL, NULL, 0, password); } -extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) -{ +extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int* method, int* level, int raw) { return unzOpenCurrentFile3(file, method, level, raw, NULL); } /** Addition for GDAL : START */ -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) -{ +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; s=(unz64_s*)file; @@ -1678,13 +1544,12 @@ buf contain buffer where data must be copied len the size of buf. - return the number of byte copied if somes bytes are copied + return the number of byte copied if some bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ -extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) -{ +extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { int err=UNZ_OK; uInt iRead = 0; unz64_s* s; @@ -1891,8 +1756,7 @@ /* Give the current position in uncompressed data */ -extern z_off_t ZEXPORT unztell (unzFile file) -{ +extern z_off_t ZEXPORT unztell(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; if (file==NULL) @@ -1906,8 +1770,7 @@ return (z_off_t)pfile_in_zip_read_info->stream.total_out; } -extern ZPOS64_T ZEXPORT unztell64 (unzFile file) -{ +extern ZPOS64_T ZEXPORT unztell64(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; @@ -1926,8 +1789,7 @@ /* return 1 if the end of file was reached, 0 elsewhere */ -extern int ZEXPORT unzeof (unzFile file) -{ +extern int ZEXPORT unzeof(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; if (file==NULL) @@ -1958,8 +1820,7 @@ the return value is the number of bytes copied in buf, or (if <0) the error code */ -extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) -{ +extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; uInt read_now; @@ -2006,8 +1867,7 @@ Close the file in zip opened with unzOpenCurrentFile Return UNZ_CRCERROR if all the file was read but the CRC is not good */ -extern int ZEXPORT unzCloseCurrentFile (unzFile file) -{ +extern int ZEXPORT unzCloseCurrentFile(unzFile file) { int err=UNZ_OK; unz64_s* s; @@ -2029,7 +1889,7 @@ } - TRYFREE(pfile_in_zip_read_info->read_buffer); + free(pfile_in_zip_read_info->read_buffer); pfile_in_zip_read_info->read_buffer = NULL; if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) inflateEnd(&pfile_in_zip_read_info->stream); @@ -2040,7 +1900,7 @@ pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info); s->pfile_in_zip_read=NULL; @@ -2053,8 +1913,7 @@ uSizeBuf is the size of the szComment buffer. return the number of byte copied or an error code <0 */ -extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) -{ +extern int ZEXPORT unzGetGlobalComment(unzFile file, char * szComment, uLong uSizeBuf) { unz64_s* s; uLong uReadThis ; if (file==NULL) @@ -2081,8 +1940,7 @@ } /* Additions by RX '2004 */ -extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) -{ +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) { unz64_s* s; if (file==NULL) @@ -2096,8 +1954,7 @@ return s->pos_in_central_dir; } -extern uLong ZEXPORT unzGetOffset (unzFile file) -{ +extern uLong ZEXPORT unzGetOffset(unzFile file) { ZPOS64_T offset64; if (file==NULL) @@ -2106,8 +1963,7 @@ return (uLong)offset64; } -extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) -{ +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) { unz64_s* s; int err; @@ -2124,7 +1980,6 @@ return err; } -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) -{ +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) { return unzSetOffset64(file,pos); } diff -Nru zlib-1.2.13.dfsg/contrib/minizip/unzip.h zlib-1.3.1.dfsg/contrib/minizip/unzip.h --- zlib-1.2.13.dfsg/contrib/minizip/unzip.h 2022-01-01 22:55:47.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/unzip.h 2024-01-17 21:49:11.000000000 +0000 @@ -150,21 +150,21 @@ tm_unz tmu_date; } unz_file_info; -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi +extern int ZEXPORT unzStringFileNameCompare(const char* fileName1, + const char* fileName2, + int iCaseSensitivity); +/* + Compare two filenames (fileName1,fileName2). + If iCaseSensitivity = 1, comparison is case sensitive (like strcmp) + If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + If iCaseSensitivity = 0, case sensitivity is default of your operating system (like 1 on Unix, 2 on Windows) */ -extern unzFile ZEXPORT unzOpen OF((const char *path)); -extern unzFile ZEXPORT unzOpen64 OF((const void *path)); +extern unzFile ZEXPORT unzOpen(const char *path); +extern unzFile ZEXPORT unzOpen64(const void *path); /* Open a Zip file. path contain the full pathname (by example, on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer @@ -181,41 +181,41 @@ */ -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); +extern unzFile ZEXPORT unzOpen2(const char *path, + zlib_filefunc_def* pzlib_filefunc_def); /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write the zip file (see ioapi.h) */ -extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, - zlib_filefunc64_def* pzlib_filefunc_def)); +extern unzFile ZEXPORT unzOpen2_64(const void *path, + zlib_filefunc64_def* pzlib_filefunc_def); /* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write the zip file (see ioapi.h) */ -extern int ZEXPORT unzClose OF((unzFile file)); +extern int ZEXPORT unzClose(unzFile file); /* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile (see later), these files MUST be closed with unzCloseCurrentFile before call unzClose. return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); +extern int ZEXPORT unzGetGlobalInfo(unzFile file, + unz_global_info *pglobal_info); -extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, - unz_global_info64 *pglobal_info)); +extern int ZEXPORT unzGetGlobalInfo64(unzFile file, + unz_global_info64 *pglobal_info); /* Write info about the ZipFile in the *pglobal_info structure. No preparation of the structure is needed return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); +extern int ZEXPORT unzGetGlobalComment(unzFile file, + char *szComment, + uLong uSizeBuf); /* Get the global comment string of the ZipFile, in the szComment buffer. uSizeBuf is the size of the szComment buffer. @@ -226,22 +226,22 @@ /***************************************************************************/ /* Unzip package allow you browse the directory of the zipfile */ -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +extern int ZEXPORT unzGoToFirstFile(unzFile file); /* Set the current file of the zipfile to the first file. return UNZ_OK if there is no problem */ -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +extern int ZEXPORT unzGoToNextFile(unzFile file); /* Set the current file of the zipfile to the next file. return UNZ_OK if there is no problem return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. */ -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); +extern int ZEXPORT unzLocateFile(unzFile file, + const char *szFileName, + int iCaseSensitivity); /* Try locate the file szFileName in the zipfile. For the iCaseSensitivity signification, see unzStringFileNameCompare @@ -285,28 +285,28 @@ /* ****************************************** */ -extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); +extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize); + +extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize); /* Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about + if pfile_info!=NULL, the *pfile_info structure will contain some info about the current file - if szFileName!=NULL, the filemane string will be copied in szFileName + if szFileName!=NULL, the filename string will be copied in szFileName (fileNameBufferSize is the size of the buffer) if extraField!=NULL, the extra field information will be copied in extraField (extraFieldBufferSize is the size of the buffer). @@ -318,7 +318,7 @@ /** Addition for GDAL : START */ -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file); /** Addition for GDAL : END */ @@ -328,24 +328,24 @@ from it, and close it (you can close it before reading all the file) */ -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +extern int ZEXPORT unzOpenCurrentFile(unzFile file); /* Open for reading data the current file in the zipfile. If there is no error, the return value is UNZ_OK. */ -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); +extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, + const char* password); /* Open for reading data the current file in the zipfile. password is a crypting password If there is no error, the return value is UNZ_OK. */ -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); +extern int ZEXPORT unzOpenCurrentFile2(unzFile file, + int* method, + int* level, + int raw); /* Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) if raw==1 @@ -355,11 +355,11 @@ but you CANNOT set method parameter as NULL */ -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); +extern int ZEXPORT unzOpenCurrentFile3(unzFile file, + int* method, + int* level, + int raw, + const char* password); /* Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) if raw==1 @@ -370,41 +370,41 @@ */ -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +extern int ZEXPORT unzCloseCurrentFile(unzFile file); /* Close the file in zip opened with unzOpenCurrentFile Return UNZ_CRCERROR if all the file was read but the CRC is not good */ -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); +extern int ZEXPORT unzReadCurrentFile(unzFile file, + voidp buf, + unsigned len); /* Read bytes from the current file (opened by unzOpenCurrentFile) buf contain buffer where data must be copied len the size of buf. - return the number of byte copied if somes bytes are copied + return the number of byte copied if some bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ -extern z_off_t ZEXPORT unztell OF((unzFile file)); +extern z_off_t ZEXPORT unztell(unzFile file); -extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +extern ZPOS64_T ZEXPORT unztell64(unzFile file); /* Give the current position in uncompressed data */ -extern int ZEXPORT unzeof OF((unzFile file)); +extern int ZEXPORT unzeof(unzFile file); /* return 1 if the end of file was reached, 0 elsewhere */ -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); +extern int ZEXPORT unzGetLocalExtrafield(unzFile file, + voidp buf, + unsigned len); /* Read extra field from the current file (opened by unzOpenCurrentFile) This is the local-header version of the extra field (sometimes, there is diff -Nru zlib-1.2.13.dfsg/contrib/minizip/zip.c zlib-1.3.1.dfsg/contrib/minizip/zip.c --- zlib-1.2.13.dfsg/contrib/minizip/zip.c 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/zip.c 2024-01-17 21:49:11.000000000 +0000 @@ -14,7 +14,7 @@ Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data - It is used when recreting zip archive with RAW when deleting items from a zip. + It is used when recreating zip archive with RAW when deleting items from a zip. ZIP64 data is automatically added to items that needs it, and existing ZIP64 data need to be removed. Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer @@ -25,14 +25,13 @@ #include #include #include +#include #include #include "zlib.h" #include "zip.h" #ifdef STDC # include -# include -# include #endif #ifdef NO_ERRNO_H extern int errno; @@ -47,7 +46,7 @@ /* compile with -Dlocal if your debugger can't find static symbols */ #ifndef VERSIONMADEBY -# define VERSIONMADEBY (0x0) /* platform depedent */ +# define VERSIONMADEBY (0x0) /* platform dependent */ #endif #ifndef Z_BUFSIZE @@ -61,9 +60,6 @@ #ifndef ALLOC # define ALLOC(size) (malloc(size)) #endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif /* #define SIZECENTRALDIRITEM (0x2e) @@ -138,20 +134,20 @@ uInt pos_in_buffered_data; /* last written byte in buffered_data */ ZPOS64_T pos_local_header; /* offset of the local header of the file - currenty writing */ + currently writing */ char* central_header; /* central header data for the current file */ uLong size_centralExtra; uLong size_centralheader; /* size of the central header for cur file */ uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */ uLong flag; /* flag of the file currently writing */ - int method; /* compression method of file currenty wr.*/ + int method; /* compression method of file currently wr.*/ int raw; /* 1 for directly writing raw data */ Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ uLong dosDate; uLong crc32; int encrypt; - int zip64; /* Add ZIP64 extened information in the extra field */ + int zip64; /* Add ZIP64 extended information in the extra field */ ZPOS64_T pos_zip64extrainfo; ZPOS64_T totalCompressedData; ZPOS64_T totalUncompressedData; @@ -165,10 +161,10 @@ typedef struct { zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ linkedlist_data central_dir;/* datablock with central dir in construction*/ int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ - curfile64_info ci; /* info on the file curretly writing */ + curfile64_info ci; /* info on the file currently writing */ ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ ZPOS64_T add_position_when_writing_offset; @@ -186,8 +182,7 @@ #include "crypt.h" #endif -local linkedlist_datablock_internal* allocate_new_datablock() -{ +local linkedlist_datablock_internal* allocate_new_datablock(void) { linkedlist_datablock_internal* ldi; ldi = (linkedlist_datablock_internal*) ALLOC(sizeof(linkedlist_datablock_internal)); @@ -200,30 +195,26 @@ return ldi; } -local void free_datablock(linkedlist_datablock_internal* ldi) -{ +local void free_datablock(linkedlist_datablock_internal* ldi) { while (ldi!=NULL) { linkedlist_datablock_internal* ldinext = ldi->next_datablock; - TRYFREE(ldi); + free(ldi); ldi = ldinext; } } -local void init_linkedlist(linkedlist_data* ll) -{ +local void init_linkedlist(linkedlist_data* ll) { ll->first_block = ll->last_block = NULL; } -local void free_linkedlist(linkedlist_data* ll) -{ +local void free_linkedlist(linkedlist_data* ll) { free_datablock(ll->first_block); ll->first_block = ll->last_block = NULL; } -local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) -{ +local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) { linkedlist_datablock_internal* ldi; const unsigned char* from_copy; @@ -238,7 +229,7 @@ } ldi = ll->last_block; - from_copy = (unsigned char*)buf; + from_copy = (const unsigned char*)buf; while (len>0) { @@ -283,9 +274,7 @@ nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) */ -local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)); -local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) -{ +local int zip64local_putValue(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) { unsigned char buf[8]; int n; for (n = 0; n < nbByte; n++) @@ -307,9 +296,7 @@ return ZIP_OK; } -local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); -local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) -{ +local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) { unsigned char* buf=(unsigned char*)dest; int n; for (n = 0; n < nbByte; n++) { @@ -329,8 +316,7 @@ /****************************************************************************/ -local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) -{ +local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) { uLong year = (uLong)ptm->tm_year; if (year>=1980) year-=1980; @@ -344,10 +330,7 @@ /****************************************************************************/ -local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); - -local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) -{ +local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int* pi) { unsigned char c; int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); if (err==1) @@ -368,10 +351,7 @@ /* =========================================================================== Reads a long in LSB order from the given gz_stream. Sets */ -local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); - -local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) -{ +local int zip64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) { uLong x ; int i = 0; int err; @@ -390,10 +370,7 @@ return err; } -local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); - -local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) -{ +local int zip64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) { uLong x ; int i = 0; int err; @@ -420,11 +397,8 @@ return err; } -local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); - -local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) -{ +local int zip64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) { ZPOS64_T x; int i = 0; int err; @@ -475,10 +449,7 @@ Locate the Central directory of a zipfile (at the end, just before the global comment) */ -local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); - -local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ +local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) { unsigned char* buf; ZPOS64_T uSizeFile; ZPOS64_T uBackRead; @@ -529,7 +500,7 @@ if (uPosFound!=0) break; } - TRYFREE(buf); + free(buf); return uPosFound; } @@ -537,10 +508,7 @@ Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before the global comment) */ -local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); - -local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ +local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) { unsigned char* buf; ZPOS64_T uSizeFile; ZPOS64_T uBackRead; @@ -595,7 +563,7 @@ break; } - TRYFREE(buf); + free(buf); if (uPosFound == 0) return 0; @@ -607,7 +575,7 @@ if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) return 0; - /* number of the disk with the start of the zip64 end of central directory */ + /* number of the disk with the start of the zip64 end of central directory */ if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) return 0; if (uL != 0) @@ -637,8 +605,7 @@ return relativeOffset; } -local int LoadCentralDirectoryRecord(zip64_internal* pziinit) -{ +local int LoadCentralDirectoryRecord(zip64_internal* pziinit) { int err=ZIP_OK; ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ @@ -647,10 +614,10 @@ ZPOS64_T central_pos; uLong uL; - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ + uLong number_disk; /* number of the current disk, used for + spanning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number of the disk with central dir, used + for spanning ZIP, unsupported, always 0*/ ZPOS64_T number_entry; ZPOS64_T number_entry_CD; /* total number of entries in the central dir @@ -830,7 +797,7 @@ size_central_dir_to_read-=read_this; } - TRYFREE(buf_read); + free(buf_read); } pziinit->begin_pos = byte_before_the_zipfile; pziinit->number_entry = number_entry_CD; @@ -846,8 +813,7 @@ /************************************************************/ -extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) -{ +extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) { zip64_internal ziinit; zip64_internal* zi; int err=ZIP_OK; @@ -905,9 +871,9 @@ if (err != ZIP_OK) { # ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(ziinit.globalcomment); + free(ziinit.globalcomment); # endif /* !NO_ADDFILEINEXISTINGZIP*/ - TRYFREE(zi); + free(zi); return NULL; } else @@ -917,8 +883,7 @@ } } -extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) -{ +extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) { if (pzlib_filefunc32_def != NULL) { zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; @@ -929,8 +894,7 @@ return zipOpen3(pathname, append, globalcomment, NULL); } -extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) -{ +extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) { if (pzlib_filefunc_def != NULL) { zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; @@ -945,18 +909,15 @@ -extern zipFile ZEXPORT zipOpen (const char* pathname, int append) -{ +extern zipFile ZEXPORT zipOpen(const char* pathname, int append) { return zipOpen3((const void*)pathname,append,NULL,NULL); } -extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) -{ +extern zipFile ZEXPORT zipOpen64(const void* pathname, int append) { return zipOpen3(pathname,append,NULL,NULL); } -local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) -{ +local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) { /* write the local header */ int err; uInt size_filename = (uInt)strlen(filename); @@ -1052,14 +1013,13 @@ It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize unnecessary allocations. */ -extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting, - uLong versionMadeBy, uLong flagBase, int zip64) -{ +extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, + uLong versionMadeBy, uLong flagBase, int zip64) { zip64_internal* zi; uInt size_filename; uInt size_comment; @@ -1083,6 +1043,17 @@ return ZIP_PARAMERROR; #endif + // The filename and comment length must fit in 16 bits. + if ((filename!=NULL) && (strlen(filename)>0xffff)) + return ZIP_PARAMERROR; + if ((comment!=NULL) && (strlen(comment)>0xffff)) + return ZIP_PARAMERROR; + // The extra field length must fit in 16 bits. If the member also requires + // a Zip64 extra block, that will also need to fit within that 16-bit + // length, but that will be checked for later. + if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff)) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; if (zi->in_opened_file_inzip == 1) @@ -1262,35 +1233,33 @@ return err; } -extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting, - uLong versionMadeBy, uLong flagBase) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting, versionMadeBy, flagBase, 0); +extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, + uLong versionMadeBy, uLong flagBase) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, versionMadeBy, flagBase, 0); } -extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting, VERSIONMADEBY, 0, 0); +extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, 0); } extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, @@ -1298,70 +1267,64 @@ const void* extrafield_global, uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting, int zip64) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting, VERSIONMADEBY, 0, zip64); + const char* password, uLong crcForCrypting, int zip64) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, zip64); } extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, 0); + const char* comment, int method, int level, int raw) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, 0); } extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, int zip64) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, zip64); + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, int zip64) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, zip64); } -extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void*extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int zip64) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, 0, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void*extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, 0, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, 0); +extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void*extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int zip64) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void*extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level) { + return zipOpenNewFileInZip4_64(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, 0); } -local int zip64FlushWriteBuffer(zip64_internal* zi) -{ +local int zip64FlushWriteBuffer(zip64_internal* zi) { int err=ZIP_OK; if (zi->ci.encrypt != 0) @@ -1399,8 +1362,7 @@ return err; } -extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) -{ +extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned int len) { zip64_internal* zi; int err=ZIP_OK; @@ -1450,7 +1412,7 @@ else #endif { - zi->ci.stream.next_in = (Bytef*)buf; + zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf; zi->ci.stream.avail_in = len; while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) @@ -1501,13 +1463,11 @@ return err; } -extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) -{ +extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32) { return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); } -extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) -{ +extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32) { zip64_internal* zi; ZPOS64_T compressed_size; uLong invalidValue = 0xffffffff; @@ -1648,7 +1608,7 @@ if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) { - // we can not write more data to the buffer that we have room for. + // we cannot write more data to the buffer that we have room for. return ZIP_BADZIPFILE; } @@ -1742,13 +1702,11 @@ return err; } -extern int ZEXPORT zipCloseFileInZip (zipFile file) -{ +extern int ZEXPORT zipCloseFileInZip(zipFile file) { return zipCloseFileInZipRaw (file,0,0); } -local int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) -{ +local int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) { int err = ZIP_OK; ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset; @@ -1769,8 +1727,7 @@ return err; } -local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) -{ +local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) { int err = ZIP_OK; uLong Zip64DataSize = 44; @@ -1808,8 +1765,8 @@ } return err; } -local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) -{ + +local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) { int err = ZIP_OK; /*signature*/ @@ -1856,8 +1813,7 @@ return err; } -local int Write_GlobalComment(zip64_internal* zi, const char* global_comment) -{ +local int Write_GlobalComment(zip64_internal* zi, const char* global_comment) { int err = ZIP_OK; uInt size_global_comment = 0; @@ -1874,8 +1830,7 @@ return err; } -extern int ZEXPORT zipClose (zipFile file, const char* global_comment) -{ +extern int ZEXPORT zipClose(zipFile file, const char* global_comment) { zip64_internal* zi; int err = 0; uLong size_centraldir = 0; @@ -1917,7 +1872,7 @@ free_linkedlist(&(zi->central_dir)); pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; - if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) + if(pos >= 0xffffffff || zi->number_entry >= 0xFFFF) { ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); @@ -1936,15 +1891,14 @@ err = ZIP_ERRNO; #ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(zi->globalcomment); + free(zi->globalcomment); #endif - TRYFREE(zi); + free(zi); return err; } -extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) -{ +extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader) { char* p = pData; int size = 0; char* pNewHeader; @@ -1996,7 +1950,7 @@ else retVal = ZIP_ERRNO; - TRYFREE(pNewHeader); + free(pNewHeader); return retVal; } diff -Nru zlib-1.2.13.dfsg/contrib/minizip/zip.h zlib-1.3.1.dfsg/contrib/minizip/zip.h --- zlib-1.2.13.dfsg/contrib/minizip/zip.h 2022-01-01 22:55:47.000000000 +0000 +++ zlib-1.3.1.dfsg/contrib/minizip/zip.h 2023-11-15 02:44:32.000000000 +0000 @@ -113,8 +113,8 @@ #define APPEND_STATUS_CREATEAFTER (1) #define APPEND_STATUS_ADDINZIP (2) -extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); -extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); +extern zipFile ZEXPORT zipOpen(const char *pathname, int append); +extern zipFile ZEXPORT zipOpen64(const void *pathname, int append); /* Create a zipfile. pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on @@ -131,55 +131,55 @@ /* Note : there is no delete function into a zipfile. If you want delete file into a zipfile, you must open a zipfile, and create another - Of couse, you can use RAW reading and writing to copy the file you did not want delte + Of course, you can use RAW reading and writing to copy the file you did not want delete */ -extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc_def* pzlib_filefunc_def)); +extern zipFile ZEXPORT zipOpen2(const char *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc_def* pzlib_filefunc_def); -extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, +extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc* globalcomment, - zlib_filefunc64_def* pzlib_filefunc_def)); + zlib_filefunc64_def* pzlib_filefunc_def); -extern zipFile ZEXPORT zipOpen3 OF((const void *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc64_32_def* pzlib_filefunc64_32_def)); - -extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level)); - -extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int zip64)); +extern zipFile ZEXPORT zipOpen3(const void *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc64_32_def* pzlib_filefunc64_32_def); + +extern int ZEXPORT zipOpenNewFileInZip(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level); + +extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int zip64); /* Open a file in the ZIP for writing. filename : the filename in zip (if NULL, '-' without quote will be used *zipfi contain supplemental information if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header + contains the extrafield data for the local header if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header + contains the extrafield data for the global header if comment != NULL, comment contain the comment string method contain the compression method (0 for store, Z_DEFLATED for deflate) level contain the level of compression (can be Z_DEFAULT_COMPRESSION) @@ -189,70 +189,69 @@ */ -extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw)); - - -extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int zip64)); +extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw); + + +extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int zip64); /* Same than zipOpenNewFileInZip, except if raw=1, we write raw file */ -extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting)); - -extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting, - int zip64 - )); +extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting); + +extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + int zip64); /* Same than zipOpenNewFileInZip2, except @@ -261,47 +260,45 @@ crcForCrypting : crc of file to compress (needed for crypting) */ -extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting, - uLong versionMadeBy, - uLong flagBase - )); - - -extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting, - uLong versionMadeBy, - uLong flagBase, - int zip64 - )); +extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase); + + +extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase, + int zip64); /* Same than zipOpenNewFileInZip4, except versionMadeBy : value for Version made by field @@ -309,25 +306,25 @@ */ -extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, - const void* buf, - unsigned len)); +extern int ZEXPORT zipWriteInFileInZip(zipFile file, + const void* buf, + unsigned len); /* Write data in the zipfile */ -extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); +extern int ZEXPORT zipCloseFileInZip(zipFile file); /* Close the current file in the zipfile */ -extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, - uLong uncompressed_size, - uLong crc32)); - -extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, - ZPOS64_T uncompressed_size, - uLong crc32)); +extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, + uLong uncompressed_size, + uLong crc32); + +extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, + ZPOS64_T uncompressed_size, + uLong crc32); /* Close the current file in the zipfile, for file opened with @@ -335,14 +332,14 @@ uncompressed_size and crc32 are value for the uncompressed size */ -extern int ZEXPORT zipClose OF((zipFile file, - const char* global_comment)); +extern int ZEXPORT zipClose(zipFile file, + const char* global_comment); /* Close the zipfile */ -extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); +extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader); /* zipRemoveExtraInfoBlock - Added by Mathias Svensson diff -Nru zlib-1.2.13.dfsg/crc32.c zlib-1.3.1.dfsg/crc32.c --- zlib-1.2.13.dfsg/crc32.c 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/crc32.c 2023-08-03 20:53:24.000000000 +0000 @@ -103,19 +103,6 @@ # define ARMCRC32 #endif -/* Local functions. */ -local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); -local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); - -#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap OF((z_word_t word)); -#endif - -#if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word OF((z_word_t data)); - local z_word_t crc_word_big OF((z_word_t data)); -#endif - #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) /* Swap the bytes in a z_word_t to convert between little and big endian. Any @@ -123,9 +110,7 @@ instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap(word) - z_word_t word; -{ +local z_word_t byte_swap(z_word_t word) { # if W == 8 return (word & 0xff00000000000000) >> 56 | @@ -146,24 +131,77 @@ } #endif +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Table of powers of x for combining CRC-32s, filled in by make_crc_table() + * below. + */ + local z_crc_t FAR x2n_table[32]; +#else +/* ========================================================================= + * Tables for byte-wise and braided CRC-32 calculations, and a table of powers + * of x for combining CRC-32s, all made by make_crc_table(). + */ +# include "crc32.h" +#endif + /* CRC polynomial. */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ -#ifdef DYNAMIC_CRC_TABLE +/* + Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, + reflected. For speed, this requires that a not be zero. + */ +local z_crc_t multmodp(z_crc_t a, z_crc_t b) { + z_crc_t m, p; + + m = (z_crc_t)1 << 31; + p = 0; + for (;;) { + if (a & m) { + p ^= b; + if ((a & (m - 1)) == 0) + break; + } + m >>= 1; + b = b & 1 ? (b >> 1) ^ POLY : b >> 1; + } + return p; +} +/* + Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been + initialized. + */ +local z_crc_t x2nmodp(z_off64_t n, unsigned k) { + z_crc_t p; + + p = (z_crc_t)1 << 31; /* x^0 == 1 */ + while (n) { + if (n & 1) + p = multmodp(x2n_table[k & 31], p); + n >>= 1; + k++; + } + return p; +} + +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Build the tables for byte-wise and braided CRC-32 calculations, and a table + * of powers of x for combining CRC-32s. + */ local z_crc_t FAR crc_table[256]; -local z_crc_t FAR x2n_table[32]; -local void make_crc_table OF((void)); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256]; - local void braid OF((z_crc_t [][256], z_word_t [][256], int, int)); + local void braid(z_crc_t [][256], z_word_t [][256], int, int); #endif #ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *, int)); - local void write_table32hi OF((FILE *, const z_word_t FAR *, int)); - local void write_table64 OF((FILE *, const z_word_t FAR *, int)); + local void write_table(FILE *, const z_crc_t FAR *, int); + local void write_table32hi(FILE *, const z_word_t FAR *, int); + local void write_table64(FILE *, const z_word_t FAR *, int); #endif /* MAKECRCH */ /* @@ -176,7 +214,6 @@ /* Definition of once functionality. */ typedef struct once_s once_t; -local void once OF((once_t *, void (*)(void))); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -196,10 +233,7 @@ invoke once() at the same time. The state must be a once_t initialized with ONCE_INIT. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!atomic_load(&state->done)) { if (atomic_flag_test_and_set(&state->begun)) while (!atomic_load(&state->done)) @@ -222,10 +256,7 @@ /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set OF((int volatile *)); -local int test_and_set(flag) - int volatile *flag; -{ +local int test_and_set(int volatile *flag) { int was; was = *flag; @@ -234,10 +265,7 @@ } /* Run the provided init() function once. This is not thread-safe. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!state->done) { if (test_and_set(&state->begun)) while (!state->done) @@ -279,8 +307,7 @@ combinations of CRC register values and incoming bytes. */ -local void make_crc_table() -{ +local void make_crc_table(void) { unsigned i, j, n; z_crc_t p; @@ -447,11 +474,7 @@ Write the 32-bit values in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table(out, table, k) - FILE *out; - const z_crc_t FAR *table; - int k; -{ +local void write_table(FILE *out, const z_crc_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -464,11 +487,7 @@ Write the high 32-bits of each value in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table32hi(out, table, k) -FILE *out; -const z_word_t FAR *table; -int k; -{ +local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -484,11 +503,7 @@ bits. If not, then the type cast and format string can be adjusted accordingly. */ -local void write_table64(out, table, k) - FILE *out; - const z_word_t FAR *table; - int k; -{ +local void write_table64(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -498,8 +513,7 @@ } /* Actually do the deed. */ -int main() -{ +int main(void) { make_crc_table(); return 0; } @@ -511,12 +525,7 @@ Generate the little and big-endian braid tables for the given n and z_word_t size w. Each array must have room for w blocks of 256 elements. */ -local void braid(ltl, big, n, w) - z_crc_t ltl[][256]; - z_word_t big[][256]; - int n; - int w; -{ +local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { int k; z_crc_t i, p, q; for (k = 0; k < w; k++) { @@ -531,69 +540,13 @@ } #endif -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables for byte-wise and braided CRC-32 calculations, and a table of powers - * of x for combining CRC-32s, all made by make_crc_table(). - */ -#include "crc32.h" #endif /* DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Routines used for CRC calculation. Some are also required for the table - * generation above. - */ - -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -local z_crc_t multmodp(a, b) - z_crc_t a; - z_crc_t b; -{ - z_crc_t m, p; - - m = (z_crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -local z_crc_t x2nmodp(n, k) - z_off64_t n; - unsigned k; -{ - z_crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - /* ========================================================================= * This function can be used by asm versions of crc32(), and to force the * generation of the CRC tables in a threaded application. */ -const z_crc_t FAR * ZEXPORT get_crc_table() -{ +const z_crc_t FAR * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -619,11 +572,8 @@ #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { z_crc_t val; z_word_t crc1, crc2; const z_word_t *word; @@ -723,18 +673,14 @@ least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word(data) - z_word_t data; -{ +local z_crc_t crc_word(z_word_t data) { int k; for (k = 0; k < W; k++) data = (data >> 8) ^ crc_table[data & 0xff]; return (z_crc_t)data; } -local z_word_t crc_word_big(data) - z_word_t data; -{ +local z_word_t crc_word_big(z_word_t data) { int k; for (k = 0; k < W; k++) data = (data << 8) ^ @@ -745,11 +691,8 @@ #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { /* Return initial CRC, if requested. */ if (buf == Z_NULL) return 0; @@ -781,8 +724,8 @@ words = (z_word_t const *)buf; /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianess at execution time. If the - compiler knows what the endianess will be, it can optimize out the + processors can change the endianness at execution time. If the + compiler knows what the endianness will be, it can optimize out the check and the unused branch. */ endian = 1; if (*(unsigned char *)&endian) { @@ -1069,20 +1012,13 @@ #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; -{ +unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, + uInt len) { return crc32_z(crc, buf, len); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ +uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1090,18 +1026,12 @@ } /* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; -{ +uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64(len2) - z_off64_t len2; -{ +uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1109,17 +1039,11 @@ } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen(len2) - z_off_t len2; -{ +uLong ZEXPORT crc32_combine_gen(z_off_t len2) { return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_op(crc1, crc2, op) - uLong crc1; - uLong crc2; - uLong op; -{ +uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { return multmodp(op, crc1) ^ (crc2 & 0xffffffff); } diff -Nru zlib-1.2.13.dfsg/debian/changelog zlib-1.3.1.dfsg/debian/changelog --- zlib-1.2.13.dfsg/debian/changelog 2023-07-25 05:53:57.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/changelog 2024-03-17 03:04:31.000000000 +0000 @@ -1,9 +1,94 @@ -zlib (1:1.2.13.dfsg-1ubuntu4~20.04.sav0) focal; urgency=medium +zlib (1:1.3.1.dfsg-0ubuntu1~20.04.sav1) focal; urgency=medium - * Backport to Focal - * debian/compat,control: Set compat level to 12 and debhelper BD to (>= 12) + * Revert "Update the version of texlive-binaries we break" (src:texlive-bin + at SavOS PPAs has now been patched to allow zlib 1.3 when linked with 1.2) - -- Rob Savoury Tue, 25 Jul 2023 15:53:57 +1000 + -- Rob Savoury Sat, 16 Mar 2024 20:04:31 -0700 + +zlib (1:1.3.1.dfsg-0ubuntu1~20.04.sav0) focal; urgency=medium + + * New upstream release (fixes minizip CVE-2014-9485 and CVE-2023-45853) + * d/p/: Drop CVE-{2014-9485-miniunzip,2023-45853-minizip}.patch (upstreamed) + - Rebase s390x/add-{accel-deflate,vectorized-crc32}.patch and + power/add-optimized-crc32.patch for source changes + * d/{control,copyright}: Update upstream source URL from http -> https + * d/copyright: Remove contrib/{amd64,asm686,inflate86,masmx64,masmx86} from + Files-Excluded as these directories are no longer in upstream tarball + - Add new contrib/nuget directory to Files-Excluded + * d/watch: Fix watch file for correct download URL (https://zlib.net/) + * debian/{compat,control}: Set compat level 12 and debhelper (>= 12) BD + + -- Rob Savoury Sat, 16 Mar 2024 13:03:35 -0700 + +zlib (1:1.3.dfsg-3ubuntu1) noble; urgency=medium + + * Merge with Debian unstable. Remaining changes: + - Build x32 packages + - Add watch file, with GPG tarball checking, and version mangling + - d/rules: Compile with DFLTCC enabled on s390x and hardware + compression at level 6 + - d/zlib-core.symbols: Drop dfsg suffix from version + * New patches rebased from iii-i/zlib/dfltcc on GitHub: + - d/p/power/*: Add optimized crc32 for POWER8+ + - d/p/s390x/*: Add optimized crc32 and hardware deflate + * Patches superseded by the above: + - d/p/410.patch: Add support for IBM Z hardware-accelerated deflate + - d/p/478.patch: Add optimized crc32 for Power 8+ processors + - d/p/s390x-vectorize-crc32.patch: Add s390x vectorized crc32 support + - d/p/1390.patch: Don't update strm.adler for raw streams on s390x + (DFLTCC), otherwise libxml2 gets broken on s390x. LP #2002511 + - d/p/lp-2018293-fix-crash-in-deflateBound-if-called-before-deflateInt + .patch: Avoid potential deflateBound() function crash on s390x + + -- Mate Kukri Fri, 24 Nov 2023 08:22:52 +0000 + +zlib (1:1.3.dfsg-3) unstable; urgency=low + + * Update the version of texlive-binaries we break since they still had + broken version checks (closes: #1056312). + + -- Mark Brown Thu, 23 Nov 2023 13:02:20 +0000 + +zlib (1:1.3.dfsg-2) unstable; urgency=low + + * Install library into /usr (closes: #1055938). + * Backport patch for minizip CVE-2023-45853 (closes: #1054290). + + -- Mark Brown Fri, 17 Nov 2023 22:10:10 +0000 + +zlib (1:1.3.dfsg-1) unstable; urgency=low + + * New upstream release. + + -- Mark Brown Mon, 06 Nov 2023 16:28:55 +0000 + +zlib (1:1.2.13.dfsg-3) unstable; urgency=low + + * Further fixes to the minizip integration, don't install the minizip + headers in both -dev packages (closes: #1049384). + + -- Mark Brown Tue, 15 Aug 2023 14:35:28 +0100 + +zlib (1:1.2.13.dfsg-2) unstable; urgency=low + + * Build minizip packages since for some reason the minizip upstream + appears to have decided to release via zlib's contrib directiory + and do nothing separate, patch from Michael Gilbert adapted to fix + build issues (closes: #956181). + + -- Mark Brown Tue, 15 Aug 2023 00:28:42 +0100 + +zlib (1:1.2.13.dfsg-1ubuntu5) mantic; urgency=medium + + * Add + d/p/lp-2018293-fix-crash-in-deflateBound-if-called-before-deflateInt.patch + to avoid potential deflateBound() function crash on s390x. + * Clean-up and remove + d/p/lp1932010-ibm-z-add-vectorized-crc32-implementation.patch since it was + replaced by d/p/s390x-vectorize-crc32.patch with 1.2.13.dfsg-1ubuntu3 + but was still in d/p/ (but not in d/p/series). + + -- Frank Heimes Wed, 02 Aug 2023 13:22:26 +0200 zlib (1:1.2.13.dfsg-1ubuntu4) lunar; urgency=medium diff -Nru zlib-1.2.13.dfsg/debian/control zlib-1.3.1.dfsg/debian/control --- zlib-1.2.13.dfsg/debian/control 2023-07-25 05:53:57.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/control 2024-03-17 03:04:31.000000000 +0000 @@ -4,8 +4,8 @@ Maintainer: Ubuntu Developers XSBC-Original-Maintainer: Mark Brown Standards-Version: 4.6.1 -Homepage: http://zlib.net/ -Build-Depends: debhelper (>= 12), gcc-multilib [amd64 i386 kfreebsd-amd64 mips mipsel powerpc ppc64 s390 sparc s390x mipsn32 mipsn32el mipsr6 mipsr6el mipsn32r6 mipsn32r6el mips64 mips64el mips64r6 mips64r6el x32] , dpkg-dev (>= 1.16.1) +Homepage: https://zlib.net/ +Build-Depends: debhelper (>= 12), gcc-multilib [amd64 i386 kfreebsd-amd64 mips mipsel powerpc ppc64 s390 sparc s390x mipsn32 mipsn32el mipsr6 mipsr6el mipsn32r6 mipsn32r6el mips64 mips64el mips64r6 mips64r6el x32] , dpkg-dev (>= 1.16.1), autoconf Package: zlib1g Architecture: any @@ -141,3 +141,50 @@ This package should ONLY be used for building packages, users who do not need to build packages should use multiarch to install the relevant runtime. + +Package: minizip +Section: utils +Architecture: any +Depends: + ${misc:Depends}, + ${shlibs:Depends}, +Replaces: + zlib-bin, +Conflicts: + zlib-bin, +Description: compression library - minizip tools + minizip is a minimalistic library that supports compressing, extracting, + viewing, and manipulating zip files. + . + This package includes the minizip and miniunzip tools. + +Package: libminizip1 +Architecture: any +Multi-Arch: same +Pre-Depends: + ${misc:Pre-Depends} +Depends: + ${misc:Depends}, + ${shlibs:Depends}, +Description: compression library - minizip library + minizip is a minimalistic library that supports compressing, extracting, + viewing, and manipulating zip files. + . + This package includes the minizip library. + +Package: libminizip-dev +Architecture: any +Multi-Arch: same +Section: libdevel +Depends: + ${misc:Depends}, + libminizip1 (= ${binary:Version}) +Replaces: + libkml-dev (<< 1.3.0~r864+git20150723-0fa2f22-1~), +Breaks: + libkml-dev (<< 1.3.0~r864+git20150723-0fa2f22-1~), +Description: compression library - minizip development files + minizip is a minimalistic library that supports compressing, extracting, + viewing, and manipulating zip files. + . + This package includes development support files for the minizip library. diff -Nru zlib-1.2.13.dfsg/debian/copyright zlib-1.3.1.dfsg/debian/copyright --- zlib-1.2.13.dfsg/debian/copyright 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/copyright 2024-03-16 19:23:04.000000000 +0000 @@ -1,7 +1,7 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: zlib Upstream-Contact: zlib@gzip.org -Source: http://zlib.net/ +Source: https://zlib.net/ Comment: This is the pre-packaged Debian Linux version of the zlib compression library. It was packaged by Michael Alan Dorman from sources originally retrieved from ftp.uu.net in the directory @@ -12,9 +12,6 @@ people who reported problems and suggested various improvements in zlib; they are too numerous to cite here. Files-Excluded: - contrib/ada - contrib/amd64 - contrib/asm686 contrib/blast contrib/delphi contrib/dotzlib @@ -24,8 +21,7 @@ contrib/iostream contrib/iostream2 contrib/iostream3 - contrib/masmx64 - contrib/masmx86 + contrib/nuget contrib/pascal contrib/puff contrib/testzlib diff -Nru zlib-1.2.13.dfsg/debian/libminizip-dev.install zlib-1.3.1.dfsg/debian/libminizip-dev.install --- zlib-1.2.13.dfsg/debian/libminizip-dev.install 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/libminizip-dev.install 2023-11-24 08:22:52.000000000 +0000 @@ -0,0 +1,4 @@ +usr/include/minizip +usr/lib/*/libminizip.a +usr/lib/*/libminizip.so +usr/lib/*/pkgconfig/minizip.pc diff -Nru zlib-1.2.13.dfsg/debian/libminizip1.install zlib-1.3.1.dfsg/debian/libminizip1.install --- zlib-1.2.13.dfsg/debian/libminizip1.install 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/libminizip1.install 2023-11-24 08:22:52.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/*/libminizip.so.* diff -Nru zlib-1.2.13.dfsg/debian/libminizip1.symbols zlib-1.3.1.dfsg/debian/libminizip1.symbols --- zlib-1.2.13.dfsg/debian/libminizip1.symbols 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/libminizip1.symbols 2023-11-24 08:22:52.000000000 +0000 @@ -0,0 +1,62 @@ +libminizip.so.1 libminizip1 + call_zopen64@Base 1.1 + call_zseek64@Base 1.1 + call_ztell64@Base 1.1 + fill_fopen64_filefunc@Base 1.1 + fill_fopen_filefunc@Base 1.1 + fill_zlib_filefunc64_32_def_from_filefunc32@Base 1.1 + unzClose@Base 1.1 + unzCloseCurrentFile@Base 1.1 + unzGetCurrentFileInfo64@Base 1.1 + unzGetCurrentFileInfo@Base 1.1 + unzGetCurrentFileZStreamPos64@Base 1.1 + unzGetFilePos64@Base 1.1 + unzGetFilePos@Base 1.1 + unzGetGlobalComment@Base 1.1 + unzGetGlobalInfo64@Base 1.1 + unzGetGlobalInfo@Base 1.1 + unzGetLocalExtrafield@Base 1.1 + unzGetOffset64@Base 1.1 + unzGetOffset@Base 1.1 + unzGoToFilePos64@Base 1.1 + unzGoToFilePos@Base 1.1 + unzGoToFirstFile@Base 1.1 + unzGoToNextFile@Base 1.1 + unzLocateFile@Base 1.1 + unzOpen2@Base 1.1 + unzOpen2_64@Base 1.1 + unzOpen64@Base 1.1 + unzOpen@Base 1.1 + unzOpenCurrentFile2@Base 1.1 + unzOpenCurrentFile3@Base 1.1 + unzOpenCurrentFile@Base 1.1 + unzOpenCurrentFilePassword@Base 1.1 + unzReadCurrentFile@Base 1.1 + unzRepair@Base 1.1 + unzSetOffset64@Base 1.1 + unzSetOffset@Base 1.1 + unzStringFileNameCompare@Base 1.1 + unz_copyright@Base 1.1 + unzeof@Base 1.1 + unztell64@Base 1.1 + unztell@Base 1.1 + zipClose@Base 1.1 + zipCloseFileInZip@Base 1.1 + zipCloseFileInZipRaw64@Base 1.1 + zipCloseFileInZipRaw@Base 1.1 + zipOpen2@Base 1.1 + zipOpen2_64@Base 1.1 + zipOpen3@Base 1.1 + zipOpen64@Base 1.1 + zipOpen@Base 1.1 + zipOpenNewFileInZip2@Base 1.1 + zipOpenNewFileInZip2_64@Base 1.1 + zipOpenNewFileInZip3@Base 1.1 + zipOpenNewFileInZip3_64@Base 1.1 + zipOpenNewFileInZip4@Base 1.1 + zipOpenNewFileInZip4_64@Base 1.1 + zipOpenNewFileInZip64@Base 1.1 + zipOpenNewFileInZip@Base 1.1 + zipRemoveExtraInfoBlock@Base 1.1 + zipWriteInFileInZip@Base 1.1 + zip_copyright@Base 1.1 diff -Nru zlib-1.2.13.dfsg/debian/minizip.install zlib-1.3.1.dfsg/debian/minizip.install --- zlib-1.2.13.dfsg/debian/minizip.install 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/minizip.install 2023-11-24 08:22:52.000000000 +0000 @@ -0,0 +1,2 @@ +usr/bin/minizip +usr/bin/miniunzip diff -Nru zlib-1.2.13.dfsg/debian/minizip.manpages zlib-1.3.1.dfsg/debian/minizip.manpages --- zlib-1.2.13.dfsg/debian/minizip.manpages 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/minizip.manpages 2023-11-24 08:22:52.000000000 +0000 @@ -0,0 +1,2 @@ +contrib/minizip/minizip.1 +contrib/minizip/miniunzip.1 diff -Nru zlib-1.2.13.dfsg/debian/patches/1390.patch zlib-1.3.1.dfsg/debian/patches/1390.patch --- zlib-1.2.13.dfsg/debian/patches/1390.patch 2023-01-11 17:02:34.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/1390.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -Description: IBM zSystems DFLTCC: Do not update strm.adler for raw streams #1390 - Commit d38dd92 ("IBM Z DFLTCC: Fix updating strm.adler with inflate()") broke libxml2, as can be seen with the repro from [1]: - $ echo "" | gzip >file.xml.gz - $ python3 -c 'import libxml2; libxml2.parseFile("file.xml.gz")' - file.xml.gz:1: parser error : Document is empty - This is because libxml2 expects strm.adler to be untouched for raw streams. - Fix this and a similar issue in deflate by adding state->wrap checks. Add tests. - [1] https://bugzilla.redhat.com/show_bug.cgi?id=2155328 - [2] https://gitlab.gnome.org/GNOME/libxml2/-/blob/v2.10.3/xzlib.c#L607 -Author: Ilya Leoshkevich -Origin: upstream, https://github.com/zlib-ng/zlib-ng/pull/1390/commits/cc06335176d4cd1dfceaf8b6bcb757ad73da73be - backport, https://launchpadlibrarian.net/645435847/1390.patch -Bug-Ubuntu: https://bugs.launchpad.net/bugs/2002511 -Bug-RedHat: https://bugzilla.redhat.com/show_bug.cgi?id=2155328 -Reviewed-by: Frank Heimes -Last-Update: 2023-01-11 ---- -This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ ---- a/contrib/s390/dfltcc.c -+++ b/contrib/s390/dfltcc.c -@@ -457,7 +457,10 @@ - *strm->next_out = (Bytef)state->bi_buf; - /* Honor history and check value */ - param->nt = 0; -- param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler; -+ if (state->wrap == 1) -+ param->cv = strm->adler; -+ else if (state->wrap == 2) -+ param->cv = ZSWAP32(strm->adler); - - /* When opening a block, choose a Huffman-Table Type */ - if (!param->bcf) { -@@ -489,7 +492,10 @@ - state->bi_buf = 0; /* Avoid accessing next_out */ - else - state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1); -- strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv; -+ if (state->wrap == 1) -+ strm->adler = param->cv; -+ else if (state->wrap == 2) -+ strm->adler = ZSWAP32(param->cv); - - /* Unmask the input data */ - strm->avail_in += masked_avail_in; -@@ -605,13 +611,14 @@ - } - - /* Translate stream to parameter block */ -- param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32; -+ param->cvt = ((state->wrap & 4) && state->flags) ? CVT_CRC32 : CVT_ADLER32; - param->sbb = state->bits; - param->hl = state->whave; /* Software and hardware history formats match */ - param->ho = (state->wnext - state->whave) & ((1 << HB_BITS) - 1); - if (param->hl) - param->nt = 0; /* Honor history for the first block */ -- param->cv = state->flags ? ZSWAP32(state->check) : state->check; -+ if (state->wrap & 4) -+ param->cv = state->flags ? ZSWAP32(state->check) : state->check; - - /* Inflate */ - do { -@@ -624,7 +631,9 @@ - state->bits = param->sbb; - state->whave = param->hl; - state->wnext = (param->ho + param->hl) & ((1 << HB_BITS) - 1); -- strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv; -+ if (state->wrap & 4) -+ strm->adler = state->check = state->flags ? -+ ZSWAP32(param->cv) : param->cv; - if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) { - /* Report an error if stream is corrupted */ - state->mode = BAD; diff -Nru zlib-1.2.13.dfsg/debian/patches/410.patch zlib-1.3.1.dfsg/debian/patches/410.patch --- zlib-1.2.13.dfsg/debian/patches/410.patch 2022-11-21 19:28:58.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/410.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,1955 +0,0 @@ -From 26f2c0a4e17e5558d779797d713aa37ebaeef390 Mon Sep 17 00:00:00 2001 -From: Ilya Leoshkevich -Date: Wed, 18 Jul 2018 13:14:07 +0200 -Subject: [PATCH] Add support for IBM Z hardware-accelerated deflate - -IBM Z mainframes starting from version z15 provide DFLTCC instruction, -which implements deflate algorithm in hardware with estimated -compression and decompression performance orders of magnitude faster -than the current zlib and ratio comparable with that of level 1. - -This patch adds DFLTCC support to zlib. In order to enable it, the -following build commands should be used: - - $ ./configure --dfltcc - $ make - -When built like this, zlib would compress in hardware on level 1, and in -software on all other levels. Decompression will always happen in -hardware. In order to enable DFLTCC compression for levels 1-6 (i.e. to -make it used by default) one could either configure with ---dfltcc-level-mask=0x7e or set the environment variable -DFLTCC_LEVEL_MASK to 0x7e at run time. - -Two DFLTCC compression calls produce the same results only when they -both are made on machines of the same generation, and when the -respective buffers have the same offset relative to the start of the -page. Therefore care should be taken when using hardware compression -when reproducible results are desired. One such use case - reproducible -software builds - is handled explicitly: when SOURCE_DATE_EPOCH -environment variable is set, the hardware compression is disabled. - -DFLTCC does not support every single zlib feature, in particular: - - * inflate(Z_BLOCK) and inflate(Z_TREES) - * inflateMark() - * inflatePrime() - * inflateSyncPoint() - -When used, these functions will either switch to software, or, in case -this is not possible, gracefully fail. - -This patch tries to add DFLTCC support in the least intrusive way. -All SystemZ-specific code is placed into a separate file, but -unfortunately there is still a noticeable amount of changes in the -main zlib code. Below is the summary of these changes. - -DFLTCC takes as arguments a parameter block, an input buffer, an output -buffer and a window. Since DFLTCC requires parameter block to be -doubleword-aligned, and it's reasonable to allocate it alongside -deflate and inflate states, ZALLOC_STATE, ZFREE_STATE and ZCOPY_STATE -macros were introduced in order to encapsulate the allocation details. -The same is true for window, for which ZALLOC_WINDOW and -TRY_FREE_WINDOW macros were introduced. - -While for inflate software and hardware window formats match, this is -not the case for deflate. Therefore, deflateSetDictionary and -deflateGetDictionary need special handling, which is triggered using the -new DEFLATE_SET_DICTIONARY_HOOK and DEFLATE_GET_DICTIONARY_HOOK macros. - -deflateResetKeep() and inflateResetKeep() now update the DFLTCC -parameter block, which is allocated alongside zlib state, using -the new DEFLATE_RESET_KEEP_HOOK and INFLATE_RESET_KEEP_HOOK macros. - -The new DEFLATE_PARAMS_HOOK switches between hardware and software -deflate implementations when deflateParams() arguments demand this. - -The new INFLATE_PRIME_HOOK, INFLATE_MARK_HOOK and -INFLATE_SYNC_POINT_HOOK macros make the respective unsupported calls -gracefully fail. - -The algorithm implemented in hardware has different compression ratio -than the one implemented in software. In order for deflateBound() to -return the correct results for the hardware implementation, the new -DEFLATE_BOUND_ADJUST_COMPLEN and DEFLATE_NEED_CONSERVATIVE_BOUND macros -were introduced. - -Actual compression and decompression are handled by the new DEFLATE_HOOK -and INFLATE_TYPEDO_HOOK macros. Since inflation with DFLTCC manages the -window on its own, calling updatewindow() is suppressed using the new -INFLATE_NEED_UPDATEWINDOW() macro. - -In addition to compression, DFLTCC computes CRC-32 and Adler-32 -checksums, therefore, whenever it's used, software checksumming needs to -be suppressed using the new DEFLATE_NEED_CHECKSUM and -INFLATE_NEED_CHECKSUM macros. - -DFLTCC will refuse to write an End-of-block Symbol if there is no input -data, thus in some cases it is necessary to do this manually. In order -to achieve this, send_bits, bi_reverse, bi_windup and flush_pending -were promoted from local to ZLIB_INTERNAL. Furthermore, since block and -stream termination must be handled in software as well, block_state enum -was moved to deflate.h. - -Since the first call to dfltcc_inflate already needs the window, and it -might be not allocated yet, inflate_ensure_window was factored out of -updatewindow and made ZLIB_INTERNAL. - -Author: Ilya Leoshkevich -Origin: upstream, https://github.com/iii-i/zlib/commit/26f2c0a4e17e5558d779797d713aa37ebaeef390 -Forwarded: not-needed -Reviewed-by: Frank Heimes -Last-Update: 2022-11-30 ---- -This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ ---- a/compress.c -+++ b/compress.c -@@ -5,9 +5,15 @@ - - /* @(#) $Id$ */ - --#define ZLIB_INTERNAL -+#include "zutil.h" - #include "zlib.h" - -+#ifdef DFLTCC -+# include "contrib/s390/dfltcc.h" -+#else -+#define DEFLATE_BOUND_COMPLEN(source_len) 0 -+#endif -+ - /* =========================================================================== - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte -@@ -81,6 +87,12 @@ - uLong ZEXPORT compressBound(sourceLen) - uLong sourceLen; - { -+ uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen); -+ -+ if (complen > 0) -+ /* Architecture-specific code provided an upper bound. */ -+ return complen + ZLIB_WRAPLEN; -+ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13; - } ---- a/configure -+++ b/configure -@@ -118,6 +118,7 @@ - echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log - echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log - echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log -+ echo ' [--dfltcc] [--dfltcc-level-mask=MASK]' | tee -a configure.log - exit 0 ;; - -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;; - -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;; -@@ -142,6 +143,16 @@ - -w* | --warn) warn=1; shift ;; - -d* | --debug) debug=1; shift ;; - --sanitize) sanitize=1; shift ;; -+ --dfltcc) -+ CFLAGS="$CFLAGS -DDFLTCC" -+ OBJC="$OBJC dfltcc.o" -+ PIC_OBJC="$PIC_OBJC dfltcc.lo" -+ shift -+ ;; -+ --dfltcc-level-mask=*) -+ CFLAGS="$CFLAGS -DDFLTCC_LEVEL_MASK=`echo $1 | sed 's/.*=//'`" -+ shift -+ ;; - *) - echo "unknown option: $1" | tee -a configure.log - echo "$0 --help for help" | tee -a configure.log -@@ -828,6 +839,19 @@ - fi - fi - -+# Check whether sys/sdt.h is available -+cat > $test.c << EOF -+#include -+int main() { return 0; } -+EOF -+if try $CC -c $CFLAGS $test.c; then -+ echo "Checking for sys/sdt.h ... Yes." | tee -a configure.log -+ CFLAGS="$CFLAGS -DHAVE_SYS_SDT_H" -+ SFLAGS="$SFLAGS -DHAVE_SYS_SDT_H" -+else -+ echo "Checking for sys/sdt.h ... No." | tee -a configure.log -+fi -+ - # show the results in the log - echo >> configure.log - echo ALL = $ALL >> configure.log ---- a/contrib/README.contrib -+++ b/contrib/README.contrib -@@ -46,6 +46,10 @@ - Small, low memory usage inflate. Also serves to provide an - unambiguous description of the deflate format. - -+s390/ by Ilya Leoshkevich -+ Hardware-accelerated deflate on IBM Z with DEFLATE CONVERSION CALL -+ instruction. -+ - testzlib/ by Gilles Vollant - Example of the use of zlib - ---- /dev/null -+++ b/contrib/s390/dfltcc.c -@@ -0,0 +1,995 @@ -+/* dfltcc.c - SystemZ DEFLATE CONVERSION CALL support. */ -+ -+/* -+ Use the following commands to build zlib with DFLTCC support: -+ -+ $ ./configure --dfltcc -+ $ make -+*/ -+ -+#define _GNU_SOURCE -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "../../zutil.h" -+#include "../../deflate.h" -+#include "../../inftrees.h" -+#include "../../inflate.h" -+#include "dfltcc.h" -+#include "dfltcc_deflate.h" -+#ifdef HAVE_SYS_SDT_H -+#include -+#endif -+ -+/* -+ C wrapper for the DEFLATE CONVERSION CALL instruction. -+ */ -+typedef enum { -+ DFLTCC_CC_OK = 0, -+ DFLTCC_CC_OP1_TOO_SHORT = 1, -+ DFLTCC_CC_OP2_TOO_SHORT = 2, -+ DFLTCC_CC_OP2_CORRUPT = 2, -+ DFLTCC_CC_AGAIN = 3, -+} dfltcc_cc; -+ -+#define DFLTCC_QAF 0 -+#define DFLTCC_GDHT 1 -+#define DFLTCC_CMPR 2 -+#define DFLTCC_XPND 4 -+#define HBT_CIRCULAR (1 << 7) -+#define HB_BITS 15 -+#define HB_SIZE (1 << HB_BITS) -+#define DFLTCC_FACILITY 151 -+ -+local inline dfltcc_cc dfltcc OF((int fn, void *param, -+ Bytef **op1, size_t *len1, -+ z_const Bytef **op2, size_t *len2, -+ void *hist)); -+local inline dfltcc_cc dfltcc(fn, param, op1, len1, op2, len2, hist) -+ int fn; -+ void *param; -+ Bytef **op1; -+ size_t *len1; -+ z_const Bytef **op2; -+ size_t *len2; -+ void *hist; -+{ -+ Bytef *t2 = op1 ? *op1 : NULL; -+ size_t t3 = len1 ? *len1 : 0; -+ z_const Bytef *t4 = op2 ? *op2 : NULL; -+ size_t t5 = len2 ? *len2 : 0; -+ register int r0 __asm__("r0") = fn; -+ register void *r1 __asm__("r1") = param; -+ register Bytef *r2 __asm__("r2") = t2; -+ register size_t r3 __asm__("r3") = t3; -+ register z_const Bytef *r4 __asm__("r4") = t4; -+ register size_t r5 __asm__("r5") = t5; -+ int cc; -+ -+ __asm__ volatile( -+#ifdef HAVE_SYS_SDT_H -+ STAP_PROBE_ASM(zlib, dfltcc_entry, -+ STAP_PROBE_ASM_TEMPLATE(5)) -+#endif -+ ".insn rrf,0xb9390000,%[r2],%[r4],%[hist],0\n" -+#ifdef HAVE_SYS_SDT_H -+ STAP_PROBE_ASM(zlib, dfltcc_exit, -+ STAP_PROBE_ASM_TEMPLATE(5)) -+#endif -+ "ipm %[cc]\n" -+ : [r2] "+r" (r2) -+ , [r3] "+r" (r3) -+ , [r4] "+r" (r4) -+ , [r5] "+r" (r5) -+ , [cc] "=r" (cc) -+ : [r0] "r" (r0) -+ , [r1] "r" (r1) -+ , [hist] "r" (hist) -+#ifdef HAVE_SYS_SDT_H -+ , STAP_PROBE_ASM_OPERANDS(5, r2, r3, r4, r5, hist) -+#endif -+ : "cc", "memory"); -+ t2 = r2; t3 = r3; t4 = r4; t5 = r5; -+ -+ if (op1) -+ *op1 = t2; -+ if (len1) -+ *len1 = t3; -+ if (op2) -+ *op2 = t4; -+ if (len2) -+ *len2 = t5; -+ return (cc >> 28) & 3; -+} -+ -+/* -+ Parameter Block for Query Available Functions. -+ */ -+#define static_assert(c, msg) \ -+ __attribute__((unused)) \ -+ static char static_assert_failed_ ## msg[c ? 1 : -1] -+ -+struct dfltcc_qaf_param { -+ char fns[16]; -+ char reserved1[8]; -+ char fmts[2]; -+ char reserved2[6]; -+}; -+ -+static_assert(sizeof(struct dfltcc_qaf_param) == 32, -+ sizeof_struct_dfltcc_qaf_param_is_32); -+ -+local inline int is_bit_set OF((const char *bits, int n)); -+local inline int is_bit_set(bits, n) -+ const char *bits; -+ int n; -+{ -+ return bits[n / 8] & (1 << (7 - (n % 8))); -+} -+ -+local inline void clear_bit OF((char *bits, int n)); -+local inline void clear_bit(bits, n) -+ char *bits; -+ int n; -+{ -+ bits[n / 8] &= ~(1 << (7 - (n % 8))); -+} -+ -+#define DFLTCC_FMT0 0 -+ -+/* -+ Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand. -+ */ -+#define CVT_CRC32 0 -+#define CVT_ADLER32 1 -+#define HTT_FIXED 0 -+#define HTT_DYNAMIC 1 -+ -+struct dfltcc_param_v0 { -+ uint16_t pbvn; /* Parameter-Block-Version Number */ -+ uint8_t mvn; /* Model-Version Number */ -+ uint8_t ribm; /* Reserved for IBM use */ -+ unsigned reserved32 : 31; -+ unsigned cf : 1; /* Continuation Flag */ -+ uint8_t reserved64[8]; -+ unsigned nt : 1; /* New Task */ -+ unsigned reserved129 : 1; -+ unsigned cvt : 1; /* Check Value Type */ -+ unsigned reserved131 : 1; -+ unsigned htt : 1; /* Huffman-Table Type */ -+ unsigned bcf : 1; /* Block-Continuation Flag */ -+ unsigned bcc : 1; /* Block Closing Control */ -+ unsigned bhf : 1; /* Block Header Final */ -+ unsigned reserved136 : 1; -+ unsigned reserved137 : 1; -+ unsigned dhtgc : 1; /* DHT Generation Control */ -+ unsigned reserved139 : 5; -+ unsigned reserved144 : 5; -+ unsigned sbb : 3; /* Sub-Byte Boundary */ -+ uint8_t oesc; /* Operation-Ending-Supplemental Code */ -+ unsigned reserved160 : 12; -+ unsigned ifs : 4; /* Incomplete-Function Status */ -+ uint16_t ifl; /* Incomplete-Function Length */ -+ uint8_t reserved192[8]; -+ uint8_t reserved256[8]; -+ uint8_t reserved320[4]; -+ uint16_t hl; /* History Length */ -+ unsigned reserved368 : 1; -+ uint16_t ho : 15; /* History Offset */ -+ uint32_t cv; /* Check Value */ -+ unsigned eobs : 15; /* End-of-block Symbol */ -+ unsigned reserved431: 1; -+ uint8_t eobl : 4; /* End-of-block Length */ -+ unsigned reserved436 : 12; -+ unsigned reserved448 : 4; -+ uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table -+ Length */ -+ uint8_t reserved464[6]; -+ uint8_t cdht[288]; -+ uint8_t reserved[32]; -+ uint8_t csb[1152]; -+}; -+ -+static_assert(sizeof(struct dfltcc_param_v0) == 1536, -+ sizeof_struct_dfltcc_param_v0_is_1536); -+ -+local z_const char *oesc_msg OF((char *buf, int oesc)); -+local z_const char *oesc_msg(buf, oesc) -+ char *buf; -+ int oesc; -+{ -+ if (oesc == 0x00) -+ return NULL; /* Successful completion */ -+ else { -+ sprintf(buf, "Operation-Ending-Supplemental Code is 0x%.2X", oesc); -+ return buf; -+ } -+} -+ -+/* -+ Extension of inflate_state and deflate_state. Must be doubleword-aligned. -+*/ -+struct dfltcc_state { -+ struct dfltcc_param_v0 param; /* Parameter block. */ -+ struct dfltcc_qaf_param af; /* Available functions. */ -+ uLong level_mask; /* Levels on which to use DFLTCC */ -+ uLong block_size; /* New block each X bytes */ -+ uLong block_threshold; /* New block after total_in > X */ -+ uLong dht_threshold; /* New block only if avail_in >= X */ -+ char msg[64]; /* Buffer for strm->msg */ -+}; -+ -+#define ALIGN_UP(p, size) \ -+ (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1)) -+ -+#define GET_DFLTCC_STATE(state) ((struct dfltcc_state FAR *)( \ -+ (char FAR *)(state) + ALIGN_UP(sizeof(*state), 8))) -+ -+/* -+ Compress. -+ */ -+local inline int dfltcc_can_deflate_with_params(z_streamp strm, -+ int level, -+ uInt window_bits, -+ int strategy); -+local inline int dfltcc_can_deflate_with_params(strm, -+ level, -+ window_bits, -+ strategy) -+ z_streamp strm; -+ int level; -+ uInt window_bits; -+ int strategy; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ -+ /* Unsupported compression settings */ -+ if ((dfltcc_state->level_mask & (1 << level)) == 0) -+ return 0; -+ if (window_bits != HB_BITS) -+ return 0; -+ if (strategy != Z_FIXED && strategy != Z_DEFAULT_STRATEGY) -+ return 0; -+ -+ /* Unsupported hardware */ -+ if (!is_bit_set(dfltcc_state->af.fns, DFLTCC_GDHT) || -+ !is_bit_set(dfltcc_state->af.fns, DFLTCC_CMPR) || -+ !is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0)) -+ return 0; -+ -+ return 1; -+} -+ -+int ZLIB_INTERNAL dfltcc_can_deflate(strm) -+ z_streamp strm; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ -+ return dfltcc_can_deflate_with_params(strm, -+ state->level, -+ state->w_bits, -+ state->strategy); -+} -+ -+local void dfltcc_gdht OF((z_streamp strm)); -+local void dfltcc_gdht(strm) -+ z_streamp strm; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_param_v0 FAR *param = &GET_DFLTCC_STATE(state)->param; -+ size_t avail_in = avail_in = strm->avail_in; -+ -+ dfltcc(DFLTCC_GDHT, -+ param, NULL, NULL, -+ &strm->next_in, &avail_in, NULL); -+} -+ -+local dfltcc_cc dfltcc_cmpr OF((z_streamp strm)); -+local dfltcc_cc dfltcc_cmpr(strm) -+ z_streamp strm; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_param_v0 FAR *param = &GET_DFLTCC_STATE(state)->param; -+ size_t avail_in = strm->avail_in; -+ size_t avail_out = strm->avail_out; -+ dfltcc_cc cc; -+ -+ cc = dfltcc(DFLTCC_CMPR | HBT_CIRCULAR, -+ param, &strm->next_out, &avail_out, -+ &strm->next_in, &avail_in, state->window); -+ strm->total_in += (strm->avail_in - avail_in); -+ strm->total_out += (strm->avail_out - avail_out); -+ strm->avail_in = avail_in; -+ strm->avail_out = avail_out; -+ return cc; -+} -+ -+local void send_eobs OF((z_streamp strm, -+ z_const struct dfltcc_param_v0 FAR *param)); -+local void send_eobs(strm, param) -+ z_streamp strm; -+ z_const struct dfltcc_param_v0 FAR *param; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ -+ _tr_send_bits( -+ state, -+ bi_reverse(param->eobs >> (15 - param->eobl), param->eobl), -+ param->eobl); -+ flush_pending(strm); -+ if (state->pending != 0) { -+ /* The remaining data is located in pending_out[0:pending]. If someone -+ * calls put_byte() - this might happen in deflate() - the byte will be -+ * placed into pending_buf[pending], which is incorrect. Move the -+ * remaining data to the beginning of pending_buf so that put_byte() is -+ * usable again. -+ */ -+ memmove(state->pending_buf, state->pending_out, state->pending); -+ state->pending_out = state->pending_buf; -+ } -+#ifdef ZLIB_DEBUG -+ state->compressed_len += param->eobl; -+#endif -+} -+ -+int ZLIB_INTERNAL dfltcc_deflate(strm, flush, result) -+ z_streamp strm; -+ int flush; -+ block_state *result; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; -+ uInt masked_avail_in; -+ dfltcc_cc cc; -+ int need_empty_block; -+ int soft_bcc; -+ int no_flush; -+ -+ if (!dfltcc_can_deflate(strm)) { -+ /* Clear history. */ -+ if (flush == Z_FULL_FLUSH) -+ param->hl = 0; -+ return 0; -+ } -+ -+again: -+ masked_avail_in = 0; -+ soft_bcc = 0; -+ no_flush = flush == Z_NO_FLUSH; -+ -+ /* No input data. Return, except when Continuation Flag is set, which means -+ * that DFLTCC has buffered some output in the parameter block and needs to -+ * be called again in order to flush it. -+ */ -+ if (strm->avail_in == 0 && !param->cf) { -+ /* A block is still open, and the hardware does not support closing -+ * blocks without adding data. Thus, close it manually. -+ */ -+ if (!no_flush && param->bcf) { -+ send_eobs(strm, param); -+ param->bcf = 0; -+ } -+ /* Let one of deflate_* functions write a trailing empty block. */ -+ if (flush == Z_FINISH) -+ return 0; -+ /* Clear history. */ -+ if (flush == Z_FULL_FLUSH) -+ param->hl = 0; -+ /* Trigger block post-processing if necessary. */ -+ *result = no_flush ? need_more : block_done; -+ return 1; -+ } -+ -+ /* There is an open non-BFINAL block, we are not going to close it just -+ * yet, we have compressed more than DFLTCC_BLOCK_SIZE bytes and we see -+ * more than DFLTCC_DHT_MIN_SAMPLE_SIZE bytes. Open a new block with a new -+ * DHT in order to adapt to a possibly changed input data distribution. -+ */ -+ if (param->bcf && no_flush && -+ strm->total_in > dfltcc_state->block_threshold && -+ strm->avail_in >= dfltcc_state->dht_threshold) { -+ if (param->cf) { -+ /* We need to flush the DFLTCC buffer before writing the -+ * End-of-block Symbol. Mask the input data and proceed as usual. -+ */ -+ masked_avail_in += strm->avail_in; -+ strm->avail_in = 0; -+ no_flush = 0; -+ } else { -+ /* DFLTCC buffer is empty, so we can manually write the -+ * End-of-block Symbol right away. -+ */ -+ send_eobs(strm, param); -+ param->bcf = 0; -+ dfltcc_state->block_threshold = -+ strm->total_in + dfltcc_state->block_size; -+ } -+ } -+ -+ /* No space for compressed data. If we proceed, dfltcc_cmpr() will return -+ * DFLTCC_CC_OP1_TOO_SHORT without buffering header bits, but we will still -+ * set BCF=1, which is wrong. Avoid complications and return early. -+ */ -+ if (strm->avail_out == 0) { -+ *result = need_more; -+ return 1; -+ } -+ -+ /* The caller gave us too much data. Pass only one block worth of -+ * uncompressed data to DFLTCC and mask the rest, so that on the next -+ * iteration we start a new block. -+ */ -+ if (no_flush && strm->avail_in > dfltcc_state->block_size) { -+ masked_avail_in += (strm->avail_in - dfltcc_state->block_size); -+ strm->avail_in = dfltcc_state->block_size; -+ } -+ -+ /* When we have an open non-BFINAL deflate block and caller indicates that -+ * the stream is ending, we need to close an open deflate block and open a -+ * BFINAL one. -+ */ -+ need_empty_block = flush == Z_FINISH && param->bcf && !param->bhf; -+ -+ /* Translate stream to parameter block */ -+ param->cvt = state->wrap == 2 ? CVT_CRC32 : CVT_ADLER32; -+ if (!no_flush) -+ /* We need to close a block. Always do this in software - when there is -+ * no input data, the hardware will not honor BCC. */ -+ soft_bcc = 1; -+ if (flush == Z_FINISH && !param->bcf) -+ /* We are about to open a BFINAL block, set Block Header Final bit -+ * until the stream ends. -+ */ -+ param->bhf = 1; -+ /* DFLTCC-CMPR will write to next_out, so make sure that buffers with -+ * higher precedence are empty. -+ */ -+ Assert(state->pending == 0, "There must be no pending bytes"); -+ Assert(state->bi_valid < 8, "There must be less than 8 pending bits"); -+ param->sbb = (unsigned int)state->bi_valid; -+ if (param->sbb > 0) -+ *strm->next_out = (Bytef)state->bi_buf; -+ /* Honor history and check value */ -+ param->nt = 0; -+ param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler; -+ -+ /* When opening a block, choose a Huffman-Table Type */ -+ if (!param->bcf) { -+ if (state->strategy == Z_FIXED || -+ (strm->total_in == 0 && dfltcc_state->block_threshold > 0)) -+ param->htt = HTT_FIXED; -+ else { -+ param->htt = HTT_DYNAMIC; -+ dfltcc_gdht(strm); -+ } -+ } -+ -+ /* Deflate */ -+ do { -+ cc = dfltcc_cmpr(strm); -+ if (strm->avail_in < 4096 && masked_avail_in > 0) -+ /* We are about to call DFLTCC with a small input buffer, which is -+ * inefficient. Since there is masked data, there will be at least -+ * one more DFLTCC call, so skip the current one and make the next -+ * one handle more data. -+ */ -+ break; -+ } while (cc == DFLTCC_CC_AGAIN); -+ -+ /* Translate parameter block to stream */ -+ strm->msg = oesc_msg(dfltcc_state->msg, param->oesc); -+ state->bi_valid = param->sbb; -+ if (state->bi_valid == 0) -+ state->bi_buf = 0; /* Avoid accessing next_out */ -+ else -+ state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1); -+ strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv; -+ -+ /* Unmask the input data */ -+ strm->avail_in += masked_avail_in; -+ masked_avail_in = 0; -+ -+ /* If we encounter an error, it means there is a bug in DFLTCC call */ -+ Assert(cc != DFLTCC_CC_OP2_CORRUPT || param->oesc == 0, "BUG"); -+ -+ /* Update Block-Continuation Flag. It will be used to check whether to call -+ * GDHT the next time. -+ */ -+ if (cc == DFLTCC_CC_OK) { -+ if (soft_bcc) { -+ send_eobs(strm, param); -+ param->bcf = 0; -+ dfltcc_state->block_threshold = -+ strm->total_in + dfltcc_state->block_size; -+ } else -+ param->bcf = 1; -+ if (flush == Z_FINISH) { -+ if (need_empty_block) -+ /* Make the current deflate() call also close the stream */ -+ return 0; -+ else { -+ bi_windup(state); -+ *result = finish_done; -+ } -+ } else { -+ if (flush == Z_FULL_FLUSH) -+ param->hl = 0; /* Clear history */ -+ *result = flush == Z_NO_FLUSH ? need_more : block_done; -+ } -+ } else { -+ param->bcf = 1; -+ *result = need_more; -+ } -+ if (strm->avail_in != 0 && strm->avail_out != 0) -+ goto again; /* deflate() must use all input or all output */ -+ return 1; -+} -+ -+/* -+ Expand. -+ */ -+int ZLIB_INTERNAL dfltcc_can_inflate(strm) -+ z_streamp strm; -+{ -+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ -+ /* Unsupported compression settings */ -+ if (state->wbits != HB_BITS) -+ return 0; -+ -+ /* Unsupported hardware */ -+ return is_bit_set(dfltcc_state->af.fns, DFLTCC_XPND) && -+ is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0); -+} -+ -+local dfltcc_cc dfltcc_xpnd OF((z_streamp strm)); -+local dfltcc_cc dfltcc_xpnd(strm) -+ z_streamp strm; -+{ -+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state; -+ struct dfltcc_param_v0 FAR *param = &GET_DFLTCC_STATE(state)->param; -+ size_t avail_in = strm->avail_in; -+ size_t avail_out = strm->avail_out; -+ dfltcc_cc cc; -+ -+ cc = dfltcc(DFLTCC_XPND | HBT_CIRCULAR, -+ param, &strm->next_out, &avail_out, -+ &strm->next_in, &avail_in, state->window); -+ strm->avail_in = avail_in; -+ strm->avail_out = avail_out; -+ return cc; -+} -+ -+dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret) -+ z_streamp strm; -+ int flush; -+ int *ret; -+{ -+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; -+ dfltcc_cc cc; -+ -+ if (flush == Z_BLOCK || flush == Z_TREES) { -+ /* DFLTCC does not support stopping on block boundaries */ -+ if (dfltcc_inflate_disable(strm)) { -+ *ret = Z_STREAM_ERROR; -+ return DFLTCC_INFLATE_BREAK; -+ } else -+ return DFLTCC_INFLATE_SOFTWARE; -+ } -+ -+ if (state->last) { -+ if (state->bits != 0) { -+ strm->next_in++; -+ strm->avail_in--; -+ state->bits = 0; -+ } -+ state->mode = CHECK; -+ return DFLTCC_INFLATE_CONTINUE; -+ } -+ -+ if (strm->avail_in == 0 && !param->cf) -+ return DFLTCC_INFLATE_BREAK; -+ -+ if (inflate_ensure_window(state)) { -+ state->mode = MEM; -+ return DFLTCC_INFLATE_CONTINUE; -+ } -+ -+ /* Translate stream to parameter block */ -+ param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32; -+ param->sbb = state->bits; -+ param->hl = state->whave; /* Software and hardware history formats match */ -+ param->ho = (state->wnext - state->whave) & ((1 << HB_BITS) - 1); -+ if (param->hl) -+ param->nt = 0; /* Honor history for the first block */ -+ param->cv = state->flags ? ZSWAP32(state->check) : state->check; -+ -+ /* Inflate */ -+ do { -+ cc = dfltcc_xpnd(strm); -+ } while (cc == DFLTCC_CC_AGAIN); -+ -+ /* Translate parameter block to stream */ -+ strm->msg = oesc_msg(dfltcc_state->msg, param->oesc); -+ state->last = cc == DFLTCC_CC_OK; -+ state->bits = param->sbb; -+ state->whave = param->hl; -+ state->wnext = (param->ho + param->hl) & ((1 << HB_BITS) - 1); -+ strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv; -+ if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) { -+ /* Report an error if stream is corrupted */ -+ state->mode = BAD; -+ return DFLTCC_INFLATE_CONTINUE; -+ } -+ state->mode = TYPEDO; -+ /* Break if operands are exhausted, otherwise continue looping */ -+ return (cc == DFLTCC_CC_OP1_TOO_SHORT || cc == DFLTCC_CC_OP2_TOO_SHORT) ? -+ DFLTCC_INFLATE_BREAK : DFLTCC_INFLATE_CONTINUE; -+} -+ -+int ZLIB_INTERNAL dfltcc_was_inflate_used(strm) -+ z_streamp strm; -+{ -+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state; -+ struct dfltcc_param_v0 FAR *param = &GET_DFLTCC_STATE(state)->param; -+ -+ return !param->nt; -+} -+ -+int ZLIB_INTERNAL dfltcc_inflate_disable(strm) -+ z_streamp strm; -+{ -+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ -+ if (!dfltcc_can_inflate(strm)) -+ return 0; -+ if (dfltcc_was_inflate_used(strm)) -+ /* DFLTCC has already decompressed some data. Since there is not -+ * enough information to resume decompression in software, the call -+ * must fail. -+ */ -+ return 1; -+ /* DFLTCC was not used yet - decompress in software */ -+ memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af)); -+ return 0; -+} -+ -+local int env_dfltcc_disabled; -+local int env_source_date_epoch; -+local unsigned long env_level_mask; -+local unsigned long env_block_size; -+local unsigned long env_block_threshold; -+local unsigned long env_dht_threshold; -+local unsigned long env_ribm; -+local uint64_t cpu_facilities[(DFLTCC_FACILITY / 64) + 1]; -+local struct dfltcc_qaf_param cpu_af __attribute__((aligned(8))); -+ -+local inline int is_dfltcc_enabled OF((void)); -+local inline int is_dfltcc_enabled(void) -+{ -+ if (env_dfltcc_disabled) -+ /* User has explicitly disabled DFLTCC. */ -+ return 0; -+ -+ return is_bit_set((const char *)cpu_facilities, DFLTCC_FACILITY); -+} -+ -+local unsigned long xstrtoul OF((const char *s, unsigned long _default)); -+local unsigned long xstrtoul(s, _default) -+ const char *s; -+ unsigned long _default; -+{ -+ char *endptr; -+ unsigned long result; -+ -+ if (!(s && *s)) -+ return _default; -+ errno = 0; -+ result = strtoul(s, &endptr, 0); -+ return (errno || *endptr) ? _default : result; -+} -+ -+__attribute__((constructor)) local void init_globals OF((void)); -+__attribute__((constructor)) local void init_globals(void) -+{ -+ const char *env; -+ register char r0 __asm__("r0"); -+ -+ env = secure_getenv("DFLTCC"); -+ env_dfltcc_disabled = env && !strcmp(env, "0"); -+ -+ env = secure_getenv("SOURCE_DATE_EPOCH"); -+ env_source_date_epoch = !!env; -+ -+#ifndef DFLTCC_LEVEL_MASK -+#define DFLTCC_LEVEL_MASK 0x2 -+#endif -+ env_level_mask = xstrtoul(secure_getenv("DFLTCC_LEVEL_MASK"), -+ DFLTCC_LEVEL_MASK); -+ -+#ifndef DFLTCC_BLOCK_SIZE -+#define DFLTCC_BLOCK_SIZE 1048576 -+#endif -+ env_block_size = xstrtoul(secure_getenv("DFLTCC_BLOCK_SIZE"), -+ DFLTCC_BLOCK_SIZE); -+ -+#ifndef DFLTCC_FIRST_FHT_BLOCK_SIZE -+#define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096 -+#endif -+ env_block_threshold = xstrtoul(secure_getenv("DFLTCC_FIRST_FHT_BLOCK_SIZE"), -+ DFLTCC_FIRST_FHT_BLOCK_SIZE); -+ -+#ifndef DFLTCC_DHT_MIN_SAMPLE_SIZE -+#define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096 -+#endif -+ env_dht_threshold = xstrtoul(secure_getenv("DFLTCC_DHT_MIN_SAMPLE_SIZE"), -+ DFLTCC_DHT_MIN_SAMPLE_SIZE); -+ -+#ifndef DFLTCC_RIBM -+#define DFLTCC_RIBM 0 -+#endif -+ env_ribm = xstrtoul(secure_getenv("DFLTCC_RIBM"), DFLTCC_RIBM); -+ -+ memset(cpu_facilities, 0, sizeof(cpu_facilities)); -+ r0 = sizeof(cpu_facilities) / sizeof(cpu_facilities[0]) - 1; -+ /* STFLE is supported since z9-109 and only in z/Architecture mode. When -+ * compiling with -m31, gcc defaults to ESA mode, however, since the kernel -+ * is 64-bit, it's always z/Architecture mode at runtime. -+ */ -+ __asm__ volatile( -+#ifndef __clang__ -+ ".machinemode push\n" -+ ".machinemode zarch\n" -+#endif -+ "stfle %[facilities]\n" -+#ifndef __clang__ -+ ".machinemode pop\n" -+#endif -+ : [facilities] "=Q" (cpu_facilities) -+ , [r0] "+r" (r0) -+ : -+ : "cc"); -+ -+ /* Initialize available functions */ -+ if (is_dfltcc_enabled()) -+ dfltcc(DFLTCC_QAF, &cpu_af, NULL, NULL, NULL, NULL, NULL); -+ else -+ memset(&cpu_af, 0, sizeof(cpu_af)); -+} -+ -+/* -+ Memory management. -+ -+ DFLTCC requires parameter blocks and window to be aligned. zlib allows -+ users to specify their own allocation functions, so using e.g. -+ `posix_memalign' is not an option. Thus, we overallocate and take the -+ aligned portion of the buffer. -+*/ -+void ZLIB_INTERNAL dfltcc_reset(strm, size) -+ z_streamp strm; -+ uInt size; -+{ -+ struct dfltcc_state *dfltcc_state = -+ (struct dfltcc_state *)((char FAR *)strm->state + ALIGN_UP(size, 8)); -+ -+ memcpy(&dfltcc_state->af, &cpu_af, sizeof(dfltcc_state->af)); -+ -+ if (env_source_date_epoch) -+ /* User needs reproducible results, but the output of DFLTCC_CMPR -+ * depends on buffers' page offsets. -+ */ -+ clear_bit(dfltcc_state->af.fns, DFLTCC_CMPR); -+ -+ /* Initialize parameter block */ -+ memset(&dfltcc_state->param, 0, sizeof(dfltcc_state->param)); -+ dfltcc_state->param.nt = 1; -+ -+ /* Initialize tuning parameters */ -+ dfltcc_state->level_mask = env_level_mask; -+ dfltcc_state->block_size = env_block_size; -+ dfltcc_state->block_threshold = env_block_threshold; -+ dfltcc_state->dht_threshold = env_dht_threshold; -+ dfltcc_state->param.ribm = env_ribm; -+} -+ -+voidpf ZLIB_INTERNAL dfltcc_alloc_state(strm, items, size) -+ z_streamp strm; -+ uInt items; -+ uInt size; -+{ -+ return ZALLOC(strm, -+ ALIGN_UP(items * size, 8) + sizeof(struct dfltcc_state), -+ sizeof(unsigned char)); -+} -+ -+void ZLIB_INTERNAL dfltcc_copy_state(dst, src, size) -+ voidpf dst; -+ const voidpf src; -+ uInt size; -+{ -+ zmemcpy(dst, src, ALIGN_UP(size, 8) + sizeof(struct dfltcc_state)); -+} -+ -+static const int PAGE_ALIGN = 0x1000; -+ -+voidpf ZLIB_INTERNAL dfltcc_alloc_window(strm, items, size) -+ z_streamp strm; -+ uInt items; -+ uInt size; -+{ -+ voidpf p, w; -+ -+ /* To simplify freeing, we store the pointer to the allocated buffer right -+ * before the window. -+ */ -+ p = ZALLOC(strm, sizeof(voidpf) + items * size + PAGE_ALIGN, -+ sizeof(unsigned char)); -+ if (p == NULL) -+ return NULL; -+ w = ALIGN_UP((char FAR *)p + sizeof(voidpf), PAGE_ALIGN); -+ *(voidpf *)((char FAR *)w - sizeof(voidpf)) = p; -+ return w; -+} -+ -+void ZLIB_INTERNAL dfltcc_free_window(strm, w) -+ z_streamp strm; -+ voidpf w; -+{ -+ if (w) -+ ZFREE(strm, *(voidpf *)((unsigned char FAR *)w - sizeof(voidpf))); -+} -+ -+/* -+ Switching between hardware and software compression. -+ -+ DFLTCC does not support all zlib settings, e.g. generation of non-compressed -+ blocks or alternative window sizes. When such settings are applied on the -+ fly with deflateParams, we need to convert between hardware and software -+ window formats. -+*/ -+int ZLIB_INTERNAL dfltcc_deflate_params(strm, level, strategy, flush) -+ z_streamp strm; -+ int level; -+ int strategy; -+ int *flush; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; -+ int could_deflate = dfltcc_can_deflate(strm); -+ int can_deflate = dfltcc_can_deflate_with_params(strm, -+ level, -+ state->w_bits, -+ strategy); -+ -+ if (can_deflate == could_deflate) -+ /* We continue to work in the same mode - no changes needed */ -+ return Z_OK; -+ -+ if (strm->total_in == 0 && param->nt == 1 && param->hl == 0) -+ /* DFLTCC was not used yet - no changes needed */ -+ return Z_OK; -+ -+ /* For now, do not convert between window formats - simply get rid of the -+ * old data instead. -+ */ -+ *flush = Z_FULL_FLUSH; -+ return Z_OK; -+} -+ -+int ZLIB_INTERNAL dfltcc_deflate_done(strm, flush) -+ z_streamp strm; -+ int flush; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; -+ -+ /* When deflate(Z_FULL_FLUSH) is called with small avail_out, it might -+ * close the block without resetting the compression state. Detect this -+ * situation and return that deflation is not done. -+ */ -+ if (flush == Z_FULL_FLUSH && strm->avail_out == 0) -+ return 0; -+ -+ /* Return that deflation is not done if DFLTCC is used and either it -+ * buffered some data (Continuation Flag is set), or has not written EOBS -+ * yet (Block-Continuation Flag is set). -+ */ -+ return !dfltcc_can_deflate(strm) || (!param->cf && !param->bcf); -+} -+ -+/* -+ Preloading history. -+*/ -+local void append_history OF((struct dfltcc_param_v0 FAR *param, -+ Bytef *history, -+ const Bytef *buf, -+ uInt count)); -+local void append_history(param, history, buf, count) -+ struct dfltcc_param_v0 FAR *param; -+ Bytef *history; -+ const Bytef *buf; -+ uInt count; -+{ -+ size_t offset; -+ size_t n; -+ -+ /* Do not use more than 32K */ -+ if (count > HB_SIZE) { -+ buf += count - HB_SIZE; -+ count = HB_SIZE; -+ } -+ offset = (param->ho + param->hl) % HB_SIZE; -+ if (offset + count <= HB_SIZE) -+ /* Circular history buffer does not wrap - copy one chunk */ -+ zmemcpy(history + offset, buf, count); -+ else { -+ /* Circular history buffer wraps - copy two chunks */ -+ n = HB_SIZE - offset; -+ zmemcpy(history + offset, buf, n); -+ zmemcpy(history, buf + n, count - n); -+ } -+ n = param->hl + count; -+ if (n <= HB_SIZE) -+ /* All history fits into buffer - no need to discard anything */ -+ param->hl = n; -+ else { -+ /* History does not fit into buffer - discard extra bytes */ -+ param->ho = (param->ho + (n - HB_SIZE)) % HB_SIZE; -+ param->hl = HB_SIZE; -+ } -+} -+ -+int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(strm, dictionary, dict_length) -+ z_streamp strm; -+ const Bytef *dictionary; -+ uInt dict_length; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; -+ -+ append_history(param, state->window, dictionary, dict_length); -+ state->strstart = 1; /* Add FDICT to zlib header */ -+ state->block_start = state->strstart; /* Make deflate_stored happy */ -+ return Z_OK; -+} -+ -+int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(strm, dictionary, dict_length) -+ z_streamp strm; -+ Bytef *dictionary; -+ uInt *dict_length; -+{ -+ deflate_state FAR *state = (deflate_state FAR *)strm->state; -+ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); -+ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; -+ -+ if (dictionary) { -+ if (param->ho + param->hl <= HB_SIZE) -+ /* Circular history buffer does not wrap - copy one chunk */ -+ zmemcpy(dictionary, state->window + param->ho, param->hl); -+ else { -+ /* Circular history buffer wraps - copy two chunks */ -+ zmemcpy(dictionary, -+ state->window + param->ho, -+ HB_SIZE - param->ho); -+ zmemcpy(dictionary + HB_SIZE - param->ho, -+ state->window, -+ param->ho + param->hl - HB_SIZE); -+ } -+ } -+ if (dict_length) -+ *dict_length = param->hl; -+ return Z_OK; -+} ---- /dev/null -+++ b/contrib/s390/dfltcc_deflate.h -@@ -0,0 +1,55 @@ -+#ifndef DFLTCC_DEFLATE_H -+#define DFLTCC_DEFLATE_H -+ -+#include "dfltcc.h" -+ -+int ZLIB_INTERNAL dfltcc_can_deflate OF((z_streamp strm)); -+int ZLIB_INTERNAL dfltcc_deflate OF((z_streamp strm, -+ int flush, -+ block_state *result)); -+int ZLIB_INTERNAL dfltcc_deflate_params OF((z_streamp strm, -+ int level, -+ int strategy, -+ int *flush)); -+int ZLIB_INTERNAL dfltcc_deflate_done OF((z_streamp strm, int flush)); -+int ZLIB_INTERNAL dfltcc_deflate_set_dictionary OF((z_streamp strm, -+ const Bytef *dictionary, -+ uInt dict_length)); -+int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm, -+ Bytef *dictionary, -+ uInt* dict_length)); -+ -+#define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \ -+ do { \ -+ if (dfltcc_can_deflate((strm))) \ -+ return dfltcc_deflate_set_dictionary((strm), (dict), (dict_len)); \ -+ } while (0) -+#define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) \ -+ do { \ -+ if (dfltcc_can_deflate((strm))) \ -+ return dfltcc_deflate_get_dictionary((strm), (dict), (dict_len)); \ -+ } while (0) -+#define DEFLATE_RESET_KEEP_HOOK(strm) \ -+ dfltcc_reset((strm), sizeof(deflate_state)) -+#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) \ -+ do { \ -+ int err; \ -+\ -+ err = dfltcc_deflate_params((strm), \ -+ (level), \ -+ (strategy), \ -+ (hook_flush)); \ -+ if (err == Z_STREAM_ERROR) \ -+ return err; \ -+ } while (0) -+#define DEFLATE_DONE dfltcc_deflate_done -+#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \ -+ do { \ -+ if (dfltcc_can_deflate((strm))) \ -+ (complen) = DEFLATE_BOUND_COMPLEN(source_len); \ -+ } while (0) -+#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm))) -+#define DEFLATE_HOOK dfltcc_deflate -+#define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm))) -+ -+#endif ---- /dev/null -+++ b/contrib/s390/dfltcc.h -@@ -0,0 +1,81 @@ -+#ifndef DFLTCC_H -+#define DFLTCC_H -+ -+#include "../../zlib.h" -+#include "../../zutil.h" -+ -+voidpf ZLIB_INTERNAL dfltcc_alloc_state OF((z_streamp strm, uInt items, -+ uInt size)); -+void ZLIB_INTERNAL dfltcc_copy_state OF((voidpf dst, const voidpf src, -+ uInt size)); -+void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size)); -+voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items, -+ uInt size)); -+void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w)); -+#define DFLTCC_BLOCK_HEADER_BITS 3 -+#define DFLTCC_HLITS_COUNT_BITS 5 -+#define DFLTCC_HDISTS_COUNT_BITS 5 -+#define DFLTCC_HCLENS_COUNT_BITS 4 -+#define DFLTCC_MAX_HCLENS 19 -+#define DFLTCC_HCLEN_BITS 3 -+#define DFLTCC_MAX_HLITS 286 -+#define DFLTCC_MAX_HDISTS 30 -+#define DFLTCC_MAX_HLIT_HDIST_BITS 7 -+#define DFLTCC_MAX_SYMBOL_BITS 16 -+#define DFLTCC_MAX_EOBS_BITS 15 -+#define DFLTCC_MAX_PADDING_BITS 7 -+#define DEFLATE_BOUND_COMPLEN(source_len) \ -+ ((DFLTCC_BLOCK_HEADER_BITS + \ -+ DFLTCC_HLITS_COUNT_BITS + \ -+ DFLTCC_HDISTS_COUNT_BITS + \ -+ DFLTCC_HCLENS_COUNT_BITS + \ -+ DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \ -+ (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \ -+ (source_len) * DFLTCC_MAX_SYMBOL_BITS + \ -+ DFLTCC_MAX_EOBS_BITS + \ -+ DFLTCC_MAX_PADDING_BITS) >> 3) -+int ZLIB_INTERNAL dfltcc_can_inflate OF((z_streamp strm)); -+typedef enum { -+ DFLTCC_INFLATE_CONTINUE, -+ DFLTCC_INFLATE_BREAK, -+ DFLTCC_INFLATE_SOFTWARE, -+} dfltcc_inflate_action; -+dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate OF((z_streamp strm, -+ int flush, int *ret)); -+int ZLIB_INTERNAL dfltcc_was_inflate_used OF((z_streamp strm)); -+int ZLIB_INTERNAL dfltcc_inflate_disable OF((z_streamp strm)); -+ -+#define ZALLOC_STATE dfltcc_alloc_state -+#define ZFREE_STATE ZFREE -+#define ZCOPY_STATE dfltcc_copy_state -+#define ZALLOC_WINDOW dfltcc_alloc_window -+#define ZFREE_WINDOW dfltcc_free_window -+#define TRY_FREE_WINDOW dfltcc_free_window -+#define INFLATE_RESET_KEEP_HOOK(strm) \ -+ dfltcc_reset((strm), sizeof(struct inflate_state)) -+#define INFLATE_PRIME_HOOK(strm, bits, value) \ -+ do { if (dfltcc_inflate_disable((strm))) return Z_STREAM_ERROR; } while (0) -+#define INFLATE_TYPEDO_HOOK(strm, flush) \ -+ if (dfltcc_can_inflate((strm))) { \ -+ dfltcc_inflate_action action; \ -+\ -+ RESTORE(); \ -+ action = dfltcc_inflate((strm), (flush), &ret); \ -+ LOAD(); \ -+ if (action == DFLTCC_INFLATE_CONTINUE) \ -+ break; \ -+ else if (action == DFLTCC_INFLATE_BREAK) \ -+ goto inf_leave; \ -+ } -+#define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm))) -+#define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm))) -+#define INFLATE_MARK_HOOK(strm) \ -+ do { \ -+ if (dfltcc_was_inflate_used((strm))) return -(1L << 16); \ -+ } while (0) -+#define INFLATE_SYNC_POINT_HOOK(strm) \ -+ do { \ -+ if (dfltcc_was_inflate_used((strm))) return Z_STREAM_ERROR; \ -+ } while (0) -+ -+#endif ---- /dev/null -+++ b/contrib/s390/README.txt -@@ -0,0 +1,17 @@ -+IBM Z mainframes starting from version z15 provide DFLTCC instruction, -+which implements deflate algorithm in hardware with estimated -+compression and decompression performance orders of magnitude faster -+than the current zlib and ratio comparable with that of level 1. -+ -+This directory adds DFLTCC support. In order to enable it, the following -+build commands should be used: -+ -+ $ ./configure --dfltcc -+ $ make -+ -+When built like this, zlib would compress in hardware on level 1, and in -+software on all other levels. Decompression will always happen in -+hardware. In order to enable DFLTCC compression for levels 1-6 (i.e. to -+make it used by default) one could either configure with -+--dfltcc-level-mask=0x7e or set the environment variable -+DFLTCC_LEVEL_MASK to 0x7e at run time. ---- a/deflate.c -+++ b/deflate.c -@@ -61,15 +61,30 @@ - */ - - /* =========================================================================== -- * Function prototypes. -+ * Architecture-specific bits. - */ --typedef enum { -- need_more, /* block not completed, need more input or more output */ -- block_done, /* block flush performed */ -- finish_started, /* finish started, need only more output at next deflate */ -- finish_done /* finish done, accept no more input or output */ --} block_state; -+#ifdef DFLTCC -+# include "contrib/s390/dfltcc_deflate.h" -+#else -+#define ZALLOC_STATE ZALLOC -+#define ZFREE_STATE ZFREE -+#define ZCOPY_STATE zmemcpy -+#define ZALLOC_WINDOW ZALLOC -+#define TRY_FREE_WINDOW TRY_FREE -+#define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) -+#define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) -+#define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0) -+#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0) -+#define DEFLATE_DONE(strm, flush) 1 -+#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0) -+#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0 -+#define DEFLATE_HOOK(strm, flush, bstate) 0 -+#define DEFLATE_NEED_CHECKSUM(strm) 1 -+#endif - -+/* =========================================================================== -+ * Function prototypes. -+ */ - typedef block_state (*compress_func) OF((deflate_state *s, int flush)); - /* Compression function. Returns the block state after the call. */ - -@@ -85,7 +100,6 @@ - local block_state deflate_huff OF((deflate_state *s, int flush)); - local void lm_init OF((deflate_state *s)); - local void putShortMSB OF((deflate_state *s, uInt b)); --local void flush_pending OF((z_streamp strm)); - local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); - local uInt longest_match OF((deflate_state *s, IPos cur_match)); - -@@ -295,7 +309,7 @@ - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ -- s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); -+ s = (deflate_state *) ZALLOC_STATE(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; -@@ -312,7 +326,7 @@ - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH); - -- s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); -+ s->window = (Bytef *) ZALLOC_WINDOW(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - -@@ -430,6 +444,7 @@ - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); -+ DEFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ -@@ -488,6 +503,7 @@ - - if (deflateStateCheck(strm)) - return Z_STREAM_ERROR; -+ DEFLATE_GET_DICTIONARY_HOOK(strm, dictionary, dictLength); - s = strm->state; - len = s->strstart + s->lookahead; - if (len > s->w_size) -@@ -534,6 +550,8 @@ - - _tr_init(s); - -+ DEFLATE_RESET_KEEP_HOOK(strm); -+ - return Z_OK; - } - -@@ -609,6 +627,7 @@ - { - deflate_state *s; - compress_func func; -+ int hook_flush = Z_NO_FLUSH; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; -@@ -621,15 +640,18 @@ - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } -+ DEFLATE_PARAMS_HOOK(strm, level, strategy, &hook_flush); - func = configuration_table[s->level].func; - -- if ((strategy != s->strategy || func != configuration_table[level].func) && -- s->last_flush != -2) { -+ if (((strategy != s->strategy || func != configuration_table[level].func) && -+ s->last_flush != -2) || hook_flush != Z_NO_FLUSH) { - /* Flush the last buffer: */ -- int err = deflate(strm, Z_BLOCK); -+ int flush = RANK(hook_flush) > RANK(Z_BLOCK) ? hook_flush : Z_BLOCK; -+ int err = deflate(strm, flush); - if (err == Z_STREAM_ERROR) - return err; -- if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead) -+ if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead || -+ !DEFLATE_DONE(strm, flush)) - return Z_BUF_ERROR; - } - if (s->level != level) { -@@ -705,11 +727,13 @@ - ~13% overhead plus a small constant */ - fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) + - (sourceLen >> 9) + 4; -+ DEFLATE_BOUND_ADJUST_COMPLEN(strm, fixedlen, sourceLen); - - /* upper bound for stored blocks with length 127 (memLevel == 1) -- - ~4% overhead plus a small constant */ - storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + - (sourceLen >> 11) + 7; -+ DEFLATE_BOUND_ADJUST_COMPLEN(strm, storelen, sourceLen); - - /* if can't get parameters, return larger bound plus a zlib wrapper */ - if (deflateStateCheck(strm)) -@@ -751,7 +775,8 @@ - } - - /* if not default parameters, return one of the conservative bounds */ -- if (s->w_bits != 15 || s->hash_bits != 8 + 7) -+ if (DEFLATE_NEED_CONSERVATIVE_BOUND(strm) || -+ s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; - - /* default settings: return tight bound for that case -- ~0.03% overhead -@@ -779,7 +804,7 @@ - * applications may wish to modify it to avoid allocating a large - * strm->next_out buffer and copying into it. (See also read_buf()). - */ --local void flush_pending(strm) -+void ZLIB_INTERNAL flush_pending(strm) - z_streamp strm; - { - unsigned len; -@@ -1051,7 +1076,8 @@ - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - -- bstate = s->level == 0 ? deflate_stored(s, flush) : -+ bstate = DEFLATE_HOOK(strm, flush, &bstate) ? bstate : -+ s->level == 0 ? deflate_stored(s, flush) : - s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush); -@@ -1098,7 +1124,6 @@ - } - - if (flush != Z_FINISH) return Z_OK; -- if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ - #ifdef GZIP -@@ -1114,7 +1139,7 @@ - } - else - #endif -- { -+ if (s->wrap == 1) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } -@@ -1123,7 +1148,11 @@ - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ -- return s->pending != 0 ? Z_OK : Z_STREAM_END; -+ if (s->pending == 0) { -+ Assert(s->bi_valid == 0, "bi_buf not flushed"); -+ return Z_STREAM_END; -+ } -+ return Z_OK; - } - - /* ========================================================================= */ -@@ -1140,9 +1169,9 @@ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); -- TRY_FREE(strm, strm->state->window); -+ TRY_FREE_WINDOW(strm, strm->state->window); - -- ZFREE(strm, strm->state); -+ ZFREE_STATE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -@@ -1172,13 +1201,13 @@ - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - -- ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); -+ ds = (deflate_state *) ZALLOC_STATE(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; -- zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); -+ ZCOPY_STATE((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - -- ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); -+ ds->window = (Bytef *) ZALLOC_WINDOW(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); -@@ -1225,7 +1254,8 @@ - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); -- if (strm->state->wrap == 1) { -+ if (!DEFLATE_NEED_CHECKSUM(strm)) {} -+ else if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } - #ifdef GZIP ---- a/deflate.h -+++ b/deflate.h -@@ -299,6 +299,7 @@ - void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); - void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -+void ZLIB_INTERNAL _tr_send_bits OF((deflate_state *s, int value, int length)); - - #define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -@@ -343,4 +344,15 @@ - flush = _tr_tally(s, distance, length) - #endif - -+typedef enum { -+ need_more, /* block not completed, need more input or more output */ -+ block_done, /* block flush performed */ -+ finish_started, /* finish started, need only more output at next deflate */ -+ finish_done /* finish done, accept no more input or output */ -+} block_state; -+ -+unsigned ZLIB_INTERNAL bi_reverse OF((unsigned code, int len)); -+void ZLIB_INTERNAL bi_windup OF((deflate_state *s)); -+void ZLIB_INTERNAL flush_pending OF((z_streamp strm)); -+ - #endif /* DEFLATE_H */ ---- a/gzguts.h -+++ b/gzguts.h -@@ -153,7 +153,11 @@ - - /* default i/o buffer size -- double this for output when reading (this and - twice this must be able to fit in an unsigned type) */ -+#ifdef DFLTCC -+#define GZBUFSIZE 131072 -+#else - #define GZBUFSIZE 8192 -+#endif - - /* gzip modes, also provide a little integrity check on the passed structure */ - #define GZ_NONE 0 ---- a/inflate.c -+++ b/inflate.c -@@ -85,6 +85,24 @@ - #include "inflate.h" - #include "inffast.h" - -+/* architecture-specific bits */ -+#ifdef DFLTCC -+# include "contrib/s390/dfltcc.h" -+#else -+#define ZALLOC_STATE ZALLOC -+#define ZFREE_STATE ZFREE -+#define ZCOPY_STATE zmemcpy -+#define ZALLOC_WINDOW ZALLOC -+#define ZFREE_WINDOW ZFREE -+#define INFLATE_RESET_KEEP_HOOK(strm) do {} while (0) -+#define INFLATE_PRIME_HOOK(strm, bits, value) do {} while (0) -+#define INFLATE_TYPEDO_HOOK(strm, flush) do {} while (0) -+#define INFLATE_NEED_CHECKSUM(strm) 1 -+#define INFLATE_NEED_UPDATEWINDOW(strm) 1 -+#define INFLATE_MARK_HOOK(strm) do {} while (0) -+#define INFLATE_SYNC_POINT_HOOK(strm) do {} while (0) -+#endif -+ - #ifdef MAKEFIXED - # ifndef BUILDFIXED - # define BUILDFIXED -@@ -138,6 +156,7 @@ - state->lencode = state->distcode = state->next = state->codes; - state->sane = 1; - state->back = -1; -+ INFLATE_RESET_KEEP_HOOK(strm); - Tracev((stderr, "inflate: reset\n")); - return Z_OK; - } -@@ -185,7 +204,7 @@ - if (windowBits && (windowBits < 8 || windowBits > 15)) - return Z_STREAM_ERROR; - if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { -- ZFREE(strm, state->window); -+ ZFREE_WINDOW(strm, state->window); - state->window = Z_NULL; - } - -@@ -224,7 +243,7 @@ - strm->zfree = zcfree; - #endif - state = (struct inflate_state FAR *) -- ZALLOC(strm, 1, sizeof(struct inflate_state)); -+ ZALLOC_STATE(strm, 1, sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; -@@ -233,7 +252,7 @@ - state->mode = HEAD; /* to pass state test in inflateReset2() */ - ret = inflateReset2(strm, windowBits); - if (ret != Z_OK) { -- ZFREE(strm, state); -+ ZFREE_STATE(strm, state); - strm->state = Z_NULL; - } - return ret; -@@ -255,6 +274,7 @@ - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; -+ INFLATE_PRIME_HOOK(strm, bits, value); - state = (struct inflate_state FAR *)strm->state; - if (bits < 0) { - state->hold = 0; -@@ -382,6 +402,27 @@ - } - #endif /* MAKEFIXED */ - -+int ZLIB_INTERNAL inflate_ensure_window(state) -+ struct inflate_state *state; -+{ -+ /* if it hasn't been done already, allocate space for the window */ -+ if (state->window == Z_NULL) { -+ state->window = (unsigned char FAR *) -+ ZALLOC_WINDOW(state->strm, 1U << state->wbits, -+ sizeof(unsigned char)); -+ if (state->window == Z_NULL) return 1; -+ } -+ -+ /* if window not in use yet, initialize */ -+ if (state->wsize == 0) { -+ state->wsize = 1U << state->wbits; -+ state->wnext = 0; -+ state->whave = 0; -+ } -+ -+ return 0; -+} -+ - /* - Update the window with the last wsize (normally 32K) bytes written before - returning. If window does not exist yet, create it. This is only called -@@ -406,20 +447,7 @@ - - state = (struct inflate_state FAR *)strm->state; - -- /* if it hasn't been done already, allocate space for the window */ -- if (state->window == Z_NULL) { -- state->window = (unsigned char FAR *) -- ZALLOC(strm, 1U << state->wbits, -- sizeof(unsigned char)); -- if (state->window == Z_NULL) return 1; -- } -- -- /* if window not in use yet, initialize */ -- if (state->wsize == 0) { -- state->wsize = 1U << state->wbits; -- state->wnext = 0; -- state->whave = 0; -- } -+ if (inflate_ensure_window(state)) return 1; - - /* copy state->wsize or less output bytes into the circular window */ - if (copy >= state->wsize) { -@@ -863,6 +891,7 @@ - if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; - /* fallthrough */ - case TYPEDO: -+ INFLATE_TYPEDO_HOOK(strm, flush); - if (state->last) { - BYTEBITS(); - state->mode = CHECK; -@@ -1224,7 +1253,7 @@ - out -= left; - strm->total_out += out; - state->total += out; -- if ((state->wrap & 4) && out) -+ if (INFLATE_NEED_CHECKSUM(strm) && (state->wrap & 4) && out) - strm->adler = state->check = - UPDATE_CHECK(state->check, put - out, out); - out = left; -@@ -1279,8 +1308,9 @@ - */ - inf_leave: - RESTORE(); -- if (state->wsize || (out != strm->avail_out && state->mode < BAD && -- (state->mode < CHECK || flush != Z_FINISH))) -+ if (INFLATE_NEED_UPDATEWINDOW(strm) && -+ (state->wsize || (out != strm->avail_out && state->mode < BAD && -+ (state->mode < CHECK || flush != Z_FINISH)))) - if (updatewindow(strm, strm->next_out, out - strm->avail_out)) { - state->mode = MEM; - return Z_MEM_ERROR; -@@ -1290,7 +1320,7 @@ - strm->total_in += in; - strm->total_out += out; - state->total += out; -- if ((state->wrap & 4) && out) -+ if (INFLATE_NEED_CHECKSUM(strm) && (state->wrap & 4) && out) - strm->adler = state->check = - UPDATE_CHECK(state->check, strm->next_out - out, out); - strm->data_type = (int)state->bits + (state->last ? 64 : 0) + -@@ -1308,8 +1338,8 @@ - if (inflateStateCheck(strm)) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; -- if (state->window != Z_NULL) ZFREE(strm, state->window); -- ZFREE(strm, strm->state); -+ if (state->window != Z_NULL) ZFREE_WINDOW(strm, state->window); -+ ZFREE_STATE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -@@ -1488,6 +1518,7 @@ - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; -+ INFLATE_SYNC_POINT_HOOK(strm); - state = (struct inflate_state FAR *)strm->state; - return state->mode == STORED && state->bits == 0; - } -@@ -1508,21 +1539,22 @@ - - /* allocate space */ - copy = (struct inflate_state FAR *) -- ZALLOC(source, 1, sizeof(struct inflate_state)); -+ ZALLOC_STATE(source, 1, sizeof(struct inflate_state)); - if (copy == Z_NULL) return Z_MEM_ERROR; - window = Z_NULL; - if (state->window != Z_NULL) { - window = (unsigned char FAR *) -- ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); -+ ZALLOC_WINDOW(source, 1U << state->wbits, -+ sizeof(unsigned char)); - if (window == Z_NULL) { -- ZFREE(source, copy); -+ ZFREE_STATE(source, copy); - return Z_MEM_ERROR; - } - } - - /* copy state */ - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); -- zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); -+ ZCOPY_STATE((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); - copy->strm = dest; - if (state->lencode >= state->codes && - state->lencode <= state->codes + ENOUGH - 1) { -@@ -1579,6 +1611,7 @@ - - if (inflateStateCheck(strm)) - return -(1L << 16); -+ INFLATE_MARK_HOOK(strm); - state = (struct inflate_state FAR *)strm->state; - return (long)(((unsigned long)((long)state->back)) << 16) + - (state->mode == COPY ? state->length : ---- a/inflate.h -+++ b/inflate.h -@@ -124,3 +124,5 @@ - int back; /* bits back of last unprocessed length/lit */ - unsigned was; /* initial length of match */ - }; -+ -+int ZLIB_INTERNAL inflate_ensure_window OF((struct inflate_state *state)); ---- a/Makefile.in -+++ b/Makefile.in -@@ -139,6 +139,14 @@ - mv _match.o match.lo - rm -f _match.s - -+dfltcc.o: $(SRCDIR)contrib/s390/dfltcc.c $(SRCDIR)zlib.h zconf.h -+ $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)contrib/s390/dfltcc.c -+ -+dfltcc.lo: $(SRCDIR)contrib/s390/dfltcc.c $(SRCDIR)zlib.h zconf.h -+ -@mkdir objs 2>/dev/null || test -d objs -+ $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/s390/dfltcc.c -+ -@mv objs/dfltcc.o $@ -+ - example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c - ---- a/test/infcover.c -+++ b/test/infcover.c -@@ -373,7 +373,7 @@ - mem_setup(&strm); - strm.avail_in = 0; - strm.next_in = Z_NULL; -- ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream)); -+ ret = inflateInit_(&strm, &ZLIB_VERSION[1], (int)sizeof(z_stream)); - assert(ret == Z_VERSION_ERROR); - mem_done(&strm, "wrong version"); - -@@ -444,7 +444,7 @@ - } - - /* input and output functions for inflateBack() */ --local unsigned pull(void *desc, unsigned char **buf) -+local unsigned pull(void *desc, z_const unsigned char **buf) - { - static unsigned int next = 0; - static unsigned char dat[] = {0x63, 0, 2, 0}; ---- a/test/minigzip.c -+++ b/test/minigzip.c -@@ -132,7 +132,11 @@ - #endif - #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) - -+#ifdef DFLTCC -+#define BUFLEN 262144 -+#else - #define BUFLEN 16384 -+#endif - #define MAX_NAME_LEN 1024 - - #ifdef MAXSEG_64K ---- a/trees.c -+++ b/trees.c -@@ -149,8 +149,6 @@ - local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); - local int detect_data_type OF((deflate_state *s)); --local unsigned bi_reverse OF((unsigned code, int len)); --local void bi_windup OF((deflate_state *s)); - local void bi_flush OF((deflate_state *s)); - - #ifdef GEN_TREES_H -@@ -223,6 +221,13 @@ - } - #endif /* ZLIB_DEBUG */ - -+void ZLIB_INTERNAL _tr_send_bits(s, value, length) -+ deflate_state *s; -+ int value; -+ int length; -+{ -+ send_bits(s, value, length); -+} - - /* the arguments must not have side effects */ - -@@ -1133,7 +1138,7 @@ - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ --local unsigned bi_reverse(code, len) -+unsigned ZLIB_INTERNAL bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ - { -@@ -1165,7 +1170,7 @@ - /* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ --local void bi_windup(s) -+void ZLIB_INTERNAL bi_windup(s) - deflate_state *s; - { - if (s->bi_valid > 8) { ---- a/zutil.h -+++ b/zutil.h -@@ -87,6 +87,8 @@ - - #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - -+#define ZLIB_WRAPLEN 6 /* zlib format overhead */ -+ - /* target dependencies */ - - #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) diff -Nru zlib-1.2.13.dfsg/debian/patches/478.patch zlib-1.3.1.dfsg/debian/patches/478.patch --- zlib-1.2.13.dfsg/debian/patches/478.patch 2022-11-07 23:57:28.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/478.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,2678 +0,0 @@ -https://github.com/madler/zlib/pull/478, powerpc optimizations - -Index: zlib-1.2.13.dfsg-1ubuntu1/CMakeLists.txt -=================================================================== ---- zlib-1.2.13.dfsg-1ubuntu1.orig/CMakeLists.txt -+++ zlib-1.2.13.dfsg-1ubuntu1/CMakeLists.txt -@@ -5,6 +5,8 @@ - - set(VERSION "1.2.13") - -+option(POWER "Enable building power implementation") -+ - set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") - set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") - set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") -@@ -56,6 +58,75 @@ - # - check_include_file(unistd.h Z_HAVE_UNISTD_H) - -+if(CMAKE_COMPILER_IS_GNUCC) -+ # test to see if we can use a GNU indirect function to detect and load optimized code at runtime -+ CHECK_C_SOURCE_COMPILES(" -+ static int test_ifunc_native(void) -+ { -+ return 1; -+ } -+ static int (*(check_ifunc_native(void)))(void) -+ { -+ return test_ifunc_native; -+ } -+ int test_ifunc(void) __attribute__ ((ifunc (\"check_ifunc_native\"))); -+ int main(void) -+ { -+ return 0; -+ } -+ " HAS_C_ATTR_IFUNC) -+ -+ if(HAS_C_ATTR_IFUNC) -+ add_definitions(-DHAVE_IFUNC) -+ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/gcc/zifunc.h) -+ endif() -+ -+ if(POWER) -+ # Test to see if we can use the optimizations for Power -+ CHECK_C_SOURCE_COMPILES(" -+ #ifndef _ARCH_PPC -+ #error \"Target is not Power\" -+ #endif -+ #ifndef __BUILTIN_CPU_SUPPORTS__ -+ #error \"Target doesn't support __builtin_cpu_supports()\" -+ #endif -+ int main() { return 0; } -+ " HAS_POWER_SUPPORT) -+ -+ if(HAS_POWER_SUPPORT AND HAS_C_ATTR_IFUNC) -+ add_definitions(-DZ_POWER_OPT) -+ -+ set(CMAKE_REQUIRED_FLAGS -mcpu=power8) -+ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER8) -+ -+ if(POWER8) -+ add_definitions(-DZ_POWER8) -+ set(ZLIB_POWER8 -+ contrib/power/crc32_z_power8.c) -+ -+ set_source_files_properties( -+ ${ZLIB_POWER8} -+ PROPERTIES COMPILE_FLAGS -mcpu=power8) -+ endif() -+ -+ set(CMAKE_REQUIRED_FLAGS -mcpu=power9) -+ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER9) -+ -+ if(POWER9) -+ add_definitions(-DZ_POWER9) -+ set(ZLIB_POWER9 ) -+ -+ set_source_files_properties( -+ ${ZLIB_POWER9} -+ PROPERTIES COMPILE_FLAGS -mcpu=power9) -+ endif() -+ -+ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/power/power.h) -+ set(ZLIB_SRCS ${ZLIB_SRCS} ${ZLIB_POWER8} ${ZLIB_POWER9}) -+ endif() -+ endif() -+endif() -+ - if(MSVC) - set(CMAKE_DEBUG_POSTFIX "d") - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) -@@ -198,6 +269,10 @@ - target_link_libraries(example zlib) - add_test(example example) - -+add_executable(crc32_test test/crc32_test.c) -+target_link_libraries(crc32_test zlib) -+add_test(crc32_test crc32_test) -+ - add_executable(minigzip test/minigzip.c) - target_link_libraries(minigzip zlib) - -Index: zlib-1.2.13.dfsg-1ubuntu1/Makefile.in -=================================================================== ---- zlib-1.2.13.dfsg-1ubuntu1.orig/Makefile.in -+++ zlib-1.2.13.dfsg-1ubuntu1/Makefile.in -@@ -71,11 +71,11 @@ - - all: static shared - --static: example$(EXE) minigzip$(EXE) -+static: crc32_test$(EXE) example$(EXE) minigzip$(EXE) - --shared: examplesh$(EXE) minigzipsh$(EXE) -+shared: crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) - --all64: example64$(EXE) minigzip64$(EXE) -+all64: crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE) - - check: test - -@@ -83,7 +83,7 @@ - - teststatic: static - @TMPST=tmpst_$$; \ -- if echo hello world | ${QEMU_RUN} ./minigzip | ${QEMU_RUN} ./minigzip -d && ${QEMU_RUN} ./example $$TMPST ; then \ -+ if echo hello world | ${QEMU_RUN} ./minigzip | ${QEMU_RUN} ./minigzip -d && ${QEMU_RUN} ./example $$TMPST && ./crc32_test ; then \ - echo ' *** zlib test OK ***'; \ - else \ - echo ' *** zlib test FAILED ***'; false; \ -@@ -96,7 +96,7 @@ - DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \ - SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \ - TMPSH=tmpsh_$$; \ -- if echo hello world | ${QEMU_RUN} ./minigzipsh | ${QEMU_RUN} ./minigzipsh -d && ${QEMU_RUN} ./examplesh $$TMPSH; then \ -+ if echo hello world | ${QEMU_RUN} ./minigzipsh | ${QEMU_RUN} ./minigzipsh -d && ${QEMU_RUN} ./examplesh $$TMPSH && ./crc32_testsh; then \ - echo ' *** zlib shared test OK ***'; \ - else \ - echo ' *** zlib shared test FAILED ***'; false; \ -@@ -105,7 +105,7 @@ - - test64: all64 - @TMP64=tmp64_$$; \ -- if echo hello world | ${QEMU_RUN} ./minigzip64 | ${QEMU_RUN} ./minigzip64 -d && ${QEMU_RUN} ./example64 $$TMP64; then \ -+ if echo hello world | ${QEMU_RUN} ./minigzip64 | ${QEMU_RUN} ./minigzip64 -d && ${QEMU_RUN} ./example64 $$TMP64 && ./crc32_test64; then \ - echo ' *** zlib 64-bit test OK ***'; \ - else \ - echo ' *** zlib 64-bit test FAILED ***'; false; \ -@@ -147,12 +147,18 @@ - $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/s390/dfltcc.c - -@mv objs/dfltcc.o $@ - -+crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h -+ $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c -+ - example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c - - minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c - -+crc32_test64.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h -+ $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/crc32_test.c -+ - example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c - -@@ -166,6 +172,9 @@ - crc32.o: $(SRCDIR)crc32.c - $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c - -+crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c -+ $(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c -+ - deflate.o: $(SRCDIR)deflate.c - $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c - -@@ -216,6 +225,11 @@ - $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c - -@mv objs/crc32.o $@ - -+crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c -+ -@mkdir objs 2>/dev/null || test -d objs -+ $(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c -+ -@mv objs/crc32_z_power8.o $@ -+ - deflate.lo: $(SRCDIR)deflate.c - -@mkdir objs 2>/dev/null || test -d objs - $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c -@@ -289,18 +303,27 @@ - ln -s $@ $(SHAREDLIBM) - -@rmdir objs - -+crc32_test$(EXE): crc32_test.o $(STATICLIB) -+ $(CC) $(CFLAGS) -o $@ crc32_test.o $(TEST_LDFLAGS) -+ - example$(EXE): example.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) - - minigzip$(EXE): minigzip.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) - -+crc32_testsh$(EXE): crc32_test.o $(SHAREDLIBV) -+ $(CC) $(CFLAGS) -o $@ crc32_test.o -L. $(SHAREDLIBV) -+ - examplesh$(EXE): example.o $(SHAREDLIBV) - $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) -L. $(SHAREDLIBV) - - minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) - $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV) - -+crc32_test64$(EXE): crc32_test64.o $(STATICLIB) -+ $(CC) $(CFLAGS) -o $@ crc32_test64.o $(TEST_LDFLAGS) -+ - example64$(EXE): example64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) - -@@ -370,8 +393,8 @@ - mostlyclean: clean - clean: - rm -f *.o *.lo *~ \ -- example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ -- example64$(EXE) minigzip64$(EXE) \ -+ crc32_test$(EXE) example$(EXE) minigzip$(EXE) crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ -+ crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE) \ - infcover \ - libz.* foo.gz so_locations \ - _match.s maketree contrib/infback9/*.o -@@ -393,7 +416,7 @@ - - adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h - gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h --compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h -+compress.o crc32_test.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h - crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h - deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h - infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h -@@ -403,7 +426,7 @@ - - adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h - gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h --compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h -+compress.lo crc32_test.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h - crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h - deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h - infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h -Index: zlib-1.2.13.dfsg-1ubuntu1/configure -=================================================================== ---- zlib-1.2.13.dfsg-1ubuntu1.orig/configure -+++ zlib-1.2.13.dfsg-1ubuntu1/configure -@@ -852,6 +852,75 @@ - echo "Checking for sys/sdt.h ... No." | tee -a configure.log - fi - -+# test to see if we can use a gnu indirection function to detect and load optimized code at runtime -+echo >> configure.log -+cat > $test.c <> configure.log -+cat > $test.c < $test.c -+ -+ if tryboth $CC -c $CFLAGS -mcpu=power8 $test.c; then -+ POWER8="-DZ_POWER8" -+ PIC_OBJC="${PIC_OBJC} crc32_z_power8.lo" -+ OBJC="${OBJC} crc32_z_power8.o" -+ echo "Checking for -mcpu=power8 support... Yes." | tee -a configure.log -+ else -+ echo "Checking for -mcpu=power8 support... No." | tee -a configure.log -+ fi -+ -+ if tryboth $CC -c $CFLAGS -mcpu=power9 $test.c; then -+ POWER9="-DZ_POWER9" -+ PIC_OBJC="${PIC_OBJC}" -+ OBJC="${OBJC}" -+ echo "Checking for -mcpu=power9 support... Yes." | tee -a configure.log -+ else -+ echo "Checking for -mcpu=power9 support... No." | tee -a configure.log -+ fi -+ -+ SFLAGS="${SFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT" -+ CFLAGS="${CFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT" -+ echo "Checking for Power optimizations support... Yes." | tee -a configure.log -+else -+ echo "Checking for Power optimizations support... No." | tee -a configure.log -+fi -+ - # show the results in the log - echo >> configure.log - echo ALL = $ALL >> configure.log -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/README.contrib -=================================================================== ---- zlib-1.2.13.dfsg-1ubuntu1.orig/contrib/README.contrib -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/README.contrib -@@ -11,6 +11,10 @@ - blast/ by Mark Adler - Decompressor for output of PKWare Data Compression Library (DCL) - -+gcc/ by Matheus Castanho -+ and Rogerio Alves -+ Optimization helpers using GCC-specific extensions -+ - delphi/ by Cosmin Truta - Support for Delphi and C++ Builder - -@@ -42,6 +46,11 @@ - pascal/ by Bob Dellaca et al. - Support for Pascal - -+power/ by Daniel Black -+ Matheus Castanho -+ and Rogerio Alves -+ Optimized functions for Power processors -+ - puff/ by Mark Adler - Small, low memory usage inflate. Also serves to provide an - unambiguous description of the deflate format. -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/gcc/zifunc.h -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/gcc/zifunc.h -@@ -0,0 +1,60 @@ -+/* Copyright (C) 2019 Matheus Castanho , IBM -+ * 2019 Rogerio Alves , IBM -+ * For conditions of distribution and use, see copyright notice in zlib.h -+ */ -+ -+#ifndef Z_IFUNC_H_ -+#define Z_IFUNC_H_ -+ -+/* Helpers for arch optimizations */ -+ -+#define Z_IFUNC(fname) \ -+ typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \ -+ local typeof(fname) *fname##_resolver(void) -+/* This is a helper macro to declare a resolver for an indirect function -+ * (ifunc). Let's say you have function -+ * -+ * int foo (int a); -+ * -+ * for which you want to provide different implementations, for example: -+ * -+ * int foo_clever (int a) { -+ * ... clever things ... -+ * } -+ * -+ * int foo_smart (int a) { -+ * ... smart things ... -+ * } -+ * -+ * You will have to declare foo() as an indirect function and also provide a -+ * resolver for it, to choose between foo_clever() and foo_smart() based on -+ * some criteria you define (e.g. processor features). -+ * -+ * Since most likely foo() has a default implementation somewhere in zlib, you -+ * may have to rename it so the 'foo' symbol can be used by the ifunc without -+ * conflicts. -+ * -+ * #define foo foo_default -+ * int foo (int a) { -+ * ... -+ * } -+ * #undef foo -+ * -+ * Now you just have to provide a resolver function to choose which function -+ * should be used (decided at runtime on the first call to foo()): -+ * -+ * Z_IFUNC(foo) { -+ * if (... some condition ...) -+ * return foo_clever; -+ * -+ * if (... other condition ...) -+ * return foo_smart; -+ * -+ * return foo_default; -+ * } -+ * -+ * All calls to foo() throughout the code can remain untouched, all the magic -+ * will be done by the linker using the resolver function. -+ */ -+ -+#endif /* Z_IFUNC_H_ */ -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/power/clang_workaround.h -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/power/clang_workaround.h -@@ -0,0 +1,87 @@ -+#ifndef CLANG_WORKAROUNDS_H -+#define CLANG_WORKAROUNDS_H -+ -+/* -+ * These stubs fix clang incompatibilities with GCC builtins. -+ */ -+ -+#ifndef __builtin_crypto_vpmsumw -+#define __builtin_crypto_vpmsumw __builtin_crypto_vpmsumb -+#endif -+#ifndef __builtin_crypto_vpmsumd -+#define __builtin_crypto_vpmsumd __builtin_crypto_vpmsumb -+#endif -+ -+static inline -+__vector unsigned long long __attribute__((overloadable)) -+vec_ld(int __a, const __vector unsigned long long* __b) -+{ -+ return (__vector unsigned long long)__builtin_altivec_lvx(__a, __b); -+} -+ -+/* -+ * GCC __builtin_pack_vector_int128 returns a vector __int128_t but Clang -+ * does not recognize this type. On GCC this builtin is translated to a -+ * xxpermdi instruction that only moves the registers __a, __b instead generates -+ * a load. -+ * -+ * Clang has vec_xxpermdi intrinsics. It was implemented in 4.0.0. -+ */ -+static inline -+__vector unsigned long long __builtin_pack_vector (unsigned long __a, -+ unsigned long __b) -+{ -+ #if defined(__BIG_ENDIAN__) -+ __vector unsigned long long __v = {__a, __b}; -+ #else -+ __vector unsigned long long __v = {__b, __a}; -+ #endif -+ return __v; -+} -+ -+/* -+ * Clang 7 changed the behavior of vec_xxpermdi in order to provide the same -+ * behavior of GCC. That means code adapted to Clang >= 7 does not work on -+ * Clang <= 6. So, fallback to __builtin_unpack_vector() on Clang <= 6. -+ */ -+#if !defined vec_xxpermdi || __clang_major__ <= 6 -+ -+static inline -+unsigned long __builtin_unpack_vector (__vector unsigned long long __v, -+ int __o) -+{ -+ return __v[__o]; -+} -+ -+#if defined(__BIG_ENDIAN__) -+#define __builtin_unpack_vector_0(a) __builtin_unpack_vector ((a), 0) -+#define __builtin_unpack_vector_1(a) __builtin_unpack_vector ((a), 1) -+#else -+#define __builtin_unpack_vector_0(a) __builtin_unpack_vector ((a), 1) -+#define __builtin_unpack_vector_1(a) __builtin_unpack_vector ((a), 0) -+#endif -+ -+#else -+ -+static inline -+unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v) -+{ -+ #if defined(__BIG_ENDIAN__) -+ return vec_xxpermdi(__v, __v, 0x0)[0]; -+ #else -+ return vec_xxpermdi(__v, __v, 0x3)[0]; -+ #endif -+} -+ -+static inline -+unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v) -+{ -+ #if defined(__BIG_ENDIAN__) -+ return vec_xxpermdi(__v, __v, 0x3)[0]; -+ #else -+ return vec_xxpermdi(__v, __v, 0x0)[0]; -+ #endif -+} -+#endif /* vec_xxpermdi */ -+ -+#endif -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/power/crc32_constants.h -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/power/crc32_constants.h -@@ -0,0 +1,1206 @@ -+/* -+* -+* THIS FILE IS GENERATED WITH -+./crc32_constants -c -r -x 0x04C11DB7 -+ -+* This is from https://github.com/antonblanchard/crc32-vpmsum/ -+* DO NOT MODIFY IT MANUALLY! -+* -+*/ -+ -+#define CRC 0x4c11db7 -+#define CRC_XOR -+#define REFLECT -+#define MAX_SIZE 32768 -+ -+#ifndef __ASSEMBLER__ -+#ifdef CRC_TABLE -+static const unsigned int crc_table[] = { -+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, -+ 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, -+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, -+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, -+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, -+ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, -+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, -+ 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, -+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, -+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, -+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, -+ 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, -+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, -+ 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, -+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, -+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, -+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, -+ 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, -+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, -+ 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, -+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, -+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, -+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, -+ 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, -+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, -+ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, -+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, -+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, -+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, -+ 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, -+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, -+ 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, -+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, -+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, -+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, -+ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, -+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, -+ 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, -+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, -+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, -+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, -+ 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, -+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, -+ 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, -+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, -+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, -+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, -+ 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, -+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, -+ 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, -+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, -+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, -+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, -+ 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, -+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, -+ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, -+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, -+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, -+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, -+ 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, -+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, -+ 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, -+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, -+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,}; -+ -+#endif /* CRC_TABLE */ -+#ifdef POWER8_INTRINSICS -+ -+/* Constants */ -+ -+/* Reduce 262144 kbits to 1024 bits */ -+static const __vector unsigned long long vcrc_const[255] -+ __attribute__((aligned (16))) = { -+#ifdef __LITTLE_ENDIAN__ -+ /* x^261120 mod p(x)` << 1, x^261184 mod p(x)` << 1 */ -+ { 0x0000000099ea94a8, 0x00000001651797d2 }, -+ /* x^260096 mod p(x)` << 1, x^260160 mod p(x)` << 1 */ -+ { 0x00000000945a8420, 0x0000000021e0d56c }, -+ /* x^259072 mod p(x)` << 1, x^259136 mod p(x)` << 1 */ -+ { 0x0000000030762706, 0x000000000f95ecaa }, -+ /* x^258048 mod p(x)` << 1, x^258112 mod p(x)` << 1 */ -+ { 0x00000001a52fc582, 0x00000001ebd224ac }, -+ /* x^257024 mod p(x)` << 1, x^257088 mod p(x)` << 1 */ -+ { 0x00000001a4a7167a, 0x000000000ccb97ca }, -+ /* x^256000 mod p(x)` << 1, x^256064 mod p(x)` << 1 */ -+ { 0x000000000c18249a, 0x00000001006ec8a8 }, -+ /* x^254976 mod p(x)` << 1, x^255040 mod p(x)` << 1 */ -+ { 0x00000000a924ae7c, 0x000000014f58f196 }, -+ /* x^253952 mod p(x)` << 1, x^254016 mod p(x)` << 1 */ -+ { 0x00000001e12ccc12, 0x00000001a7192ca6 }, -+ /* x^252928 mod p(x)` << 1, x^252992 mod p(x)` << 1 */ -+ { 0x00000000a0b9d4ac, 0x000000019a64bab2 }, -+ /* x^251904 mod p(x)` << 1, x^251968 mod p(x)` << 1 */ -+ { 0x0000000095e8ddfe, 0x0000000014f4ed2e }, -+ /* x^250880 mod p(x)` << 1, x^250944 mod p(x)` << 1 */ -+ { 0x00000000233fddc4, 0x000000011092b6a2 }, -+ /* x^249856 mod p(x)` << 1, x^249920 mod p(x)` << 1 */ -+ { 0x00000001b4529b62, 0x00000000c8a1629c }, -+ /* x^248832 mod p(x)` << 1, x^248896 mod p(x)` << 1 */ -+ { 0x00000001a7fa0e64, 0x000000017bf32e8e }, -+ /* x^247808 mod p(x)` << 1, x^247872 mod p(x)` << 1 */ -+ { 0x00000001b5334592, 0x00000001f8cc6582 }, -+ /* x^246784 mod p(x)` << 1, x^246848 mod p(x)` << 1 */ -+ { 0x000000011f8ee1b4, 0x000000008631ddf0 }, -+ /* x^245760 mod p(x)` << 1, x^245824 mod p(x)` << 1 */ -+ { 0x000000006252e632, 0x000000007e5a76d0 }, -+ /* x^244736 mod p(x)` << 1, x^244800 mod p(x)` << 1 */ -+ { 0x00000000ab973e84, 0x000000002b09b31c }, -+ /* x^243712 mod p(x)` << 1, x^243776 mod p(x)` << 1 */ -+ { 0x000000007734f5ec, 0x00000001b2df1f84 }, -+ /* x^242688 mod p(x)` << 1, x^242752 mod p(x)` << 1 */ -+ { 0x000000007c547798, 0x00000001d6f56afc }, -+ /* x^241664 mod p(x)` << 1, x^241728 mod p(x)` << 1 */ -+ { 0x000000007ec40210, 0x00000001b9b5e70c }, -+ /* x^240640 mod p(x)` << 1, x^240704 mod p(x)` << 1 */ -+ { 0x00000001ab1695a8, 0x0000000034b626d2 }, -+ /* x^239616 mod p(x)` << 1, x^239680 mod p(x)` << 1 */ -+ { 0x0000000090494bba, 0x000000014c53479a }, -+ /* x^238592 mod p(x)` << 1, x^238656 mod p(x)` << 1 */ -+ { 0x00000001123fb816, 0x00000001a6d179a4 }, -+ /* x^237568 mod p(x)` << 1, x^237632 mod p(x)` << 1 */ -+ { 0x00000001e188c74c, 0x000000015abd16b4 }, -+ /* x^236544 mod p(x)` << 1, x^236608 mod p(x)` << 1 */ -+ { 0x00000001c2d3451c, 0x00000000018f9852 }, -+ /* x^235520 mod p(x)` << 1, x^235584 mod p(x)` << 1 */ -+ { 0x00000000f55cf1ca, 0x000000001fb3084a }, -+ /* x^234496 mod p(x)` << 1, x^234560 mod p(x)` << 1 */ -+ { 0x00000001a0531540, 0x00000000c53dfb04 }, -+ /* x^233472 mod p(x)` << 1, x^233536 mod p(x)` << 1 */ -+ { 0x0000000132cd7ebc, 0x00000000e10c9ad6 }, -+ /* x^232448 mod p(x)` << 1, x^232512 mod p(x)` << 1 */ -+ { 0x0000000073ab7f36, 0x0000000025aa994a }, -+ /* x^231424 mod p(x)` << 1, x^231488 mod p(x)` << 1 */ -+ { 0x0000000041aed1c2, 0x00000000fa3a74c4 }, -+ /* x^230400 mod p(x)` << 1, x^230464 mod p(x)` << 1 */ -+ { 0x0000000136c53800, 0x0000000033eb3f40 }, -+ /* x^229376 mod p(x)` << 1, x^229440 mod p(x)` << 1 */ -+ { 0x0000000126835a30, 0x000000017193f296 }, -+ /* x^228352 mod p(x)` << 1, x^228416 mod p(x)` << 1 */ -+ { 0x000000006241b502, 0x0000000043f6c86a }, -+ /* x^227328 mod p(x)` << 1, x^227392 mod p(x)` << 1 */ -+ { 0x00000000d5196ad4, 0x000000016b513ec6 }, -+ /* x^226304 mod p(x)` << 1, x^226368 mod p(x)` << 1 */ -+ { 0x000000009cfa769a, 0x00000000c8f25b4e }, -+ /* x^225280 mod p(x)` << 1, x^225344 mod p(x)` << 1 */ -+ { 0x00000000920e5df4, 0x00000001a45048ec }, -+ /* x^224256 mod p(x)` << 1, x^224320 mod p(x)` << 1 */ -+ { 0x0000000169dc310e, 0x000000000c441004 }, -+ /* x^223232 mod p(x)` << 1, x^223296 mod p(x)` << 1 */ -+ { 0x0000000009fc331c, 0x000000000e17cad6 }, -+ /* x^222208 mod p(x)` << 1, x^222272 mod p(x)` << 1 */ -+ { 0x000000010d94a81e, 0x00000001253ae964 }, -+ /* x^221184 mod p(x)` << 1, x^221248 mod p(x)` << 1 */ -+ { 0x0000000027a20ab2, 0x00000001d7c88ebc }, -+ /* x^220160 mod p(x)` << 1, x^220224 mod p(x)` << 1 */ -+ { 0x0000000114f87504, 0x00000001e7ca913a }, -+ /* x^219136 mod p(x)` << 1, x^219200 mod p(x)` << 1 */ -+ { 0x000000004b076d96, 0x0000000033ed078a }, -+ /* x^218112 mod p(x)` << 1, x^218176 mod p(x)` << 1 */ -+ { 0x00000000da4d1e74, 0x00000000e1839c78 }, -+ /* x^217088 mod p(x)` << 1, x^217152 mod p(x)` << 1 */ -+ { 0x000000001b81f672, 0x00000001322b267e }, -+ /* x^216064 mod p(x)` << 1, x^216128 mod p(x)` << 1 */ -+ { 0x000000009367c988, 0x00000000638231b6 }, -+ /* x^215040 mod p(x)` << 1, x^215104 mod p(x)` << 1 */ -+ { 0x00000001717214ca, 0x00000001ee7f16f4 }, -+ /* x^214016 mod p(x)` << 1, x^214080 mod p(x)` << 1 */ -+ { 0x000000009f47d820, 0x0000000117d9924a }, -+ /* x^212992 mod p(x)` << 1, x^213056 mod p(x)` << 1 */ -+ { 0x000000010d9a47d2, 0x00000000e1a9e0c4 }, -+ /* x^211968 mod p(x)` << 1, x^212032 mod p(x)` << 1 */ -+ { 0x00000000a696c58c, 0x00000001403731dc }, -+ /* x^210944 mod p(x)` << 1, x^211008 mod p(x)` << 1 */ -+ { 0x000000002aa28ec6, 0x00000001a5ea9682 }, -+ /* x^209920 mod p(x)` << 1, x^209984 mod p(x)` << 1 */ -+ { 0x00000001fe18fd9a, 0x0000000101c5c578 }, -+ /* x^208896 mod p(x)` << 1, x^208960 mod p(x)` << 1 */ -+ { 0x000000019d4fc1ae, 0x00000000dddf6494 }, -+ /* x^207872 mod p(x)` << 1, x^207936 mod p(x)` << 1 */ -+ { 0x00000001ba0e3dea, 0x00000000f1c3db28 }, -+ /* x^206848 mod p(x)` << 1, x^206912 mod p(x)` << 1 */ -+ { 0x0000000074b59a5e, 0x000000013112fb9c }, -+ /* x^205824 mod p(x)` << 1, x^205888 mod p(x)` << 1 */ -+ { 0x00000000f2b5ea98, 0x00000000b680b906 }, -+ /* x^204800 mod p(x)` << 1, x^204864 mod p(x)` << 1 */ -+ { 0x0000000187132676, 0x000000001a282932 }, -+ /* x^203776 mod p(x)` << 1, x^203840 mod p(x)` << 1 */ -+ { 0x000000010a8c6ad4, 0x0000000089406e7e }, -+ /* x^202752 mod p(x)` << 1, x^202816 mod p(x)` << 1 */ -+ { 0x00000001e21dfe70, 0x00000001def6be8c }, -+ /* x^201728 mod p(x)` << 1, x^201792 mod p(x)` << 1 */ -+ { 0x00000001da0050e4, 0x0000000075258728 }, -+ /* x^200704 mod p(x)` << 1, x^200768 mod p(x)` << 1 */ -+ { 0x00000000772172ae, 0x000000019536090a }, -+ /* x^199680 mod p(x)` << 1, x^199744 mod p(x)` << 1 */ -+ { 0x00000000e47724aa, 0x00000000f2455bfc }, -+ /* x^198656 mod p(x)` << 1, x^198720 mod p(x)` << 1 */ -+ { 0x000000003cd63ac4, 0x000000018c40baf4 }, -+ /* x^197632 mod p(x)` << 1, x^197696 mod p(x)` << 1 */ -+ { 0x00000001bf47d352, 0x000000004cd390d4 }, -+ /* x^196608 mod p(x)` << 1, x^196672 mod p(x)` << 1 */ -+ { 0x000000018dc1d708, 0x00000001e4ece95a }, -+ /* x^195584 mod p(x)` << 1, x^195648 mod p(x)` << 1 */ -+ { 0x000000002d4620a4, 0x000000001a3ee918 }, -+ /* x^194560 mod p(x)` << 1, x^194624 mod p(x)` << 1 */ -+ { 0x0000000058fd1740, 0x000000007c652fb8 }, -+ /* x^193536 mod p(x)` << 1, x^193600 mod p(x)` << 1 */ -+ { 0x00000000dadd9bfc, 0x000000011c67842c }, -+ /* x^192512 mod p(x)` << 1, x^192576 mod p(x)` << 1 */ -+ { 0x00000001ea2140be, 0x00000000254f759c }, -+ /* x^191488 mod p(x)` << 1, x^191552 mod p(x)` << 1 */ -+ { 0x000000009de128ba, 0x000000007ece94ca }, -+ /* x^190464 mod p(x)` << 1, x^190528 mod p(x)` << 1 */ -+ { 0x000000013ac3aa8e, 0x0000000038f258c2 }, -+ /* x^189440 mod p(x)` << 1, x^189504 mod p(x)` << 1 */ -+ { 0x0000000099980562, 0x00000001cdf17b00 }, -+ /* x^188416 mod p(x)` << 1, x^188480 mod p(x)` << 1 */ -+ { 0x00000001c1579c86, 0x000000011f882c16 }, -+ /* x^187392 mod p(x)` << 1, x^187456 mod p(x)` << 1 */ -+ { 0x0000000068dbbf94, 0x0000000100093fc8 }, -+ /* x^186368 mod p(x)` << 1, x^186432 mod p(x)` << 1 */ -+ { 0x000000004509fb04, 0x00000001cd684f16 }, -+ /* x^185344 mod p(x)` << 1, x^185408 mod p(x)` << 1 */ -+ { 0x00000001202f6398, 0x000000004bc6a70a }, -+ /* x^184320 mod p(x)` << 1, x^184384 mod p(x)` << 1 */ -+ { 0x000000013aea243e, 0x000000004fc7e8e4 }, -+ /* x^183296 mod p(x)` << 1, x^183360 mod p(x)` << 1 */ -+ { 0x00000001b4052ae6, 0x0000000130103f1c }, -+ /* x^182272 mod p(x)` << 1, x^182336 mod p(x)` << 1 */ -+ { 0x00000001cd2a0ae8, 0x0000000111b0024c }, -+ /* x^181248 mod p(x)` << 1, x^181312 mod p(x)` << 1 */ -+ { 0x00000001fe4aa8b4, 0x000000010b3079da }, -+ /* x^180224 mod p(x)` << 1, x^180288 mod p(x)` << 1 */ -+ { 0x00000001d1559a42, 0x000000010192bcc2 }, -+ /* x^179200 mod p(x)` << 1, x^179264 mod p(x)` << 1 */ -+ { 0x00000001f3e05ecc, 0x0000000074838d50 }, -+ /* x^178176 mod p(x)` << 1, x^178240 mod p(x)` << 1 */ -+ { 0x0000000104ddd2cc, 0x000000001b20f520 }, -+ /* x^177152 mod p(x)` << 1, x^177216 mod p(x)` << 1 */ -+ { 0x000000015393153c, 0x0000000050c3590a }, -+ /* x^176128 mod p(x)` << 1, x^176192 mod p(x)` << 1 */ -+ { 0x0000000057e942c6, 0x00000000b41cac8e }, -+ /* x^175104 mod p(x)` << 1, x^175168 mod p(x)` << 1 */ -+ { 0x000000012c633850, 0x000000000c72cc78 }, -+ /* x^174080 mod p(x)` << 1, x^174144 mod p(x)` << 1 */ -+ { 0x00000000ebcaae4c, 0x0000000030cdb032 }, -+ /* x^173056 mod p(x)` << 1, x^173120 mod p(x)` << 1 */ -+ { 0x000000013ee532a6, 0x000000013e09fc32 }, -+ /* x^172032 mod p(x)` << 1, x^172096 mod p(x)` << 1 */ -+ { 0x00000001bf0cbc7e, 0x000000001ed624d2 }, -+ /* x^171008 mod p(x)` << 1, x^171072 mod p(x)` << 1 */ -+ { 0x00000000d50b7a5a, 0x00000000781aee1a }, -+ /* x^169984 mod p(x)` << 1, x^170048 mod p(x)` << 1 */ -+ { 0x0000000002fca6e8, 0x00000001c4d8348c }, -+ /* x^168960 mod p(x)` << 1, x^169024 mod p(x)` << 1 */ -+ { 0x000000007af40044, 0x0000000057a40336 }, -+ /* x^167936 mod p(x)` << 1, x^168000 mod p(x)` << 1 */ -+ { 0x0000000016178744, 0x0000000085544940 }, -+ /* x^166912 mod p(x)` << 1, x^166976 mod p(x)` << 1 */ -+ { 0x000000014c177458, 0x000000019cd21e80 }, -+ /* x^165888 mod p(x)` << 1, x^165952 mod p(x)` << 1 */ -+ { 0x000000011b6ddf04, 0x000000013eb95bc0 }, -+ /* x^164864 mod p(x)` << 1, x^164928 mod p(x)` << 1 */ -+ { 0x00000001f3e29ccc, 0x00000001dfc9fdfc }, -+ /* x^163840 mod p(x)` << 1, x^163904 mod p(x)` << 1 */ -+ { 0x0000000135ae7562, 0x00000000cd028bc2 }, -+ /* x^162816 mod p(x)` << 1, x^162880 mod p(x)` << 1 */ -+ { 0x0000000190ef812c, 0x0000000090db8c44 }, -+ /* x^161792 mod p(x)` << 1, x^161856 mod p(x)` << 1 */ -+ { 0x0000000067a2c786, 0x000000010010a4ce }, -+ /* x^160768 mod p(x)` << 1, x^160832 mod p(x)` << 1 */ -+ { 0x0000000048b9496c, 0x00000001c8f4c72c }, -+ /* x^159744 mod p(x)` << 1, x^159808 mod p(x)` << 1 */ -+ { 0x000000015a422de6, 0x000000001c26170c }, -+ /* x^158720 mod p(x)` << 1, x^158784 mod p(x)` << 1 */ -+ { 0x00000001ef0e3640, 0x00000000e3fccf68 }, -+ /* x^157696 mod p(x)` << 1, x^157760 mod p(x)` << 1 */ -+ { 0x00000001006d2d26, 0x00000000d513ed24 }, -+ /* x^156672 mod p(x)` << 1, x^156736 mod p(x)` << 1 */ -+ { 0x00000001170d56d6, 0x00000000141beada }, -+ /* x^155648 mod p(x)` << 1, x^155712 mod p(x)` << 1 */ -+ { 0x00000000a5fb613c, 0x000000011071aea0 }, -+ /* x^154624 mod p(x)` << 1, x^154688 mod p(x)` << 1 */ -+ { 0x0000000040bbf7fc, 0x000000012e19080a }, -+ /* x^153600 mod p(x)` << 1, x^153664 mod p(x)` << 1 */ -+ { 0x000000016ac3a5b2, 0x0000000100ecf826 }, -+ /* x^152576 mod p(x)` << 1, x^152640 mod p(x)` << 1 */ -+ { 0x00000000abf16230, 0x0000000069b09412 }, -+ /* x^151552 mod p(x)` << 1, x^151616 mod p(x)` << 1 */ -+ { 0x00000001ebe23fac, 0x0000000122297bac }, -+ /* x^150528 mod p(x)` << 1, x^150592 mod p(x)` << 1 */ -+ { 0x000000008b6a0894, 0x00000000e9e4b068 }, -+ /* x^149504 mod p(x)` << 1, x^149568 mod p(x)` << 1 */ -+ { 0x00000001288ea478, 0x000000004b38651a }, -+ /* x^148480 mod p(x)` << 1, x^148544 mod p(x)` << 1 */ -+ { 0x000000016619c442, 0x00000001468360e2 }, -+ /* x^147456 mod p(x)` << 1, x^147520 mod p(x)` << 1 */ -+ { 0x0000000086230038, 0x00000000121c2408 }, -+ /* x^146432 mod p(x)` << 1, x^146496 mod p(x)` << 1 */ -+ { 0x000000017746a756, 0x00000000da7e7d08 }, -+ /* x^145408 mod p(x)` << 1, x^145472 mod p(x)` << 1 */ -+ { 0x0000000191b8f8f8, 0x00000001058d7652 }, -+ /* x^144384 mod p(x)` << 1, x^144448 mod p(x)` << 1 */ -+ { 0x000000008e167708, 0x000000014a098a90 }, -+ /* x^143360 mod p(x)` << 1, x^143424 mod p(x)` << 1 */ -+ { 0x0000000148b22d54, 0x0000000020dbe72e }, -+ /* x^142336 mod p(x)` << 1, x^142400 mod p(x)` << 1 */ -+ { 0x0000000044ba2c3c, 0x000000011e7323e8 }, -+ /* x^141312 mod p(x)` << 1, x^141376 mod p(x)` << 1 */ -+ { 0x00000000b54d2b52, 0x00000000d5d4bf94 }, -+ /* x^140288 mod p(x)` << 1, x^140352 mod p(x)` << 1 */ -+ { 0x0000000005a4fd8a, 0x0000000199d8746c }, -+ /* x^139264 mod p(x)` << 1, x^139328 mod p(x)` << 1 */ -+ { 0x0000000139f9fc46, 0x00000000ce9ca8a0 }, -+ /* x^138240 mod p(x)` << 1, x^138304 mod p(x)` << 1 */ -+ { 0x000000015a1fa824, 0x00000000136edece }, -+ /* x^137216 mod p(x)` << 1, x^137280 mod p(x)` << 1 */ -+ { 0x000000000a61ae4c, 0x000000019b92a068 }, -+ /* x^136192 mod p(x)` << 1, x^136256 mod p(x)` << 1 */ -+ { 0x0000000145e9113e, 0x0000000071d62206 }, -+ /* x^135168 mod p(x)` << 1, x^135232 mod p(x)` << 1 */ -+ { 0x000000006a348448, 0x00000000dfc50158 }, -+ /* x^134144 mod p(x)` << 1, x^134208 mod p(x)` << 1 */ -+ { 0x000000004d80a08c, 0x00000001517626bc }, -+ /* x^133120 mod p(x)` << 1, x^133184 mod p(x)` << 1 */ -+ { 0x000000014b6837a0, 0x0000000148d1e4fa }, -+ /* x^132096 mod p(x)` << 1, x^132160 mod p(x)` << 1 */ -+ { 0x000000016896a7fc, 0x0000000094d8266e }, -+ /* x^131072 mod p(x)` << 1, x^131136 mod p(x)` << 1 */ -+ { 0x000000014f187140, 0x00000000606c5e34 }, -+ /* x^130048 mod p(x)` << 1, x^130112 mod p(x)` << 1 */ -+ { 0x000000019581b9da, 0x000000019766beaa }, -+ /* x^129024 mod p(x)` << 1, x^129088 mod p(x)` << 1 */ -+ { 0x00000001091bc984, 0x00000001d80c506c }, -+ /* x^128000 mod p(x)` << 1, x^128064 mod p(x)` << 1 */ -+ { 0x000000001067223c, 0x000000001e73837c }, -+ /* x^126976 mod p(x)` << 1, x^127040 mod p(x)` << 1 */ -+ { 0x00000001ab16ea02, 0x0000000064d587de }, -+ /* x^125952 mod p(x)` << 1, x^126016 mod p(x)` << 1 */ -+ { 0x000000013c4598a8, 0x00000000f4a507b0 }, -+ /* x^124928 mod p(x)` << 1, x^124992 mod p(x)` << 1 */ -+ { 0x00000000b3735430, 0x0000000040e342fc }, -+ /* x^123904 mod p(x)` << 1, x^123968 mod p(x)` << 1 */ -+ { 0x00000001bb3fc0c0, 0x00000001d5ad9c3a }, -+ /* x^122880 mod p(x)` << 1, x^122944 mod p(x)` << 1 */ -+ { 0x00000001570ae19c, 0x0000000094a691a4 }, -+ /* x^121856 mod p(x)` << 1, x^121920 mod p(x)` << 1 */ -+ { 0x00000001ea910712, 0x00000001271ecdfa }, -+ /* x^120832 mod p(x)` << 1, x^120896 mod p(x)` << 1 */ -+ { 0x0000000167127128, 0x000000009e54475a }, -+ /* x^119808 mod p(x)` << 1, x^119872 mod p(x)` << 1 */ -+ { 0x0000000019e790a2, 0x00000000c9c099ee }, -+ /* x^118784 mod p(x)` << 1, x^118848 mod p(x)` << 1 */ -+ { 0x000000003788f710, 0x000000009a2f736c }, -+ /* x^117760 mod p(x)` << 1, x^117824 mod p(x)` << 1 */ -+ { 0x00000001682a160e, 0x00000000bb9f4996 }, -+ /* x^116736 mod p(x)` << 1, x^116800 mod p(x)` << 1 */ -+ { 0x000000007f0ebd2e, 0x00000001db688050 }, -+ /* x^115712 mod p(x)` << 1, x^115776 mod p(x)` << 1 */ -+ { 0x000000002b032080, 0x00000000e9b10af4 }, -+ /* x^114688 mod p(x)` << 1, x^114752 mod p(x)` << 1 */ -+ { 0x00000000cfd1664a, 0x000000012d4545e4 }, -+ /* x^113664 mod p(x)` << 1, x^113728 mod p(x)` << 1 */ -+ { 0x00000000aa1181c2, 0x000000000361139c }, -+ /* x^112640 mod p(x)` << 1, x^112704 mod p(x)` << 1 */ -+ { 0x00000000ddd08002, 0x00000001a5a1a3a8 }, -+ /* x^111616 mod p(x)` << 1, x^111680 mod p(x)` << 1 */ -+ { 0x00000000e8dd0446, 0x000000006844e0b0 }, -+ /* x^110592 mod p(x)` << 1, x^110656 mod p(x)` << 1 */ -+ { 0x00000001bbd94a00, 0x00000000c3762f28 }, -+ /* x^109568 mod p(x)` << 1, x^109632 mod p(x)` << 1 */ -+ { 0x00000000ab6cd180, 0x00000001d26287a2 }, -+ /* x^108544 mod p(x)` << 1, x^108608 mod p(x)` << 1 */ -+ { 0x0000000031803ce2, 0x00000001f6f0bba8 }, -+ /* x^107520 mod p(x)` << 1, x^107584 mod p(x)` << 1 */ -+ { 0x0000000024f40b0c, 0x000000002ffabd62 }, -+ /* x^106496 mod p(x)` << 1, x^106560 mod p(x)` << 1 */ -+ { 0x00000001ba1d9834, 0x00000000fb4516b8 }, -+ /* x^105472 mod p(x)` << 1, x^105536 mod p(x)` << 1 */ -+ { 0x0000000104de61aa, 0x000000018cfa961c }, -+ /* x^104448 mod p(x)` << 1, x^104512 mod p(x)` << 1 */ -+ { 0x0000000113e40d46, 0x000000019e588d52 }, -+ /* x^103424 mod p(x)` << 1, x^103488 mod p(x)` << 1 */ -+ { 0x00000001415598a0, 0x00000001180f0bbc }, -+ /* x^102400 mod p(x)` << 1, x^102464 mod p(x)` << 1 */ -+ { 0x00000000bf6c8c90, 0x00000000e1d9177a }, -+ /* x^101376 mod p(x)` << 1, x^101440 mod p(x)` << 1 */ -+ { 0x00000001788b0504, 0x0000000105abc27c }, -+ /* x^100352 mod p(x)` << 1, x^100416 mod p(x)` << 1 */ -+ { 0x0000000038385d02, 0x00000000972e4a58 }, -+ /* x^99328 mod p(x)` << 1, x^99392 mod p(x)` << 1 */ -+ { 0x00000001b6c83844, 0x0000000183499a5e }, -+ /* x^98304 mod p(x)` << 1, x^98368 mod p(x)` << 1 */ -+ { 0x0000000051061a8a, 0x00000001c96a8cca }, -+ /* x^97280 mod p(x)` << 1, x^97344 mod p(x)` << 1 */ -+ { 0x000000017351388a, 0x00000001a1a5b60c }, -+ /* x^96256 mod p(x)` << 1, x^96320 mod p(x)` << 1 */ -+ { 0x0000000132928f92, 0x00000000e4b6ac9c }, -+ /* x^95232 mod p(x)` << 1, x^95296 mod p(x)` << 1 */ -+ { 0x00000000e6b4f48a, 0x00000001807e7f5a }, -+ /* x^94208 mod p(x)` << 1, x^94272 mod p(x)` << 1 */ -+ { 0x0000000039d15e90, 0x000000017a7e3bc8 }, -+ /* x^93184 mod p(x)` << 1, x^93248 mod p(x)` << 1 */ -+ { 0x00000000312d6074, 0x00000000d73975da }, -+ /* x^92160 mod p(x)` << 1, x^92224 mod p(x)` << 1 */ -+ { 0x000000017bbb2cc4, 0x000000017375d038 }, -+ /* x^91136 mod p(x)` << 1, x^91200 mod p(x)` << 1 */ -+ { 0x000000016ded3e18, 0x00000000193680bc }, -+ /* x^90112 mod p(x)` << 1, x^90176 mod p(x)` << 1 */ -+ { 0x00000000f1638b16, 0x00000000999b06f6 }, -+ /* x^89088 mod p(x)` << 1, x^89152 mod p(x)` << 1 */ -+ { 0x00000001d38b9ecc, 0x00000001f685d2b8 }, -+ /* x^88064 mod p(x)` << 1, x^88128 mod p(x)` << 1 */ -+ { 0x000000018b8d09dc, 0x00000001f4ecbed2 }, -+ /* x^87040 mod p(x)` << 1, x^87104 mod p(x)` << 1 */ -+ { 0x00000000e7bc27d2, 0x00000000ba16f1a0 }, -+ /* x^86016 mod p(x)` << 1, x^86080 mod p(x)` << 1 */ -+ { 0x00000000275e1e96, 0x0000000115aceac4 }, -+ /* x^84992 mod p(x)` << 1, x^85056 mod p(x)` << 1 */ -+ { 0x00000000e2e3031e, 0x00000001aeff6292 }, -+ /* x^83968 mod p(x)` << 1, x^84032 mod p(x)` << 1 */ -+ { 0x00000001041c84d8, 0x000000009640124c }, -+ /* x^82944 mod p(x)` << 1, x^83008 mod p(x)` << 1 */ -+ { 0x00000000706ce672, 0x0000000114f41f02 }, -+ /* x^81920 mod p(x)` << 1, x^81984 mod p(x)` << 1 */ -+ { 0x000000015d5070da, 0x000000009c5f3586 }, -+ /* x^80896 mod p(x)` << 1, x^80960 mod p(x)` << 1 */ -+ { 0x0000000038f9493a, 0x00000001878275fa }, -+ /* x^79872 mod p(x)` << 1, x^79936 mod p(x)` << 1 */ -+ { 0x00000000a3348a76, 0x00000000ddc42ce8 }, -+ /* x^78848 mod p(x)` << 1, x^78912 mod p(x)` << 1 */ -+ { 0x00000001ad0aab92, 0x0000000181d2c73a }, -+ /* x^77824 mod p(x)` << 1, x^77888 mod p(x)` << 1 */ -+ { 0x000000019e85f712, 0x0000000141c9320a }, -+ /* x^76800 mod p(x)` << 1, x^76864 mod p(x)` << 1 */ -+ { 0x000000005a871e76, 0x000000015235719a }, -+ /* x^75776 mod p(x)` << 1, x^75840 mod p(x)` << 1 */ -+ { 0x000000017249c662, 0x00000000be27d804 }, -+ /* x^74752 mod p(x)` << 1, x^74816 mod p(x)` << 1 */ -+ { 0x000000003a084712, 0x000000006242d45a }, -+ /* x^73728 mod p(x)` << 1, x^73792 mod p(x)` << 1 */ -+ { 0x00000000ed438478, 0x000000009a53638e }, -+ /* x^72704 mod p(x)` << 1, x^72768 mod p(x)` << 1 */ -+ { 0x00000000abac34cc, 0x00000001001ecfb6 }, -+ /* x^71680 mod p(x)` << 1, x^71744 mod p(x)` << 1 */ -+ { 0x000000005f35ef3e, 0x000000016d7c2d64 }, -+ /* x^70656 mod p(x)` << 1, x^70720 mod p(x)` << 1 */ -+ { 0x0000000047d6608c, 0x00000001d0ce46c0 }, -+ /* x^69632 mod p(x)` << 1, x^69696 mod p(x)` << 1 */ -+ { 0x000000002d01470e, 0x0000000124c907b4 }, -+ /* x^68608 mod p(x)` << 1, x^68672 mod p(x)` << 1 */ -+ { 0x0000000158bbc7b0, 0x0000000018a555ca }, -+ /* x^67584 mod p(x)` << 1, x^67648 mod p(x)` << 1 */ -+ { 0x00000000c0a23e8e, 0x000000006b0980bc }, -+ /* x^66560 mod p(x)` << 1, x^66624 mod p(x)` << 1 */ -+ { 0x00000001ebd85c88, 0x000000008bbba964 }, -+ /* x^65536 mod p(x)` << 1, x^65600 mod p(x)` << 1 */ -+ { 0x000000019ee20bb2, 0x00000001070a5a1e }, -+ /* x^64512 mod p(x)` << 1, x^64576 mod p(x)` << 1 */ -+ { 0x00000001acabf2d6, 0x000000002204322a }, -+ /* x^63488 mod p(x)` << 1, x^63552 mod p(x)` << 1 */ -+ { 0x00000001b7963d56, 0x00000000a27524d0 }, -+ /* x^62464 mod p(x)` << 1, x^62528 mod p(x)` << 1 */ -+ { 0x000000017bffa1fe, 0x0000000020b1e4ba }, -+ /* x^61440 mod p(x)` << 1, x^61504 mod p(x)` << 1 */ -+ { 0x000000001f15333e, 0x0000000032cc27fc }, -+ /* x^60416 mod p(x)` << 1, x^60480 mod p(x)` << 1 */ -+ { 0x000000018593129e, 0x0000000044dd22b8 }, -+ /* x^59392 mod p(x)` << 1, x^59456 mod p(x)` << 1 */ -+ { 0x000000019cb32602, 0x00000000dffc9e0a }, -+ /* x^58368 mod p(x)` << 1, x^58432 mod p(x)` << 1 */ -+ { 0x0000000142b05cc8, 0x00000001b7a0ed14 }, -+ /* x^57344 mod p(x)` << 1, x^57408 mod p(x)` << 1 */ -+ { 0x00000001be49e7a4, 0x00000000c7842488 }, -+ /* x^56320 mod p(x)` << 1, x^56384 mod p(x)` << 1 */ -+ { 0x0000000108f69d6c, 0x00000001c02a4fee }, -+ /* x^55296 mod p(x)` << 1, x^55360 mod p(x)` << 1 */ -+ { 0x000000006c0971f0, 0x000000003c273778 }, -+ /* x^54272 mod p(x)` << 1, x^54336 mod p(x)` << 1 */ -+ { 0x000000005b16467a, 0x00000001d63f8894 }, -+ /* x^53248 mod p(x)` << 1, x^53312 mod p(x)` << 1 */ -+ { 0x00000001551a628e, 0x000000006be557d6 }, -+ /* x^52224 mod p(x)` << 1, x^52288 mod p(x)` << 1 */ -+ { 0x000000019e42ea92, 0x000000006a7806ea }, -+ /* x^51200 mod p(x)` << 1, x^51264 mod p(x)` << 1 */ -+ { 0x000000012fa83ff2, 0x000000016155aa0c }, -+ /* x^50176 mod p(x)` << 1, x^50240 mod p(x)` << 1 */ -+ { 0x000000011ca9cde0, 0x00000000908650ac }, -+ /* x^49152 mod p(x)` << 1, x^49216 mod p(x)` << 1 */ -+ { 0x00000000c8e5cd74, 0x00000000aa5a8084 }, -+ /* x^48128 mod p(x)` << 1, x^48192 mod p(x)` << 1 */ -+ { 0x0000000096c27f0c, 0x0000000191bb500a }, -+ /* x^47104 mod p(x)` << 1, x^47168 mod p(x)` << 1 */ -+ { 0x000000002baed926, 0x0000000064e9bed0 }, -+ /* x^46080 mod p(x)` << 1, x^46144 mod p(x)` << 1 */ -+ { 0x000000017c8de8d2, 0x000000009444f302 }, -+ /* x^45056 mod p(x)` << 1, x^45120 mod p(x)` << 1 */ -+ { 0x00000000d43d6068, 0x000000019db07d3c }, -+ /* x^44032 mod p(x)` << 1, x^44096 mod p(x)` << 1 */ -+ { 0x00000000cb2c4b26, 0x00000001359e3e6e }, -+ /* x^43008 mod p(x)` << 1, x^43072 mod p(x)` << 1 */ -+ { 0x0000000145b8da26, 0x00000001e4f10dd2 }, -+ /* x^41984 mod p(x)` << 1, x^42048 mod p(x)` << 1 */ -+ { 0x000000018fff4b08, 0x0000000124f5735e }, -+ /* x^40960 mod p(x)` << 1, x^41024 mod p(x)` << 1 */ -+ { 0x0000000150b58ed0, 0x0000000124760a4c }, -+ /* x^39936 mod p(x)` << 1, x^40000 mod p(x)` << 1 */ -+ { 0x00000001549f39bc, 0x000000000f1fc186 }, -+ /* x^38912 mod p(x)` << 1, x^38976 mod p(x)` << 1 */ -+ { 0x00000000ef4d2f42, 0x00000000150e4cc4 }, -+ /* x^37888 mod p(x)` << 1, x^37952 mod p(x)` << 1 */ -+ { 0x00000001b1468572, 0x000000002a6204e8 }, -+ /* x^36864 mod p(x)` << 1, x^36928 mod p(x)` << 1 */ -+ { 0x000000013d7403b2, 0x00000000beb1d432 }, -+ /* x^35840 mod p(x)` << 1, x^35904 mod p(x)` << 1 */ -+ { 0x00000001a4681842, 0x0000000135f3f1f0 }, -+ /* x^34816 mod p(x)` << 1, x^34880 mod p(x)` << 1 */ -+ { 0x0000000167714492, 0x0000000074fe2232 }, -+ /* x^33792 mod p(x)` << 1, x^33856 mod p(x)` << 1 */ -+ { 0x00000001e599099a, 0x000000001ac6e2ba }, -+ /* x^32768 mod p(x)` << 1, x^32832 mod p(x)` << 1 */ -+ { 0x00000000fe128194, 0x0000000013fca91e }, -+ /* x^31744 mod p(x)` << 1, x^31808 mod p(x)` << 1 */ -+ { 0x0000000077e8b990, 0x0000000183f4931e }, -+ /* x^30720 mod p(x)` << 1, x^30784 mod p(x)` << 1 */ -+ { 0x00000001a267f63a, 0x00000000b6d9b4e4 }, -+ /* x^29696 mod p(x)` << 1, x^29760 mod p(x)` << 1 */ -+ { 0x00000001945c245a, 0x00000000b5188656 }, -+ /* x^28672 mod p(x)` << 1, x^28736 mod p(x)` << 1 */ -+ { 0x0000000149002e76, 0x0000000027a81a84 }, -+ /* x^27648 mod p(x)` << 1, x^27712 mod p(x)` << 1 */ -+ { 0x00000001bb8310a4, 0x0000000125699258 }, -+ /* x^26624 mod p(x)` << 1, x^26688 mod p(x)` << 1 */ -+ { 0x000000019ec60bcc, 0x00000001b23de796 }, -+ /* x^25600 mod p(x)` << 1, x^25664 mod p(x)` << 1 */ -+ { 0x000000012d8590ae, 0x00000000fe4365dc }, -+ /* x^24576 mod p(x)` << 1, x^24640 mod p(x)` << 1 */ -+ { 0x0000000065b00684, 0x00000000c68f497a }, -+ /* x^23552 mod p(x)` << 1, x^23616 mod p(x)` << 1 */ -+ { 0x000000015e5aeadc, 0x00000000fbf521ee }, -+ /* x^22528 mod p(x)` << 1, x^22592 mod p(x)` << 1 */ -+ { 0x00000000b77ff2b0, 0x000000015eac3378 }, -+ /* x^21504 mod p(x)` << 1, x^21568 mod p(x)` << 1 */ -+ { 0x0000000188da2ff6, 0x0000000134914b90 }, -+ /* x^20480 mod p(x)` << 1, x^20544 mod p(x)` << 1 */ -+ { 0x0000000063da929a, 0x0000000016335cfe }, -+ /* x^19456 mod p(x)` << 1, x^19520 mod p(x)` << 1 */ -+ { 0x00000001389caa80, 0x000000010372d10c }, -+ /* x^18432 mod p(x)` << 1, x^18496 mod p(x)` << 1 */ -+ { 0x000000013db599d2, 0x000000015097b908 }, -+ /* x^17408 mod p(x)` << 1, x^17472 mod p(x)` << 1 */ -+ { 0x0000000122505a86, 0x00000001227a7572 }, -+ /* x^16384 mod p(x)` << 1, x^16448 mod p(x)` << 1 */ -+ { 0x000000016bd72746, 0x000000009a8f75c0 }, -+ /* x^15360 mod p(x)` << 1, x^15424 mod p(x)` << 1 */ -+ { 0x00000001c3faf1d4, 0x00000000682c77a2 }, -+ /* x^14336 mod p(x)` << 1, x^14400 mod p(x)` << 1 */ -+ { 0x00000001111c826c, 0x00000000231f091c }, -+ /* x^13312 mod p(x)` << 1, x^13376 mod p(x)` << 1 */ -+ { 0x00000000153e9fb2, 0x000000007d4439f2 }, -+ /* x^12288 mod p(x)` << 1, x^12352 mod p(x)` << 1 */ -+ { 0x000000002b1f7b60, 0x000000017e221efc }, -+ /* x^11264 mod p(x)` << 1, x^11328 mod p(x)` << 1 */ -+ { 0x00000000b1dba570, 0x0000000167457c38 }, -+ /* x^10240 mod p(x)` << 1, x^10304 mod p(x)` << 1 */ -+ { 0x00000001f6397b76, 0x00000000bdf081c4 }, -+ /* x^9216 mod p(x)` << 1, x^9280 mod p(x)` << 1 */ -+ { 0x0000000156335214, 0x000000016286d6b0 }, -+ /* x^8192 mod p(x)` << 1, x^8256 mod p(x)` << 1 */ -+ { 0x00000001d70e3986, 0x00000000c84f001c }, -+ /* x^7168 mod p(x)` << 1, x^7232 mod p(x)` << 1 */ -+ { 0x000000003701a774, 0x0000000064efe7c0 }, -+ /* x^6144 mod p(x)` << 1, x^6208 mod p(x)` << 1 */ -+ { 0x00000000ac81ef72, 0x000000000ac2d904 }, -+ /* x^5120 mod p(x)` << 1, x^5184 mod p(x)` << 1 */ -+ { 0x0000000133212464, 0x00000000fd226d14 }, -+ /* x^4096 mod p(x)` << 1, x^4160 mod p(x)` << 1 */ -+ { 0x00000000e4e45610, 0x000000011cfd42e0 }, -+ /* x^3072 mod p(x)` << 1, x^3136 mod p(x)` << 1 */ -+ { 0x000000000c1bd370, 0x000000016e5a5678 }, -+ /* x^2048 mod p(x)` << 1, x^2112 mod p(x)` << 1 */ -+ { 0x00000001a7b9e7a6, 0x00000001d888fe22 }, -+ /* x^1024 mod p(x)` << 1, x^1088 mod p(x)` << 1 */ -+ { 0x000000007d657a10, 0x00000001af77fcd4 } -+#else /* __LITTLE_ENDIAN__ */ -+ /* x^261120 mod p(x)` << 1, x^261184 mod p(x)` << 1 */ -+ { 0x00000001651797d2, 0x0000000099ea94a8 }, -+ /* x^260096 mod p(x)` << 1, x^260160 mod p(x)` << 1 */ -+ { 0x0000000021e0d56c, 0x00000000945a8420 }, -+ /* x^259072 mod p(x)` << 1, x^259136 mod p(x)` << 1 */ -+ { 0x000000000f95ecaa, 0x0000000030762706 }, -+ /* x^258048 mod p(x)` << 1, x^258112 mod p(x)` << 1 */ -+ { 0x00000001ebd224ac, 0x00000001a52fc582 }, -+ /* x^257024 mod p(x)` << 1, x^257088 mod p(x)` << 1 */ -+ { 0x000000000ccb97ca, 0x00000001a4a7167a }, -+ /* x^256000 mod p(x)` << 1, x^256064 mod p(x)` << 1 */ -+ { 0x00000001006ec8a8, 0x000000000c18249a }, -+ /* x^254976 mod p(x)` << 1, x^255040 mod p(x)` << 1 */ -+ { 0x000000014f58f196, 0x00000000a924ae7c }, -+ /* x^253952 mod p(x)` << 1, x^254016 mod p(x)` << 1 */ -+ { 0x00000001a7192ca6, 0x00000001e12ccc12 }, -+ /* x^252928 mod p(x)` << 1, x^252992 mod p(x)` << 1 */ -+ { 0x000000019a64bab2, 0x00000000a0b9d4ac }, -+ /* x^251904 mod p(x)` << 1, x^251968 mod p(x)` << 1 */ -+ { 0x0000000014f4ed2e, 0x0000000095e8ddfe }, -+ /* x^250880 mod p(x)` << 1, x^250944 mod p(x)` << 1 */ -+ { 0x000000011092b6a2, 0x00000000233fddc4 }, -+ /* x^249856 mod p(x)` << 1, x^249920 mod p(x)` << 1 */ -+ { 0x00000000c8a1629c, 0x00000001b4529b62 }, -+ /* x^248832 mod p(x)` << 1, x^248896 mod p(x)` << 1 */ -+ { 0x000000017bf32e8e, 0x00000001a7fa0e64 }, -+ /* x^247808 mod p(x)` << 1, x^247872 mod p(x)` << 1 */ -+ { 0x00000001f8cc6582, 0x00000001b5334592 }, -+ /* x^246784 mod p(x)` << 1, x^246848 mod p(x)` << 1 */ -+ { 0x000000008631ddf0, 0x000000011f8ee1b4 }, -+ /* x^245760 mod p(x)` << 1, x^245824 mod p(x)` << 1 */ -+ { 0x000000007e5a76d0, 0x000000006252e632 }, -+ /* x^244736 mod p(x)` << 1, x^244800 mod p(x)` << 1 */ -+ { 0x000000002b09b31c, 0x00000000ab973e84 }, -+ /* x^243712 mod p(x)` << 1, x^243776 mod p(x)` << 1 */ -+ { 0x00000001b2df1f84, 0x000000007734f5ec }, -+ /* x^242688 mod p(x)` << 1, x^242752 mod p(x)` << 1 */ -+ { 0x00000001d6f56afc, 0x000000007c547798 }, -+ /* x^241664 mod p(x)` << 1, x^241728 mod p(x)` << 1 */ -+ { 0x00000001b9b5e70c, 0x000000007ec40210 }, -+ /* x^240640 mod p(x)` << 1, x^240704 mod p(x)` << 1 */ -+ { 0x0000000034b626d2, 0x00000001ab1695a8 }, -+ /* x^239616 mod p(x)` << 1, x^239680 mod p(x)` << 1 */ -+ { 0x000000014c53479a, 0x0000000090494bba }, -+ /* x^238592 mod p(x)` << 1, x^238656 mod p(x)` << 1 */ -+ { 0x00000001a6d179a4, 0x00000001123fb816 }, -+ /* x^237568 mod p(x)` << 1, x^237632 mod p(x)` << 1 */ -+ { 0x000000015abd16b4, 0x00000001e188c74c }, -+ /* x^236544 mod p(x)` << 1, x^236608 mod p(x)` << 1 */ -+ { 0x00000000018f9852, 0x00000001c2d3451c }, -+ /* x^235520 mod p(x)` << 1, x^235584 mod p(x)` << 1 */ -+ { 0x000000001fb3084a, 0x00000000f55cf1ca }, -+ /* x^234496 mod p(x)` << 1, x^234560 mod p(x)` << 1 */ -+ { 0x00000000c53dfb04, 0x00000001a0531540 }, -+ /* x^233472 mod p(x)` << 1, x^233536 mod p(x)` << 1 */ -+ { 0x00000000e10c9ad6, 0x0000000132cd7ebc }, -+ /* x^232448 mod p(x)` << 1, x^232512 mod p(x)` << 1 */ -+ { 0x0000000025aa994a, 0x0000000073ab7f36 }, -+ /* x^231424 mod p(x)` << 1, x^231488 mod p(x)` << 1 */ -+ { 0x00000000fa3a74c4, 0x0000000041aed1c2 }, -+ /* x^230400 mod p(x)` << 1, x^230464 mod p(x)` << 1 */ -+ { 0x0000000033eb3f40, 0x0000000136c53800 }, -+ /* x^229376 mod p(x)` << 1, x^229440 mod p(x)` << 1 */ -+ { 0x000000017193f296, 0x0000000126835a30 }, -+ /* x^228352 mod p(x)` << 1, x^228416 mod p(x)` << 1 */ -+ { 0x0000000043f6c86a, 0x000000006241b502 }, -+ /* x^227328 mod p(x)` << 1, x^227392 mod p(x)` << 1 */ -+ { 0x000000016b513ec6, 0x00000000d5196ad4 }, -+ /* x^226304 mod p(x)` << 1, x^226368 mod p(x)` << 1 */ -+ { 0x00000000c8f25b4e, 0x000000009cfa769a }, -+ /* x^225280 mod p(x)` << 1, x^225344 mod p(x)` << 1 */ -+ { 0x00000001a45048ec, 0x00000000920e5df4 }, -+ /* x^224256 mod p(x)` << 1, x^224320 mod p(x)` << 1 */ -+ { 0x000000000c441004, 0x0000000169dc310e }, -+ /* x^223232 mod p(x)` << 1, x^223296 mod p(x)` << 1 */ -+ { 0x000000000e17cad6, 0x0000000009fc331c }, -+ /* x^222208 mod p(x)` << 1, x^222272 mod p(x)` << 1 */ -+ { 0x00000001253ae964, 0x000000010d94a81e }, -+ /* x^221184 mod p(x)` << 1, x^221248 mod p(x)` << 1 */ -+ { 0x00000001d7c88ebc, 0x0000000027a20ab2 }, -+ /* x^220160 mod p(x)` << 1, x^220224 mod p(x)` << 1 */ -+ { 0x00000001e7ca913a, 0x0000000114f87504 }, -+ /* x^219136 mod p(x)` << 1, x^219200 mod p(x)` << 1 */ -+ { 0x0000000033ed078a, 0x000000004b076d96 }, -+ /* x^218112 mod p(x)` << 1, x^218176 mod p(x)` << 1 */ -+ { 0x00000000e1839c78, 0x00000000da4d1e74 }, -+ /* x^217088 mod p(x)` << 1, x^217152 mod p(x)` << 1 */ -+ { 0x00000001322b267e, 0x000000001b81f672 }, -+ /* x^216064 mod p(x)` << 1, x^216128 mod p(x)` << 1 */ -+ { 0x00000000638231b6, 0x000000009367c988 }, -+ /* x^215040 mod p(x)` << 1, x^215104 mod p(x)` << 1 */ -+ { 0x00000001ee7f16f4, 0x00000001717214ca }, -+ /* x^214016 mod p(x)` << 1, x^214080 mod p(x)` << 1 */ -+ { 0x0000000117d9924a, 0x000000009f47d820 }, -+ /* x^212992 mod p(x)` << 1, x^213056 mod p(x)` << 1 */ -+ { 0x00000000e1a9e0c4, 0x000000010d9a47d2 }, -+ /* x^211968 mod p(x)` << 1, x^212032 mod p(x)` << 1 */ -+ { 0x00000001403731dc, 0x00000000a696c58c }, -+ /* x^210944 mod p(x)` << 1, x^211008 mod p(x)` << 1 */ -+ { 0x00000001a5ea9682, 0x000000002aa28ec6 }, -+ /* x^209920 mod p(x)` << 1, x^209984 mod p(x)` << 1 */ -+ { 0x0000000101c5c578, 0x00000001fe18fd9a }, -+ /* x^208896 mod p(x)` << 1, x^208960 mod p(x)` << 1 */ -+ { 0x00000000dddf6494, 0x000000019d4fc1ae }, -+ /* x^207872 mod p(x)` << 1, x^207936 mod p(x)` << 1 */ -+ { 0x00000000f1c3db28, 0x00000001ba0e3dea }, -+ /* x^206848 mod p(x)` << 1, x^206912 mod p(x)` << 1 */ -+ { 0x000000013112fb9c, 0x0000000074b59a5e }, -+ /* x^205824 mod p(x)` << 1, x^205888 mod p(x)` << 1 */ -+ { 0x00000000b680b906, 0x00000000f2b5ea98 }, -+ /* x^204800 mod p(x)` << 1, x^204864 mod p(x)` << 1 */ -+ { 0x000000001a282932, 0x0000000187132676 }, -+ /* x^203776 mod p(x)` << 1, x^203840 mod p(x)` << 1 */ -+ { 0x0000000089406e7e, 0x000000010a8c6ad4 }, -+ /* x^202752 mod p(x)` << 1, x^202816 mod p(x)` << 1 */ -+ { 0x00000001def6be8c, 0x00000001e21dfe70 }, -+ /* x^201728 mod p(x)` << 1, x^201792 mod p(x)` << 1 */ -+ { 0x0000000075258728, 0x00000001da0050e4 }, -+ /* x^200704 mod p(x)` << 1, x^200768 mod p(x)` << 1 */ -+ { 0x000000019536090a, 0x00000000772172ae }, -+ /* x^199680 mod p(x)` << 1, x^199744 mod p(x)` << 1 */ -+ { 0x00000000f2455bfc, 0x00000000e47724aa }, -+ /* x^198656 mod p(x)` << 1, x^198720 mod p(x)` << 1 */ -+ { 0x000000018c40baf4, 0x000000003cd63ac4 }, -+ /* x^197632 mod p(x)` << 1, x^197696 mod p(x)` << 1 */ -+ { 0x000000004cd390d4, 0x00000001bf47d352 }, -+ /* x^196608 mod p(x)` << 1, x^196672 mod p(x)` << 1 */ -+ { 0x00000001e4ece95a, 0x000000018dc1d708 }, -+ /* x^195584 mod p(x)` << 1, x^195648 mod p(x)` << 1 */ -+ { 0x000000001a3ee918, 0x000000002d4620a4 }, -+ /* x^194560 mod p(x)` << 1, x^194624 mod p(x)` << 1 */ -+ { 0x000000007c652fb8, 0x0000000058fd1740 }, -+ /* x^193536 mod p(x)` << 1, x^193600 mod p(x)` << 1 */ -+ { 0x000000011c67842c, 0x00000000dadd9bfc }, -+ /* x^192512 mod p(x)` << 1, x^192576 mod p(x)` << 1 */ -+ { 0x00000000254f759c, 0x00000001ea2140be }, -+ /* x^191488 mod p(x)` << 1, x^191552 mod p(x)` << 1 */ -+ { 0x000000007ece94ca, 0x000000009de128ba }, -+ /* x^190464 mod p(x)` << 1, x^190528 mod p(x)` << 1 */ -+ { 0x0000000038f258c2, 0x000000013ac3aa8e }, -+ /* x^189440 mod p(x)` << 1, x^189504 mod p(x)` << 1 */ -+ { 0x00000001cdf17b00, 0x0000000099980562 }, -+ /* x^188416 mod p(x)` << 1, x^188480 mod p(x)` << 1 */ -+ { 0x000000011f882c16, 0x00000001c1579c86 }, -+ /* x^187392 mod p(x)` << 1, x^187456 mod p(x)` << 1 */ -+ { 0x0000000100093fc8, 0x0000000068dbbf94 }, -+ /* x^186368 mod p(x)` << 1, x^186432 mod p(x)` << 1 */ -+ { 0x00000001cd684f16, 0x000000004509fb04 }, -+ /* x^185344 mod p(x)` << 1, x^185408 mod p(x)` << 1 */ -+ { 0x000000004bc6a70a, 0x00000001202f6398 }, -+ /* x^184320 mod p(x)` << 1, x^184384 mod p(x)` << 1 */ -+ { 0x000000004fc7e8e4, 0x000000013aea243e }, -+ /* x^183296 mod p(x)` << 1, x^183360 mod p(x)` << 1 */ -+ { 0x0000000130103f1c, 0x00000001b4052ae6 }, -+ /* x^182272 mod p(x)` << 1, x^182336 mod p(x)` << 1 */ -+ { 0x0000000111b0024c, 0x00000001cd2a0ae8 }, -+ /* x^181248 mod p(x)` << 1, x^181312 mod p(x)` << 1 */ -+ { 0x000000010b3079da, 0x00000001fe4aa8b4 }, -+ /* x^180224 mod p(x)` << 1, x^180288 mod p(x)` << 1 */ -+ { 0x000000010192bcc2, 0x00000001d1559a42 }, -+ /* x^179200 mod p(x)` << 1, x^179264 mod p(x)` << 1 */ -+ { 0x0000000074838d50, 0x00000001f3e05ecc }, -+ /* x^178176 mod p(x)` << 1, x^178240 mod p(x)` << 1 */ -+ { 0x000000001b20f520, 0x0000000104ddd2cc }, -+ /* x^177152 mod p(x)` << 1, x^177216 mod p(x)` << 1 */ -+ { 0x0000000050c3590a, 0x000000015393153c }, -+ /* x^176128 mod p(x)` << 1, x^176192 mod p(x)` << 1 */ -+ { 0x00000000b41cac8e, 0x0000000057e942c6 }, -+ /* x^175104 mod p(x)` << 1, x^175168 mod p(x)` << 1 */ -+ { 0x000000000c72cc78, 0x000000012c633850 }, -+ /* x^174080 mod p(x)` << 1, x^174144 mod p(x)` << 1 */ -+ { 0x0000000030cdb032, 0x00000000ebcaae4c }, -+ /* x^173056 mod p(x)` << 1, x^173120 mod p(x)` << 1 */ -+ { 0x000000013e09fc32, 0x000000013ee532a6 }, -+ /* x^172032 mod p(x)` << 1, x^172096 mod p(x)` << 1 */ -+ { 0x000000001ed624d2, 0x00000001bf0cbc7e }, -+ /* x^171008 mod p(x)` << 1, x^171072 mod p(x)` << 1 */ -+ { 0x00000000781aee1a, 0x00000000d50b7a5a }, -+ /* x^169984 mod p(x)` << 1, x^170048 mod p(x)` << 1 */ -+ { 0x00000001c4d8348c, 0x0000000002fca6e8 }, -+ /* x^168960 mod p(x)` << 1, x^169024 mod p(x)` << 1 */ -+ { 0x0000000057a40336, 0x000000007af40044 }, -+ /* x^167936 mod p(x)` << 1, x^168000 mod p(x)` << 1 */ -+ { 0x0000000085544940, 0x0000000016178744 }, -+ /* x^166912 mod p(x)` << 1, x^166976 mod p(x)` << 1 */ -+ { 0x000000019cd21e80, 0x000000014c177458 }, -+ /* x^165888 mod p(x)` << 1, x^165952 mod p(x)` << 1 */ -+ { 0x000000013eb95bc0, 0x000000011b6ddf04 }, -+ /* x^164864 mod p(x)` << 1, x^164928 mod p(x)` << 1 */ -+ { 0x00000001dfc9fdfc, 0x00000001f3e29ccc }, -+ /* x^163840 mod p(x)` << 1, x^163904 mod p(x)` << 1 */ -+ { 0x00000000cd028bc2, 0x0000000135ae7562 }, -+ /* x^162816 mod p(x)` << 1, x^162880 mod p(x)` << 1 */ -+ { 0x0000000090db8c44, 0x0000000190ef812c }, -+ /* x^161792 mod p(x)` << 1, x^161856 mod p(x)` << 1 */ -+ { 0x000000010010a4ce, 0x0000000067a2c786 }, -+ /* x^160768 mod p(x)` << 1, x^160832 mod p(x)` << 1 */ -+ { 0x00000001c8f4c72c, 0x0000000048b9496c }, -+ /* x^159744 mod p(x)` << 1, x^159808 mod p(x)` << 1 */ -+ { 0x000000001c26170c, 0x000000015a422de6 }, -+ /* x^158720 mod p(x)` << 1, x^158784 mod p(x)` << 1 */ -+ { 0x00000000e3fccf68, 0x00000001ef0e3640 }, -+ /* x^157696 mod p(x)` << 1, x^157760 mod p(x)` << 1 */ -+ { 0x00000000d513ed24, 0x00000001006d2d26 }, -+ /* x^156672 mod p(x)` << 1, x^156736 mod p(x)` << 1 */ -+ { 0x00000000141beada, 0x00000001170d56d6 }, -+ /* x^155648 mod p(x)` << 1, x^155712 mod p(x)` << 1 */ -+ { 0x000000011071aea0, 0x00000000a5fb613c }, -+ /* x^154624 mod p(x)` << 1, x^154688 mod p(x)` << 1 */ -+ { 0x000000012e19080a, 0x0000000040bbf7fc }, -+ /* x^153600 mod p(x)` << 1, x^153664 mod p(x)` << 1 */ -+ { 0x0000000100ecf826, 0x000000016ac3a5b2 }, -+ /* x^152576 mod p(x)` << 1, x^152640 mod p(x)` << 1 */ -+ { 0x0000000069b09412, 0x00000000abf16230 }, -+ /* x^151552 mod p(x)` << 1, x^151616 mod p(x)` << 1 */ -+ { 0x0000000122297bac, 0x00000001ebe23fac }, -+ /* x^150528 mod p(x)` << 1, x^150592 mod p(x)` << 1 */ -+ { 0x00000000e9e4b068, 0x000000008b6a0894 }, -+ /* x^149504 mod p(x)` << 1, x^149568 mod p(x)` << 1 */ -+ { 0x000000004b38651a, 0x00000001288ea478 }, -+ /* x^148480 mod p(x)` << 1, x^148544 mod p(x)` << 1 */ -+ { 0x00000001468360e2, 0x000000016619c442 }, -+ /* x^147456 mod p(x)` << 1, x^147520 mod p(x)` << 1 */ -+ { 0x00000000121c2408, 0x0000000086230038 }, -+ /* x^146432 mod p(x)` << 1, x^146496 mod p(x)` << 1 */ -+ { 0x00000000da7e7d08, 0x000000017746a756 }, -+ /* x^145408 mod p(x)` << 1, x^145472 mod p(x)` << 1 */ -+ { 0x00000001058d7652, 0x0000000191b8f8f8 }, -+ /* x^144384 mod p(x)` << 1, x^144448 mod p(x)` << 1 */ -+ { 0x000000014a098a90, 0x000000008e167708 }, -+ /* x^143360 mod p(x)` << 1, x^143424 mod p(x)` << 1 */ -+ { 0x0000000020dbe72e, 0x0000000148b22d54 }, -+ /* x^142336 mod p(x)` << 1, x^142400 mod p(x)` << 1 */ -+ { 0x000000011e7323e8, 0x0000000044ba2c3c }, -+ /* x^141312 mod p(x)` << 1, x^141376 mod p(x)` << 1 */ -+ { 0x00000000d5d4bf94, 0x00000000b54d2b52 }, -+ /* x^140288 mod p(x)` << 1, x^140352 mod p(x)` << 1 */ -+ { 0x0000000199d8746c, 0x0000000005a4fd8a }, -+ /* x^139264 mod p(x)` << 1, x^139328 mod p(x)` << 1 */ -+ { 0x00000000ce9ca8a0, 0x0000000139f9fc46 }, -+ /* x^138240 mod p(x)` << 1, x^138304 mod p(x)` << 1 */ -+ { 0x00000000136edece, 0x000000015a1fa824 }, -+ /* x^137216 mod p(x)` << 1, x^137280 mod p(x)` << 1 */ -+ { 0x000000019b92a068, 0x000000000a61ae4c }, -+ /* x^136192 mod p(x)` << 1, x^136256 mod p(x)` << 1 */ -+ { 0x0000000071d62206, 0x0000000145e9113e }, -+ /* x^135168 mod p(x)` << 1, x^135232 mod p(x)` << 1 */ -+ { 0x00000000dfc50158, 0x000000006a348448 }, -+ /* x^134144 mod p(x)` << 1, x^134208 mod p(x)` << 1 */ -+ { 0x00000001517626bc, 0x000000004d80a08c }, -+ /* x^133120 mod p(x)` << 1, x^133184 mod p(x)` << 1 */ -+ { 0x0000000148d1e4fa, 0x000000014b6837a0 }, -+ /* x^132096 mod p(x)` << 1, x^132160 mod p(x)` << 1 */ -+ { 0x0000000094d8266e, 0x000000016896a7fc }, -+ /* x^131072 mod p(x)` << 1, x^131136 mod p(x)` << 1 */ -+ { 0x00000000606c5e34, 0x000000014f187140 }, -+ /* x^130048 mod p(x)` << 1, x^130112 mod p(x)` << 1 */ -+ { 0x000000019766beaa, 0x000000019581b9da }, -+ /* x^129024 mod p(x)` << 1, x^129088 mod p(x)` << 1 */ -+ { 0x00000001d80c506c, 0x00000001091bc984 }, -+ /* x^128000 mod p(x)` << 1, x^128064 mod p(x)` << 1 */ -+ { 0x000000001e73837c, 0x000000001067223c }, -+ /* x^126976 mod p(x)` << 1, x^127040 mod p(x)` << 1 */ -+ { 0x0000000064d587de, 0x00000001ab16ea02 }, -+ /* x^125952 mod p(x)` << 1, x^126016 mod p(x)` << 1 */ -+ { 0x00000000f4a507b0, 0x000000013c4598a8 }, -+ /* x^124928 mod p(x)` << 1, x^124992 mod p(x)` << 1 */ -+ { 0x0000000040e342fc, 0x00000000b3735430 }, -+ /* x^123904 mod p(x)` << 1, x^123968 mod p(x)` << 1 */ -+ { 0x00000001d5ad9c3a, 0x00000001bb3fc0c0 }, -+ /* x^122880 mod p(x)` << 1, x^122944 mod p(x)` << 1 */ -+ { 0x0000000094a691a4, 0x00000001570ae19c }, -+ /* x^121856 mod p(x)` << 1, x^121920 mod p(x)` << 1 */ -+ { 0x00000001271ecdfa, 0x00000001ea910712 }, -+ /* x^120832 mod p(x)` << 1, x^120896 mod p(x)` << 1 */ -+ { 0x000000009e54475a, 0x0000000167127128 }, -+ /* x^119808 mod p(x)` << 1, x^119872 mod p(x)` << 1 */ -+ { 0x00000000c9c099ee, 0x0000000019e790a2 }, -+ /* x^118784 mod p(x)` << 1, x^118848 mod p(x)` << 1 */ -+ { 0x000000009a2f736c, 0x000000003788f710 }, -+ /* x^117760 mod p(x)` << 1, x^117824 mod p(x)` << 1 */ -+ { 0x00000000bb9f4996, 0x00000001682a160e }, -+ /* x^116736 mod p(x)` << 1, x^116800 mod p(x)` << 1 */ -+ { 0x00000001db688050, 0x000000007f0ebd2e }, -+ /* x^115712 mod p(x)` << 1, x^115776 mod p(x)` << 1 */ -+ { 0x00000000e9b10af4, 0x000000002b032080 }, -+ /* x^114688 mod p(x)` << 1, x^114752 mod p(x)` << 1 */ -+ { 0x000000012d4545e4, 0x00000000cfd1664a }, -+ /* x^113664 mod p(x)` << 1, x^113728 mod p(x)` << 1 */ -+ { 0x000000000361139c, 0x00000000aa1181c2 }, -+ /* x^112640 mod p(x)` << 1, x^112704 mod p(x)` << 1 */ -+ { 0x00000001a5a1a3a8, 0x00000000ddd08002 }, -+ /* x^111616 mod p(x)` << 1, x^111680 mod p(x)` << 1 */ -+ { 0x000000006844e0b0, 0x00000000e8dd0446 }, -+ /* x^110592 mod p(x)` << 1, x^110656 mod p(x)` << 1 */ -+ { 0x00000000c3762f28, 0x00000001bbd94a00 }, -+ /* x^109568 mod p(x)` << 1, x^109632 mod p(x)` << 1 */ -+ { 0x00000001d26287a2, 0x00000000ab6cd180 }, -+ /* x^108544 mod p(x)` << 1, x^108608 mod p(x)` << 1 */ -+ { 0x00000001f6f0bba8, 0x0000000031803ce2 }, -+ /* x^107520 mod p(x)` << 1, x^107584 mod p(x)` << 1 */ -+ { 0x000000002ffabd62, 0x0000000024f40b0c }, -+ /* x^106496 mod p(x)` << 1, x^106560 mod p(x)` << 1 */ -+ { 0x00000000fb4516b8, 0x00000001ba1d9834 }, -+ /* x^105472 mod p(x)` << 1, x^105536 mod p(x)` << 1 */ -+ { 0x000000018cfa961c, 0x0000000104de61aa }, -+ /* x^104448 mod p(x)` << 1, x^104512 mod p(x)` << 1 */ -+ { 0x000000019e588d52, 0x0000000113e40d46 }, -+ /* x^103424 mod p(x)` << 1, x^103488 mod p(x)` << 1 */ -+ { 0x00000001180f0bbc, 0x00000001415598a0 }, -+ /* x^102400 mod p(x)` << 1, x^102464 mod p(x)` << 1 */ -+ { 0x00000000e1d9177a, 0x00000000bf6c8c90 }, -+ /* x^101376 mod p(x)` << 1, x^101440 mod p(x)` << 1 */ -+ { 0x0000000105abc27c, 0x00000001788b0504 }, -+ /* x^100352 mod p(x)` << 1, x^100416 mod p(x)` << 1 */ -+ { 0x00000000972e4a58, 0x0000000038385d02 }, -+ /* x^99328 mod p(x)` << 1, x^99392 mod p(x)` << 1 */ -+ { 0x0000000183499a5e, 0x00000001b6c83844 }, -+ /* x^98304 mod p(x)` << 1, x^98368 mod p(x)` << 1 */ -+ { 0x00000001c96a8cca, 0x0000000051061a8a }, -+ /* x^97280 mod p(x)` << 1, x^97344 mod p(x)` << 1 */ -+ { 0x00000001a1a5b60c, 0x000000017351388a }, -+ /* x^96256 mod p(x)` << 1, x^96320 mod p(x)` << 1 */ -+ { 0x00000000e4b6ac9c, 0x0000000132928f92 }, -+ /* x^95232 mod p(x)` << 1, x^95296 mod p(x)` << 1 */ -+ { 0x00000001807e7f5a, 0x00000000e6b4f48a }, -+ /* x^94208 mod p(x)` << 1, x^94272 mod p(x)` << 1 */ -+ { 0x000000017a7e3bc8, 0x0000000039d15e90 }, -+ /* x^93184 mod p(x)` << 1, x^93248 mod p(x)` << 1 */ -+ { 0x00000000d73975da, 0x00000000312d6074 }, -+ /* x^92160 mod p(x)` << 1, x^92224 mod p(x)` << 1 */ -+ { 0x000000017375d038, 0x000000017bbb2cc4 }, -+ /* x^91136 mod p(x)` << 1, x^91200 mod p(x)` << 1 */ -+ { 0x00000000193680bc, 0x000000016ded3e18 }, -+ /* x^90112 mod p(x)` << 1, x^90176 mod p(x)` << 1 */ -+ { 0x00000000999b06f6, 0x00000000f1638b16 }, -+ /* x^89088 mod p(x)` << 1, x^89152 mod p(x)` << 1 */ -+ { 0x00000001f685d2b8, 0x00000001d38b9ecc }, -+ /* x^88064 mod p(x)` << 1, x^88128 mod p(x)` << 1 */ -+ { 0x00000001f4ecbed2, 0x000000018b8d09dc }, -+ /* x^87040 mod p(x)` << 1, x^87104 mod p(x)` << 1 */ -+ { 0x00000000ba16f1a0, 0x00000000e7bc27d2 }, -+ /* x^86016 mod p(x)` << 1, x^86080 mod p(x)` << 1 */ -+ { 0x0000000115aceac4, 0x00000000275e1e96 }, -+ /* x^84992 mod p(x)` << 1, x^85056 mod p(x)` << 1 */ -+ { 0x00000001aeff6292, 0x00000000e2e3031e }, -+ /* x^83968 mod p(x)` << 1, x^84032 mod p(x)` << 1 */ -+ { 0x000000009640124c, 0x00000001041c84d8 }, -+ /* x^82944 mod p(x)` << 1, x^83008 mod p(x)` << 1 */ -+ { 0x0000000114f41f02, 0x00000000706ce672 }, -+ /* x^81920 mod p(x)` << 1, x^81984 mod p(x)` << 1 */ -+ { 0x000000009c5f3586, 0x000000015d5070da }, -+ /* x^80896 mod p(x)` << 1, x^80960 mod p(x)` << 1 */ -+ { 0x00000001878275fa, 0x0000000038f9493a }, -+ /* x^79872 mod p(x)` << 1, x^79936 mod p(x)` << 1 */ -+ { 0x00000000ddc42ce8, 0x00000000a3348a76 }, -+ /* x^78848 mod p(x)` << 1, x^78912 mod p(x)` << 1 */ -+ { 0x0000000181d2c73a, 0x00000001ad0aab92 }, -+ /* x^77824 mod p(x)` << 1, x^77888 mod p(x)` << 1 */ -+ { 0x0000000141c9320a, 0x000000019e85f712 }, -+ /* x^76800 mod p(x)` << 1, x^76864 mod p(x)` << 1 */ -+ { 0x000000015235719a, 0x000000005a871e76 }, -+ /* x^75776 mod p(x)` << 1, x^75840 mod p(x)` << 1 */ -+ { 0x00000000be27d804, 0x000000017249c662 }, -+ /* x^74752 mod p(x)` << 1, x^74816 mod p(x)` << 1 */ -+ { 0x000000006242d45a, 0x000000003a084712 }, -+ /* x^73728 mod p(x)` << 1, x^73792 mod p(x)` << 1 */ -+ { 0x000000009a53638e, 0x00000000ed438478 }, -+ /* x^72704 mod p(x)` << 1, x^72768 mod p(x)` << 1 */ -+ { 0x00000001001ecfb6, 0x00000000abac34cc }, -+ /* x^71680 mod p(x)` << 1, x^71744 mod p(x)` << 1 */ -+ { 0x000000016d7c2d64, 0x000000005f35ef3e }, -+ /* x^70656 mod p(x)` << 1, x^70720 mod p(x)` << 1 */ -+ { 0x00000001d0ce46c0, 0x0000000047d6608c }, -+ /* x^69632 mod p(x)` << 1, x^69696 mod p(x)` << 1 */ -+ { 0x0000000124c907b4, 0x000000002d01470e }, -+ /* x^68608 mod p(x)` << 1, x^68672 mod p(x)` << 1 */ -+ { 0x0000000018a555ca, 0x0000000158bbc7b0 }, -+ /* x^67584 mod p(x)` << 1, x^67648 mod p(x)` << 1 */ -+ { 0x000000006b0980bc, 0x00000000c0a23e8e }, -+ /* x^66560 mod p(x)` << 1, x^66624 mod p(x)` << 1 */ -+ { 0x000000008bbba964, 0x00000001ebd85c88 }, -+ /* x^65536 mod p(x)` << 1, x^65600 mod p(x)` << 1 */ -+ { 0x00000001070a5a1e, 0x000000019ee20bb2 }, -+ /* x^64512 mod p(x)` << 1, x^64576 mod p(x)` << 1 */ -+ { 0x000000002204322a, 0x00000001acabf2d6 }, -+ /* x^63488 mod p(x)` << 1, x^63552 mod p(x)` << 1 */ -+ { 0x00000000a27524d0, 0x00000001b7963d56 }, -+ /* x^62464 mod p(x)` << 1, x^62528 mod p(x)` << 1 */ -+ { 0x0000000020b1e4ba, 0x000000017bffa1fe }, -+ /* x^61440 mod p(x)` << 1, x^61504 mod p(x)` << 1 */ -+ { 0x0000000032cc27fc, 0x000000001f15333e }, -+ /* x^60416 mod p(x)` << 1, x^60480 mod p(x)` << 1 */ -+ { 0x0000000044dd22b8, 0x000000018593129e }, -+ /* x^59392 mod p(x)` << 1, x^59456 mod p(x)` << 1 */ -+ { 0x00000000dffc9e0a, 0x000000019cb32602 }, -+ /* x^58368 mod p(x)` << 1, x^58432 mod p(x)` << 1 */ -+ { 0x00000001b7a0ed14, 0x0000000142b05cc8 }, -+ /* x^57344 mod p(x)` << 1, x^57408 mod p(x)` << 1 */ -+ { 0x00000000c7842488, 0x00000001be49e7a4 }, -+ /* x^56320 mod p(x)` << 1, x^56384 mod p(x)` << 1 */ -+ { 0x00000001c02a4fee, 0x0000000108f69d6c }, -+ /* x^55296 mod p(x)` << 1, x^55360 mod p(x)` << 1 */ -+ { 0x000000003c273778, 0x000000006c0971f0 }, -+ /* x^54272 mod p(x)` << 1, x^54336 mod p(x)` << 1 */ -+ { 0x00000001d63f8894, 0x000000005b16467a }, -+ /* x^53248 mod p(x)` << 1, x^53312 mod p(x)` << 1 */ -+ { 0x000000006be557d6, 0x00000001551a628e }, -+ /* x^52224 mod p(x)` << 1, x^52288 mod p(x)` << 1 */ -+ { 0x000000006a7806ea, 0x000000019e42ea92 }, -+ /* x^51200 mod p(x)` << 1, x^51264 mod p(x)` << 1 */ -+ { 0x000000016155aa0c, 0x000000012fa83ff2 }, -+ /* x^50176 mod p(x)` << 1, x^50240 mod p(x)` << 1 */ -+ { 0x00000000908650ac, 0x000000011ca9cde0 }, -+ /* x^49152 mod p(x)` << 1, x^49216 mod p(x)` << 1 */ -+ { 0x00000000aa5a8084, 0x00000000c8e5cd74 }, -+ /* x^48128 mod p(x)` << 1, x^48192 mod p(x)` << 1 */ -+ { 0x0000000191bb500a, 0x0000000096c27f0c }, -+ /* x^47104 mod p(x)` << 1, x^47168 mod p(x)` << 1 */ -+ { 0x0000000064e9bed0, 0x000000002baed926 }, -+ /* x^46080 mod p(x)` << 1, x^46144 mod p(x)` << 1 */ -+ { 0x000000009444f302, 0x000000017c8de8d2 }, -+ /* x^45056 mod p(x)` << 1, x^45120 mod p(x)` << 1 */ -+ { 0x000000019db07d3c, 0x00000000d43d6068 }, -+ /* x^44032 mod p(x)` << 1, x^44096 mod p(x)` << 1 */ -+ { 0x00000001359e3e6e, 0x00000000cb2c4b26 }, -+ /* x^43008 mod p(x)` << 1, x^43072 mod p(x)` << 1 */ -+ { 0x00000001e4f10dd2, 0x0000000145b8da26 }, -+ /* x^41984 mod p(x)` << 1, x^42048 mod p(x)` << 1 */ -+ { 0x0000000124f5735e, 0x000000018fff4b08 }, -+ /* x^40960 mod p(x)` << 1, x^41024 mod p(x)` << 1 */ -+ { 0x0000000124760a4c, 0x0000000150b58ed0 }, -+ /* x^39936 mod p(x)` << 1, x^40000 mod p(x)` << 1 */ -+ { 0x000000000f1fc186, 0x00000001549f39bc }, -+ /* x^38912 mod p(x)` << 1, x^38976 mod p(x)` << 1 */ -+ { 0x00000000150e4cc4, 0x00000000ef4d2f42 }, -+ /* x^37888 mod p(x)` << 1, x^37952 mod p(x)` << 1 */ -+ { 0x000000002a6204e8, 0x00000001b1468572 }, -+ /* x^36864 mod p(x)` << 1, x^36928 mod p(x)` << 1 */ -+ { 0x00000000beb1d432, 0x000000013d7403b2 }, -+ /* x^35840 mod p(x)` << 1, x^35904 mod p(x)` << 1 */ -+ { 0x0000000135f3f1f0, 0x00000001a4681842 }, -+ /* x^34816 mod p(x)` << 1, x^34880 mod p(x)` << 1 */ -+ { 0x0000000074fe2232, 0x0000000167714492 }, -+ /* x^33792 mod p(x)` << 1, x^33856 mod p(x)` << 1 */ -+ { 0x000000001ac6e2ba, 0x00000001e599099a }, -+ /* x^32768 mod p(x)` << 1, x^32832 mod p(x)` << 1 */ -+ { 0x0000000013fca91e, 0x00000000fe128194 }, -+ /* x^31744 mod p(x)` << 1, x^31808 mod p(x)` << 1 */ -+ { 0x0000000183f4931e, 0x0000000077e8b990 }, -+ /* x^30720 mod p(x)` << 1, x^30784 mod p(x)` << 1 */ -+ { 0x00000000b6d9b4e4, 0x00000001a267f63a }, -+ /* x^29696 mod p(x)` << 1, x^29760 mod p(x)` << 1 */ -+ { 0x00000000b5188656, 0x00000001945c245a }, -+ /* x^28672 mod p(x)` << 1, x^28736 mod p(x)` << 1 */ -+ { 0x0000000027a81a84, 0x0000000149002e76 }, -+ /* x^27648 mod p(x)` << 1, x^27712 mod p(x)` << 1 */ -+ { 0x0000000125699258, 0x00000001bb8310a4 }, -+ /* x^26624 mod p(x)` << 1, x^26688 mod p(x)` << 1 */ -+ { 0x00000001b23de796, 0x000000019ec60bcc }, -+ /* x^25600 mod p(x)` << 1, x^25664 mod p(x)` << 1 */ -+ { 0x00000000fe4365dc, 0x000000012d8590ae }, -+ /* x^24576 mod p(x)` << 1, x^24640 mod p(x)` << 1 */ -+ { 0x00000000c68f497a, 0x0000000065b00684 }, -+ /* x^23552 mod p(x)` << 1, x^23616 mod p(x)` << 1 */ -+ { 0x00000000fbf521ee, 0x000000015e5aeadc }, -+ /* x^22528 mod p(x)` << 1, x^22592 mod p(x)` << 1 */ -+ { 0x000000015eac3378, 0x00000000b77ff2b0 }, -+ /* x^21504 mod p(x)` << 1, x^21568 mod p(x)` << 1 */ -+ { 0x0000000134914b90, 0x0000000188da2ff6 }, -+ /* x^20480 mod p(x)` << 1, x^20544 mod p(x)` << 1 */ -+ { 0x0000000016335cfe, 0x0000000063da929a }, -+ /* x^19456 mod p(x)` << 1, x^19520 mod p(x)` << 1 */ -+ { 0x000000010372d10c, 0x00000001389caa80 }, -+ /* x^18432 mod p(x)` << 1, x^18496 mod p(x)` << 1 */ -+ { 0x000000015097b908, 0x000000013db599d2 }, -+ /* x^17408 mod p(x)` << 1, x^17472 mod p(x)` << 1 */ -+ { 0x00000001227a7572, 0x0000000122505a86 }, -+ /* x^16384 mod p(x)` << 1, x^16448 mod p(x)` << 1 */ -+ { 0x000000009a8f75c0, 0x000000016bd72746 }, -+ /* x^15360 mod p(x)` << 1, x^15424 mod p(x)` << 1 */ -+ { 0x00000000682c77a2, 0x00000001c3faf1d4 }, -+ /* x^14336 mod p(x)` << 1, x^14400 mod p(x)` << 1 */ -+ { 0x00000000231f091c, 0x00000001111c826c }, -+ /* x^13312 mod p(x)` << 1, x^13376 mod p(x)` << 1 */ -+ { 0x000000007d4439f2, 0x00000000153e9fb2 }, -+ /* x^12288 mod p(x)` << 1, x^12352 mod p(x)` << 1 */ -+ { 0x000000017e221efc, 0x000000002b1f7b60 }, -+ /* x^11264 mod p(x)` << 1, x^11328 mod p(x)` << 1 */ -+ { 0x0000000167457c38, 0x00000000b1dba570 }, -+ /* x^10240 mod p(x)` << 1, x^10304 mod p(x)` << 1 */ -+ { 0x00000000bdf081c4, 0x00000001f6397b76 }, -+ /* x^9216 mod p(x)` << 1, x^9280 mod p(x)` << 1 */ -+ { 0x000000016286d6b0, 0x0000000156335214 }, -+ /* x^8192 mod p(x)` << 1, x^8256 mod p(x)` << 1 */ -+ { 0x00000000c84f001c, 0x00000001d70e3986 }, -+ /* x^7168 mod p(x)` << 1, x^7232 mod p(x)` << 1 */ -+ { 0x0000000064efe7c0, 0x000000003701a774 }, -+ /* x^6144 mod p(x)` << 1, x^6208 mod p(x)` << 1 */ -+ { 0x000000000ac2d904, 0x00000000ac81ef72 }, -+ /* x^5120 mod p(x)` << 1, x^5184 mod p(x)` << 1 */ -+ { 0x00000000fd226d14, 0x0000000133212464 }, -+ /* x^4096 mod p(x)` << 1, x^4160 mod p(x)` << 1 */ -+ { 0x000000011cfd42e0, 0x00000000e4e45610 }, -+ /* x^3072 mod p(x)` << 1, x^3136 mod p(x)` << 1 */ -+ { 0x000000016e5a5678, 0x000000000c1bd370 }, -+ /* x^2048 mod p(x)` << 1, x^2112 mod p(x)` << 1 */ -+ { 0x00000001d888fe22, 0x00000001a7b9e7a6 }, -+ /* x^1024 mod p(x)` << 1, x^1088 mod p(x)` << 1 */ -+ { 0x00000001af77fcd4, 0x000000007d657a10 } -+#endif /* __LITTLE_ENDIAN__ */ -+ }; -+ -+/* Reduce final 1024-2048 bits to 64 bits, shifting 32 bits to include the trailing 32 bits of zeros */ -+ -+static const __vector unsigned long long vcrc_short_const[16] -+ __attribute__((aligned (16))) = { -+#ifdef __LITTLE_ENDIAN__ -+ /* x^1952 mod p(x) , x^1984 mod p(x) , x^2016 mod p(x) , x^2048 mod p(x) */ -+ { 0x99168a18ec447f11, 0xed837b2613e8221e }, -+ /* x^1824 mod p(x) , x^1856 mod p(x) , x^1888 mod p(x) , x^1920 mod p(x) */ -+ { 0xe23e954e8fd2cd3c, 0xc8acdd8147b9ce5a }, -+ /* x^1696 mod p(x) , x^1728 mod p(x) , x^1760 mod p(x) , x^1792 mod p(x) */ -+ { 0x92f8befe6b1d2b53, 0xd9ad6d87d4277e25 }, -+ /* x^1568 mod p(x) , x^1600 mod p(x) , x^1632 mod p(x) , x^1664 mod p(x) */ -+ { 0xf38a3556291ea462, 0xc10ec5e033fbca3b }, -+ /* x^1440 mod p(x) , x^1472 mod p(x) , x^1504 mod p(x) , x^1536 mod p(x) */ -+ { 0x974ac56262b6ca4b, 0xc0b55b0e82e02e2f }, -+ /* x^1312 mod p(x) , x^1344 mod p(x) , x^1376 mod p(x) , x^1408 mod p(x) */ -+ { 0x855712b3784d2a56, 0x71aa1df0e172334d }, -+ /* x^1184 mod p(x) , x^1216 mod p(x) , x^1248 mod p(x) , x^1280 mod p(x) */ -+ { 0xa5abe9f80eaee722, 0xfee3053e3969324d }, -+ /* x^1056 mod p(x) , x^1088 mod p(x) , x^1120 mod p(x) , x^1152 mod p(x) */ -+ { 0x1fa0943ddb54814c, 0xf44779b93eb2bd08 }, -+ /* x^928 mod p(x) , x^960 mod p(x) , x^992 mod p(x) , x^1024 mod p(x) */ -+ { 0xa53ff440d7bbfe6a, 0xf5449b3f00cc3374 }, -+ /* x^800 mod p(x) , x^832 mod p(x) , x^864 mod p(x) , x^896 mod p(x) */ -+ { 0xebe7e3566325605c, 0x6f8346e1d777606e }, -+ /* x^672 mod p(x) , x^704 mod p(x) , x^736 mod p(x) , x^768 mod p(x) */ -+ { 0xc65a272ce5b592b8, 0xe3ab4f2ac0b95347 }, -+ /* x^544 mod p(x) , x^576 mod p(x) , x^608 mod p(x) , x^640 mod p(x) */ -+ { 0x5705a9ca4721589f, 0xaa2215ea329ecc11 }, -+ /* x^416 mod p(x) , x^448 mod p(x) , x^480 mod p(x) , x^512 mod p(x) */ -+ { 0xe3720acb88d14467, 0x1ed8f66ed95efd26 }, -+ /* x^288 mod p(x) , x^320 mod p(x) , x^352 mod p(x) , x^384 mod p(x) */ -+ { 0xba1aca0315141c31, 0x78ed02d5a700e96a }, -+ /* x^160 mod p(x) , x^192 mod p(x) , x^224 mod p(x) , x^256 mod p(x) */ -+ { 0xad2a31b3ed627dae, 0xba8ccbe832b39da3 }, -+ /* x^32 mod p(x) , x^64 mod p(x) , x^96 mod p(x) , x^128 mod p(x) */ -+ { 0x6655004fa06a2517, 0xedb88320b1e6b092 } -+#else /* __LITTLE_ENDIAN__ */ -+ /* x^1952 mod p(x) , x^1984 mod p(x) , x^2016 mod p(x) , x^2048 mod p(x) */ -+ { 0xed837b2613e8221e, 0x99168a18ec447f11 }, -+ /* x^1824 mod p(x) , x^1856 mod p(x) , x^1888 mod p(x) , x^1920 mod p(x) */ -+ { 0xc8acdd8147b9ce5a, 0xe23e954e8fd2cd3c }, -+ /* x^1696 mod p(x) , x^1728 mod p(x) , x^1760 mod p(x) , x^1792 mod p(x) */ -+ { 0xd9ad6d87d4277e25, 0x92f8befe6b1d2b53 }, -+ /* x^1568 mod p(x) , x^1600 mod p(x) , x^1632 mod p(x) , x^1664 mod p(x) */ -+ { 0xc10ec5e033fbca3b, 0xf38a3556291ea462 }, -+ /* x^1440 mod p(x) , x^1472 mod p(x) , x^1504 mod p(x) , x^1536 mod p(x) */ -+ { 0xc0b55b0e82e02e2f, 0x974ac56262b6ca4b }, -+ /* x^1312 mod p(x) , x^1344 mod p(x) , x^1376 mod p(x) , x^1408 mod p(x) */ -+ { 0x71aa1df0e172334d, 0x855712b3784d2a56 }, -+ /* x^1184 mod p(x) , x^1216 mod p(x) , x^1248 mod p(x) , x^1280 mod p(x) */ -+ { 0xfee3053e3969324d, 0xa5abe9f80eaee722 }, -+ /* x^1056 mod p(x) , x^1088 mod p(x) , x^1120 mod p(x) , x^1152 mod p(x) */ -+ { 0xf44779b93eb2bd08, 0x1fa0943ddb54814c }, -+ /* x^928 mod p(x) , x^960 mod p(x) , x^992 mod p(x) , x^1024 mod p(x) */ -+ { 0xf5449b3f00cc3374, 0xa53ff440d7bbfe6a }, -+ /* x^800 mod p(x) , x^832 mod p(x) , x^864 mod p(x) , x^896 mod p(x) */ -+ { 0x6f8346e1d777606e, 0xebe7e3566325605c }, -+ /* x^672 mod p(x) , x^704 mod p(x) , x^736 mod p(x) , x^768 mod p(x) */ -+ { 0xe3ab4f2ac0b95347, 0xc65a272ce5b592b8 }, -+ /* x^544 mod p(x) , x^576 mod p(x) , x^608 mod p(x) , x^640 mod p(x) */ -+ { 0xaa2215ea329ecc11, 0x5705a9ca4721589f }, -+ /* x^416 mod p(x) , x^448 mod p(x) , x^480 mod p(x) , x^512 mod p(x) */ -+ { 0x1ed8f66ed95efd26, 0xe3720acb88d14467 }, -+ /* x^288 mod p(x) , x^320 mod p(x) , x^352 mod p(x) , x^384 mod p(x) */ -+ { 0x78ed02d5a700e96a, 0xba1aca0315141c31 }, -+ /* x^160 mod p(x) , x^192 mod p(x) , x^224 mod p(x) , x^256 mod p(x) */ -+ { 0xba8ccbe832b39da3, 0xad2a31b3ed627dae }, -+ /* x^32 mod p(x) , x^64 mod p(x) , x^96 mod p(x) , x^128 mod p(x) */ -+ { 0xedb88320b1e6b092, 0x6655004fa06a2517 } -+#endif /* __LITTLE_ENDIAN__ */ -+ }; -+ -+/* Barrett constants */ -+/* 33 bit reflected Barrett constant m - (4^32)/n */ -+ -+static const __vector unsigned long long v_Barrett_const[2] -+ __attribute__((aligned (16))) = { -+ /* x^64 div p(x) */ -+#ifdef __LITTLE_ENDIAN__ -+ { 0x00000001f7011641, 0x0000000000000000 }, -+ { 0x00000001db710641, 0x0000000000000000 } -+#else /* __LITTLE_ENDIAN__ */ -+ { 0x0000000000000000, 0x00000001f7011641 }, -+ { 0x0000000000000000, 0x00000001db710641 } -+#endif /* __LITTLE_ENDIAN__ */ -+ }; -+#endif /* POWER8_INTRINSICS */ -+ -+#endif /* __ASSEMBLER__ */ -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/power/crc32_z_power8.c -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/power/crc32_z_power8.c -@@ -0,0 +1,679 @@ -+/* -+ * Calculate the checksum of data that is 16 byte aligned and a multiple of -+ * 16 bytes. -+ * -+ * The first step is to reduce it to 1024 bits. We do this in 8 parallel -+ * chunks in order to mask the latency of the vpmsum instructions. If we -+ * have more than 32 kB of data to checksum we repeat this step multiple -+ * times, passing in the previous 1024 bits. -+ * -+ * The next step is to reduce the 1024 bits to 64 bits. This step adds -+ * 32 bits of 0s to the end - this matches what a CRC does. We just -+ * calculate constants that land the data in this 32 bits. -+ * -+ * We then use fixed point Barrett reduction to compute a mod n over GF(2) -+ * for n = CRC using POWER8 instructions. We use x = 32. -+ * -+ * http://en.wikipedia.org/wiki/Barrett_reduction -+ * -+ * This code uses gcc vector builtins instead using assembly directly. -+ * -+ * Copyright (C) 2017 Rogerio Alves , IBM -+ * -+ * This program is free software; you can redistribute it and/or -+ * modify it under the terms of either: -+ * -+ * a) the GNU General Public License as published by the Free Software -+ * Foundation; either version 2 of the License, or (at your option) -+ * any later version, or -+ * b) the Apache License, Version 2.0 -+ */ -+ -+#include -+#include "../../zutil.h" -+#include "power.h" -+ -+#define POWER8_INTRINSICS -+#define CRC_TABLE -+ -+#ifdef CRC32_CONSTANTS_HEADER -+#include CRC32_CONSTANTS_HEADER -+#else -+#include "crc32_constants.h" -+#endif -+ -+#define VMX_ALIGN 16 -+#define VMX_ALIGN_MASK (VMX_ALIGN-1) -+ -+#ifdef REFLECT -+static unsigned int crc32_align(unsigned int crc, const unsigned char *p, -+ unsigned long len) -+{ -+ while (len--) -+ crc = crc_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); -+ return crc; -+} -+#else -+static unsigned int crc32_align(unsigned int crc, const unsigned char *p, -+ unsigned long len) -+{ -+ while (len--) -+ crc = crc_table[((crc >> 24) ^ *p++) & 0xff] ^ (crc << 8); -+ return crc; -+} -+#endif -+ -+static unsigned int __attribute__ ((aligned (32))) -+__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len); -+ -+unsigned long ZLIB_INTERNAL _crc32_z_power8(uLong _crc, const Bytef *_p, -+ z_size_t _len) -+{ -+ unsigned int prealign; -+ unsigned int tail; -+ -+ /* Map zlib API to crc32_vpmsum API */ -+ unsigned int crc = (unsigned int) (0xffffffff & _crc); -+ const unsigned char *p = _p; -+ unsigned long len = (unsigned long) _len; -+ -+ if (p == (const unsigned char *) 0x0) return 0; -+#ifdef CRC_XOR -+ crc ^= 0xffffffff; -+#endif -+ -+ if (len < VMX_ALIGN + VMX_ALIGN_MASK) { -+ crc = crc32_align(crc, p, len); -+ goto out; -+ } -+ -+ if ((unsigned long)p & VMX_ALIGN_MASK) { -+ prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK); -+ crc = crc32_align(crc, p, prealign); -+ len -= prealign; -+ p += prealign; -+ } -+ -+ crc = __crc32_vpmsum(crc, p, len & ~VMX_ALIGN_MASK); -+ -+ tail = len & VMX_ALIGN_MASK; -+ if (tail) { -+ p += len & ~VMX_ALIGN_MASK; -+ crc = crc32_align(crc, p, tail); -+ } -+ -+out: -+#ifdef CRC_XOR -+ crc ^= 0xffffffff; -+#endif -+ -+ /* Convert to zlib API */ -+ return (unsigned long) crc; -+} -+ -+#if defined (__clang__) -+#include "clang_workaround.h" -+#else -+#define __builtin_pack_vector(a, b) __builtin_pack_vector_int128 ((a), (b)) -+#define __builtin_unpack_vector_0(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 0) -+#define __builtin_unpack_vector_1(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 1) -+#endif -+ -+/* When we have a load-store in a single-dispatch group and address overlap -+ * such that foward is not allowed (load-hit-store) the group must be flushed. -+ * A group ending NOP prevents the flush. -+ */ -+#define GROUP_ENDING_NOP asm("ori 2,2,0" ::: "memory") -+ -+#if defined(__BIG_ENDIAN__) && defined (REFLECT) -+#define BYTESWAP_DATA -+#elif defined(__LITTLE_ENDIAN__) && !defined(REFLECT) -+#define BYTESWAP_DATA -+#endif -+ -+#ifdef BYTESWAP_DATA -+#define VEC_PERM(vr, va, vb, vc) vr = vec_perm(va, vb,\ -+ (__vector unsigned char) vc) -+#if defined(__LITTLE_ENDIAN__) -+/* Byte reverse permute constant LE. */ -+static const __vector unsigned long long vperm_const -+ __attribute__ ((aligned(16))) = { 0x08090A0B0C0D0E0FUL, -+ 0x0001020304050607UL }; -+#else -+static const __vector unsigned long long vperm_const -+ __attribute__ ((aligned(16))) = { 0x0F0E0D0C0B0A0908UL, -+ 0X0706050403020100UL }; -+#endif -+#else -+#define VEC_PERM(vr, va, vb, vc) -+#endif -+ -+static unsigned int __attribute__ ((aligned (32))) -+__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len) { -+ -+ const __vector unsigned long long vzero = {0,0}; -+ const __vector unsigned long long vones = {0xffffffffffffffffUL, -+ 0xffffffffffffffffUL}; -+ -+#ifdef REFLECT -+ const __vector unsigned long long vmask_32bit = -+ (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, -+ (__vector unsigned char)vones, 4); -+#endif -+ -+ const __vector unsigned long long vmask_64bit = -+ (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, -+ (__vector unsigned char)vones, 8); -+ -+ __vector unsigned long long vcrc; -+ -+ __vector unsigned long long vconst1, vconst2; -+ -+ /* vdata0-vdata7 will contain our data (p). */ -+ __vector unsigned long long vdata0, vdata1, vdata2, vdata3, vdata4, -+ vdata5, vdata6, vdata7; -+ -+ /* v0-v7 will contain our checksums */ -+ __vector unsigned long long v0 = {0,0}; -+ __vector unsigned long long v1 = {0,0}; -+ __vector unsigned long long v2 = {0,0}; -+ __vector unsigned long long v3 = {0,0}; -+ __vector unsigned long long v4 = {0,0}; -+ __vector unsigned long long v5 = {0,0}; -+ __vector unsigned long long v6 = {0,0}; -+ __vector unsigned long long v7 = {0,0}; -+ -+ -+ /* Vector auxiliary variables. */ -+ __vector unsigned long long va0, va1, va2, va3, va4, va5, va6, va7; -+ -+ unsigned int result = 0; -+ unsigned int offset; /* Constant table offset. */ -+ -+ unsigned long i; /* Counter. */ -+ unsigned long chunks; -+ -+ unsigned long block_size; -+ int next_block = 0; -+ -+ /* Align by 128 bits. The last 128 bit block will be processed at end. */ -+ unsigned long length = len & 0xFFFFFFFFFFFFFF80UL; -+ -+#ifdef REFLECT -+ vcrc = (__vector unsigned long long)__builtin_pack_vector(0UL, crc); -+#else -+ vcrc = (__vector unsigned long long)__builtin_pack_vector(crc, 0UL); -+ -+ /* Shift into top 32 bits */ -+ vcrc = (__vector unsigned long long)vec_sld((__vector unsigned char)vcrc, -+ (__vector unsigned char)vzero, 4); -+#endif -+ -+ /* Short version. */ -+ if (len < 256) { -+ /* Calculate where in the constant table we need to start. */ -+ offset = 256 - len; -+ -+ vconst1 = vec_ld(offset, vcrc_short_const); -+ vdata0 = vec_ld(0, (__vector unsigned long long*) p); -+ VEC_PERM(vdata0, vdata0, vconst1, vperm_const); -+ -+ /* xor initial value*/ -+ vdata0 = vec_xor(vdata0, vcrc); -+ -+ vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw -+ ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); -+ v0 = vec_xor(v0, vdata0); -+ -+ for (i = 16; i < len; i += 16) { -+ vconst1 = vec_ld(offset + i, vcrc_short_const); -+ vdata0 = vec_ld(i, (__vector unsigned long long*) p); -+ VEC_PERM(vdata0, vdata0, vconst1, vperm_const); -+ vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw -+ ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); -+ v0 = vec_xor(v0, vdata0); -+ } -+ } else { -+ -+ /* Load initial values. */ -+ vdata0 = vec_ld(0, (__vector unsigned long long*) p); -+ vdata1 = vec_ld(16, (__vector unsigned long long*) p); -+ -+ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); -+ VEC_PERM(vdata1, vdata1, vdata1, vperm_const); -+ -+ vdata2 = vec_ld(32, (__vector unsigned long long*) p); -+ vdata3 = vec_ld(48, (__vector unsigned long long*) p); -+ -+ VEC_PERM(vdata2, vdata2, vdata2, vperm_const); -+ VEC_PERM(vdata3, vdata3, vdata3, vperm_const); -+ -+ vdata4 = vec_ld(64, (__vector unsigned long long*) p); -+ vdata5 = vec_ld(80, (__vector unsigned long long*) p); -+ -+ VEC_PERM(vdata4, vdata4, vdata4, vperm_const); -+ VEC_PERM(vdata5, vdata5, vdata5, vperm_const); -+ -+ vdata6 = vec_ld(96, (__vector unsigned long long*) p); -+ vdata7 = vec_ld(112, (__vector unsigned long long*) p); -+ -+ VEC_PERM(vdata6, vdata6, vdata6, vperm_const); -+ VEC_PERM(vdata7, vdata7, vdata7, vperm_const); -+ -+ /* xor in initial value */ -+ vdata0 = vec_xor(vdata0, vcrc); -+ -+ p = (char *)p + 128; -+ -+ do { -+ /* Checksum in blocks of MAX_SIZE. */ -+ block_size = length; -+ if (block_size > MAX_SIZE) { -+ block_size = MAX_SIZE; -+ } -+ -+ length = length - block_size; -+ -+ /* -+ * Work out the offset into the constants table to start at. Each -+ * constant is 16 bytes, and it is used against 128 bytes of input -+ * data - 128 / 16 = 8 -+ */ -+ offset = (MAX_SIZE/8) - (block_size/8); -+ /* We reduce our final 128 bytes in a separate step */ -+ chunks = (block_size/128)-1; -+ -+ vconst1 = vec_ld(offset, vcrc_const); -+ -+ va0 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata0, -+ (__vector unsigned long long)vconst1); -+ va1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata1, -+ (__vector unsigned long long)vconst1); -+ va2 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata2, -+ (__vector unsigned long long)vconst1); -+ va3 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata3, -+ (__vector unsigned long long)vconst1); -+ va4 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata4, -+ (__vector unsigned long long)vconst1); -+ va5 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata5, -+ (__vector unsigned long long)vconst1); -+ va6 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata6, -+ (__vector unsigned long long)vconst1); -+ va7 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata7, -+ (__vector unsigned long long)vconst1); -+ -+ if (chunks > 1) { -+ offset += 16; -+ vconst2 = vec_ld(offset, vcrc_const); -+ GROUP_ENDING_NOP; -+ -+ vdata0 = vec_ld(0, (__vector unsigned long long*) p); -+ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); -+ -+ vdata1 = vec_ld(16, (__vector unsigned long long*) p); -+ VEC_PERM(vdata1, vdata1, vdata1, vperm_const); -+ -+ vdata2 = vec_ld(32, (__vector unsigned long long*) p); -+ VEC_PERM(vdata2, vdata2, vdata2, vperm_const); -+ -+ vdata3 = vec_ld(48, (__vector unsigned long long*) p); -+ VEC_PERM(vdata3, vdata3, vdata3, vperm_const); -+ -+ vdata4 = vec_ld(64, (__vector unsigned long long*) p); -+ VEC_PERM(vdata4, vdata4, vdata4, vperm_const); -+ -+ vdata5 = vec_ld(80, (__vector unsigned long long*) p); -+ VEC_PERM(vdata5, vdata5, vdata5, vperm_const); -+ -+ vdata6 = vec_ld(96, (__vector unsigned long long*) p); -+ VEC_PERM(vdata6, vdata6, vdata6, vperm_const); -+ -+ vdata7 = vec_ld(112, (__vector unsigned long long*) p); -+ VEC_PERM(vdata7, vdata7, vdata7, vperm_const); -+ -+ p = (char *)p + 128; -+ -+ /* -+ * main loop. We modulo schedule it such that it takes three -+ * iterations to complete - first iteration load, second -+ * iteration vpmsum, third iteration xor. -+ */ -+ for (i = 0; i < chunks-2; i++) { -+ vconst1 = vec_ld(offset, vcrc_const); -+ offset += 16; -+ GROUP_ENDING_NOP; -+ -+ v0 = vec_xor(v0, va0); -+ va0 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata0, (__vector unsigned long long)vconst2); -+ vdata0 = vec_ld(0, (__vector unsigned long long*) p); -+ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); -+ GROUP_ENDING_NOP; -+ -+ v1 = vec_xor(v1, va1); -+ va1 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata1, (__vector unsigned long long)vconst2); -+ vdata1 = vec_ld(16, (__vector unsigned long long*) p); -+ VEC_PERM(vdata1, vdata1, vdata1, vperm_const); -+ GROUP_ENDING_NOP; -+ -+ v2 = vec_xor(v2, va2); -+ va2 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata2, (__vector unsigned long long)vconst2); -+ vdata2 = vec_ld(32, (__vector unsigned long long*) p); -+ VEC_PERM(vdata2, vdata2, vdata2, vperm_const); -+ GROUP_ENDING_NOP; -+ -+ v3 = vec_xor(v3, va3); -+ va3 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata3, (__vector unsigned long long)vconst2); -+ vdata3 = vec_ld(48, (__vector unsigned long long*) p); -+ VEC_PERM(vdata3, vdata3, vdata3, vperm_const); -+ -+ vconst2 = vec_ld(offset, vcrc_const); -+ GROUP_ENDING_NOP; -+ -+ v4 = vec_xor(v4, va4); -+ va4 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata4, (__vector unsigned long long)vconst1); -+ vdata4 = vec_ld(64, (__vector unsigned long long*) p); -+ VEC_PERM(vdata4, vdata4, vdata4, vperm_const); -+ GROUP_ENDING_NOP; -+ -+ v5 = vec_xor(v5, va5); -+ va5 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata5, (__vector unsigned long long)vconst1); -+ vdata5 = vec_ld(80, (__vector unsigned long long*) p); -+ VEC_PERM(vdata5, vdata5, vdata5, vperm_const); -+ GROUP_ENDING_NOP; -+ -+ v6 = vec_xor(v6, va6); -+ va6 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata6, (__vector unsigned long long)vconst1); -+ vdata6 = vec_ld(96, (__vector unsigned long long*) p); -+ VEC_PERM(vdata6, vdata6, vdata6, vperm_const); -+ GROUP_ENDING_NOP; -+ -+ v7 = vec_xor(v7, va7); -+ va7 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata7, (__vector unsigned long long)vconst1); -+ vdata7 = vec_ld(112, (__vector unsigned long long*) p); -+ VEC_PERM(vdata7, vdata7, vdata7, vperm_const); -+ -+ p = (char *)p + 128; -+ } -+ -+ /* First cool down*/ -+ vconst1 = vec_ld(offset, vcrc_const); -+ offset += 16; -+ -+ v0 = vec_xor(v0, va0); -+ va0 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata0, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v1 = vec_xor(v1, va1); -+ va1 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata1, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v2 = vec_xor(v2, va2); -+ va2 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata2, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v3 = vec_xor(v3, va3); -+ va3 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata3, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v4 = vec_xor(v4, va4); -+ va4 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata4, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v5 = vec_xor(v5, va5); -+ va5 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata5, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v6 = vec_xor(v6, va6); -+ va6 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata6, (__vector unsigned long long)vconst1); -+ GROUP_ENDING_NOP; -+ -+ v7 = vec_xor(v7, va7); -+ va7 = __builtin_crypto_vpmsumd ((__vector unsigned long -+ long)vdata7, (__vector unsigned long long)vconst1); -+ }/* else */ -+ -+ /* Second cool down. */ -+ v0 = vec_xor(v0, va0); -+ v1 = vec_xor(v1, va1); -+ v2 = vec_xor(v2, va2); -+ v3 = vec_xor(v3, va3); -+ v4 = vec_xor(v4, va4); -+ v5 = vec_xor(v5, va5); -+ v6 = vec_xor(v6, va6); -+ v7 = vec_xor(v7, va7); -+ -+#ifdef REFLECT -+ /* -+ * vpmsumd produces a 96 bit result in the least significant bits -+ * of the register. Since we are bit reflected we have to shift it -+ * left 32 bits so it occupies the least significant bits in the -+ * bit reflected domain. -+ */ -+ v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, -+ (__vector unsigned char)vzero, 4); -+ v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v1, -+ (__vector unsigned char)vzero, 4); -+ v2 = (__vector unsigned long long)vec_sld((__vector unsigned char)v2, -+ (__vector unsigned char)vzero, 4); -+ v3 = (__vector unsigned long long)vec_sld((__vector unsigned char)v3, -+ (__vector unsigned char)vzero, 4); -+ v4 = (__vector unsigned long long)vec_sld((__vector unsigned char)v4, -+ (__vector unsigned char)vzero, 4); -+ v5 = (__vector unsigned long long)vec_sld((__vector unsigned char)v5, -+ (__vector unsigned char)vzero, 4); -+ v6 = (__vector unsigned long long)vec_sld((__vector unsigned char)v6, -+ (__vector unsigned char)vzero, 4); -+ v7 = (__vector unsigned long long)vec_sld((__vector unsigned char)v7, -+ (__vector unsigned char)vzero, 4); -+#endif -+ -+ /* xor with the last 1024 bits. */ -+ va0 = vec_ld(0, (__vector unsigned long long*) p); -+ VEC_PERM(va0, va0, va0, vperm_const); -+ -+ va1 = vec_ld(16, (__vector unsigned long long*) p); -+ VEC_PERM(va1, va1, va1, vperm_const); -+ -+ va2 = vec_ld(32, (__vector unsigned long long*) p); -+ VEC_PERM(va2, va2, va2, vperm_const); -+ -+ va3 = vec_ld(48, (__vector unsigned long long*) p); -+ VEC_PERM(va3, va3, va3, vperm_const); -+ -+ va4 = vec_ld(64, (__vector unsigned long long*) p); -+ VEC_PERM(va4, va4, va4, vperm_const); -+ -+ va5 = vec_ld(80, (__vector unsigned long long*) p); -+ VEC_PERM(va5, va5, va5, vperm_const); -+ -+ va6 = vec_ld(96, (__vector unsigned long long*) p); -+ VEC_PERM(va6, va6, va6, vperm_const); -+ -+ va7 = vec_ld(112, (__vector unsigned long long*) p); -+ VEC_PERM(va7, va7, va7, vperm_const); -+ -+ p = (char *)p + 128; -+ -+ vdata0 = vec_xor(v0, va0); -+ vdata1 = vec_xor(v1, va1); -+ vdata2 = vec_xor(v2, va2); -+ vdata3 = vec_xor(v3, va3); -+ vdata4 = vec_xor(v4, va4); -+ vdata5 = vec_xor(v5, va5); -+ vdata6 = vec_xor(v6, va6); -+ vdata7 = vec_xor(v7, va7); -+ -+ /* Check if we have more blocks to process */ -+ next_block = 0; -+ if (length != 0) { -+ next_block = 1; -+ -+ /* zero v0-v7 */ -+ v0 = vec_xor(v0, v0); -+ v1 = vec_xor(v1, v1); -+ v2 = vec_xor(v2, v2); -+ v3 = vec_xor(v3, v3); -+ v4 = vec_xor(v4, v4); -+ v5 = vec_xor(v5, v5); -+ v6 = vec_xor(v6, v6); -+ v7 = vec_xor(v7, v7); -+ } -+ length = length + 128; -+ -+ } while (next_block); -+ -+ /* Calculate how many bytes we have left. */ -+ length = (len & 127); -+ -+ /* Calculate where in (short) constant table we need to start. */ -+ offset = 128 - length; -+ -+ v0 = vec_ld(offset, vcrc_short_const); -+ v1 = vec_ld(offset + 16, vcrc_short_const); -+ v2 = vec_ld(offset + 32, vcrc_short_const); -+ v3 = vec_ld(offset + 48, vcrc_short_const); -+ v4 = vec_ld(offset + 64, vcrc_short_const); -+ v5 = vec_ld(offset + 80, vcrc_short_const); -+ v6 = vec_ld(offset + 96, vcrc_short_const); -+ v7 = vec_ld(offset + 112, vcrc_short_const); -+ -+ offset += 128; -+ -+ v0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata0,(__vector unsigned int)v0); -+ v1 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata1,(__vector unsigned int)v1); -+ v2 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata2,(__vector unsigned int)v2); -+ v3 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata3,(__vector unsigned int)v3); -+ v4 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata4,(__vector unsigned int)v4); -+ v5 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata5,(__vector unsigned int)v5); -+ v6 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata6,(__vector unsigned int)v6); -+ v7 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata7,(__vector unsigned int)v7); -+ -+ /* Now reduce the tail (0-112 bytes). */ -+ for (i = 0; i < length; i+=16) { -+ vdata0 = vec_ld(i,(__vector unsigned long long*)p); -+ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); -+ va0 = vec_ld(offset + i,vcrc_short_const); -+ va0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( -+ (__vector unsigned int)vdata0,(__vector unsigned int)va0); -+ v0 = vec_xor(v0, va0); -+ } -+ -+ /* xor all parallel chunks together. */ -+ v0 = vec_xor(v0, v1); -+ v2 = vec_xor(v2, v3); -+ v4 = vec_xor(v4, v5); -+ v6 = vec_xor(v6, v7); -+ -+ v0 = vec_xor(v0, v2); -+ v4 = vec_xor(v4, v6); -+ -+ v0 = vec_xor(v0, v4); -+ } -+ -+ /* Barrett Reduction */ -+ vconst1 = vec_ld(0, v_Barrett_const); -+ vconst2 = vec_ld(16, v_Barrett_const); -+ -+ v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, -+ (__vector unsigned char)v0, 8); -+ v0 = vec_xor(v1,v0); -+ -+#ifdef REFLECT -+ /* shift left one bit */ -+ __vector unsigned char vsht_splat = vec_splat_u8 (1); -+ v0 = (__vector unsigned long long)vec_sll ((__vector unsigned char)v0, -+ vsht_splat); -+#endif -+ -+ v0 = vec_and(v0, vmask_64bit); -+ -+#ifndef REFLECT -+ -+ /* -+ * Now for the actual algorithm. The idea is to calculate q, -+ * the multiple of our polynomial that we need to subtract. By -+ * doing the computation 2x bits higher (ie 64 bits) and shifting the -+ * result back down 2x bits, we round down to the nearest multiple. -+ */ -+ -+ /* ma */ -+ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v0, -+ (__vector unsigned long long)vconst1); -+ /* q = floor(ma/(2^64)) */ -+ v1 = (__vector unsigned long long)vec_sld ((__vector unsigned char)vzero, -+ (__vector unsigned char)v1, 8); -+ /* qn */ -+ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, -+ (__vector unsigned long long)vconst2); -+ /* a - qn, subtraction is xor in GF(2) */ -+ v0 = vec_xor (v0, v1); -+ /* -+ * Get the result into r3. We need to shift it left 8 bytes: -+ * V0 [ 0 1 2 X ] -+ * V0 [ 0 X 2 3 ] -+ */ -+ result = __builtin_unpack_vector_1 (v0); -+#else -+ -+ /* -+ * The reflected version of Barrett reduction. Instead of bit -+ * reflecting our data (which is expensive to do), we bit reflect our -+ * constants and our algorithm, which means the intermediate data in -+ * our vector registers goes from 0-63 instead of 63-0. We can reflect -+ * the algorithm because we don't carry in mod 2 arithmetic. -+ */ -+ -+ /* bottom 32 bits of a */ -+ v1 = vec_and(v0, vmask_32bit); -+ -+ /* ma */ -+ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, -+ (__vector unsigned long long)vconst1); -+ -+ /* bottom 32bits of ma */ -+ v1 = vec_and(v1, vmask_32bit); -+ /* qn */ -+ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, -+ (__vector unsigned long long)vconst2); -+ /* a - qn, subtraction is xor in GF(2) */ -+ v0 = vec_xor (v0, v1); -+ -+ /* -+ * Since we are bit reflected, the result (ie the low 32 bits) is in -+ * the high 32 bits. We just need to shift it left 4 bytes -+ * V0 [ 0 1 X 3 ] -+ * V0 [ 0 X 2 3 ] -+ */ -+ -+ /* shift result into top 64 bits of */ -+ v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, -+ (__vector unsigned char)vzero, 4); -+ -+ result = __builtin_unpack_vector_0 (v0); -+#endif -+ -+ return result; -+} -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/power/crc32_z_resolver.c -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/power/crc32_z_resolver.c -@@ -0,0 +1,15 @@ -+/* Copyright (C) 2019 Matheus Castanho , IBM -+ * For conditions of distribution and use, see copyright notice in zlib.h -+ */ -+ -+#include "../gcc/zifunc.h" -+#include "power.h" -+ -+Z_IFUNC(crc32_z) { -+#ifdef Z_POWER8 -+ if (__builtin_cpu_supports("arch_2_07")) -+ return _crc32_z_power8; -+#endif -+ -+ return crc32_z_default; -+} -Index: zlib-1.2.13.dfsg-1ubuntu1/contrib/power/power.h -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/contrib/power/power.h -@@ -0,0 +1,8 @@ -+/* Copyright (C) 2019 Matheus Castanho , IBM -+ * 2019 Rogerio Alves , IBM -+ * For conditions of distribution and use, see copyright notice in zlib.h -+ */ -+ -+#include "../../zconf.h" -+ -+unsigned long _crc32_z_power8(unsigned long, const Bytef *, z_size_t); -Index: zlib-1.2.13.dfsg-1ubuntu1/crc32.c -=================================================================== ---- zlib-1.2.13.dfsg-1ubuntu1.orig/crc32.c -+++ zlib-1.2.13.dfsg-1ubuntu1/crc32.c -@@ -745,6 +745,13 @@ - #endif - - /* ========================================================================= */ -+#ifdef Z_POWER_OPT -+/* Rename function so resolver can use its symbol. The default version will be -+ * returned by the resolver if the host has no support for an optimized version. -+ */ -+#define crc32_z crc32_z_default -+#endif /* Z_POWER_OPT */ -+ - unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; -@@ -1066,6 +1073,11 @@ - return crc ^ 0xffffffff; - } - -+#ifdef Z_POWER_OPT -+#undef crc32_z -+#include "contrib/power/crc32_z_resolver.c" -+#endif /* Z_POWER_OPT */ -+ - #endif - - /* ========================================================================= */ -Index: zlib-1.2.13.dfsg-1ubuntu1/test/crc32_test.c -=================================================================== ---- /dev/null -+++ zlib-1.2.13.dfsg-1ubuntu1/test/crc32_test.c -@@ -0,0 +1,205 @@ -+/* crc32_tes.c -- unit test for crc32 in the zlib compression library -+ * Copyright (C) 1995-2006, 2010, 2011, 2016, 2019 Rogerio Alves -+ * For conditions of distribution and use, see copyright notice in zlib.h -+ */ -+ -+#include "zlib.h" -+#include -+ -+#ifdef STDC -+# include -+# include -+#endif -+ -+void test_crc32 OF((uLong crc, Byte* buf, z_size_t len, uLong chk, int line)); -+int main OF((void)); -+ -+typedef struct { -+ int line; -+ uLong crc; -+ char* buf; -+ int len; -+ uLong expect; -+} crc32_test; -+ -+void test_crc32(crc, buf, len, chk, line) -+ uLong crc; -+ Byte *buf; -+ z_size_t len; -+ uLong chk; -+ int line; -+{ -+ uLong res = crc32(crc, buf, len); -+ if (res != chk) { -+ fprintf(stderr, "FAIL [%d]: crc32 returned 0x%08X expected 0x%08X\n", -+ line, (unsigned int)res, (unsigned int)chk); -+ exit(1); -+ } -+} -+ -+static const crc32_test tests[] = { -+ {__LINE__, 0x0, 0x0, 0, 0x0}, -+ {__LINE__, 0xffffffff, 0x0, 0, 0x0}, -+ {__LINE__, 0x0, 0x0, 255, 0x0}, /* BZ 174799. */ -+ {__LINE__, 0x0, 0x0, 256, 0x0}, -+ {__LINE__, 0x0, 0x0, 257, 0x0}, -+ {__LINE__, 0x0, 0x0, 32767, 0x0}, -+ {__LINE__, 0x0, 0x0, 32768, 0x0}, -+ {__LINE__, 0x0, 0x0, 32769, 0x0}, -+ {__LINE__, 0x0, "", 0, 0x0}, -+ {__LINE__, 0xffffffff, "", 0, 0xffffffff}, -+ {__LINE__, 0x0, "abacus", 6, 0xc3d7115b}, -+ {__LINE__, 0x0, "backlog", 7, 0x269205}, -+ {__LINE__, 0x0, "campfire", 8, 0x22a515f8}, -+ {__LINE__, 0x0, "delta", 5, 0x9643fed9}, -+ {__LINE__, 0x0, "executable", 10, 0xd68eda01}, -+ {__LINE__, 0x0, "file", 4, 0x8c9f3610}, -+ {__LINE__, 0x0, "greatest", 8, 0xc1abd6cd}, -+ {__LINE__, 0x0, "hello", 5, 0x3610a686}, -+ {__LINE__, 0x0, "inverter", 8, 0xc9e962c9}, -+ {__LINE__, 0x0, "jigsaw", 6, 0xce4e3f69}, -+ {__LINE__, 0x0, "karate", 6, 0x890be0e2}, -+ {__LINE__, 0x0, "landscape", 9, 0xc4e0330b}, -+ {__LINE__, 0x0, "machine", 7, 0x1505df84}, -+ {__LINE__, 0x0, "nanometer", 9, 0xd4e19f39}, -+ {__LINE__, 0x0, "oblivion", 8, 0xdae9de77}, -+ {__LINE__, 0x0, "panama", 6, 0x66b8979c}, -+ {__LINE__, 0x0, "quest", 5, 0x4317f817}, -+ {__LINE__, 0x0, "resource", 8, 0xbc91f416}, -+ {__LINE__, 0x0, "secret", 6, 0x5ca2e8e5}, -+ {__LINE__, 0x0, "test", 4, 0xd87f7e0c}, -+ {__LINE__, 0x0, "ultimate", 8, 0x3fc79b0b}, -+ {__LINE__, 0x0, "vector", 6, 0x1b6e485b}, -+ {__LINE__, 0x0, "walrus", 6, 0xbe769b97}, -+ {__LINE__, 0x0, "xeno", 4, 0xe7a06444}, -+ {__LINE__, 0x0, "yelling", 7, 0xfe3944e5}, -+ {__LINE__, 0x0, "zlib", 4, 0x73887d3a}, -+ {__LINE__, 0x0, "4BJD7PocN1VqX0jXVpWB", 20, 0xd487a5a1}, -+ {__LINE__, 0x0, "F1rPWI7XvDs6nAIRx41l", 20, 0x61a0132e}, -+ {__LINE__, 0x0, "ldhKlsVkPFOveXgkGtC2", 20, 0xdf02f76}, -+ {__LINE__, 0x0, "5KKnGOOrs8BvJ35iKTOS", 20, 0x579b2b0a}, -+ {__LINE__, 0x0, "0l1tw7GOcem06Ddu7yn4", 20, 0xf7d16e2d}, -+ {__LINE__, 0x0, "MCr47CjPIn9R1IvE1Tm5", 20, 0x731788f5}, -+ {__LINE__, 0x0, "UcixbzPKTIv0SvILHVdO", 20, 0x7112bb11}, -+ {__LINE__, 0x0, "dGnAyAhRQDsWw0ESou24", 20, 0xf32a0dac}, -+ {__LINE__, 0x0, "di0nvmY9UYMYDh0r45XT", 20, 0x625437bb}, -+ {__LINE__, 0x0, "2XKDwHfAhFsV0RhbqtvH", 20, 0x896930f9}, -+ {__LINE__, 0x0, "ZhrANFIiIvRnqClIVyeD", 20, 0x8579a37}, -+ {__LINE__, 0x0, "v7Q9ehzioTOVeDIZioT1", 20, 0x632aa8e0}, -+ {__LINE__, 0x0, "Yod5hEeKcYqyhfXbhxj2", 20, 0xc829af29}, -+ {__LINE__, 0x0, "GehSWY2ay4uUKhehXYb0", 20, 0x1b08b7e8}, -+ {__LINE__, 0x0, "kwytJmq6UqpflV8Y8GoE", 20, 0x4e33b192}, -+ {__LINE__, 0x0, "70684206568419061514", 20, 0x59a179f0}, -+ {__LINE__, 0x0, "42015093765128581010", 20, 0xcd1013d7}, -+ {__LINE__, 0x0, "88214814356148806939", 20, 0xab927546}, -+ {__LINE__, 0x0, "43472694284527343838", 20, 0x11f3b20c}, -+ {__LINE__, 0x0, "49769333513942933689", 20, 0xd562d4ca}, -+ {__LINE__, 0x0, "54979784887993251199", 20, 0x233395f7}, -+ {__LINE__, 0x0, "58360544869206793220", 20, 0x2d167fd5}, -+ {__LINE__, 0x0, "27347953487840714234", 20, 0x8b5108ba}, -+ {__LINE__, 0x0, "07650690295365319082", 20, 0xc46b3cd8}, -+ {__LINE__, 0x0, "42655507906821911703", 20, 0xc10b2662}, -+ {__LINE__, 0x0, "29977409200786225655", 20, 0xc9a0f9d2}, -+ {__LINE__, 0x0, "85181542907229116674", 20, 0x9341357b}, -+ {__LINE__, 0x0, "87963594337989416799", 20, 0xf0424937}, -+ {__LINE__, 0x0, "21395988329504168551", 20, 0xd7c4c31f}, -+ {__LINE__, 0x0, "51991013580943379423", 20, 0xf11edcc4}, -+ {__LINE__, 0x0, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x40795df4}, -+ {__LINE__, 0x0, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0xdd61a631}, -+ {__LINE__, 0x0, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xca907a99}, -+ {__LINE__, 0x0, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0xf652deac}, -+ {__LINE__, 0x0, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0xaf39a5a9}, -+ {__LINE__, 0x0, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x6bebb4cf}, -+ {__LINE__, 0x0, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0x76430bac}, -+ {__LINE__, 0x0, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x6c80c388}, -+ {__LINE__, 0x0, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xd54d977d}, -+ {__LINE__, 0x0, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0xe3966ad5}, -+ {__LINE__, 0x0, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xe7c71db9}, -+ {__LINE__, 0x0, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xeaa52777}, -+ {__LINE__, 0x0, "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 100, 0xcd472048}, -+ {__LINE__, 0x7a30360d, "abacus", 6, 0xf8655a84}, -+ {__LINE__, 0x6fd767ee, "backlog", 7, 0x1ed834b1}, -+ {__LINE__, 0xefeb7589, "campfire", 8, 0x686cfca}, -+ {__LINE__, 0x61cf7e6b, "delta", 5, 0x1554e4b1}, -+ {__LINE__, 0xdc712e2, "executable", 10, 0x761b4254}, -+ {__LINE__, 0xad23c7fd, "file", 4, 0x7abdd09b}, -+ {__LINE__, 0x85cb2317, "greatest", 8, 0x4ba91c6b}, -+ {__LINE__, 0x9eed31b0, "inverter", 8, 0xd5e78ba5}, -+ {__LINE__, 0xb94f34ca, "jigsaw", 6, 0x23649109}, -+ {__LINE__, 0xab058a2, "karate", 6, 0xc5591f41}, -+ {__LINE__, 0x5bff2b7a, "landscape", 9, 0xf10eb644}, -+ {__LINE__, 0x605c9a5f, "machine", 7, 0xbaa0a636}, -+ {__LINE__, 0x51bdeea5, "nanometer", 9, 0x6af89afb}, -+ {__LINE__, 0x85c21c79, "oblivion", 8, 0xecae222b}, -+ {__LINE__, 0x97216f56, "panama", 6, 0x47dffac4}, -+ {__LINE__, 0x18444af2, "quest", 5, 0x70c2fe36}, -+ {__LINE__, 0xbe6ce359, "resource", 8, 0x1471d925}, -+ {__LINE__, 0x843071f1, "secret", 6, 0x50c9a0db}, -+ {__LINE__, 0xf2480c60, "ultimate", 8, 0xf973daf8}, -+ {__LINE__, 0x2d2feb3d, "vector", 6, 0x344ac03d}, -+ {__LINE__, 0x7490310a, "walrus", 6, 0x6d1408ef}, -+ {__LINE__, 0x97d247d4, "xeno", 4, 0xe62670b5}, -+ {__LINE__, 0x93cf7599, "yelling", 7, 0x1b36da38}, -+ {__LINE__, 0x73c84278, "zlib", 4, 0x6432d127}, -+ {__LINE__, 0x228a87d1, "4BJD7PocN1VqX0jXVpWB", 20, 0x997107d0}, -+ {__LINE__, 0xa7a048d0, "F1rPWI7XvDs6nAIRx41l", 20, 0xdc567274}, -+ {__LINE__, 0x1f0ded40, "ldhKlsVkPFOveXgkGtC2", 20, 0xdcc63870}, -+ {__LINE__, 0xa804a62f, "5KKnGOOrs8BvJ35iKTOS", 20, 0x6926cffd}, -+ {__LINE__, 0x508fae6a, "0l1tw7GOcem06Ddu7yn4", 20, 0xb52b38bc}, -+ {__LINE__, 0xe5adaf4f, "MCr47CjPIn9R1IvE1Tm5", 20, 0xf83b8178}, -+ {__LINE__, 0x67136a40, "UcixbzPKTIv0SvILHVdO", 20, 0xc5213070}, -+ {__LINE__, 0xb00c4a10, "dGnAyAhRQDsWw0ESou24", 20, 0xbc7648b0}, -+ {__LINE__, 0x2e0c84b5, "di0nvmY9UYMYDh0r45XT", 20, 0xd8123a72}, -+ {__LINE__, 0x81238d44, "2XKDwHfAhFsV0RhbqtvH", 20, 0xd5ac5620}, -+ {__LINE__, 0xf853aa92, "ZhrANFIiIvRnqClIVyeD", 20, 0xceae099d}, -+ {__LINE__, 0x5a692325, "v7Q9ehzioTOVeDIZioT1", 20, 0xb07d2b24}, -+ {__LINE__, 0x3275b9f, "Yod5hEeKcYqyhfXbhxj2", 20, 0x24ce91df}, -+ {__LINE__, 0x38371feb, "GehSWY2ay4uUKhehXYb0", 20, 0x707b3b30}, -+ {__LINE__, 0xafc8bf62, "kwytJmq6UqpflV8Y8GoE", 20, 0x16abc6a9}, -+ {__LINE__, 0x9b07db73, "70684206568419061514", 20, 0xae1fb7b7}, -+ {__LINE__, 0xe75b214, "42015093765128581010", 20, 0xd4eecd2d}, -+ {__LINE__, 0x72d0fe6f, "88214814356148806939", 20, 0x4660ec7}, -+ {__LINE__, 0xf857a4b1, "43472694284527343838", 20, 0xfd8afdf7}, -+ {__LINE__, 0x54b8e14, "49769333513942933689", 20, 0xc6d1b5f2}, -+ {__LINE__, 0xd6aa5616, "54979784887993251199", 20, 0x32476461}, -+ {__LINE__, 0x11e63098, "58360544869206793220", 20, 0xd917cf1a}, -+ {__LINE__, 0xbe92385, "27347953487840714234", 20, 0x4ad14a12}, -+ {__LINE__, 0x49511de0, "07650690295365319082", 20, 0xe37b5c6c}, -+ {__LINE__, 0x3db13bc1, "42655507906821911703", 20, 0x7cc497f1}, -+ {__LINE__, 0xbb899bea, "29977409200786225655", 20, 0x99781bb2}, -+ {__LINE__, 0xf6cd9436, "85181542907229116674", 20, 0x132256a1}, -+ {__LINE__, 0x9109e6c3, "87963594337989416799", 20, 0xbfdb2c83}, -+ {__LINE__, 0x75770fc, "21395988329504168551", 20, 0x8d9d1e81}, -+ {__LINE__, 0x69b1d19b, "51991013580943379423", 20, 0x7b6d4404}, -+ {__LINE__, 0xc6132975, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x8619f010}, -+ {__LINE__, 0xd58cb00c, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0x15746ac3}, -+ {__LINE__, 0xb63b8caa, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xaccf812f}, -+ {__LINE__, 0x8a45a2b8, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0x78af45de}, -+ {__LINE__, 0xcbe95b78, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0x25b06b59}, -+ {__LINE__, 0x4ef8a54b, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x4ba0d08f}, -+ {__LINE__, 0x76ad267a, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0xe26b6aac}, -+ {__LINE__, 0x569e613c, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x7e2b0a66}, -+ {__LINE__, 0x36aa61da, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xb3430dc7}, -+ {__LINE__, 0xf67222df, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0x626c17a}, -+ {__LINE__, 0x74b34fd3, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xccf98060}, -+ {__LINE__, 0x351fd770, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xd8b95312}, -+ {__LINE__, 0xc45aef77, "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 100, 0xbb1c9912}, -+ {__LINE__, 0xc45aef77, "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" -+ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" -+ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" -+ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" -+ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" -+ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 600, 0x888AFA5B} -+}; -+ -+static const int test_size = sizeof(tests) / sizeof(tests[0]); -+ -+int main(void) -+{ -+ int i; -+ for (i = 0; i < test_size; i++) { -+ test_crc32(tests[i].crc, (Byte*) tests[i].buf, tests[i].len, -+ tests[i].expect, tests[i].line); -+ } -+ return 0; -+} diff -Nru zlib-1.2.13.dfsg/debian/patches/cflags-for-minizip zlib-1.3.1.dfsg/debian/patches/cflags-for-minizip --- zlib-1.2.13.dfsg/debian/patches/cflags-for-minizip 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/cflags-for-minizip 1970-01-01 00:00:00.000000000 +0000 @@ -1,22 +0,0 @@ ---- a/contrib/minizip/Makefile.orig 2022-11-05 12:35:09.684809015 +0000 -+++ b/contrib/minizip/Makefile 2022-11-05 12:35:49.885262972 +0000 -@@ -1,5 +1,5 @@ - CC=cc --CFLAGS := $(CFLAGS) -O -I../.. -+CFLAGS += $(CFLAGS) -O -I../.. - - UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a - ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a -@@ -10,10 +10,10 @@ - all: miniunz minizip - - miniunz: $(UNZ_OBJS) -- $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) -+ $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) $(LDFLAGS) - - minizip: $(ZIP_OBJS) -- $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) -+ $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) $(LDFLAGS) - - test: miniunz minizip - @rm -f test.* diff -Nru zlib-1.2.13.dfsg/debian/patches/lp1932010-ibm-z-add-vectorized-crc32-implementation.patch zlib-1.3.1.dfsg/debian/patches/lp1932010-ibm-z-add-vectorized-crc32-implementation.patch --- zlib-1.2.13.dfsg/debian/patches/lp1932010-ibm-z-add-vectorized-crc32-implementation.patch 2021-08-12 03:36:55.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/lp1932010-ibm-z-add-vectorized-crc32-implementation.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,430 +0,0 @@ -From f8801cc4f765c500867f1ff950708071b6c3c2e2 Mon Sep 17 00:00:00 2001 -From: Ilya Leoshkevich -Date: Tue, 6 Apr 2021 13:51:16 +0200 -Subject: [PATCH] IBM Z: Add vectorized CRC32 implementation - -While DFLTCC takes care of accelerating compression on level 1, other -levels can be sped up too by computing CRC32 using various vector -instructions. - -Take the Linux kernel assembly code that does that - its original -author (Hendrik Brueckner) works for IBM at the time of writing and has -allowed reusing the code under the zlib license. Rewrite it in C for -better maintainability, but keep the original structure, variable names -and comments. - -Ubuntu zlib backport modifications: - -Added a NULL-check in the code, not necessary in -ng -Retrofitted the configuration knobs -Removed the CI part of the patch ---- - Makefile.in | 8 ++ - configure | 52 +++++++++ - contrib/s390/crc32-vx.c | 226 ++++++++++++++++++++++++++++++++++++++++ - crc32.c | 19 +++- - 5 files changed, 321 insertions(+), 4 deletions(-) - create mode 100644 contrib/s390/crc32-vx.c - ---- a/Makefile.in -+++ b/Makefile.in -@@ -30,6 +30,8 @@ - LDSHARED=$(CC) - CPP=$(CC) -E - -+VGFMAFLAG= -+ - STATICLIB=libz.a - SHAREDLIB=libz.so - SHAREDLIBV=libz.so.1.2.11 -@@ -151,6 +153,12 @@ - $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/s390/dfltcc.c - -@mv objs/dfltcc.o $@ - -+crc32-vx.o: $(SRCDIR)contrib/s390/crc32-vx.c $(SRCDIR)zlib.h zconf.h -+ $(CC) $(CFLAGS) $(VGFMAFLAG) -c -o $@ $(SRCDIR)contrib/s390/crc32-vx.c -+ -+crc32-vx.lo: $(SRCDIR)contrib/s390/crc32-vx.c $(SRCDIR)zlib.h zconf.h -+ $(CC) $(SFLAGS) $(VGFMAFLAG) -c -o $@ $(SRCDIR)contrib/s390/crc32-vx.c -+ - crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c - ---- a/configure -+++ b/configure -@@ -89,6 +89,8 @@ - debug=0 - old_cc="$CC" - old_cflags="$CFLAGS" -+vgfmaflag="-march=z13" -+crc32_vx=0 - OBJC='$(OBJZ) $(OBJG)' - PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)' - -@@ -144,6 +146,10 @@ - PIC_OBJC="$PIC_OBJC dfltcc.lo" - shift - ;; -+ --crc32-vx) -+ crc32_vx=1 -+ shift -+ ;; - *) - echo "unknown option: $1" | tee -a configure.log - echo "$0 --help for help" | tee -a configure.log -@@ -927,6 +933,51 @@ - fi - fi - -+# Check whether "VECTOR GALOIS FIELD MULTIPLY SUM AND ACCUMULATE" intrinsic is available -+assert_crc32_vgfma() { -+ echo -n "Checking for -mzarch... " | tee -a configure.log -+ if try $CC -x c -c /dev/null -o /dev/null -mzarch; then -+ echo Yes. | tee -a configure.log -+ vgfmaflag="${vgfmaflag} -mzarch" -+ else -+ echo No. | tee -a configure.log -+ fi -+ echo -n "Checking for -fzvector... " | tee -a configure.log -+ if try $CC -x c -c /dev/null -o /dev/null -fzvector; then -+ echo Yes. | tee -a configure.log -+ vgfmaflag="${vgfmaflag} -fzvector" -+ else -+ echo No. | tee -a configure.log -+ fi -+ cat > $test.c << EOF -+#include -+int main(void) { -+ unsigned long long a __attribute__((vector_size(16))) = { 0 }; -+ unsigned long long b __attribute__((vector_size(16))) = { 0 }; -+ unsigned char c __attribute__((vector_size(16))) = { 0 }; -+ c = vec_gfmsum_accum_128(a, b, c); -+ return c[0]; -+} -+EOF -+ -+ echo -n "Checking for VGFMA support... " | tee -a configure.log -+ if try $CC -c $CFLAGS $vgfmaflag $test.c; then -+ echo "Yes." | tee -a configure.log -+ else -+ echo "No." | tee -a configure.log -+ echo "VGFMA support mandatory for crc32-vx feature." -+ leave 1 -+ fi -+} -+ -+ -+if test "$crc32_vx" -eq 1; then -+ CFLAGS="$CFLAGS -DS390_CRC32_VX" -+ OBJC="$OBJC crc32-vx.o" -+ PIC_OBJC="$PIC_OBJC crc32-vx.lo" -+ assert_crc32_vgfma -+fi -+ - # show the results in the log - echo >> configure.log - echo ALL = $ALL >> configure.log -@@ -968,6 +1019,7 @@ - /^LDFLAGS *=/s#=.*#=$LDFLAGS# - /^LDSHARED *=/s#=.*#=$LDSHARED# - /^CPP *=/s#=.*#=$CPP# -+/^VGFMAFLAG *=/s#=.*#=$vgfmaflag# - /^STATICLIB *=/s#=.*#=$STATICLIB# - /^SHAREDLIB *=/s#=.*#=$SHAREDLIB# - /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# ---- /dev/null -+++ b/contrib/s390/crc32-vx.c -@@ -0,0 +1,196 @@ -+/* -+ * Hardware-accelerated CRC-32 variants for Linux on z Systems -+ * -+ * Use the z/Architecture Vector Extension Facility to accelerate the -+ * computing of bitreflected CRC-32 checksums. -+ * -+ * This CRC-32 implementation algorithm is bitreflected and processes -+ * the least-significant bit first (Little-Endian). -+ * -+ * This code was originally written by Hendrik Brueckner -+ * for use in the Linux kernel and has been -+ * relicensed under the zlib license. -+ */ -+ -+#include "../../zutil.h" -+ -+#include -+#include -+ -+typedef unsigned char uv16qi __attribute__((vector_size(16))); -+typedef unsigned int uv4si __attribute__((vector_size(16))); -+typedef unsigned long long uv2di __attribute__((vector_size(16))); -+ -+ZLIB_INTERNAL uint32_t crc32_le_vgfm_16(uint32_t crc, const unsigned char *buf, size_t len) { -+ /* -+ * The CRC-32 constant block contains reduction constants to fold and -+ * process particular chunks of the input data stream in parallel. -+ * -+ * For the CRC-32 variants, the constants are precomputed according to -+ * these definitions: -+ * -+ * R1 = [(x4*128+32 mod P'(x) << 32)]' << 1 -+ * R2 = [(x4*128-32 mod P'(x) << 32)]' << 1 -+ * R3 = [(x128+32 mod P'(x) << 32)]' << 1 -+ * R4 = [(x128-32 mod P'(x) << 32)]' << 1 -+ * R5 = [(x64 mod P'(x) << 32)]' << 1 -+ * R6 = [(x32 mod P'(x) << 32)]' << 1 -+ * -+ * The bitreflected Barret reduction constant, u', is defined as -+ * the bit reversal of floor(x**64 / P(x)). -+ * -+ * where P(x) is the polynomial in the normal domain and the P'(x) is the -+ * polynomial in the reversed (bitreflected) domain. -+ * -+ * CRC-32 (IEEE 802.3 Ethernet, ...) polynomials: -+ * -+ * P(x) = 0x04C11DB7 -+ * P'(x) = 0xEDB88320 -+ */ -+ const uv16qi perm_le2be = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; /* BE->LE mask */ -+ const uv2di r2r1 = {0x1C6E41596, 0x154442BD4}; /* R2, R1 */ -+ const uv2di r4r3 = {0x0CCAA009E, 0x1751997D0}; /* R4, R3 */ -+ const uv2di r5 = {0, 0x163CD6124}; /* R5 */ -+ const uv2di ru_poly = {0, 0x1F7011641}; /* u' */ -+ const uv2di crc_poly = {0, 0x1DB710641}; /* P'(x) << 1 */ -+ -+ /* -+ * Load the initial CRC value. -+ * -+ * The CRC value is loaded into the rightmost word of the -+ * vector register and is later XORed with the LSB portion -+ * of the loaded input data. -+ */ -+ uv2di v0 = {0, 0}; -+ v0 = (uv2di)vec_insert(crc, (uv4si)v0, 3); -+ -+ /* Load a 64-byte data chunk and XOR with CRC */ -+ uv2di v1 = vec_perm(((uv2di *)buf)[0], ((uv2di *)buf)[0], perm_le2be); -+ uv2di v2 = vec_perm(((uv2di *)buf)[1], ((uv2di *)buf)[1], perm_le2be); -+ uv2di v3 = vec_perm(((uv2di *)buf)[2], ((uv2di *)buf)[2], perm_le2be); -+ uv2di v4 = vec_perm(((uv2di *)buf)[3], ((uv2di *)buf)[3], perm_le2be); -+ -+ v1 ^= v0; -+ buf += 64; -+ len -= 64; -+ -+ while (len >= 64) { -+ /* Load the next 64-byte data chunk */ -+ uv16qi part1 = vec_perm(((uv16qi *)buf)[0], ((uv16qi *)buf)[0], perm_le2be); -+ uv16qi part2 = vec_perm(((uv16qi *)buf)[1], ((uv16qi *)buf)[1], perm_le2be); -+ uv16qi part3 = vec_perm(((uv16qi *)buf)[2], ((uv16qi *)buf)[2], perm_le2be); -+ uv16qi part4 = vec_perm(((uv16qi *)buf)[3], ((uv16qi *)buf)[3], perm_le2be); -+ -+ /* -+ * Perform a GF(2) multiplication of the doublewords in V1 with -+ * the R1 and R2 reduction constants in V0. The intermediate result -+ * is then folded (accumulated) with the next data chunk in PART1 and -+ * stored in V1. Repeat this step for the register contents -+ * in V2, V3, and V4 respectively. -+ */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r2r1, v1, part1); -+ v2 = (uv2di)vec_gfmsum_accum_128(r2r1, v2, part2); -+ v3 = (uv2di)vec_gfmsum_accum_128(r2r1, v3, part3); -+ v4 = (uv2di)vec_gfmsum_accum_128(r2r1, v4, part4); -+ -+ buf += 64; -+ len -= 64; -+ } -+ -+ /* -+ * Fold V1 to V4 into a single 128-bit value in V1. Multiply V1 with R3 -+ * and R4 and accumulating the next 128-bit chunk until a single 128-bit -+ * value remains. -+ */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v2); -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v3); -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v4); -+ -+ while (len >= 16) { -+ /* Load next data chunk */ -+ v2 = vec_perm(*(uv2di *)buf, *(uv2di *)buf, perm_le2be); -+ -+ /* Fold next data chunk */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v2); -+ -+ buf += 16; -+ len -= 16; -+ } -+ -+ /* -+ * Set up a vector register for byte shifts. The shift value must -+ * be loaded in bits 1-4 in byte element 7 of a vector register. -+ * Shift by 8 bytes: 0x40 -+ * Shift by 4 bytes: 0x20 -+ */ -+ uv16qi v9 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -+ v9 = vec_insert((unsigned char)0x40, v9, 7); -+ -+ /* -+ * Prepare V0 for the next GF(2) multiplication: shift V0 by 8 bytes -+ * to move R4 into the rightmost doubleword and set the leftmost -+ * doubleword to 0x1. -+ */ -+ v0 = vec_srb(r4r3, (uv2di)v9); -+ v0[0] = 1; -+ -+ /* -+ * Compute GF(2) product of V1 and V0. The rightmost doubleword -+ * of V1 is multiplied with R4. The leftmost doubleword of V1 is -+ * multiplied by 0x1 and is then XORed with rightmost product. -+ * Implicitly, the intermediate leftmost product becomes padded -+ */ -+ v1 = (uv2di)vec_gfmsum_128(v0, v1); -+ -+ /* -+ * Now do the final 32-bit fold by multiplying the rightmost word -+ * in V1 with R5 and XOR the result with the remaining bits in V1. -+ * -+ * To achieve this by a single VGFMAG, right shift V1 by a word -+ * and store the result in V2 which is then accumulated. Use the -+ * vector unpack instruction to load the rightmost half of the -+ * doubleword into the rightmost doubleword element of V1; the other -+ * half is loaded in the leftmost doubleword. -+ * The vector register with CONST_R5 contains the R5 constant in the -+ * rightmost doubleword and the leftmost doubleword is zero to ignore -+ * the leftmost product of V1. -+ */ -+ v9 = vec_insert((unsigned char)0x20, v9, 7); -+ v2 = vec_srb(v1, (uv2di)v9); -+ v1 = vec_unpackl((uv4si)v1); /* Split rightmost doubleword */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r5, v1, (uv16qi)v2); -+ -+ /* -+ * Apply a Barret reduction to compute the final 32-bit CRC value. -+ * -+ * The input values to the Barret reduction are the degree-63 polynomial -+ * in V1 (R(x)), degree-32 generator polynomial, and the reduction -+ * constant u. The Barret reduction result is the CRC value of R(x) mod -+ * P(x). -+ * -+ * The Barret reduction algorithm is defined as: -+ * -+ * 1. T1(x) = floor( R(x) / x^32 ) GF2MUL u -+ * 2. T2(x) = floor( T1(x) / x^32 ) GF2MUL P(x) -+ * 3. C(x) = R(x) XOR T2(x) mod x^32 -+ * -+ * Note: The leftmost doubleword of vector register containing -+ * CONST_RU_POLY is zero and, thus, the intermediate GF(2) product -+ * is zero and does not contribute to the final result. -+ */ -+ -+ /* T1(x) = floor( R(x) / x^32 ) GF2MUL u */ -+ v2 = vec_unpackl((uv4si)v1); -+ v2 = (uv2di)vec_gfmsum_128(ru_poly, v2); -+ -+ /* -+ * Compute the GF(2) product of the CRC polynomial with T1(x) in -+ * V2 and XOR the intermediate result, T2(x), with the value in V1. -+ * The final result is stored in word element 2 of V2. -+ */ -+ v2 = vec_unpackl((uv4si)v2); -+ v2 = (uv2di)vec_gfmsum_accum_128(crc_poly, v2, (uv16qi)v1); -+ -+ return ((uv4si)v2)[2]; -+} -+ ---- a/crc32.c -+++ b/crc32.c -@@ -252,12 +252,60 @@ - #endif - #endif - -+#ifdef __s390__ -+#include -+#include -+ -+#ifdef S390_CRC32_VX -+#define VX_MIN_LEN 64 -+#define VX_ALIGNMENT 16L -+#define VX_ALIGN_MASK (VX_ALIGNMENT - 1) -+ -+extern unsigned int crc32_le_vgfm_16(unsigned int, const unsigned char *, z_size_t); -+ -+local uint32_t s390_crc32_vx(uint32_t crc, const unsigned char *buf, uint64_t len) { -+ uint64_t prealign, aligned, remaining; -+ -+ if (buf == Z_NULL) -+ return 0; -+ -+ if (len < VX_MIN_LEN + VX_ALIGN_MASK) -+ return crc32_big(crc, buf, len); -+ -+ if ((uintptr_t)buf & VX_ALIGN_MASK) { -+ prealign = VX_ALIGNMENT - ((uintptr_t)buf & VX_ALIGN_MASK); -+ len -= prealign; -+ crc = crc32_big(crc, buf, prealign); -+ buf += prealign; -+ } -+ aligned = len & ~VX_ALIGN_MASK; -+ remaining = len & VX_ALIGN_MASK; -+ -+ crc = crc32_le_vgfm_16(crc ^ 0xffffffff, buf, (size_t)aligned) ^ 0xffffffff; -+ -+ if (remaining) -+ crc = crc32_big(crc, buf + aligned, remaining); -+ -+ return crc; -+} -+ -+#endif /* S390_CRC32_VX */ -+#endif /* __s390__ */ -+ - /* due to a quirk of gnu_indirect_function - "local" (aka static) is applied to - * crc32_z which is not desired. crc32_z_ifunc is implictly "local" */ - #ifndef Z_IFUNC_ASM - local - #endif --unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *, z_size_t) -+unsigned long (*(crc32_z_ifunc( -+#ifdef __s390__ -+/* hwcap is passed to ifuncs on s390 so we can avoid a call to getauxval -+ while relocations are still being processed */ -+ unsigned long hwcap -+#else -+ void -+#endif -+ )))(unsigned long, const unsigned char FAR *, z_size_t) - { - #if _ARCH_PWR8==1 - #if defined(__BUILTIN_CPU_SUPPORTS__) -@@ -269,6 +317,11 @@ - #endif - #endif /* _ARCH_PWR8 */ - -+#if defined(__s390__) && defined(S390_CRC32_VX) -+ if (hwcap & HWCAP_S390_VX) -+ return s390_crc32_vx; -+#endif -+ - /* return a function pointer for optimized arches here */ - - #ifdef DYNAMIC_CRC_TABLE -@@ -301,7 +354,11 @@ - static unsigned long ZEXPORT (*crc32_func)(unsigned long, const unsigned char FAR *, z_size_t) = NULL; - - if (!crc32_func) -+#ifdef __s390__ -+ crc32_func = crc32_z_ifunc(getauxval(AT_HWCAP)); -+#else - crc32_func = crc32_z_ifunc(); -+#endif - return (*crc32_func)(crc, buf, len); - } - -@@ -378,7 +435,7 @@ - #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 - - /* ========================================================================= */ --local unsigned long crc32_big(crc, buf, len) -+ZLIB_INTERNAL unsigned long crc32_big(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; diff -Nru zlib-1.2.13.dfsg/debian/patches/power/add-optimized-crc32.patch zlib-1.3.1.dfsg/debian/patches/power/add-optimized-crc32.patch --- zlib-1.2.13.dfsg/debian/patches/power/add-optimized-crc32.patch 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/power/add-optimized-crc32.patch 2024-03-16 20:03:26.000000000 +0000 @@ -0,0 +1,2539 @@ +From: Manjunath S Matti +Date: Thu, 14 Sep 2023 06:43:11 -0500 +Subject: Add Power8+ optimized crc32 + +This commit adds an optimized version for the crc32 function based +on crc32-vpmsum from https://github.com/antonblanchard/crc32-vpmsum/ + +This is the C implementation created by Rogerio Alves + + +It makes use of vector instructions to speed up CRC32 algorithm. + +Author: Rogerio Alves +Signed-off-by: Manjunath Matti + +Origin: i-iii/zlib,https://github.com/iii-i/zlib/commit/6879bc81b111247939b4924b08c5993fd0482b1a +--- + .gitignore | 29 + + CMakeLists.txt | 7 +- + Makefile.in | 43 +- + configure | 7 +- + contrib/README.contrib | 3 +- + contrib/power/clang_workaround.h | 82 +++ + contrib/power/crc32_constants.h | 1206 ++++++++++++++++++++++++++++++++++++++ + contrib/power/crc32_z_power8.c | 679 +++++++++++++++++++++ + contrib/power/crc32_z_resolver.c | 15 + + contrib/power/power.h | 4 + + crc32.c | 12 + + test/crc32_test.c | 205 +++++++ + 12 files changed, 2278 insertions(+), 14 deletions(-) + create mode 100644 .gitignore + create mode 100644 contrib/power/clang_workaround.h + create mode 100644 contrib/power/crc32_constants.h + create mode 100644 contrib/power/crc32_z_power8.c + create mode 100644 contrib/power/crc32_z_resolver.c + create mode 100644 test/crc32_test.c + +diff --git a/.gitignore b/.gitignore +new file mode 100644 +index 0000000..e324531 +--- /dev/null ++++ b/.gitignore +@@ -0,0 +1,29 @@ ++*.diff ++*.patch ++*.orig ++*.rej ++ ++*~ ++*.a ++*.lo ++*.o ++*.dylib ++ ++*.gcda ++*.gcno ++*.gcov ++ ++/crc32_test ++/crc32_test64 ++/crc32_testsh ++/example ++/example64 ++/examplesh ++/libz.so* ++/minigzip ++/minigzip64 ++/minigzipsh ++/zlib.pc ++/configure.log ++ ++.DS_Store +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4456cd7..0464ba3 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -174,7 +174,8 @@ if(CMAKE_COMPILER_IS_GNUCC) + + if(POWER8) + add_definitions(-DZ_POWER8) +- set(ZLIB_POWER8 ) ++ set(ZLIB_POWER8 ++ contrib/power/crc32_z_power8.c) + + set_source_files_properties( + ${ZLIB_POWER8} +@@ -273,6 +274,10 @@ add_executable(example test/example.c) + target_link_libraries(example zlib) + add_test(example example) + ++ add_executable(crc32_test test/crc32_test.c) ++ target_link_libraries(crc32_test zlib) ++ add_test(crc32_test crc32_test) ++ + add_executable(minigzip test/minigzip.c) + target_link_libraries(minigzip zlib) + +diff --git a/Makefile.in b/Makefile.in +index 34d3cd7..2dbb20a 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -71,11 +71,11 @@ PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA) + + all: static shared + +-static: example$(EXE) minigzip$(EXE) ++static: crc32_test$(EXE) example$(EXE) minigzip$(EXE) + +-shared: examplesh$(EXE) minigzipsh$(EXE) ++shared: crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) + +-all64: example64$(EXE) minigzip64$(EXE) ++all64: crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE) + + check: test + +@@ -83,7 +83,7 @@ test: all teststatic testshared + + teststatic: static + @TMPST=tmpst_$$; \ +- if echo hello world | ${QEMU_RUN} ./minigzip | ${QEMU_RUN} ./minigzip -d && ${QEMU_RUN} ./example $$TMPST ; then \ ++ if echo hello world | ${QEMU_RUN} ./minigzip | ${QEMU_RUN} ./minigzip -d && ${QEMU_RUN} ./example $$TMPST && ${QEMU_RUN} ./crc32_test; then \ + echo ' *** zlib test OK ***'; \ + else \ + echo ' *** zlib test FAILED ***'; false; \ +@@ -96,7 +96,7 @@ testshared: shared + DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \ + SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \ + TMPSH=tmpsh_$$; \ +- if echo hello world | ${QEMU_RUN} ./minigzipsh | ${QEMU_RUN} ./minigzipsh -d && ${QEMU_RUN} ./examplesh $$TMPSH; then \ ++ if echo hello world | ${QEMU_RUN} ./minigzipsh | ${QEMU_RUN} ./minigzipsh -d && ${QEMU_RUN} ./examplesh $$TMPSH && ${QEMU_RUN} ./crc32_testsh; then \ + echo ' *** zlib shared test OK ***'; \ + else \ + echo ' *** zlib shared test FAILED ***'; false; \ +@@ -105,7 +105,7 @@ testshared: shared + + test64: all64 + @TMP64=tmp64_$$; \ +- if echo hello world | ${QEMU_RUN} ./minigzip64 | ${QEMU_RUN} ./minigzip64 -d && ${QEMU_RUN} ./example64 $$TMP64; then \ ++ if echo hello world | ${QEMU_RUN} ./minigzip64 | ${QEMU_RUN} ./minigzip64 -d && ${QEMU_RUN} ./example64 $$TMP64 && ${QEMU_RUN} ./crc32_test64; then \ + echo ' *** zlib 64-bit test OK ***'; \ + else \ + echo ' *** zlib 64-bit test FAILED ***'; false; \ +@@ -139,12 +139,18 @@ match.lo: match.S + mv _match.o match.lo + rm -f _match.s + ++crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h ++ $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c ++ + example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h + $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c + + minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h + $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c + ++crc32_test64.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h ++ $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/crc32_test.c ++ + example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h + $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c + +@@ -158,6 +164,9 @@ adler32.o: $(SRCDIR)adler32.c + crc32.o: $(SRCDIR)crc32.c + $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c + ++crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c ++ $(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c ++ + deflate.o: $(SRCDIR)deflate.c + $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c + +@@ -208,6 +217,11 @@ crc32.lo: $(SRCDIR)crc32.c + $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c + -@mv objs/crc32.o $@ + ++crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c ++ -@mkdir objs 2>/dev/null || test -d objs ++ $(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c ++ -@mv objs/crc32_z_power8.o $@ ++ + deflate.lo: $(SRCDIR)deflate.c + -@mkdir objs 2>/dev/null || test -d objs + $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c +@@ -281,18 +295,27 @@ placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a + ln -s $@ $(SHAREDLIBM) + -@rmdir objs + ++crc32_test$(EXE): crc32_test.o $(STATICLIB) ++ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ crc32_test.o $(TEST_LIBS) ++ + example$(EXE): example.o $(STATICLIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TEST_LIBS) + + minigzip$(EXE): minigzip.o $(STATICLIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(TEST_LIBS) + ++crc32_testsh$(EXE): crc32_test.o $(SHAREDLIBV) ++ $(CC) $(CFLAGS) -o $@ crc32_test.o -L. $(SHAREDLIBV) ++ + examplesh$(EXE): example.o $(SHAREDLIBV) + $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) -L. $(SHAREDLIBV) + + minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) + $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV) + ++crc32_test64$(EXE): crc32_test64.o $(STATICLIB) ++ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ crc32_test64.o $(TEST_LIBS) ++ + example64$(EXE): example64.o $(STATICLIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS) + +@@ -368,8 +391,8 @@ minizip-clean: + mostlyclean: clean + clean: minizip-clean + rm -f *.o *.lo *~ \ +- example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ +- example64$(EXE) minigzip64$(EXE) \ ++ crc32_test$(EXE) example$(EXE) minigzip$(EXE) crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ ++ crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE) \ + infcover \ + libz.* foo.gz so_locations \ + _match.s maketree contrib/infback9/*.o +@@ -391,7 +414,7 @@ tags: + + adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h + gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h +-compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h ++compress.o crc32_test.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h + crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h + deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h + infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h +@@ -401,7 +424,7 @@ trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)tr + + adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h + gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h +-compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h ++compress.lo crc32_test.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h + crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h + deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h + infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h +diff --git a/configure b/configure +index e307a8d..b96ed4a 100755 +--- a/configure ++++ b/configure +@@ -865,6 +865,9 @@ cat > $test.c < + pascal/ by Bob Dellaca et al. + Support for Pascal + +-power/ by Matheus Castanho ++power/ by Daniel Black ++ Matheus Castanho + and Rogerio Alves + Optimized functions for Power processors + +diff --git a/contrib/power/clang_workaround.h b/contrib/power/clang_workaround.h +new file mode 100644 +index 0000000..b5e7dae +--- /dev/null ++++ b/contrib/power/clang_workaround.h +@@ -0,0 +1,82 @@ ++#ifndef CLANG_WORKAROUNDS_H ++#define CLANG_WORKAROUNDS_H ++ ++/* ++ * These stubs fix clang incompatibilities with GCC builtins. ++ */ ++ ++#ifndef __builtin_crypto_vpmsumw ++#define __builtin_crypto_vpmsumw __builtin_crypto_vpmsumb ++#endif ++#ifndef __builtin_crypto_vpmsumd ++#define __builtin_crypto_vpmsumd __builtin_crypto_vpmsumb ++#endif ++ ++static inline ++__vector unsigned long long __attribute__((overloadable)) ++vec_ld(int __a, const __vector unsigned long long* __b) ++{ ++ return (__vector unsigned long long)__builtin_altivec_lvx(__a, __b); ++} ++ ++/* ++ * GCC __builtin_pack_vector_int128 returns a vector __int128_t but Clang ++ * does not recognize this type. On GCC this builtin is translated to a ++ * xxpermdi instruction that only moves the registers __a, __b instead generates ++ * a load. ++ * ++ * Clang has vec_xxpermdi intrinsics. It was implemented in 4.0.0. ++ */ ++static inline ++__vector unsigned long long __builtin_pack_vector (unsigned long __a, ++ unsigned long __b) ++{ ++ #if defined(__BIG_ENDIAN__) ++ __vector unsigned long long __v = {__a, __b}; ++ #else ++ __vector unsigned long long __v = {__b, __a}; ++ #endif ++ return __v; ++} ++ ++#ifndef vec_xxpermdi ++ ++static inline ++unsigned long __builtin_unpack_vector (__vector unsigned long long __v, ++ int __o) ++{ ++ return __v[__o]; ++} ++ ++#if defined(__BIG_ENDIAN__) ++#define __builtin_unpack_vector_0(a) __builtin_unpack_vector ((a), 0) ++#define __builtin_unpack_vector_1(a) __builtin_unpack_vector ((a), 1) ++#else ++#define __builtin_unpack_vector_0(a) __builtin_unpack_vector ((a), 1) ++#define __builtin_unpack_vector_1(a) __builtin_unpack_vector ((a), 0) ++#endif ++ ++#else ++ ++static inline ++unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v) ++{ ++ #if defined(__BIG_ENDIAN__) ++ return vec_xxpermdi(__v, __v, 0x0)[1]; ++ #else ++ return vec_xxpermdi(__v, __v, 0x0)[0]; ++ #endif ++} ++ ++static inline ++unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v) ++{ ++ #if defined(__BIG_ENDIAN__) ++ return vec_xxpermdi(__v, __v, 0x3)[1]; ++ #else ++ return vec_xxpermdi(__v, __v, 0x3)[0]; ++ #endif ++} ++#endif /* vec_xxpermdi */ ++ ++#endif +diff --git a/contrib/power/crc32_constants.h b/contrib/power/crc32_constants.h +new file mode 100644 +index 0000000..3d01150 +--- /dev/null ++++ b/contrib/power/crc32_constants.h +@@ -0,0 +1,1206 @@ ++/* ++* ++* THIS FILE IS GENERATED WITH ++./crc32_constants -c -r -x 0x04C11DB7 ++ ++* This is from https://github.com/antonblanchard/crc32-vpmsum/ ++* DO NOT MODIFY IT MANUALLY! ++* ++*/ ++ ++#define CRC 0x4c11db7 ++#define CRC_XOR ++#define REFLECT ++#define MAX_SIZE 32768 ++ ++#ifndef __ASSEMBLER__ ++#ifdef CRC_TABLE ++static const unsigned int crc_table[] = { ++ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, ++ 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, ++ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, ++ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, ++ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, ++ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, ++ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, ++ 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, ++ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, ++ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, ++ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, ++ 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, ++ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, ++ 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, ++ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, ++ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, ++ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, ++ 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, ++ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, ++ 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, ++ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, ++ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, ++ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, ++ 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, ++ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, ++ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, ++ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, ++ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, ++ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, ++ 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, ++ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, ++ 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, ++ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, ++ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, ++ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, ++ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, ++ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, ++ 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, ++ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, ++ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, ++ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, ++ 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, ++ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, ++ 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, ++ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, ++ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, ++ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, ++ 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, ++ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, ++ 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, ++ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, ++ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, ++ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, ++ 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, ++ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, ++ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, ++ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, ++ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, ++ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, ++ 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, ++ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, ++ 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, ++ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, ++ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,}; ++ ++#endif /* CRC_TABLE */ ++#ifdef POWER8_INTRINSICS ++ ++/* Constants */ ++ ++/* Reduce 262144 kbits to 1024 bits */ ++static const __vector unsigned long long vcrc_const[255] ++ __attribute__((aligned (16))) = { ++#ifdef __LITTLE_ENDIAN__ ++ /* x^261120 mod p(x)` << 1, x^261184 mod p(x)` << 1 */ ++ { 0x0000000099ea94a8, 0x00000001651797d2 }, ++ /* x^260096 mod p(x)` << 1, x^260160 mod p(x)` << 1 */ ++ { 0x00000000945a8420, 0x0000000021e0d56c }, ++ /* x^259072 mod p(x)` << 1, x^259136 mod p(x)` << 1 */ ++ { 0x0000000030762706, 0x000000000f95ecaa }, ++ /* x^258048 mod p(x)` << 1, x^258112 mod p(x)` << 1 */ ++ { 0x00000001a52fc582, 0x00000001ebd224ac }, ++ /* x^257024 mod p(x)` << 1, x^257088 mod p(x)` << 1 */ ++ { 0x00000001a4a7167a, 0x000000000ccb97ca }, ++ /* x^256000 mod p(x)` << 1, x^256064 mod p(x)` << 1 */ ++ { 0x000000000c18249a, 0x00000001006ec8a8 }, ++ /* x^254976 mod p(x)` << 1, x^255040 mod p(x)` << 1 */ ++ { 0x00000000a924ae7c, 0x000000014f58f196 }, ++ /* x^253952 mod p(x)` << 1, x^254016 mod p(x)` << 1 */ ++ { 0x00000001e12ccc12, 0x00000001a7192ca6 }, ++ /* x^252928 mod p(x)` << 1, x^252992 mod p(x)` << 1 */ ++ { 0x00000000a0b9d4ac, 0x000000019a64bab2 }, ++ /* x^251904 mod p(x)` << 1, x^251968 mod p(x)` << 1 */ ++ { 0x0000000095e8ddfe, 0x0000000014f4ed2e }, ++ /* x^250880 mod p(x)` << 1, x^250944 mod p(x)` << 1 */ ++ { 0x00000000233fddc4, 0x000000011092b6a2 }, ++ /* x^249856 mod p(x)` << 1, x^249920 mod p(x)` << 1 */ ++ { 0x00000001b4529b62, 0x00000000c8a1629c }, ++ /* x^248832 mod p(x)` << 1, x^248896 mod p(x)` << 1 */ ++ { 0x00000001a7fa0e64, 0x000000017bf32e8e }, ++ /* x^247808 mod p(x)` << 1, x^247872 mod p(x)` << 1 */ ++ { 0x00000001b5334592, 0x00000001f8cc6582 }, ++ /* x^246784 mod p(x)` << 1, x^246848 mod p(x)` << 1 */ ++ { 0x000000011f8ee1b4, 0x000000008631ddf0 }, ++ /* x^245760 mod p(x)` << 1, x^245824 mod p(x)` << 1 */ ++ { 0x000000006252e632, 0x000000007e5a76d0 }, ++ /* x^244736 mod p(x)` << 1, x^244800 mod p(x)` << 1 */ ++ { 0x00000000ab973e84, 0x000000002b09b31c }, ++ /* x^243712 mod p(x)` << 1, x^243776 mod p(x)` << 1 */ ++ { 0x000000007734f5ec, 0x00000001b2df1f84 }, ++ /* x^242688 mod p(x)` << 1, x^242752 mod p(x)` << 1 */ ++ { 0x000000007c547798, 0x00000001d6f56afc }, ++ /* x^241664 mod p(x)` << 1, x^241728 mod p(x)` << 1 */ ++ { 0x000000007ec40210, 0x00000001b9b5e70c }, ++ /* x^240640 mod p(x)` << 1, x^240704 mod p(x)` << 1 */ ++ { 0x00000001ab1695a8, 0x0000000034b626d2 }, ++ /* x^239616 mod p(x)` << 1, x^239680 mod p(x)` << 1 */ ++ { 0x0000000090494bba, 0x000000014c53479a }, ++ /* x^238592 mod p(x)` << 1, x^238656 mod p(x)` << 1 */ ++ { 0x00000001123fb816, 0x00000001a6d179a4 }, ++ /* x^237568 mod p(x)` << 1, x^237632 mod p(x)` << 1 */ ++ { 0x00000001e188c74c, 0x000000015abd16b4 }, ++ /* x^236544 mod p(x)` << 1, x^236608 mod p(x)` << 1 */ ++ { 0x00000001c2d3451c, 0x00000000018f9852 }, ++ /* x^235520 mod p(x)` << 1, x^235584 mod p(x)` << 1 */ ++ { 0x00000000f55cf1ca, 0x000000001fb3084a }, ++ /* x^234496 mod p(x)` << 1, x^234560 mod p(x)` << 1 */ ++ { 0x00000001a0531540, 0x00000000c53dfb04 }, ++ /* x^233472 mod p(x)` << 1, x^233536 mod p(x)` << 1 */ ++ { 0x0000000132cd7ebc, 0x00000000e10c9ad6 }, ++ /* x^232448 mod p(x)` << 1, x^232512 mod p(x)` << 1 */ ++ { 0x0000000073ab7f36, 0x0000000025aa994a }, ++ /* x^231424 mod p(x)` << 1, x^231488 mod p(x)` << 1 */ ++ { 0x0000000041aed1c2, 0x00000000fa3a74c4 }, ++ /* x^230400 mod p(x)` << 1, x^230464 mod p(x)` << 1 */ ++ { 0x0000000136c53800, 0x0000000033eb3f40 }, ++ /* x^229376 mod p(x)` << 1, x^229440 mod p(x)` << 1 */ ++ { 0x0000000126835a30, 0x000000017193f296 }, ++ /* x^228352 mod p(x)` << 1, x^228416 mod p(x)` << 1 */ ++ { 0x000000006241b502, 0x0000000043f6c86a }, ++ /* x^227328 mod p(x)` << 1, x^227392 mod p(x)` << 1 */ ++ { 0x00000000d5196ad4, 0x000000016b513ec6 }, ++ /* x^226304 mod p(x)` << 1, x^226368 mod p(x)` << 1 */ ++ { 0x000000009cfa769a, 0x00000000c8f25b4e }, ++ /* x^225280 mod p(x)` << 1, x^225344 mod p(x)` << 1 */ ++ { 0x00000000920e5df4, 0x00000001a45048ec }, ++ /* x^224256 mod p(x)` << 1, x^224320 mod p(x)` << 1 */ ++ { 0x0000000169dc310e, 0x000000000c441004 }, ++ /* x^223232 mod p(x)` << 1, x^223296 mod p(x)` << 1 */ ++ { 0x0000000009fc331c, 0x000000000e17cad6 }, ++ /* x^222208 mod p(x)` << 1, x^222272 mod p(x)` << 1 */ ++ { 0x000000010d94a81e, 0x00000001253ae964 }, ++ /* x^221184 mod p(x)` << 1, x^221248 mod p(x)` << 1 */ ++ { 0x0000000027a20ab2, 0x00000001d7c88ebc }, ++ /* x^220160 mod p(x)` << 1, x^220224 mod p(x)` << 1 */ ++ { 0x0000000114f87504, 0x00000001e7ca913a }, ++ /* x^219136 mod p(x)` << 1, x^219200 mod p(x)` << 1 */ ++ { 0x000000004b076d96, 0x0000000033ed078a }, ++ /* x^218112 mod p(x)` << 1, x^218176 mod p(x)` << 1 */ ++ { 0x00000000da4d1e74, 0x00000000e1839c78 }, ++ /* x^217088 mod p(x)` << 1, x^217152 mod p(x)` << 1 */ ++ { 0x000000001b81f672, 0x00000001322b267e }, ++ /* x^216064 mod p(x)` << 1, x^216128 mod p(x)` << 1 */ ++ { 0x000000009367c988, 0x00000000638231b6 }, ++ /* x^215040 mod p(x)` << 1, x^215104 mod p(x)` << 1 */ ++ { 0x00000001717214ca, 0x00000001ee7f16f4 }, ++ /* x^214016 mod p(x)` << 1, x^214080 mod p(x)` << 1 */ ++ { 0x000000009f47d820, 0x0000000117d9924a }, ++ /* x^212992 mod p(x)` << 1, x^213056 mod p(x)` << 1 */ ++ { 0x000000010d9a47d2, 0x00000000e1a9e0c4 }, ++ /* x^211968 mod p(x)` << 1, x^212032 mod p(x)` << 1 */ ++ { 0x00000000a696c58c, 0x00000001403731dc }, ++ /* x^210944 mod p(x)` << 1, x^211008 mod p(x)` << 1 */ ++ { 0x000000002aa28ec6, 0x00000001a5ea9682 }, ++ /* x^209920 mod p(x)` << 1, x^209984 mod p(x)` << 1 */ ++ { 0x00000001fe18fd9a, 0x0000000101c5c578 }, ++ /* x^208896 mod p(x)` << 1, x^208960 mod p(x)` << 1 */ ++ { 0x000000019d4fc1ae, 0x00000000dddf6494 }, ++ /* x^207872 mod p(x)` << 1, x^207936 mod p(x)` << 1 */ ++ { 0x00000001ba0e3dea, 0x00000000f1c3db28 }, ++ /* x^206848 mod p(x)` << 1, x^206912 mod p(x)` << 1 */ ++ { 0x0000000074b59a5e, 0x000000013112fb9c }, ++ /* x^205824 mod p(x)` << 1, x^205888 mod p(x)` << 1 */ ++ { 0x00000000f2b5ea98, 0x00000000b680b906 }, ++ /* x^204800 mod p(x)` << 1, x^204864 mod p(x)` << 1 */ ++ { 0x0000000187132676, 0x000000001a282932 }, ++ /* x^203776 mod p(x)` << 1, x^203840 mod p(x)` << 1 */ ++ { 0x000000010a8c6ad4, 0x0000000089406e7e }, ++ /* x^202752 mod p(x)` << 1, x^202816 mod p(x)` << 1 */ ++ { 0x00000001e21dfe70, 0x00000001def6be8c }, ++ /* x^201728 mod p(x)` << 1, x^201792 mod p(x)` << 1 */ ++ { 0x00000001da0050e4, 0x0000000075258728 }, ++ /* x^200704 mod p(x)` << 1, x^200768 mod p(x)` << 1 */ ++ { 0x00000000772172ae, 0x000000019536090a }, ++ /* x^199680 mod p(x)` << 1, x^199744 mod p(x)` << 1 */ ++ { 0x00000000e47724aa, 0x00000000f2455bfc }, ++ /* x^198656 mod p(x)` << 1, x^198720 mod p(x)` << 1 */ ++ { 0x000000003cd63ac4, 0x000000018c40baf4 }, ++ /* x^197632 mod p(x)` << 1, x^197696 mod p(x)` << 1 */ ++ { 0x00000001bf47d352, 0x000000004cd390d4 }, ++ /* x^196608 mod p(x)` << 1, x^196672 mod p(x)` << 1 */ ++ { 0x000000018dc1d708, 0x00000001e4ece95a }, ++ /* x^195584 mod p(x)` << 1, x^195648 mod p(x)` << 1 */ ++ { 0x000000002d4620a4, 0x000000001a3ee918 }, ++ /* x^194560 mod p(x)` << 1, x^194624 mod p(x)` << 1 */ ++ { 0x0000000058fd1740, 0x000000007c652fb8 }, ++ /* x^193536 mod p(x)` << 1, x^193600 mod p(x)` << 1 */ ++ { 0x00000000dadd9bfc, 0x000000011c67842c }, ++ /* x^192512 mod p(x)` << 1, x^192576 mod p(x)` << 1 */ ++ { 0x00000001ea2140be, 0x00000000254f759c }, ++ /* x^191488 mod p(x)` << 1, x^191552 mod p(x)` << 1 */ ++ { 0x000000009de128ba, 0x000000007ece94ca }, ++ /* x^190464 mod p(x)` << 1, x^190528 mod p(x)` << 1 */ ++ { 0x000000013ac3aa8e, 0x0000000038f258c2 }, ++ /* x^189440 mod p(x)` << 1, x^189504 mod p(x)` << 1 */ ++ { 0x0000000099980562, 0x00000001cdf17b00 }, ++ /* x^188416 mod p(x)` << 1, x^188480 mod p(x)` << 1 */ ++ { 0x00000001c1579c86, 0x000000011f882c16 }, ++ /* x^187392 mod p(x)` << 1, x^187456 mod p(x)` << 1 */ ++ { 0x0000000068dbbf94, 0x0000000100093fc8 }, ++ /* x^186368 mod p(x)` << 1, x^186432 mod p(x)` << 1 */ ++ { 0x000000004509fb04, 0x00000001cd684f16 }, ++ /* x^185344 mod p(x)` << 1, x^185408 mod p(x)` << 1 */ ++ { 0x00000001202f6398, 0x000000004bc6a70a }, ++ /* x^184320 mod p(x)` << 1, x^184384 mod p(x)` << 1 */ ++ { 0x000000013aea243e, 0x000000004fc7e8e4 }, ++ /* x^183296 mod p(x)` << 1, x^183360 mod p(x)` << 1 */ ++ { 0x00000001b4052ae6, 0x0000000130103f1c }, ++ /* x^182272 mod p(x)` << 1, x^182336 mod p(x)` << 1 */ ++ { 0x00000001cd2a0ae8, 0x0000000111b0024c }, ++ /* x^181248 mod p(x)` << 1, x^181312 mod p(x)` << 1 */ ++ { 0x00000001fe4aa8b4, 0x000000010b3079da }, ++ /* x^180224 mod p(x)` << 1, x^180288 mod p(x)` << 1 */ ++ { 0x00000001d1559a42, 0x000000010192bcc2 }, ++ /* x^179200 mod p(x)` << 1, x^179264 mod p(x)` << 1 */ ++ { 0x00000001f3e05ecc, 0x0000000074838d50 }, ++ /* x^178176 mod p(x)` << 1, x^178240 mod p(x)` << 1 */ ++ { 0x0000000104ddd2cc, 0x000000001b20f520 }, ++ /* x^177152 mod p(x)` << 1, x^177216 mod p(x)` << 1 */ ++ { 0x000000015393153c, 0x0000000050c3590a }, ++ /* x^176128 mod p(x)` << 1, x^176192 mod p(x)` << 1 */ ++ { 0x0000000057e942c6, 0x00000000b41cac8e }, ++ /* x^175104 mod p(x)` << 1, x^175168 mod p(x)` << 1 */ ++ { 0x000000012c633850, 0x000000000c72cc78 }, ++ /* x^174080 mod p(x)` << 1, x^174144 mod p(x)` << 1 */ ++ { 0x00000000ebcaae4c, 0x0000000030cdb032 }, ++ /* x^173056 mod p(x)` << 1, x^173120 mod p(x)` << 1 */ ++ { 0x000000013ee532a6, 0x000000013e09fc32 }, ++ /* x^172032 mod p(x)` << 1, x^172096 mod p(x)` << 1 */ ++ { 0x00000001bf0cbc7e, 0x000000001ed624d2 }, ++ /* x^171008 mod p(x)` << 1, x^171072 mod p(x)` << 1 */ ++ { 0x00000000d50b7a5a, 0x00000000781aee1a }, ++ /* x^169984 mod p(x)` << 1, x^170048 mod p(x)` << 1 */ ++ { 0x0000000002fca6e8, 0x00000001c4d8348c }, ++ /* x^168960 mod p(x)` << 1, x^169024 mod p(x)` << 1 */ ++ { 0x000000007af40044, 0x0000000057a40336 }, ++ /* x^167936 mod p(x)` << 1, x^168000 mod p(x)` << 1 */ ++ { 0x0000000016178744, 0x0000000085544940 }, ++ /* x^166912 mod p(x)` << 1, x^166976 mod p(x)` << 1 */ ++ { 0x000000014c177458, 0x000000019cd21e80 }, ++ /* x^165888 mod p(x)` << 1, x^165952 mod p(x)` << 1 */ ++ { 0x000000011b6ddf04, 0x000000013eb95bc0 }, ++ /* x^164864 mod p(x)` << 1, x^164928 mod p(x)` << 1 */ ++ { 0x00000001f3e29ccc, 0x00000001dfc9fdfc }, ++ /* x^163840 mod p(x)` << 1, x^163904 mod p(x)` << 1 */ ++ { 0x0000000135ae7562, 0x00000000cd028bc2 }, ++ /* x^162816 mod p(x)` << 1, x^162880 mod p(x)` << 1 */ ++ { 0x0000000190ef812c, 0x0000000090db8c44 }, ++ /* x^161792 mod p(x)` << 1, x^161856 mod p(x)` << 1 */ ++ { 0x0000000067a2c786, 0x000000010010a4ce }, ++ /* x^160768 mod p(x)` << 1, x^160832 mod p(x)` << 1 */ ++ { 0x0000000048b9496c, 0x00000001c8f4c72c }, ++ /* x^159744 mod p(x)` << 1, x^159808 mod p(x)` << 1 */ ++ { 0x000000015a422de6, 0x000000001c26170c }, ++ /* x^158720 mod p(x)` << 1, x^158784 mod p(x)` << 1 */ ++ { 0x00000001ef0e3640, 0x00000000e3fccf68 }, ++ /* x^157696 mod p(x)` << 1, x^157760 mod p(x)` << 1 */ ++ { 0x00000001006d2d26, 0x00000000d513ed24 }, ++ /* x^156672 mod p(x)` << 1, x^156736 mod p(x)` << 1 */ ++ { 0x00000001170d56d6, 0x00000000141beada }, ++ /* x^155648 mod p(x)` << 1, x^155712 mod p(x)` << 1 */ ++ { 0x00000000a5fb613c, 0x000000011071aea0 }, ++ /* x^154624 mod p(x)` << 1, x^154688 mod p(x)` << 1 */ ++ { 0x0000000040bbf7fc, 0x000000012e19080a }, ++ /* x^153600 mod p(x)` << 1, x^153664 mod p(x)` << 1 */ ++ { 0x000000016ac3a5b2, 0x0000000100ecf826 }, ++ /* x^152576 mod p(x)` << 1, x^152640 mod p(x)` << 1 */ ++ { 0x00000000abf16230, 0x0000000069b09412 }, ++ /* x^151552 mod p(x)` << 1, x^151616 mod p(x)` << 1 */ ++ { 0x00000001ebe23fac, 0x0000000122297bac }, ++ /* x^150528 mod p(x)` << 1, x^150592 mod p(x)` << 1 */ ++ { 0x000000008b6a0894, 0x00000000e9e4b068 }, ++ /* x^149504 mod p(x)` << 1, x^149568 mod p(x)` << 1 */ ++ { 0x00000001288ea478, 0x000000004b38651a }, ++ /* x^148480 mod p(x)` << 1, x^148544 mod p(x)` << 1 */ ++ { 0x000000016619c442, 0x00000001468360e2 }, ++ /* x^147456 mod p(x)` << 1, x^147520 mod p(x)` << 1 */ ++ { 0x0000000086230038, 0x00000000121c2408 }, ++ /* x^146432 mod p(x)` << 1, x^146496 mod p(x)` << 1 */ ++ { 0x000000017746a756, 0x00000000da7e7d08 }, ++ /* x^145408 mod p(x)` << 1, x^145472 mod p(x)` << 1 */ ++ { 0x0000000191b8f8f8, 0x00000001058d7652 }, ++ /* x^144384 mod p(x)` << 1, x^144448 mod p(x)` << 1 */ ++ { 0x000000008e167708, 0x000000014a098a90 }, ++ /* x^143360 mod p(x)` << 1, x^143424 mod p(x)` << 1 */ ++ { 0x0000000148b22d54, 0x0000000020dbe72e }, ++ /* x^142336 mod p(x)` << 1, x^142400 mod p(x)` << 1 */ ++ { 0x0000000044ba2c3c, 0x000000011e7323e8 }, ++ /* x^141312 mod p(x)` << 1, x^141376 mod p(x)` << 1 */ ++ { 0x00000000b54d2b52, 0x00000000d5d4bf94 }, ++ /* x^140288 mod p(x)` << 1, x^140352 mod p(x)` << 1 */ ++ { 0x0000000005a4fd8a, 0x0000000199d8746c }, ++ /* x^139264 mod p(x)` << 1, x^139328 mod p(x)` << 1 */ ++ { 0x0000000139f9fc46, 0x00000000ce9ca8a0 }, ++ /* x^138240 mod p(x)` << 1, x^138304 mod p(x)` << 1 */ ++ { 0x000000015a1fa824, 0x00000000136edece }, ++ /* x^137216 mod p(x)` << 1, x^137280 mod p(x)` << 1 */ ++ { 0x000000000a61ae4c, 0x000000019b92a068 }, ++ /* x^136192 mod p(x)` << 1, x^136256 mod p(x)` << 1 */ ++ { 0x0000000145e9113e, 0x0000000071d62206 }, ++ /* x^135168 mod p(x)` << 1, x^135232 mod p(x)` << 1 */ ++ { 0x000000006a348448, 0x00000000dfc50158 }, ++ /* x^134144 mod p(x)` << 1, x^134208 mod p(x)` << 1 */ ++ { 0x000000004d80a08c, 0x00000001517626bc }, ++ /* x^133120 mod p(x)` << 1, x^133184 mod p(x)` << 1 */ ++ { 0x000000014b6837a0, 0x0000000148d1e4fa }, ++ /* x^132096 mod p(x)` << 1, x^132160 mod p(x)` << 1 */ ++ { 0x000000016896a7fc, 0x0000000094d8266e }, ++ /* x^131072 mod p(x)` << 1, x^131136 mod p(x)` << 1 */ ++ { 0x000000014f187140, 0x00000000606c5e34 }, ++ /* x^130048 mod p(x)` << 1, x^130112 mod p(x)` << 1 */ ++ { 0x000000019581b9da, 0x000000019766beaa }, ++ /* x^129024 mod p(x)` << 1, x^129088 mod p(x)` << 1 */ ++ { 0x00000001091bc984, 0x00000001d80c506c }, ++ /* x^128000 mod p(x)` << 1, x^128064 mod p(x)` << 1 */ ++ { 0x000000001067223c, 0x000000001e73837c }, ++ /* x^126976 mod p(x)` << 1, x^127040 mod p(x)` << 1 */ ++ { 0x00000001ab16ea02, 0x0000000064d587de }, ++ /* x^125952 mod p(x)` << 1, x^126016 mod p(x)` << 1 */ ++ { 0x000000013c4598a8, 0x00000000f4a507b0 }, ++ /* x^124928 mod p(x)` << 1, x^124992 mod p(x)` << 1 */ ++ { 0x00000000b3735430, 0x0000000040e342fc }, ++ /* x^123904 mod p(x)` << 1, x^123968 mod p(x)` << 1 */ ++ { 0x00000001bb3fc0c0, 0x00000001d5ad9c3a }, ++ /* x^122880 mod p(x)` << 1, x^122944 mod p(x)` << 1 */ ++ { 0x00000001570ae19c, 0x0000000094a691a4 }, ++ /* x^121856 mod p(x)` << 1, x^121920 mod p(x)` << 1 */ ++ { 0x00000001ea910712, 0x00000001271ecdfa }, ++ /* x^120832 mod p(x)` << 1, x^120896 mod p(x)` << 1 */ ++ { 0x0000000167127128, 0x000000009e54475a }, ++ /* x^119808 mod p(x)` << 1, x^119872 mod p(x)` << 1 */ ++ { 0x0000000019e790a2, 0x00000000c9c099ee }, ++ /* x^118784 mod p(x)` << 1, x^118848 mod p(x)` << 1 */ ++ { 0x000000003788f710, 0x000000009a2f736c }, ++ /* x^117760 mod p(x)` << 1, x^117824 mod p(x)` << 1 */ ++ { 0x00000001682a160e, 0x00000000bb9f4996 }, ++ /* x^116736 mod p(x)` << 1, x^116800 mod p(x)` << 1 */ ++ { 0x000000007f0ebd2e, 0x00000001db688050 }, ++ /* x^115712 mod p(x)` << 1, x^115776 mod p(x)` << 1 */ ++ { 0x000000002b032080, 0x00000000e9b10af4 }, ++ /* x^114688 mod p(x)` << 1, x^114752 mod p(x)` << 1 */ ++ { 0x00000000cfd1664a, 0x000000012d4545e4 }, ++ /* x^113664 mod p(x)` << 1, x^113728 mod p(x)` << 1 */ ++ { 0x00000000aa1181c2, 0x000000000361139c }, ++ /* x^112640 mod p(x)` << 1, x^112704 mod p(x)` << 1 */ ++ { 0x00000000ddd08002, 0x00000001a5a1a3a8 }, ++ /* x^111616 mod p(x)` << 1, x^111680 mod p(x)` << 1 */ ++ { 0x00000000e8dd0446, 0x000000006844e0b0 }, ++ /* x^110592 mod p(x)` << 1, x^110656 mod p(x)` << 1 */ ++ { 0x00000001bbd94a00, 0x00000000c3762f28 }, ++ /* x^109568 mod p(x)` << 1, x^109632 mod p(x)` << 1 */ ++ { 0x00000000ab6cd180, 0x00000001d26287a2 }, ++ /* x^108544 mod p(x)` << 1, x^108608 mod p(x)` << 1 */ ++ { 0x0000000031803ce2, 0x00000001f6f0bba8 }, ++ /* x^107520 mod p(x)` << 1, x^107584 mod p(x)` << 1 */ ++ { 0x0000000024f40b0c, 0x000000002ffabd62 }, ++ /* x^106496 mod p(x)` << 1, x^106560 mod p(x)` << 1 */ ++ { 0x00000001ba1d9834, 0x00000000fb4516b8 }, ++ /* x^105472 mod p(x)` << 1, x^105536 mod p(x)` << 1 */ ++ { 0x0000000104de61aa, 0x000000018cfa961c }, ++ /* x^104448 mod p(x)` << 1, x^104512 mod p(x)` << 1 */ ++ { 0x0000000113e40d46, 0x000000019e588d52 }, ++ /* x^103424 mod p(x)` << 1, x^103488 mod p(x)` << 1 */ ++ { 0x00000001415598a0, 0x00000001180f0bbc }, ++ /* x^102400 mod p(x)` << 1, x^102464 mod p(x)` << 1 */ ++ { 0x00000000bf6c8c90, 0x00000000e1d9177a }, ++ /* x^101376 mod p(x)` << 1, x^101440 mod p(x)` << 1 */ ++ { 0x00000001788b0504, 0x0000000105abc27c }, ++ /* x^100352 mod p(x)` << 1, x^100416 mod p(x)` << 1 */ ++ { 0x0000000038385d02, 0x00000000972e4a58 }, ++ /* x^99328 mod p(x)` << 1, x^99392 mod p(x)` << 1 */ ++ { 0x00000001b6c83844, 0x0000000183499a5e }, ++ /* x^98304 mod p(x)` << 1, x^98368 mod p(x)` << 1 */ ++ { 0x0000000051061a8a, 0x00000001c96a8cca }, ++ /* x^97280 mod p(x)` << 1, x^97344 mod p(x)` << 1 */ ++ { 0x000000017351388a, 0x00000001a1a5b60c }, ++ /* x^96256 mod p(x)` << 1, x^96320 mod p(x)` << 1 */ ++ { 0x0000000132928f92, 0x00000000e4b6ac9c }, ++ /* x^95232 mod p(x)` << 1, x^95296 mod p(x)` << 1 */ ++ { 0x00000000e6b4f48a, 0x00000001807e7f5a }, ++ /* x^94208 mod p(x)` << 1, x^94272 mod p(x)` << 1 */ ++ { 0x0000000039d15e90, 0x000000017a7e3bc8 }, ++ /* x^93184 mod p(x)` << 1, x^93248 mod p(x)` << 1 */ ++ { 0x00000000312d6074, 0x00000000d73975da }, ++ /* x^92160 mod p(x)` << 1, x^92224 mod p(x)` << 1 */ ++ { 0x000000017bbb2cc4, 0x000000017375d038 }, ++ /* x^91136 mod p(x)` << 1, x^91200 mod p(x)` << 1 */ ++ { 0x000000016ded3e18, 0x00000000193680bc }, ++ /* x^90112 mod p(x)` << 1, x^90176 mod p(x)` << 1 */ ++ { 0x00000000f1638b16, 0x00000000999b06f6 }, ++ /* x^89088 mod p(x)` << 1, x^89152 mod p(x)` << 1 */ ++ { 0x00000001d38b9ecc, 0x00000001f685d2b8 }, ++ /* x^88064 mod p(x)` << 1, x^88128 mod p(x)` << 1 */ ++ { 0x000000018b8d09dc, 0x00000001f4ecbed2 }, ++ /* x^87040 mod p(x)` << 1, x^87104 mod p(x)` << 1 */ ++ { 0x00000000e7bc27d2, 0x00000000ba16f1a0 }, ++ /* x^86016 mod p(x)` << 1, x^86080 mod p(x)` << 1 */ ++ { 0x00000000275e1e96, 0x0000000115aceac4 }, ++ /* x^84992 mod p(x)` << 1, x^85056 mod p(x)` << 1 */ ++ { 0x00000000e2e3031e, 0x00000001aeff6292 }, ++ /* x^83968 mod p(x)` << 1, x^84032 mod p(x)` << 1 */ ++ { 0x00000001041c84d8, 0x000000009640124c }, ++ /* x^82944 mod p(x)` << 1, x^83008 mod p(x)` << 1 */ ++ { 0x00000000706ce672, 0x0000000114f41f02 }, ++ /* x^81920 mod p(x)` << 1, x^81984 mod p(x)` << 1 */ ++ { 0x000000015d5070da, 0x000000009c5f3586 }, ++ /* x^80896 mod p(x)` << 1, x^80960 mod p(x)` << 1 */ ++ { 0x0000000038f9493a, 0x00000001878275fa }, ++ /* x^79872 mod p(x)` << 1, x^79936 mod p(x)` << 1 */ ++ { 0x00000000a3348a76, 0x00000000ddc42ce8 }, ++ /* x^78848 mod p(x)` << 1, x^78912 mod p(x)` << 1 */ ++ { 0x00000001ad0aab92, 0x0000000181d2c73a }, ++ /* x^77824 mod p(x)` << 1, x^77888 mod p(x)` << 1 */ ++ { 0x000000019e85f712, 0x0000000141c9320a }, ++ /* x^76800 mod p(x)` << 1, x^76864 mod p(x)` << 1 */ ++ { 0x000000005a871e76, 0x000000015235719a }, ++ /* x^75776 mod p(x)` << 1, x^75840 mod p(x)` << 1 */ ++ { 0x000000017249c662, 0x00000000be27d804 }, ++ /* x^74752 mod p(x)` << 1, x^74816 mod p(x)` << 1 */ ++ { 0x000000003a084712, 0x000000006242d45a }, ++ /* x^73728 mod p(x)` << 1, x^73792 mod p(x)` << 1 */ ++ { 0x00000000ed438478, 0x000000009a53638e }, ++ /* x^72704 mod p(x)` << 1, x^72768 mod p(x)` << 1 */ ++ { 0x00000000abac34cc, 0x00000001001ecfb6 }, ++ /* x^71680 mod p(x)` << 1, x^71744 mod p(x)` << 1 */ ++ { 0x000000005f35ef3e, 0x000000016d7c2d64 }, ++ /* x^70656 mod p(x)` << 1, x^70720 mod p(x)` << 1 */ ++ { 0x0000000047d6608c, 0x00000001d0ce46c0 }, ++ /* x^69632 mod p(x)` << 1, x^69696 mod p(x)` << 1 */ ++ { 0x000000002d01470e, 0x0000000124c907b4 }, ++ /* x^68608 mod p(x)` << 1, x^68672 mod p(x)` << 1 */ ++ { 0x0000000158bbc7b0, 0x0000000018a555ca }, ++ /* x^67584 mod p(x)` << 1, x^67648 mod p(x)` << 1 */ ++ { 0x00000000c0a23e8e, 0x000000006b0980bc }, ++ /* x^66560 mod p(x)` << 1, x^66624 mod p(x)` << 1 */ ++ { 0x00000001ebd85c88, 0x000000008bbba964 }, ++ /* x^65536 mod p(x)` << 1, x^65600 mod p(x)` << 1 */ ++ { 0x000000019ee20bb2, 0x00000001070a5a1e }, ++ /* x^64512 mod p(x)` << 1, x^64576 mod p(x)` << 1 */ ++ { 0x00000001acabf2d6, 0x000000002204322a }, ++ /* x^63488 mod p(x)` << 1, x^63552 mod p(x)` << 1 */ ++ { 0x00000001b7963d56, 0x00000000a27524d0 }, ++ /* x^62464 mod p(x)` << 1, x^62528 mod p(x)` << 1 */ ++ { 0x000000017bffa1fe, 0x0000000020b1e4ba }, ++ /* x^61440 mod p(x)` << 1, x^61504 mod p(x)` << 1 */ ++ { 0x000000001f15333e, 0x0000000032cc27fc }, ++ /* x^60416 mod p(x)` << 1, x^60480 mod p(x)` << 1 */ ++ { 0x000000018593129e, 0x0000000044dd22b8 }, ++ /* x^59392 mod p(x)` << 1, x^59456 mod p(x)` << 1 */ ++ { 0x000000019cb32602, 0x00000000dffc9e0a }, ++ /* x^58368 mod p(x)` << 1, x^58432 mod p(x)` << 1 */ ++ { 0x0000000142b05cc8, 0x00000001b7a0ed14 }, ++ /* x^57344 mod p(x)` << 1, x^57408 mod p(x)` << 1 */ ++ { 0x00000001be49e7a4, 0x00000000c7842488 }, ++ /* x^56320 mod p(x)` << 1, x^56384 mod p(x)` << 1 */ ++ { 0x0000000108f69d6c, 0x00000001c02a4fee }, ++ /* x^55296 mod p(x)` << 1, x^55360 mod p(x)` << 1 */ ++ { 0x000000006c0971f0, 0x000000003c273778 }, ++ /* x^54272 mod p(x)` << 1, x^54336 mod p(x)` << 1 */ ++ { 0x000000005b16467a, 0x00000001d63f8894 }, ++ /* x^53248 mod p(x)` << 1, x^53312 mod p(x)` << 1 */ ++ { 0x00000001551a628e, 0x000000006be557d6 }, ++ /* x^52224 mod p(x)` << 1, x^52288 mod p(x)` << 1 */ ++ { 0x000000019e42ea92, 0x000000006a7806ea }, ++ /* x^51200 mod p(x)` << 1, x^51264 mod p(x)` << 1 */ ++ { 0x000000012fa83ff2, 0x000000016155aa0c }, ++ /* x^50176 mod p(x)` << 1, x^50240 mod p(x)` << 1 */ ++ { 0x000000011ca9cde0, 0x00000000908650ac }, ++ /* x^49152 mod p(x)` << 1, x^49216 mod p(x)` << 1 */ ++ { 0x00000000c8e5cd74, 0x00000000aa5a8084 }, ++ /* x^48128 mod p(x)` << 1, x^48192 mod p(x)` << 1 */ ++ { 0x0000000096c27f0c, 0x0000000191bb500a }, ++ /* x^47104 mod p(x)` << 1, x^47168 mod p(x)` << 1 */ ++ { 0x000000002baed926, 0x0000000064e9bed0 }, ++ /* x^46080 mod p(x)` << 1, x^46144 mod p(x)` << 1 */ ++ { 0x000000017c8de8d2, 0x000000009444f302 }, ++ /* x^45056 mod p(x)` << 1, x^45120 mod p(x)` << 1 */ ++ { 0x00000000d43d6068, 0x000000019db07d3c }, ++ /* x^44032 mod p(x)` << 1, x^44096 mod p(x)` << 1 */ ++ { 0x00000000cb2c4b26, 0x00000001359e3e6e }, ++ /* x^43008 mod p(x)` << 1, x^43072 mod p(x)` << 1 */ ++ { 0x0000000145b8da26, 0x00000001e4f10dd2 }, ++ /* x^41984 mod p(x)` << 1, x^42048 mod p(x)` << 1 */ ++ { 0x000000018fff4b08, 0x0000000124f5735e }, ++ /* x^40960 mod p(x)` << 1, x^41024 mod p(x)` << 1 */ ++ { 0x0000000150b58ed0, 0x0000000124760a4c }, ++ /* x^39936 mod p(x)` << 1, x^40000 mod p(x)` << 1 */ ++ { 0x00000001549f39bc, 0x000000000f1fc186 }, ++ /* x^38912 mod p(x)` << 1, x^38976 mod p(x)` << 1 */ ++ { 0x00000000ef4d2f42, 0x00000000150e4cc4 }, ++ /* x^37888 mod p(x)` << 1, x^37952 mod p(x)` << 1 */ ++ { 0x00000001b1468572, 0x000000002a6204e8 }, ++ /* x^36864 mod p(x)` << 1, x^36928 mod p(x)` << 1 */ ++ { 0x000000013d7403b2, 0x00000000beb1d432 }, ++ /* x^35840 mod p(x)` << 1, x^35904 mod p(x)` << 1 */ ++ { 0x00000001a4681842, 0x0000000135f3f1f0 }, ++ /* x^34816 mod p(x)` << 1, x^34880 mod p(x)` << 1 */ ++ { 0x0000000167714492, 0x0000000074fe2232 }, ++ /* x^33792 mod p(x)` << 1, x^33856 mod p(x)` << 1 */ ++ { 0x00000001e599099a, 0x000000001ac6e2ba }, ++ /* x^32768 mod p(x)` << 1, x^32832 mod p(x)` << 1 */ ++ { 0x00000000fe128194, 0x0000000013fca91e }, ++ /* x^31744 mod p(x)` << 1, x^31808 mod p(x)` << 1 */ ++ { 0x0000000077e8b990, 0x0000000183f4931e }, ++ /* x^30720 mod p(x)` << 1, x^30784 mod p(x)` << 1 */ ++ { 0x00000001a267f63a, 0x00000000b6d9b4e4 }, ++ /* x^29696 mod p(x)` << 1, x^29760 mod p(x)` << 1 */ ++ { 0x00000001945c245a, 0x00000000b5188656 }, ++ /* x^28672 mod p(x)` << 1, x^28736 mod p(x)` << 1 */ ++ { 0x0000000149002e76, 0x0000000027a81a84 }, ++ /* x^27648 mod p(x)` << 1, x^27712 mod p(x)` << 1 */ ++ { 0x00000001bb8310a4, 0x0000000125699258 }, ++ /* x^26624 mod p(x)` << 1, x^26688 mod p(x)` << 1 */ ++ { 0x000000019ec60bcc, 0x00000001b23de796 }, ++ /* x^25600 mod p(x)` << 1, x^25664 mod p(x)` << 1 */ ++ { 0x000000012d8590ae, 0x00000000fe4365dc }, ++ /* x^24576 mod p(x)` << 1, x^24640 mod p(x)` << 1 */ ++ { 0x0000000065b00684, 0x00000000c68f497a }, ++ /* x^23552 mod p(x)` << 1, x^23616 mod p(x)` << 1 */ ++ { 0x000000015e5aeadc, 0x00000000fbf521ee }, ++ /* x^22528 mod p(x)` << 1, x^22592 mod p(x)` << 1 */ ++ { 0x00000000b77ff2b0, 0x000000015eac3378 }, ++ /* x^21504 mod p(x)` << 1, x^21568 mod p(x)` << 1 */ ++ { 0x0000000188da2ff6, 0x0000000134914b90 }, ++ /* x^20480 mod p(x)` << 1, x^20544 mod p(x)` << 1 */ ++ { 0x0000000063da929a, 0x0000000016335cfe }, ++ /* x^19456 mod p(x)` << 1, x^19520 mod p(x)` << 1 */ ++ { 0x00000001389caa80, 0x000000010372d10c }, ++ /* x^18432 mod p(x)` << 1, x^18496 mod p(x)` << 1 */ ++ { 0x000000013db599d2, 0x000000015097b908 }, ++ /* x^17408 mod p(x)` << 1, x^17472 mod p(x)` << 1 */ ++ { 0x0000000122505a86, 0x00000001227a7572 }, ++ /* x^16384 mod p(x)` << 1, x^16448 mod p(x)` << 1 */ ++ { 0x000000016bd72746, 0x000000009a8f75c0 }, ++ /* x^15360 mod p(x)` << 1, x^15424 mod p(x)` << 1 */ ++ { 0x00000001c3faf1d4, 0x00000000682c77a2 }, ++ /* x^14336 mod p(x)` << 1, x^14400 mod p(x)` << 1 */ ++ { 0x00000001111c826c, 0x00000000231f091c }, ++ /* x^13312 mod p(x)` << 1, x^13376 mod p(x)` << 1 */ ++ { 0x00000000153e9fb2, 0x000000007d4439f2 }, ++ /* x^12288 mod p(x)` << 1, x^12352 mod p(x)` << 1 */ ++ { 0x000000002b1f7b60, 0x000000017e221efc }, ++ /* x^11264 mod p(x)` << 1, x^11328 mod p(x)` << 1 */ ++ { 0x00000000b1dba570, 0x0000000167457c38 }, ++ /* x^10240 mod p(x)` << 1, x^10304 mod p(x)` << 1 */ ++ { 0x00000001f6397b76, 0x00000000bdf081c4 }, ++ /* x^9216 mod p(x)` << 1, x^9280 mod p(x)` << 1 */ ++ { 0x0000000156335214, 0x000000016286d6b0 }, ++ /* x^8192 mod p(x)` << 1, x^8256 mod p(x)` << 1 */ ++ { 0x00000001d70e3986, 0x00000000c84f001c }, ++ /* x^7168 mod p(x)` << 1, x^7232 mod p(x)` << 1 */ ++ { 0x000000003701a774, 0x0000000064efe7c0 }, ++ /* x^6144 mod p(x)` << 1, x^6208 mod p(x)` << 1 */ ++ { 0x00000000ac81ef72, 0x000000000ac2d904 }, ++ /* x^5120 mod p(x)` << 1, x^5184 mod p(x)` << 1 */ ++ { 0x0000000133212464, 0x00000000fd226d14 }, ++ /* x^4096 mod p(x)` << 1, x^4160 mod p(x)` << 1 */ ++ { 0x00000000e4e45610, 0x000000011cfd42e0 }, ++ /* x^3072 mod p(x)` << 1, x^3136 mod p(x)` << 1 */ ++ { 0x000000000c1bd370, 0x000000016e5a5678 }, ++ /* x^2048 mod p(x)` << 1, x^2112 mod p(x)` << 1 */ ++ { 0x00000001a7b9e7a6, 0x00000001d888fe22 }, ++ /* x^1024 mod p(x)` << 1, x^1088 mod p(x)` << 1 */ ++ { 0x000000007d657a10, 0x00000001af77fcd4 } ++#else /* __LITTLE_ENDIAN__ */ ++ /* x^261120 mod p(x)` << 1, x^261184 mod p(x)` << 1 */ ++ { 0x00000001651797d2, 0x0000000099ea94a8 }, ++ /* x^260096 mod p(x)` << 1, x^260160 mod p(x)` << 1 */ ++ { 0x0000000021e0d56c, 0x00000000945a8420 }, ++ /* x^259072 mod p(x)` << 1, x^259136 mod p(x)` << 1 */ ++ { 0x000000000f95ecaa, 0x0000000030762706 }, ++ /* x^258048 mod p(x)` << 1, x^258112 mod p(x)` << 1 */ ++ { 0x00000001ebd224ac, 0x00000001a52fc582 }, ++ /* x^257024 mod p(x)` << 1, x^257088 mod p(x)` << 1 */ ++ { 0x000000000ccb97ca, 0x00000001a4a7167a }, ++ /* x^256000 mod p(x)` << 1, x^256064 mod p(x)` << 1 */ ++ { 0x00000001006ec8a8, 0x000000000c18249a }, ++ /* x^254976 mod p(x)` << 1, x^255040 mod p(x)` << 1 */ ++ { 0x000000014f58f196, 0x00000000a924ae7c }, ++ /* x^253952 mod p(x)` << 1, x^254016 mod p(x)` << 1 */ ++ { 0x00000001a7192ca6, 0x00000001e12ccc12 }, ++ /* x^252928 mod p(x)` << 1, x^252992 mod p(x)` << 1 */ ++ { 0x000000019a64bab2, 0x00000000a0b9d4ac }, ++ /* x^251904 mod p(x)` << 1, x^251968 mod p(x)` << 1 */ ++ { 0x0000000014f4ed2e, 0x0000000095e8ddfe }, ++ /* x^250880 mod p(x)` << 1, x^250944 mod p(x)` << 1 */ ++ { 0x000000011092b6a2, 0x00000000233fddc4 }, ++ /* x^249856 mod p(x)` << 1, x^249920 mod p(x)` << 1 */ ++ { 0x00000000c8a1629c, 0x00000001b4529b62 }, ++ /* x^248832 mod p(x)` << 1, x^248896 mod p(x)` << 1 */ ++ { 0x000000017bf32e8e, 0x00000001a7fa0e64 }, ++ /* x^247808 mod p(x)` << 1, x^247872 mod p(x)` << 1 */ ++ { 0x00000001f8cc6582, 0x00000001b5334592 }, ++ /* x^246784 mod p(x)` << 1, x^246848 mod p(x)` << 1 */ ++ { 0x000000008631ddf0, 0x000000011f8ee1b4 }, ++ /* x^245760 mod p(x)` << 1, x^245824 mod p(x)` << 1 */ ++ { 0x000000007e5a76d0, 0x000000006252e632 }, ++ /* x^244736 mod p(x)` << 1, x^244800 mod p(x)` << 1 */ ++ { 0x000000002b09b31c, 0x00000000ab973e84 }, ++ /* x^243712 mod p(x)` << 1, x^243776 mod p(x)` << 1 */ ++ { 0x00000001b2df1f84, 0x000000007734f5ec }, ++ /* x^242688 mod p(x)` << 1, x^242752 mod p(x)` << 1 */ ++ { 0x00000001d6f56afc, 0x000000007c547798 }, ++ /* x^241664 mod p(x)` << 1, x^241728 mod p(x)` << 1 */ ++ { 0x00000001b9b5e70c, 0x000000007ec40210 }, ++ /* x^240640 mod p(x)` << 1, x^240704 mod p(x)` << 1 */ ++ { 0x0000000034b626d2, 0x00000001ab1695a8 }, ++ /* x^239616 mod p(x)` << 1, x^239680 mod p(x)` << 1 */ ++ { 0x000000014c53479a, 0x0000000090494bba }, ++ /* x^238592 mod p(x)` << 1, x^238656 mod p(x)` << 1 */ ++ { 0x00000001a6d179a4, 0x00000001123fb816 }, ++ /* x^237568 mod p(x)` << 1, x^237632 mod p(x)` << 1 */ ++ { 0x000000015abd16b4, 0x00000001e188c74c }, ++ /* x^236544 mod p(x)` << 1, x^236608 mod p(x)` << 1 */ ++ { 0x00000000018f9852, 0x00000001c2d3451c }, ++ /* x^235520 mod p(x)` << 1, x^235584 mod p(x)` << 1 */ ++ { 0x000000001fb3084a, 0x00000000f55cf1ca }, ++ /* x^234496 mod p(x)` << 1, x^234560 mod p(x)` << 1 */ ++ { 0x00000000c53dfb04, 0x00000001a0531540 }, ++ /* x^233472 mod p(x)` << 1, x^233536 mod p(x)` << 1 */ ++ { 0x00000000e10c9ad6, 0x0000000132cd7ebc }, ++ /* x^232448 mod p(x)` << 1, x^232512 mod p(x)` << 1 */ ++ { 0x0000000025aa994a, 0x0000000073ab7f36 }, ++ /* x^231424 mod p(x)` << 1, x^231488 mod p(x)` << 1 */ ++ { 0x00000000fa3a74c4, 0x0000000041aed1c2 }, ++ /* x^230400 mod p(x)` << 1, x^230464 mod p(x)` << 1 */ ++ { 0x0000000033eb3f40, 0x0000000136c53800 }, ++ /* x^229376 mod p(x)` << 1, x^229440 mod p(x)` << 1 */ ++ { 0x000000017193f296, 0x0000000126835a30 }, ++ /* x^228352 mod p(x)` << 1, x^228416 mod p(x)` << 1 */ ++ { 0x0000000043f6c86a, 0x000000006241b502 }, ++ /* x^227328 mod p(x)` << 1, x^227392 mod p(x)` << 1 */ ++ { 0x000000016b513ec6, 0x00000000d5196ad4 }, ++ /* x^226304 mod p(x)` << 1, x^226368 mod p(x)` << 1 */ ++ { 0x00000000c8f25b4e, 0x000000009cfa769a }, ++ /* x^225280 mod p(x)` << 1, x^225344 mod p(x)` << 1 */ ++ { 0x00000001a45048ec, 0x00000000920e5df4 }, ++ /* x^224256 mod p(x)` << 1, x^224320 mod p(x)` << 1 */ ++ { 0x000000000c441004, 0x0000000169dc310e }, ++ /* x^223232 mod p(x)` << 1, x^223296 mod p(x)` << 1 */ ++ { 0x000000000e17cad6, 0x0000000009fc331c }, ++ /* x^222208 mod p(x)` << 1, x^222272 mod p(x)` << 1 */ ++ { 0x00000001253ae964, 0x000000010d94a81e }, ++ /* x^221184 mod p(x)` << 1, x^221248 mod p(x)` << 1 */ ++ { 0x00000001d7c88ebc, 0x0000000027a20ab2 }, ++ /* x^220160 mod p(x)` << 1, x^220224 mod p(x)` << 1 */ ++ { 0x00000001e7ca913a, 0x0000000114f87504 }, ++ /* x^219136 mod p(x)` << 1, x^219200 mod p(x)` << 1 */ ++ { 0x0000000033ed078a, 0x000000004b076d96 }, ++ /* x^218112 mod p(x)` << 1, x^218176 mod p(x)` << 1 */ ++ { 0x00000000e1839c78, 0x00000000da4d1e74 }, ++ /* x^217088 mod p(x)` << 1, x^217152 mod p(x)` << 1 */ ++ { 0x00000001322b267e, 0x000000001b81f672 }, ++ /* x^216064 mod p(x)` << 1, x^216128 mod p(x)` << 1 */ ++ { 0x00000000638231b6, 0x000000009367c988 }, ++ /* x^215040 mod p(x)` << 1, x^215104 mod p(x)` << 1 */ ++ { 0x00000001ee7f16f4, 0x00000001717214ca }, ++ /* x^214016 mod p(x)` << 1, x^214080 mod p(x)` << 1 */ ++ { 0x0000000117d9924a, 0x000000009f47d820 }, ++ /* x^212992 mod p(x)` << 1, x^213056 mod p(x)` << 1 */ ++ { 0x00000000e1a9e0c4, 0x000000010d9a47d2 }, ++ /* x^211968 mod p(x)` << 1, x^212032 mod p(x)` << 1 */ ++ { 0x00000001403731dc, 0x00000000a696c58c }, ++ /* x^210944 mod p(x)` << 1, x^211008 mod p(x)` << 1 */ ++ { 0x00000001a5ea9682, 0x000000002aa28ec6 }, ++ /* x^209920 mod p(x)` << 1, x^209984 mod p(x)` << 1 */ ++ { 0x0000000101c5c578, 0x00000001fe18fd9a }, ++ /* x^208896 mod p(x)` << 1, x^208960 mod p(x)` << 1 */ ++ { 0x00000000dddf6494, 0x000000019d4fc1ae }, ++ /* x^207872 mod p(x)` << 1, x^207936 mod p(x)` << 1 */ ++ { 0x00000000f1c3db28, 0x00000001ba0e3dea }, ++ /* x^206848 mod p(x)` << 1, x^206912 mod p(x)` << 1 */ ++ { 0x000000013112fb9c, 0x0000000074b59a5e }, ++ /* x^205824 mod p(x)` << 1, x^205888 mod p(x)` << 1 */ ++ { 0x00000000b680b906, 0x00000000f2b5ea98 }, ++ /* x^204800 mod p(x)` << 1, x^204864 mod p(x)` << 1 */ ++ { 0x000000001a282932, 0x0000000187132676 }, ++ /* x^203776 mod p(x)` << 1, x^203840 mod p(x)` << 1 */ ++ { 0x0000000089406e7e, 0x000000010a8c6ad4 }, ++ /* x^202752 mod p(x)` << 1, x^202816 mod p(x)` << 1 */ ++ { 0x00000001def6be8c, 0x00000001e21dfe70 }, ++ /* x^201728 mod p(x)` << 1, x^201792 mod p(x)` << 1 */ ++ { 0x0000000075258728, 0x00000001da0050e4 }, ++ /* x^200704 mod p(x)` << 1, x^200768 mod p(x)` << 1 */ ++ { 0x000000019536090a, 0x00000000772172ae }, ++ /* x^199680 mod p(x)` << 1, x^199744 mod p(x)` << 1 */ ++ { 0x00000000f2455bfc, 0x00000000e47724aa }, ++ /* x^198656 mod p(x)` << 1, x^198720 mod p(x)` << 1 */ ++ { 0x000000018c40baf4, 0x000000003cd63ac4 }, ++ /* x^197632 mod p(x)` << 1, x^197696 mod p(x)` << 1 */ ++ { 0x000000004cd390d4, 0x00000001bf47d352 }, ++ /* x^196608 mod p(x)` << 1, x^196672 mod p(x)` << 1 */ ++ { 0x00000001e4ece95a, 0x000000018dc1d708 }, ++ /* x^195584 mod p(x)` << 1, x^195648 mod p(x)` << 1 */ ++ { 0x000000001a3ee918, 0x000000002d4620a4 }, ++ /* x^194560 mod p(x)` << 1, x^194624 mod p(x)` << 1 */ ++ { 0x000000007c652fb8, 0x0000000058fd1740 }, ++ /* x^193536 mod p(x)` << 1, x^193600 mod p(x)` << 1 */ ++ { 0x000000011c67842c, 0x00000000dadd9bfc }, ++ /* x^192512 mod p(x)` << 1, x^192576 mod p(x)` << 1 */ ++ { 0x00000000254f759c, 0x00000001ea2140be }, ++ /* x^191488 mod p(x)` << 1, x^191552 mod p(x)` << 1 */ ++ { 0x000000007ece94ca, 0x000000009de128ba }, ++ /* x^190464 mod p(x)` << 1, x^190528 mod p(x)` << 1 */ ++ { 0x0000000038f258c2, 0x000000013ac3aa8e }, ++ /* x^189440 mod p(x)` << 1, x^189504 mod p(x)` << 1 */ ++ { 0x00000001cdf17b00, 0x0000000099980562 }, ++ /* x^188416 mod p(x)` << 1, x^188480 mod p(x)` << 1 */ ++ { 0x000000011f882c16, 0x00000001c1579c86 }, ++ /* x^187392 mod p(x)` << 1, x^187456 mod p(x)` << 1 */ ++ { 0x0000000100093fc8, 0x0000000068dbbf94 }, ++ /* x^186368 mod p(x)` << 1, x^186432 mod p(x)` << 1 */ ++ { 0x00000001cd684f16, 0x000000004509fb04 }, ++ /* x^185344 mod p(x)` << 1, x^185408 mod p(x)` << 1 */ ++ { 0x000000004bc6a70a, 0x00000001202f6398 }, ++ /* x^184320 mod p(x)` << 1, x^184384 mod p(x)` << 1 */ ++ { 0x000000004fc7e8e4, 0x000000013aea243e }, ++ /* x^183296 mod p(x)` << 1, x^183360 mod p(x)` << 1 */ ++ { 0x0000000130103f1c, 0x00000001b4052ae6 }, ++ /* x^182272 mod p(x)` << 1, x^182336 mod p(x)` << 1 */ ++ { 0x0000000111b0024c, 0x00000001cd2a0ae8 }, ++ /* x^181248 mod p(x)` << 1, x^181312 mod p(x)` << 1 */ ++ { 0x000000010b3079da, 0x00000001fe4aa8b4 }, ++ /* x^180224 mod p(x)` << 1, x^180288 mod p(x)` << 1 */ ++ { 0x000000010192bcc2, 0x00000001d1559a42 }, ++ /* x^179200 mod p(x)` << 1, x^179264 mod p(x)` << 1 */ ++ { 0x0000000074838d50, 0x00000001f3e05ecc }, ++ /* x^178176 mod p(x)` << 1, x^178240 mod p(x)` << 1 */ ++ { 0x000000001b20f520, 0x0000000104ddd2cc }, ++ /* x^177152 mod p(x)` << 1, x^177216 mod p(x)` << 1 */ ++ { 0x0000000050c3590a, 0x000000015393153c }, ++ /* x^176128 mod p(x)` << 1, x^176192 mod p(x)` << 1 */ ++ { 0x00000000b41cac8e, 0x0000000057e942c6 }, ++ /* x^175104 mod p(x)` << 1, x^175168 mod p(x)` << 1 */ ++ { 0x000000000c72cc78, 0x000000012c633850 }, ++ /* x^174080 mod p(x)` << 1, x^174144 mod p(x)` << 1 */ ++ { 0x0000000030cdb032, 0x00000000ebcaae4c }, ++ /* x^173056 mod p(x)` << 1, x^173120 mod p(x)` << 1 */ ++ { 0x000000013e09fc32, 0x000000013ee532a6 }, ++ /* x^172032 mod p(x)` << 1, x^172096 mod p(x)` << 1 */ ++ { 0x000000001ed624d2, 0x00000001bf0cbc7e }, ++ /* x^171008 mod p(x)` << 1, x^171072 mod p(x)` << 1 */ ++ { 0x00000000781aee1a, 0x00000000d50b7a5a }, ++ /* x^169984 mod p(x)` << 1, x^170048 mod p(x)` << 1 */ ++ { 0x00000001c4d8348c, 0x0000000002fca6e8 }, ++ /* x^168960 mod p(x)` << 1, x^169024 mod p(x)` << 1 */ ++ { 0x0000000057a40336, 0x000000007af40044 }, ++ /* x^167936 mod p(x)` << 1, x^168000 mod p(x)` << 1 */ ++ { 0x0000000085544940, 0x0000000016178744 }, ++ /* x^166912 mod p(x)` << 1, x^166976 mod p(x)` << 1 */ ++ { 0x000000019cd21e80, 0x000000014c177458 }, ++ /* x^165888 mod p(x)` << 1, x^165952 mod p(x)` << 1 */ ++ { 0x000000013eb95bc0, 0x000000011b6ddf04 }, ++ /* x^164864 mod p(x)` << 1, x^164928 mod p(x)` << 1 */ ++ { 0x00000001dfc9fdfc, 0x00000001f3e29ccc }, ++ /* x^163840 mod p(x)` << 1, x^163904 mod p(x)` << 1 */ ++ { 0x00000000cd028bc2, 0x0000000135ae7562 }, ++ /* x^162816 mod p(x)` << 1, x^162880 mod p(x)` << 1 */ ++ { 0x0000000090db8c44, 0x0000000190ef812c }, ++ /* x^161792 mod p(x)` << 1, x^161856 mod p(x)` << 1 */ ++ { 0x000000010010a4ce, 0x0000000067a2c786 }, ++ /* x^160768 mod p(x)` << 1, x^160832 mod p(x)` << 1 */ ++ { 0x00000001c8f4c72c, 0x0000000048b9496c }, ++ /* x^159744 mod p(x)` << 1, x^159808 mod p(x)` << 1 */ ++ { 0x000000001c26170c, 0x000000015a422de6 }, ++ /* x^158720 mod p(x)` << 1, x^158784 mod p(x)` << 1 */ ++ { 0x00000000e3fccf68, 0x00000001ef0e3640 }, ++ /* x^157696 mod p(x)` << 1, x^157760 mod p(x)` << 1 */ ++ { 0x00000000d513ed24, 0x00000001006d2d26 }, ++ /* x^156672 mod p(x)` << 1, x^156736 mod p(x)` << 1 */ ++ { 0x00000000141beada, 0x00000001170d56d6 }, ++ /* x^155648 mod p(x)` << 1, x^155712 mod p(x)` << 1 */ ++ { 0x000000011071aea0, 0x00000000a5fb613c }, ++ /* x^154624 mod p(x)` << 1, x^154688 mod p(x)` << 1 */ ++ { 0x000000012e19080a, 0x0000000040bbf7fc }, ++ /* x^153600 mod p(x)` << 1, x^153664 mod p(x)` << 1 */ ++ { 0x0000000100ecf826, 0x000000016ac3a5b2 }, ++ /* x^152576 mod p(x)` << 1, x^152640 mod p(x)` << 1 */ ++ { 0x0000000069b09412, 0x00000000abf16230 }, ++ /* x^151552 mod p(x)` << 1, x^151616 mod p(x)` << 1 */ ++ { 0x0000000122297bac, 0x00000001ebe23fac }, ++ /* x^150528 mod p(x)` << 1, x^150592 mod p(x)` << 1 */ ++ { 0x00000000e9e4b068, 0x000000008b6a0894 }, ++ /* x^149504 mod p(x)` << 1, x^149568 mod p(x)` << 1 */ ++ { 0x000000004b38651a, 0x00000001288ea478 }, ++ /* x^148480 mod p(x)` << 1, x^148544 mod p(x)` << 1 */ ++ { 0x00000001468360e2, 0x000000016619c442 }, ++ /* x^147456 mod p(x)` << 1, x^147520 mod p(x)` << 1 */ ++ { 0x00000000121c2408, 0x0000000086230038 }, ++ /* x^146432 mod p(x)` << 1, x^146496 mod p(x)` << 1 */ ++ { 0x00000000da7e7d08, 0x000000017746a756 }, ++ /* x^145408 mod p(x)` << 1, x^145472 mod p(x)` << 1 */ ++ { 0x00000001058d7652, 0x0000000191b8f8f8 }, ++ /* x^144384 mod p(x)` << 1, x^144448 mod p(x)` << 1 */ ++ { 0x000000014a098a90, 0x000000008e167708 }, ++ /* x^143360 mod p(x)` << 1, x^143424 mod p(x)` << 1 */ ++ { 0x0000000020dbe72e, 0x0000000148b22d54 }, ++ /* x^142336 mod p(x)` << 1, x^142400 mod p(x)` << 1 */ ++ { 0x000000011e7323e8, 0x0000000044ba2c3c }, ++ /* x^141312 mod p(x)` << 1, x^141376 mod p(x)` << 1 */ ++ { 0x00000000d5d4bf94, 0x00000000b54d2b52 }, ++ /* x^140288 mod p(x)` << 1, x^140352 mod p(x)` << 1 */ ++ { 0x0000000199d8746c, 0x0000000005a4fd8a }, ++ /* x^139264 mod p(x)` << 1, x^139328 mod p(x)` << 1 */ ++ { 0x00000000ce9ca8a0, 0x0000000139f9fc46 }, ++ /* x^138240 mod p(x)` << 1, x^138304 mod p(x)` << 1 */ ++ { 0x00000000136edece, 0x000000015a1fa824 }, ++ /* x^137216 mod p(x)` << 1, x^137280 mod p(x)` << 1 */ ++ { 0x000000019b92a068, 0x000000000a61ae4c }, ++ /* x^136192 mod p(x)` << 1, x^136256 mod p(x)` << 1 */ ++ { 0x0000000071d62206, 0x0000000145e9113e }, ++ /* x^135168 mod p(x)` << 1, x^135232 mod p(x)` << 1 */ ++ { 0x00000000dfc50158, 0x000000006a348448 }, ++ /* x^134144 mod p(x)` << 1, x^134208 mod p(x)` << 1 */ ++ { 0x00000001517626bc, 0x000000004d80a08c }, ++ /* x^133120 mod p(x)` << 1, x^133184 mod p(x)` << 1 */ ++ { 0x0000000148d1e4fa, 0x000000014b6837a0 }, ++ /* x^132096 mod p(x)` << 1, x^132160 mod p(x)` << 1 */ ++ { 0x0000000094d8266e, 0x000000016896a7fc }, ++ /* x^131072 mod p(x)` << 1, x^131136 mod p(x)` << 1 */ ++ { 0x00000000606c5e34, 0x000000014f187140 }, ++ /* x^130048 mod p(x)` << 1, x^130112 mod p(x)` << 1 */ ++ { 0x000000019766beaa, 0x000000019581b9da }, ++ /* x^129024 mod p(x)` << 1, x^129088 mod p(x)` << 1 */ ++ { 0x00000001d80c506c, 0x00000001091bc984 }, ++ /* x^128000 mod p(x)` << 1, x^128064 mod p(x)` << 1 */ ++ { 0x000000001e73837c, 0x000000001067223c }, ++ /* x^126976 mod p(x)` << 1, x^127040 mod p(x)` << 1 */ ++ { 0x0000000064d587de, 0x00000001ab16ea02 }, ++ /* x^125952 mod p(x)` << 1, x^126016 mod p(x)` << 1 */ ++ { 0x00000000f4a507b0, 0x000000013c4598a8 }, ++ /* x^124928 mod p(x)` << 1, x^124992 mod p(x)` << 1 */ ++ { 0x0000000040e342fc, 0x00000000b3735430 }, ++ /* x^123904 mod p(x)` << 1, x^123968 mod p(x)` << 1 */ ++ { 0x00000001d5ad9c3a, 0x00000001bb3fc0c0 }, ++ /* x^122880 mod p(x)` << 1, x^122944 mod p(x)` << 1 */ ++ { 0x0000000094a691a4, 0x00000001570ae19c }, ++ /* x^121856 mod p(x)` << 1, x^121920 mod p(x)` << 1 */ ++ { 0x00000001271ecdfa, 0x00000001ea910712 }, ++ /* x^120832 mod p(x)` << 1, x^120896 mod p(x)` << 1 */ ++ { 0x000000009e54475a, 0x0000000167127128 }, ++ /* x^119808 mod p(x)` << 1, x^119872 mod p(x)` << 1 */ ++ { 0x00000000c9c099ee, 0x0000000019e790a2 }, ++ /* x^118784 mod p(x)` << 1, x^118848 mod p(x)` << 1 */ ++ { 0x000000009a2f736c, 0x000000003788f710 }, ++ /* x^117760 mod p(x)` << 1, x^117824 mod p(x)` << 1 */ ++ { 0x00000000bb9f4996, 0x00000001682a160e }, ++ /* x^116736 mod p(x)` << 1, x^116800 mod p(x)` << 1 */ ++ { 0x00000001db688050, 0x000000007f0ebd2e }, ++ /* x^115712 mod p(x)` << 1, x^115776 mod p(x)` << 1 */ ++ { 0x00000000e9b10af4, 0x000000002b032080 }, ++ /* x^114688 mod p(x)` << 1, x^114752 mod p(x)` << 1 */ ++ { 0x000000012d4545e4, 0x00000000cfd1664a }, ++ /* x^113664 mod p(x)` << 1, x^113728 mod p(x)` << 1 */ ++ { 0x000000000361139c, 0x00000000aa1181c2 }, ++ /* x^112640 mod p(x)` << 1, x^112704 mod p(x)` << 1 */ ++ { 0x00000001a5a1a3a8, 0x00000000ddd08002 }, ++ /* x^111616 mod p(x)` << 1, x^111680 mod p(x)` << 1 */ ++ { 0x000000006844e0b0, 0x00000000e8dd0446 }, ++ /* x^110592 mod p(x)` << 1, x^110656 mod p(x)` << 1 */ ++ { 0x00000000c3762f28, 0x00000001bbd94a00 }, ++ /* x^109568 mod p(x)` << 1, x^109632 mod p(x)` << 1 */ ++ { 0x00000001d26287a2, 0x00000000ab6cd180 }, ++ /* x^108544 mod p(x)` << 1, x^108608 mod p(x)` << 1 */ ++ { 0x00000001f6f0bba8, 0x0000000031803ce2 }, ++ /* x^107520 mod p(x)` << 1, x^107584 mod p(x)` << 1 */ ++ { 0x000000002ffabd62, 0x0000000024f40b0c }, ++ /* x^106496 mod p(x)` << 1, x^106560 mod p(x)` << 1 */ ++ { 0x00000000fb4516b8, 0x00000001ba1d9834 }, ++ /* x^105472 mod p(x)` << 1, x^105536 mod p(x)` << 1 */ ++ { 0x000000018cfa961c, 0x0000000104de61aa }, ++ /* x^104448 mod p(x)` << 1, x^104512 mod p(x)` << 1 */ ++ { 0x000000019e588d52, 0x0000000113e40d46 }, ++ /* x^103424 mod p(x)` << 1, x^103488 mod p(x)` << 1 */ ++ { 0x00000001180f0bbc, 0x00000001415598a0 }, ++ /* x^102400 mod p(x)` << 1, x^102464 mod p(x)` << 1 */ ++ { 0x00000000e1d9177a, 0x00000000bf6c8c90 }, ++ /* x^101376 mod p(x)` << 1, x^101440 mod p(x)` << 1 */ ++ { 0x0000000105abc27c, 0x00000001788b0504 }, ++ /* x^100352 mod p(x)` << 1, x^100416 mod p(x)` << 1 */ ++ { 0x00000000972e4a58, 0x0000000038385d02 }, ++ /* x^99328 mod p(x)` << 1, x^99392 mod p(x)` << 1 */ ++ { 0x0000000183499a5e, 0x00000001b6c83844 }, ++ /* x^98304 mod p(x)` << 1, x^98368 mod p(x)` << 1 */ ++ { 0x00000001c96a8cca, 0x0000000051061a8a }, ++ /* x^97280 mod p(x)` << 1, x^97344 mod p(x)` << 1 */ ++ { 0x00000001a1a5b60c, 0x000000017351388a }, ++ /* x^96256 mod p(x)` << 1, x^96320 mod p(x)` << 1 */ ++ { 0x00000000e4b6ac9c, 0x0000000132928f92 }, ++ /* x^95232 mod p(x)` << 1, x^95296 mod p(x)` << 1 */ ++ { 0x00000001807e7f5a, 0x00000000e6b4f48a }, ++ /* x^94208 mod p(x)` << 1, x^94272 mod p(x)` << 1 */ ++ { 0x000000017a7e3bc8, 0x0000000039d15e90 }, ++ /* x^93184 mod p(x)` << 1, x^93248 mod p(x)` << 1 */ ++ { 0x00000000d73975da, 0x00000000312d6074 }, ++ /* x^92160 mod p(x)` << 1, x^92224 mod p(x)` << 1 */ ++ { 0x000000017375d038, 0x000000017bbb2cc4 }, ++ /* x^91136 mod p(x)` << 1, x^91200 mod p(x)` << 1 */ ++ { 0x00000000193680bc, 0x000000016ded3e18 }, ++ /* x^90112 mod p(x)` << 1, x^90176 mod p(x)` << 1 */ ++ { 0x00000000999b06f6, 0x00000000f1638b16 }, ++ /* x^89088 mod p(x)` << 1, x^89152 mod p(x)` << 1 */ ++ { 0x00000001f685d2b8, 0x00000001d38b9ecc }, ++ /* x^88064 mod p(x)` << 1, x^88128 mod p(x)` << 1 */ ++ { 0x00000001f4ecbed2, 0x000000018b8d09dc }, ++ /* x^87040 mod p(x)` << 1, x^87104 mod p(x)` << 1 */ ++ { 0x00000000ba16f1a0, 0x00000000e7bc27d2 }, ++ /* x^86016 mod p(x)` << 1, x^86080 mod p(x)` << 1 */ ++ { 0x0000000115aceac4, 0x00000000275e1e96 }, ++ /* x^84992 mod p(x)` << 1, x^85056 mod p(x)` << 1 */ ++ { 0x00000001aeff6292, 0x00000000e2e3031e }, ++ /* x^83968 mod p(x)` << 1, x^84032 mod p(x)` << 1 */ ++ { 0x000000009640124c, 0x00000001041c84d8 }, ++ /* x^82944 mod p(x)` << 1, x^83008 mod p(x)` << 1 */ ++ { 0x0000000114f41f02, 0x00000000706ce672 }, ++ /* x^81920 mod p(x)` << 1, x^81984 mod p(x)` << 1 */ ++ { 0x000000009c5f3586, 0x000000015d5070da }, ++ /* x^80896 mod p(x)` << 1, x^80960 mod p(x)` << 1 */ ++ { 0x00000001878275fa, 0x0000000038f9493a }, ++ /* x^79872 mod p(x)` << 1, x^79936 mod p(x)` << 1 */ ++ { 0x00000000ddc42ce8, 0x00000000a3348a76 }, ++ /* x^78848 mod p(x)` << 1, x^78912 mod p(x)` << 1 */ ++ { 0x0000000181d2c73a, 0x00000001ad0aab92 }, ++ /* x^77824 mod p(x)` << 1, x^77888 mod p(x)` << 1 */ ++ { 0x0000000141c9320a, 0x000000019e85f712 }, ++ /* x^76800 mod p(x)` << 1, x^76864 mod p(x)` << 1 */ ++ { 0x000000015235719a, 0x000000005a871e76 }, ++ /* x^75776 mod p(x)` << 1, x^75840 mod p(x)` << 1 */ ++ { 0x00000000be27d804, 0x000000017249c662 }, ++ /* x^74752 mod p(x)` << 1, x^74816 mod p(x)` << 1 */ ++ { 0x000000006242d45a, 0x000000003a084712 }, ++ /* x^73728 mod p(x)` << 1, x^73792 mod p(x)` << 1 */ ++ { 0x000000009a53638e, 0x00000000ed438478 }, ++ /* x^72704 mod p(x)` << 1, x^72768 mod p(x)` << 1 */ ++ { 0x00000001001ecfb6, 0x00000000abac34cc }, ++ /* x^71680 mod p(x)` << 1, x^71744 mod p(x)` << 1 */ ++ { 0x000000016d7c2d64, 0x000000005f35ef3e }, ++ /* x^70656 mod p(x)` << 1, x^70720 mod p(x)` << 1 */ ++ { 0x00000001d0ce46c0, 0x0000000047d6608c }, ++ /* x^69632 mod p(x)` << 1, x^69696 mod p(x)` << 1 */ ++ { 0x0000000124c907b4, 0x000000002d01470e }, ++ /* x^68608 mod p(x)` << 1, x^68672 mod p(x)` << 1 */ ++ { 0x0000000018a555ca, 0x0000000158bbc7b0 }, ++ /* x^67584 mod p(x)` << 1, x^67648 mod p(x)` << 1 */ ++ { 0x000000006b0980bc, 0x00000000c0a23e8e }, ++ /* x^66560 mod p(x)` << 1, x^66624 mod p(x)` << 1 */ ++ { 0x000000008bbba964, 0x00000001ebd85c88 }, ++ /* x^65536 mod p(x)` << 1, x^65600 mod p(x)` << 1 */ ++ { 0x00000001070a5a1e, 0x000000019ee20bb2 }, ++ /* x^64512 mod p(x)` << 1, x^64576 mod p(x)` << 1 */ ++ { 0x000000002204322a, 0x00000001acabf2d6 }, ++ /* x^63488 mod p(x)` << 1, x^63552 mod p(x)` << 1 */ ++ { 0x00000000a27524d0, 0x00000001b7963d56 }, ++ /* x^62464 mod p(x)` << 1, x^62528 mod p(x)` << 1 */ ++ { 0x0000000020b1e4ba, 0x000000017bffa1fe }, ++ /* x^61440 mod p(x)` << 1, x^61504 mod p(x)` << 1 */ ++ { 0x0000000032cc27fc, 0x000000001f15333e }, ++ /* x^60416 mod p(x)` << 1, x^60480 mod p(x)` << 1 */ ++ { 0x0000000044dd22b8, 0x000000018593129e }, ++ /* x^59392 mod p(x)` << 1, x^59456 mod p(x)` << 1 */ ++ { 0x00000000dffc9e0a, 0x000000019cb32602 }, ++ /* x^58368 mod p(x)` << 1, x^58432 mod p(x)` << 1 */ ++ { 0x00000001b7a0ed14, 0x0000000142b05cc8 }, ++ /* x^57344 mod p(x)` << 1, x^57408 mod p(x)` << 1 */ ++ { 0x00000000c7842488, 0x00000001be49e7a4 }, ++ /* x^56320 mod p(x)` << 1, x^56384 mod p(x)` << 1 */ ++ { 0x00000001c02a4fee, 0x0000000108f69d6c }, ++ /* x^55296 mod p(x)` << 1, x^55360 mod p(x)` << 1 */ ++ { 0x000000003c273778, 0x000000006c0971f0 }, ++ /* x^54272 mod p(x)` << 1, x^54336 mod p(x)` << 1 */ ++ { 0x00000001d63f8894, 0x000000005b16467a }, ++ /* x^53248 mod p(x)` << 1, x^53312 mod p(x)` << 1 */ ++ { 0x000000006be557d6, 0x00000001551a628e }, ++ /* x^52224 mod p(x)` << 1, x^52288 mod p(x)` << 1 */ ++ { 0x000000006a7806ea, 0x000000019e42ea92 }, ++ /* x^51200 mod p(x)` << 1, x^51264 mod p(x)` << 1 */ ++ { 0x000000016155aa0c, 0x000000012fa83ff2 }, ++ /* x^50176 mod p(x)` << 1, x^50240 mod p(x)` << 1 */ ++ { 0x00000000908650ac, 0x000000011ca9cde0 }, ++ /* x^49152 mod p(x)` << 1, x^49216 mod p(x)` << 1 */ ++ { 0x00000000aa5a8084, 0x00000000c8e5cd74 }, ++ /* x^48128 mod p(x)` << 1, x^48192 mod p(x)` << 1 */ ++ { 0x0000000191bb500a, 0x0000000096c27f0c }, ++ /* x^47104 mod p(x)` << 1, x^47168 mod p(x)` << 1 */ ++ { 0x0000000064e9bed0, 0x000000002baed926 }, ++ /* x^46080 mod p(x)` << 1, x^46144 mod p(x)` << 1 */ ++ { 0x000000009444f302, 0x000000017c8de8d2 }, ++ /* x^45056 mod p(x)` << 1, x^45120 mod p(x)` << 1 */ ++ { 0x000000019db07d3c, 0x00000000d43d6068 }, ++ /* x^44032 mod p(x)` << 1, x^44096 mod p(x)` << 1 */ ++ { 0x00000001359e3e6e, 0x00000000cb2c4b26 }, ++ /* x^43008 mod p(x)` << 1, x^43072 mod p(x)` << 1 */ ++ { 0x00000001e4f10dd2, 0x0000000145b8da26 }, ++ /* x^41984 mod p(x)` << 1, x^42048 mod p(x)` << 1 */ ++ { 0x0000000124f5735e, 0x000000018fff4b08 }, ++ /* x^40960 mod p(x)` << 1, x^41024 mod p(x)` << 1 */ ++ { 0x0000000124760a4c, 0x0000000150b58ed0 }, ++ /* x^39936 mod p(x)` << 1, x^40000 mod p(x)` << 1 */ ++ { 0x000000000f1fc186, 0x00000001549f39bc }, ++ /* x^38912 mod p(x)` << 1, x^38976 mod p(x)` << 1 */ ++ { 0x00000000150e4cc4, 0x00000000ef4d2f42 }, ++ /* x^37888 mod p(x)` << 1, x^37952 mod p(x)` << 1 */ ++ { 0x000000002a6204e8, 0x00000001b1468572 }, ++ /* x^36864 mod p(x)` << 1, x^36928 mod p(x)` << 1 */ ++ { 0x00000000beb1d432, 0x000000013d7403b2 }, ++ /* x^35840 mod p(x)` << 1, x^35904 mod p(x)` << 1 */ ++ { 0x0000000135f3f1f0, 0x00000001a4681842 }, ++ /* x^34816 mod p(x)` << 1, x^34880 mod p(x)` << 1 */ ++ { 0x0000000074fe2232, 0x0000000167714492 }, ++ /* x^33792 mod p(x)` << 1, x^33856 mod p(x)` << 1 */ ++ { 0x000000001ac6e2ba, 0x00000001e599099a }, ++ /* x^32768 mod p(x)` << 1, x^32832 mod p(x)` << 1 */ ++ { 0x0000000013fca91e, 0x00000000fe128194 }, ++ /* x^31744 mod p(x)` << 1, x^31808 mod p(x)` << 1 */ ++ { 0x0000000183f4931e, 0x0000000077e8b990 }, ++ /* x^30720 mod p(x)` << 1, x^30784 mod p(x)` << 1 */ ++ { 0x00000000b6d9b4e4, 0x00000001a267f63a }, ++ /* x^29696 mod p(x)` << 1, x^29760 mod p(x)` << 1 */ ++ { 0x00000000b5188656, 0x00000001945c245a }, ++ /* x^28672 mod p(x)` << 1, x^28736 mod p(x)` << 1 */ ++ { 0x0000000027a81a84, 0x0000000149002e76 }, ++ /* x^27648 mod p(x)` << 1, x^27712 mod p(x)` << 1 */ ++ { 0x0000000125699258, 0x00000001bb8310a4 }, ++ /* x^26624 mod p(x)` << 1, x^26688 mod p(x)` << 1 */ ++ { 0x00000001b23de796, 0x000000019ec60bcc }, ++ /* x^25600 mod p(x)` << 1, x^25664 mod p(x)` << 1 */ ++ { 0x00000000fe4365dc, 0x000000012d8590ae }, ++ /* x^24576 mod p(x)` << 1, x^24640 mod p(x)` << 1 */ ++ { 0x00000000c68f497a, 0x0000000065b00684 }, ++ /* x^23552 mod p(x)` << 1, x^23616 mod p(x)` << 1 */ ++ { 0x00000000fbf521ee, 0x000000015e5aeadc }, ++ /* x^22528 mod p(x)` << 1, x^22592 mod p(x)` << 1 */ ++ { 0x000000015eac3378, 0x00000000b77ff2b0 }, ++ /* x^21504 mod p(x)` << 1, x^21568 mod p(x)` << 1 */ ++ { 0x0000000134914b90, 0x0000000188da2ff6 }, ++ /* x^20480 mod p(x)` << 1, x^20544 mod p(x)` << 1 */ ++ { 0x0000000016335cfe, 0x0000000063da929a }, ++ /* x^19456 mod p(x)` << 1, x^19520 mod p(x)` << 1 */ ++ { 0x000000010372d10c, 0x00000001389caa80 }, ++ /* x^18432 mod p(x)` << 1, x^18496 mod p(x)` << 1 */ ++ { 0x000000015097b908, 0x000000013db599d2 }, ++ /* x^17408 mod p(x)` << 1, x^17472 mod p(x)` << 1 */ ++ { 0x00000001227a7572, 0x0000000122505a86 }, ++ /* x^16384 mod p(x)` << 1, x^16448 mod p(x)` << 1 */ ++ { 0x000000009a8f75c0, 0x000000016bd72746 }, ++ /* x^15360 mod p(x)` << 1, x^15424 mod p(x)` << 1 */ ++ { 0x00000000682c77a2, 0x00000001c3faf1d4 }, ++ /* x^14336 mod p(x)` << 1, x^14400 mod p(x)` << 1 */ ++ { 0x00000000231f091c, 0x00000001111c826c }, ++ /* x^13312 mod p(x)` << 1, x^13376 mod p(x)` << 1 */ ++ { 0x000000007d4439f2, 0x00000000153e9fb2 }, ++ /* x^12288 mod p(x)` << 1, x^12352 mod p(x)` << 1 */ ++ { 0x000000017e221efc, 0x000000002b1f7b60 }, ++ /* x^11264 mod p(x)` << 1, x^11328 mod p(x)` << 1 */ ++ { 0x0000000167457c38, 0x00000000b1dba570 }, ++ /* x^10240 mod p(x)` << 1, x^10304 mod p(x)` << 1 */ ++ { 0x00000000bdf081c4, 0x00000001f6397b76 }, ++ /* x^9216 mod p(x)` << 1, x^9280 mod p(x)` << 1 */ ++ { 0x000000016286d6b0, 0x0000000156335214 }, ++ /* x^8192 mod p(x)` << 1, x^8256 mod p(x)` << 1 */ ++ { 0x00000000c84f001c, 0x00000001d70e3986 }, ++ /* x^7168 mod p(x)` << 1, x^7232 mod p(x)` << 1 */ ++ { 0x0000000064efe7c0, 0x000000003701a774 }, ++ /* x^6144 mod p(x)` << 1, x^6208 mod p(x)` << 1 */ ++ { 0x000000000ac2d904, 0x00000000ac81ef72 }, ++ /* x^5120 mod p(x)` << 1, x^5184 mod p(x)` << 1 */ ++ { 0x00000000fd226d14, 0x0000000133212464 }, ++ /* x^4096 mod p(x)` << 1, x^4160 mod p(x)` << 1 */ ++ { 0x000000011cfd42e0, 0x00000000e4e45610 }, ++ /* x^3072 mod p(x)` << 1, x^3136 mod p(x)` << 1 */ ++ { 0x000000016e5a5678, 0x000000000c1bd370 }, ++ /* x^2048 mod p(x)` << 1, x^2112 mod p(x)` << 1 */ ++ { 0x00000001d888fe22, 0x00000001a7b9e7a6 }, ++ /* x^1024 mod p(x)` << 1, x^1088 mod p(x)` << 1 */ ++ { 0x00000001af77fcd4, 0x000000007d657a10 } ++#endif /* __LITTLE_ENDIAN__ */ ++ }; ++ ++/* Reduce final 1024-2048 bits to 64 bits, shifting 32 bits to include the trailing 32 bits of zeros */ ++ ++static const __vector unsigned long long vcrc_short_const[16] ++ __attribute__((aligned (16))) = { ++#ifdef __LITTLE_ENDIAN__ ++ /* x^1952 mod p(x) , x^1984 mod p(x) , x^2016 mod p(x) , x^2048 mod p(x) */ ++ { 0x99168a18ec447f11, 0xed837b2613e8221e }, ++ /* x^1824 mod p(x) , x^1856 mod p(x) , x^1888 mod p(x) , x^1920 mod p(x) */ ++ { 0xe23e954e8fd2cd3c, 0xc8acdd8147b9ce5a }, ++ /* x^1696 mod p(x) , x^1728 mod p(x) , x^1760 mod p(x) , x^1792 mod p(x) */ ++ { 0x92f8befe6b1d2b53, 0xd9ad6d87d4277e25 }, ++ /* x^1568 mod p(x) , x^1600 mod p(x) , x^1632 mod p(x) , x^1664 mod p(x) */ ++ { 0xf38a3556291ea462, 0xc10ec5e033fbca3b }, ++ /* x^1440 mod p(x) , x^1472 mod p(x) , x^1504 mod p(x) , x^1536 mod p(x) */ ++ { 0x974ac56262b6ca4b, 0xc0b55b0e82e02e2f }, ++ /* x^1312 mod p(x) , x^1344 mod p(x) , x^1376 mod p(x) , x^1408 mod p(x) */ ++ { 0x855712b3784d2a56, 0x71aa1df0e172334d }, ++ /* x^1184 mod p(x) , x^1216 mod p(x) , x^1248 mod p(x) , x^1280 mod p(x) */ ++ { 0xa5abe9f80eaee722, 0xfee3053e3969324d }, ++ /* x^1056 mod p(x) , x^1088 mod p(x) , x^1120 mod p(x) , x^1152 mod p(x) */ ++ { 0x1fa0943ddb54814c, 0xf44779b93eb2bd08 }, ++ /* x^928 mod p(x) , x^960 mod p(x) , x^992 mod p(x) , x^1024 mod p(x) */ ++ { 0xa53ff440d7bbfe6a, 0xf5449b3f00cc3374 }, ++ /* x^800 mod p(x) , x^832 mod p(x) , x^864 mod p(x) , x^896 mod p(x) */ ++ { 0xebe7e3566325605c, 0x6f8346e1d777606e }, ++ /* x^672 mod p(x) , x^704 mod p(x) , x^736 mod p(x) , x^768 mod p(x) */ ++ { 0xc65a272ce5b592b8, 0xe3ab4f2ac0b95347 }, ++ /* x^544 mod p(x) , x^576 mod p(x) , x^608 mod p(x) , x^640 mod p(x) */ ++ { 0x5705a9ca4721589f, 0xaa2215ea329ecc11 }, ++ /* x^416 mod p(x) , x^448 mod p(x) , x^480 mod p(x) , x^512 mod p(x) */ ++ { 0xe3720acb88d14467, 0x1ed8f66ed95efd26 }, ++ /* x^288 mod p(x) , x^320 mod p(x) , x^352 mod p(x) , x^384 mod p(x) */ ++ { 0xba1aca0315141c31, 0x78ed02d5a700e96a }, ++ /* x^160 mod p(x) , x^192 mod p(x) , x^224 mod p(x) , x^256 mod p(x) */ ++ { 0xad2a31b3ed627dae, 0xba8ccbe832b39da3 }, ++ /* x^32 mod p(x) , x^64 mod p(x) , x^96 mod p(x) , x^128 mod p(x) */ ++ { 0x6655004fa06a2517, 0xedb88320b1e6b092 } ++#else /* __LITTLE_ENDIAN__ */ ++ /* x^1952 mod p(x) , x^1984 mod p(x) , x^2016 mod p(x) , x^2048 mod p(x) */ ++ { 0xed837b2613e8221e, 0x99168a18ec447f11 }, ++ /* x^1824 mod p(x) , x^1856 mod p(x) , x^1888 mod p(x) , x^1920 mod p(x) */ ++ { 0xc8acdd8147b9ce5a, 0xe23e954e8fd2cd3c }, ++ /* x^1696 mod p(x) , x^1728 mod p(x) , x^1760 mod p(x) , x^1792 mod p(x) */ ++ { 0xd9ad6d87d4277e25, 0x92f8befe6b1d2b53 }, ++ /* x^1568 mod p(x) , x^1600 mod p(x) , x^1632 mod p(x) , x^1664 mod p(x) */ ++ { 0xc10ec5e033fbca3b, 0xf38a3556291ea462 }, ++ /* x^1440 mod p(x) , x^1472 mod p(x) , x^1504 mod p(x) , x^1536 mod p(x) */ ++ { 0xc0b55b0e82e02e2f, 0x974ac56262b6ca4b }, ++ /* x^1312 mod p(x) , x^1344 mod p(x) , x^1376 mod p(x) , x^1408 mod p(x) */ ++ { 0x71aa1df0e172334d, 0x855712b3784d2a56 }, ++ /* x^1184 mod p(x) , x^1216 mod p(x) , x^1248 mod p(x) , x^1280 mod p(x) */ ++ { 0xfee3053e3969324d, 0xa5abe9f80eaee722 }, ++ /* x^1056 mod p(x) , x^1088 mod p(x) , x^1120 mod p(x) , x^1152 mod p(x) */ ++ { 0xf44779b93eb2bd08, 0x1fa0943ddb54814c }, ++ /* x^928 mod p(x) , x^960 mod p(x) , x^992 mod p(x) , x^1024 mod p(x) */ ++ { 0xf5449b3f00cc3374, 0xa53ff440d7bbfe6a }, ++ /* x^800 mod p(x) , x^832 mod p(x) , x^864 mod p(x) , x^896 mod p(x) */ ++ { 0x6f8346e1d777606e, 0xebe7e3566325605c }, ++ /* x^672 mod p(x) , x^704 mod p(x) , x^736 mod p(x) , x^768 mod p(x) */ ++ { 0xe3ab4f2ac0b95347, 0xc65a272ce5b592b8 }, ++ /* x^544 mod p(x) , x^576 mod p(x) , x^608 mod p(x) , x^640 mod p(x) */ ++ { 0xaa2215ea329ecc11, 0x5705a9ca4721589f }, ++ /* x^416 mod p(x) , x^448 mod p(x) , x^480 mod p(x) , x^512 mod p(x) */ ++ { 0x1ed8f66ed95efd26, 0xe3720acb88d14467 }, ++ /* x^288 mod p(x) , x^320 mod p(x) , x^352 mod p(x) , x^384 mod p(x) */ ++ { 0x78ed02d5a700e96a, 0xba1aca0315141c31 }, ++ /* x^160 mod p(x) , x^192 mod p(x) , x^224 mod p(x) , x^256 mod p(x) */ ++ { 0xba8ccbe832b39da3, 0xad2a31b3ed627dae }, ++ /* x^32 mod p(x) , x^64 mod p(x) , x^96 mod p(x) , x^128 mod p(x) */ ++ { 0xedb88320b1e6b092, 0x6655004fa06a2517 } ++#endif /* __LITTLE_ENDIAN__ */ ++ }; ++ ++/* Barrett constants */ ++/* 33 bit reflected Barrett constant m - (4^32)/n */ ++ ++static const __vector unsigned long long v_Barrett_const[2] ++ __attribute__((aligned (16))) = { ++ /* x^64 div p(x) */ ++#ifdef __LITTLE_ENDIAN__ ++ { 0x00000001f7011641, 0x0000000000000000 }, ++ { 0x00000001db710641, 0x0000000000000000 } ++#else /* __LITTLE_ENDIAN__ */ ++ { 0x0000000000000000, 0x00000001f7011641 }, ++ { 0x0000000000000000, 0x00000001db710641 } ++#endif /* __LITTLE_ENDIAN__ */ ++ }; ++#endif /* POWER8_INTRINSICS */ ++ ++#endif /* __ASSEMBLER__ */ +diff --git a/contrib/power/crc32_z_power8.c b/contrib/power/crc32_z_power8.c +new file mode 100644 +index 0000000..7858cfe +--- /dev/null ++++ b/contrib/power/crc32_z_power8.c +@@ -0,0 +1,679 @@ ++/* ++ * Calculate the checksum of data that is 16 byte aligned and a multiple of ++ * 16 bytes. ++ * ++ * The first step is to reduce it to 1024 bits. We do this in 8 parallel ++ * chunks in order to mask the latency of the vpmsum instructions. If we ++ * have more than 32 kB of data to checksum we repeat this step multiple ++ * times, passing in the previous 1024 bits. ++ * ++ * The next step is to reduce the 1024 bits to 64 bits. This step adds ++ * 32 bits of 0s to the end - this matches what a CRC does. We just ++ * calculate constants that land the data in this 32 bits. ++ * ++ * We then use fixed point Barrett reduction to compute a mod n over GF(2) ++ * for n = CRC using POWER8 instructions. We use x = 32. ++ * ++ * http://en.wikipedia.org/wiki/Barrett_reduction ++ * ++ * This code uses gcc vector builtins instead using assembly directly. ++ * ++ * Copyright (C) 2017 Rogerio Alves , IBM ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of either: ++ * ++ * a) the GNU General Public License as published by the Free Software ++ * Foundation; either version 2 of the License, or (at your option) ++ * any later version, or ++ * b) the Apache License, Version 2.0 ++ */ ++ ++#include ++#include "../../zutil.h" ++#include "power.h" ++ ++#define POWER8_INTRINSICS ++#define CRC_TABLE ++ ++#ifdef CRC32_CONSTANTS_HEADER ++#include CRC32_CONSTANTS_HEADER ++#else ++#include "crc32_constants.h" ++#endif ++ ++#define VMX_ALIGN 16 ++#define VMX_ALIGN_MASK (VMX_ALIGN-1) ++ ++#ifdef REFLECT ++static unsigned int crc32_align(unsigned int crc, const unsigned char *p, ++ unsigned long len) ++{ ++ while (len--) ++ crc = crc_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); ++ return crc; ++} ++#else ++static unsigned int crc32_align(unsigned int crc, const unsigned char *p, ++ unsigned long len) ++{ ++ while (len--) ++ crc = crc_table[((crc >> 24) ^ *p++) & 0xff] ^ (crc << 8); ++ return crc; ++} ++#endif ++ ++static unsigned int __attribute__ ((aligned (32))) ++__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len); ++ ++unsigned long ZLIB_INTERNAL _crc32_z_power8(uLong _crc, const Bytef *_p, ++ z_size_t _len) ++{ ++ unsigned int prealign; ++ unsigned int tail; ++ ++ /* Map zlib API to crc32_vpmsum API */ ++ unsigned int crc = (unsigned int) (0xffffffff & _crc); ++ const unsigned char *p = _p; ++ unsigned long len = (unsigned long) _len; ++ ++ if (p == (const unsigned char *) 0x0) return 0; ++#ifdef CRC_XOR ++ crc ^= 0xffffffff; ++#endif ++ ++ if (len < VMX_ALIGN + VMX_ALIGN_MASK) { ++ crc = crc32_align(crc, p, len); ++ goto out; ++ } ++ ++ if ((unsigned long)p & VMX_ALIGN_MASK) { ++ prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK); ++ crc = crc32_align(crc, p, prealign); ++ len -= prealign; ++ p += prealign; ++ } ++ ++ crc = __crc32_vpmsum(crc, p, len & ~VMX_ALIGN_MASK); ++ ++ tail = len & VMX_ALIGN_MASK; ++ if (tail) { ++ p += len & ~VMX_ALIGN_MASK; ++ crc = crc32_align(crc, p, tail); ++ } ++ ++out: ++#ifdef CRC_XOR ++ crc ^= 0xffffffff; ++#endif ++ ++ /* Convert to zlib API */ ++ return (unsigned long) crc; ++} ++ ++#if defined (__clang__) ++#include "clang_workaround.h" ++#else ++#define __builtin_pack_vector(a, b) __builtin_pack_vector_int128 ((a), (b)) ++#define __builtin_unpack_vector_0(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 0) ++#define __builtin_unpack_vector_1(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 1) ++#endif ++ ++/* When we have a load-store in a single-dispatch group and address overlap ++ * such that foward is not allowed (load-hit-store) the group must be flushed. ++ * A group ending NOP prevents the flush. ++ */ ++#define GROUP_ENDING_NOP asm("ori 2,2,0" ::: "memory") ++ ++#if defined(__BIG_ENDIAN__) && defined (REFLECT) ++#define BYTESWAP_DATA ++#elif defined(__LITTLE_ENDIAN__) && !defined(REFLECT) ++#define BYTESWAP_DATA ++#endif ++ ++#ifdef BYTESWAP_DATA ++#define VEC_PERM(vr, va, vb, vc) vr = vec_perm(va, vb,\ ++ (__vector unsigned char) vc) ++#if defined(__LITTLE_ENDIAN__) ++/* Byte reverse permute constant LE. */ ++static const __vector unsigned long long vperm_const ++ __attribute__ ((aligned(16))) = { 0x08090A0B0C0D0E0FUL, ++ 0x0001020304050607UL }; ++#else ++static const __vector unsigned long long vperm_const ++ __attribute__ ((aligned(16))) = { 0x0F0E0D0C0B0A0908UL, ++ 0X0706050403020100UL }; ++#endif ++#else ++#define VEC_PERM(vr, va, vb, vc) ++#endif ++ ++static unsigned int __attribute__ ((aligned (32))) ++__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len) { ++ ++ const __vector unsigned long long vzero = {0,0}; ++ const __vector unsigned long long vones = {0xffffffffffffffffUL, ++ 0xffffffffffffffffUL}; ++ ++#ifdef REFLECT ++ const __vector unsigned long long vmask_32bit = ++ (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, ++ (__vector unsigned char)vones, 4); ++#endif ++ ++ const __vector unsigned long long vmask_64bit = ++ (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, ++ (__vector unsigned char)vones, 8); ++ ++ __vector unsigned long long vcrc; ++ ++ __vector unsigned long long vconst1, vconst2; ++ ++ /* vdata0-vdata7 will contain our data (p). */ ++ __vector unsigned long long vdata0, vdata1, vdata2, vdata3, vdata4, ++ vdata5, vdata6, vdata7; ++ ++ /* v0-v7 will contain our checksums */ ++ __vector unsigned long long v0 = {0,0}; ++ __vector unsigned long long v1 = {0,0}; ++ __vector unsigned long long v2 = {0,0}; ++ __vector unsigned long long v3 = {0,0}; ++ __vector unsigned long long v4 = {0,0}; ++ __vector unsigned long long v5 = {0,0}; ++ __vector unsigned long long v6 = {0,0}; ++ __vector unsigned long long v7 = {0,0}; ++ ++ ++ /* Vector auxiliary variables. */ ++ __vector unsigned long long va0, va1, va2, va3, va4, va5, va6, va7; ++ ++ unsigned int result = 0; ++ unsigned int offset; /* Constant table offset. */ ++ ++ unsigned long i; /* Counter. */ ++ unsigned long chunks; ++ ++ unsigned long block_size; ++ int next_block = 0; ++ ++ /* Align by 128 bits. The last 128 bit block will be processed at end. */ ++ unsigned long length = len & 0xFFFFFFFFFFFFFF80UL; ++ ++#ifdef REFLECT ++ vcrc = (__vector unsigned long long)__builtin_pack_vector(0UL, crc); ++#else ++ vcrc = (__vector unsigned long long)__builtin_pack_vector(crc, 0UL); ++ ++ /* Shift into top 32 bits */ ++ vcrc = (__vector unsigned long long)vec_sld((__vector unsigned char)vcrc, ++ (__vector unsigned char)vzero, 4); ++#endif ++ ++ /* Short version. */ ++ if (len < 256) { ++ /* Calculate where in the constant table we need to start. */ ++ offset = 256 - len; ++ ++ vconst1 = vec_ld(offset, vcrc_short_const); ++ vdata0 = vec_ld(0, (__vector unsigned long long*) p); ++ VEC_PERM(vdata0, vdata0, vconst1, vperm_const); ++ ++ /* xor initial value*/ ++ vdata0 = vec_xor(vdata0, vcrc); ++ ++ vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw ++ ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); ++ v0 = vec_xor(v0, vdata0); ++ ++ for (i = 16; i < len; i += 16) { ++ vconst1 = vec_ld(offset + i, vcrc_short_const); ++ vdata0 = vec_ld(i, (__vector unsigned long long*) p); ++ VEC_PERM(vdata0, vdata0, vconst1, vperm_const); ++ vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw ++ ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); ++ v0 = vec_xor(v0, vdata0); ++ } ++ } else { ++ ++ /* Load initial values. */ ++ vdata0 = vec_ld(0, (__vector unsigned long long*) p); ++ vdata1 = vec_ld(16, (__vector unsigned long long*) p); ++ ++ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); ++ VEC_PERM(vdata1, vdata1, vdata1, vperm_const); ++ ++ vdata2 = vec_ld(32, (__vector unsigned long long*) p); ++ vdata3 = vec_ld(48, (__vector unsigned long long*) p); ++ ++ VEC_PERM(vdata2, vdata2, vdata2, vperm_const); ++ VEC_PERM(vdata3, vdata3, vdata3, vperm_const); ++ ++ vdata4 = vec_ld(64, (__vector unsigned long long*) p); ++ vdata5 = vec_ld(80, (__vector unsigned long long*) p); ++ ++ VEC_PERM(vdata4, vdata4, vdata4, vperm_const); ++ VEC_PERM(vdata5, vdata5, vdata5, vperm_const); ++ ++ vdata6 = vec_ld(96, (__vector unsigned long long*) p); ++ vdata7 = vec_ld(112, (__vector unsigned long long*) p); ++ ++ VEC_PERM(vdata6, vdata6, vdata6, vperm_const); ++ VEC_PERM(vdata7, vdata7, vdata7, vperm_const); ++ ++ /* xor in initial value */ ++ vdata0 = vec_xor(vdata0, vcrc); ++ ++ p = (char *)p + 128; ++ ++ do { ++ /* Checksum in blocks of MAX_SIZE. */ ++ block_size = length; ++ if (block_size > MAX_SIZE) { ++ block_size = MAX_SIZE; ++ } ++ ++ length = length - block_size; ++ ++ /* ++ * Work out the offset into the constants table to start at. Each ++ * constant is 16 bytes, and it is used against 128 bytes of input ++ * data - 128 / 16 = 8 ++ */ ++ offset = (MAX_SIZE/8) - (block_size/8); ++ /* We reduce our final 128 bytes in a separate step */ ++ chunks = (block_size/128)-1; ++ ++ vconst1 = vec_ld(offset, vcrc_const); ++ ++ va0 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata0, ++ (__vector unsigned long long)vconst1); ++ va1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata1, ++ (__vector unsigned long long)vconst1); ++ va2 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata2, ++ (__vector unsigned long long)vconst1); ++ va3 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata3, ++ (__vector unsigned long long)vconst1); ++ va4 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata4, ++ (__vector unsigned long long)vconst1); ++ va5 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata5, ++ (__vector unsigned long long)vconst1); ++ va6 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata6, ++ (__vector unsigned long long)vconst1); ++ va7 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata7, ++ (__vector unsigned long long)vconst1); ++ ++ if (chunks > 1) { ++ offset += 16; ++ vconst2 = vec_ld(offset, vcrc_const); ++ GROUP_ENDING_NOP; ++ ++ vdata0 = vec_ld(0, (__vector unsigned long long*) p); ++ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); ++ ++ vdata1 = vec_ld(16, (__vector unsigned long long*) p); ++ VEC_PERM(vdata1, vdata1, vdata1, vperm_const); ++ ++ vdata2 = vec_ld(32, (__vector unsigned long long*) p); ++ VEC_PERM(vdata2, vdata2, vdata2, vperm_const); ++ ++ vdata3 = vec_ld(48, (__vector unsigned long long*) p); ++ VEC_PERM(vdata3, vdata3, vdata3, vperm_const); ++ ++ vdata4 = vec_ld(64, (__vector unsigned long long*) p); ++ VEC_PERM(vdata4, vdata4, vdata4, vperm_const); ++ ++ vdata5 = vec_ld(80, (__vector unsigned long long*) p); ++ VEC_PERM(vdata5, vdata5, vdata5, vperm_const); ++ ++ vdata6 = vec_ld(96, (__vector unsigned long long*) p); ++ VEC_PERM(vdata6, vdata6, vdata6, vperm_const); ++ ++ vdata7 = vec_ld(112, (__vector unsigned long long*) p); ++ VEC_PERM(vdata7, vdata7, vdata7, vperm_const); ++ ++ p = (char *)p + 128; ++ ++ /* ++ * main loop. We modulo schedule it such that it takes three ++ * iterations to complete - first iteration load, second ++ * iteration vpmsum, third iteration xor. ++ */ ++ for (i = 0; i < chunks-2; i++) { ++ vconst1 = vec_ld(offset, vcrc_const); ++ offset += 16; ++ GROUP_ENDING_NOP; ++ ++ v0 = vec_xor(v0, va0); ++ va0 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata0, (__vector unsigned long long)vconst2); ++ vdata0 = vec_ld(0, (__vector unsigned long long*) p); ++ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); ++ GROUP_ENDING_NOP; ++ ++ v1 = vec_xor(v1, va1); ++ va1 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata1, (__vector unsigned long long)vconst2); ++ vdata1 = vec_ld(16, (__vector unsigned long long*) p); ++ VEC_PERM(vdata1, vdata1, vdata1, vperm_const); ++ GROUP_ENDING_NOP; ++ ++ v2 = vec_xor(v2, va2); ++ va2 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata2, (__vector unsigned long long)vconst2); ++ vdata2 = vec_ld(32, (__vector unsigned long long*) p); ++ VEC_PERM(vdata2, vdata2, vdata2, vperm_const); ++ GROUP_ENDING_NOP; ++ ++ v3 = vec_xor(v3, va3); ++ va3 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata3, (__vector unsigned long long)vconst2); ++ vdata3 = vec_ld(48, (__vector unsigned long long*) p); ++ VEC_PERM(vdata3, vdata3, vdata3, vperm_const); ++ ++ vconst2 = vec_ld(offset, vcrc_const); ++ GROUP_ENDING_NOP; ++ ++ v4 = vec_xor(v4, va4); ++ va4 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata4, (__vector unsigned long long)vconst1); ++ vdata4 = vec_ld(64, (__vector unsigned long long*) p); ++ VEC_PERM(vdata4, vdata4, vdata4, vperm_const); ++ GROUP_ENDING_NOP; ++ ++ v5 = vec_xor(v5, va5); ++ va5 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata5, (__vector unsigned long long)vconst1); ++ vdata5 = vec_ld(80, (__vector unsigned long long*) p); ++ VEC_PERM(vdata5, vdata5, vdata5, vperm_const); ++ GROUP_ENDING_NOP; ++ ++ v6 = vec_xor(v6, va6); ++ va6 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata6, (__vector unsigned long long)vconst1); ++ vdata6 = vec_ld(96, (__vector unsigned long long*) p); ++ VEC_PERM(vdata6, vdata6, vdata6, vperm_const); ++ GROUP_ENDING_NOP; ++ ++ v7 = vec_xor(v7, va7); ++ va7 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata7, (__vector unsigned long long)vconst1); ++ vdata7 = vec_ld(112, (__vector unsigned long long*) p); ++ VEC_PERM(vdata7, vdata7, vdata7, vperm_const); ++ ++ p = (char *)p + 128; ++ } ++ ++ /* First cool down*/ ++ vconst1 = vec_ld(offset, vcrc_const); ++ offset += 16; ++ ++ v0 = vec_xor(v0, va0); ++ va0 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata0, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v1 = vec_xor(v1, va1); ++ va1 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata1, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v2 = vec_xor(v2, va2); ++ va2 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata2, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v3 = vec_xor(v3, va3); ++ va3 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata3, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v4 = vec_xor(v4, va4); ++ va4 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata4, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v5 = vec_xor(v5, va5); ++ va5 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata5, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v6 = vec_xor(v6, va6); ++ va6 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata6, (__vector unsigned long long)vconst1); ++ GROUP_ENDING_NOP; ++ ++ v7 = vec_xor(v7, va7); ++ va7 = __builtin_crypto_vpmsumd ((__vector unsigned long ++ long)vdata7, (__vector unsigned long long)vconst1); ++ }/* else */ ++ ++ /* Second cool down. */ ++ v0 = vec_xor(v0, va0); ++ v1 = vec_xor(v1, va1); ++ v2 = vec_xor(v2, va2); ++ v3 = vec_xor(v3, va3); ++ v4 = vec_xor(v4, va4); ++ v5 = vec_xor(v5, va5); ++ v6 = vec_xor(v6, va6); ++ v7 = vec_xor(v7, va7); ++ ++#ifdef REFLECT ++ /* ++ * vpmsumd produces a 96 bit result in the least significant bits ++ * of the register. Since we are bit reflected we have to shift it ++ * left 32 bits so it occupies the least significant bits in the ++ * bit reflected domain. ++ */ ++ v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, ++ (__vector unsigned char)vzero, 4); ++ v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v1, ++ (__vector unsigned char)vzero, 4); ++ v2 = (__vector unsigned long long)vec_sld((__vector unsigned char)v2, ++ (__vector unsigned char)vzero, 4); ++ v3 = (__vector unsigned long long)vec_sld((__vector unsigned char)v3, ++ (__vector unsigned char)vzero, 4); ++ v4 = (__vector unsigned long long)vec_sld((__vector unsigned char)v4, ++ (__vector unsigned char)vzero, 4); ++ v5 = (__vector unsigned long long)vec_sld((__vector unsigned char)v5, ++ (__vector unsigned char)vzero, 4); ++ v6 = (__vector unsigned long long)vec_sld((__vector unsigned char)v6, ++ (__vector unsigned char)vzero, 4); ++ v7 = (__vector unsigned long long)vec_sld((__vector unsigned char)v7, ++ (__vector unsigned char)vzero, 4); ++#endif ++ ++ /* xor with the last 1024 bits. */ ++ va0 = vec_ld(0, (__vector unsigned long long*) p); ++ VEC_PERM(va0, va0, va0, vperm_const); ++ ++ va1 = vec_ld(16, (__vector unsigned long long*) p); ++ VEC_PERM(va1, va1, va1, vperm_const); ++ ++ va2 = vec_ld(32, (__vector unsigned long long*) p); ++ VEC_PERM(va2, va2, va2, vperm_const); ++ ++ va3 = vec_ld(48, (__vector unsigned long long*) p); ++ VEC_PERM(va3, va3, va3, vperm_const); ++ ++ va4 = vec_ld(64, (__vector unsigned long long*) p); ++ VEC_PERM(va4, va4, va4, vperm_const); ++ ++ va5 = vec_ld(80, (__vector unsigned long long*) p); ++ VEC_PERM(va5, va5, va5, vperm_const); ++ ++ va6 = vec_ld(96, (__vector unsigned long long*) p); ++ VEC_PERM(va6, va6, va6, vperm_const); ++ ++ va7 = vec_ld(112, (__vector unsigned long long*) p); ++ VEC_PERM(va7, va7, va7, vperm_const); ++ ++ p = (char *)p + 128; ++ ++ vdata0 = vec_xor(v0, va0); ++ vdata1 = vec_xor(v1, va1); ++ vdata2 = vec_xor(v2, va2); ++ vdata3 = vec_xor(v3, va3); ++ vdata4 = vec_xor(v4, va4); ++ vdata5 = vec_xor(v5, va5); ++ vdata6 = vec_xor(v6, va6); ++ vdata7 = vec_xor(v7, va7); ++ ++ /* Check if we have more blocks to process */ ++ next_block = 0; ++ if (length != 0) { ++ next_block = 1; ++ ++ /* zero v0-v7 */ ++ v0 = vec_xor(v0, v0); ++ v1 = vec_xor(v1, v1); ++ v2 = vec_xor(v2, v2); ++ v3 = vec_xor(v3, v3); ++ v4 = vec_xor(v4, v4); ++ v5 = vec_xor(v5, v5); ++ v6 = vec_xor(v6, v6); ++ v7 = vec_xor(v7, v7); ++ } ++ length = length + 128; ++ ++ } while (next_block); ++ ++ /* Calculate how many bytes we have left. */ ++ length = (len & 127); ++ ++ /* Calculate where in (short) constant table we need to start. */ ++ offset = 128 - length; ++ ++ v0 = vec_ld(offset, vcrc_short_const); ++ v1 = vec_ld(offset + 16, vcrc_short_const); ++ v2 = vec_ld(offset + 32, vcrc_short_const); ++ v3 = vec_ld(offset + 48, vcrc_short_const); ++ v4 = vec_ld(offset + 64, vcrc_short_const); ++ v5 = vec_ld(offset + 80, vcrc_short_const); ++ v6 = vec_ld(offset + 96, vcrc_short_const); ++ v7 = vec_ld(offset + 112, vcrc_short_const); ++ ++ offset += 128; ++ ++ v0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata0,(__vector unsigned int)v0); ++ v1 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata1,(__vector unsigned int)v1); ++ v2 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata2,(__vector unsigned int)v2); ++ v3 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata3,(__vector unsigned int)v3); ++ v4 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata4,(__vector unsigned int)v4); ++ v5 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata5,(__vector unsigned int)v5); ++ v6 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata6,(__vector unsigned int)v6); ++ v7 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata7,(__vector unsigned int)v7); ++ ++ /* Now reduce the tail (0-112 bytes). */ ++ for (i = 0; i < length; i+=16) { ++ vdata0 = vec_ld(i,(__vector unsigned long long*)p); ++ VEC_PERM(vdata0, vdata0, vdata0, vperm_const); ++ va0 = vec_ld(offset + i,vcrc_short_const); ++ va0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( ++ (__vector unsigned int)vdata0,(__vector unsigned int)va0); ++ v0 = vec_xor(v0, va0); ++ } ++ ++ /* xor all parallel chunks together. */ ++ v0 = vec_xor(v0, v1); ++ v2 = vec_xor(v2, v3); ++ v4 = vec_xor(v4, v5); ++ v6 = vec_xor(v6, v7); ++ ++ v0 = vec_xor(v0, v2); ++ v4 = vec_xor(v4, v6); ++ ++ v0 = vec_xor(v0, v4); ++ } ++ ++ /* Barrett Reduction */ ++ vconst1 = vec_ld(0, v_Barrett_const); ++ vconst2 = vec_ld(16, v_Barrett_const); ++ ++ v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, ++ (__vector unsigned char)v0, 8); ++ v0 = vec_xor(v1,v0); ++ ++#ifdef REFLECT ++ /* shift left one bit */ ++ __vector unsigned char vsht_splat = vec_splat_u8 (1); ++ v0 = (__vector unsigned long long)vec_sll ((__vector unsigned char)v0, ++ vsht_splat); ++#endif ++ ++ v0 = vec_and(v0, vmask_64bit); ++ ++#ifndef REFLECT ++ ++ /* ++ * Now for the actual algorithm. The idea is to calculate q, ++ * the multiple of our polynomial that we need to subtract. By ++ * doing the computation 2x bits higher (ie 64 bits) and shifting the ++ * result back down 2x bits, we round down to the nearest multiple. ++ */ ++ ++ /* ma */ ++ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v0, ++ (__vector unsigned long long)vconst1); ++ /* q = floor(ma/(2^64)) */ ++ v1 = (__vector unsigned long long)vec_sld ((__vector unsigned char)vzero, ++ (__vector unsigned char)v1, 8); ++ /* qn */ ++ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, ++ (__vector unsigned long long)vconst2); ++ /* a - qn, subtraction is xor in GF(2) */ ++ v0 = vec_xor (v0, v1); ++ /* ++ * Get the result into r3. We need to shift it left 8 bytes: ++ * V0 [ 0 1 2 X ] ++ * V0 [ 0 X 2 3 ] ++ */ ++ result = __builtin_unpack_vector_1 (v0); ++#else ++ ++ /* ++ * The reflected version of Barrett reduction. Instead of bit ++ * reflecting our data (which is expensive to do), we bit reflect our ++ * constants and our algorithm, which means the intermediate data in ++ * our vector registers goes from 0-63 instead of 63-0. We can reflect ++ * the algorithm because we don't carry in mod 2 arithmetic. ++ */ ++ ++ /* bottom 32 bits of a */ ++ v1 = vec_and(v0, vmask_32bit); ++ ++ /* ma */ ++ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, ++ (__vector unsigned long long)vconst1); ++ ++ /* bottom 32bits of ma */ ++ v1 = vec_and(v1, vmask_32bit); ++ /* qn */ ++ v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, ++ (__vector unsigned long long)vconst2); ++ /* a - qn, subtraction is xor in GF(2) */ ++ v0 = vec_xor (v0, v1); ++ ++ /* ++ * Since we are bit reflected, the result (ie the low 32 bits) is in ++ * the high 32 bits. We just need to shift it left 4 bytes ++ * V0 [ 0 1 X 3 ] ++ * V0 [ 0 X 2 3 ] ++ */ ++ ++ /* shift result into top 64 bits of */ ++ v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, ++ (__vector unsigned char)vzero, 4); ++ ++ result = __builtin_unpack_vector_0 (v0); ++#endif ++ ++ return result; ++} +diff --git a/contrib/power/crc32_z_resolver.c b/contrib/power/crc32_z_resolver.c +new file mode 100644 +index 0000000..f4e9aa4 +--- /dev/null ++++ b/contrib/power/crc32_z_resolver.c +@@ -0,0 +1,15 @@ ++/* Copyright (C) 2019 Matheus Castanho , IBM ++ * For conditions of distribution and use, see copyright notice in zlib.h ++ */ ++ ++#include "../gcc/zifunc.h" ++#include "power.h" ++ ++Z_IFUNC(crc32_z) { ++#ifdef Z_POWER8 ++ if (__builtin_cpu_supports("arch_2_07")) ++ return _crc32_z_power8; ++#endif ++ ++ return crc32_z_default; ++} +diff --git a/contrib/power/power.h b/contrib/power/power.h +index b42c7d6..79123aa 100644 +--- a/contrib/power/power.h ++++ b/contrib/power/power.h +@@ -2,3 +2,7 @@ + * 2019 Rogerio Alves , IBM + * For conditions of distribution and use, see copyright notice in zlib.h + */ ++ ++#include "../../zconf.h" ++ ++unsigned long _crc32_z_power8(unsigned long, const Bytef *, z_size_t); +diff --git a/crc32.c b/crc32.c +index 6c38f5c..5589d54 100644 +--- a/crc32.c ++++ b/crc32.c +@@ -691,6 +691,13 @@ local z_word_t crc_word_big(z_word_t data) { + #endif + + /* ========================================================================= */ ++#ifdef Z_POWER_OPT ++/* Rename function so resolver can use its symbol. The default version will be ++ * returned by the resolver if the host has no support for an optimized version. ++ */ ++#define crc32_z crc32_z_default ++#endif /* Z_POWER_OPT */ ++ + unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { + /* Return initial CRC, if requested. */ +@@ -1009,6 +1016,11 @@ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + return crc ^ 0xffffffff; + } + ++#ifdef Z_POWER_OPT ++#undef crc32_z ++#include "contrib/power/crc32_z_resolver.c" ++#endif /* Z_POWER_OPT */ ++ + #endif + + /* ========================================================================= */ +diff --git a/test/crc32_test.c b/test/crc32_test.c +new file mode 100644 +index 0000000..3155553 +--- /dev/null ++++ b/test/crc32_test.c +@@ -0,0 +1,205 @@ ++/* crc32_tes.c -- unit test for crc32 in the zlib compression library ++ * Copyright (C) 1995-2006, 2010, 2011, 2016, 2019 Rogerio Alves ++ * For conditions of distribution and use, see copyright notice in zlib.h ++ */ ++ ++#include "zlib.h" ++#include ++ ++#ifdef STDC ++# include ++# include ++#endif ++ ++void test_crc32 OF((uLong crc, Byte* buf, z_size_t len, uLong chk, int line)); ++int main OF((void)); ++ ++typedef struct { ++ int line; ++ uLong crc; ++ char* buf; ++ int len; ++ uLong expect; ++} crc32_test; ++ ++void test_crc32(crc, buf, len, chk, line) ++ uLong crc; ++ Byte *buf; ++ z_size_t len; ++ uLong chk; ++ int line; ++{ ++ uLong res = crc32(crc, buf, len); ++ if (res != chk) { ++ fprintf(stderr, "FAIL [%d]: crc32 returned 0x%08X expected 0x%08X\n", ++ line, (unsigned int)res, (unsigned int)chk); ++ exit(1); ++ } ++} ++ ++static const crc32_test tests[] = { ++ {__LINE__, 0x0, 0x0, 0, 0x0}, ++ {__LINE__, 0xffffffff, 0x0, 0, 0x0}, ++ {__LINE__, 0x0, 0x0, 255, 0x0}, /* BZ 174799. */ ++ {__LINE__, 0x0, 0x0, 256, 0x0}, ++ {__LINE__, 0x0, 0x0, 257, 0x0}, ++ {__LINE__, 0x0, 0x0, 32767, 0x0}, ++ {__LINE__, 0x0, 0x0, 32768, 0x0}, ++ {__LINE__, 0x0, 0x0, 32769, 0x0}, ++ {__LINE__, 0x0, "", 0, 0x0}, ++ {__LINE__, 0xffffffff, "", 0, 0xffffffff}, ++ {__LINE__, 0x0, "abacus", 6, 0xc3d7115b}, ++ {__LINE__, 0x0, "backlog", 7, 0x269205}, ++ {__LINE__, 0x0, "campfire", 8, 0x22a515f8}, ++ {__LINE__, 0x0, "delta", 5, 0x9643fed9}, ++ {__LINE__, 0x0, "executable", 10, 0xd68eda01}, ++ {__LINE__, 0x0, "file", 4, 0x8c9f3610}, ++ {__LINE__, 0x0, "greatest", 8, 0xc1abd6cd}, ++ {__LINE__, 0x0, "hello", 5, 0x3610a686}, ++ {__LINE__, 0x0, "inverter", 8, 0xc9e962c9}, ++ {__LINE__, 0x0, "jigsaw", 6, 0xce4e3f69}, ++ {__LINE__, 0x0, "karate", 6, 0x890be0e2}, ++ {__LINE__, 0x0, "landscape", 9, 0xc4e0330b}, ++ {__LINE__, 0x0, "machine", 7, 0x1505df84}, ++ {__LINE__, 0x0, "nanometer", 9, 0xd4e19f39}, ++ {__LINE__, 0x0, "oblivion", 8, 0xdae9de77}, ++ {__LINE__, 0x0, "panama", 6, 0x66b8979c}, ++ {__LINE__, 0x0, "quest", 5, 0x4317f817}, ++ {__LINE__, 0x0, "resource", 8, 0xbc91f416}, ++ {__LINE__, 0x0, "secret", 6, 0x5ca2e8e5}, ++ {__LINE__, 0x0, "test", 4, 0xd87f7e0c}, ++ {__LINE__, 0x0, "ultimate", 8, 0x3fc79b0b}, ++ {__LINE__, 0x0, "vector", 6, 0x1b6e485b}, ++ {__LINE__, 0x0, "walrus", 6, 0xbe769b97}, ++ {__LINE__, 0x0, "xeno", 4, 0xe7a06444}, ++ {__LINE__, 0x0, "yelling", 7, 0xfe3944e5}, ++ {__LINE__, 0x0, "zlib", 4, 0x73887d3a}, ++ {__LINE__, 0x0, "4BJD7PocN1VqX0jXVpWB", 20, 0xd487a5a1}, ++ {__LINE__, 0x0, "F1rPWI7XvDs6nAIRx41l", 20, 0x61a0132e}, ++ {__LINE__, 0x0, "ldhKlsVkPFOveXgkGtC2", 20, 0xdf02f76}, ++ {__LINE__, 0x0, "5KKnGOOrs8BvJ35iKTOS", 20, 0x579b2b0a}, ++ {__LINE__, 0x0, "0l1tw7GOcem06Ddu7yn4", 20, 0xf7d16e2d}, ++ {__LINE__, 0x0, "MCr47CjPIn9R1IvE1Tm5", 20, 0x731788f5}, ++ {__LINE__, 0x0, "UcixbzPKTIv0SvILHVdO", 20, 0x7112bb11}, ++ {__LINE__, 0x0, "dGnAyAhRQDsWw0ESou24", 20, 0xf32a0dac}, ++ {__LINE__, 0x0, "di0nvmY9UYMYDh0r45XT", 20, 0x625437bb}, ++ {__LINE__, 0x0, "2XKDwHfAhFsV0RhbqtvH", 20, 0x896930f9}, ++ {__LINE__, 0x0, "ZhrANFIiIvRnqClIVyeD", 20, 0x8579a37}, ++ {__LINE__, 0x0, "v7Q9ehzioTOVeDIZioT1", 20, 0x632aa8e0}, ++ {__LINE__, 0x0, "Yod5hEeKcYqyhfXbhxj2", 20, 0xc829af29}, ++ {__LINE__, 0x0, "GehSWY2ay4uUKhehXYb0", 20, 0x1b08b7e8}, ++ {__LINE__, 0x0, "kwytJmq6UqpflV8Y8GoE", 20, 0x4e33b192}, ++ {__LINE__, 0x0, "70684206568419061514", 20, 0x59a179f0}, ++ {__LINE__, 0x0, "42015093765128581010", 20, 0xcd1013d7}, ++ {__LINE__, 0x0, "88214814356148806939", 20, 0xab927546}, ++ {__LINE__, 0x0, "43472694284527343838", 20, 0x11f3b20c}, ++ {__LINE__, 0x0, "49769333513942933689", 20, 0xd562d4ca}, ++ {__LINE__, 0x0, "54979784887993251199", 20, 0x233395f7}, ++ {__LINE__, 0x0, "58360544869206793220", 20, 0x2d167fd5}, ++ {__LINE__, 0x0, "27347953487840714234", 20, 0x8b5108ba}, ++ {__LINE__, 0x0, "07650690295365319082", 20, 0xc46b3cd8}, ++ {__LINE__, 0x0, "42655507906821911703", 20, 0xc10b2662}, ++ {__LINE__, 0x0, "29977409200786225655", 20, 0xc9a0f9d2}, ++ {__LINE__, 0x0, "85181542907229116674", 20, 0x9341357b}, ++ {__LINE__, 0x0, "87963594337989416799", 20, 0xf0424937}, ++ {__LINE__, 0x0, "21395988329504168551", 20, 0xd7c4c31f}, ++ {__LINE__, 0x0, "51991013580943379423", 20, 0xf11edcc4}, ++ {__LINE__, 0x0, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x40795df4}, ++ {__LINE__, 0x0, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0xdd61a631}, ++ {__LINE__, 0x0, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xca907a99}, ++ {__LINE__, 0x0, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0xf652deac}, ++ {__LINE__, 0x0, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0xaf39a5a9}, ++ {__LINE__, 0x0, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x6bebb4cf}, ++ {__LINE__, 0x0, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0x76430bac}, ++ {__LINE__, 0x0, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x6c80c388}, ++ {__LINE__, 0x0, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xd54d977d}, ++ {__LINE__, 0x0, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0xe3966ad5}, ++ {__LINE__, 0x0, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xe7c71db9}, ++ {__LINE__, 0x0, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xeaa52777}, ++ {__LINE__, 0x0, "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 100, 0xcd472048}, ++ {__LINE__, 0x7a30360d, "abacus", 6, 0xf8655a84}, ++ {__LINE__, 0x6fd767ee, "backlog", 7, 0x1ed834b1}, ++ {__LINE__, 0xefeb7589, "campfire", 8, 0x686cfca}, ++ {__LINE__, 0x61cf7e6b, "delta", 5, 0x1554e4b1}, ++ {__LINE__, 0xdc712e2, "executable", 10, 0x761b4254}, ++ {__LINE__, 0xad23c7fd, "file", 4, 0x7abdd09b}, ++ {__LINE__, 0x85cb2317, "greatest", 8, 0x4ba91c6b}, ++ {__LINE__, 0x9eed31b0, "inverter", 8, 0xd5e78ba5}, ++ {__LINE__, 0xb94f34ca, "jigsaw", 6, 0x23649109}, ++ {__LINE__, 0xab058a2, "karate", 6, 0xc5591f41}, ++ {__LINE__, 0x5bff2b7a, "landscape", 9, 0xf10eb644}, ++ {__LINE__, 0x605c9a5f, "machine", 7, 0xbaa0a636}, ++ {__LINE__, 0x51bdeea5, "nanometer", 9, 0x6af89afb}, ++ {__LINE__, 0x85c21c79, "oblivion", 8, 0xecae222b}, ++ {__LINE__, 0x97216f56, "panama", 6, 0x47dffac4}, ++ {__LINE__, 0x18444af2, "quest", 5, 0x70c2fe36}, ++ {__LINE__, 0xbe6ce359, "resource", 8, 0x1471d925}, ++ {__LINE__, 0x843071f1, "secret", 6, 0x50c9a0db}, ++ {__LINE__, 0xf2480c60, "ultimate", 8, 0xf973daf8}, ++ {__LINE__, 0x2d2feb3d, "vector", 6, 0x344ac03d}, ++ {__LINE__, 0x7490310a, "walrus", 6, 0x6d1408ef}, ++ {__LINE__, 0x97d247d4, "xeno", 4, 0xe62670b5}, ++ {__LINE__, 0x93cf7599, "yelling", 7, 0x1b36da38}, ++ {__LINE__, 0x73c84278, "zlib", 4, 0x6432d127}, ++ {__LINE__, 0x228a87d1, "4BJD7PocN1VqX0jXVpWB", 20, 0x997107d0}, ++ {__LINE__, 0xa7a048d0, "F1rPWI7XvDs6nAIRx41l", 20, 0xdc567274}, ++ {__LINE__, 0x1f0ded40, "ldhKlsVkPFOveXgkGtC2", 20, 0xdcc63870}, ++ {__LINE__, 0xa804a62f, "5KKnGOOrs8BvJ35iKTOS", 20, 0x6926cffd}, ++ {__LINE__, 0x508fae6a, "0l1tw7GOcem06Ddu7yn4", 20, 0xb52b38bc}, ++ {__LINE__, 0xe5adaf4f, "MCr47CjPIn9R1IvE1Tm5", 20, 0xf83b8178}, ++ {__LINE__, 0x67136a40, "UcixbzPKTIv0SvILHVdO", 20, 0xc5213070}, ++ {__LINE__, 0xb00c4a10, "dGnAyAhRQDsWw0ESou24", 20, 0xbc7648b0}, ++ {__LINE__, 0x2e0c84b5, "di0nvmY9UYMYDh0r45XT", 20, 0xd8123a72}, ++ {__LINE__, 0x81238d44, "2XKDwHfAhFsV0RhbqtvH", 20, 0xd5ac5620}, ++ {__LINE__, 0xf853aa92, "ZhrANFIiIvRnqClIVyeD", 20, 0xceae099d}, ++ {__LINE__, 0x5a692325, "v7Q9ehzioTOVeDIZioT1", 20, 0xb07d2b24}, ++ {__LINE__, 0x3275b9f, "Yod5hEeKcYqyhfXbhxj2", 20, 0x24ce91df}, ++ {__LINE__, 0x38371feb, "GehSWY2ay4uUKhehXYb0", 20, 0x707b3b30}, ++ {__LINE__, 0xafc8bf62, "kwytJmq6UqpflV8Y8GoE", 20, 0x16abc6a9}, ++ {__LINE__, 0x9b07db73, "70684206568419061514", 20, 0xae1fb7b7}, ++ {__LINE__, 0xe75b214, "42015093765128581010", 20, 0xd4eecd2d}, ++ {__LINE__, 0x72d0fe6f, "88214814356148806939", 20, 0x4660ec7}, ++ {__LINE__, 0xf857a4b1, "43472694284527343838", 20, 0xfd8afdf7}, ++ {__LINE__, 0x54b8e14, "49769333513942933689", 20, 0xc6d1b5f2}, ++ {__LINE__, 0xd6aa5616, "54979784887993251199", 20, 0x32476461}, ++ {__LINE__, 0x11e63098, "58360544869206793220", 20, 0xd917cf1a}, ++ {__LINE__, 0xbe92385, "27347953487840714234", 20, 0x4ad14a12}, ++ {__LINE__, 0x49511de0, "07650690295365319082", 20, 0xe37b5c6c}, ++ {__LINE__, 0x3db13bc1, "42655507906821911703", 20, 0x7cc497f1}, ++ {__LINE__, 0xbb899bea, "29977409200786225655", 20, 0x99781bb2}, ++ {__LINE__, 0xf6cd9436, "85181542907229116674", 20, 0x132256a1}, ++ {__LINE__, 0x9109e6c3, "87963594337989416799", 20, 0xbfdb2c83}, ++ {__LINE__, 0x75770fc, "21395988329504168551", 20, 0x8d9d1e81}, ++ {__LINE__, 0x69b1d19b, "51991013580943379423", 20, 0x7b6d4404}, ++ {__LINE__, 0xc6132975, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x8619f010}, ++ {__LINE__, 0xd58cb00c, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0x15746ac3}, ++ {__LINE__, 0xb63b8caa, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xaccf812f}, ++ {__LINE__, 0x8a45a2b8, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0x78af45de}, ++ {__LINE__, 0xcbe95b78, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0x25b06b59}, ++ {__LINE__, 0x4ef8a54b, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x4ba0d08f}, ++ {__LINE__, 0x76ad267a, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0xe26b6aac}, ++ {__LINE__, 0x569e613c, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x7e2b0a66}, ++ {__LINE__, 0x36aa61da, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xb3430dc7}, ++ {__LINE__, 0xf67222df, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0x626c17a}, ++ {__LINE__, 0x74b34fd3, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xccf98060}, ++ {__LINE__, 0x351fd770, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xd8b95312}, ++ {__LINE__, 0xc45aef77, "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 100, 0xbb1c9912}, ++ {__LINE__, 0xc45aef77, "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" ++ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" ++ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" ++ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" ++ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&" ++ "h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 600, 0x888AFA5B} ++}; ++ ++static const int test_size = sizeof(tests) / sizeof(tests[0]); ++ ++int main(void) ++{ ++ int i; ++ for (i = 0; i < test_size; i++) { ++ test_crc32(tests[i].crc, (Byte*) tests[i].buf, tests[i].len, ++ tests[i].expect, tests[i].line); ++ } ++ return 0; ++} diff -Nru zlib-1.2.13.dfsg/debian/patches/power/fix-clang7-builtins.patch zlib-1.3.1.dfsg/debian/patches/power/fix-clang7-builtins.patch --- zlib-1.2.13.dfsg/debian/patches/power/fix-clang7-builtins.patch 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/power/fix-clang7-builtins.patch 2023-11-24 08:22:52.000000000 +0000 @@ -0,0 +1,62 @@ +From: Manjunath S Matti +Date: Thu, 14 Sep 2023 06:45:31 -0500 +Subject: Fix clang's behavior on versions >= 7 + +Clang 7 changed the behavior of vec_xxpermdi in order to match GCC's +behavior. After this change, code that used to work on Clang 6 stopped +to work on Clang >= 7. + +Tested on Clang 6, 7, 8 and 9. + +Reference: https://bugs.llvm.org/show_bug.cgi?id=38192 + +Signed-off-by: Tulio Magno Quites Machado Filho +Signed-off-by: Manjunath Matti + +Origin: i-iii/zlib, https://github.com/iii-i/zlib/commit/8aca10a8a5ddb397854eb9a443f29658d3e3e12e +--- + contrib/power/clang_workaround.h | 15 ++++++++++----- + 1 file changed, 10 insertions(+), 5 deletions(-) + +diff --git a/contrib/power/clang_workaround.h b/contrib/power/clang_workaround.h +index b5e7dae..915f7e5 100644 +--- a/contrib/power/clang_workaround.h ++++ b/contrib/power/clang_workaround.h +@@ -39,7 +39,12 @@ __vector unsigned long long __builtin_pack_vector (unsigned long __a, + return __v; + } + +-#ifndef vec_xxpermdi ++/* ++ * Clang 7 changed the behavior of vec_xxpermdi in order to provide the same ++ * behavior of GCC. That means code adapted to Clang >= 7 does not work on ++ * Clang <= 6. So, fallback to __builtin_unpack_vector() on Clang <= 6. ++ */ ++#if !defined vec_xxpermdi || __clang_major__ <= 6 + + static inline + unsigned long __builtin_unpack_vector (__vector unsigned long long __v, +@@ -62,9 +67,9 @@ static inline + unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v) + { + #if defined(__BIG_ENDIAN__) +- return vec_xxpermdi(__v, __v, 0x0)[1]; +- #else + return vec_xxpermdi(__v, __v, 0x0)[0]; ++ #else ++ return vec_xxpermdi(__v, __v, 0x3)[0]; + #endif + } + +@@ -72,9 +77,9 @@ static inline + unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v) + { + #if defined(__BIG_ENDIAN__) +- return vec_xxpermdi(__v, __v, 0x3)[1]; +- #else + return vec_xxpermdi(__v, __v, 0x3)[0]; ++ #else ++ return vec_xxpermdi(__v, __v, 0x0)[0]; + #endif + } + #endif /* vec_xxpermdi */ diff -Nru zlib-1.2.13.dfsg/debian/patches/power/indirect-func-macros.patch zlib-1.3.1.dfsg/debian/patches/power/indirect-func-macros.patch --- zlib-1.2.13.dfsg/debian/patches/power/indirect-func-macros.patch 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/power/indirect-func-macros.patch 2024-03-16 19:41:35.000000000 +0000 @@ -0,0 +1,297 @@ +From: Manjunath S Matti +Date: Thu, 14 Sep 2023 06:15:57 -0500 +Subject: Preparation for Power optimizations + +Optimized functions for Power will make use of GNU indirect functions, +an extension to support different implementations of the same function, +which can be selected during runtime. This will be used to provide +optimized functions for different processor versions. + +Since this is a GNU extension, we placed the definition of the Z_IFUNC +macro under `contrib/gcc`. This can be reused by other archs as well. + +Author: Matheus Castanho +Author: Rogerio Alves +Signed-off-by: Manjunath Matti + +Origin: iii-i/zlib, https://github.com/iii-i/zlib/commit/096441298ecd1c123f1d37c2b34d6b6bb3c42e93 + +Last-Update: 2024-03-16 +--- + CMakeLists.txt | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ + configure | 66 ++++++++++++++++++++++++++++++++++++++++++++++ + contrib/README.contrib | 8 ++++++ + contrib/gcc/zifunc.h | 60 ++++++++++++++++++++++++++++++++++++++++++ + contrib/power/power.h | 4 +++ + 5 files changed, 209 insertions(+) + create mode 100644 contrib/gcc/zifunc.h + create mode 100644 contrib/power/power.h + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7f1b69f..4456cd7 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -7,6 +7,8 @@ project(zlib C) + + option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) + ++option(POWER "Enable building power implementation") ++ + set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") + set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") + set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") +@@ -128,6 +130,75 @@ if(NOT MINGW) + ) + endif() + ++if(CMAKE_COMPILER_IS_GNUCC) ++ ++ # test to see if we can use a GNU indirect function to detect and load optimized code at runtime ++ CHECK_C_SOURCE_COMPILES(" ++ static int test_ifunc_native(void) ++ { ++ return 1; ++ } ++ static int (*(check_ifunc_native(void)))(void) ++ { ++ return test_ifunc_native; ++ } ++ int test_ifunc(void) __attribute__ ((ifunc (\"check_ifunc_native\"))); ++ int main(void) ++ { ++ return 0; ++ } ++ " HAS_C_ATTR_IFUNC) ++ ++ if(HAS_C_ATTR_IFUNC) ++ add_definitions(-DHAVE_IFUNC) ++ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/gcc/zifunc.h) ++ endif() ++ ++ if(POWER) ++ # Test to see if we can use the optimizations for Power ++ CHECK_C_SOURCE_COMPILES(" ++ #ifndef _ARCH_PPC ++ #error \"Target is not Power\" ++ #endif ++ #ifndef __BUILTIN_CPU_SUPPORTS__ ++ #error \"Target doesn't support __builtin_cpu_supports()\" ++ #endif ++ int main() { return 0; } ++ " HAS_POWER_SUPPORT) ++ ++ if(HAS_POWER_SUPPORT AND HAS_C_ATTR_IFUNC) ++ add_definitions(-DZ_POWER_OPT) ++ ++ set(CMAKE_REQUIRED_FLAGS -mcpu=power8) ++ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER8) ++ ++ if(POWER8) ++ add_definitions(-DZ_POWER8) ++ set(ZLIB_POWER8 ) ++ ++ set_source_files_properties( ++ ${ZLIB_POWER8} ++ PROPERTIES COMPILE_FLAGS -mcpu=power8) ++ endif() ++ ++ set(CMAKE_REQUIRED_FLAGS -mcpu=power9) ++ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER9) ++ ++ if(POWER9) ++ add_definitions(-DZ_POWER9) ++ set(ZLIB_POWER9 ) ++ ++ set_source_files_properties( ++ ${ZLIB_POWER9} ++ PROPERTIES COMPILE_FLAGS -mcpu=power9) ++ endif() ++ ++ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/power/power.h) ++ set(ZLIB_SRCS ${ZLIB_SRCS} ${ZLIB_POWER8} ${ZLIB_POWER9}) ++ endif() ++ endif() ++endif() ++ + # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) + string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" +diff --git a/configure b/configure +index cc867c9..e307a8d 100755 +--- a/configure ++++ b/configure +@@ -835,6 +835,72 @@ EOF + fi + fi + ++# test to see if we can use a gnu indirection function to detect and load optimized code at runtime ++echo >> configure.log ++cat > $test.c <> configure.log ++cat > $test.c < $test.c ++ ++ if tryboth $CC -c $CFLAGS -mcpu=power8 $test.c; then ++ POWER8="-DZ_POWER8" ++ PIC_OBJC="${PIC_OBJC}" ++ OBJC="${OBJC}" ++ echo "Checking for -mcpu=power8 support... Yes." | tee -a configure.log ++ else ++ echo "Checking for -mcpu=power8 support... No." | tee -a configure.log ++ fi ++ ++ if tryboth $CC -c $CFLAGS -mcpu=power9 $test.c; then ++ POWER9="-DZ_POWER9" ++ PIC_OBJC="${PIC_OBJC}" ++ OBJC="${OBJC}" ++ echo "Checking for -mcpu=power9 support... Yes." | tee -a configure.log ++ else ++ echo "Checking for -mcpu=power9 support... No." | tee -a configure.log ++ fi ++ ++ SFLAGS="${SFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT" ++ CFLAGS="${CFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT" ++ echo "Checking for Power optimizations support... Yes." | tee -a configure.log ++else ++ echo "Checking for Power optimizations support... No." | tee -a configure.log ++fi ++ + # show the results in the log + echo >> configure.log + echo ALL = $ALL >> configure.log +diff --git a/contrib/README.contrib b/contrib/README.contrib +index 5e5f950..c57b520 100644 +--- a/contrib/README.contrib ++++ b/contrib/README.contrib +@@ -11,6 +11,10 @@ ada/ by Dmitriy Anisimkov + blast/ by Mark Adler + Decompressor for output of PKWare Data Compression Library (DCL) + ++gcc/ by Matheus Castanho ++ and Rogerio Alves ++ Optimization helpers using GCC-specific extensions ++ + delphi/ by Cosmin Truta + Support for Delphi and C++ Builder + +@@ -42,6 +46,10 @@ minizip/ by Gilles Vollant + pascal/ by Bob Dellaca et al. + Support for Pascal + ++power/ by Matheus Castanho ++ and Rogerio Alves ++ Optimized functions for Power processors ++ + puff/ by Mark Adler + Small, low memory usage inflate. Also serves to provide an + unambiguous description of the deflate format. +diff --git a/contrib/gcc/zifunc.h b/contrib/gcc/zifunc.h +new file mode 100644 +index 0000000..daf4fe4 +--- /dev/null ++++ b/contrib/gcc/zifunc.h +@@ -0,0 +1,60 @@ ++/* Copyright (C) 2019 Matheus Castanho , IBM ++ * 2019 Rogerio Alves , IBM ++ * For conditions of distribution and use, see copyright notice in zlib.h ++ */ ++ ++#ifndef Z_IFUNC_H_ ++#define Z_IFUNC_H_ ++ ++/* Helpers for arch optimizations */ ++ ++#define Z_IFUNC(fname) \ ++ typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \ ++ local typeof(fname) *fname##_resolver(void) ++/* This is a helper macro to declare a resolver for an indirect function ++ * (ifunc). Let's say you have function ++ * ++ * int foo (int a); ++ * ++ * for which you want to provide different implementations, for example: ++ * ++ * int foo_clever (int a) { ++ * ... clever things ... ++ * } ++ * ++ * int foo_smart (int a) { ++ * ... smart things ... ++ * } ++ * ++ * You will have to declare foo() as an indirect function and also provide a ++ * resolver for it, to choose between foo_clever() and foo_smart() based on ++ * some criteria you define (e.g. processor features). ++ * ++ * Since most likely foo() has a default implementation somewhere in zlib, you ++ * may have to rename it so the 'foo' symbol can be used by the ifunc without ++ * conflicts. ++ * ++ * #define foo foo_default ++ * int foo (int a) { ++ * ... ++ * } ++ * #undef foo ++ * ++ * Now you just have to provide a resolver function to choose which function ++ * should be used (decided at runtime on the first call to foo()): ++ * ++ * Z_IFUNC(foo) { ++ * if (... some condition ...) ++ * return foo_clever; ++ * ++ * if (... other condition ...) ++ * return foo_smart; ++ * ++ * return foo_default; ++ * } ++ * ++ * All calls to foo() throughout the code can remain untouched, all the magic ++ * will be done by the linker using the resolver function. ++ */ ++ ++#endif /* Z_IFUNC_H_ */ +diff --git a/contrib/power/power.h b/contrib/power/power.h +new file mode 100644 +index 0000000..b42c7d6 +--- /dev/null ++++ b/contrib/power/power.h +@@ -0,0 +1,4 @@ ++/* Copyright (C) 2019 Matheus Castanho , IBM ++ * 2019 Rogerio Alves , IBM ++ * For conditions of distribution and use, see copyright notice in zlib.h ++ */ diff -Nru zlib-1.2.13.dfsg/debian/patches/s390x/add-accel-deflate.patch zlib-1.3.1.dfsg/debian/patches/s390x/add-accel-deflate.patch --- zlib-1.2.13.dfsg/debian/patches/s390x/add-accel-deflate.patch 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/s390x/add-accel-deflate.patch 2024-03-16 19:53:57.000000000 +0000 @@ -0,0 +1,2045 @@ +From: Ilya Leoshkevich +Date: Wed, 18 Jul 2018 13:14:07 +0200 +Subject: Add support for IBM Z hardware-accelerated deflate + +IBM Z mainframes starting from version z15 provide DFLTCC instruction, +which implements deflate algorithm in hardware with estimated +compression and decompression performance orders of magnitude faster +than the current zlib and ratio comparable with that of level 1. + +This patch adds DFLTCC support to zlib. It can be enabled using the +following build commands: + + $ ./configure --dfltcc + $ make + +When built like this, zlib would compress in hardware on level 1, and +in software on all other levels. Decompression will always happen in +hardware. In order to enable DFLTCC compression for levels 1-6 (i.e., +to make it used by default) one could either configure with +`--dfltcc-level-mask=0x7e` or `export DFLTCC_LEVEL_MASK=0x7e` at run +time. + +Two DFLTCC compression calls produce the same results only when they +both are made on machines of the same generation, and when the +respective buffers have the same offset relative to the start of the +page. Therefore care should be taken when using hardware compression +when reproducible results are desired. One such use case - reproducible +software builds - is handled explicitly: when the `SOURCE_DATE_EPOCH` +environment variable is set, the hardware compression is disabled. + +DFLTCC does not support every single zlib feature, in particular: + + * `inflate(Z_BLOCK)` and `inflate(Z_TREES)` + * `inflateMark()` + * `inflatePrime()` + * `inflateSyncPoint()` + +When used, these functions will either switch to software, or, in case +this is not possible, gracefully fail. + +This patch tries to add DFLTCC support in the least intrusive way. +All SystemZ-specific code is placed into a separate file, but +unfortunately there is still a noticeable amount of changes in the +main zlib code. Below is the summary of these changes. + +DFLTCC takes as arguments a parameter block, an input buffer, an output +buffer and a window. Since DFLTCC requires parameter block to be +doubleword-aligned, and it's reasonable to allocate it alongside +deflate and inflate states, The `ZALLOC_STATE()`, `ZFREE_STATE()` and +`ZCOPY_STATE()` macros are introduced in order to encapsulate the +allocation details. The same is true for window, for which +the `ZALLOC_WINDOW()` and `TRY_FREE_WINDOW()` macros are introduced. + +Software and hardware window formats do not match, therefore, +`deflateSetDictionary()`, `deflateGetDictionary()`, +`inflateSetDictionary()` and `inflateGetDictionary()` need special +handling, which is triggered using the new +`DEFLATE_SET_DICTIONARY_HOOK()`, `DEFLATE_GET_DICTIONARY_HOOK()`, +`INFLATE_SET_DICTIONARY_HOOK()` and `INFLATE_GET_DICTIONARY_HOOK()` +macros. + +`deflateResetKeep()` and `inflateResetKeep()` now update the DFLTCC +parameter block, which is allocated alongside zlib state, using +the new `DEFLATE_RESET_KEEP_HOOK()` and `INFLATE_RESET_KEEP_HOOK()` +macros. + +The new `DEFLATE_PARAMS_HOOK()` macro switches between the hardware +and the software deflate implementations when the `deflateParams()` +arguments demand this. + +The new `INFLATE_PRIME_HOOK()`, `INFLATE_MARK_HOOK()` and +`INFLATE_SYNC_POINT_HOOK()` macros make the respective unsupported +calls gracefully fail. + +The algorithm implemented in the hardware has different compression +ratio than the one implemented in software. In order for +`deflateBound()` to return the correct results for the hardware +implementation, the new `DEFLATE_BOUND_ADJUST_COMPLEN()` and +`DEFLATE_NEED_CONSERVATIVE_BOUND()` macros are introduced. + +Actual compression and decompression are handled by the new +`DEFLATE_HOOK()` and `INFLATE_TYPEDO_HOOK()` macros. Since inflation +with DFLTCC manages the window on its own, calling `updatewindow()` is +suppressed using the new `INFLATE_NEED_UPDATEWINDOW()` macro. + +In addition to the compression, DFLTCC computes the CRC-32 and Adler-32 +checksums, therefore, whenever it's used, the software checksumming is +suppressed using the new `DEFLATE_NEED_CHECKSUM()` and +`INFLATE_NEED_CHECKSUM()` macros. + +DFLTCC will refuse to write an End-of-block Symbol if there is no input +data, thus in some cases it is necessary to do this manually. In order +to achieve this, `send_bits()`, `bi_reverse()`, `bi_windup()` and +`flush_pending()` are promoted from `local` to `ZLIB_INTERNAL`. +Furthermore, since the block and the stream termination must be handled +in software as well, `enum block_state` is moved to `deflate.h`. + +Since the first call to `dfltcc_inflate()` already needs the window, +and it might be not allocated yet, `inflate_ensure_window()` is +factored out of `updatewindow()` and made `ZLIB_INTERNAL`. + +Signed-off-by: Ilya Leoshkevich +Origin: i-iii/zlib,https://github.com/iii-i/zlib/commit/481ee63d5f8fa12b5c833d32d08a3c74bc62cb20 + +Last-Update: 2024-03-16 +--- + Makefile.in | 8 + + compress.c | 14 +- + configure | 24 + + contrib/README.contrib | 4 + + contrib/s390/README.txt | 17 + + contrib/s390/dfltcc.c | 1004 +++++++++++++++++++++++++++++++++++++++++ + contrib/s390/dfltcc.h | 97 ++++ + contrib/s390/dfltcc_deflate.h | 53 +++ + deflate.c | 76 +++- + deflate.h | 12 + + gzguts.h | 4 + + inflate.c | 98 ++-- + inflate.h | 2 + + test/infcover.c | 3 +- + test/minigzip.c | 4 + + trees.c | 8 +- + zutil.h | 2 + + 17 files changed, 1371 insertions(+), 59 deletions(-) + create mode 100644 contrib/s390/README.txt + create mode 100644 contrib/s390/dfltcc.c + create mode 100644 contrib/s390/dfltcc.h + create mode 100644 contrib/s390/dfltcc_deflate.h + +diff --git a/Makefile.in b/Makefile.in +index ede4db3..1710f63 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -140,6 +140,14 @@ match.lo: match.S + mv _match.o match.lo + rm -f _match.s + ++dfltcc.o: $(SRCDIR)contrib/s390/dfltcc.c $(SRCDIR)zlib.h zconf.h ++ $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)contrib/s390/dfltcc.c ++ ++dfltcc.lo: $(SRCDIR)contrib/s390/dfltcc.c $(SRCDIR)zlib.h zconf.h ++ -@mkdir objs 2>/dev/null || test -d objs ++ $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/s390/dfltcc.c ++ -@mv objs/dfltcc.o $@ ++ + crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h + $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c + +diff --git a/compress.c b/compress.c +index f43bacf..08a0660 100644 +--- a/compress.c ++++ b/compress.c +@@ -5,9 +5,15 @@ + + /* @(#) $Id$ */ + +-#define ZLIB_INTERNAL ++#include "zutil.h" + #include "zlib.h" + ++#ifdef DFLTCC ++# include "contrib/s390/dfltcc.h" ++#else ++#define DEFLATE_BOUND_COMPLEN(source_len) 0 ++#endif ++ + /* =========================================================================== + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte +@@ -70,6 +76,12 @@ int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, + this function needs to be updated. + */ + uLong ZEXPORT compressBound(uLong sourceLen) { ++ uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen); ++ ++ if (complen > 0) ++ /* Architecture-specific code provided an upper bound. */ ++ return complen + ZLIB_WRAPLEN; ++ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13; + } +diff --git a/configure b/configure +index 3372cbf..b99a348 100755 +--- a/configure ++++ b/configure +@@ -118,6 +118,7 @@ case "$1" in + echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log + echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log + echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log ++ echo ' [--dfltcc] [--dfltcc-level-mask=MASK]' | tee -a configure.log + exit 0 ;; + -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;; + -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;; +@@ -144,6 +145,16 @@ case "$1" in + --sanitize) address=1; shift ;; + --address) address=1; shift ;; + --memory) memory=1; shift ;; ++ --dfltcc) ++ CFLAGS="$CFLAGS -DDFLTCC" ++ OBJC="$OBJC dfltcc.o" ++ PIC_OBJC="$PIC_OBJC dfltcc.lo" ++ shift ++ ;; ++ --dfltcc-level-mask=*) ++ CFLAGS="$CFLAGS -DDFLTCC_LEVEL_MASK=`echo $1 | sed 's/.*=//'`" ++ shift ++ ;; + *) + echo "unknown option: $1" | tee -a configure.log + echo "$0 --help for help" | tee -a configure.log +@@ -835,6 +846,19 @@ EOF + fi + fi + ++# Check whether sys/sdt.h is available ++cat > $test.c << EOF ++#include ++int main() { return 0; } ++EOF ++if try $CC -c $CFLAGS $test.c; then ++ echo "Checking for sys/sdt.h ... Yes." | tee -a configure.log ++ CFLAGS="$CFLAGS -DHAVE_SYS_SDT_H" ++ SFLAGS="$SFLAGS -DHAVE_SYS_SDT_H" ++else ++ echo "Checking for sys/sdt.h ... No." | tee -a configure.log ++fi ++ + # test to see if we can use a gnu indirection function to detect and load optimized code at runtime + echo >> configure.log + cat > $test.c < + Small, low memory usage inflate. Also serves to provide an + unambiguous description of the deflate format. + ++s390/ by Ilya Leoshkevich ++ Hardware-accelerated deflate on IBM Z with DEFLATE CONVERSION CALL ++ instruction. ++ + testzlib/ by Gilles Vollant + Example of the use of zlib + +diff --git a/contrib/s390/README.txt b/contrib/s390/README.txt +new file mode 100644 +index 0000000..48be008 +--- /dev/null ++++ b/contrib/s390/README.txt +@@ -0,0 +1,17 @@ ++IBM Z mainframes starting from version z15 provide DFLTCC instruction, ++which implements deflate algorithm in hardware with estimated ++compression and decompression performance orders of magnitude faster ++than the current zlib and ratio comparable with that of level 1. ++ ++This directory adds DFLTCC support. In order to enable it, the following ++build commands should be used: ++ ++ $ ./configure --dfltcc ++ $ make ++ ++When built like this, zlib would compress in hardware on level 1, and in ++software on all other levels. Decompression will always happen in ++hardware. In order to enable DFLTCC compression for levels 1-6 (i.e. to ++make it used by default) one could either configure with ++--dfltcc-level-mask=0x7e or set the environment variable ++DFLTCC_LEVEL_MASK to 0x7e at run time. +diff --git a/contrib/s390/dfltcc.c b/contrib/s390/dfltcc.c +new file mode 100644 +index 0000000..f2b222d +--- /dev/null ++++ b/contrib/s390/dfltcc.c +@@ -0,0 +1,1004 @@ ++/* dfltcc.c - SystemZ DEFLATE CONVERSION CALL support. */ ++ ++/* ++ Use the following commands to build zlib with DFLTCC support: ++ ++ $ ./configure --dfltcc ++ $ make ++*/ ++ ++#define _GNU_SOURCE ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "../../zutil.h" ++#include "../../deflate.h" ++#include "../../inftrees.h" ++#include "../../inflate.h" ++#include "dfltcc.h" ++#include "dfltcc_deflate.h" ++#ifdef HAVE_SYS_SDT_H ++#include ++#endif ++ ++/* ++ C wrapper for the DEFLATE CONVERSION CALL instruction. ++ */ ++typedef enum { ++ DFLTCC_CC_OK = 0, ++ DFLTCC_CC_OP1_TOO_SHORT = 1, ++ DFLTCC_CC_OP2_TOO_SHORT = 2, ++ DFLTCC_CC_OP2_CORRUPT = 2, ++ DFLTCC_CC_AGAIN = 3, ++} dfltcc_cc; ++ ++#define DFLTCC_QAF 0 ++#define DFLTCC_GDHT 1 ++#define DFLTCC_CMPR 2 ++#define DFLTCC_XPND 4 ++#define HBT_CIRCULAR (1 << 7) ++#define HB_BITS 15 ++#define HB_SIZE (1 << HB_BITS) ++#define DFLTCC_FACILITY 151 ++ ++local inline dfltcc_cc dfltcc(int fn, void *param, ++ Bytef **op1, size_t *len1, ++ z_const Bytef **op2, size_t *len2, ++ void *hist) ++{ ++ Bytef *t2 = op1 ? *op1 : NULL; ++ size_t t3 = len1 ? *len1 : 0; ++ z_const Bytef *t4 = op2 ? *op2 : NULL; ++ size_t t5 = len2 ? *len2 : 0; ++ register int r0 __asm__("r0") = fn; ++ register void *r1 __asm__("r1") = param; ++ register Bytef *r2 __asm__("r2") = t2; ++ register size_t r3 __asm__("r3") = t3; ++ register z_const Bytef *r4 __asm__("r4") = t4; ++ register size_t r5 __asm__("r5") = t5; ++ int cc; ++ ++ __asm__ volatile( ++#ifdef HAVE_SYS_SDT_H ++ STAP_PROBE_ASM(zlib, dfltcc_entry, ++ STAP_PROBE_ASM_TEMPLATE(5)) ++#endif ++ ".insn rrf,0xb9390000,%[r2],%[r4],%[hist],0\n" ++#ifdef HAVE_SYS_SDT_H ++ STAP_PROBE_ASM(zlib, dfltcc_exit, ++ STAP_PROBE_ASM_TEMPLATE(5)) ++#endif ++ "ipm %[cc]\n" ++ : [r2] "+r" (r2) ++ , [r3] "+r" (r3) ++ , [r4] "+r" (r4) ++ , [r5] "+r" (r5) ++ , [cc] "=r" (cc) ++ : [r0] "r" (r0) ++ , [r1] "r" (r1) ++ , [hist] "r" (hist) ++#ifdef HAVE_SYS_SDT_H ++ , STAP_PROBE_ASM_OPERANDS(5, r2, r3, r4, r5, hist) ++#endif ++ : "cc", "memory"); ++ t2 = r2; t3 = r3; t4 = r4; t5 = r5; ++ ++ if (op1) ++ *op1 = t2; ++ if (len1) ++ *len1 = t3; ++ if (op2) ++ *op2 = t4; ++ if (len2) ++ *len2 = t5; ++ return (cc >> 28) & 3; ++} ++ ++/* ++ Parameter Block for Query Available Functions. ++ */ ++#define static_assert(c, msg) \ ++ __attribute__((unused)) \ ++ static char static_assert_failed_ ## msg[c ? 1 : -1] ++ ++struct dfltcc_qaf_param { ++ char fns[16]; ++ char reserved1[8]; ++ char fmts[2]; ++ char reserved2[6]; ++}; ++ ++static_assert(sizeof(struct dfltcc_qaf_param) == 32, ++ sizeof_struct_dfltcc_qaf_param_is_32); ++ ++local inline int is_bit_set(const char *bits, int n) ++{ ++ return bits[n / 8] & (1 << (7 - (n % 8))); ++} ++ ++local inline void clear_bit(char *bits, int n) ++{ ++ bits[n / 8] &= ~(1 << (7 - (n % 8))); ++} ++ ++#define DFLTCC_FMT0 0 ++ ++/* ++ Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand. ++ */ ++#define CVT_CRC32 0 ++#define CVT_ADLER32 1 ++#define HTT_FIXED 0 ++#define HTT_DYNAMIC 1 ++ ++struct dfltcc_param_v0 { ++ uint16_t pbvn; /* Parameter-Block-Version Number */ ++ uint8_t mvn; /* Model-Version Number */ ++ uint8_t ribm; /* Reserved for IBM use */ ++ unsigned reserved32 : 31; ++ unsigned cf : 1; /* Continuation Flag */ ++ uint8_t reserved64[8]; ++ unsigned nt : 1; /* New Task */ ++ unsigned reserved129 : 1; ++ unsigned cvt : 1; /* Check Value Type */ ++ unsigned reserved131 : 1; ++ unsigned htt : 1; /* Huffman-Table Type */ ++ unsigned bcf : 1; /* Block-Continuation Flag */ ++ unsigned bcc : 1; /* Block Closing Control */ ++ unsigned bhf : 1; /* Block Header Final */ ++ unsigned reserved136 : 1; ++ unsigned reserved137 : 1; ++ unsigned dhtgc : 1; /* DHT Generation Control */ ++ unsigned reserved139 : 5; ++ unsigned reserved144 : 5; ++ unsigned sbb : 3; /* Sub-Byte Boundary */ ++ uint8_t oesc; /* Operation-Ending-Supplemental Code */ ++ unsigned reserved160 : 12; ++ unsigned ifs : 4; /* Incomplete-Function Status */ ++ uint16_t ifl; /* Incomplete-Function Length */ ++ uint8_t reserved192[8]; ++ uint8_t reserved256[8]; ++ uint8_t reserved320[4]; ++ uint16_t hl; /* History Length */ ++ unsigned reserved368 : 1; ++ uint16_t ho : 15; /* History Offset */ ++ uint32_t cv; /* Check Value */ ++ unsigned eobs : 15; /* End-of-block Symbol */ ++ unsigned reserved431: 1; ++ uint8_t eobl : 4; /* End-of-block Length */ ++ unsigned reserved436 : 12; ++ unsigned reserved448 : 4; ++ uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table ++ Length */ ++ uint8_t reserved464[6]; ++ uint8_t cdht[288]; ++ uint8_t reserved[32]; ++ uint8_t csb[1152]; ++}; ++ ++static_assert(sizeof(struct dfltcc_param_v0) == 1536, ++ sizeof_struct_dfltcc_param_v0_is_1536); ++ ++local z_const char *oesc_msg(char *buf, int oesc) ++{ ++ if (oesc == 0x00) ++ return NULL; /* Successful completion */ ++ else { ++ sprintf(buf, "Operation-Ending-Supplemental Code is 0x%.2X", oesc); ++ return buf; ++ } ++} ++ ++/* ++ Extension of inflate_state and deflate_state. Must be doubleword-aligned. ++*/ ++struct dfltcc_state { ++ struct dfltcc_param_v0 param; /* Parameter block. */ ++ struct dfltcc_qaf_param af; /* Available functions. */ ++ uLong level_mask; /* Levels on which to use DFLTCC */ ++ uLong block_size; /* New block each X bytes */ ++ uLong block_threshold; /* New block after total_in > X */ ++ uLong dht_threshold; /* New block only if avail_in >= X */ ++ char msg[64]; /* Buffer for strm->msg */ ++}; ++ ++#define ALIGN_UP(p, size) \ ++ (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1)) ++ ++#define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)( \ ++ (char *)(state) + ALIGN_UP(sizeof(*state), 8))) ++ ++/* ++ Compress. ++ */ ++local inline int dfltcc_can_deflate_with_params(z_streamp strm, ++ int level, ++ uInt window_bits, ++ int strategy) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ ++ /* Unsupported compression settings */ ++ if ((dfltcc_state->level_mask & (1 << level)) == 0) ++ return 0; ++ if (window_bits != HB_BITS) ++ return 0; ++ if (strategy != Z_FIXED && strategy != Z_DEFAULT_STRATEGY) ++ return 0; ++ ++ /* Unsupported hardware */ ++ if (!is_bit_set(dfltcc_state->af.fns, DFLTCC_GDHT) || ++ !is_bit_set(dfltcc_state->af.fns, DFLTCC_CMPR) || ++ !is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0)) ++ return 0; ++ ++ return 1; ++} ++ ++int ZLIB_INTERNAL dfltcc_can_deflate(z_streamp strm) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ ++ return dfltcc_can_deflate_with_params(strm, ++ state->level, ++ state->w_bits, ++ state->strategy); ++} ++ ++local void dfltcc_gdht(z_streamp strm) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; ++ size_t avail_in = avail_in = strm->avail_in; ++ ++ dfltcc(DFLTCC_GDHT, ++ param, NULL, NULL, ++ &strm->next_in, &avail_in, NULL); ++} ++ ++local dfltcc_cc dfltcc_cmpr(z_streamp strm) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; ++ size_t avail_in = strm->avail_in; ++ size_t avail_out = strm->avail_out; ++ dfltcc_cc cc; ++ ++ cc = dfltcc(DFLTCC_CMPR | HBT_CIRCULAR, ++ param, &strm->next_out, &avail_out, ++ &strm->next_in, &avail_in, state->window); ++ strm->total_in += (strm->avail_in - avail_in); ++ strm->total_out += (strm->avail_out - avail_out); ++ strm->avail_in = avail_in; ++ strm->avail_out = avail_out; ++ return cc; ++} ++ ++local void send_eobs(z_streamp strm, ++ z_const struct dfltcc_param_v0 *param) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ ++ _tr_send_bits( ++ state, ++ bi_reverse(param->eobs >> (15 - param->eobl), param->eobl), ++ param->eobl); ++ flush_pending(strm); ++ if (state->pending != 0) { ++ /* The remaining data is located in pending_out[0:pending]. If someone ++ * calls put_byte() - this might happen in deflate() - the byte will be ++ * placed into pending_buf[pending], which is incorrect. Move the ++ * remaining data to the beginning of pending_buf so that put_byte() is ++ * usable again. ++ */ ++ memmove(state->pending_buf, state->pending_out, state->pending); ++ state->pending_out = state->pending_buf; ++ } ++#ifdef ZLIB_DEBUG ++ state->compressed_len += param->eobl; ++#endif ++} ++ ++int ZLIB_INTERNAL dfltcc_deflate(z_streamp strm, int flush, ++ block_state *result) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ uInt masked_avail_in; ++ dfltcc_cc cc; ++ int need_empty_block; ++ int soft_bcc; ++ int no_flush; ++ ++ if (!dfltcc_can_deflate(strm)) { ++ /* Clear history. */ ++ if (flush == Z_FULL_FLUSH) ++ param->hl = 0; ++ return 0; ++ } ++ ++again: ++ masked_avail_in = 0; ++ soft_bcc = 0; ++ no_flush = flush == Z_NO_FLUSH; ++ ++ /* No input data. Return, except when Continuation Flag is set, which means ++ * that DFLTCC has buffered some output in the parameter block and needs to ++ * be called again in order to flush it. ++ */ ++ if (strm->avail_in == 0 && !param->cf) { ++ /* A block is still open, and the hardware does not support closing ++ * blocks without adding data. Thus, close it manually. ++ */ ++ if (!no_flush && param->bcf) { ++ send_eobs(strm, param); ++ param->bcf = 0; ++ } ++ /* Let one of deflate_* functions write a trailing empty block. */ ++ if (flush == Z_FINISH) ++ return 0; ++ /* Clear history. */ ++ if (flush == Z_FULL_FLUSH) ++ param->hl = 0; ++ /* Trigger block post-processing if necessary. */ ++ *result = no_flush ? need_more : block_done; ++ return 1; ++ } ++ ++ /* There is an open non-BFINAL block, we are not going to close it just ++ * yet, we have compressed more than DFLTCC_BLOCK_SIZE bytes and we see ++ * more than DFLTCC_DHT_MIN_SAMPLE_SIZE bytes. Open a new block with a new ++ * DHT in order to adapt to a possibly changed input data distribution. ++ */ ++ if (param->bcf && no_flush && ++ strm->total_in > dfltcc_state->block_threshold && ++ strm->avail_in >= dfltcc_state->dht_threshold) { ++ if (param->cf) { ++ /* We need to flush the DFLTCC buffer before writing the ++ * End-of-block Symbol. Mask the input data and proceed as usual. ++ */ ++ masked_avail_in += strm->avail_in; ++ strm->avail_in = 0; ++ no_flush = 0; ++ } else { ++ /* DFLTCC buffer is empty, so we can manually write the ++ * End-of-block Symbol right away. ++ */ ++ send_eobs(strm, param); ++ param->bcf = 0; ++ dfltcc_state->block_threshold = ++ strm->total_in + dfltcc_state->block_size; ++ } ++ } ++ ++ /* No space for compressed data. If we proceed, dfltcc_cmpr() will return ++ * DFLTCC_CC_OP1_TOO_SHORT without buffering header bits, but we will still ++ * set BCF=1, which is wrong. Avoid complications and return early. ++ */ ++ if (strm->avail_out == 0) { ++ *result = need_more; ++ return 1; ++ } ++ ++ /* The caller gave us too much data. Pass only one block worth of ++ * uncompressed data to DFLTCC and mask the rest, so that on the next ++ * iteration we start a new block. ++ */ ++ if (no_flush && strm->avail_in > dfltcc_state->block_size) { ++ masked_avail_in += (strm->avail_in - dfltcc_state->block_size); ++ strm->avail_in = dfltcc_state->block_size; ++ } ++ ++ /* When we have an open non-BFINAL deflate block and caller indicates that ++ * the stream is ending, we need to close an open deflate block and open a ++ * BFINAL one. ++ */ ++ need_empty_block = flush == Z_FINISH && param->bcf && !param->bhf; ++ ++ /* Translate stream to parameter block */ ++ param->cvt = state->wrap == 2 ? CVT_CRC32 : CVT_ADLER32; ++ if (!no_flush) ++ /* We need to close a block. Always do this in software - when there is ++ * no input data, the hardware will not honor BCC. */ ++ soft_bcc = 1; ++ if (flush == Z_FINISH && !param->bcf) ++ /* We are about to open a BFINAL block, set Block Header Final bit ++ * until the stream ends. ++ */ ++ param->bhf = 1; ++ /* DFLTCC-CMPR will write to next_out, so make sure that buffers with ++ * higher precedence are empty. ++ */ ++ Assert(state->pending == 0, "There must be no pending bytes"); ++ Assert(state->bi_valid < 8, "There must be less than 8 pending bits"); ++ param->sbb = (unsigned int)state->bi_valid; ++ if (param->sbb > 0) ++ *strm->next_out = (Bytef)state->bi_buf; ++ /* Honor history and check value */ ++ param->nt = 0; ++ if (state->wrap == 1) ++ param->cv = strm->adler; ++ else if (state->wrap == 2) ++ param->cv = ZSWAP32(strm->adler); ++ ++ /* When opening a block, choose a Huffman-Table Type */ ++ if (!param->bcf) { ++ if (state->strategy == Z_FIXED || ++ (strm->total_in == 0 && dfltcc_state->block_threshold > 0)) ++ param->htt = HTT_FIXED; ++ else { ++ param->htt = HTT_DYNAMIC; ++ dfltcc_gdht(strm); ++ } ++ } ++ ++ /* Deflate */ ++ do { ++ cc = dfltcc_cmpr(strm); ++ if (strm->avail_in < 4096 && masked_avail_in > 0) ++ /* We are about to call DFLTCC with a small input buffer, which is ++ * inefficient. Since there is masked data, there will be at least ++ * one more DFLTCC call, so skip the current one and make the next ++ * one handle more data. ++ */ ++ break; ++ } while (cc == DFLTCC_CC_AGAIN); ++ ++ /* Translate parameter block to stream */ ++ strm->msg = oesc_msg(dfltcc_state->msg, param->oesc); ++ state->bi_valid = param->sbb; ++ if (state->bi_valid == 0) ++ state->bi_buf = 0; /* Avoid accessing next_out */ ++ else ++ state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1); ++ if (state->wrap == 1) ++ strm->adler = param->cv; ++ else if (state->wrap == 2) ++ strm->adler = ZSWAP32(param->cv); ++ ++ /* Unmask the input data */ ++ strm->avail_in += masked_avail_in; ++ masked_avail_in = 0; ++ ++ /* If we encounter an error, it means there is a bug in DFLTCC call */ ++ Assert(cc != DFLTCC_CC_OP2_CORRUPT || param->oesc == 0, "BUG"); ++ ++ /* Update Block-Continuation Flag. It will be used to check whether to call ++ * GDHT the next time. ++ */ ++ if (cc == DFLTCC_CC_OK) { ++ if (soft_bcc) { ++ send_eobs(strm, param); ++ param->bcf = 0; ++ dfltcc_state->block_threshold = ++ strm->total_in + dfltcc_state->block_size; ++ } else ++ param->bcf = 1; ++ if (flush == Z_FINISH) { ++ if (need_empty_block) ++ /* Make the current deflate() call also close the stream */ ++ return 0; ++ else { ++ bi_windup(state); ++ *result = finish_done; ++ } ++ } else { ++ if (flush == Z_FULL_FLUSH) ++ param->hl = 0; /* Clear history */ ++ *result = flush == Z_NO_FLUSH ? need_more : block_done; ++ } ++ } else { ++ param->bcf = 1; ++ *result = need_more; ++ } ++ if (strm->avail_in != 0 && strm->avail_out != 0) ++ goto again; /* deflate() must use all input or all output */ ++ return 1; ++} ++ ++/* ++ Expand. ++ */ ++int ZLIB_INTERNAL dfltcc_can_inflate(z_streamp strm) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ ++ /* Unsupported hardware */ ++ return is_bit_set(dfltcc_state->af.fns, DFLTCC_XPND) && ++ is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0); ++} ++ ++local dfltcc_cc dfltcc_xpnd(z_streamp strm) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; ++ size_t avail_in = strm->avail_in; ++ size_t avail_out = strm->avail_out; ++ dfltcc_cc cc; ++ ++ cc = dfltcc(DFLTCC_XPND | HBT_CIRCULAR, ++ param, &strm->next_out, &avail_out, ++ &strm->next_in, &avail_in, state->window); ++ strm->avail_in = avail_in; ++ strm->avail_out = avail_out; ++ return cc; ++} ++ ++dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(z_streamp strm, int flush, ++ int *ret) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ dfltcc_cc cc; ++ ++ if (flush == Z_BLOCK || flush == Z_TREES) { ++ /* DFLTCC does not support stopping on block boundaries */ ++ if (dfltcc_inflate_disable(strm)) { ++ *ret = Z_STREAM_ERROR; ++ return DFLTCC_INFLATE_BREAK; ++ } else ++ return DFLTCC_INFLATE_SOFTWARE; ++ } ++ ++ if (state->last) { ++ if (state->bits != 0) { ++ strm->next_in++; ++ strm->avail_in--; ++ state->bits = 0; ++ } ++ state->mode = CHECK; ++ return DFLTCC_INFLATE_CONTINUE; ++ } ++ ++ if (strm->avail_in == 0 && !param->cf) ++ return DFLTCC_INFLATE_BREAK; ++ ++ if (inflate_ensure_window(state)) { ++ state->mode = MEM; ++ return DFLTCC_INFLATE_CONTINUE; ++ } ++ ++ /* Translate stream to parameter block */ ++ param->cvt = ((state->wrap & 4) && state->flags) ? CVT_CRC32 : CVT_ADLER32; ++ param->sbb = state->bits; ++ if (param->hl) ++ param->nt = 0; /* Honor history for the first block */ ++ if (state->wrap & 4) ++ param->cv = state->flags ? ZSWAP32(state->check) : state->check; ++ ++ /* Inflate */ ++ do { ++ cc = dfltcc_xpnd(strm); ++ } while (cc == DFLTCC_CC_AGAIN); ++ ++ /* Translate parameter block to stream */ ++ strm->msg = oesc_msg(dfltcc_state->msg, param->oesc); ++ state->last = cc == DFLTCC_CC_OK; ++ state->bits = param->sbb; ++ if (state->wrap & 4) ++ strm->adler = state->check = state->flags ? ++ ZSWAP32(param->cv) : param->cv; ++ if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) { ++ /* Report an error if stream is corrupted */ ++ state->mode = BAD; ++ return DFLTCC_INFLATE_CONTINUE; ++ } ++ state->mode = TYPEDO; ++ /* Break if operands are exhausted, otherwise continue looping */ ++ return (cc == DFLTCC_CC_OP1_TOO_SHORT || cc == DFLTCC_CC_OP2_TOO_SHORT) ? ++ DFLTCC_INFLATE_BREAK : DFLTCC_INFLATE_CONTINUE; ++} ++ ++int ZLIB_INTERNAL dfltcc_was_inflate_used(z_streamp strm) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; ++ ++ return !param->nt; ++} ++ ++/* ++ Rotates a circular buffer. ++ The implementation is based on https://cplusplus.com/reference/algorithm/rotate/ ++ */ ++local void rotate(Bytef *start, Bytef *pivot, Bytef *end) ++{ ++ Bytef *p = pivot; ++ Bytef tmp; ++ ++ while (p != start) { ++ tmp = *start; ++ *start = *p; ++ *p = tmp; ++ ++ start++; ++ p++; ++ ++ if (p == end) ++ p = pivot; ++ else if (start == pivot) ++ pivot = p; ++ } ++} ++ ++#define MIN(x, y) ({ \ ++ typeof(x) _x = (x); \ ++ typeof(y) _y = (y); \ ++ _x < _y ? _x : _y; \ ++}) ++ ++#define MAX(x, y) ({ \ ++ typeof(x) _x = (x); \ ++ typeof(y) _y = (y); \ ++ _x > _y ? _x : _y; \ ++}) ++ ++int ZLIB_INTERNAL dfltcc_inflate_disable(z_streamp strm) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ ++ if (!dfltcc_can_inflate(strm)) ++ return 0; ++ if (dfltcc_was_inflate_used(strm)) ++ /* DFLTCC has already decompressed some data. Since there is not ++ * enough information to resume decompression in software, the call ++ * must fail. ++ */ ++ return 1; ++ /* DFLTCC was not used yet - decompress in software */ ++ memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af)); ++ /* Convert the window from the hardware to the software format */ ++ rotate(state->window, state->window + param->ho, state->window + HB_SIZE); ++ state->whave = state->wnext = MIN(param->hl, state->wsize); ++ return 0; ++} ++ ++local int env_dfltcc_disabled; ++local int env_source_date_epoch; ++local unsigned long env_level_mask; ++local unsigned long env_block_size; ++local unsigned long env_block_threshold; ++local unsigned long env_dht_threshold; ++local unsigned long env_ribm; ++local uint64_t cpu_facilities[(DFLTCC_FACILITY / 64) + 1]; ++local struct dfltcc_qaf_param cpu_af __attribute__((aligned(8))); ++ ++local inline int is_dfltcc_enabled(void) ++{ ++ if (env_dfltcc_disabled) ++ /* User has explicitly disabled DFLTCC. */ ++ return 0; ++ ++ return is_bit_set((const char *)cpu_facilities, DFLTCC_FACILITY); ++} ++ ++local unsigned long xstrtoul(const char *s, unsigned long _default) ++{ ++ char *endptr; ++ unsigned long result; ++ ++ if (!(s && *s)) ++ return _default; ++ errno = 0; ++ result = strtoul(s, &endptr, 0); ++ return (errno || *endptr) ? _default : result; ++} ++ ++__attribute__((constructor)) local void init_globals(void) ++{ ++ const char *env; ++ register char r0 __asm__("r0"); ++ ++ env = secure_getenv("DFLTCC"); ++ env_dfltcc_disabled = env && !strcmp(env, "0"); ++ ++ env = secure_getenv("SOURCE_DATE_EPOCH"); ++ env_source_date_epoch = !!env; ++ ++#ifndef DFLTCC_LEVEL_MASK ++#define DFLTCC_LEVEL_MASK 0x2 ++#endif ++ env_level_mask = xstrtoul(secure_getenv("DFLTCC_LEVEL_MASK"), ++ DFLTCC_LEVEL_MASK); ++ ++#ifndef DFLTCC_BLOCK_SIZE ++#define DFLTCC_BLOCK_SIZE 1048576 ++#endif ++ env_block_size = xstrtoul(secure_getenv("DFLTCC_BLOCK_SIZE"), ++ DFLTCC_BLOCK_SIZE); ++ ++#ifndef DFLTCC_FIRST_FHT_BLOCK_SIZE ++#define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096 ++#endif ++ env_block_threshold = xstrtoul(secure_getenv("DFLTCC_FIRST_FHT_BLOCK_SIZE"), ++ DFLTCC_FIRST_FHT_BLOCK_SIZE); ++ ++#ifndef DFLTCC_DHT_MIN_SAMPLE_SIZE ++#define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096 ++#endif ++ env_dht_threshold = xstrtoul(secure_getenv("DFLTCC_DHT_MIN_SAMPLE_SIZE"), ++ DFLTCC_DHT_MIN_SAMPLE_SIZE); ++ ++#ifndef DFLTCC_RIBM ++#define DFLTCC_RIBM 0 ++#endif ++ env_ribm = xstrtoul(secure_getenv("DFLTCC_RIBM"), DFLTCC_RIBM); ++ ++ memset(cpu_facilities, 0, sizeof(cpu_facilities)); ++ r0 = sizeof(cpu_facilities) / sizeof(cpu_facilities[0]) - 1; ++ /* STFLE is supported since z9-109 and only in z/Architecture mode. When ++ * compiling with -m31, gcc defaults to ESA mode, however, since the kernel ++ * is 64-bit, it's always z/Architecture mode at runtime. ++ */ ++ __asm__ volatile( ++#ifndef __clang__ ++ ".machinemode push\n" ++ ".machinemode zarch\n" ++#endif ++ "stfle %[facilities]\n" ++#ifndef __clang__ ++ ".machinemode pop\n" ++#endif ++ : [facilities] "=Q" (cpu_facilities) ++ , [r0] "+r" (r0) ++ : ++ : "cc"); ++ ++ /* Initialize available functions */ ++ if (is_dfltcc_enabled()) ++ dfltcc(DFLTCC_QAF, &cpu_af, NULL, NULL, NULL, NULL, NULL); ++ else ++ memset(&cpu_af, 0, sizeof(cpu_af)); ++} ++ ++/* ++ Memory management. ++ ++ DFLTCC requires parameter blocks and window to be aligned. zlib allows ++ users to specify their own allocation functions, so using e.g. ++ `posix_memalign' is not an option. Thus, we overallocate and take the ++ aligned portion of the buffer. ++*/ ++void ZLIB_INTERNAL dfltcc_reset(z_streamp strm, uInt size) ++{ ++ struct dfltcc_state *dfltcc_state = ++ (struct dfltcc_state *)((char *)strm->state + ALIGN_UP(size, 8)); ++ ++ memcpy(&dfltcc_state->af, &cpu_af, sizeof(dfltcc_state->af)); ++ ++ if (env_source_date_epoch) ++ /* User needs reproducible results, but the output of DFLTCC_CMPR ++ * depends on buffers' page offsets. ++ */ ++ clear_bit(dfltcc_state->af.fns, DFLTCC_CMPR); ++ ++ /* Initialize parameter block */ ++ memset(&dfltcc_state->param, 0, sizeof(dfltcc_state->param)); ++ dfltcc_state->param.nt = 1; ++ ++ /* Initialize tuning parameters */ ++ dfltcc_state->level_mask = env_level_mask; ++ dfltcc_state->block_size = env_block_size; ++ dfltcc_state->block_threshold = env_block_threshold; ++ dfltcc_state->dht_threshold = env_dht_threshold; ++ dfltcc_state->param.ribm = env_ribm; ++} ++ ++voidpf ZLIB_INTERNAL dfltcc_alloc_state(z_streamp strm, uInt items, uInt size) ++{ ++ return ZALLOC(strm, ++ ALIGN_UP(items * size, 8) + sizeof(struct dfltcc_state), ++ sizeof(unsigned char)); ++} ++ ++void ZLIB_INTERNAL dfltcc_copy_state(voidpf dst, const voidpf src, uInt size) ++{ ++ zmemcpy(dst, src, ALIGN_UP(size, 8) + sizeof(struct dfltcc_state)); ++} ++ ++static const int PAGE_ALIGN = 0x1000; ++ ++voidpf ZLIB_INTERNAL dfltcc_alloc_window(z_streamp strm, uInt items, uInt size) ++{ ++ voidpf p, w; ++ ++ /* To simplify freeing, we store the pointer to the allocated buffer right ++ * before the window. Note that DFLTCC always uses HB_SIZE bytes. ++ */ ++ p = ZALLOC(strm, sizeof(voidpf) + MAX(items * size, HB_SIZE) + PAGE_ALIGN, ++ sizeof(unsigned char)); ++ if (p == NULL) ++ return NULL; ++ w = ALIGN_UP((char *)p + sizeof(voidpf), PAGE_ALIGN); ++ *(voidpf *)((char *)w - sizeof(voidpf)) = p; ++ return w; ++} ++ ++void ZLIB_INTERNAL dfltcc_copy_window(void *dest, const void *src, size_t n) ++{ ++ memcpy(dest, src, MAX(n, HB_SIZE)); ++} ++ ++void ZLIB_INTERNAL dfltcc_free_window(z_streamp strm, voidpf w) ++{ ++ if (w) ++ ZFREE(strm, *(voidpf *)((unsigned char *)w - sizeof(voidpf))); ++} ++ ++/* ++ Switching between hardware and software compression. ++ ++ DFLTCC does not support all zlib settings, e.g. generation of non-compressed ++ blocks or alternative window sizes. When such settings are applied on the ++ fly with deflateParams, we need to convert between hardware and software ++ window formats. ++*/ ++int ZLIB_INTERNAL dfltcc_deflate_params(z_streamp strm, int level, ++ int strategy, int *flush) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ int could_deflate = dfltcc_can_deflate(strm); ++ int can_deflate = dfltcc_can_deflate_with_params(strm, ++ level, ++ state->w_bits, ++ strategy); ++ ++ if (can_deflate == could_deflate) ++ /* We continue to work in the same mode - no changes needed */ ++ return Z_OK; ++ ++ if (strm->total_in == 0 && param->nt == 1 && param->hl == 0) ++ /* DFLTCC was not used yet - no changes needed */ ++ return Z_OK; ++ ++ /* For now, do not convert between window formats - simply get rid of the ++ * old data instead. ++ */ ++ *flush = Z_FULL_FLUSH; ++ return Z_OK; ++} ++ ++int ZLIB_INTERNAL dfltcc_deflate_done(z_streamp strm, int flush) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ ++ /* When deflate(Z_FULL_FLUSH) is called with small avail_out, it might ++ * close the block without resetting the compression state. Detect this ++ * situation and return that deflation is not done. ++ */ ++ if (flush == Z_FULL_FLUSH && strm->avail_out == 0) ++ return 0; ++ ++ /* Return that deflation is not done if DFLTCC is used and either it ++ * buffered some data (Continuation Flag is set), or has not written EOBS ++ * yet (Block-Continuation Flag is set). ++ */ ++ return !dfltcc_can_deflate(strm) || (!param->cf && !param->bcf); ++} ++ ++/* ++ Preloading history. ++*/ ++local void append_history(struct dfltcc_param_v0 *param, ++ Bytef *history, ++ const Bytef *buf, ++ uInt count) ++{ ++ size_t offset; ++ size_t n; ++ ++ /* Do not use more than 32K */ ++ if (count > HB_SIZE) { ++ buf += count - HB_SIZE; ++ count = HB_SIZE; ++ } ++ offset = (param->ho + param->hl) % HB_SIZE; ++ if (offset + count <= HB_SIZE) ++ /* Circular history buffer does not wrap - copy one chunk */ ++ zmemcpy(history + offset, buf, count); ++ else { ++ /* Circular history buffer wraps - copy two chunks */ ++ n = HB_SIZE - offset; ++ zmemcpy(history + offset, buf, n); ++ zmemcpy(history, buf + n, count - n); ++ } ++ n = param->hl + count; ++ if (n <= HB_SIZE) ++ /* All history fits into buffer - no need to discard anything */ ++ param->hl = n; ++ else { ++ /* History does not fit into buffer - discard extra bytes */ ++ param->ho = (param->ho + (n - HB_SIZE)) % HB_SIZE; ++ param->hl = HB_SIZE; ++ } ++} ++ ++local void get_history(struct dfltcc_param_v0 *param, ++ const Bytef *history, ++ Bytef *buf) ++{ ++ if (param->ho + param->hl <= HB_SIZE) ++ /* Circular history buffer does not wrap - copy one chunk */ ++ memcpy(buf, history + param->ho, param->hl); ++ else { ++ /* Circular history buffer wraps - copy two chunks */ ++ memcpy(buf, history + param->ho, HB_SIZE - param->ho); ++ memcpy(buf + HB_SIZE - param->ho, history, param->ho + param->hl - HB_SIZE); ++ } ++} ++ ++int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(z_streamp strm, ++ const Bytef *dictionary, ++ uInt dict_length) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ ++ append_history(param, state->window, dictionary, dict_length); ++ state->strstart = 1; /* Add FDICT to zlib header */ ++ state->block_start = state->strstart; /* Make deflate_stored happy */ ++ return Z_OK; ++} ++ ++int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(z_streamp strm, ++ Bytef *dictionary, ++ uInt *dict_length) ++{ ++ deflate_state *state = (deflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ ++ if (dictionary) ++ get_history(param, state->window, dictionary); ++ if (dict_length) ++ *dict_length = param->hl; ++ return Z_OK; ++} ++ ++int ZLIB_INTERNAL dfltcc_inflate_set_dictionary(z_streamp strm, ++ const Bytef *dictionary, ++ uInt dict_length) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ ++ if (inflate_ensure_window(state)) { ++ state->mode = MEM; ++ return Z_MEM_ERROR; ++ } ++ ++ append_history(param, state->window, dictionary, dict_length); ++ state->havedict = 1; ++ return Z_OK; ++} ++ ++int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(z_streamp strm, ++ Bytef *dictionary, ++ uInt *dict_length) ++{ ++ struct inflate_state *state = (struct inflate_state *)strm->state; ++ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 *param = &dfltcc_state->param; ++ ++ if (dictionary && state->window) ++ get_history(param, state->window, dictionary); ++ if (dict_length) ++ *dict_length = param->hl; ++ return Z_OK; ++} +diff --git a/contrib/s390/dfltcc.h b/contrib/s390/dfltcc.h +new file mode 100644 +index 0000000..c8491c4 +--- /dev/null ++++ b/contrib/s390/dfltcc.h +@@ -0,0 +1,97 @@ ++#ifndef DFLTCC_H ++#define DFLTCC_H ++ ++#include "../../zlib.h" ++#include "../../zutil.h" ++ ++voidpf ZLIB_INTERNAL dfltcc_alloc_state(z_streamp strm, uInt items, uInt size); ++void ZLIB_INTERNAL dfltcc_copy_state(voidpf dst, const voidpf src, uInt size); ++void ZLIB_INTERNAL dfltcc_reset(z_streamp strm, uInt size); ++voidpf ZLIB_INTERNAL dfltcc_alloc_window(z_streamp strm, uInt items, ++ uInt size); ++void ZLIB_INTERNAL dfltcc_copy_window(void *dest, const void *src, size_t n); ++void ZLIB_INTERNAL dfltcc_free_window(z_streamp strm, voidpf w); ++#define DFLTCC_BLOCK_HEADER_BITS 3 ++#define DFLTCC_HLITS_COUNT_BITS 5 ++#define DFLTCC_HDISTS_COUNT_BITS 5 ++#define DFLTCC_HCLENS_COUNT_BITS 4 ++#define DFLTCC_MAX_HCLENS 19 ++#define DFLTCC_HCLEN_BITS 3 ++#define DFLTCC_MAX_HLITS 286 ++#define DFLTCC_MAX_HDISTS 30 ++#define DFLTCC_MAX_HLIT_HDIST_BITS 7 ++#define DFLTCC_MAX_SYMBOL_BITS 16 ++#define DFLTCC_MAX_EOBS_BITS 15 ++#define DFLTCC_MAX_PADDING_BITS 7 ++#define DEFLATE_BOUND_COMPLEN(source_len) \ ++ ((DFLTCC_BLOCK_HEADER_BITS + \ ++ DFLTCC_HLITS_COUNT_BITS + \ ++ DFLTCC_HDISTS_COUNT_BITS + \ ++ DFLTCC_HCLENS_COUNT_BITS + \ ++ DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \ ++ (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \ ++ (source_len) * DFLTCC_MAX_SYMBOL_BITS + \ ++ DFLTCC_MAX_EOBS_BITS + \ ++ DFLTCC_MAX_PADDING_BITS) >> 3) ++int ZLIB_INTERNAL dfltcc_can_inflate(z_streamp strm); ++typedef enum { ++ DFLTCC_INFLATE_CONTINUE, ++ DFLTCC_INFLATE_BREAK, ++ DFLTCC_INFLATE_SOFTWARE, ++} dfltcc_inflate_action; ++dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(z_streamp strm, ++ int flush, int *ret); ++int ZLIB_INTERNAL dfltcc_was_inflate_used(z_streamp strm); ++int ZLIB_INTERNAL dfltcc_inflate_disable(z_streamp strm); ++int ZLIB_INTERNAL dfltcc_inflate_set_dictionary(z_streamp strm, ++ const Bytef *dictionary, ++ uInt dict_length); ++int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(z_streamp strm, ++ Bytef *dictionary, ++ uInt* dict_length); ++ ++#define ZALLOC_STATE dfltcc_alloc_state ++#define ZFREE_STATE ZFREE ++#define ZCOPY_STATE dfltcc_copy_state ++#define ZALLOC_WINDOW dfltcc_alloc_window ++#define ZCOPY_WINDOW dfltcc_copy_window ++#define ZFREE_WINDOW dfltcc_free_window ++#define TRY_FREE_WINDOW dfltcc_free_window ++#define INFLATE_RESET_KEEP_HOOK(strm) \ ++ dfltcc_reset((strm), sizeof(struct inflate_state)) ++#define INFLATE_PRIME_HOOK(strm, bits, value) \ ++ do { if (dfltcc_inflate_disable((strm))) return Z_STREAM_ERROR; } while (0) ++#define INFLATE_TYPEDO_HOOK(strm, flush) \ ++ if (dfltcc_can_inflate((strm))) { \ ++ dfltcc_inflate_action action; \ ++\ ++ RESTORE(); \ ++ action = dfltcc_inflate((strm), (flush), &ret); \ ++ LOAD(); \ ++ if (action == DFLTCC_INFLATE_CONTINUE) \ ++ break; \ ++ else if (action == DFLTCC_INFLATE_BREAK) \ ++ goto inf_leave; \ ++ } ++#define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm))) ++#define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm))) ++#define INFLATE_MARK_HOOK(strm) \ ++ do { \ ++ if (dfltcc_was_inflate_used((strm))) return -(1L << 16); \ ++ } while (0) ++#define INFLATE_SYNC_POINT_HOOK(strm) \ ++ do { \ ++ if (dfltcc_was_inflate_used((strm))) return Z_STREAM_ERROR; \ ++ } while (0) ++#define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \ ++ do { \ ++ if (dfltcc_can_inflate(strm)) \ ++ return dfltcc_inflate_set_dictionary(strm, dict, dict_len); \ ++ } while (0) ++#define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) \ ++ do { \ ++ if (dfltcc_can_inflate(strm)) \ ++ return dfltcc_inflate_get_dictionary(strm, dict, dict_len); \ ++ } while (0) ++ ++#endif +diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h +new file mode 100644 +index 0000000..2699d15 +--- /dev/null ++++ b/contrib/s390/dfltcc_deflate.h +@@ -0,0 +1,53 @@ ++#ifndef DFLTCC_DEFLATE_H ++#define DFLTCC_DEFLATE_H ++ ++#include "dfltcc.h" ++ ++int ZLIB_INTERNAL dfltcc_can_deflate(z_streamp strm); ++int ZLIB_INTERNAL dfltcc_deflate(z_streamp strm, ++ int flush, ++ block_state *result); ++int ZLIB_INTERNAL dfltcc_deflate_params(z_streamp strm, int level, ++ int strategy, int *flush); ++int ZLIB_INTERNAL dfltcc_deflate_done(z_streamp strm, int flush); ++int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(z_streamp strm, ++ const Bytef *dictionary, ++ uInt dict_length); ++int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(z_streamp strm, ++ Bytef *dictionary, ++ uInt* dict_length); ++ ++#define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \ ++ do { \ ++ if (dfltcc_can_deflate((strm))) \ ++ return dfltcc_deflate_set_dictionary((strm), (dict), (dict_len)); \ ++ } while (0) ++#define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) \ ++ do { \ ++ if (dfltcc_can_deflate((strm))) \ ++ return dfltcc_deflate_get_dictionary((strm), (dict), (dict_len)); \ ++ } while (0) ++#define DEFLATE_RESET_KEEP_HOOK(strm) \ ++ dfltcc_reset((strm), sizeof(deflate_state)) ++#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) \ ++ do { \ ++ int err; \ ++\ ++ err = dfltcc_deflate_params((strm), \ ++ (level), \ ++ (strategy), \ ++ (hook_flush)); \ ++ if (err == Z_STREAM_ERROR) \ ++ return err; \ ++ } while (0) ++#define DEFLATE_DONE dfltcc_deflate_done ++#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \ ++ do { \ ++ if (deflateStateCheck((strm)) || dfltcc_can_deflate((strm))) \ ++ (complen) = DEFLATE_BOUND_COMPLEN(source_len); \ ++ } while (0) ++#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm))) ++#define DEFLATE_HOOK dfltcc_deflate ++#define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm))) ++ ++#endif +diff --git a/deflate.c b/deflate.c +index bd01175..9f5bc8b 100644 +--- a/deflate.c ++++ b/deflate.c +@@ -60,12 +60,24 @@ const char deflate_copyright[] = + copyright string in the executable of your product. + */ + +-typedef enum { +- need_more, /* block not completed, need more input or more output */ +- block_done, /* block flush performed */ +- finish_started, /* finish started, need only more output at next deflate */ +- finish_done /* finish done, accept no more input or output */ +-} block_state; ++#ifdef DFLTCC ++#include "contrib/s390/dfltcc_deflate.h" ++#else ++#define ZALLOC_STATE ZALLOC ++#define ZFREE_STATE ZFREE ++#define ZCOPY_STATE zmemcpy ++#define ZALLOC_WINDOW ZALLOC ++#define TRY_FREE_WINDOW TRY_FREE ++#define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) ++#define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) ++#define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0) ++#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0) ++#define DEFLATE_DONE(strm, flush) 1 ++#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0) ++#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0 ++#define DEFLATE_HOOK(strm, flush, bstate) 0 ++#define DEFLATE_NEED_CHECKSUM(strm) 1 ++#endif + + typedef block_state (*compress_func)(deflate_state *s, int flush); + /* Compression function. Returns the block state after the call. */ +@@ -224,7 +236,8 @@ local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); +- if (strm->state->wrap == 1) { ++ if (!DEFLATE_NEED_CHECKSUM(strm)) {} ++ else if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } + #ifdef GZIP +@@ -429,7 +442,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + return Z_STREAM_ERROR; + } + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ +- s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); ++ s = (deflate_state *) ZALLOC_STATE(strm, 1, sizeof(deflate_state)); + if (s == Z_NULL) return Z_MEM_ERROR; + strm->state = (struct internal_state FAR *)s; + s->strm = strm; +@@ -446,7 +459,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + s->hash_mask = s->hash_size - 1; + s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH); + +- s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); ++ s->window = (Bytef *) ZALLOC_WINDOW(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + +@@ -565,6 +578,7 @@ int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + /* when using zlib wrappers, compute Adler-32 for provided dictionary */ + if (wrap == 1) + strm->adler = adler32(strm->adler, dictionary, dictLength); ++ DEFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength); + s->wrap = 0; /* avoid computing Adler-32 in read_buf */ + + /* if dictionary would fill window, just replace the history */ +@@ -620,6 +634,7 @@ int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + + if (deflateStateCheck(strm)) + return Z_STREAM_ERROR; ++ DEFLATE_GET_DICTIONARY_HOOK(strm, dictionary, dictLength); + s = strm->state; + len = s->strstart + s->lookahead; + if (len > s->w_size) +@@ -664,6 +679,8 @@ int ZEXPORT deflateResetKeep(z_streamp strm) { + + _tr_init(s); + ++ DEFLATE_RESET_KEEP_HOOK(strm); ++ + return Z_OK; + } + +@@ -752,6 +769,7 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { + int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { + deflate_state *s; + compress_func func; ++ int hook_flush = Z_NO_FLUSH; + + if (deflateStateCheck(strm)) return Z_STREAM_ERROR; + s = strm->state; +@@ -764,15 +782,18 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } ++ DEFLATE_PARAMS_HOOK(strm, level, strategy, &hook_flush); + func = configuration_table[s->level].func; + +- if ((strategy != s->strategy || func != configuration_table[level].func) && +- s->last_flush != -2) { ++ if (((strategy != s->strategy || func != configuration_table[level].func) && ++ s->last_flush != -2) || hook_flush != Z_NO_FLUSH) { + /* Flush the last buffer: */ +- int err = deflate(strm, Z_BLOCK); ++ int flush = RANK(hook_flush) > RANK(Z_BLOCK) ? hook_flush : Z_BLOCK; ++ int err = deflate(strm, flush); + if (err == Z_STREAM_ERROR) + return err; +- if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead) ++ if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead || ++ !DEFLATE_DONE(strm, flush)) + return Z_BUF_ERROR; + } + if (s->level != level) { +@@ -840,11 +861,13 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { + ~13% overhead plus a small constant */ + fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) + + (sourceLen >> 9) + 4; ++ DEFLATE_BOUND_ADJUST_COMPLEN(strm, fixedlen, sourceLen); + + /* upper bound for stored blocks with length 127 (memLevel == 1) -- + ~4% overhead plus a small constant */ + storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + + (sourceLen >> 11) + 7; ++ DEFLATE_BOUND_ADJUST_COMPLEN(strm, storelen, sourceLen); + + /* if can't get parameters, return larger bound plus a zlib wrapper */ + if (deflateStateCheck(strm)) +@@ -886,7 +909,8 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { + } + + /* if not default parameters, return one of the conservative bounds */ +- if (s->w_bits != 15 || s->hash_bits != 8 + 7) ++ if (DEFLATE_NEED_CONSERVATIVE_BOUND(strm) || ++ s->w_bits != 15 || s->hash_bits != 8 + 7) + return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + + wraplen; + +@@ -912,7 +936,7 @@ local void putShortMSB(deflate_state *s, uInt b) { + * applications may wish to modify it to avoid allocating a large + * strm->next_out buffer and copying into it. (See also read_buf()). + */ +-local void flush_pending(z_streamp strm) { ++void ZLIB_INTERNAL flush_pending(z_streamp strm) { + unsigned len; + deflate_state *s = strm->state; + +@@ -1179,7 +1203,8 @@ int ZEXPORT deflate(z_streamp strm, int flush) { + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { + block_state bstate; + +- bstate = s->level == 0 ? deflate_stored(s, flush) : ++ bstate = DEFLATE_HOOK(strm, flush, &bstate) ? bstate : ++ s->level == 0 ? deflate_stored(s, flush) : + s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : + s->strategy == Z_RLE ? deflate_rle(s, flush) : + (*(configuration_table[s->level].func))(s, flush); +@@ -1226,7 +1251,6 @@ int ZEXPORT deflate(z_streamp strm, int flush) { + } + + if (flush != Z_FINISH) return Z_OK; +- if (s->wrap <= 0) return Z_STREAM_END; + + /* Write the trailer */ + #ifdef GZIP +@@ -1242,7 +1266,7 @@ int ZEXPORT deflate(z_streamp strm, int flush) { + } + else + #endif +- { ++ if (s->wrap == 1) { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } +@@ -1251,7 +1275,11 @@ int ZEXPORT deflate(z_streamp strm, int flush) { + * to flush the rest. + */ + if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ +- return s->pending != 0 ? Z_OK : Z_STREAM_END; ++ if (s->pending == 0) { ++ Assert(s->bi_valid == 0, "bi_buf not flushed"); ++ return Z_STREAM_END; ++ } ++ return Z_OK; + } + + /* ========================================================================= */ +@@ -1266,9 +1294,9 @@ int ZEXPORT deflateEnd(z_streamp strm) { + TRY_FREE(strm, strm->state->pending_buf); + TRY_FREE(strm, strm->state->head); + TRY_FREE(strm, strm->state->prev); +- TRY_FREE(strm, strm->state->window); ++ TRY_FREE_WINDOW(strm, strm->state->window); + +- ZFREE(strm, strm->state); ++ ZFREE_STATE(strm, strm->state); + strm->state = Z_NULL; + + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; +@@ -1297,13 +1325,13 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { + + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); + +- ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); ++ ds = (deflate_state *) ZALLOC_STATE(dest, 1, sizeof(deflate_state)); + if (ds == Z_NULL) return Z_MEM_ERROR; + dest->state = (struct internal_state FAR *) ds; +- zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); ++ ZCOPY_STATE((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); + ds->strm = dest; + +- ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ++ ds->window = (Bytef *) ZALLOC_WINDOW(dest, ds->w_size, 2*sizeof(Byte)); + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); +diff --git a/deflate.h b/deflate.h +index 8696791..d49e698 100644 +--- a/deflate.h ++++ b/deflate.h +@@ -310,6 +310,7 @@ void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s); + void ZLIB_INTERNAL _tr_align(deflate_state *s); + void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last); ++void ZLIB_INTERNAL _tr_send_bits(deflate_state *s, int value, int length); + + #define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +@@ -374,4 +375,15 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + flush = _tr_tally(s, distance, length) + #endif + ++typedef enum { ++ need_more, /* block not completed, need more input or more output */ ++ block_done, /* block flush performed */ ++ finish_started, /* finish started, need only more output at next deflate */ ++ finish_done /* finish done, accept no more input or output */ ++} block_state; ++ ++unsigned ZLIB_INTERNAL bi_reverse(unsigned code, int len); ++void ZLIB_INTERNAL bi_windup(deflate_state *s); ++void ZLIB_INTERNAL flush_pending(z_streamp strm); ++ + #endif /* DEFLATE_H */ +diff --git a/gzguts.h b/gzguts.h +index f937504..5adfd1d 100644 +--- a/gzguts.h ++++ b/gzguts.h +@@ -152,7 +152,11 @@ + + /* default i/o buffer size -- double this for output when reading (this and + twice this must be able to fit in an unsigned type) */ ++#ifdef DFLTCC ++#define GZBUFSIZE 131072 ++#else + #define GZBUFSIZE 8192 ++#endif + + /* gzip modes, also provide a little integrity check on the passed structure */ + #define GZ_NONE 0 +diff --git a/inflate.c b/inflate.c +index b0757a9..c0f808f 100644 +--- a/inflate.c ++++ b/inflate.c +@@ -85,6 +85,27 @@ + #include "inflate.h" + #include "inffast.h" + ++/* architecture-specific bits */ ++#ifdef DFLTCC ++#include "contrib/s390/dfltcc.h" ++#else ++#define ZALLOC_STATE ZALLOC ++#define ZFREE_STATE ZFREE ++#define ZCOPY_STATE zmemcpy ++#define ZALLOC_WINDOW ZALLOC ++#define ZCOPY_WINDOW zmemcpy ++#define ZFREE_WINDOW ZFREE ++#define INFLATE_RESET_KEEP_HOOK(strm) do {} while (0) ++#define INFLATE_PRIME_HOOK(strm, bits, value) do {} while (0) ++#define INFLATE_TYPEDO_HOOK(strm, flush) do {} while (0) ++#define INFLATE_NEED_CHECKSUM(strm) 1 ++#define INFLATE_NEED_UPDATEWINDOW(strm) 1 ++#define INFLATE_MARK_HOOK(strm) do {} while (0) ++#define INFLATE_SYNC_POINT_HOOK(strm) do {} while (0) ++#define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) ++#define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) ++#endif ++ + #ifdef MAKEFIXED + # ifndef BUILDFIXED + # define BUILDFIXED +@@ -123,6 +144,7 @@ int ZEXPORT inflateResetKeep(z_streamp strm) { + state->lencode = state->distcode = state->next = state->codes; + state->sane = 1; + state->back = -1; ++ INFLATE_RESET_KEEP_HOOK(strm); + Tracev((stderr, "inflate: reset\n")); + return Z_OK; + } +@@ -165,7 +187,7 @@ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { + if (windowBits && (windowBits < 8 || windowBits > 15)) + return Z_STREAM_ERROR; + if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { +- ZFREE(strm, state->window); ++ ZFREE_WINDOW(strm, state->window); + state->window = Z_NULL; + } + +@@ -200,7 +222,7 @@ int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + strm->zfree = zcfree; + #endif + state = (struct inflate_state FAR *) +- ZALLOC(strm, 1, sizeof(struct inflate_state)); ++ ZALLOC_STATE(strm, 1, sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; +@@ -209,7 +231,7 @@ int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + state->mode = HEAD; /* to pass state test in inflateReset2() */ + ret = inflateReset2(strm, windowBits); + if (ret != Z_OK) { +- ZFREE(strm, state); ++ ZFREE_STATE(strm, state); + strm->state = Z_NULL; + } + return ret; +@@ -226,6 +248,7 @@ int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { + if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; ++ INFLATE_PRIME_HOOK(strm, bits, value); + state = (struct inflate_state FAR *)strm->state; + if (bits < 0) { + state->hold = 0; +@@ -351,6 +374,27 @@ void makefixed(void) + } + #endif /* MAKEFIXED */ + ++int ZLIB_INTERNAL inflate_ensure_window(state) ++ struct inflate_state *state; ++{ ++ /* if it hasn't been done already, allocate space for the window */ ++ if (state->window == Z_NULL) { ++ state->window = (unsigned char FAR *) ++ ZALLOC_WINDOW(state->strm, 1U << state->wbits, ++ sizeof(unsigned char)); ++ if (state->window == Z_NULL) return 1; ++ } ++ ++ /* if window not in use yet, initialize */ ++ if (state->wsize == 0) { ++ state->wsize = 1U << state->wbits; ++ state->wnext = 0; ++ state->whave = 0; ++ } ++ ++ return 0; ++} ++ + /* + Update the window with the last wsize (normally 32K) bytes written before + returning. If window does not exist yet, create it. This is only called +@@ -371,20 +415,7 @@ local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { + + state = (struct inflate_state FAR *)strm->state; + +- /* if it hasn't been done already, allocate space for the window */ +- if (state->window == Z_NULL) { +- state->window = (unsigned char FAR *) +- ZALLOC(strm, 1U << state->wbits, +- sizeof(unsigned char)); +- if (state->window == Z_NULL) return 1; +- } +- +- /* if window not in use yet, initialize */ +- if (state->wsize == 0) { +- state->wsize = 1U << state->wbits; +- state->wnext = 0; +- state->whave = 0; +- } ++ if (inflate_ensure_window(state)) return 1; + + /* copy state->wsize or less output bytes into the circular window */ + if (copy >= state->wsize) { +@@ -825,6 +856,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { + if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; + /* fallthrough */ + case TYPEDO: ++ INFLATE_TYPEDO_HOOK(strm, flush); + if (state->last) { + BYTEBITS(); + state->mode = CHECK; +@@ -1186,7 +1218,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { + out -= left; + strm->total_out += out; + state->total += out; +- if ((state->wrap & 4) && out) ++ if (INFLATE_NEED_CHECKSUM(strm) && (state->wrap & 4) && out) + strm->adler = state->check = + UPDATE_CHECK(state->check, put - out, out); + out = left; +@@ -1241,8 +1273,9 @@ int ZEXPORT inflate(z_streamp strm, int flush) { + */ + inf_leave: + RESTORE(); +- if (state->wsize || (out != strm->avail_out && state->mode < BAD && +- (state->mode < CHECK || flush != Z_FINISH))) ++ if (INFLATE_NEED_UPDATEWINDOW(strm) && ++ (state->wsize || (out != strm->avail_out && state->mode < BAD && ++ (state->mode < CHECK || flush != Z_FINISH)))) + if (updatewindow(strm, strm->next_out, out - strm->avail_out)) { + state->mode = MEM; + return Z_MEM_ERROR; +@@ -1252,7 +1285,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { + strm->total_in += in; + strm->total_out += out; + state->total += out; +- if ((state->wrap & 4) && out) ++ if (INFLATE_NEED_CHECKSUM(strm) && (state->wrap & 4) && out) + strm->adler = state->check = + UPDATE_CHECK(state->check, strm->next_out - out, out); + strm->data_type = (int)state->bits + (state->last ? 64 : 0) + +@@ -1268,8 +1301,8 @@ int ZEXPORT inflateEnd(z_streamp strm) { + if (inflateStateCheck(strm)) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; +- if (state->window != Z_NULL) ZFREE(strm, state->window); +- ZFREE(strm, strm->state); ++ if (state->window != Z_NULL) ZFREE_WINDOW(strm, state->window); ++ ZFREE_STATE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +@@ -1283,6 +1316,8 @@ int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + ++ INFLATE_GET_DICTIONARY_HOOK(strm, dictionary, dictLength); ++ + /* copy dictionary */ + if (state->whave && dictionary != Z_NULL) { + zmemcpy(dictionary, state->window + state->wnext, +@@ -1315,6 +1350,8 @@ int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + return Z_DATA_ERROR; + } + ++ INFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength); ++ + /* copy dictionary to window using updatewindow(), which will amend the + existing dictionary if appropriate */ + ret = updatewindow(strm, dictionary + dictLength, dictLength); +@@ -1432,6 +1469,7 @@ int ZEXPORT inflateSyncPoint(z_streamp strm) { + struct inflate_state FAR *state; + + if (inflateStateCheck(strm)) return Z_STREAM_ERROR; ++ INFLATE_SYNC_POINT_HOOK(strm); + state = (struct inflate_state FAR *)strm->state; + return state->mode == STORED && state->bits == 0; + } +@@ -1440,7 +1478,6 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { + struct inflate_state FAR *state; + struct inflate_state FAR *copy; + unsigned char FAR *window; +- unsigned wsize; + + /* check input */ + if (inflateStateCheck(source) || dest == Z_NULL) +@@ -1449,21 +1486,22 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { + + /* allocate space */ + copy = (struct inflate_state FAR *) +- ZALLOC(source, 1, sizeof(struct inflate_state)); ++ ZALLOC_STATE(source, 1, sizeof(struct inflate_state)); + if (copy == Z_NULL) return Z_MEM_ERROR; + window = Z_NULL; + if (state->window != Z_NULL) { + window = (unsigned char FAR *) +- ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); ++ ZALLOC_WINDOW(source, 1U << state->wbits, ++ sizeof(unsigned char)); + if (window == Z_NULL) { +- ZFREE(source, copy); ++ ZFREE_STATE(source, copy); + return Z_MEM_ERROR; + } + } + + /* copy state */ + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); +- zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); ++ ZCOPY_STATE((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); + copy->strm = dest; + if (state->lencode >= state->codes && + state->lencode <= state->codes + ENOUGH - 1) { +@@ -1472,8 +1510,7 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { + } + copy->next = copy->codes + (state->next - state->codes); + if (window != Z_NULL) { +- wsize = 1U << state->wbits; +- zmemcpy(window, state->window, wsize); ++ ZCOPY_WINDOW(window, state->window, 1U << state->wbits); + } + copy->window = window; + dest->state = (struct internal_state FAR *)copy; +@@ -1512,6 +1549,7 @@ long ZEXPORT inflateMark(z_streamp strm) { + + if (inflateStateCheck(strm)) + return -(1L << 16); ++ INFLATE_MARK_HOOK(strm); + state = (struct inflate_state FAR *)strm->state; + return (long)(((unsigned long)((long)state->back)) << 16) + + (state->mode == COPY ? state->length : +diff --git a/inflate.h b/inflate.h +index f127b6b..3d504e3 100644 +--- a/inflate.h ++++ b/inflate.h +@@ -124,3 +124,5 @@ struct inflate_state { + int back; /* bits back of last unprocessed length/lit */ + unsigned was; /* initial length of match */ + }; ++ ++int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state); +diff --git a/test/infcover.c b/test/infcover.c +index 8912c40..d1e8f5e 100644 +--- a/test/infcover.c ++++ b/test/infcover.c +@@ -462,8 +462,7 @@ local unsigned pull(void *desc, unsigned char **buf) + + local int push(void *desc, unsigned char *buf, unsigned len) + { +- (void)buf; +- (void)len; ++ buf += len; + return desc != Z_NULL; /* force error if desc not null */ + } + +diff --git a/test/minigzip.c b/test/minigzip.c +index 8a21ddf..a9d6cbc 100644 +--- a/test/minigzip.c ++++ b/test/minigzip.c +@@ -132,7 +132,11 @@ static void pwinerror (s) + #endif + #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) + ++#ifdef DFLTCC ++#define BUFLEN 262144 ++#else + #define BUFLEN 16384 ++#endif + #define MAX_NAME_LEN 1024 + + #ifdef MAXSEG_64K +diff --git a/trees.c b/trees.c +index 8dbdc40..c2786d6 100644 +--- a/trees.c ++++ b/trees.c +@@ -151,7 +151,7 @@ local TCONST static_tree_desc static_bl_desc = + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +-local unsigned bi_reverse(unsigned code, int len) { ++unsigned ZLIB_INTERNAL bi_reverse(unsigned code, int len) { + register unsigned res = 0; + do { + res |= code & 1; +@@ -178,7 +178,7 @@ local void bi_flush(deflate_state *s) { + /* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +-local void bi_windup(deflate_state *s) { ++void ZLIB_INTERNAL bi_windup(deflate_state *s) { + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { +@@ -285,6 +285,10 @@ local void send_bits(deflate_state *s, int value, int length) { + } + #endif /* ZLIB_DEBUG */ + ++void ZLIB_INTERNAL _tr_send_bits(deflate_state *s, int value, int length) ++{ ++ send_bits(s, value, length); ++} + + /* the arguments must not have side effects */ + +diff --git a/zutil.h b/zutil.h +index 902a304..573d954 100644 +--- a/zutil.h ++++ b/zutil.h +@@ -87,6 +87,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ + + #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + ++#define ZLIB_WRAPLEN 6 /* zlib format overhead */ ++ + /* target dependencies */ + + #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) diff -Nru zlib-1.2.13.dfsg/debian/patches/s390x/add-vectorized-crc32.patch zlib-1.3.1.dfsg/debian/patches/s390x/add-vectorized-crc32.patch --- zlib-1.2.13.dfsg/debian/patches/s390x/add-vectorized-crc32.patch 1970-01-01 00:00:00.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/s390x/add-vectorized-crc32.patch 2024-03-16 19:46:00.000000000 +0000 @@ -0,0 +1,428 @@ +From: Ilya Leoshkevich +Date: Thu, 19 Mar 2020 11:52:03 +0100 +Subject: s390x: vectorize crc32 + +Use vector extensions when compiling for s390x and binutils knows +about them. At runtime, check whether kernel supports vector +extensions (it has to be not just the CPU, but also the kernel) and +choose between the regular and the vectorized implementations. + +Origin: i-iii/zlib,https://github.com/iii-i/zlib/commit/559c8ee83d905535645a9eb62a09673bacb8229b + +Last-Update: 2024-03-16 +--- + Makefile.in | 9 ++ + configure | 28 ++++++ + contrib/gcc/zifunc.h | 21 ++++- + contrib/s390/crc32-vx.c | 195 ++++++++++++++++++++++++++++++++++++++++ + contrib/s390/crc32_z_resolver.c | 41 +++++++++ + crc32.c | 11 ++- + 6 files changed, 301 insertions(+), 4 deletions(-) + create mode 100644 contrib/s390/crc32-vx.c + create mode 100644 contrib/s390/crc32_z_resolver.c + +diff --git a/Makefile.in b/Makefile.in +index 2dbb20a..ede4db3 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -25,6 +25,7 @@ LDFLAGS= + TEST_LIBS=-L. libz.a + LDSHARED=$(CC) + CPP=$(CC) -E ++VGFMAFLAG= + + STATICLIB=libz.a + SHAREDLIB=libz.so +@@ -167,6 +168,9 @@ crc32.o: $(SRCDIR)crc32.c + crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c + $(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c + ++crc32-vx.o: $(SRCDIR)contrib/s390/crc32-vx.c ++ $(CC) $(CFLAGS) $(VGFMAFLAG) $(ZINC) -c -o $@ $(SRCDIR)contrib/s390/crc32-vx.c ++ + deflate.o: $(SRCDIR)deflate.c + $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c + +@@ -217,6 +221,11 @@ crc32.lo: $(SRCDIR)crc32.c + $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c + -@mv objs/crc32.o $@ + ++crc32-vx.lo: $(SRCDIR)contrib/s390/crc32-vx.c ++ -@mkdir objs 2>/dev/null || test -d objs ++ $(CC) $(SFLAGS) $(VGFMAFLAG) $(ZINC) -DPIC -c -o objs/crc32-vx.o $(SRCDIR)contrib/s390/crc32-vx.c ++ -@mv objs/crc32-vx.o $@ ++ + crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c + -@mkdir objs 2>/dev/null || test -d objs + $(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c +diff --git a/configure b/configure +index b96ed4a..3372cbf 100755 +--- a/configure ++++ b/configure +@@ -904,6 +904,32 @@ else + echo "Checking for Power optimizations support... No." | tee -a configure.log + fi + ++# check if we are compiling for s390 and binutils support vector extensions ++VGFMAFLAG=-march=z13 ++cat > $test.c <> configure.log + echo ALL = $ALL >> configure.log +@@ -935,6 +961,7 @@ echo mandir = $mandir >> configure.log + echo prefix = $prefix >> configure.log + echo sharedlibdir = $sharedlibdir >> configure.log + echo uname = $uname >> configure.log ++echo VGFMAFLAG = $VGFMAFLAG >> configure.log + + # update Makefile with the configure results + sed < ${SRCDIR}Makefile.in " +@@ -944,6 +971,7 @@ sed < ${SRCDIR}Makefile.in " + /^LDFLAGS *=/s#=.*#=$LDFLAGS# + /^LDSHARED *=/s#=.*#=$LDSHARED# + /^CPP *=/s#=.*#=$CPP# ++/^VGFMAFLAG *=/s#=.*#=$VGFMAFLAG# + /^STATICLIB *=/s#=.*#=$STATICLIB# + /^SHAREDLIB *=/s#=.*#=$SHAREDLIB# + /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# +diff --git a/contrib/gcc/zifunc.h b/contrib/gcc/zifunc.h +index daf4fe4..b62379e 100644 +--- a/contrib/gcc/zifunc.h ++++ b/contrib/gcc/zifunc.h +@@ -8,9 +8,28 @@ + + /* Helpers for arch optimizations */ + ++#if defined(__clang__) ++#if __has_feature(coverage_sanitizer) ++#define Z_IFUNC_NO_SANCOV __attribute__((no_sanitize("coverage"))) ++#else /* __has_feature(coverage_sanitizer) */ ++#define Z_IFUNC_NO_SANCOV ++#endif /* __has_feature(coverage_sanitizer) */ ++#else /* __clang__ */ ++#define Z_IFUNC_NO_SANCOV ++#endif /* __clang__ */ ++ ++#ifdef __s390__ ++#define Z_IFUNC_PARAMS unsigned long hwcap ++#define Z_IFUNC_ATTRS Z_IFUNC_NO_SANCOV ++#else /* __s390__ */ ++#define Z_IFUNC_PARAMS void ++#define Z_IFUNC_ATTRS ++#endif /* __s390__ */ ++ + #define Z_IFUNC(fname) \ + typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \ +- local typeof(fname) *fname##_resolver(void) ++ Z_IFUNC_ATTRS \ ++ local typeof(fname) *fname##_resolver(Z_IFUNC_PARAMS) + /* This is a helper macro to declare a resolver for an indirect function + * (ifunc). Let's say you have function + * +diff --git a/contrib/s390/crc32-vx.c b/contrib/s390/crc32-vx.c +new file mode 100644 +index 0000000..fa5387c +--- /dev/null ++++ b/contrib/s390/crc32-vx.c +@@ -0,0 +1,195 @@ ++/* ++ * Hardware-accelerated CRC-32 variants for Linux on z Systems ++ * ++ * Use the z/Architecture Vector Extension Facility to accelerate the ++ * computing of bitreflected CRC-32 checksums. ++ * ++ * This CRC-32 implementation algorithm is bitreflected and processes ++ * the least-significant bit first (Little-Endian). ++ * ++ * This code was originally written by Hendrik Brueckner ++ * for use in the Linux kernel and has been ++ * relicensed under the zlib license. ++ */ ++ ++#include "../../zutil.h" ++ ++#include ++#include ++ ++typedef unsigned char uv16qi __attribute__((vector_size(16))); ++typedef unsigned int uv4si __attribute__((vector_size(16))); ++typedef unsigned long long uv2di __attribute__((vector_size(16))); ++ ++uint32_t crc32_le_vgfm_16(uint32_t crc, const unsigned char *buf, size_t len) { ++ /* ++ * The CRC-32 constant block contains reduction constants to fold and ++ * process particular chunks of the input data stream in parallel. ++ * ++ * For the CRC-32 variants, the constants are precomputed according to ++ * these definitions: ++ * ++ * R1 = [(x4*128+32 mod P'(x) << 32)]' << 1 ++ * R2 = [(x4*128-32 mod P'(x) << 32)]' << 1 ++ * R3 = [(x128+32 mod P'(x) << 32)]' << 1 ++ * R4 = [(x128-32 mod P'(x) << 32)]' << 1 ++ * R5 = [(x64 mod P'(x) << 32)]' << 1 ++ * R6 = [(x32 mod P'(x) << 32)]' << 1 ++ * ++ * The bitreflected Barret reduction constant, u', is defined as ++ * the bit reversal of floor(x**64 / P(x)). ++ * ++ * where P(x) is the polynomial in the normal domain and the P'(x) is the ++ * polynomial in the reversed (bitreflected) domain. ++ * ++ * CRC-32 (IEEE 802.3 Ethernet, ...) polynomials: ++ * ++ * P(x) = 0x04C11DB7 ++ * P'(x) = 0xEDB88320 ++ */ ++ const uv16qi perm_le2be = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; /* BE->LE mask */ ++ const uv2di r2r1 = {0x1C6E41596, 0x154442BD4}; /* R2, R1 */ ++ const uv2di r4r3 = {0x0CCAA009E, 0x1751997D0}; /* R4, R3 */ ++ const uv2di r5 = {0, 0x163CD6124}; /* R5 */ ++ const uv2di ru_poly = {0, 0x1F7011641}; /* u' */ ++ const uv2di crc_poly = {0, 0x1DB710641}; /* P'(x) << 1 */ ++ ++ /* ++ * Load the initial CRC value. ++ * ++ * The CRC value is loaded into the rightmost word of the ++ * vector register and is later XORed with the LSB portion ++ * of the loaded input data. ++ */ ++ uv2di v0 = {0, 0}; ++ v0 = (uv2di)vec_insert(crc, (uv4si)v0, 3); ++ ++ /* Load a 64-byte data chunk and XOR with CRC */ ++ uv2di v1 = vec_perm(((uv2di *)buf)[0], ((uv2di *)buf)[0], perm_le2be); ++ uv2di v2 = vec_perm(((uv2di *)buf)[1], ((uv2di *)buf)[1], perm_le2be); ++ uv2di v3 = vec_perm(((uv2di *)buf)[2], ((uv2di *)buf)[2], perm_le2be); ++ uv2di v4 = vec_perm(((uv2di *)buf)[3], ((uv2di *)buf)[3], perm_le2be); ++ ++ v1 ^= v0; ++ buf += 64; ++ len -= 64; ++ ++ while (len >= 64) { ++ /* Load the next 64-byte data chunk */ ++ uv16qi part1 = vec_perm(((uv16qi *)buf)[0], ((uv16qi *)buf)[0], perm_le2be); ++ uv16qi part2 = vec_perm(((uv16qi *)buf)[1], ((uv16qi *)buf)[1], perm_le2be); ++ uv16qi part3 = vec_perm(((uv16qi *)buf)[2], ((uv16qi *)buf)[2], perm_le2be); ++ uv16qi part4 = vec_perm(((uv16qi *)buf)[3], ((uv16qi *)buf)[3], perm_le2be); ++ ++ /* ++ * Perform a GF(2) multiplication of the doublewords in V1 with ++ * the R1 and R2 reduction constants in V0. The intermediate result ++ * is then folded (accumulated) with the next data chunk in PART1 and ++ * stored in V1. Repeat this step for the register contents ++ * in V2, V3, and V4 respectively. ++ */ ++ v1 = (uv2di)vec_gfmsum_accum_128(r2r1, v1, part1); ++ v2 = (uv2di)vec_gfmsum_accum_128(r2r1, v2, part2); ++ v3 = (uv2di)vec_gfmsum_accum_128(r2r1, v3, part3); ++ v4 = (uv2di)vec_gfmsum_accum_128(r2r1, v4, part4); ++ ++ buf += 64; ++ len -= 64; ++ } ++ ++ /* ++ * Fold V1 to V4 into a single 128-bit value in V1. Multiply V1 with R3 ++ * and R4 and accumulating the next 128-bit chunk until a single 128-bit ++ * value remains. ++ */ ++ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v2); ++ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v3); ++ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v4); ++ ++ while (len >= 16) { ++ /* Load next data chunk */ ++ v2 = vec_perm(*(uv2di *)buf, *(uv2di *)buf, perm_le2be); ++ ++ /* Fold next data chunk */ ++ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v2); ++ ++ buf += 16; ++ len -= 16; ++ } ++ ++ /* ++ * Set up a vector register for byte shifts. The shift value must ++ * be loaded in bits 1-4 in byte element 7 of a vector register. ++ * Shift by 8 bytes: 0x40 ++ * Shift by 4 bytes: 0x20 ++ */ ++ uv16qi v9 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; ++ v9 = vec_insert((unsigned char)0x40, v9, 7); ++ ++ /* ++ * Prepare V0 for the next GF(2) multiplication: shift V0 by 8 bytes ++ * to move R4 into the rightmost doubleword and set the leftmost ++ * doubleword to 0x1. ++ */ ++ v0 = vec_srb(r4r3, (uv2di)v9); ++ v0[0] = 1; ++ ++ /* ++ * Compute GF(2) product of V1 and V0. The rightmost doubleword ++ * of V1 is multiplied with R4. The leftmost doubleword of V1 is ++ * multiplied by 0x1 and is then XORed with rightmost product. ++ * Implicitly, the intermediate leftmost product becomes padded ++ */ ++ v1 = (uv2di)vec_gfmsum_128(v0, v1); ++ ++ /* ++ * Now do the final 32-bit fold by multiplying the rightmost word ++ * in V1 with R5 and XOR the result with the remaining bits in V1. ++ * ++ * To achieve this by a single VGFMAG, right shift V1 by a word ++ * and store the result in V2 which is then accumulated. Use the ++ * vector unpack instruction to load the rightmost half of the ++ * doubleword into the rightmost doubleword element of V1; the other ++ * half is loaded in the leftmost doubleword. ++ * The vector register with CONST_R5 contains the R5 constant in the ++ * rightmost doubleword and the leftmost doubleword is zero to ignore ++ * the leftmost product of V1. ++ */ ++ v9 = vec_insert((unsigned char)0x20, v9, 7); ++ v2 = vec_srb(v1, (uv2di)v9); ++ v1 = vec_unpackl((uv4si)v1); /* Split rightmost doubleword */ ++ v1 = (uv2di)vec_gfmsum_accum_128(r5, v1, (uv16qi)v2); ++ ++ /* ++ * Apply a Barret reduction to compute the final 32-bit CRC value. ++ * ++ * The input values to the Barret reduction are the degree-63 polynomial ++ * in V1 (R(x)), degree-32 generator polynomial, and the reduction ++ * constant u. The Barret reduction result is the CRC value of R(x) mod ++ * P(x). ++ * ++ * The Barret reduction algorithm is defined as: ++ * ++ * 1. T1(x) = floor( R(x) / x^32 ) GF2MUL u ++ * 2. T2(x) = floor( T1(x) / x^32 ) GF2MUL P(x) ++ * 3. C(x) = R(x) XOR T2(x) mod x^32 ++ * ++ * Note: The leftmost doubleword of vector register containing ++ * CONST_RU_POLY is zero and, thus, the intermediate GF(2) product ++ * is zero and does not contribute to the final result. ++ */ ++ ++ /* T1(x) = floor( R(x) / x^32 ) GF2MUL u */ ++ v2 = vec_unpackl((uv4si)v1); ++ v2 = (uv2di)vec_gfmsum_128(ru_poly, v2); ++ ++ /* ++ * Compute the GF(2) product of the CRC polynomial with T1(x) in ++ * V2 and XOR the intermediate result, T2(x), with the value in V1. ++ * The final result is stored in word element 2 of V2. ++ */ ++ v2 = vec_unpackl((uv4si)v2); ++ v2 = (uv2di)vec_gfmsum_accum_128(crc_poly, v2, (uv16qi)v1); ++ ++ return ((uv4si)v2)[2]; ++} +diff --git a/contrib/s390/crc32_z_resolver.c b/contrib/s390/crc32_z_resolver.c +new file mode 100644 +index 0000000..9749cab +--- /dev/null ++++ b/contrib/s390/crc32_z_resolver.c +@@ -0,0 +1,41 @@ ++#include ++#include "../gcc/zifunc.h" ++ ++#define VX_MIN_LEN 64 ++#define VX_ALIGNMENT 16L ++#define VX_ALIGN_MASK (VX_ALIGNMENT - 1) ++ ++unsigned int crc32_le_vgfm_16(unsigned int crc, const unsigned char FAR *buf, z_size_t len); ++ ++local unsigned long s390_crc32_vx(unsigned long crc, const unsigned char FAR *buf, z_size_t len) ++{ ++ uintptr_t prealign, aligned, remaining; ++ ++ if (buf == Z_NULL) return 0UL; ++ ++ if (len < VX_MIN_LEN + VX_ALIGN_MASK) ++ return crc32_z_default(crc, buf, len); ++ ++ if ((uintptr_t)buf & VX_ALIGN_MASK) { ++ prealign = VX_ALIGNMENT - ((uintptr_t)buf & VX_ALIGN_MASK); ++ len -= prealign; ++ crc = crc32_z_default(crc, buf, prealign); ++ buf += prealign; ++ } ++ aligned = len & ~VX_ALIGN_MASK; ++ remaining = len & VX_ALIGN_MASK; ++ ++ crc = crc32_le_vgfm_16(crc ^ 0xffffffff, buf, (size_t)aligned) ^ 0xffffffff; ++ ++ if (remaining) ++ crc = crc32_z_default(crc, buf + aligned, remaining); ++ ++ return crc; ++} ++ ++Z_IFUNC(crc32_z) ++{ ++ if (hwcap & HWCAP_S390_VX) ++ return s390_crc32_vx; ++ return crc32_z_default; ++} +diff --git a/crc32.c b/crc32.c +index 5589d54..afff3d7 100644 +--- a/crc32.c ++++ b/crc32.c +@@ -691,12 +691,12 @@ local z_word_t crc_word_big(z_word_t data) { + #endif + + /* ========================================================================= */ +-#ifdef Z_POWER_OPT ++#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) + /* Rename function so resolver can use its symbol. The default version will be + * returned by the resolver if the host has no support for an optimized version. + */ + #define crc32_z crc32_z_default +-#endif /* Z_POWER_OPT */ ++#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */ + + unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { +@@ -1016,10 +1016,15 @@ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + return crc ^ 0xffffffff; + } + +-#ifdef Z_POWER_OPT ++#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) + #undef crc32_z ++#ifdef Z_POWER_OPT + #include "contrib/power/crc32_z_resolver.c" + #endif /* Z_POWER_OPT */ ++#ifdef HAVE_S390X_VX ++#include "contrib/s390/crc32_z_resolver.c" ++#endif /* HAVE_S390X_VX */ ++#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */ + + #endif + diff -Nru zlib-1.2.13.dfsg/debian/patches/s390x-vectorize-crc32.patch zlib-1.3.1.dfsg/debian/patches/s390x-vectorize-crc32.patch --- zlib-1.2.13.dfsg/debian/patches/s390x-vectorize-crc32.patch 2022-11-21 19:28:58.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/s390x-vectorize-crc32.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,402 +0,0 @@ -Description: s390x: vectorize crc32 - Use vector extensions when compiling for s390x and binutils knows - about them. At runtime, check whether kernel supports vector - extensions (it has to be not just the CPU, but also the kernel) and - choose between the regular and the vectorized implementations. -Author: Ilya Leoshkevich -Origin: https://github.com/iii-i/zlib/commit/05710d5fb8eb1447289ebf11109e149ece95d839 -Bug-Ubuntu: https://bugs.launchpad.net/bugs/1234567 -Forwarded: not-needed -Reviewed-by: Frank Heimes -Last-Update: 2022-11-21 ---- a/Makefile.in -+++ b/Makefile.in -@@ -25,6 +25,7 @@ - TEST_LDFLAGS=$(LDFLAGS) -L. libz.a - LDSHARED=$(CC) - CPP=$(CC) -E -+VGFMAFLAG= - - STATICLIB=libz.a - SHAREDLIB=libz.so -@@ -175,6 +176,9 @@ - crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c - $(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c - -+crc32-vx.o: $(SRCDIR)contrib/s390/crc32-vx.c -+ $(CC) $(CFLAGS) $(VGFMAFLAG) $(ZINC) -c -o $@ $(SRCDIR)contrib/s390/crc32-vx.c -+ - deflate.o: $(SRCDIR)deflate.c - $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c - -@@ -225,6 +229,11 @@ - $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c - -@mv objs/crc32.o $@ - -+crc32-vx.lo: $(SRCDIR)contrib/s390/crc32-vx.c -+ -@mkdir objs 2>/dev/null || test -d objs -+ $(CC) $(SFLAGS) $(VGFMAFLAG) $(ZINC) -DPIC -c -o objs/crc32-vx.o $(SRCDIR)contrib/s390/crc32-vx.c -+ -@mv objs/crc32-vx.o $@ -+ - crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c - -@mkdir objs 2>/dev/null || test -d objs - $(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c ---- a/configure -+++ b/configure -@@ -921,6 +921,32 @@ - echo "Checking for Power optimizations support... No." | tee -a configure.log - fi - -+# check if we are compiling for s390 and binutils support vector extensions -+VGFMAFLAG=-march=z13 -+cat > $test.c <> configure.log - echo ALL = $ALL >> configure.log -@@ -952,6 +978,7 @@ - echo prefix = $prefix >> configure.log - echo sharedlibdir = $sharedlibdir >> configure.log - echo uname = $uname >> configure.log -+echo VGFMAFLAG = $VGFMAFLAG >> configure.log - - # udpate Makefile with the configure results - sed < ${SRCDIR}Makefile.in " -@@ -961,6 +988,7 @@ - /^LDFLAGS *=/s#=.*#=$LDFLAGS# - /^LDSHARED *=/s#=.*#=$LDSHARED# - /^CPP *=/s#=.*#=$CPP# -+/^VGFMAFLAG *=/s#=.*#=$VGFMAFLAG# - /^STATICLIB *=/s#=.*#=$STATICLIB# - /^SHAREDLIB *=/s#=.*#=$SHAREDLIB# - /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# ---- a/contrib/gcc/zifunc.h -+++ b/contrib/gcc/zifunc.h -@@ -8,9 +8,28 @@ - - /* Helpers for arch optimizations */ - -+#if defined(__clang__) -+#if __has_feature(coverage_sanitizer) -+#define Z_IFUNC_NO_SANCOV __attribute__((no_sanitize("coverage"))) -+#else /* __has_feature(coverage_sanitizer) */ -+#define Z_IFUNC_NO_SANCOV -+#endif /* __has_feature(coverage_sanitizer) */ -+#else /* __clang__ */ -+#define Z_IFUNC_NO_SANCOV -+#endif /* __clang__ */ -+ -+#ifdef __s390__ -+#define Z_IFUNC_PARAMS unsigned long hwcap -+#define Z_IFUNC_ATTRS Z_IFUNC_NO_SANCOV -+#else /* __s390__ */ -+#define Z_IFUNC_PARAMS void -+#define Z_IFUNC_ATTRS -+#endif /* __s390__ */ -+ - #define Z_IFUNC(fname) \ - typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \ -- local typeof(fname) *fname##_resolver(void) -+ Z_IFUNC_ATTRS \ -+ local typeof(fname) *fname##_resolver(Z_IFUNC_PARAMS) - /* This is a helper macro to declare a resolver for an indirect function - * (ifunc). Let's say you have function - * ---- /dev/null -+++ b/contrib/s390/crc32-vx.c -@@ -0,0 +1,195 @@ -+/* -+ * Hardware-accelerated CRC-32 variants for Linux on z Systems -+ * -+ * Use the z/Architecture Vector Extension Facility to accelerate the -+ * computing of bitreflected CRC-32 checksums. -+ * -+ * This CRC-32 implementation algorithm is bitreflected and processes -+ * the least-significant bit first (Little-Endian). -+ * -+ * This code was originally written by Hendrik Brueckner -+ * for use in the Linux kernel and has been -+ * relicensed under the zlib license. -+ */ -+ -+#include "../../zutil.h" -+ -+#include -+#include -+ -+typedef unsigned char uv16qi __attribute__((vector_size(16))); -+typedef unsigned int uv4si __attribute__((vector_size(16))); -+typedef unsigned long long uv2di __attribute__((vector_size(16))); -+ -+uint32_t crc32_le_vgfm_16(uint32_t crc, const unsigned char *buf, size_t len) { -+ /* -+ * The CRC-32 constant block contains reduction constants to fold and -+ * process particular chunks of the input data stream in parallel. -+ * -+ * For the CRC-32 variants, the constants are precomputed according to -+ * these definitions: -+ * -+ * R1 = [(x4*128+32 mod P'(x) << 32)]' << 1 -+ * R2 = [(x4*128-32 mod P'(x) << 32)]' << 1 -+ * R3 = [(x128+32 mod P'(x) << 32)]' << 1 -+ * R4 = [(x128-32 mod P'(x) << 32)]' << 1 -+ * R5 = [(x64 mod P'(x) << 32)]' << 1 -+ * R6 = [(x32 mod P'(x) << 32)]' << 1 -+ * -+ * The bitreflected Barret reduction constant, u', is defined as -+ * the bit reversal of floor(x**64 / P(x)). -+ * -+ * where P(x) is the polynomial in the normal domain and the P'(x) is the -+ * polynomial in the reversed (bitreflected) domain. -+ * -+ * CRC-32 (IEEE 802.3 Ethernet, ...) polynomials: -+ * -+ * P(x) = 0x04C11DB7 -+ * P'(x) = 0xEDB88320 -+ */ -+ const uv16qi perm_le2be = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; /* BE->LE mask */ -+ const uv2di r2r1 = {0x1C6E41596, 0x154442BD4}; /* R2, R1 */ -+ const uv2di r4r3 = {0x0CCAA009E, 0x1751997D0}; /* R4, R3 */ -+ const uv2di r5 = {0, 0x163CD6124}; /* R5 */ -+ const uv2di ru_poly = {0, 0x1F7011641}; /* u' */ -+ const uv2di crc_poly = {0, 0x1DB710641}; /* P'(x) << 1 */ -+ -+ /* -+ * Load the initial CRC value. -+ * -+ * The CRC value is loaded into the rightmost word of the -+ * vector register and is later XORed with the LSB portion -+ * of the loaded input data. -+ */ -+ uv2di v0 = {0, 0}; -+ v0 = (uv2di)vec_insert(crc, (uv4si)v0, 3); -+ -+ /* Load a 64-byte data chunk and XOR with CRC */ -+ uv2di v1 = vec_perm(((uv2di *)buf)[0], ((uv2di *)buf)[0], perm_le2be); -+ uv2di v2 = vec_perm(((uv2di *)buf)[1], ((uv2di *)buf)[1], perm_le2be); -+ uv2di v3 = vec_perm(((uv2di *)buf)[2], ((uv2di *)buf)[2], perm_le2be); -+ uv2di v4 = vec_perm(((uv2di *)buf)[3], ((uv2di *)buf)[3], perm_le2be); -+ -+ v1 ^= v0; -+ buf += 64; -+ len -= 64; -+ -+ while (len >= 64) { -+ /* Load the next 64-byte data chunk */ -+ uv16qi part1 = vec_perm(((uv16qi *)buf)[0], ((uv16qi *)buf)[0], perm_le2be); -+ uv16qi part2 = vec_perm(((uv16qi *)buf)[1], ((uv16qi *)buf)[1], perm_le2be); -+ uv16qi part3 = vec_perm(((uv16qi *)buf)[2], ((uv16qi *)buf)[2], perm_le2be); -+ uv16qi part4 = vec_perm(((uv16qi *)buf)[3], ((uv16qi *)buf)[3], perm_le2be); -+ -+ /* -+ * Perform a GF(2) multiplication of the doublewords in V1 with -+ * the R1 and R2 reduction constants in V0. The intermediate result -+ * is then folded (accumulated) with the next data chunk in PART1 and -+ * stored in V1. Repeat this step for the register contents -+ * in V2, V3, and V4 respectively. -+ */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r2r1, v1, part1); -+ v2 = (uv2di)vec_gfmsum_accum_128(r2r1, v2, part2); -+ v3 = (uv2di)vec_gfmsum_accum_128(r2r1, v3, part3); -+ v4 = (uv2di)vec_gfmsum_accum_128(r2r1, v4, part4); -+ -+ buf += 64; -+ len -= 64; -+ } -+ -+ /* -+ * Fold V1 to V4 into a single 128-bit value in V1. Multiply V1 with R3 -+ * and R4 and accumulating the next 128-bit chunk until a single 128-bit -+ * value remains. -+ */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v2); -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v3); -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v4); -+ -+ while (len >= 16) { -+ /* Load next data chunk */ -+ v2 = vec_perm(*(uv2di *)buf, *(uv2di *)buf, perm_le2be); -+ -+ /* Fold next data chunk */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r4r3, v1, (uv16qi)v2); -+ -+ buf += 16; -+ len -= 16; -+ } -+ -+ /* -+ * Set up a vector register for byte shifts. The shift value must -+ * be loaded in bits 1-4 in byte element 7 of a vector register. -+ * Shift by 8 bytes: 0x40 -+ * Shift by 4 bytes: 0x20 -+ */ -+ uv16qi v9 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -+ v9 = vec_insert((unsigned char)0x40, v9, 7); -+ -+ /* -+ * Prepare V0 for the next GF(2) multiplication: shift V0 by 8 bytes -+ * to move R4 into the rightmost doubleword and set the leftmost -+ * doubleword to 0x1. -+ */ -+ v0 = vec_srb(r4r3, (uv2di)v9); -+ v0[0] = 1; -+ -+ /* -+ * Compute GF(2) product of V1 and V0. The rightmost doubleword -+ * of V1 is multiplied with R4. The leftmost doubleword of V1 is -+ * multiplied by 0x1 and is then XORed with rightmost product. -+ * Implicitly, the intermediate leftmost product becomes padded -+ */ -+ v1 = (uv2di)vec_gfmsum_128(v0, v1); -+ -+ /* -+ * Now do the final 32-bit fold by multiplying the rightmost word -+ * in V1 with R5 and XOR the result with the remaining bits in V1. -+ * -+ * To achieve this by a single VGFMAG, right shift V1 by a word -+ * and store the result in V2 which is then accumulated. Use the -+ * vector unpack instruction to load the rightmost half of the -+ * doubleword into the rightmost doubleword element of V1; the other -+ * half is loaded in the leftmost doubleword. -+ * The vector register with CONST_R5 contains the R5 constant in the -+ * rightmost doubleword and the leftmost doubleword is zero to ignore -+ * the leftmost product of V1. -+ */ -+ v9 = vec_insert((unsigned char)0x20, v9, 7); -+ v2 = vec_srb(v1, (uv2di)v9); -+ v1 = vec_unpackl((uv4si)v1); /* Split rightmost doubleword */ -+ v1 = (uv2di)vec_gfmsum_accum_128(r5, v1, (uv16qi)v2); -+ -+ /* -+ * Apply a Barret reduction to compute the final 32-bit CRC value. -+ * -+ * The input values to the Barret reduction are the degree-63 polynomial -+ * in V1 (R(x)), degree-32 generator polynomial, and the reduction -+ * constant u. The Barret reduction result is the CRC value of R(x) mod -+ * P(x). -+ * -+ * The Barret reduction algorithm is defined as: -+ * -+ * 1. T1(x) = floor( R(x) / x^32 ) GF2MUL u -+ * 2. T2(x) = floor( T1(x) / x^32 ) GF2MUL P(x) -+ * 3. C(x) = R(x) XOR T2(x) mod x^32 -+ * -+ * Note: The leftmost doubleword of vector register containing -+ * CONST_RU_POLY is zero and, thus, the intermediate GF(2) product -+ * is zero and does not contribute to the final result. -+ */ -+ -+ /* T1(x) = floor( R(x) / x^32 ) GF2MUL u */ -+ v2 = vec_unpackl((uv4si)v1); -+ v2 = (uv2di)vec_gfmsum_128(ru_poly, v2); -+ -+ /* -+ * Compute the GF(2) product of the CRC polynomial with T1(x) in -+ * V2 and XOR the intermediate result, T2(x), with the value in V1. -+ * The final result is stored in word element 2 of V2. -+ */ -+ v2 = vec_unpackl((uv4si)v2); -+ v2 = (uv2di)vec_gfmsum_accum_128(crc_poly, v2, (uv16qi)v1); -+ -+ return ((uv4si)v2)[2]; -+} ---- /dev/null -+++ b/contrib/s390/crc32_z_resolver.c -@@ -0,0 +1,41 @@ -+#include -+#include "../gcc/zifunc.h" -+ -+#define VX_MIN_LEN 64 -+#define VX_ALIGNMENT 16L -+#define VX_ALIGN_MASK (VX_ALIGNMENT - 1) -+ -+unsigned int crc32_le_vgfm_16(unsigned int crc, const unsigned char FAR *buf, z_size_t len); -+ -+local unsigned long s390_crc32_vx(unsigned long crc, const unsigned char FAR *buf, z_size_t len) -+{ -+ uintptr_t prealign, aligned, remaining; -+ -+ if (buf == Z_NULL) return 0UL; -+ -+ if (len < VX_MIN_LEN + VX_ALIGN_MASK) -+ return crc32_z_default(crc, buf, len); -+ -+ if ((uintptr_t)buf & VX_ALIGN_MASK) { -+ prealign = VX_ALIGNMENT - ((uintptr_t)buf & VX_ALIGN_MASK); -+ len -= prealign; -+ crc = crc32_z_default(crc, buf, prealign); -+ buf += prealign; -+ } -+ aligned = len & ~VX_ALIGN_MASK; -+ remaining = len & VX_ALIGN_MASK; -+ -+ crc = crc32_le_vgfm_16(crc ^ 0xffffffff, buf, (size_t)aligned) ^ 0xffffffff; -+ -+ if (remaining) -+ crc = crc32_z_default(crc, buf + aligned, remaining); -+ -+ return crc; -+} -+ -+Z_IFUNC(crc32_z) -+{ -+ if (hwcap & HWCAP_S390_VX) -+ return s390_crc32_vx; -+ return crc32_z_default; -+} ---- a/crc32.c -+++ b/crc32.c -@@ -745,12 +745,12 @@ - #endif - - /* ========================================================================= */ --#ifdef Z_POWER_OPT -+#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) - /* Rename function so resolver can use its symbol. The default version will be - * returned by the resolver if the host has no support for an optimized version. - */ - #define crc32_z crc32_z_default --#endif /* Z_POWER_OPT */ -+#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */ - - unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; -@@ -1073,10 +1073,15 @@ - return crc ^ 0xffffffff; - } - --#ifdef Z_POWER_OPT -+#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) - #undef crc32_z -+#ifdef Z_POWER_OPT - #include "contrib/power/crc32_z_resolver.c" - #endif /* Z_POWER_OPT */ -+#ifdef HAVE_S390X_VX -+#include "contrib/s390/crc32_z_resolver.c" -+#endif /* HAVE_S390X_VX */ -+#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */ - - #endif - diff -Nru zlib-1.2.13.dfsg/debian/patches/series zlib-1.3.1.dfsg/debian/patches/series --- zlib-1.2.13.dfsg/debian/patches/series 2023-01-11 17:02:34.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/series 2024-03-16 19:36:29.000000000 +0000 @@ -1,6 +1,5 @@ -cflags-for-minizip -use-dso-really -410.patch -478.patch -s390x-vectorize-crc32.patch -1390.patch +power/indirect-func-macros.patch +power/add-optimized-crc32.patch +power/fix-clang7-builtins.patch +s390x/add-vectorized-crc32.patch +s390x/add-accel-deflate.patch diff -Nru zlib-1.2.13.dfsg/debian/patches/use-dso-really zlib-1.3.1.dfsg/debian/patches/use-dso-really --- zlib-1.2.13.dfsg/debian/patches/use-dso-really 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/patches/use-dso-really 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ ---- a/contrib/minizip/Makefile.orig 2022-11-05 12:58:48.240820416 +0000 -+++ b/contrib/minizip/Makefile 2022-11-05 12:59:42.329430869 +0000 -@@ -1,8 +1,9 @@ - CC=cc - CFLAGS += $(CFLAGS) -O -I../.. -+LDFLAGS += -L../.. -lz - --UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a --ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a -+UNZ_OBJS = miniunz.o unzip.o ioapi.o -+ZIP_OBJS = minizip.o zip.o ioapi.o - - .c.o: - $(CC) -c $(CFLAGS) $*.c diff -Nru zlib-1.2.13.dfsg/debian/rules zlib-1.3.1.dfsg/debian/rules --- zlib-1.2.13.dfsg/debian/rules 2022-11-21 19:28:58.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/rules 2023-11-24 08:22:52.000000000 +0000 @@ -19,7 +19,6 @@ CFLAGS = `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` -Wall -D_REENTRANT LDFLAGS = `dpkg-buildflags --get LDFLAGS` -EXTRA_MAKE = CONFIGURE_COMMON=--shared --prefix=/usr CONFIGURE_HOST=--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) @@ -100,6 +99,8 @@ AR=$(AR) CC="$(DEB_HOST_GNU_TYPE)-gcc" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" uname=GNU ./configure $(CONFIGURE_COMMON) $(CONFIGURE_HOST) + cd contrib/minizip && autoreconf -fis && CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" uname=GNU ./configure --prefix=/usr --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) + touch $@ configure64-stamp: configure @@ -149,7 +150,10 @@ build-stamp: configure-stamp dh_testdir - $(MAKE) $(EXTRA_MAKE) + $(MAKE) + + $(MAKE) -C contrib/minizip minizip miniunzip + -$(MAKE) test touch $@ @@ -161,7 +165,7 @@ build32-stamp: configure32-stamp dh_testdir - make -C debian/32 $(EXTRA_MAKE) + make -C debian/32 touch $@ buildn32-stamp: configuren32-stamp @@ -178,6 +182,9 @@ dh_testdir dh_testroot + if [ -f contrib/minizip/Makefile ]; then $(MAKE) -C contrib/minizip clean; fi + cd contrib/minizip && rm -f compile config.* configure depcomp install-sh libtool Makefile Makefile.in aclocal.m4 ltmain.sh missing minizip.pc minizip miniunzip + $(MAKE) distclean rm -f build-stamp configure-stamp foo.gz @@ -198,9 +205,8 @@ $(MAKE) prefix=$(CURDIR)/debian/tmp/usr install - install -d debian/tmp/lib/$(DEB_HOST_MULTIARCH) - mv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libz.so.* debian/tmp/lib/$(DEB_HOST_MULTIARCH) - ln -sf /lib/$(DEB_HOST_MULTIARCH)/$$(readlink debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libz.so) debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libz.so + $(MAKE) -C contrib/minizip prefix=$(CURDIR)/debian/tmp/usr install + find contrib/minizip install64: install build64-stamp $(MAKE) -C debian/64 prefix=$(CURDIR)/debian/tmp install @@ -222,6 +228,9 @@ binary-arch: build install $(EXTRA_INSTALL) dh_testdir dh_testroot + mkdir -p debian/tmp/usr/bin + cp contrib/minizip/.libs/minizip debian/tmp/usr/bin + cp contrib/minizip/.libs/miniunzip debian/tmp/usr/bin dh_installchangelogs -a ChangeLog dh_installdocs -a dh_installexamples -a @@ -232,6 +241,7 @@ dh_strip -a --dbgsym-migration="zlib1g-dbg (<< 1:1.2.11.dfsg-2~)" dh_compress -a dh_fixperms -a + dh_makeshlibs -plibminizip1 -V"libminizip1 (>> 1:1.2.13.dfsg-1)" dh_makeshlibs -pzlib1g -V"zlib1g (>= 1:1.2.3.3.dfsg-1)" --add-udeb=zlib1g-udeb ifeq (,$(filter nobiarch,$(DEB_BUILD_PROFILES))) ifneq (,$(filter $(DEB_HOST_ARCH), $(32-ARCHS))) diff -Nru zlib-1.2.13.dfsg/debian/watch zlib-1.3.1.dfsg/debian/watch --- zlib-1.2.13.dfsg/debian/watch 2020-08-19 23:07:11.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/watch 2024-03-16 19:14:36.000000000 +0000 @@ -1,2 +1,3 @@ version=4 -opts="pgpmode=auto, dversionmangle=s/\.dfsg$//, repacksuffix=.dfsg" http://sf.net/libpng/ zlib-(.+)\.tar\.xz +opts="pgpmode=auto, dversionmangle=s/\.dfsg$//, repacksuffix=.dfsg" \ + https://zlib.net/ zlib-(\d.\S+)\.tar\.xz diff -Nru zlib-1.2.13.dfsg/debian/zlib1g-dev.install zlib-1.3.1.dfsg/debian/zlib1g-dev.install --- zlib-1.2.13.dfsg/debian/zlib1g-dev.install 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/zlib1g-dev.install 2023-11-24 08:22:52.000000000 +0000 @@ -1,4 +1,4 @@ -usr/include/* +usr/include/*.h usr/lib/*/libz.a usr/lib/*/libz.so usr/share/man/man3/* diff -Nru zlib-1.2.13.dfsg/debian/zlib1g-udeb.install zlib-1.3.1.dfsg/debian/zlib1g-udeb.install --- zlib-1.2.13.dfsg/debian/zlib1g-udeb.install 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/zlib1g-udeb.install 2023-11-24 08:22:52.000000000 +0000 @@ -1 +1 @@ -lib/*/lib*.so.* usr/lib +usr/lib/*/lib*.so.* usr/lib diff -Nru zlib-1.2.13.dfsg/debian/zlib1g.dirs zlib-1.3.1.dfsg/debian/zlib1g.dirs --- zlib-1.2.13.dfsg/debian/zlib1g.dirs 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/zlib1g.dirs 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -lib diff -Nru zlib-1.2.13.dfsg/debian/zlib1g.install zlib-1.3.1.dfsg/debian/zlib1g.install --- zlib-1.2.13.dfsg/debian/zlib1g.install 2022-11-05 21:16:46.000000000 +0000 +++ zlib-1.3.1.dfsg/debian/zlib1g.install 2023-11-24 08:22:52.000000000 +0000 @@ -1 +1 @@ -lib/*/lib*.so.* +usr/lib/*/libz*.so.* diff -Nru zlib-1.2.13.dfsg/deflate.c zlib-1.3.1.dfsg/deflate.c --- zlib-1.2.13.dfsg/deflate.c 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/deflate.c 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -60,9 +60,6 @@ copyright string in the executable of your product. */ -/* =========================================================================== - * Function prototypes. - */ typedef enum { need_more, /* block not completed, need more input or more output */ block_done, /* block flush performed */ @@ -70,29 +67,16 @@ finish_done /* finish done, accept no more input or output */ } block_state; -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +typedef block_state (*compress_func)(deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck OF((z_streamp strm)); -local void slide_hash OF((deflate_state *s)); -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); +local block_state deflate_stored(deflate_state *s, int flush); +local block_state deflate_fast(deflate_state *s, int flush); #ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -local uInt longest_match OF((deflate_state *s, IPos cur_match)); - -#ifdef ZLIB_DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); +local block_state deflate_slow(deflate_state *s, int flush); #endif +local block_state deflate_rle(deflate_state *s, int flush); +local block_state deflate_huff(deflate_state *s, int flush); /* =========================================================================== * Local data @@ -195,9 +179,12 @@ * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ -local void slide_hash(s) - deflate_state *s; -{ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __attribute__((no_sanitize("memory"))) +# endif +#endif +local void slide_hash(deflate_state *s) { unsigned n, m; Posf *p; uInt wsize = s->w_size; @@ -221,30 +208,177 @@ #endif } +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return len; +} + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(deflate_state *s) { + unsigned n; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize + MAX_DIST(s)) { + + zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + if (s->insert > s->strstart) + s->insert = s->strstart; + slide_hash(s); + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + /* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ +int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, + int stream_size) { return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, version, stream_size); /* To do: ignore strm->next_in if we use it as window */ } /* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ +int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, int strategy, + const char *version, int stream_size) { deflate_state *s; int wrap = 1; static const char my_version[] = ZLIB_VERSION; @@ -359,7 +493,7 @@ * symbols from which it is being constructed. */ - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); s->pending_buf_size = (ulg)s->lit_bufsize * 4; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || @@ -369,8 +503,14 @@ deflateEnd (strm); return Z_MEM_ERROR; } +#ifdef LIT_MEM + s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); + s->l_buf = s->pending_buf + (s->lit_bufsize << 2); + s->sym_end = s->lit_bufsize - 1; +#else s->sym_buf = s->pending_buf + s->lit_bufsize; s->sym_end = (s->lit_bufsize - 1) * 3; +#endif /* We avoid equality with lit_bufsize*3 because of wraparound at 64K * on 16 bit machines and because stored blocks are restricted to * 64K-1 bytes. @@ -386,9 +526,7 @@ /* ========================================================================= * Check for a valid deflate stream state. Return 0 if ok, 1 if not. */ -local int deflateStateCheck(strm) - z_streamp strm; -{ +local int deflateStateCheck(z_streamp strm) { deflate_state *s; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -409,11 +547,8 @@ } /* ========================================================================= */ -int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ +int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { deflate_state *s; uInt str, n; int wrap; @@ -478,11 +613,8 @@ } /* ========================================================================= */ -int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength) - z_streamp strm; - Bytef *dictionary; - uInt *dictLength; -{ +int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { deflate_state *s; uInt len; @@ -500,9 +632,7 @@ } /* ========================================================================= */ -int ZEXPORT deflateResetKeep(strm) - z_streamp strm; -{ +int ZEXPORT deflateResetKeep(z_streamp strm) { deflate_state *s; if (deflateStateCheck(strm)) { @@ -537,10 +667,32 @@ return Z_OK; } +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init(deflate_state *s) { + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +} + /* ========================================================================= */ -int ZEXPORT deflateReset(strm) - z_streamp strm; -{ +int ZEXPORT deflateReset(z_streamp strm) { int ret; ret = deflateResetKeep(strm); @@ -550,10 +702,7 @@ } /* ========================================================================= */ -int ZEXPORT deflateSetHeader(strm, head) - z_streamp strm; - gz_headerp head; -{ +int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { if (deflateStateCheck(strm) || strm->state->wrap != 2) return Z_STREAM_ERROR; strm->state->gzhead = head; @@ -561,11 +710,7 @@ } /* ========================================================================= */ -int ZEXPORT deflatePending(strm, pending, bits) - unsigned *pending; - int *bits; - z_streamp strm; -{ +int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (pending != Z_NULL) *pending = strm->state->pending; @@ -575,19 +720,21 @@ } /* ========================================================================= */ -int ZEXPORT deflatePrime(strm, bits, value) - z_streamp strm; - int bits; - int value; -{ +int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; int put; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; +#ifdef LIT_MEM + if (bits < 0 || bits > 16 || + (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; +#else if (bits < 0 || bits > 16 || s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; +#endif do { put = Buf_size - s->bi_valid; if (put > bits) @@ -602,11 +749,7 @@ } /* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ +int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { deflate_state *s; compress_func func; @@ -651,13 +794,8 @@ } /* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ +int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain) { deflate_state *s; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -693,10 +831,7 @@ * * Shifts are used to approximate divisions, for speed. */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ +uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { deflate_state *s; uLong fixedlen, storelen, wraplen; @@ -752,7 +887,8 @@ /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; + return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + + wraplen; /* default settings: return tight bound for that case -- ~0.03% overhead plus a small constant */ @@ -765,10 +901,7 @@ * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB(s, b) - deflate_state *s; - uInt b; -{ +local void putShortMSB(deflate_state *s, uInt b) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); } @@ -779,9 +912,7 @@ * applications may wish to modify it to avoid allocating a large * strm->next_out buffer and copying into it. (See also read_buf()). */ -local void flush_pending(strm) - z_streamp strm; -{ +local void flush_pending(z_streamp strm) { unsigned len; deflate_state *s = strm->state; @@ -812,10 +943,7 @@ } while (0) /* ========================================================================= */ -int ZEXPORT deflate(strm, flush) - z_streamp strm; - int flush; -{ +int ZEXPORT deflate(z_streamp strm, int flush) { int old_flush; /* value of flush param for previous deflate call */ deflate_state *s; @@ -1127,9 +1255,7 @@ } /* ========================================================================= */ -int ZEXPORT deflateEnd(strm) - z_streamp strm; -{ +int ZEXPORT deflateEnd(z_streamp strm) { int status; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1153,11 +1279,10 @@ * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */ -int ZEXPORT deflateCopy(dest, source) - z_streamp dest; - z_streamp source; -{ +int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #ifdef MAXSEG_64K + (void)dest; + (void)source; return Z_STREAM_ERROR; #else deflate_state *ds; @@ -1181,7 +1306,7 @@ ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1192,10 +1317,15 @@ zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); +#ifdef LIT_MEM + ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); + ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); +#else ds->sym_buf = ds->pending_buf + ds->lit_bufsize; +#endif ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; @@ -1205,66 +1335,6 @@ #endif /* MAXSEG_64K */ } -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init(s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} - #ifndef FASTEST /* =========================================================================== * Set match_start to the longest match starting at the given string and @@ -1275,10 +1345,7 @@ * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ @@ -1426,10 +1493,7 @@ /* --------------------------------------------------------------------------- * Optimized version for FASTEST only */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ register int len; /* length of current match */ @@ -1490,19 +1554,23 @@ /* =========================================================================== * Check that the match at match_start is indeed a match. */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ +local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); + Bytef *back = s->window + (int)match, *here = s->window + start; + IPos len = length; + if (match == (IPos)-1) { + /* match starts one byte before the current window -- just compare the + subsequent length-1 bytes */ + back++; + here++; + len--; + } + if (zmemcmp(back, here, len) != EQUAL) { + fprintf(stderr, " start %u, match %d, length %d\n", + start, (int)match, length); do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); + fprintf(stderr, "(%02x %02x)", *back++, *here++); + } while (--len != 0); z_error("invalid match"); } if (z_verbose > 1) { @@ -1515,137 +1583,6 @@ #endif /* ZLIB_DEBUG */ /* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize + MAX_DIST(s)) { - - zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* =========================================================================== * Flush the current block, with given end-of-file flag. * IN assertion: strstart is set to the end of the current match. */ @@ -1687,10 +1624,7 @@ * copied. It is most efficient with large input and output buffers, which * maximizes the opportunities to have a single copy from next_in to next_out. */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_stored(deflate_state *s, int flush) { /* Smallest worthy block size when not flushing or finishing. By default * this is 32K. This can be as small as 507 bytes for memLevel == 1. For * large input and output buffers, the stored block size will be larger. @@ -1874,10 +1808,7 @@ * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_fast(deflate_state *s, int flush) { IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ @@ -1976,10 +1907,7 @@ * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_slow(deflate_state *s, int flush) { IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ @@ -2107,10 +2035,7 @@ * one. Do not maintain a hash table. (It will be regenerated if this run of * deflate switches away from Z_RLE.) */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_rle(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ uInt prev; /* byte at distance one to match */ Bytef *scan, *strend; /* scan goes up to strend for length of run */ @@ -2181,10 +2106,7 @@ * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * (It will be regenerated if this run of deflate switches away from Huffman.) */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_huff(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ for (;;) { diff -Nru zlib-1.2.13.dfsg/deflate.h zlib-1.3.1.dfsg/deflate.h --- zlib-1.2.13.dfsg/deflate.h 2022-03-28 17:50:16.000000000 +0000 +++ zlib-1.3.1.dfsg/deflate.h 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-2018 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -23,6 +23,10 @@ # define GZIP #endif +/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at + the cost of a larger memory footprint */ +/* #define LIT_MEM */ + /* =========================================================================== * Internal compression state. */ @@ -217,7 +221,14 @@ /* Depth of each subtree used as tie breaker for trees of equal frequency */ +#ifdef LIT_MEM +# define LIT_BUFS 5 + ushf *d_buf; /* buffer for distances */ + uchf *l_buf; /* buffer for literals/lengths */ +#else +# define LIT_BUFS 4 uchf *sym_buf; /* buffer for distances and literals/lengths */ +#endif uInt lit_bufsize; /* Size of match buffer for literals/lengths. There are 4 reasons for @@ -239,7 +250,7 @@ * - I can't count above 4 */ - uInt sym_next; /* running index in sym_buf */ + uInt sym_next; /* running index in symbol buffer */ uInt sym_end; /* symbol table full when sym_next reaches this */ ulg opt_len; /* bit length of current block with optimal trees */ @@ -291,14 +302,14 @@ memory checker errors from longest match routines */ /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_init(deflate_state *s); +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc); +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last); +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s); +void ZLIB_INTERNAL _tr_align(deflate_state *s); +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last); #define d_code(dist) \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) @@ -318,6 +329,25 @@ extern const uch ZLIB_INTERNAL _dist_code[]; #endif +#ifdef LIT_MEM +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->sym_next] = 0; \ + s->l_buf[s->sym_next++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (uch)(length); \ + ush dist = (ush)(distance); \ + s->d_buf[s->sym_next] = dist; \ + s->l_buf[s->sym_next++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +#else # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ s->sym_buf[s->sym_next++] = 0; \ @@ -337,6 +367,7 @@ s->dyn_dtree[d_code(dist)].Freq++; \ flush = (s->sym_next == s->sym_end); \ } +#endif #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_dist(s, distance, length, flush) \ diff -Nru zlib-1.2.13.dfsg/doc/algorithm.txt zlib-1.3.1.dfsg/doc/algorithm.txt --- zlib-1.2.13.dfsg/doc/algorithm.txt 2011-09-10 22:08:45.000000000 +0000 +++ zlib-1.3.1.dfsg/doc/algorithm.txt 2024-01-17 21:49:11.000000000 +0000 @@ -77,7 +77,7 @@ be a first level table to cover all the way to the longest code. However, building the table ends up taking a lot longer for more bits since short codes are replicated many times in such a table. What inflate() does is -simply to make the number of bits in the first table a variable, and then +simply to make the number of bits in the first table a variable, and then to set that variable for the maximum speed. For inflate, which has 286 possible codes for the literal/length tree, the size diff -Nru zlib-1.2.13.dfsg/examples/fitblk.c zlib-1.3.1.dfsg/examples/fitblk.c --- zlib-1.2.13.dfsg/examples/fitblk.c 2022-08-23 22:35:13.000000000 +0000 +++ zlib-1.3.1.dfsg/examples/fitblk.c 2023-08-03 20:53:24.000000000 +0000 @@ -198,7 +198,7 @@ if (ret == Z_MEM_ERROR) quit("out of memory"); - /* set up for next reocmpression */ + /* set up for next recompression */ ret = inflateReset(&inf); assert(ret != Z_STREAM_ERROR); ret = deflateReset(&def); diff -Nru zlib-1.2.13.dfsg/examples/gzlog.c zlib-1.3.1.dfsg/examples/gzlog.c --- zlib-1.2.13.dfsg/examples/gzlog.c 2019-05-26 05:23:20.000000000 +0000 +++ zlib-1.3.1.dfsg/examples/gzlog.c 2024-01-17 20:52:01.000000000 +0000 @@ -212,8 +212,8 @@ to the appropriate recovery below. If there is no foo.add file, provide a zero data length to the recovery. In that case, the append recovery restores the foo.gz to the previous compressed + uncompressed data state. - For the the compress recovery, a missing foo.add file results in foo.gz - being restored to the previous compressed-only data state. + For the compress recovery, a missing foo.add file results in foo.gz being + restored to the previous compressed-only data state. - Append recovery: - Pick up append at + step above - Compress recovery: diff -Nru zlib-1.2.13.dfsg/examples/zlib_how.html zlib-1.3.1.dfsg/examples/zlib_how.html --- zlib-1.2.13.dfsg/examples/zlib_how.html 2005-12-11 20:57:28.000000000 +0000 +++ zlib-1.3.1.dfsg/examples/zlib_how.html 2023-01-25 04:43:19.000000000 +0000 @@ -1,10 +1,10 @@ - + zlib Usage Example - +

zlib Usage Example

@@ -17,7 +17,7 @@ annotations are interspersed between lines of the code. So please read between the lines. We hope this helps explain some of the intricacies of zlib.

-Without further adieu, here is the program zpipe.c: +Without further ado, here is the program zpipe.c:


 /* zpipe.c: example of proper use of zlib's inflate() and deflate()
    Not copyrighted -- provided to the public domain
@@ -155,13 +155,11 @@
 
We start off by reading data from the input file. The number of bytes read is put directly into avail_in, and a pointer to those bytes is put into next_in. We also -check to see if end-of-file on the input has been reached. If we are at the end of file, then flush is set to the +check to see if end-of-file on the input has been reached using feof(). +If we are at the end of file, then flush is set to the zlib constant Z_FINISH, which is later passed to deflate() to -indicate that this is the last chunk of input data to compress. We need to use feof() -to check for end-of-file as opposed to seeing if fewer than CHUNK bytes have been read. The -reason is that if the input file length is an exact multiple of CHUNK, we will miss -the fact that we got to the end-of-file, and not know to tell deflate() to finish -up the compressed stream. If we are not yet at the end of the input, then the zlib +indicate that this is the last chunk of input data to compress. +If we are not yet at the end of the input, then the zlib constant Z_NO_FLUSH will be passed to deflate to indicate that we are still in the middle of the uncompressed data.

@@ -540,6 +538,12 @@ }


-Copyright (c) 2004, 2005 by Mark Adler
Last modified 11 December 2005
+Last modified 24 January 2023
+Copyright © 2004-2023 Mark Adler

+ +Creative Commons License + +Creative Commons Attribution-NoDerivatives 4.0 International License. diff -Nru zlib-1.2.13.dfsg/examples/zran.c zlib-1.3.1.dfsg/examples/zran.c --- zlib-1.2.13.dfsg/examples/zran.c 2022-08-23 22:35:13.000000000 +0000 +++ zlib-1.3.1.dfsg/examples/zran.c 2024-01-17 21:49:11.000000000 +0000 @@ -1,114 +1,102 @@ -/* zran.c -- example of zlib/gzip stream indexing and random access - * Copyright (C) 2005, 2012, 2018 Mark Adler +/* zran.c -- example of deflate stream indexing and random access + * Copyright (C) 2005, 2012, 2018, 2023 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h - * Version 1.2 14 Oct 2018 Mark Adler */ + * Version 1.4 13 Apr 2023 Mark Adler */ /* Version History: 1.0 29 May 2005 First version 1.1 29 Sep 2012 Fix memory reallocation error 1.2 14 Oct 2018 Handle gzip streams with multiple members Add a header file to facilitate usage in applications + 1.3 18 Feb 2023 Permit raw deflate streams as well as zlib and gzip + Permit crossing gzip member boundaries when extracting + Support a size_t size when extracting (was an int) + Do a binary search over the index for an access point + Expose the access point type to enable save and load + 1.4 13 Apr 2023 Add a NOPRIME define to not use inflatePrime() */ -/* Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary() - for random access of a compressed file. A file containing a zlib or gzip - stream is provided on the command line. The compressed stream is decoded in - its entirety, and an index built with access points about every SPAN bytes - in the uncompressed output. The compressed file is left open, and can then - be read randomly, having to decompress on the average SPAN/2 uncompressed - bytes before getting to the desired block of data. - - An access point can be created at the start of any deflate block, by saving - the starting file offset and bit of that block, and the 32K bytes of - uncompressed data that precede that block. Also the uncompressed offset of - that block is saved to provide a reference for locating a desired starting - point in the uncompressed stream. deflate_index_build() works by - decompressing the input zlib or gzip stream a block at a time, and at the - end of each block deciding if enough uncompressed data has gone by to - justify the creation of a new access point. If so, that point is saved in a - data structure that grows as needed to accommodate the points. - - To use the index, an offset in the uncompressed data is provided, for which - the latest access point at or preceding that offset is located in the index. - The input file is positioned to the specified location in the index, and if - necessary the first few bits of the compressed data is read from the file. - inflate is initialized with those bits and the 32K of uncompressed data, and - the decompression then proceeds until the desired offset in the file is - reached. Then the decompression continues to read the desired uncompressed - data from the file. - - Another approach would be to generate the index on demand. In that case, - requests for random access reads from the compressed data would try to use - the index, but if a read far enough past the end of the index is required, - then further index entries would be generated and added. - - There is some fair bit of overhead to starting inflation for the random - access, mainly copying the 32K byte dictionary. So if small pieces of the - file are being accessed, it would make sense to implement a cache to hold - some lookahead and avoid many calls to deflate_index_extract() for small - lengths. - - Another way to build an index would be to use inflateCopy(). That would - not be constrained to have access points at block boundaries, but requires - more memory per access point, and also cannot be saved to file due to the - use of pointers in the state. The approach here allows for storage of the - index in a file. - */ +// Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary() +// for random access of a compressed file. A file containing a raw deflate +// stream is provided on the command line. The compressed stream is decoded in +// its entirety, and an index built with access points about every SPAN bytes +// in the uncompressed output. The compressed file is left open, and can then +// be read randomly, having to decompress on the average SPAN/2 uncompressed +// bytes before getting to the desired block of data. +// +// An access point can be created at the start of any deflate block, by saving +// the starting file offset and bit of that block, and the 32K bytes of +// uncompressed data that precede that block. Also the uncompressed offset of +// that block is saved to provide a reference for locating a desired starting +// point in the uncompressed stream. deflate_index_build() decompresses the +// input raw deflate stream a block at a time, and at the end of each block +// decides if enough uncompressed data has gone by to justify the creation of a +// new access point. If so, that point is saved in a data structure that grows +// as needed to accommodate the points. +// +// To use the index, an offset in the uncompressed data is provided, for which +// the latest access point at or preceding that offset is located in the index. +// The input file is positioned to the specified location in the index, and if +// necessary the first few bits of the compressed data is read from the file. +// inflate is initialized with those bits and the 32K of uncompressed data, and +// decompression then proceeds until the desired offset in the file is reached. +// Then decompression continues to read the requested uncompressed data from +// the file. +// +// There is some fair bit of overhead to starting inflation for the random +// access, mainly copying the 32K byte dictionary. If small pieces of the file +// are being accessed, it would make sense to implement a cache to hold some +// lookahead to avoid many calls to deflate_index_extract() for small lengths. +// +// Another way to build an index would be to use inflateCopy(). That would not +// be constrained to have access points at block boundaries, but would require +// more memory per access point, and could not be saved to a file due to the +// use of pointers in the state. The approach here allows for storage of the +// index in a file. #include #include #include +#include #include "zlib.h" #include "zran.h" -#define WINSIZE 32768U /* sliding window size */ -#define CHUNK 16384 /* file input buffer size */ +#define WINSIZE 32768U // sliding window size +#define CHUNK 16384 // file input buffer size -/* Access point entry. */ -struct point { - off_t out; /* corresponding offset in uncompressed data */ - off_t in; /* offset in input file of first full byte */ - int bits; /* number of bits (1-7) from byte at in-1, or 0 */ - unsigned char window[WINSIZE]; /* preceding 32K of uncompressed data */ -}; - -/* See comments in zran.h. */ -void deflate_index_free(struct deflate_index *index) -{ +// See comments in zran.h. +void deflate_index_free(struct deflate_index *index) { if (index != NULL) { free(index->list); free(index); } } -/* Add an entry to the access point list. If out of memory, deallocate the - existing list and return NULL. index->gzip is the allocated size of the - index in point entries, until it is time for deflate_index_build() to - return, at which point gzip is set to indicate a gzip file or not. - */ -static struct deflate_index *addpoint(struct deflate_index *index, int bits, - off_t in, off_t out, unsigned left, - unsigned char *window) -{ - struct point *next; - - /* if list is empty, create it (start with eight points) */ +// Add an access point to the list. If out of memory, deallocate the existing +// list and return NULL. index->mode is temporarily the allocated number of +// access points, until it is time for deflate_index_build() to return. Then +// index->mode is set to the mode of inflation. +static struct deflate_index *add_point(struct deflate_index *index, int bits, + off_t in, off_t out, unsigned left, + unsigned char *window) { if (index == NULL) { + // The list is empty. Create it, starting with eight access points. index = malloc(sizeof(struct deflate_index)); - if (index == NULL) return NULL; - index->list = malloc(sizeof(struct point) << 3); + if (index == NULL) + return NULL; + index->have = 0; + index->mode = 8; + index->list = malloc(sizeof(point_t) * index->mode); if (index->list == NULL) { free(index); return NULL; } - index->gzip = 8; - index->have = 0; } - /* if list is full, make it bigger */ - else if (index->have == index->gzip) { - index->gzip <<= 1; - next = realloc(index->list, sizeof(struct point) * index->gzip); + else if (index->have == index->mode) { + // The list is full. Make it bigger. + index->mode <<= 1; + point_t *next = realloc(index->list, sizeof(point_t) * index->mode); if (next == NULL) { deflate_index_free(index); return NULL; @@ -116,318 +104,379 @@ index->list = next; } - /* fill in entry and increment how many we have */ - next = (struct point *)(index->list) + index->have; - next->bits = bits; - next->in = in; + // Fill in the access point and increment how many we have. + point_t *next = (point_t *)(index->list) + index->have++; + if (index->have < 0) { + // Overflowed the int! + deflate_index_free(index); + return NULL; + } next->out = out; + next->in = in; + next->bits = bits; if (left) memcpy(next->window, window + WINSIZE - left, left); if (left < WINSIZE) memcpy(next->window + left, window, WINSIZE - left); - index->have++; - /* return list, possibly reallocated */ + // Return the index, which may have been newly allocated or destroyed. return index; } -/* See comments in zran.h. */ -int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) -{ - int ret; - int gzip = 0; /* true if reading a gzip file */ - off_t totin, totout; /* our own total counters to avoid 4GB limit */ - off_t last; /* totout value of last access point */ - struct deflate_index *index; /* access points being generated */ - z_stream strm; - unsigned char input[CHUNK]; - unsigned char window[WINSIZE]; - - /* initialize inflate */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */ - if (ret != Z_OK) - return ret; - - /* inflate the input, maintain a sliding window, and build an index -- this - also validates the integrity of the compressed data using the check - information in the gzip or zlib stream */ - totin = totout = last = 0; - index = NULL; /* will be allocated by first addpoint() */ - strm.avail_out = 0; +// Decompression modes. These are the inflateInit2() windowBits parameter. +#define RAW -15 +#define ZLIB 15 +#define GZIP 31 + +// See comments in zran.h. +int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) { + // Set up inflation state. + z_stream strm = {0}; // inflate engine (gets fired up later) + unsigned char buf[CHUNK]; // input buffer + unsigned char win[WINSIZE] = {0}; // output sliding window + off_t totin = 0; // total bytes read from input + off_t totout = 0; // total bytes uncompressed + int mode = 0; // mode: RAW, ZLIB, or GZIP (0 => not set yet) + + // Decompress from in, generating access points along the way. + int ret; // the return value from zlib, or Z_ERRNO + off_t last; // last access point uncompressed offset + struct deflate_index *index = NULL; // list of access points do { - /* get some compressed data from input file */ - strm.avail_in = fread(input, 1, CHUNK, in); - if (ferror(in)) { - ret = Z_ERRNO; - goto deflate_index_build_error; - } + // Assure available input, at least until reaching EOF. if (strm.avail_in == 0) { - ret = Z_DATA_ERROR; - goto deflate_index_build_error; - } - strm.next_in = input; + strm.avail_in = fread(buf, 1, sizeof(buf), in); + totin += strm.avail_in; + strm.next_in = buf; + if (strm.avail_in < sizeof(buf) && ferror(in)) { + ret = Z_ERRNO; + break; + } - /* check for a gzip stream */ - if (totin == 0 && strm.avail_in >= 3 && - input[0] == 31 && input[1] == 139 && input[2] == 8) - gzip = 1; - - /* process all of that, or until end of stream */ - do { - /* reset sliding window if necessary */ - if (strm.avail_out == 0) { - strm.avail_out = WINSIZE; - strm.next_out = window; + if (mode == 0) { + // At the start of the input -- determine the type. Assume raw + // if it is neither zlib nor gzip. This could in theory result + // in a false positive for zlib, but in practice the fill bits + // after a stored block are always zeros, so a raw stream won't + // start with an 8 in the low nybble. + mode = strm.avail_in == 0 ? RAW : // empty -- will fail + (strm.next_in[0] & 0xf) == 8 ? ZLIB : + strm.next_in[0] == 0x1f ? GZIP : + /* else */ RAW; + ret = inflateInit2(&strm, mode); + if (ret != Z_OK) + break; } + } - /* inflate until out of input, output, or at end of block -- - update the total input and output counters */ - totin += strm.avail_in; - totout += strm.avail_out; - ret = inflate(&strm, Z_BLOCK); /* return at end of block */ - totin -= strm.avail_in; - totout -= strm.avail_out; - if (ret == Z_NEED_DICT) - ret = Z_DATA_ERROR; - if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) - goto deflate_index_build_error; - if (ret == Z_STREAM_END) { - if (gzip && - (strm.avail_in || ungetc(getc(in), in) != EOF)) { - ret = inflateReset(&strm); - if (ret != Z_OK) - goto deflate_index_build_error; - continue; - } + // Assure available output. This rotates the output through, for use as + // a sliding window on the uncompressed data. + if (strm.avail_out == 0) { + strm.avail_out = sizeof(win); + strm.next_out = win; + } + + if (mode == RAW && index == NULL) + // We skip the inflate() call at the start of raw deflate data in + // order generate an access point there. Set data_type to imitate + // the end of a header. + strm.data_type = 0x80; + else { + // Inflate and update the number of uncompressed bytes. + unsigned before = strm.avail_out; + ret = inflate(&strm, Z_BLOCK); + totout += before - strm.avail_out; + } + + if ((strm.data_type & 0xc0) == 0x80 && + (index == NULL || totout - last >= span)) { + // We are at the end of a header or a non-last deflate block, so we + // can add an access point here. Furthermore, we are either at the + // very start for the first access point, or there has been span or + // more uncompressed bytes since the last access point, so we want + // to add an access point here. + index = add_point(index, strm.data_type & 7, totin - strm.avail_in, + totout, strm.avail_out, win); + if (index == NULL) { + ret = Z_MEM_ERROR; break; } + last = totout; + } - /* if at end of block, consider adding an index entry (note that if - data_type indicates an end-of-block, then all of the - uncompressed data from that block has been delivered, and none - of the compressed data after that block has been consumed, - except for up to seven bits) -- the totout == 0 provides an - entry point after the zlib or gzip header, and assures that the - index always has at least one access point; we avoid creating an - access point after the last block by checking bit 6 of data_type - */ - if ((strm.data_type & 128) && !(strm.data_type & 64) && - (totout == 0 || totout - last > span)) { - index = addpoint(index, strm.data_type & 7, totin, - totout, strm.avail_out, window); - if (index == NULL) { - ret = Z_MEM_ERROR; - goto deflate_index_build_error; - } - last = totout; - } - } while (strm.avail_in != 0); - } while (ret != Z_STREAM_END); + if (ret == Z_STREAM_END && mode == GZIP && + (strm.avail_in || ungetc(getc(in), in) != EOF)) + // There is more input after the end of a gzip member. Reset the + // inflate state to read another gzip member. On success, this will + // set ret to Z_OK to continue decompressing. + ret = inflateReset2(&strm, GZIP); + + // Keep going until Z_STREAM_END or error. If the compressed data ends + // prematurely without a file read error, Z_BUF_ERROR is returned. + } while (ret == Z_OK); + inflateEnd(&strm); + + if (ret != Z_STREAM_END) { + // An error was encountered. Discard the index and return a negative + // error code. + deflate_index_free(index); + return ret == Z_NEED_DICT ? Z_DATA_ERROR : ret; + } - /* clean up and return index (release unused entries in list) */ - (void)inflateEnd(&strm); - index->list = realloc(index->list, sizeof(struct point) * index->have); - index->gzip = gzip; + // Shrink the index to only the occupied access points and return it. + index->mode = mode; index->length = totout; + point_t *list = realloc(index->list, sizeof(point_t) * index->have); + if (list == NULL) { + // Seems like a realloc() to make something smaller should always work, + // but just in case. + deflate_index_free(index); + return Z_MEM_ERROR; + } + index->list = list; *built = index; return index->have; +} - /* return error */ - deflate_index_build_error: - (void)inflateEnd(&strm); - deflate_index_free(index); - return ret; +#ifdef NOPRIME +// Support zlib versions before 1.2.3 (July 2005), or incomplete zlib clones +// that do not have inflatePrime(). + +# define INFLATEPRIME inflatePreface + +// Append the low bits bits of value to in[] at bit position *have, updating +// *have. value must be zero above its low bits bits. bits must be positive. +// This assumes that any bits above the *have bits in the last byte are zeros. +// That assumption is preserved on return, as any bits above *have + bits in +// the last byte written will be set to zeros. +static inline void append_bits(unsigned value, int bits, + unsigned char *in, int *have) { + in += *have >> 3; // where the first bits from value will go + int k = *have & 7; // the number of bits already there + *have += bits; + if (k) + *in |= value << k; // write value above the low k bits + else + *in = value; + k = 8 - k; // the number of bits just appended + while (bits > k) { + value >>= k; // drop the bits appended + bits -= k; + k = 8; // now at a byte boundary + *++in = value; + } } -/* See comments in zran.h. */ -int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset, - unsigned char *buf, int len) -{ - int ret, skip; - z_stream strm; - struct point *here; - unsigned char input[CHUNK]; - unsigned char discard[WINSIZE]; +// Insert enough bits in the form of empty deflate blocks in front of the +// low bits bits of value, in order to bring the sequence to a byte boundary. +// Then feed that to inflate(). This does what inflatePrime() does, except that +// a negative value of bits is not supported. bits must be in 0..16. If the +// arguments are invalid, Z_STREAM_ERROR is returned. Otherwise the return +// value from inflate() is returned. +static int inflatePreface(z_stream *strm, int bits, int value) { + // Check input. + if (strm == Z_NULL || bits < 0 || bits > 16) + return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; + value &= (2 << (bits - 1)) - 1; + + // An empty dynamic block with an odd number of bits (95). The high bit of + // the last byte is unused. + static const unsigned char dyn[] = { + 4, 0xe0, 0x81, 8, 0, 0, 0, 0, 0x20, 0xa8, 0xab, 0x1f + }; + const int dynlen = 95; // number of bits in the block + + // Build an input buffer for inflate that is a multiple of eight bits in + // length, and that ends with the low bits bits of value. + unsigned char in[(dynlen + 3 * 10 + 16 + 7) / 8]; + int have = 0; + if (bits & 1) { + // Insert an empty dynamic block to get to an odd number of bits, so + // when bits bits from value are appended, we are at an even number of + // bits. + memcpy(in, dyn, sizeof(dyn)); + have = dynlen; + } + while ((have + bits) & 7) + // Insert empty fixed blocks until appending bits bits would put us on + // a byte boundary. This will insert at most three fixed blocks. + append_bits(2, 10, in, &have); + + // Append the bits bits from value, which takes us to a byte boundary. + append_bits(value, bits, in, &have); + + // Deliver the input to inflate(). There is no output space provided, but + // inflate() can't get stuck waiting on output not ingesting all of the + // provided input. The reason is that there will be at most 16 bits of + // input from value after the empty deflate blocks (which themselves + // generate no output). At least ten bits are needed to generate the first + // output byte from a fixed block. The last two bytes of the buffer have to + // be ingested in order to get ten bits, which is the most that value can + // occupy. + strm->avail_in = have >> 3; + strm->next_in = in; + strm->avail_out = 0; + strm->next_out = in; // not used, but can't be NULL + return inflate(strm, Z_NO_FLUSH); +} + +#else +# define INFLATEPRIME inflatePrime +#endif + +// See comments in zran.h. +ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index, + off_t offset, unsigned char *buf, size_t len) { + // Do a quick sanity check on the index. + if (index == NULL || index->have < 1 || index->list[0].out != 0) + return Z_STREAM_ERROR; - /* proceed only if something reasonable to do */ - if (len < 0) + // If nothing to extract, return zero bytes extracted. + if (len == 0 || offset < 0 || offset >= index->length) return 0; - /* find where in stream to start */ - here = index->list; - ret = index->have; - while (--ret && here[1].out <= offset) - here++; - - /* initialize file and inflate state to start there */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, -15); /* raw inflate */ + // Find the access point closest to but not after offset. + int lo = -1, hi = index->have; + point_t *point = index->list; + while (hi - lo > 1) { + int mid = (lo + hi) >> 1; + if (offset < point[mid].out) + hi = mid; + else + lo = mid; + } + point += lo; + + // Initialize the input file and prime the inflate engine to start there. + int ret = fseeko(in, point->in - (point->bits ? 1 : 0), SEEK_SET); + if (ret == -1) + return Z_ERRNO; + int ch = 0; + if (point->bits && (ch = getc(in)) == EOF) + return ferror(in) ? Z_ERRNO : Z_BUF_ERROR; + z_stream strm = {0}; + ret = inflateInit2(&strm, RAW); if (ret != Z_OK) return ret; - ret = fseeko(in, here->in - (here->bits ? 1 : 0), SEEK_SET); - if (ret == -1) - goto deflate_index_extract_ret; - if (here->bits) { - ret = getc(in); - if (ret == -1) { - ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR; - goto deflate_index_extract_ret; - } - (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits)); - } - (void)inflateSetDictionary(&strm, here->window, WINSIZE); - - /* skip uncompressed bytes until offset reached, then satisfy request */ - offset -= here->out; - strm.avail_in = 0; - skip = 1; /* while skipping to offset */ + if (point->bits) + INFLATEPRIME(&strm, point->bits, ch >> (8 - point->bits)); + inflateSetDictionary(&strm, point->window, WINSIZE); + + // Skip uncompressed bytes until offset reached, then satisfy request. + unsigned char input[CHUNK]; + unsigned char discard[WINSIZE]; + offset -= point->out; // number of bytes to skip to get to offset + size_t left = len; // number of bytes left to read after offset do { - /* define where to put uncompressed data, and how much */ - if (offset > WINSIZE) { /* skip WINSIZE bytes */ - strm.avail_out = WINSIZE; + if (offset) { + // Discard up to offset uncompressed bytes. + strm.avail_out = offset < WINSIZE ? (unsigned)offset : WINSIZE; strm.next_out = discard; - offset -= WINSIZE; } - else if (offset > 0) { /* last skip */ - strm.avail_out = (unsigned)offset; - strm.next_out = discard; - offset = 0; + else { + // Uncompress up to left bytes into buf. + strm.avail_out = left < UINT_MAX ? (unsigned)left : UINT_MAX; + strm.next_out = buf + len - left; } - else if (skip) { /* at offset now */ - strm.avail_out = len; - strm.next_out = buf; - skip = 0; /* only do this once */ - } - - /* uncompress until avail_out filled, or end of stream */ - do { - if (strm.avail_in == 0) { - strm.avail_in = fread(input, 1, CHUNK, in); - if (ferror(in)) { - ret = Z_ERRNO; - goto deflate_index_extract_ret; - } - if (strm.avail_in == 0) { - ret = Z_DATA_ERROR; - goto deflate_index_extract_ret; - } - strm.next_in = input; - } - ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */ - if (ret == Z_NEED_DICT) - ret = Z_DATA_ERROR; - if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) - goto deflate_index_extract_ret; - if (ret == Z_STREAM_END) { - /* the raw deflate stream has ended */ - if (index->gzip == 0) - /* this is a zlib stream that has ended -- done */ - break; - /* near the end of a gzip member, which might be followed by - another gzip member -- skip the gzip trailer and see if - there is more input after it */ - if (strm.avail_in < 8) { - fseeko(in, 8 - strm.avail_in, SEEK_CUR); - strm.avail_in = 0; - } - else { - strm.avail_in -= 8; - strm.next_in += 8; - } - if (strm.avail_in == 0 && ungetc(getc(in), in) == EOF) - /* the input ended after the gzip trailer -- done */ - break; + // Uncompress, setting got to the number of bytes uncompressed. + if (strm.avail_in == 0) { + // Assure available input. + strm.avail_in = fread(input, 1, CHUNK, in); + if (strm.avail_in < CHUNK && ferror(in)) { + ret = Z_ERRNO; + break; + } + strm.next_in = input; + } + unsigned got = strm.avail_out; + ret = inflate(&strm, Z_NO_FLUSH); + got -= strm.avail_out; + + // Update the appropriate count. + if (offset) + offset -= got; + else + left -= got; + + // If we're at the end of a gzip member and there's more to read, + // continue to the next gzip member. + if (ret == Z_STREAM_END && index->mode == GZIP) { + // Discard the gzip trailer. + unsigned drop = 8; // length of gzip trailer + if (strm.avail_in >= drop) { + strm.avail_in -= drop; + strm.next_in += drop; + } + else { + // Read and discard the remainder of the gzip trailer. + drop -= strm.avail_in; + strm.avail_in = 0; + do { + if (getc(in) == EOF) + // The input does not have a complete trailer. + return ferror(in) ? Z_ERRNO : Z_BUF_ERROR; + } while (--drop); + } - /* there is more input, so another gzip member should follow -- - validate and skip the gzip header */ - ret = inflateReset2(&strm, 31); - if (ret != Z_OK) - goto deflate_index_extract_ret; + if (strm.avail_in || ungetc(getc(in), in) != EOF) { + // There's more after the gzip trailer. Use inflate to skip the + // gzip header and resume the raw inflate there. + inflateReset2(&strm, GZIP); do { if (strm.avail_in == 0) { strm.avail_in = fread(input, 1, CHUNK, in); - if (ferror(in)) { + if (strm.avail_in < CHUNK && ferror(in)) { ret = Z_ERRNO; - goto deflate_index_extract_ret; - } - if (strm.avail_in == 0) { - ret = Z_DATA_ERROR; - goto deflate_index_extract_ret; + break; } strm.next_in = input; } - ret = inflate(&strm, Z_BLOCK); - if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) - goto deflate_index_extract_ret; - } while ((strm.data_type & 128) == 0); - - /* set up to continue decompression of the raw deflate stream - that follows the gzip header */ - ret = inflateReset2(&strm, -15); + strm.avail_out = WINSIZE; + strm.next_out = discard; + ret = inflate(&strm, Z_BLOCK); // stop at end of header + } while (ret == Z_OK && (strm.data_type & 0x80) == 0); if (ret != Z_OK) - goto deflate_index_extract_ret; + break; + inflateReset2(&strm, RAW); } + } - /* continue to process the available input before reading more */ - } while (strm.avail_out != 0); - - if (ret == Z_STREAM_END) - /* reached the end of the compressed data -- return the data that - was available, possibly less than requested */ - break; - - /* do until offset reached and requested data read */ - } while (skip); - - /* compute the number of uncompressed bytes read after the offset */ - ret = skip ? 0 : len - strm.avail_out; + // Continue until we have the requested data, the deflate data has + // ended, or an error is encountered. + } while (ret == Z_OK && left); + inflateEnd(&strm); - /* clean up and return the bytes read, or the negative error */ - deflate_index_extract_ret: - (void)inflateEnd(&strm); - return ret; + // Return the number of uncompressed bytes read into buf, or the error. + return ret == Z_OK || ret == Z_STREAM_END ? len - left : ret; } #ifdef TEST -#define SPAN 1048576L /* desired distance between access points */ -#define LEN 16384 /* number of bytes to extract */ - -/* Demonstrate the use of deflate_index_build() and deflate_index_extract() by - processing the file provided on the command line, and extracting LEN bytes - from 2/3rds of the way through the uncompressed output, writing that to - stdout. An offset can be provided as the second argument, in which case the - data is extracted from there instead. */ -int main(int argc, char **argv) -{ - int len; - off_t offset = -1; - FILE *in; - struct deflate_index *index = NULL; - unsigned char buf[LEN]; +#define SPAN 1048576L // desired distance between access points +#define LEN 16384 // number of bytes to extract - /* open input file */ +// Demonstrate the use of deflate_index_build() and deflate_index_extract() by +// processing the file provided on the command line, and extracting LEN bytes +// from 2/3rds of the way through the uncompressed output, writing that to +// stdout. An offset can be provided as the second argument, in which case the +// data is extracted from there instead. +int main(int argc, char **argv) { + // Open the input file. if (argc < 2 || argc > 3) { - fprintf(stderr, "usage: zran file.gz [offset]\n"); + fprintf(stderr, "usage: zran file.raw [offset]\n"); return 1; } - in = fopen(argv[1], "rb"); + FILE *in = fopen(argv[1], "rb"); if (in == NULL) { fprintf(stderr, "zran: could not open %s for reading\n", argv[1]); return 1; } - /* get optional offset */ + // Get optional offset. + off_t offset = -1; if (argc == 3) { char *end; offset = strtoll(argv[2], &end, 10); @@ -437,14 +486,18 @@ } } - /* build index */ - len = deflate_index_build(in, SPAN, &index); + // Build index. + struct deflate_index *index = NULL; + int len = deflate_index_build(in, SPAN, &index); if (len < 0) { fclose(in); switch (len) { case Z_MEM_ERROR: fprintf(stderr, "zran: out of memory\n"); break; + case Z_BUF_ERROR: + fprintf(stderr, "zran: %s ended prematurely\n", argv[1]); + break; case Z_DATA_ERROR: fprintf(stderr, "zran: compressed data error in %s\n", argv[1]); break; @@ -458,19 +511,20 @@ } fprintf(stderr, "zran: built index with %d access points\n", len); - /* use index by reading some bytes from an arbitrary offset */ + // Use index by reading some bytes from an arbitrary offset. + unsigned char buf[LEN]; if (offset == -1) - offset = (index->length << 1) / 3; - len = deflate_index_extract(in, index, offset, buf, LEN); - if (len < 0) + offset = ((index->length + 1) << 1) / 3; + ptrdiff_t got = deflate_index_extract(in, index, offset, buf, LEN); + if (got < 0) fprintf(stderr, "zran: extraction failed: %s error\n", - len == Z_MEM_ERROR ? "out of memory" : "input corrupted"); + got == Z_MEM_ERROR ? "out of memory" : "input corrupted"); else { - fwrite(buf, 1, len, stdout); - fprintf(stderr, "zran: extracted %d bytes at %llu\n", len, offset); + fwrite(buf, 1, got, stdout); + fprintf(stderr, "zran: extracted %ld bytes at %lld\n", got, offset); } - /* clean up and exit */ + // Clean up and exit. deflate_index_free(index); fclose(in); return 0; diff -Nru zlib-1.2.13.dfsg/examples/zran.h zlib-1.3.1.dfsg/examples/zran.h --- zlib-1.2.13.dfsg/examples/zran.h 2018-10-14 16:57:34.000000000 +0000 +++ zlib-1.3.1.dfsg/examples/zran.h 2023-02-19 04:53:39.000000000 +0000 @@ -1,40 +1,51 @@ -/* zran.h -- example of zlib/gzip stream indexing and random access - * Copyright (C) 2005, 2012, 2018 Mark Adler +/* zran.h -- example of deflated stream indexing and random access + * Copyright (C) 2005, 2012, 2018, 2023 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h - * Version 1.2 14 Oct 2018 Mark Adler */ + * Version 1.3 18 Feb 2023 Mark Adler */ #include #include "zlib.h" -/* Access point list. */ +// Access point. +typedef struct point { + off_t out; // offset in uncompressed data + off_t in; // offset in compressed file of first full byte + int bits; // 0, or number of bits (1-7) from byte at in-1 + unsigned char window[32768]; // preceding 32K of uncompressed data +} point_t; + +// Access point list. struct deflate_index { - int have; /* number of list entries */ - int gzip; /* 1 if the index is of a gzip file, 0 if it is of a - zlib stream */ - off_t length; /* total length of uncompressed data */ - void *list; /* allocated list of entries */ + int have; // number of access points in list + int mode; // -15 for raw, 15 for zlib, or 31 for gzip + off_t length; // total length of uncompressed data + point_t *list; // allocated list of access points }; -/* Make one entire pass through a zlib or gzip compressed stream and build an - index, with access points about every span bytes of uncompressed output. - gzip files with multiple members are indexed in their entirety. span should - be chosen to balance the speed of random access against the memory - requirements of the list, about 32K bytes per access point. The return value - is the number of access points on success (>= 1), Z_MEM_ERROR for out of - memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a file - read error. On success, *built points to the resulting index. */ +// Make one pass through a zlib, gzip, or raw deflate compressed stream and +// build an index, with access points about every span bytes of uncompressed +// output. gzip files with multiple members are fully indexed. span should be +// chosen to balance the speed of random access against the memory requirements +// of the list, which is about 32K bytes per access point. The return value is +// the number of access points on success (>= 1), Z_MEM_ERROR for out of +// memory, Z_BUF_ERROR for a premature end of input, Z_DATA_ERROR for a format +// or verification error in the input file, or Z_ERRNO for a file read error. +// On success, *built points to the resulting index. int deflate_index_build(FILE *in, off_t span, struct deflate_index **built); -/* Deallocate an index built by deflate_index_build() */ -void deflate_index_free(struct deflate_index *index); +// Use the index to read len bytes from offset into buf. Return the number of +// bytes read or a negative error code. If data is requested past the end of +// the uncompressed data, then deflate_index_extract() will return a value less +// than len, indicating how much was actually read into buf. If given a valid +// index, this function should not return an error unless the file was modified +// somehow since the index was generated, given that deflate_index_build() had +// validated all of the input. If nevertheless there is a failure, Z_BUF_ERROR +// is returned if the compressed data ends prematurely, Z_DATA_ERROR if the +// deflate compressed data is not valid, Z_MEM_ERROR if out of memory, +// Z_STREAM_ERROR if the index is not valid, or Z_ERRNO if there is an error +// reading or seeking on the input file. +ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index, + off_t offset, unsigned char *buf, size_t len); -/* Use the index to read len bytes from offset into buf. Return bytes read or - negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past - the end of the uncompressed data, then deflate_index_extract() will return a - value less than len, indicating how much was actually read into buf. This - function should not return a data error unless the file was modified since - the index was generated, since deflate_index_build() validated all of the - input. deflate_index_extract() will return Z_ERRNO if there is an error on - reading or seeking the input file. */ -int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset, - unsigned char *buf, int len); +// Deallocate an index built by deflate_index_build(). +void deflate_index_free(struct deflate_index *index); diff -Nru zlib-1.2.13.dfsg/gzclose.c zlib-1.3.1.dfsg/gzclose.c --- zlib-1.2.13.dfsg/gzclose.c 2010-02-14 00:12:48.000000000 +0000 +++ zlib-1.3.1.dfsg/gzclose.c 2023-04-16 04:17:31.000000000 +0000 @@ -8,9 +8,7 @@ /* gzclose() is in a separate file so that it is linked in only if it is used. That way the other gzclose functions can be used instead to avoid linking in unneeded compression or decompression routines. */ -int ZEXPORT gzclose(file) - gzFile file; -{ +int ZEXPORT gzclose(gzFile file) { #ifndef NO_GZCOMPRESS gz_statep state; diff -Nru zlib-1.2.13.dfsg/gzguts.h zlib-1.3.1.dfsg/gzguts.h --- zlib-1.2.13.dfsg/gzguts.h 2022-03-27 23:05:02.000000000 +0000 +++ zlib-1.3.1.dfsg/gzguts.h 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004-2019 Mark Adler + * Copyright (C) 2004-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -7,9 +7,8 @@ # ifndef _LARGEFILE_SOURCE # define _LARGEFILE_SOURCE 1 # endif -# ifdef _FILE_OFFSET_BITS -# undef _FILE_OFFSET_BITS -# endif +# undef _FILE_OFFSET_BITS +# undef _TIME_BITS #endif #ifdef HAVE_HIDDEN @@ -119,8 +118,8 @@ /* gz* functions always use library allocation functions */ #ifndef STDC - extern voidp malloc OF((uInt size)); - extern void free OF((voidpf ptr)); + extern voidp malloc(uInt size); + extern void free(voidpf ptr); #endif /* get errno and strerror definition */ @@ -138,10 +137,10 @@ /* provide prototypes for these when building zlib without LFS */ #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); #endif /* default memLevel */ @@ -203,17 +202,13 @@ typedef gz_state FAR *gz_statep; /* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); +void ZLIB_INTERNAL gz_error(gz_statep, int, const char *); #if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); +char ZLIB_INTERNAL *gz_strwinerror(DWORD error); #endif /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t value -- needed when comparing unsigned to z_off64_t, which is signed (possible z_off64_t types off_t, off64_t, and long are all signed) */ -#ifdef INT_MAX -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) -#else -unsigned ZLIB_INTERNAL gz_intmax OF((void)); -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) -#endif +unsigned ZLIB_INTERNAL gz_intmax(void); +#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) diff -Nru zlib-1.2.13.dfsg/gzlib.c zlib-1.3.1.dfsg/gzlib.c --- zlib-1.2.13.dfsg/gzlib.c 2022-10-05 22:17:52.000000000 +0000 +++ zlib-1.3.1.dfsg/gzlib.c 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004-2019 Mark Adler + * Copyright (C) 2004-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -15,10 +15,6 @@ #endif #endif -/* Local functions */ -local void gz_reset OF((gz_statep)); -local gzFile gz_open OF((const void *, int, const char *)); - #if defined UNDER_CE /* Map the Windows error number in ERROR to a locale-dependent error message @@ -30,9 +26,7 @@ The gz_strwinerror function does not change the current setting of GetLastError. */ -char ZLIB_INTERNAL *gz_strwinerror(error) - DWORD error; -{ +char ZLIB_INTERNAL *gz_strwinerror(DWORD error) { static char buf[1024]; wchar_t *msgbuf; @@ -72,9 +66,7 @@ #endif /* UNDER_CE */ /* Reset gzip file state */ -local void gz_reset(state) - gz_statep state; -{ +local void gz_reset(gz_statep state) { state->x.have = 0; /* no output data available */ if (state->mode == GZ_READ) { /* for reading ... */ state->eof = 0; /* not at end of file */ @@ -90,11 +82,7 @@ } /* Open a gzip file either by name or file descriptor. */ -local gzFile gz_open(path, fd, mode) - const void *path; - int fd; - const char *mode; -{ +local gzFile gz_open(const void *path, int fd, const char *mode) { gz_statep state; z_size_t len; int oflag; @@ -269,26 +257,17 @@ } /* -- see zlib.h -- */ -gzFile ZEXPORT gzopen(path, mode) - const char *path; - const char *mode; -{ +gzFile ZEXPORT gzopen(const char *path, const char *mode) { return gz_open(path, -1, mode); } /* -- see zlib.h -- */ -gzFile ZEXPORT gzopen64(path, mode) - const char *path; - const char *mode; -{ +gzFile ZEXPORT gzopen64(const char *path, const char *mode) { return gz_open(path, -1, mode); } /* -- see zlib.h -- */ -gzFile ZEXPORT gzdopen(fd, mode) - int fd; - const char *mode; -{ +gzFile ZEXPORT gzdopen(int fd, const char *mode) { char *path; /* identifier for error messages */ gzFile gz; @@ -306,19 +285,13 @@ /* -- see zlib.h -- */ #ifdef WIDECHAR -gzFile ZEXPORT gzopen_w(path, mode) - const wchar_t *path; - const char *mode; -{ +gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) { return gz_open(path, -2, mode); } #endif /* -- see zlib.h -- */ -int ZEXPORT gzbuffer(file, size) - gzFile file; - unsigned size; -{ +int ZEXPORT gzbuffer(gzFile file, unsigned size) { gz_statep state; /* get internal structure and check integrity */ @@ -335,16 +308,14 @@ /* check and set requested size */ if ((size << 1) < size) return -1; /* need to be able to double it */ - if (size < 2) - size = 2; /* need two bytes to check magic header */ + if (size < 8) + size = 8; /* needed to behave well with flushing */ state->want = size; return 0; } /* -- see zlib.h -- */ -int ZEXPORT gzrewind(file) - gzFile file; -{ +int ZEXPORT gzrewind(gzFile file) { gz_statep state; /* get internal structure */ @@ -365,11 +336,7 @@ } /* -- see zlib.h -- */ -z_off64_t ZEXPORT gzseek64(file, offset, whence) - gzFile file; - z_off64_t offset; - int whence; -{ +z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) { unsigned n; z_off64_t ret; gz_statep state; @@ -442,11 +409,7 @@ } /* -- see zlib.h -- */ -z_off_t ZEXPORT gzseek(file, offset, whence) - gzFile file; - z_off_t offset; - int whence; -{ +z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) { z_off64_t ret; ret = gzseek64(file, (z_off64_t)offset, whence); @@ -454,9 +417,7 @@ } /* -- see zlib.h -- */ -z_off64_t ZEXPORT gztell64(file) - gzFile file; -{ +z_off64_t ZEXPORT gztell64(gzFile file) { gz_statep state; /* get internal structure and check integrity */ @@ -471,9 +432,7 @@ } /* -- see zlib.h -- */ -z_off_t ZEXPORT gztell(file) - gzFile file; -{ +z_off_t ZEXPORT gztell(gzFile file) { z_off64_t ret; ret = gztell64(file); @@ -481,9 +440,7 @@ } /* -- see zlib.h -- */ -z_off64_t ZEXPORT gzoffset64(file) - gzFile file; -{ +z_off64_t ZEXPORT gzoffset64(gzFile file) { z_off64_t offset; gz_statep state; @@ -504,9 +461,7 @@ } /* -- see zlib.h -- */ -z_off_t ZEXPORT gzoffset(file) - gzFile file; -{ +z_off_t ZEXPORT gzoffset(gzFile file) { z_off64_t ret; ret = gzoffset64(file); @@ -514,9 +469,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzeof(file) - gzFile file; -{ +int ZEXPORT gzeof(gzFile file) { gz_statep state; /* get internal structure and check integrity */ @@ -531,10 +484,7 @@ } /* -- see zlib.h -- */ -const char * ZEXPORT gzerror(file, errnum) - gzFile file; - int *errnum; -{ +const char * ZEXPORT gzerror(gzFile file, int *errnum) { gz_statep state; /* get internal structure and check integrity */ @@ -552,9 +502,7 @@ } /* -- see zlib.h -- */ -void ZEXPORT gzclearerr(file) - gzFile file; -{ +void ZEXPORT gzclearerr(gzFile file) { gz_statep state; /* get internal structure and check integrity */ @@ -578,11 +526,7 @@ memory). Simply save the error message as a static string. If there is an allocation failure constructing the error message, then convert the error to out of memory. */ -void ZLIB_INTERNAL gz_error(state, err, msg) - gz_statep state; - int err; - const char *msg; -{ +void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) { /* free previously allocated message and clear */ if (state->msg != NULL) { if (state->err != Z_MEM_ERROR) @@ -619,21 +563,20 @@ #endif } -#ifndef INT_MAX /* portably return maximum value for an int (when limits.h presumed not available) -- we need to do this to cover cases where 2's complement not used, since C standard permits 1's complement and sign-bit representations, otherwise we could just use ((unsigned)-1) >> 1 */ -unsigned ZLIB_INTERNAL gz_intmax() -{ - unsigned p, q; - - p = 1; +unsigned ZLIB_INTERNAL gz_intmax(void) { +#ifdef INT_MAX + return INT_MAX; +#else + unsigned p = 1, q; do { q = p; p <<= 1; p++; } while (p > q); return q >> 1; -} #endif +} diff -Nru zlib-1.2.13.dfsg/gzread.c zlib-1.3.1.dfsg/gzread.c --- zlib-1.2.13.dfsg/gzread.c 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/gzread.c 2023-08-11 17:59:03.000000000 +0000 @@ -5,25 +5,12 @@ #include "gzguts.h" -/* Local functions */ -local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); -local int gz_avail OF((gz_statep)); -local int gz_look OF((gz_statep)); -local int gz_decomp OF((gz_statep)); -local int gz_fetch OF((gz_statep)); -local int gz_skip OF((gz_statep, z_off64_t)); -local z_size_t gz_read OF((gz_statep, voidp, z_size_t)); - /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from state->fd, and update state->eof, state->err, and state->msg as appropriate. This function needs to loop on read(), since read() is not guaranteed to read the number of bytes requested, depending on the type of descriptor. */ -local int gz_load(state, buf, len, have) - gz_statep state; - unsigned char *buf; - unsigned len; - unsigned *have; -{ +local int gz_load(gz_statep state, unsigned char *buf, unsigned len, + unsigned *have) { int ret; unsigned get, max = ((unsigned)-1 >> 2) + 1; @@ -53,9 +40,7 @@ If strm->avail_in != 0, then the current data is moved to the beginning of the input buffer, and then the remainder of the buffer is loaded with the available data from the input file. */ -local int gz_avail(state) - gz_statep state; -{ +local int gz_avail(gz_statep state) { unsigned got; z_streamp strm = &(state->strm); @@ -88,9 +73,7 @@ case, all further file reads will be directly to either the output buffer or a user buffer. If decompressing, the inflate state will be initialized. gz_look() will return 0 on success or -1 on failure. */ -local int gz_look(state) - gz_statep state; -{ +local int gz_look(gz_statep state) { z_streamp strm = &(state->strm); /* allocate read buffers and inflate memory */ @@ -170,9 +153,7 @@ data. If the gzip stream completes, state->how is reset to LOOK to look for the next gzip stream or raw data, once state->x.have is depleted. Returns 0 on success, -1 on failure. */ -local int gz_decomp(state) - gz_statep state; -{ +local int gz_decomp(gz_statep state) { int ret = Z_OK; unsigned had; z_streamp strm = &(state->strm); @@ -224,9 +205,7 @@ looked for to determine whether to copy or decompress. Returns -1 on error, otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the end of the input file has been reached and all data has been processed. */ -local int gz_fetch(state) - gz_statep state; -{ +local int gz_fetch(gz_statep state) { z_streamp strm = &(state->strm); do { @@ -254,10 +233,7 @@ } /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ -local int gz_skip(state, len) - gz_statep state; - z_off64_t len; -{ +local int gz_skip(gz_statep state, z_off64_t len) { unsigned n; /* skip over len bytes or reach end-of-file, whichever comes first */ @@ -289,11 +265,7 @@ input. Return the number of bytes read. If zero is returned, either the end of file was reached, or there was an error. state->err must be consulted in that case to determine which. */ -local z_size_t gz_read(state, buf, len) - gz_statep state; - voidp buf; - z_size_t len; -{ +local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) { z_size_t got; unsigned n; @@ -370,11 +342,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzread(file, buf, len) - gzFile file; - voidp buf; - unsigned len; -{ +int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) { gz_statep state; /* get internal structure */ @@ -406,12 +374,7 @@ } /* -- see zlib.h -- */ -z_size_t ZEXPORT gzfread(buf, size, nitems, file) - voidp buf; - z_size_t size; - z_size_t nitems; - gzFile file; -{ +z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) { z_size_t len; gz_statep state; @@ -442,9 +405,7 @@ #else # undef gzgetc #endif -int ZEXPORT gzgetc(file) - gzFile file; -{ +int ZEXPORT gzgetc(gzFile file) { unsigned char buf[1]; gz_statep state; @@ -469,17 +430,12 @@ return gz_read(state, buf, 1) < 1 ? -1 : buf[0]; } -int ZEXPORT gzgetc_(file) -gzFile file; -{ +int ZEXPORT gzgetc_(gzFile file) { return gzgetc(file); } /* -- see zlib.h -- */ -int ZEXPORT gzungetc(c, file) - int c; - gzFile file; -{ +int ZEXPORT gzungetc(int c, gzFile file) { gz_statep state; /* get internal structure */ @@ -487,6 +443,10 @@ return -1; state = (gz_statep)file; + /* in case this was just opened, set up the input buffer */ + if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) + (void)gz_look(state); + /* check that we're reading and that there's no (serious) error */ if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR)) @@ -536,11 +496,7 @@ } /* -- see zlib.h -- */ -char * ZEXPORT gzgets(file, buf, len) - gzFile file; - char *buf; - int len; -{ +char * ZEXPORT gzgets(gzFile file, char *buf, int len) { unsigned left, n; char *str; unsigned char *eol; @@ -600,9 +556,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzdirect(file) - gzFile file; -{ +int ZEXPORT gzdirect(gzFile file) { gz_statep state; /* get internal structure */ @@ -620,9 +574,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzclose_r(file) - gzFile file; -{ +int ZEXPORT gzclose_r(gzFile file) { int ret, err; gz_statep state; diff -Nru zlib-1.2.13.dfsg/gzwrite.c zlib-1.3.1.dfsg/gzwrite.c --- zlib-1.2.13.dfsg/gzwrite.c 2022-10-05 22:17:52.000000000 +0000 +++ zlib-1.3.1.dfsg/gzwrite.c 2023-04-16 04:17:31.000000000 +0000 @@ -5,18 +5,10 @@ #include "gzguts.h" -/* Local functions */ -local int gz_init OF((gz_statep)); -local int gz_comp OF((gz_statep, int)); -local int gz_zero OF((gz_statep, z_off64_t)); -local z_size_t gz_write OF((gz_statep, voidpc, z_size_t)); - /* Initialize state for writing a gzip file. Mark initialization by setting state->size to non-zero. Return -1 on a memory allocation failure, or 0 on success. */ -local int gz_init(state) - gz_statep state; -{ +local int gz_init(gz_statep state) { int ret; z_streamp strm = &(state->strm); @@ -70,10 +62,7 @@ deflate() flush value. If flush is Z_FINISH, then the deflate() state is reset to start a new gzip stream. If gz->direct is true, then simply write to the output file without compressing, and ignore flush. */ -local int gz_comp(state, flush) - gz_statep state; - int flush; -{ +local int gz_comp(gz_statep state, int flush) { int ret, writ; unsigned have, put, max = ((unsigned)-1 >> 2) + 1; z_streamp strm = &(state->strm); @@ -151,10 +140,7 @@ /* Compress len zeros to output. Return -1 on a write error or memory allocation failure by gz_comp(), or 0 on success. */ -local int gz_zero(state, len) - gz_statep state; - z_off64_t len; -{ +local int gz_zero(gz_statep state, z_off64_t len) { int first; unsigned n; z_streamp strm = &(state->strm); @@ -184,11 +170,7 @@ /* Write len bytes from buf to file. Return the number of bytes written. If the returned value is less than len, then there was an error. */ -local z_size_t gz_write(state, buf, len) - gz_statep state; - voidpc buf; - z_size_t len; -{ +local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) { z_size_t put = len; /* if len is zero, avoid unnecessary operations */ @@ -252,11 +234,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzwrite(file, buf, len) - gzFile file; - voidpc buf; - unsigned len; -{ +int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) { gz_statep state; /* get internal structure */ @@ -280,12 +258,8 @@ } /* -- see zlib.h -- */ -z_size_t ZEXPORT gzfwrite(buf, size, nitems, file) - voidpc buf; - z_size_t size; - z_size_t nitems; - gzFile file; -{ +z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems, + gzFile file) { z_size_t len; gz_statep state; @@ -310,10 +284,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzputc(file, c) - gzFile file; - int c; -{ +int ZEXPORT gzputc(gzFile file, int c) { unsigned have; unsigned char buf[1]; gz_statep state; @@ -358,10 +329,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzputs(file, s) - gzFile file; - const char *s; -{ +int ZEXPORT gzputs(gzFile file, const char *s) { z_size_t len, put; gz_statep state; @@ -388,8 +356,7 @@ #include /* -- see zlib.h -- */ -int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) -{ +int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) { int len; unsigned left; char *next; @@ -460,8 +427,7 @@ return len; } -int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) -{ +int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) { va_list va; int ret; @@ -474,13 +440,10 @@ #else /* !STDC && !Z_HAVE_STDARG_H */ /* -- see zlib.h -- */ -int ZEXPORTVA gzprintf(file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) - gzFile file; - const char *format; - int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -{ +int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, + int a4, int a5, int a6, int a7, int a8, int a9, int a10, + int a11, int a12, int a13, int a14, int a15, int a16, + int a17, int a18, int a19, int a20) { unsigned len, left; char *next; gz_statep state; @@ -562,10 +525,7 @@ #endif /* -- see zlib.h -- */ -int ZEXPORT gzflush(file, flush) - gzFile file; - int flush; -{ +int ZEXPORT gzflush(gzFile file, int flush) { gz_statep state; /* get internal structure */ @@ -594,11 +554,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzsetparams(file, level, strategy) - gzFile file; - int level; - int strategy; -{ +int ZEXPORT gzsetparams(gzFile file, int level, int strategy) { gz_statep state; z_streamp strm; @@ -609,7 +565,7 @@ strm = &(state->strm); /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) + if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct) return Z_STREAM_ERROR; /* if no change is requested, then do nothing */ @@ -636,9 +592,7 @@ } /* -- see zlib.h -- */ -int ZEXPORT gzclose_w(file) - gzFile file; -{ +int ZEXPORT gzclose_w(gzFile file) { int ret = Z_OK; gz_statep state; diff -Nru zlib-1.2.13.dfsg/infback.c zlib-1.3.1.dfsg/infback.c --- zlib-1.2.13.dfsg/infback.c 2022-07-24 18:41:07.000000000 +0000 +++ zlib-1.3.1.dfsg/infback.c 2023-04-16 04:17:31.000000000 +0000 @@ -15,9 +15,6 @@ #include "inflate.h" #include "inffast.h" -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); - /* strm provides memory allocation functions in zalloc and zfree, or Z_NULL to use the library memory allocation functions. @@ -25,13 +22,9 @@ windowBits is in the range 8..15, and window is a user-supplied window and output buffer that is 2**windowBits bytes. */ -int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) -z_streamp strm; -int windowBits; -unsigned char FAR *window; -const char *version; -int stream_size; -{ +int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, const char *version, + int stream_size) { struct inflate_state FAR *state; if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || @@ -80,9 +73,7 @@ used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -248,13 +239,8 @@ inflateBack() can also return Z_STREAM_ERROR if the input parameters are not correct, i.e. strm is Z_NULL or the state was not initialized. */ -int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) -z_streamp strm; -in_func in; -void FAR *in_desc; -out_func out; -void FAR *out_desc; -{ +int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -632,9 +618,7 @@ return ret; } -int ZEXPORT inflateBackEnd(strm) -z_streamp strm; -{ +int ZEXPORT inflateBackEnd(z_streamp strm) { if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) return Z_STREAM_ERROR; ZFREE(strm, strm->state); diff -Nru zlib-1.2.13.dfsg/inffast.c zlib-1.3.1.dfsg/inffast.c --- zlib-1.2.13.dfsg/inffast.c 2017-02-16 06:39:26.000000000 +0000 +++ zlib-1.3.1.dfsg/inffast.c 2023-04-16 04:17:31.000000000 +0000 @@ -47,10 +47,7 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { struct inflate_state FAR *state; z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *last; /* have enough input while in < last */ diff -Nru zlib-1.2.13.dfsg/inffast.h zlib-1.3.1.dfsg/inffast.h --- zlib-1.2.13.dfsg/inffast.h 2010-04-19 04:16:01.000000000 +0000 +++ zlib-1.3.1.dfsg/inffast.h 2023-04-16 04:17:31.000000000 +0000 @@ -8,4 +8,4 @@ subject to change. Applications should only use zlib.h. */ -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start); diff -Nru zlib-1.2.13.dfsg/inflate.c zlib-1.3.1.dfsg/inflate.c --- zlib-1.2.13.dfsg/inflate.c 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/inflate.c 2023-08-24 06:14:23.000000000 +0000 @@ -91,20 +91,7 @@ # endif #endif -/* function prototypes */ -local int inflateStateCheck OF((z_streamp strm)); -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); -#ifdef BUILDFIXED - void makefixed OF((void)); -#endif -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); - -local int inflateStateCheck(strm) -z_streamp strm; -{ +local int inflateStateCheck(z_streamp strm) { struct inflate_state FAR *state; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -116,9 +103,7 @@ return 0; } -int ZEXPORT inflateResetKeep(strm) -z_streamp strm; -{ +int ZEXPORT inflateResetKeep(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -142,9 +127,7 @@ return Z_OK; } -int ZEXPORT inflateReset(strm) -z_streamp strm; -{ +int ZEXPORT inflateReset(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -155,10 +138,7 @@ return inflateResetKeep(strm); } -int ZEXPORT inflateReset2(strm, windowBits) -z_streamp strm; -int windowBits; -{ +int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { int wrap; struct inflate_state FAR *state; @@ -195,12 +175,8 @@ return inflateReset(strm); } -int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) -z_streamp strm; -int windowBits; -const char *version; -int stream_size; -{ +int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size) { int ret; struct inflate_state FAR *state; @@ -239,22 +215,17 @@ return ret; } -int ZEXPORT inflateInit_(strm, version, stream_size) -z_streamp strm; -const char *version; -int stream_size; -{ +int ZEXPORT inflateInit_(z_streamp strm, const char *version, + int stream_size) { return inflateInit2_(strm, DEF_WBITS, version, stream_size); } -int ZEXPORT inflatePrime(strm, bits, value) -z_streamp strm; -int bits; -int value; -{ +int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; state = (struct inflate_state FAR *)strm->state; if (bits < 0) { state->hold = 0; @@ -278,9 +249,7 @@ used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -342,7 +311,7 @@ a.out > inffixed.h */ -void makefixed() +void makefixed(void) { unsigned low, size; struct inflate_state state; @@ -396,11 +365,7 @@ output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -local int updatewindow(strm, end, copy) -z_streamp strm; -const Bytef *end; -unsigned copy; -{ +local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { struct inflate_state FAR *state; unsigned dist; @@ -622,10 +587,7 @@ will return Z_BUF_ERROR if it has not reached the end of the stream. */ -int ZEXPORT inflate(strm, flush) -z_streamp strm; -int flush; -{ +int ZEXPORT inflate(z_streamp strm, int flush) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -1301,9 +1263,7 @@ return ret; } -int ZEXPORT inflateEnd(strm) -z_streamp strm; -{ +int ZEXPORT inflateEnd(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1315,11 +1275,8 @@ return Z_OK; } -int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) -z_streamp strm; -Bytef *dictionary; -uInt *dictLength; -{ +int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { struct inflate_state FAR *state; /* check state */ @@ -1338,11 +1295,8 @@ return Z_OK; } -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ +int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { struct inflate_state FAR *state; unsigned long dictid; int ret; @@ -1373,10 +1327,7 @@ return Z_OK; } -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ +int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { struct inflate_state FAR *state; /* check state */ @@ -1401,11 +1352,8 @@ called again with more data and the *have state. *have is initialized to zero for the first call. */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -const unsigned char FAR *buf; -unsigned len; -{ +local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, + unsigned len) { unsigned got; unsigned next; @@ -1424,9 +1372,7 @@ return next; } -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ +int ZEXPORT inflateSync(z_streamp strm) { unsigned len; /* number of bytes to look at or looked at */ int flags; /* temporary to save header status */ unsigned long in, out; /* temporary to save total_in and total_out */ @@ -1441,7 +1387,7 @@ /* if first time, start search in bit buffer */ if (state->mode != SYNC) { state->mode = SYNC; - state->hold <<= state->bits & 7; + state->hold >>= state->bits & 7; state->bits -= state->bits & 7; len = 0; while (state->bits >= 8) { @@ -1482,9 +1428,7 @@ block. When decompressing, PPP checks that at the end of input packet, inflate is waiting for these length bytes. */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ +int ZEXPORT inflateSyncPoint(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1492,10 +1436,7 @@ return state->mode == STORED && state->bits == 0; } -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ +int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { struct inflate_state FAR *state; struct inflate_state FAR *copy; unsigned char FAR *window; @@ -1539,10 +1480,7 @@ return Z_OK; } -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ +int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1557,10 +1495,7 @@ #endif } -int ZEXPORT inflateValidate(strm, check) -z_streamp strm; -int check; -{ +int ZEXPORT inflateValidate(z_streamp strm, int check) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1572,9 +1507,7 @@ return Z_OK; } -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ +long ZEXPORT inflateMark(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) @@ -1585,9 +1518,7 @@ (state->mode == MATCH ? state->was - state->length : 0)); } -unsigned long ZEXPORT inflateCodesUsed(strm) -z_streamp strm; -{ +unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return (unsigned long)-1; state = (struct inflate_state FAR *)strm->state; diff -Nru zlib-1.2.13.dfsg/inftrees.c zlib-1.3.1.dfsg/inftrees.c --- zlib-1.2.13.dfsg/inftrees.c 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/inftrees.c 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2022 Mark Adler + * Copyright (C) 1995-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; + " inflate 1.3.1 Copyright 1995-2024 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -29,14 +29,9 @@ table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; -{ +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ unsigned min, max; /* minimum and maximum code lengths */ @@ -62,7 +57,7 @@ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff -Nru zlib-1.2.13.dfsg/inftrees.h zlib-1.3.1.dfsg/inftrees.h --- zlib-1.2.13.dfsg/inftrees.h 2022-08-23 22:35:13.000000000 +0000 +++ zlib-1.3.1.dfsg/inftrees.h 2023-11-15 02:44:32.000000000 +0000 @@ -41,8 +41,8 @@ examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the + returns 852, and "enough 30 6 15" for distance codes returns 592. The + initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in inflate.c and infback.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and updated. */ @@ -57,6 +57,6 @@ DISTS } codetype; -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work); diff -Nru zlib-1.2.13.dfsg/old/visual-basic.txt zlib-1.3.1.dfsg/old/visual-basic.txt --- zlib-1.2.13.dfsg/old/visual-basic.txt 2003-10-27 03:13:42.000000000 +0000 +++ zlib-1.3.1.dfsg/old/visual-basic.txt 2024-01-17 21:49:11.000000000 +0000 @@ -115,7 +115,7 @@ ReDim Preserve bytaryCpr(lngCprSiz - 1) Open strCprPth For Binary Access Write As #1 Put #1, , bytaryCpr() - Put #1, , lngOriSiz 'Add the the original size value to the end + Put #1, , lngOriSiz 'Add the original size value to the end (last 4 bytes) Close #1 Else diff -Nru zlib-1.2.13.dfsg/os400/README400 zlib-1.3.1.dfsg/os400/README400 --- zlib-1.2.13.dfsg/os400/README400 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/os400/README400 2024-01-22 18:32:37.000000000 +0000 @@ -1,4 +1,4 @@ - ZLIB version 1.2.13 for OS/400 installation instructions + ZLIB version 1.3.1 for OS/400 installation instructions 1) Download and unpack the zlib tarball to some IFS directory. (i.e.: /path/to/the/zlib/ifs/source/directory) diff -Nru zlib-1.2.13.dfsg/os400/zlib.inc zlib-1.3.1.dfsg/os400/zlib.inc --- zlib-1.2.13.dfsg/os400/zlib.inc 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/os400/zlib.inc 2024-01-22 18:32:37.000000000 +0000 @@ -1,7 +1,7 @@ * ZLIB.INC - Interface to the general purpose compression library * * ILE RPG400 version by Patrick Monnerat, DATASPHERE. - * Version 1.2.13 + * Version 1.3.1 * * * WARNING: @@ -22,12 +22,12 @@ * * Versioning information. * - D ZLIB_VERSION C '1.2.13' + D ZLIB_VERSION C '1.3.1' D ZLIB_VERNUM C X'12a0' D ZLIB_VER_MAJOR C 1 - D ZLIB_VER_MINOR C 2 + D ZLIB_VER_MINOR C 3 D ZLIB_VER_REVISION... - D C 13 + D C 1 D ZLIB_VER_SUBREVISION... D C 0 * diff -Nru zlib-1.2.13.dfsg/qnx/package.qpg zlib-1.3.1.dfsg/qnx/package.qpg --- zlib-1.2.13.dfsg/qnx/package.qpg 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/qnx/package.qpg 2024-01-22 18:32:37.000000000 +0000 @@ -25,10 +25,10 @@ - - - - + + + + @@ -63,7 +63,7 @@ - 1.2.13 + 1.3.1 Medium Stable diff -Nru zlib-1.2.13.dfsg/test/example.c zlib-1.3.1.dfsg/test/example.c --- zlib-1.2.13.dfsg/test/example.c 2022-05-26 15:47:51.000000000 +0000 +++ zlib-1.3.1.dfsg/test/example.c 2023-09-04 04:50:07.000000000 +0000 @@ -34,37 +34,14 @@ static const char dictionary[] = "hello"; static uLong dictId; /* Adler32 value of the dictionary */ -void test_deflate OF((Byte *compr, uLong comprLen)); -void test_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_large_deflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_large_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_flush OF((Byte *compr, uLong *comprLen)); -void test_sync OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_dict_deflate OF((Byte *compr, uLong comprLen)); -void test_dict_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -int main OF((int argc, char *argv[])); - - #ifdef Z_SOLO -void *myalloc OF((void *, unsigned, unsigned)); -void myfree OF((void *, void *)); - -void *myalloc(q, n, m) - void *q; - unsigned n, m; -{ +static void *myalloc(void *q, unsigned n, unsigned m) { (void)q; return calloc(n, m); } -void myfree(void *q, void *p) -{ +static void myfree(void *q, void *p) { (void)q; free(p); } @@ -77,18 +54,11 @@ static alloc_func zalloc = (alloc_func)0; static free_func zfree = (free_func)0; -void test_compress OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_gzio OF((const char *fname, - Byte *uncompr, uLong uncomprLen)); - /* =========================================================================== * Test compress() and uncompress() */ -void test_compress(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ +static void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { int err; uLong len = (uLong)strlen(hello)+1; @@ -111,11 +81,7 @@ /* =========================================================================== * Test read/write of .gz files */ -void test_gzio(fname, uncompr, uncomprLen) - const char *fname; /* compressed file name */ - Byte *uncompr; - uLong uncomprLen; -{ +static void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) { #ifdef NO_GZCOMPRESS fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); #else @@ -197,10 +163,7 @@ /* =========================================================================== * Test deflate() with small buffers */ -void test_deflate(compr, comprLen) - Byte *compr; - uLong comprLen; -{ +static void test_deflate(Byte *compr, uLong comprLen) { z_stream c_stream; /* compression stream */ int err; uLong len = (uLong)strlen(hello)+1; @@ -235,10 +198,8 @@ /* =========================================================================== * Test inflate() with small buffers */ -void test_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ +static void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -276,10 +237,8 @@ /* =========================================================================== * Test deflate() with large buffers and dynamic change of compression level */ -void test_large_deflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ +static void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { z_stream c_stream; /* compression stream */ int err; @@ -308,7 +267,7 @@ /* Feed in already compressed data and switch to no compression: */ deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); c_stream.next_in = compr; - c_stream.avail_in = (uInt)comprLen/2; + c_stream.avail_in = (uInt)uncomprLen/2; err = deflate(&c_stream, Z_NO_FLUSH); CHECK_ERR(err, "deflate"); @@ -331,10 +290,8 @@ /* =========================================================================== * Test inflate() with large buffers */ -void test_large_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ +static void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -361,7 +318,7 @@ err = inflateEnd(&d_stream); CHECK_ERR(err, "inflateEnd"); - if (d_stream.total_out != 2*uncomprLen + comprLen/2) { + if (d_stream.total_out != 2*uncomprLen + uncomprLen/2) { fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); exit(1); } else { @@ -372,10 +329,7 @@ /* =========================================================================== * Test deflate() with full flush */ -void test_flush(compr, comprLen) - Byte *compr; - uLong *comprLen; -{ +static void test_flush(Byte *compr, uLong *comprLen) { z_stream c_stream; /* compression stream */ int err; uInt len = (uInt)strlen(hello)+1; @@ -410,10 +364,8 @@ /* =========================================================================== * Test inflateSync() */ -void test_sync(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ +static void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -453,10 +405,7 @@ /* =========================================================================== * Test deflate() with preset dictionary */ -void test_dict_deflate(compr, comprLen) - Byte *compr; - uLong comprLen; -{ +static void test_dict_deflate(Byte *compr, uLong comprLen) { z_stream c_stream; /* compression stream */ int err; @@ -490,10 +439,8 @@ /* =========================================================================== * Test inflate() with a preset dictionary */ -void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ +static void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -541,13 +488,10 @@ * Usage: example [output.gz [input.gz]] */ -int main(argc, argv) - int argc; - char *argv[]; -{ +int main(int argc, char *argv[]) { Byte *compr, *uncompr; - uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ - uLong uncomprLen = comprLen; + uLong uncomprLen = 20000; + uLong comprLen = 3 * uncomprLen; static const char* myVersion = ZLIB_VERSION; if (zlibVersion()[0] != myVersion[0]) { @@ -590,7 +534,7 @@ test_flush(compr, &comprLen); test_sync(compr, comprLen, uncompr, uncomprLen); - comprLen = uncomprLen; + comprLen = 3 * uncomprLen; test_dict_deflate(compr, comprLen); test_dict_inflate(compr, comprLen, uncompr, uncomprLen); diff -Nru zlib-1.2.13.dfsg/test/infcover.c zlib-1.3.1.dfsg/test/infcover.c --- zlib-1.2.13.dfsg/test/infcover.c 2017-01-01 07:37:10.000000000 +0000 +++ zlib-1.3.1.dfsg/test/infcover.c 2023-04-18 03:21:58.000000000 +0000 @@ -373,7 +373,7 @@ mem_setup(&strm); strm.avail_in = 0; strm.next_in = Z_NULL; - ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream)); + ret = inflateInit_(&strm, "!", (int)sizeof(z_stream)); assert(ret == Z_VERSION_ERROR); mem_done(&strm, "wrong version"); @@ -462,7 +462,8 @@ local int push(void *desc, unsigned char *buf, unsigned len) { - buf += len; + (void)buf; + (void)len; return desc != Z_NULL; /* force error if desc not null */ } diff -Nru zlib-1.2.13.dfsg/test/minigzip.c zlib-1.3.1.dfsg/test/minigzip.c --- zlib-1.2.13.dfsg/test/minigzip.c 2022-10-01 23:52:35.000000000 +0000 +++ zlib-1.3.1.dfsg/test/minigzip.c 2024-01-18 00:43:38.000000000 +0000 @@ -59,7 +59,7 @@ #if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) #ifndef WIN32 /* unlink already in stdio.h for WIN32 */ - extern int unlink OF((const char *)); + extern int unlink(const char *); #endif #endif @@ -149,20 +149,12 @@ # include /* for unlink() */ #endif -void *myalloc OF((void *, unsigned, unsigned)); -void myfree OF((void *, void *)); - -void *myalloc(q, n, m) - void *q; - unsigned n, m; -{ +static void *myalloc(void *q, unsigned n, unsigned m) { (void)q; return calloc(n, m); } -void myfree(q, p) - void *q, *p; -{ +static void myfree(void *q, void *p) { (void)q; free(p); } @@ -175,29 +167,7 @@ z_stream strm; } *gzFile; -gzFile gzopen OF((const char *, const char *)); -gzFile gzdopen OF((int, const char *)); -gzFile gz_open OF((const char *, int, const char *)); - -gzFile gzopen(path, mode) -const char *path; -const char *mode; -{ - return gz_open(path, -1, mode); -} - -gzFile gzdopen(fd, mode) -int fd; -const char *mode; -{ - return gz_open(NULL, fd, mode); -} - -gzFile gz_open(path, fd, mode) - const char *path; - int fd; - const char *mode; -{ +static gzFile gz_open(const char *path, int fd, const char *mode) { gzFile gz; int ret; @@ -231,13 +201,15 @@ return gz; } -int gzwrite OF((gzFile, const void *, unsigned)); +static gzFile gzopen(const char *path, const char *mode) { + return gz_open(path, -1, mode); +} -int gzwrite(gz, buf, len) - gzFile gz; - const void *buf; - unsigned len; -{ +static gzFile gzdopen(int fd, const char *mode) { + return gz_open(NULL, fd, mode); +} + +static int gzwrite(gzFile gz, const void *buf, unsigned len) { z_stream *strm; unsigned char out[BUFLEN]; @@ -255,13 +227,7 @@ return len; } -int gzread OF((gzFile, void *, unsigned)); - -int gzread(gz, buf, len) - gzFile gz; - void *buf; - unsigned len; -{ +static int gzread(gzFile gz, void *buf, unsigned len) { int ret; unsigned got; unsigned char in[1]; @@ -292,11 +258,7 @@ return len - strm->avail_out; } -int gzclose OF((gzFile)); - -int gzclose(gz) - gzFile gz; -{ +static int gzclose(gzFile gz) { z_stream *strm; unsigned char out[BUFLEN]; @@ -321,12 +283,7 @@ return Z_OK; } -const char *gzerror OF((gzFile, int *)); - -const char *gzerror(gz, err) - gzFile gz; - int *err; -{ +static const char *gzerror(gzFile gz, int *err) { *err = gz->err; return gz->msg; } @@ -335,67 +292,20 @@ static char *prog; -void error OF((const char *msg)); -void gz_compress OF((FILE *in, gzFile out)); -#ifdef USE_MMAP -int gz_compress_mmap OF((FILE *in, gzFile out)); -#endif -void gz_uncompress OF((gzFile in, FILE *out)); -void file_compress OF((char *file, char *mode)); -void file_uncompress OF((char *file)); -int main OF((int argc, char *argv[])); - /* =========================================================================== * Display error message and exit */ -void error(msg) - const char *msg; -{ +static void error(const char *msg) { fprintf(stderr, "%s: %s\n", prog, msg); exit(1); } -/* =========================================================================== - * Compress input to output then close both files. - */ - -void gz_compress(in, out) - FILE *in; - gzFile out; -{ - local char buf[BUFLEN]; - int len; - int err; - -#ifdef USE_MMAP - /* Try first compressing with mmap. If mmap fails (minigzip used in a - * pipe), use the normal fread loop. - */ - if (gz_compress_mmap(in, out) == Z_OK) return; -#endif - for (;;) { - len = (int)fread(buf, 1, sizeof(buf), in); - if (ferror(in)) { - perror("fread"); - exit(1); - } - if (len == 0) break; - - if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); - } - fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); -} - #ifdef USE_MMAP /* MMAP version, Miguel Albrecht */ /* Try compressing the input file at once using mmap. Return Z_OK if - * if success, Z_ERRNO otherwise. + * success, Z_ERRNO otherwise. */ -int gz_compress_mmap(in, out) - FILE *in; - gzFile out; -{ +static int gz_compress_mmap(FILE *in, gzFile out) { int len; int err; int ifd = fileno(in); @@ -425,12 +335,38 @@ #endif /* USE_MMAP */ /* =========================================================================== + * Compress input to output then close both files. + */ + +static void gz_compress(FILE *in, gzFile out) { + local char buf[BUFLEN]; + int len; + int err; + +#ifdef USE_MMAP + /* Try first compressing with mmap. If mmap fails (minigzip used in a + * pipe), use the normal fread loop. + */ + if (gz_compress_mmap(in, out) == Z_OK) return; +#endif + for (;;) { + len = (int)fread(buf, 1, sizeof(buf), in); + if (ferror(in)) { + perror("fread"); + exit(1); + } + if (len == 0) break; + + if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); + } + fclose(in); + if (gzclose(out) != Z_OK) error("failed gzclose"); +} + +/* =========================================================================== * Uncompress input to output then close both files. */ -void gz_uncompress(in, out) - gzFile in; - FILE *out; -{ +static void gz_uncompress(gzFile in, FILE *out) { local char buf[BUFLEN]; int len; int err; @@ -454,10 +390,7 @@ * Compress the given file: create a corresponding .gz file and remove the * original. */ -void file_compress(file, mode) - char *file; - char *mode; -{ +static void file_compress(char *file, char *mode) { local char outfile[MAX_NAME_LEN]; FILE *in; gzFile out; @@ -493,9 +426,7 @@ /* =========================================================================== * Uncompress the given file and remove the original. */ -void file_uncompress(file) - char *file; -{ +static void file_uncompress(char *file) { local char buf[MAX_NAME_LEN]; char *infile, *outfile; FILE *out; @@ -553,10 +484,7 @@ * -1 to -9 : compression level */ -int main(argc, argv) - int argc; - char *argv[]; -{ +int main(int argc, char *argv[]) { int copyout = 0; int uncompr = 0; gzFile file; diff -Nru zlib-1.2.13.dfsg/treebuild.xml zlib-1.3.1.dfsg/treebuild.xml --- zlib-1.2.13.dfsg/treebuild.xml 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/treebuild.xml 2024-01-22 18:32:37.000000000 +0000 @@ -1,6 +1,6 @@ - - + + zip compression library diff -Nru zlib-1.2.13.dfsg/trees.c zlib-1.3.1.dfsg/trees.c --- zlib-1.2.13.dfsg/trees.c 2022-10-05 22:17:52.000000000 +0000 +++ zlib-1.3.1.dfsg/trees.c 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2021 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * detect_data_type() function provided freely by Cosmin Truta, 2006 * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -122,39 +122,116 @@ int max_length; /* max bit length for the codes */ }; -local const static_tree_desc static_l_desc = +#ifdef NO_INIT_GLOBAL_POINTERS +# define TCONST +#else +# define TCONST const +#endif + +local TCONST static_tree_desc static_l_desc = {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; -local const static_tree_desc static_d_desc = +local TCONST static_tree_desc static_d_desc = {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; -local const static_tree_desc static_bl_desc = +local TCONST static_tree_desc static_bl_desc = {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; /* =========================================================================== - * Local (static) routines in this file. + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 */ +local unsigned bi_reverse(unsigned code, int len) { + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned code, int len)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(deflate_state *s) { + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(deflate_state *s) { + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef ZLIB_DEBUG + s->bits_sent = (s->bits_sent + 7) & ~7; +#endif +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + unsigned code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits - 1]) << 1; + next_code[bits] = (ush)code; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, + "inconsistent bit counts"); + Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); + + for (n = 0; n <= max_code; n++) { + int len = tree[n].Len; + if (len == 0) continue; + /* Now reverse the bits */ + tree[n].Code = (ush)bi_reverse(next_code[len]++, len); + + Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", + n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); + } +} #ifdef GEN_TREES_H -local void gen_trees_header OF((void)); +local void gen_trees_header(void); #endif #ifndef ZLIB_DEBUG @@ -168,26 +245,11 @@ #endif /* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== * Send a value on a given number of bits. * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ +local void send_bits(deflate_state *s, int value, int length) { Tracevv((stderr," l %2d v %4x ", length, value)); Assert(length > 0 && length <= 15, "invalid length"); s->bits_sent += (ulg)length; @@ -229,8 +291,7 @@ /* =========================================================================== * Initialize the various 'constant' tables. */ -local void tr_static_init() -{ +local void tr_static_init(void) { #if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; int n; /* iterates over tree elements */ @@ -323,8 +384,7 @@ ((i) == (last)? "\n};\n\n" : \ ((i) % (width) == (width) - 1 ? ",\n" : ", ")) -void gen_trees_header() -{ +void gen_trees_header(void) { FILE *header = fopen("trees.h", "w"); int i; @@ -374,11 +434,25 @@ #endif /* GEN_TREES_H */ /* =========================================================================== + * Initialize a new block. + */ +local void init_block(deflate_state *s) { + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->sym_next = s->matches = 0; +} + +/* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; -{ +void ZLIB_INTERNAL _tr_init(deflate_state *s) { tr_static_init(); s->l_desc.dyn_tree = s->dyn_ltree; @@ -401,24 +475,6 @@ init_block(s); } -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - #define SMALLEST 1 /* Index within the heap array of least frequent node in the Huffman tree */ @@ -448,11 +504,7 @@ * when the heap property is re-established (each father smaller than its * two sons). */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ +local void pqdownheap(deflate_state *s, ct_data *tree, int k) { int v = s->heap[k]; int j = k << 1; /* left son of k */ while (j <= s->heap_len) { @@ -483,10 +535,7 @@ * The length opt_len is updated; static_len is also updated if stree is * not null. */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ +local void gen_bitlen(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; const ct_data *stree = desc->stat_desc->static_tree; @@ -561,48 +610,9 @@ } } -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes(tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits - 1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, - "inconsistent bit counts"); - Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); - - for (n = 0; n <= max_code; n++) { - int len = tree[n].Len; - if (len == 0) continue; - /* Now reverse the bits */ - tree[n].Code = (ush)bi_reverse(next_code[len]++, len); - - Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", - n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); - } -} +#ifdef DUMP_BL_TREE +# include +#endif /* =========================================================================== * Construct one Huffman tree and assigns the code bit strings and lengths. @@ -612,10 +622,7 @@ * and corresponding code. The length opt_len is updated; static_len is * also updated if stree is not null. The field max_code is set. */ -local void build_tree(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ +local void build_tree(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; int elems = desc->stat_desc->elems; @@ -700,11 +707,7 @@ * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */ -local void scan_tree(s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ +local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -745,11 +748,7 @@ * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */ -local void send_tree(s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ +local void send_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -796,9 +795,7 @@ * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree(s) - deflate_state *s; -{ +local int build_bl_tree(deflate_state *s) { int max_blindex; /* index of last bit length code of non zero freq */ /* Determine the bit length frequencies for literal and distance trees */ @@ -831,10 +828,8 @@ * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ +local void send_all_trees(deflate_state *s, int lcodes, int dcodes, + int blcodes) { int rank; /* index in bl_order */ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); @@ -860,12 +855,8 @@ /* =========================================================================== * Send a stored block */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */ bi_windup(s); /* align on byte boundary */ put_short(s, (ush)stored_len); @@ -884,9 +875,7 @@ /* =========================================================================== * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) */ -void ZLIB_INTERNAL _tr_flush_bits(s) - deflate_state *s; -{ +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { bi_flush(s); } @@ -894,9 +883,7 @@ * Send one empty static block to give enough lookahead for inflate. * This takes 10 bits, of which 7 may remain in the bit buffer. */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; -{ +void ZLIB_INTERNAL _tr_align(deflate_state *s) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); #ifdef ZLIB_DEBUG @@ -906,15 +893,107 @@ } /* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(deflate_state *s, const ct_data *ltree, + const ct_data *dtree) { + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned sx = 0; /* running index in symbol buffers */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->sym_next != 0) do { +#ifdef LIT_MEM + dist = s->d_buf[sx]; + lc = s->l_buf[sx++]; +#else + dist = s->sym_buf[sx++] & 0xff; + dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; + lc = s->sym_buf[sx++]; +#endif + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code + LITERALS + 1, ltree); /* send length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= (unsigned)base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check for no overlay of pending_buf on needed symbols */ +#ifdef LIT_MEM + Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); +#else + Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); +#endif + + } while (sx < s->sym_next); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "block list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(deflate_state *s) { + /* block_mask is the bit mask of block-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long block_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("block-listed") bytes. */ + for (n = 0; n <= 31; n++, block_mask >>= 1) + if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("allow-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "block-listed" or "allow-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + +/* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and write out the encoded block. */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -1011,14 +1090,15 @@ * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -int ZLIB_INTERNAL _tr_tally(s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */ -{ +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { +#ifdef LIT_MEM + s->d_buf[s->sym_next] = (ush)dist; + s->l_buf[s->sym_next++] = (uch)lc; +#else s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; +#endif if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; @@ -1035,147 +1115,3 @@ } return (s->sym_next == s->sym_end); } - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - const ct_data *ltree; /* literal tree */ - const ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and sym_buf is ok: */ - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(s) - deflate_state *s; -{ - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent + 7) & ~7; -#endif -} diff -Nru zlib-1.2.13.dfsg/uncompr.c zlib-1.3.1.dfsg/uncompr.c --- zlib-1.2.13.dfsg/uncompr.c 2022-10-05 22:17:52.000000000 +0000 +++ zlib-1.3.1.dfsg/uncompr.c 2023-04-16 04:17:31.000000000 +0000 @@ -24,12 +24,8 @@ Z_DATA_ERROR if the input data was corrupted, including if the input data is an incomplete zlib stream. */ -int ZEXPORT uncompress2(dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong *sourceLen; -{ +int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong *sourceLen) { z_stream stream; int err; const uInt max = (uInt)-1; @@ -83,11 +79,7 @@ err; } -int ZEXPORT uncompress(dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ +int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen) { return uncompress2(dest, destLen, source, &sourceLen); } diff -Nru zlib-1.2.13.dfsg/zconf.h zlib-1.3.1.dfsg/zconf.h --- zlib-1.2.13.dfsg/zconf.h 2022-10-10 00:32:50.000000000 +0000 +++ zlib-1.3.1.dfsg/zconf.h 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -241,7 +241,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -296,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -520,7 +516,7 @@ #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff -Nru zlib-1.2.13.dfsg/zconf.h.cmakein zlib-1.3.1.dfsg/zconf.h.cmakein --- zlib-1.2.13.dfsg/zconf.h.cmakein 2022-10-10 00:32:50.000000000 +0000 +++ zlib-1.3.1.dfsg/zconf.h.cmakein 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -243,7 +243,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -298,14 +302,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -522,7 +518,7 @@ #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff -Nru zlib-1.2.13.dfsg/zconf.h.in zlib-1.3.1.dfsg/zconf.h.in --- zlib-1.2.13.dfsg/zconf.h.in 2022-10-10 00:32:50.000000000 +0000 +++ zlib-1.3.1.dfsg/zconf.h.in 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -241,7 +241,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -296,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -520,7 +516,7 @@ #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff -Nru zlib-1.2.13.dfsg/zlib.3 zlib-1.3.1.dfsg/zlib.3 --- zlib-1.2.13.dfsg/zlib.3 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/zlib.3 2024-01-22 18:32:37.000000000 +0000 @@ -1,4 +1,4 @@ -.TH ZLIB 3 "13 Oct 2022" +.TH ZLIB 3 "22 Jan 2024" .SH NAME zlib \- compression/decompression library .SH SYNOPSIS @@ -105,9 +105,9 @@ Send questions and/or comments to zlib@gzip.org, or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). .SH AUTHORS AND LICENSE -Version 1.2.13 +Version 1.3.1 .LP -Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler +Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler .LP This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages Binary files /tmp/tmp13dowgjr/4DLQkXgOZC/zlib-1.2.13.dfsg/zlib.3.pdf and /tmp/tmp13dowgjr/4_2QGfnMM3/zlib-1.3.1.dfsg/zlib.3.pdf differ diff -Nru zlib-1.2.13.dfsg/zlib.h zlib-1.3.1.dfsg/zlib.h --- zlib-1.2.13.dfsg/zlib.h 2022-10-13 05:06:55.000000000 +0000 +++ zlib-1.3.1.dfsg/zlib.h 2024-01-22 18:32:37.000000000 +0000 @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13, October 13th, 2022 + version 1.3.1, January 22nd, 2024 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13" -#define ZLIB_VERNUM 0x12d0 +#define ZLIB_VERSION "1.3.1" +#define ZLIB_VERNUM 0x1310 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 1 #define ZLIB_VER_SUBREVISION 0 /* @@ -78,8 +78,8 @@ even in the case of corrupted input. */ -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); +typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); +typedef void (*free_func)(voidpf opaque, voidpf address); struct internal_state; @@ -217,7 +217,7 @@ /* basic functions */ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +ZEXTERN const char * ZEXPORT zlibVersion(void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -225,12 +225,12 @@ */ /* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); +ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -247,7 +247,7 @@ */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -320,8 +320,8 @@ with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -360,7 +360,7 @@ */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -375,7 +375,7 @@ /* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateInit(z_streamp strm); Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by @@ -383,7 +383,8 @@ read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -397,7 +398,7 @@ */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -517,7 +518,7 @@ */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -535,12 +536,12 @@ */ /* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); +ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy); This is another version of deflateInit with more compression options. The fields zalloc, zfree and opaque must be initialized before by the caller. @@ -607,9 +608,9 @@ compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -651,9 +652,9 @@ not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -673,8 +674,8 @@ stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -691,20 +692,20 @@ destination. */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateReset(z_streamp strm); /* This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); +ZEXTERN int ZEXPORT deflateParams(z_streamp strm, + int level, + int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -729,7 +730,7 @@ Then no more input data should be provided before the deflateParams() call. If this is done, the old level and strategy will be applied to the data compressed before deflateParams(), and the new level and strategy will be - applied to the the data compressed after deflateParams(). + applied to the data compressed after deflateParams(). deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if @@ -740,11 +741,11 @@ retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); +ZEXTERN int ZEXPORT deflateTune(z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -757,8 +758,8 @@ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); +ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, + uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -772,9 +773,9 @@ than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, - unsigned *pending, - int *bits)); +ZEXTERN int ZEXPORT deflatePending(z_streamp strm, + unsigned *pending, + int *bits); /* deflatePending() returns the number of bytes and bits of output that have been generated, but not yet provided in the available output. The bytes not @@ -787,9 +788,9 @@ stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, + int bits, + int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -804,8 +805,8 @@ source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, + gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -821,16 +822,17 @@ gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ /* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, + int windowBits); This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized @@ -883,9 +885,9 @@ deferred until inflate() is called. */ -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -906,9 +908,9 @@ inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -921,7 +923,7 @@ stream state is inconsistent. */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateSync(z_streamp strm); /* Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all @@ -934,14 +936,14 @@ inflateSync returns Z_OK if a possible full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. + In the success case, the application may save the current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -956,18 +958,19 @@ destination. */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateReset(z_streamp strm); /* This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, + int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -980,9 +983,9 @@ the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, + int bits, + int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1001,7 +1004,7 @@ stream state was inconsistent. */ -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +ZEXTERN long ZEXPORT inflateMark(z_streamp strm); /* This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the @@ -1029,8 +1032,8 @@ source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, + gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1070,8 +1073,8 @@ */ /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); +ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, + unsigned char FAR *window); Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized @@ -1091,13 +1094,13 @@ the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); +typedef unsigned (*in_func)(void FAR *, + z_const unsigned char FAR * FAR *); +typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); + +ZEXTERN int ZEXPORT inflateBack(z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is potentially more efficient than @@ -1165,7 +1168,7 @@ cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); /* All memory allocated by inflateBackInit() is freed. @@ -1173,7 +1176,7 @@ state was inconsistent. */ -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +ZEXTERN uLong ZEXPORT zlibCompileFlags(void); /* Return flags indicating compile-time options. Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: @@ -1226,8 +1229,8 @@ you need special options. */ -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1241,9 +1244,9 @@ buffer. */ -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); +ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1257,15 +1260,15 @@ Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1282,8 +1285,8 @@ buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen)); +ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen. On return, *sourceLen is the number of @@ -1302,7 +1305,7 @@ typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing. The mode parameter is as in fopen ("rb" or "wb") @@ -1339,7 +1342,7 @@ file could not be opened. */ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); /* Associate a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (if the file has @@ -1362,7 +1365,7 @@ will not detect if fd is invalid (unless fd is -1). */ -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); /* Set the internal buffer size used by this library's functions for file to size. The default buffer size is 8192 bytes. This function must be called @@ -1378,7 +1381,7 @@ too late. */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); /* Dynamically update the compression level and strategy for file. See the description of deflateInit2 for the meaning of these parameters. Previously @@ -1389,7 +1392,7 @@ or Z_MEM_ERROR if there is a memory allocation error. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); /* Read and decompress up to len uncompressed bytes from file into buf. If the input file is not in gzip format, gzread copies the given number of @@ -1419,8 +1422,8 @@ Z_STREAM_ERROR. */ -ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, - gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, + gzFile file); /* Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does. This duplicates the interface of @@ -1445,14 +1448,14 @@ file, resetting and retrying on end-of-file, when size is not 1. */ -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); +ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); /* Compress and write the len uncompressed bytes at buf to file. gzwrite returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, - z_size_t nitems, gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, + z_size_t nitems, gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1465,7 +1468,7 @@ is returned, and the error state is set to Z_STREAM_ERROR. */ -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); /* Convert, format, compress, and write the arguments (...) to file under control of the string format, as in fprintf. gzprintf returns the number of @@ -1480,7 +1483,7 @@ This can be determined using zlibCompileFlags(). */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); /* Compress and write the given null-terminated string s to file, excluding the terminating null character. @@ -1488,7 +1491,7 @@ gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1502,13 +1505,13 @@ buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc(gzFile file, int c); /* Compress and write c, converted to an unsigned char, into file. gzputc returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc(gzFile file); /* Read and decompress one byte from file. gzgetc returns this byte or -1 in case of end of file or error. This is implemented as a macro for speed. @@ -1517,7 +1520,7 @@ points to has been clobbered or not. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); /* Push c back onto the stream for file to be read as the first character on the next read. At least one character of push-back is always allowed. @@ -1529,7 +1532,7 @@ gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); /* Flush all pending output to file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function @@ -1545,8 +1548,8 @@ */ /* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); +ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, + z_off_t offset, int whence); Set the starting position to offset relative to whence for the next gzread or gzwrite on file. The offset represents a number of bytes in the @@ -1564,7 +1567,7 @@ would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +ZEXTERN int ZEXPORT gzrewind(gzFile file); /* Rewind file. This function is supported only for reading. @@ -1572,7 +1575,7 @@ */ /* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gztell(gzFile file); Return the starting position for the next gzread or gzwrite on file. This position represents a number of bytes in the uncompressed data stream, @@ -1583,7 +1586,7 @@ */ /* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); Return the current compressed (actual) read or write offset of file. This offset includes the count of bytes that precede the gzip stream, for example @@ -1592,7 +1595,7 @@ be used for a progress indicator. On error, gzoffset() returns -1. */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +ZEXTERN int ZEXPORT gzeof(gzFile file); /* Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise. Note that the end-of-file indicator is set @@ -1607,7 +1610,7 @@ has grown since the previous end of file was detected. */ -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +ZEXTERN int ZEXPORT gzdirect(gzFile file); /* Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed. @@ -1628,7 +1631,7 @@ gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose(gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1641,8 +1644,8 @@ last read ended in the middle of a gzip stream, or Z_OK on success. */ -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_r(gzFile file); +ZEXTERN int ZEXPORT gzclose_w(gzFile file); /* Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending. The advantage to @@ -1653,7 +1656,7 @@ zlib library. */ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1669,7 +1672,7 @@ functions above that do not distinguish those cases in their return values. */ -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +ZEXTERN void ZEXPORT gzclearerr(gzFile file); /* Clear the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip @@ -1686,7 +1689,7 @@ library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. An Adler-32 value is in the range of a 32-bit @@ -1706,15 +1709,15 @@ if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, + z_size_t len); /* Same as adler32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); +ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, + z_off_t len2); Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for @@ -1724,7 +1727,7 @@ negative, the result has no meaning or utility. */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. @@ -1742,30 +1745,30 @@ if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, + z_size_t len); /* Same as crc32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. + len2. len2 must be non-negative. */ /* -ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); Return the operator corresponding to length len2, to be used with - crc32_combine_op(). + crc32_combine_op(). len2 must be non-negative. */ -ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); /* Give the same result as crc32_combine(), using op in place of len2. op is is generated from len2 by crc32_combine_gen(). This will be faster than @@ -1778,20 +1781,20 @@ /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); +ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, + const char *version, int stream_size); +ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size); +ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size); #ifdef Z_PREFIX_SET # define z_deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) @@ -1836,7 +1839,7 @@ unsigned char *next; z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define z_gzgetc(g) \ @@ -1853,13 +1856,13 @@ * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) @@ -1881,50 +1884,50 @@ # define crc32_combine_gen crc32_combine_gen64 # endif # ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); # endif #else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +ZEXTERN const char * ZEXPORT zError(int); +ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); +ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, + const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, - const char *format, - va_list va)); +ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, + const char *format, + va_list va); # endif #endif diff -Nru zlib-1.2.13.dfsg/zlib.map zlib-1.3.1.dfsg/zlib.map --- zlib-1.2.13.dfsg/zlib.map 2022-03-27 23:05:02.000000000 +0000 +++ zlib-1.3.1.dfsg/zlib.map 2024-01-19 23:26:17.000000000 +0000 @@ -1,100 +1,100 @@ -ZLIB_1.2.0 { - global: - compressBound; - deflateBound; - inflateBack; - inflateBackEnd; - inflateBackInit_; - inflateCopy; - local: - deflate_copyright; - inflate_copyright; - inflate_fast; - inflate_table; - zcalloc; - zcfree; - z_errmsg; - gz_error; - gz_intmax; - _*; -}; - -ZLIB_1.2.0.2 { - gzclearerr; - gzungetc; - zlibCompileFlags; -} ZLIB_1.2.0; - -ZLIB_1.2.0.8 { - deflatePrime; -} ZLIB_1.2.0.2; - -ZLIB_1.2.2 { - adler32_combine; - crc32_combine; - deflateSetHeader; - inflateGetHeader; -} ZLIB_1.2.0.8; - -ZLIB_1.2.2.3 { - deflateTune; - gzdirect; -} ZLIB_1.2.2; - -ZLIB_1.2.2.4 { - inflatePrime; -} ZLIB_1.2.2.3; - -ZLIB_1.2.3.3 { - adler32_combine64; - crc32_combine64; - gzopen64; - gzseek64; - gztell64; - inflateUndermine; -} ZLIB_1.2.2.4; - -ZLIB_1.2.3.4 { - inflateReset2; - inflateMark; -} ZLIB_1.2.3.3; - -ZLIB_1.2.3.5 { - gzbuffer; - gzoffset; - gzoffset64; - gzclose_r; - gzclose_w; -} ZLIB_1.2.3.4; - -ZLIB_1.2.5.1 { - deflatePending; -} ZLIB_1.2.3.5; - -ZLIB_1.2.5.2 { - deflateResetKeep; - gzgetc_; - inflateResetKeep; -} ZLIB_1.2.5.1; - -ZLIB_1.2.7.1 { - inflateGetDictionary; - gzvprintf; -} ZLIB_1.2.5.2; - -ZLIB_1.2.9 { - inflateCodesUsed; - inflateValidate; - uncompress2; - gzfread; - gzfwrite; - deflateGetDictionary; - adler32_z; - crc32_z; -} ZLIB_1.2.7.1; - -ZLIB_1.2.12 { - crc32_combine_gen; - crc32_combine_gen64; - crc32_combine_op; -} ZLIB_1.2.9; +ZLIB_1.2.0 { + global: + compressBound; + deflateBound; + inflateBack; + inflateBackEnd; + inflateBackInit_; + inflateCopy; + local: + deflate_copyright; + inflate_copyright; + inflate_fast; + inflate_table; + zcalloc; + zcfree; + z_errmsg; + gz_error; + gz_intmax; + _*; +}; + +ZLIB_1.2.0.2 { + gzclearerr; + gzungetc; + zlibCompileFlags; +} ZLIB_1.2.0; + +ZLIB_1.2.0.8 { + deflatePrime; +} ZLIB_1.2.0.2; + +ZLIB_1.2.2 { + adler32_combine; + crc32_combine; + deflateSetHeader; + inflateGetHeader; +} ZLIB_1.2.0.8; + +ZLIB_1.2.2.3 { + deflateTune; + gzdirect; +} ZLIB_1.2.2; + +ZLIB_1.2.2.4 { + inflatePrime; +} ZLIB_1.2.2.3; + +ZLIB_1.2.3.3 { + adler32_combine64; + crc32_combine64; + gzopen64; + gzseek64; + gztell64; + inflateUndermine; +} ZLIB_1.2.2.4; + +ZLIB_1.2.3.4 { + inflateReset2; + inflateMark; +} ZLIB_1.2.3.3; + +ZLIB_1.2.3.5 { + gzbuffer; + gzoffset; + gzoffset64; + gzclose_r; + gzclose_w; +} ZLIB_1.2.3.4; + +ZLIB_1.2.5.1 { + deflatePending; +} ZLIB_1.2.3.5; + +ZLIB_1.2.5.2 { + deflateResetKeep; + gzgetc_; + inflateResetKeep; +} ZLIB_1.2.5.1; + +ZLIB_1.2.7.1 { + inflateGetDictionary; + gzvprintf; +} ZLIB_1.2.5.2; + +ZLIB_1.2.9 { + inflateCodesUsed; + inflateValidate; + uncompress2; + gzfread; + gzfwrite; + deflateGetDictionary; + adler32_z; + crc32_z; +} ZLIB_1.2.7.1; + +ZLIB_1.2.12 { + crc32_combine_gen; + crc32_combine_gen64; + crc32_combine_op; +} ZLIB_1.2.9; diff -Nru zlib-1.2.13.dfsg/zlib2ansi zlib-1.3.1.dfsg/zlib2ansi --- zlib-1.2.13.dfsg/zlib2ansi 2022-08-23 22:35:13.000000000 +0000 +++ zlib-1.3.1.dfsg/zlib2ansi 1970-01-01 00:00:00.000000000 +0000 @@ -1,152 +0,0 @@ -#!/usr/bin/perl - -# Transform K&R C function definitions into ANSI equivalent. -# -# Author: Paul Marquess -# Version: 1.0 -# Date: 3 October 2006 - -# TODO -# -# Assumes no function pointer parameters. unless they are typedefed. -# Assumes no literal strings that look like function definitions -# Assumes functions start at the beginning of a line - -use strict; -use warnings; - -local $/; -$_ = <>; - -my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments - -my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ; -my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ; -my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ; - - -while (s/^ - ( # Start $1 - ( # Start $2 - .*? # Minimal eat content - ( ^ \w [\w\s\*]+ ) # $3 -- function name - \s* # optional whitespace - ) # $2 - Matched up to before parameter list - - \( \s* # Literal "(" + optional whitespace - ( [^\)]+ ) # $4 - one or more anythings except ")" - \s* \) # optional whitespace surrounding a Literal ")" - - ( (?: $dList )+ ) # $5 - - $sp ^ { # literal "{" at start of line - ) # Remember to $1 - //xsom - ) -{ - my $all = $1 ; - my $prefix = $2; - my $param_list = $4 ; - my $params = $5; - - StripComments($params); - StripComments($param_list); - $param_list =~ s/^\s+//; - $param_list =~ s/\s+$//; - - my $i = 0 ; - my %pList = map { $_ => $i++ } - split /\s*,\s*/, $param_list; - my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ; - - my @params = split /\s*;\s*/, $params; - my @outParams = (); - foreach my $p (@params) - { - if ($p =~ /,/) - { - my @bits = split /\s*,\s*/, $p; - my $first = shift @bits; - $first =~ s/^\s*//; - push @outParams, $first; - $first =~ /^(\w+\s*)/; - my $type = $1 ; - push @outParams, map { $type . $_ } @bits; - } - else - { - $p =~ s/^\s+//; - push @outParams, $p; - } - } - - - my %tmp = map { /$pMatch/; $_ => $pList{$1} } - @outParams ; - - @outParams = map { " $_" } - sort { $tmp{$a} <=> $tmp{$b} } - @outParams ; - - print $prefix ; - print "(\n" . join(",\n", @outParams) . ")\n"; - print "{" ; - -} - -# Output any trailing code. -print ; -exit 0; - - -sub StripComments -{ - - no warnings; - - # Strip C & C++ comments - # From the perlfaq - $_[0] =~ - - s{ - /\* ## Start of /* ... */ comment - [^*]*\*+ ## Non-* followed by 1-or-more *'s - ( - [^/*][^*]*\*+ - )* ## 0-or-more things which don't start with / - ## but do end with '*' - / ## End of /* ... */ comment - - | ## OR C++ Comment - // ## Start of C++ comment // - [^\n]* ## followed by 0-or-more non end of line characters - - | ## OR various things which aren't comments: - - ( - " ## Start of " ... " string - ( - \\. ## Escaped char - | ## OR - [^"\\] ## Non "\ - )* - " ## End of " ... " string - - | ## OR - - ' ## Start of ' ... ' string - ( - \\. ## Escaped char - | ## OR - [^'\\] ## Non '\ - )* - ' ## End of ' ... ' string - - | ## OR - - . ## Anything other char - [^/"'\\]* ## Chars which doesn't start a comment, string or escape - ) - }{$2}gxs; - -} diff -Nru zlib-1.2.13.dfsg/zutil.c zlib-1.3.1.dfsg/zutil.c --- zlib-1.2.13.dfsg/zutil.c 2022-10-07 03:43:09.000000000 +0000 +++ zlib-1.3.1.dfsg/zutil.c 2023-04-16 04:17:31.000000000 +0000 @@ -24,13 +24,11 @@ }; -const char * ZEXPORT zlibVersion() -{ +const char * ZEXPORT zlibVersion(void) { return ZLIB_VERSION; } -uLong ZEXPORT zlibCompileFlags() -{ +uLong ZEXPORT zlibCompileFlags(void) { uLong flags; flags = 0; @@ -121,9 +119,7 @@ # endif int ZLIB_INTERNAL z_verbose = verbose; -void ZLIB_INTERNAL z_error(m) - char *m; -{ +void ZLIB_INTERNAL z_error(char *m) { fprintf(stderr, "%s\n", m); exit(1); } @@ -132,9 +128,7 @@ /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT zError(err) - int err; -{ +const char * ZEXPORT zError(int err) { return ERR_MSG(err); } @@ -148,22 +142,14 @@ #ifndef HAVE_MEMCPY -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ +void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { if (len == 0) return; do { *dest++ = *source++; /* ??? to be unrolled */ } while (--len != 0); } -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ +int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { uInt j; for (j = 0; j < len; j++) { @@ -172,10 +158,7 @@ return 0; } -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ +void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { if (len == 0) return; do { *dest++ = 0; /* ??? to be unrolled */ @@ -216,8 +199,7 @@ * a protected system like OS/2. Use Microsoft C instead. */ -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { voidpf buf; ulg bsize = (ulg)items*size; @@ -242,8 +224,7 @@ return buf; } -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { int n; (void)opaque; @@ -279,14 +260,12 @@ # define _hfree hfree #endif -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) { (void)opaque; return _halloc((long)items, size); } -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; _hfree(ptr); } @@ -299,25 +278,18 @@ #ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); +extern voidp malloc(uInt size); +extern voidp calloc(uInt items, uInt size); +extern void free(voidpf ptr); #endif -voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { (void)opaque; return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } -void ZLIB_INTERNAL zcfree(opaque, ptr) - voidpf opaque; - voidpf ptr; -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; free(ptr); } diff -Nru zlib-1.2.13.dfsg/zutil.h zlib-1.3.1.dfsg/zutil.h --- zlib-1.2.13.dfsg/zutil.h 2022-10-07 03:43:18.000000000 +0000 +++ zlib-1.3.1.dfsg/zutil.h 2024-01-22 18:32:37.000000000 +0000 @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -56,7 +56,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] +#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] #define ERR_RETURN(strm,err) \ return (strm->msg = ERR_MSG(err), (err)) @@ -137,17 +137,8 @@ # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if defined(MACOS) # define OS_CODE 7 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif #endif #ifdef __acorn @@ -170,18 +161,6 @@ # define OS_CODE 19 #endif -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - #if defined(__BORLANDC__) && !defined(MSDOS) #pragma warn -8004 #pragma warn -8008 @@ -191,9 +170,9 @@ /* provide prototypes for these when building zlib without LFS */ #if !defined(_WIN32) && \ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); #endif /* common defaults */ @@ -232,16 +211,16 @@ # define zmemzero(dest, len) memset(dest, 0, len) # endif #else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); + void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len); + int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len); + void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len); #endif /* Diagnostic functions */ #ifdef ZLIB_DEBUG # include extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); + extern void ZLIB_INTERNAL z_error(char *m); # define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;} @@ -258,9 +237,9 @@ #endif #ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); + voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, + unsigned size); + void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr); #endif #define ZALLOC(strm, items, size) \