idnits 2.17.00 (12 Aug 2021) /tmp/idnits52618/draft-deutsch-zlib-spec-02.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 (11 Mar 1996) is 9566 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. -------------------------------------------------------------------------------- 1 INTERNET-DRAFT L. Peter Deutsch 2 ZLIB 3.3 Aladdin Enterprises 3 Expires: 16 Sep 1996 Jean-Loup Gailly 4 Info-Zip 5 11 Mar 1996 7 ZLIB Compressed Data Format Specification version 3.3 9 File draft-deutsch-zlib-spec-02.txt 11 Status of this Memo 13 This document is an Internet-Draft. Internet-Drafts are working 14 documents of the Internet Engineering Task Force (IETF), its areas, 15 and its working groups. Note that other groups may also distribute 16 working documents as Internet-Drafts. 18 Internet-Drafts are draft documents valid for a maximum of six months 19 and may be updated, replaced, or obsoleted by other documents at any 20 time. It is inappropriate to use Internet- Drafts as reference 21 material or to cite them other than as ``work in progress.'' 23 To learn the current status of any Internet-Draft, please check the 24 ``1id-abstracts.txt'' listing contained in the Internet- Drafts 25 Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), 26 munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or 27 ftp.isi.edu (US West Coast). 29 Distribution of this memo is unlimited. 31 Notices 33 Copyright (c) 1996 L. Peter Deutsch and Jean-loup Gailly 35 Permission is granted to copy and distribute this document for any 36 purpose and without charge, including translations into other 37 languages and incorporation into compilations, provided that it is 38 copied as a whole (including the copyright notice and this notice) 39 and with no changes. 41 Deutsch and Gailly [Page 1] 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 50 not covered by patents. This specification also defines the ADLER-32 51 checksum (an extension and improvement of the Fletcher checksum), 52 used for detection of data corruption, and provides an algorithm for 53 computing it. 55 Table of Contents 57 1. Introduction ................................................... 2 58 1.1. Purpose ................................................... 2 59 1.2. Intended audience ......................................... 3 60 1.3. Scope ..................................................... 3 61 1.4. Compliance ................................................ 3 62 1.5. Definitions of terms and conventions used ................ 3 63 1.6. Changes from previous versions ............................ 3 64 2. Detailed specification ......................................... 4 65 2.1. Overall conventions ....................................... 4 66 2.2. Data format ............................................... 4 67 2.3. Compliance ................................................ 6 68 3. References ..................................................... 7 69 4. Source code .................................................... 7 70 5. Security considerations ........................................ 8 71 6. Acknowledgements ............................................... 8 72 7. Authors' addresses ............................................. 8 73 8. Appendix: Rationale ............................................ 8 74 9. Appendix: Sample code .......................................... 9 76 1. Introduction 78 1.1. Purpose 80 The purpose of this specification is to define a lossless 81 compressed data format that: 83 * Is independent of CPU type, operating system, file system, 84 and character set, and hence can be used for interchange; 86 * Can be produced or consumed, even for an arbitrarily long 87 sequentially presented input data stream, using only an a 88 priori bounded amount of intermediate storage, and hence can 89 be used in data communications or similar structures such as 90 Unix filters; 91 * Can use a number of different compression methods; 93 * Can be implemented readily in a manner not covered by 95 Deutsch and Gailly [Page 2] 96 patents, and hence can be practiced freely. 98 The data format defined by this specification does not attempt to 99 allow random access to compressed data. 101 1.2. Intended audience 103 This specification is intended for use by implementors of software 104 to compress data into zlib format and/or decompress data from zlib 105 format. 107 The text of the specification assumes a basic background in 108 programming at the level of bits and other primitive data 109 representations. 111 1.3. Scope 113 The specification specifies a compressed data format that can be 114 used for in-memory compression of a sequence of arbitrary bytes. 116 1.4. Compliance 118 Unless otherwise indicated below, a compliant decompressor must be 119 able to accept and decompress any data set that conforms to all 120 the specifications presented here; a compliant compressor must 121 produce data sets that conform to all the specifications presented 122 here. 124 1.5. Definitions of terms and conventions used 126 byte: 8 bits stored or transmitted as a unit (same as an octet). 127 (For this specification, a byte is exactly 8 bits, even on 128 machines which store a character on a number of bits different 129 from 8.) See below, for the numbering of bits within a byte. 131 1.6. Changes from previous versions 133 Version 3.1 was the first public release of this specification. 134 In version 3.2, some terminology was changed and the Adler-32 135 sample code was rewritten for clarity. In version 3.3, the 136 support for a preset dictionary was introduced, and the 137 specification was converted to Internet Draft style. 139 Deutsch and Gailly [Page 3] 140 2. Detailed specification 142 2.1. Overall conventions 144 In the diagrams below, a box like this: 146 +---+ 147 | | <-- the vertical bars might be missing 148 +---+ 150 represents one byte; a box like this: 152 +==============+ 153 | | 154 +==============+ 156 represents a variable number of bytes. 158 Bytes stored within a computer do not have a 'bit order', since 159 they are always treated as a unit. However, a byte considered as 160 an integer between 0 and 255 does have a most- and least- 161 significant bit, and since we write numbers with the most- 162 significant digit on the left, we also write bytes with the most- 163 significant bit on the left. In the diagrams below, we number the 164 bits of a byte so that bit 0 is the least-significant bit, i.e., 165 the bits are numbered: 167 +--------+ 168 |76543210| 169 +--------+ 171 Within a computer, a number may occupy multiple bytes. All 172 multi-byte numbers in the format described here are stored with 173 the MOST-significant byte first (at the lower memory address). 174 For example, the decimal number 520 is stored as: 176 0 1 177 +--------+--------+ 178 |00000010|00001000| 179 +--------+--------+ 180 ^ ^ 181 | | 182 | + less significant byte = 8 183 + more significant byte = 2 x 256 185 2.2. Data format 187 A zlib stream has the following structure: 189 Deutsch and Gailly [Page 4] 190 0 1 191 +---+---+ 192 |CMF|FLG| (more-->) 193 +---+---+ 195 (if FLG.FDICT set) 197 0 1 2 3 198 +---+---+---+---+ 199 | DICTID | (more-->) 200 +---+---+---+---+ 202 +=====================+---+---+---+---+ 203 |...compressed data...| ADLER32 | 204 +=====================+---+---+---+---+ 206 Any data which may appear after ADLER32 are not part of the zlib 207 stream. 209 CMF (Compression Method and flags) 210 This byte is divided into a 4-bit compression method and a 4- 211 bit information field depending on the compression method. 213 bits 0 to 3 CM Compression method 214 bits 4 to 7 CINFO Compression info 216 CM (Compression method) 217 This identifies the compression method used in the file. CM = 8 218 denotes the 'deflate' compression method with a window size up 219 to 32K. This is the method used by gzip and PNG (see 220 references [1] and [2] in Chapter 3, below, for the reference 221 documents). CM = 15 is reserved. It might be used in a future 222 version of this specification to indicate the presence of an 223 extra field before the compressed data. 225 CINFO (Compression info) 226 For CM = 8, CINFO is the base-2 logarithm of the LZ77 window 227 size, minus eight (CINFO=7 indicates a 32K window size). Values 228 of CINFO above 7 are not allowed in this version of the 229 specification. CINFO is not defined in this specification for 230 CM not equal to 8. 232 FLG (FLaGs) 233 This flag byte is divided as follows: 235 bits 0 to 4 FCHECK (check bits for CMF and FLG) 236 bit 5 FDICT (preset dictionary) 237 bits 6 to 7 FLEVEL (compression level) 239 The FCHECK value must be such that CMF and FLG, when viewed as 240 a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG), 241 is a multiple of 31. 243 Deutsch and Gailly [Page 5] 244 FDICT (Preset dictionary) 245 If FDICT is set, a DICT dictionary identifier is present 246 immediately after the FLG byte. The dictionary is a sequence of 247 bytes which are initially fed to the compressor without 248 producing any compressed output. DICT is the Adler-32 checksum 249 of this sequence of bytes (see the definition of ADLER32 250 below). The decompressor can use this identifier to determine 251 which dictionary has been used by the compressor. 253 FLEVEL (Compression level) 254 These flags are available for use by specific compression 255 methods. The 'deflate' method (CM = 8) sets these flags as 256 follows: 258 0 - compressor used fastest algorithm 259 1 - compressor used fast algorithm 260 2 - compressor used default algorithm 261 3 - compressor used maximum compression, slowest algorithm 263 The information in FLEVEL is not needed for decompression; it 264 is there to indicate if recompression might be worthwhile. 266 compressed data 267 For compression method 8, the compressed data is stored in the 268 deflate compressed data format as described in the document 269 "'Deflate' Compressed Data Format Specification" by L. Peter 270 Deutsch. (See reference [3] in Chapter 3, below) 272 Other compressed data formats are not specified in this version 273 of the zlib specification. 275 ADLER32 (Adler-32 checksum) 276 This contains a checksum value of the uncompressed data 277 (excluding any dictionary data) computed according to Adler-32 278 algorithm. This algorithm is a 32-bit extension and improvement 279 of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 280 standard. See references [4] and [5] in Chapter 3, below) 282 Adler-32 is composed of two sums accumulated per byte: s1 is 283 the sum of all bytes, s2 is the sum of all s1 values. Both sums 284 are done modulo 65521. s1 is initialized to 1, s2 to zero. The 285 Adler-32 checksum is stored as s2*65536 + s1 in most- 286 significant-byte first (network) order. 288 2.3. Compliance 290 A compliant compressor must produce streams with correct CMF, FLG 291 and ADLER32, but need not support preset dictionaries. When the 292 zlib data format is used as part of another standard data format, 293 the compressor may use only preset dictionaries that are specified 294 by this other data format. If this other format does not use the 295 preset dictionary feature, the compressor must not set the FDICT 297 Deutsch and Gailly [Page 6] 298 flag. 300 A compliant decompressor must check CMF, FLG, and ADLER32, and 301 provide an error indication if any of these have incorrect values. 302 A compliant decompressor must give an error indication if CM is 303 not one of the values defined in this specification (only the 304 value 8 is permitted in this version), since another value could 305 indicate the presence of new features that would cause subsequent 306 data to be interpreted incorrectly. A compliant decompressor must 307 give an error indication if FDICT is set and DICTID is not the 308 identifier of a known preset dictionary. A decompressor may 309 ignore FLEVEL and still be compliant. When the zlib data format 310 is being used as a part of another standard format, a compliant 311 decompressor must support all the preset dictionaries specified by 312 the other format. When the other format does not use the preset 313 dictionary feature, a compliant decompressor must reject any 314 stream in which the FDICT flag is set. 316 3. References 318 [1] Deutsch, L.P.,"'Gzip' Compressed Data Format Specification". 319 available in ftp.uu.net:/pub/archiving/zip/doc/gzip-*.doc 321 [2] Thomas Boutell, "PNG (Portable Network Graphics) specification". 322 available in ftp://ftp.uu.net/graphics/png/png* 324 [3] Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". 325 available in ftp.uu.net:/pub/archiving/zip/doc/deflate-*.doc 327 [4] Fletcher, J. G., "An Arithmetic Checksum for Serial 328 Transmissions," IEEE Transactions on Communications, Vol. COM-30, 329 No. 1, January 1982, pp. 247-252. 331 [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms," 332 November, 1993, pp. 144, 145. (Available from 333 gopher://info.itu.ch). ITU-T X.244 is also the same as ISO 8073. 335 4. Source code 337 Source code for a C language implementation of a 'zlib' compliant 338 library is available at ftp.uu.net:/pub/archiving/zip/zlib/zlib*. 340 Deutsch and Gailly [Page 7] 341 5. Security considerations 343 A decoder that fails to check the ADLER32 checksum value may be 344 subject to undetected data corruption. 346 6. Acknowledgements 348 Trademarks cited in this document are the property of their 349 respective owners. 351 Jean-Loup Gailly and Mark Adler designed the zlib format and wrote 352 the related software described in this specification. Glenn 353 Randers-Pehrson converted this document to Internet Draft and HTML 354 format. 356 7. Authors' addresses L. Peter Deutsch 358 Aladdin Enterprises 359 203 Santa Margarita Ave. 360 Menlo Park, CA 94025 362 Phone: (415) 322-0103 (AM only) 363 FAX: (415) 322-1734 364 EMail: 366 Jean-loup Gailly 368 EMail: 370 Questions about the technical content of this specification can be 371 sent by email to 373 Jean-loup Gailly and 374 Mark Adler 376 Editorial comments on this specification can be sent by email to 378 L. Peter Deutsch and 379 Glenn Randers-Pehrson 381 8. Appendix: Rationale 383 8.1. Preset dictionaries 385 A preset dictionary is specially useful to compress short input 386 sequences. The compressor can take advantage of the dictionary 387 context to encode the input in a more compact manner. The 388 decompressor can be initialized with the appropriate context by 389 virtually decompressing a compressed version of the dictionary 390 without producing any output. However for certain compression 391 algorithms such as the deflate algorithm this operation can be 392 achieved without actually performing any decompression. 394 Deutsch and Gailly [Page 8] 395 The compressor and the decompressor must use exactly the same 396 dictionary. The dictionary may be fixed or may be chosen among a 397 certain number of predefined dictionaries, according to the kind 398 of input data. The decompressor can determine which dictionary has 399 been chosen by the compressor by checking the dictionary 400 identifier. This document does not specify the contents of 401 predefined dictionaries, since the optimal dictionaries are 402 application specific. Standard data formats using this feature of 403 the zlib specification must precisely define the allowed 404 dictionaries. 406 8.2. The Adler-32 algorithm 408 The Adler-32 algorithm is much faster than the CRC32 algorithm yet 409 still provides an extremely low probability of undetected errors. 411 The modulo on unsigned long accumulators can be delayed for 5552 412 bytes, so the modulo operation time is negligible. If the bytes 413 are a, b, c, the second sum is 3a + 2b + c + 3, and so is position 414 and order sensitive, unlike the first sum, which is just a 415 checksum. That 65521 is prime is important to avoid a possible 416 large class of two-byte errors that leave the check unchanged. 417 (The Fletcher checksum uses 255, which is not prime and which also 418 makes the Fletcher check insensitive to single byte changes 0 419 255.) 421 The sum s1 is initialized to 1 instead of zero to make the length 422 of the sequence part of s2, so that the length does not have to be 423 checked separately. (Any sequence of zeroes has a Fletcher 424 checksum of zero.) 426 9. Appendix: Sample code 428 The following C code computes the Adler-32 checksum of a data buffer. 429 It is written for clarity, not for speed. The sample code is in the 430 ANSI C programming language. Non C users may find it easier to read 431 with these hints: 433 & Bitwise AND operator. 434 >> Bitwise right shift operator. When applied to an 435 unsigned quantity, as here, right shift inserts zero bit(s) 436 at the left. 437 << Bitwise left shift operator. Left shift inserts zero 438 bit(s) at the right. 439 ++ "n++" increments the variable n. 440 % modulo operator: a % b is the remainder of a divided by b. 442 #define BASE 65521 /* largest prime smaller than 65536 */ 444 Deutsch and Gailly [Page 9] 445 /* 446 Update a running Adler-32 checksum with the bytes buf[0..len-1] 447 and return the updated checksum. The Adler-32 checksum should be 448 initialized to 1. 450 Usage example: 452 unsigned long adler = 1L; 454 while (read_buffer(buffer, length) != EOF) { 455 adler = update_adler32(adler, buffer, length); 456 } 457 if (adler != original_adler) error(); 458 */ 459 unsigned long update_adler32(unsigned long adler, 460 unsigned char *buf, int len) 461 { 462 unsigned long s1 = adler & 0xffff; 463 unsigned long s2 = (adler >> 16) & 0xffff; 464 int n; 466 for (n = 0; n < len; n++) { 467 s1 = (s1 + buf[n]) % BASE; 468 s2 = (s2 + s1) % BASE; 469 } 470 return (s2 << 16) + s1; 471 } 473 /* Return the adler32 of the bytes buf[0..len-1] */ 475 unsigned long adler32(unsigned char *buf, int len) 476 { 477 return update_adler32(1L, buf, len); 478 } 480 Deutsch and Gailly [Page 10]