idnits 2.17.00 (12 Aug 2021) /tmp/idnits52098/draft-deutsch-zlib-spec-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Cannot find the required boilerplate sections (Copyright, IPR, etc.) in this document. Expected boilerplate is as follows today (2022-05-20) according to https://trustee.ietf.org/license-info : IETF Trust Legal Provisions of 28-dec-2009, Section 6.a: This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 2: Copyright (c) 2022 IETF Trust and the persons identified as the document authors. All rights reserved. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 3: This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity -- however, there's a paragraph with a matching beginning. Boilerplate error? ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. == No 'Intended status' indicated for this document; assuming Proposed Standard == The page length should not exceed 58 lines per page, but there was 9 longer pages, the longest (page 2) being 59 lines Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. Miscellaneous warnings: ---------------------------------------------------------------------------- -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (12 Feb 1996) is 9594 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Possible downref: Non-RFC (?) normative reference: ref. '1' -- Possible downref: Non-RFC (?) normative reference: ref. '2' -- Possible downref: Non-RFC (?) normative reference: ref. '3' -- Possible downref: Non-RFC (?) normative reference: ref. '4' -- Possible downref: Non-RFC (?) normative reference: ref. '5' Summary: 8 errors (**), 0 flaws (~~), 2 warnings (==), 8 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 INTERNET-DRAFT L. Peter Deutsch 3 ZLIB 3.3 Aladdin Enterprises 4 Expires: 17 Aug 1996 Jean-Loup Gailly 5 Info-Zip 6 12 Feb 1996 8 ZLIB Compressed Data Format Specification version 3.3 10 File draft-deutsch-zlib-spec-01.txt 12 Status of this Memo 14 This document is an Internet-Draft. Internet-Drafts are working 15 documents of the Internet Engineering Task Force (IETF), its areas, 16 and its working groups. Note that other groups may also distribute 17 working documents as Internet-Drafts. 19 Internet-Drafts are draft documents valid for a maximum of six months 20 and may be updated, replaced, or obsoleted by other documents at any 21 time. It is inappropriate to use Internet- Drafts as reference 22 material or to cite them other than as ``work in progress.'' 24 To learn the current status of any Internet-Draft, please check the 25 ``1id-abstracts.txt'' listing contained in the Internet- Drafts 26 Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), 27 munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or 28 ftp.isi.edu (US West Coast). 30 Distribution of this memo is unlimited. 32 Notices 34 Copyright (C) 1996 L. Peter Deutsch and Jean-loup Gailly 36 Permission is granted to copy and distribute this document for any 37 purpose and without charge, including translations into other 38 languages and incorporation into compilations, provided that it is 39 copied as a whole (including the copyright notice and this notice) 40 and with no changes. 42 Abstract 44 This specification defines a lossless compressed data format. The 45 data can be produced or consumed, even for an arbitrarily long 46 sequentially presented input data stream, using only an a priori 47 bounded amount of intermediate storage. The format presently uses 48 the DEFLATE compression method but can be easily extended to use 49 other compression methods. It can be implemented readily in a manner 51 Deutsch and Gailly [Page 1] 52 not covered by patents. This specification also defines the ADLER-32 53 checksum (an extension and improvement of the Fletcher checksum), 54 used for detection of data corruption, and provides an algorithm for 55 computing it. 57 Table of contents 59 1. Introduction ................................................... 2 60 1.1 Purpose .................................................... 2 61 1.2 Intended audience .......................................... 2 62 1.3 Scope ...................................................... 3 63 1.4 Compliance ................................................. 3 64 1.5 Definitions of terms and conventions used ................. 3 65 1.6 Changes from previous versions ............................. 3 66 2. Detailed specification ......................................... 3 67 2.1 Overall conventions ........................................ 3 68 2.2 Data format ................................................ 4 69 2.3 Compliance ................................................. 6 70 3. References ..................................................... 7 71 4. Source code .................................................... 7 72 5. Security considerations ........................................ 7 73 6. Acknowledgements ............................................... 7 74 7. Authors' addresses ............................................. 7 75 8. Appendix: Rationale ............................................ 8 76 9. Appendix: Sample code .......................................... 9 78 1. Introduction 80 1.1. Purpose 82 The purpose of this specification is to define a lossless 83 compressed data format that: 85 o Is independent of CPU type, operating system, file system, 86 and character set, and hence can be used for interchange; 88 o Can be produced or consumed, even for an arbitrarily long 89 sequentially presented input data stream, using only an a 90 priori bounded amount of intermediate storage, and hence can 91 be used in data communications or similar structures such as 92 Unix filters; 94 o Can use a number of different compression methods; 96 o Can be implemented readily in a manner not covered by 97 patents, and hence can be practiced freely. 99 The data format defined by this specification does not attempt to 100 allow random access to compressed data. 101 1.2. Intended audience 103 This specification is intended for use by implementors of software 105 Deutsch and Gailly [Page 2] 106 to compress data into zlib format and/or decompress data from zlib 107 format. 109 The text of the specification assumes a basic background in 110 programming at the level of bits and other primitive data 111 representations. 113 1.3. Scope 115 The specification specifies a compressed data format that can be 116 used for in-memory compression of a sequence of arbitrary bytes. 118 1.4. Compliance 120 Unless otherwise indicated below, a compliant decompressor must be 121 able to accept and decompress any data set that conforms to all 122 the specifications presented here; a compliant compressor must 123 produce data sets that conform to all the specifications presented 124 here. 126 1.5. Definitions of terms and conventions used 128 byte: 8 bits stored or transmitted as a unit (same as an octet). 129 (For this specification, a byte is exactly 8 bits, even on 130 machines which store a character on a number of bits different 131 from 8.) See Section 2.1, below, for the numbering of bits within 132 a byte. 134 1.6. Changes from previous versions 136 Version 3.1 was the first public release of this specification. 137 In version 3.2, some terminology was changed and the Adler-32 138 sample code was rewritten for clarity. In version 3.3, the 139 support for a preset dictionary was introduced, and the 140 specification was converted to Internet Draft style. 142 2. Detailed specification 144 2.1. Overall conventions 146 In the diagrams below, a box like this: 148 +---+ 149 | | <-- the vertical bars might be missing 150 +---+ 152 represents one byte; a box like this: 154 +==============+ 155 | | 156 +==============+ 158 Deutsch and Gailly [Page 3] 159 represents a variable number of bytes. 161 Bytes stored within a computer do not have a 'bit order', since 162 they are always treated as a unit. However, a byte considered as 163 an integer between 0 and 255 does have a most- and least- 164 significant bit, and since we write numbers with the most- 165 significant digit on the left, we also write bytes with the most- 166 significant bit on the left. In the diagrams below, we number the 167 bits of a byte so that bit 0 is the least-significant bit, i.e., 168 the bits are numbered: 170 +--------+ 171 |76543210| 172 +--------+ 174 Within a computer, a number may occupy multiple bytes. All 175 multi-byte numbers in the format described here are stored with 176 the MOST-significant byte first (at the lower memory address). 177 For example, the decimal number 520 is stored as: 179 0 1 180 +--------+--------+ 181 |00000010|00001000| 182 +--------+--------+ 183 ^ ^ 184 | | 185 | + less significant byte = 8 186 + more significant byte = 2 x 256 188 2.2. Data format 190 A zlib stream has the following structure: 192 0 1 193 +---+---+ 194 |CMF|FLG| (more-->) 195 +---+---+ 197 (if FLG.FDICT set) 199 0 1 2 3 200 +---+---+---+---+ 201 | DICTID | (more-->) 202 +---+---+---+---+ 204 +=====================+---+---+---+---+ 205 |...compressed data...| ADLER32 | 206 +=====================+---+---+---+---+ 208 Any data which may appear after ADLER32 are not part of the zlib 209 stream. 211 Deutsch and Gailly [Page 4] 212 CMF (Compression Method and flags) 214 This byte is divided into a 4-bit compression method and a 4- 215 bit information field depending on the compression method. 217 bits 0 to 3 CM Compression method 218 bits 4 to 7 CINFO Compression info 220 CM (Compression method) 222 This identifies the compression method used in the file. CM = 8 223 denotes the 'deflate' compression method with a window size up 224 to 32K. This is the method used by gzip and PNG (see 225 references [1] and [2] in Chapter 3, below, for the reference 226 documents). CM = 15 is reserved. It might be used in a future 227 version of this specification to indicate the presence of an 228 extra field before the compressed data. 230 CINFO (Compression info) 232 For CM = 8, CINFO is the base-2 logarithm of the LZ77 window 233 size, minus eight (CINFO=7 indicates a 32K window size). Values 234 of CINFO above 7 are not allowed in this version of the 235 specification. CINFO is not defined in this specification for 236 CM not equal to 8. 238 FLG (FLaGs) 240 This flag byte is divided as follows: 242 bits 0 to 4 FCHECK (check bits for CMF and FLG) 243 bit 5 FDICT (preset dictionary) 244 bits 6 to 7 FLEVEL (compression level) 246 The FCHECK value must be such that CMF and FLG, when viewed as 247 a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG), 248 is a multiple of 31. 250 FDICT (Preset dictionary) 252 If FDICT is set, a DICT dictionary identifier is present 253 immediately after the FLG byte. The dictionary is a sequence of 254 bytes which are initially fed to the compressor without 255 producing any compressed output. DICT is the Adler-32 checksum 256 of this sequence of bytes (see the definition of ADLER32 257 below). The decompressor can use this identifier to determine 258 which dictionary has been used by the compressor. 260 FLEVEL (Compression level) 262 These flags are available for use by specific compression 263 methods. The 'deflate' method (CM = 8) sets these flags as 265 Deutsch and Gailly [Page 5] 266 follows: 268 0 - compressor used fastest algorithm 269 1 - compressor used fast algorithm 270 2 - compressor used default algorithm 271 3 - compressor used maximum compression, slowest algorithm 273 The information in FLEVEL is not needed for decompression; it 274 is there to indicate if recompression might be worthwhile. 276 compressed data 278 For compression method 8, the compressed data is stored in the 279 deflate compressed data format as described in the document 280 "'Deflate' Compressed Data Format Specification" by L. Peter 281 Deutsch. (See reference [3] in Chapter 3, below) 283 Other compressed data formats are not specified in this version 284 of the zlib specification. 286 ADLER32 (Adler-32 checksum) 288 This contains a checksum value of the uncompressed data 289 (excluding any dictionary data) computed according to Adler-32 290 algorithm. This algorithm is a 32-bit extension and improvement 291 of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 292 standard. See references [4] and [5] in Chapter 3, below) 294 Adler-32 is composed of two sums accumulated per byte: s1 is 295 the sum of all bytes, s2 is the sum of all s1 values. Both sums 296 are done modulo 65521. s1 is initialized to 1, s2 to zero. The 297 Adler-32 checksum is stored as s2*65536 + s1 in most- 298 significant-byte first (network) order. 300 2.3. Compliance 302 A compliant compressor must produce streams with correct CMF, FLG 303 and ADLER32, but need not support preset dictionaries. When the 304 zlib data format is used as part of another standard data format, 305 the compressor may use only preset dictionaries that are specified 306 by this other data format. If this other format does not use the 307 preset dictionary feature, the compressor must not set the FDICT 308 flag. 310 A compliant decompressor must check CMF, FLG, and ADLER32, and 311 provide an error indication if any of these have incorrect values. 312 A compliant decompressor must give an error indication if CM is 313 not one of the values defined in this specification (only the 314 value 8 is permitted in this version), since another value could 315 indicate the presence of new features that would cause subsequent 316 data to be interpreted incorrectly. A compliant decompressor must 317 give an error indication if FDICT is set and DICTID is not the 319 Deutsch and Gailly [Page 6] 320 identifier of a known preset dictionary. A decompressor may 321 ignore FLEVEL and still be compliant. When the zlib data format 322 is being used as a part of another standard format, a compliant 323 decompressor must support all the preset dictionaries specified by 324 the other format. When the other format does not use the preset 325 dictionary feature, a compliant decompressor must reject any 326 stream in which the FDICT flag is set. 328 3. References 330 [1] Deutsch, L.P.,"'Gzip' Compressed Data Format Specification". 331 available in ftp.uu.net:/pub/archiving/zip/doc/gzip-*.doc 333 [2] Thomas Boutell, "PNG (Portable Network Graphics) specification". 334 available in ftp://ftp.uu.net/graphics/png/png* 336 [3] Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". 337 available in ftp.uu.net:/pub/archiving/zip/doc/deflate-*.doc 339 [4] Fletcher, J. G., "An Arithmetic Checksum for Serial 340 Transmissions," IEEE Transactions on Communications, Vol. COM-30, No. 341 1, January 1982, pp. 247-252. 343 [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms," 344 November, 1993, pp. 144, 145. (Available from gopher://info.itu.ch). 345 ITU-T X.244 is also the same as ISO 8073. 347 4. Source code 349 Source code for a C language implementation of a 'zlib' compliant 350 library is available at ftp.uu.net:/pub/archiving/zip/zlib/zlib*. 352 5. Security considerations 354 A decoder that fails to check the ADLER32 checksum value may be 355 subject to undetected data corruption. 357 6. Acknowledgements 359 Trademarks cited in this document are the property of their 360 respective owners. 362 Jean-Loup Gailly and Mark Adler designed the zlib format and wrote 363 the related software described in this specification. Glenn 364 Randers-Pehrson converted this document to Internet Draft and HTML 365 format. 367 7. Authors' addresses L. Peter Deutsch 369 Aladdin Enterprises 370 203 Santa Margarita Ave. 371 Menlo Park, CA 94025 373 Deutsch and Gailly [Page 7] 374 Phone: (415) 322-0103 (AM only) 375 FAX: (415) 322-1734 376 EMail: 378 Jean-loup Gailly 380 EMail: 382 Questions about the technical content of this specification can be 383 sent by email to 385 Jean-loup Gailly and 386 Mark Adler 388 Editorial comments on this specification can be sent by email to 390 L. Peter Deutsch and 391 Glenn Randers-Pehrson 393 8. Appendix: Rationale 395 8.1. Preset dictionaries 397 A preset dictionary is specially useful to compress short input 398 sequences. The compressor can take advantage of the dictionary 399 context to encode the input in a more compact manner. The 400 decompressor can be initialized with the appropriate context by 401 virtually decompressing a compressed version of the dictionary 402 without producing any output. However for certain compression 403 algorithms such as the deflate algorithm this operation be 404 optimized without actually performing any decompression. 406 The compressor and the decompressor must use exactly the same 407 dictionary. The dictionary may be fixed or may be chosen among a 408 certain number of predefined dictionaries, according to the kind 409 of input data. The decompressor can determine which dictionary has 410 been chosen by the compressor by checking the dictionary 411 identifier. This document does not specify the contents of 412 predefined dictionaries, since the optimal dictionaries are 413 application specific. Standard data formats using this feature of 414 the zlib specification must precisely define the allowed 415 dictionaries. 417 8.2. The Adler-32 algorithm 419 The Adler-32 algorithm is much faster than the CRC32 algorithm yet 420 still provides an extremely low probability of undetected errors. 422 The modulo on unsigned long accumulators can be delayed for 5552 423 bytes, so the modulo operation time is negligible. If the bytes 424 are a, b, c, the second sum is 3a + 2b + c + 3, and so is position 425 and order sensitive, unlike the first sum, which is just a 427 Deutsch and Gailly [Page 8] 428 checksum. That 65521 is prime is important to avoid a possible 429 large class of two-byte errors that leave the check unchanged. 430 (The Fletcher checksum uses 255, which is not prime and which also 431 makes the Fletcher check insensitive to single byte changes 0 432 255.) 434 The sum s1 is initialized to 1 instead of zero to make the length 435 of the sequence part of s2, so that the length does not have to be 436 checked separately. (Any sequence of zeroes has a Fletcher 437 checksum of zero.) 439 9. Appendix: Sample code 441 The following C code computes the Adler-32 checksum of a data buffer. 442 It is written for clarity, not for speed. The sample code is in the 443 ANSI C programming language. Non C users may find it easier to read 444 with these hints: 446 & Bitwise AND operator. 447 >> Bitwise right shift operator. When applied to an 448 unsigned quantity, as here, right shift inserts zero bit(s) 449 at the left. 450 << Bitwise left shift operator. Left shift inserts zero 451 bit(s) at the right. 452 ++ "n++" increments the variable n. 453 % modulo operator: a % b is the remainder of a divided by b. 455 #define BASE 65521 /* largest prime smaller than 65536 */ 457 /* 458 Update a running Adler-32 checksum with the bytes buf[0..len-1] 459 and return the updated checksum. The Adler-32 checksum should be 460 initialized to 1. 462 Usage example: 464 unsigned long adler = 1L; 466 while (read_buffer(buffer, length) != EOF) { 467 adler = update_adler32(adler, buffer, length); 468 } 469 if (adler != original_adler) error(); 470 */ 471 unsigned long update_adler32(unsigned long adler, 472 unsigned char *buf, int len) 473 { 474 unsigned long s1 = adler & 0xffff; 475 unsigned long s2 = (adler >> 16) & 0xffff; 476 int n; 478 for (n = 0; n < len; n++) { 479 s1 = (s1 + buf[n]) % BASE; 481 Deutsch and Gailly [Page 9] 482 s2 = (s2 + s1) % BASE; 483 } 484 return (s2 << 16) + s1; 485 } 487 /* Return the adler32 of the bytes buf[0..len-1] */ 489 unsigned long adler32(unsigned char *buf, int len) 490 { 491 return update_adler32(1L, buf, len); 492 } 494 Deutsch and Gailly [Page 10]