home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / library / hack / zip-attack.txt / zip-attack.txt
Text File  |  1998-03-25  |  26KB  |  582 lines

  1.  
  2. If you have PostScript printer and/or GNU GhostScript (available free
  3. via FTP), the PostScript version of this paper will look nicer and
  4. will include the graph accompanying with Figure 1.
  5.  
  6. Superscripts and subscripts are in pseudo-Latex format, where a
  7. superscript b is denoted a^{b} and a subscript b is a_{b}.
  8.  
  9. The paper will appear in the proceedings of the December 1994
  10. Algorithms workshop held in Leuven, Belgium (which presumably
  11. will be printed by Springer-Verlag).
  12.  
  13. Cheers,
  14. Paul Kocher
  15. kocherp@leland.stanford.edu
  16.  
  17. ----------------------------------------------------------------------------
  18.  
  19.  
  20.  
  21.          A Known Plaintext Attack on the PKZIP Stream Cipher
  22.  
  23.                 Eli Biham (*)    Paul C. Kocher (**)
  24.  
  25.  
  26. (*)   Computer Science Department, Technion - Israel Institute of
  27.             Technology, Haifa 32000, Israel.
  28.  
  29. (**)  Independent cryptographic consultant, 7700 N.W. Ridgewood Dr.,
  30.             Corvallis, OR 97330, USA.  (415) 354-8004.
  31.  
  32.  
  33.  
  34. ABSTRACT:
  35.  
  36. The PKZIP program is one of the more widely used archive/compression
  37. programs on personal computers.  It also has many compatible variants
  38. on other computers, and is used by most BBS's and ftp sites to
  39. compress their archives.  PKZIP provides a stream cipher which allows
  40. users to scramble files with variable length keys (passwords).  In
  41. this paper we describe a known plaintext attack on this cipher, which
  42. can find the internal representation of the key within a few hours on
  43. a personal computer using a few hundred bytes of known plaintext.  In
  44. many cases, the actual user keys can also be found from the internal
  45. representation.  We conclude that the PKZIP cipher is weak, and
  46. should not be used to protect valuable data.
  47.  
  48.  
  49.  
  50. SECTION 1:  Introduction
  51.  
  52. The PKZIP program is one of the more widely used archive/compression
  53. programs on personal computers.  It also has many compatible variants
  54. on other computers (such as Infozip's zip/unzip), and is used by most
  55. BBS's and ftp sites to compress their archives.  PKZIP provides a
  56. stream cipher which allows users to scramble the archived files under
  57. variable length keys (passwords).  This stream cipher was designed by
  58. Roger Schlafly.
  59.  
  60.       In this paper we describe a known plaintext attack on the PKZIP
  61. stream cipher which takes a few hours on a personal computer and
  62. requires about 13--40 (compressed) known plaintext bytes, or the
  63. first 30--200 uncompressed bytes, when the file is compressed.  The
  64. attack primarily finds the 96-bit internal representation of the key,
  65. which suffices to decrypt the whole file and any other file encrypted
  66. under the same key.  Later, the original key can be constructed.
  67. This attack was used to find the key of the PKZIP contest.
  68.  
  69.       The analysis in this paper holds to both versions of PKZIP:
  70. version 1.10 and version 2.04g.  The ciphers used in the two versions
  71. differ in minor details, which does not affect the analysis.
  72.  
  73.       The structure of this paper is as follows: Section 2 describes
  74. PKZIP and the PKZIP stream cipher.  The attack is described in
  75. Section 3, and a summary of the results is given in Section 4.
  76.  
  77.  
  78.  
  79. SECTION 2:  The PKZIP Stream Cipher
  80.  
  81. PKZIP manages a ZIP file[1] which is an archive containing many files
  82. in a compressed form, along with file headers describing (for each
  83. file) the file name, the compression method, whether the file is
  84. encrypted, the CRC-32 value, the original and compressed sizes of the
  85. file, and other auxiliary information.
  86.  
  87.       The files are kept in the zip-file in the shortest form
  88. possible of several compression methods.  In case that the
  89. compression methods do not shrink the size of the file, the files are
  90. stored without compression.  If encryption is required, 12 bytes
  91. (called the _encryption_header_) are prepended to the compressed
  92. form, and the encrypted form of the result is kept in the zip-file.
  93. The 12 prepended bytes are used for randomization, but also include
  94. header dependent data to allow identification of wrong keys when
  95. decrypting.  In particular, in PKZIP 1.10 the last two bytes of these
  96. 12 bytes are derived from the CRC-32 field of the header, and many of
  97. the other prepended bytes are constant or can be predicted from other
  98. values in the file header.  In PKZIP 2.04g, only the last byte of
  99. these 12 bytes is derived from the CRC-32 field.  The file headers
  100. are not encrypted in both versions.
  101.  
  102.       The cipher is byte-oriented, encrypting under variable length
  103. keys.  It has a 96-bit internal memory, divided into three 32-bit
  104. words called key0, key1 and key2.  An 8-bit variable key3 (not part
  105. of the internal memory) is derived from key2.  The key initializes
  106. the memory: each key has an equivalent internal representation as
  107. three 32-bit words.  Two keys are equivalent if their internal
  108. representations are the same.  The plaintext bytes update the memory
  109. during encryption.
  110.  
  111.       The main function of the cipher is called update_keys, and is
  112. used to update the internal memory and to derive the variable key3,
  113. for each given input (usually plaintext) byte:
  114.  
  115. update_keys_{i} (char):
  116.   local unsigned short temp
  117.   key0_{i+1} <-- crc32(key0_{i},char)
  118.   key1_{i+1} <-- (key1_{i} + LSB(key0_{i+1})) * 134775813 + 1 (mod 2^{32})
  119.   key2_{i+1} <-- crc32(key2_{i},MSB(key1_{i+1}))
  120.   temp_{i+1} <-- key2_{i+1} | 3    (16 LS bits)
  121.   key3_{i+1} <-- LSB((temp_{i+1} * (temp_{i+1} xor 1)) >> 8)
  122. end update_keys
  123.  
  124. where | is the binary inclusive-or operator, and >> denotes the right
  125. shift operator (as in the C programming language).  LSB and MSB
  126. denote the least significant byte and the most significant byte of
  127. the operands, respectively.  Note that the indices are used only for
  128. future references and are not part of the algorithm, and that the
  129. results of key3 using inclusive-or with 3 in the calculation of temp
  130. are the same as with the original inclusive-or with 2 used in the
  131. original algorithm.  We prefer this notation in order to reduce one
  132. bit of uncertainty about temp in the following discussion.
  133.  
  134.       Before encrypting, the key (password) is processed to update
  135. the initial value of the internal memory by:
  136.  
  137. process_keys(key):
  138.   key0_{1-l} <-- 0x12345678
  139.   key1_{1-l} <-- 0x23456789
  140.   key2_{1-l} <-- 0x34567890
  141.   loop for i <-- 1 to l
  142.     update_keys_{i-l}(key_{i})
  143.   end loop
  144. end process_keys
  145.  
  146. where l is the length of the key (in bytes) and hexadecimal numbers
  147. are prefixed by 0x (as in the C programming language).  After
  148. executing this procedure, the internal memory contains the internal
  149. representation of the key, which is denoted by key0_{1}, key1_{1} and
  150. key2_{1}.
  151.  
  152.       The encryption algorithm itself processes the bytes of the
  153. compressed form along with the prepended 12 bytes by:
  154.  
  155.       Encryption                      Decryption
  156.       ----------                      ----------
  157.       prepend P_{1},...,P_{12}
  158.       loop for i <-- 1 to n           loop for i <-- 1 to n
  159.         C_{i} <-- P_{i} xor key3_{i}    P_{i} <-- C_{i} xor key3_{i}
  160.         update_keys_{i}(P_{i})        update_keys_{i}(P_{i})
  161.       end loop                        discard P_{1},...,P_{12}
  162.  
  163. The decryption process is similar, except that it discards the 12
  164. prepended bytes.
  165.  
  166.       The crc32 operation takes a previous 32-bit value and a byte,
  167. XORs them and calculates the next 32-bit value by the crc polynomial
  168. denoted by 0xEDB88320.  In practice, a table crctab can be
  169. precomputed, and the crc32 calculation becomes:
  170.  
  171. crc32 = crc32(pval,char) = (pval>>8) xor crctab[LSB(pval) xor char]
  172.  
  173. The crc32 equation is invertible in the following sense:
  174.  
  175. pval = crc32^{-1}(crc32,char) =
  176.       (crc32 << 8) xor crcinvtab[MSB(crc32)] xor char
  177.  
  178. crctab and crcinvtab are precomputed as:
  179.  
  180. init_crc():
  181.   local unsigned long temp
  182.   loop for i <-- 0 to 255
  183.   temp <-- crc32(0,i)
  184.     crctab[i] <-- temp
  185.     crcinvtab[temp >> 24] <-- (temp << 8) xor i
  186.   end loop
  187. end init_crc
  188.  
  189. in which crc32 refers to the original definition of crc32:
  190.  
  191. crc32(temp,i):
  192.   temp <-- temp xor i
  193.   loop for j <-- 0 to 7
  194.     if odd(temp) then
  195.       temp <-- temp >> 1 xor 0xEDB88320
  196.     else
  197.       temp <-- temp >> 1
  198.     endif
  199.   end loop
  200.   return temp
  201. end crc32
  202.  
  203.  
  204. SECTION 3:  The Attack
  205.  
  206. The attack we describe works even if the known plaintext bytes are
  207. not the first bytes (if the file is compressed, it needs the
  208. compressed bytes, rather than the uncompressed bytes).  In the
  209. following discussion the subscripts of the n known plaintext bytes
  210. are denoted by 1,...,n, even if the known bytes are not the first
  211. bytes.  We ignore the subscripts when the meaning is clear and the
  212. discussion holds for all the indices.
  213.  
  214.       Under a known plaintext attack, both the plaintext and the
  215. ciphertext are known.  In the PKZIP cipher, given a plaintext byte
  216. and the corresponding ciphertext byte, the value of the variable key3
  217. can be calculated by
  218.  
  219.                    key3_{i} = P_{i} xor C_{i}.
  220.  
  221. Given P_{1},...,P_{n} and C_{1},...,C_{n}, we receive the values of
  222. key3_{1},...,key3_{n}.  The known plaintext bytes are the inputs of
  223. the update_keys function, and the derived key3's are the outputs.
  224. Therefore, in order to break the cipher, it suffices to solve the set
  225. of equations derived from update_keys, and find the initial values of
  226. key0, key1 and key2.
  227.  
  228. In the following subsections we describe how we find many possible
  229. values for key2, then how we extend these possible values to possible
  230. values of key1, and key0, and how we discard all the wrong values.
  231. Then, we remain with only the right values which correspond to the
  232. internal representation of the key.
  233.  
  234. Subsection 3.1:  key2
  235.  
  236. The value of key3 depends only on the 14 bits of key2 that
  237. participate in temp.  Any value of key3 is suggested by exactly 64
  238. possible values of temp (and thus 64 possible values of the 14 bits
  239. of key2).  The two least significant bits of key2 and the 16 most
  240. significant bits do not affect key3 (neither temp).
  241.  
  242. Given the 64 possibilities of temp in one location of the encrypted
  243. text, we complete the 16 most significant bits of key2 with all the
  244. 2^{16} possible values, and get 2^{22} possible values for the 30
  245. most significant bits of key2.  key2_{i+1} is calculated by
  246. key2_{i+1} <-- crc32(key2_{i},MSB(key1_{i+1})).  Thus,
  247.  
  248.       key2_{i} = crc32^{-1}(key2_{i+1},MSB(key1_{i+1}))
  249.                = (key2_{i+1}<<8) xor crcinvtab[MSB(key2_{i+1})]
  250.                        xor MSB(key1_{i+1}).
  251.  
  252. Given any particular value of key2_{i+1}, for each term of this
  253. equation we can calculate the value of the 22 most significant bits
  254. of the right hand side of the equation, and we know 64 possibilities
  255. for the value of 14 bits of the left hand side, as described in Table
  256. 1.  From the table, we can see that six bits are common to the right
  257. hand side and the left hand side.  Only about 2^{-6} of the possible
  258. values of the 14 bits of key2_{i} have the same value of the common
  259. bits as in the right hand side, and thus, we remain with only one
  260. possible value of the 14 bits of key2_{i} in average, for each
  261. possible value of the 30 bits of key2_{i+1}.  When this equation
  262. holds, we can complete additional bits of the right and the left
  263. sides, up to the total of the 30 bits known in at least one of the
  264. sides.  Thus, we can deduce the 30 most significant bits of key2_{i}.
  265. We get in average one value for these 30 most significant bits of
  266. key2_{i}, for each value of the 30 most significant bits of
  267. key2_{i+1}.  Therefore, we are now just in the same situation with
  268. key2_{i} as we were before with key2_{i+1}, and we can now find
  269. values of 30 bits of key2_{i-1}, key2_{i-2},...,key2_{1}.  Given this
  270. list of 30-bit values, we can complete the 32-bit values of key2_{n},
  271. key2_{n-1},...,key2_{2} (excluding key2_{1}) using the same equation.
  272. We remain with about 2^{22} lists of possible values
  273. (key2_{n},key2_{n-1},...,key2_{2}), of which one must be the list
  274. actually calculated during encryption.
  275.  
  276.  
  277. Table 1:
  278.  
  279.   Side  Term                          Bits#  BitsPosition  #OfValues
  280.   ------------------------------------------------------------------
  281.   Left  key2_{i}                        14      2-15          64
  282.   Right key2_{i+2} << 8                 22     10-31           1
  283.         crcinvtab[MSB(key2_{i+1})]      32      0-31           1
  284.         MSB(key1_{i+1})                 24      8-31           1
  285.   ------------------------------------------------------------------
  286.   Total Left Hand Side                  14      2-15          64
  287.   Total RIght Hand Side                 22     10-31           1
  288.   ------------------------------------------------------------------
  289.   Common bits                            6     10-15
  290.   Total bits                            30      2-31
  291.  
  292.  
  293.  
  294. Subsection 3.2:  Reducing the number of possible values of key2
  295.  
  296. The total complexity of our attack is (as described later) 2^{16}
  297. times the number of possible lists of key2's.  If we remain with
  298. 2^{22} lists, the total complexity becomes 2^{38}.  This complexity
  299. can be reduced if we can reduce the number of lists of key2's without
  300. discarding the right list.
  301.  
  302.       We observed that the attack requires only 12--13 known
  303. plaintext bytes (as we describe later).  Our idea is to use longer
  304. known plaintext streams, and to reduce the number of lists based on
  305. the additional plaintext.  In particular, we are interested only in
  306. the values of key2_{13}, and not in all the list of key2_{i},
  307. i=13,...,n.  key2_{13} is then used in the attack as is described
  308. above.
  309.  
  310. We start with the 2^{22} possible values of key2_{n}, and calculate
  311. the possible values of key2_{n-1}, key2_{n-2}, etc. using Equation 1.
  312. The number of possible values of key2_{i} (i=n-1, n-2, etc.) remains
  313. about 2^{22}.  However, some of the values are duplicates of other
  314. values.  When these duplicates are discarded, the number of possible
  315. values of key2_{i} is substantially decreased.  To speed things up,
  316. we calculate all the possible values of key2_{n-1}, and remove the
  317. duplicates.  Then we calculate all the possible values of key2_{n-2},
  318. and remove the duplicates, and so on.  When the duplicates fraction
  319. becomes smaller, we can remove the duplicates only every several
  320. bytes, to save overhead.  Figure 1 shows the number of remaining
  321. values for any given size of known plaintext participating in the
  322. reduction, as was measured on the PKZIP contest file (which is
  323. typical).  We observed that using about 40 known plaintext bytes (28
  324. of them are used for the reduction and 12 for the attack), the number
  325. of possible values of key2_{13} is reduced to about 2^{18}, and the
  326. complexity of the attack is 2^{34}.  Using 10000-byte known
  327. plaintext, the complexity of our attack is reduced to 2^{24}--2^{27}.
  328.  
  329.  
  330. Figure 1:
  331.  
  332.       bytes     key2 list entries
  333.         1      2^{22}=4194304
  334.         2             3473408
  335.         3             2152448         +-----------------------------+
  336.         4             1789183         | The PostScript version of   |
  337.         5             1521084         | the paper has a graph here  |
  338.        10              798169         | showing the number of key2  |
  339.        15              538746         | values as a function of the |
  340.        20              409011         | number of plaintext bytes.  |
  341.        25              332606         +-----------------------------+
  342.        30              283930
  343.        40              213751
  344.        50              174471
  345.       100               88248
  346.       200               43796
  347.       300               31088
  348.       500               16822
  349.      1000                7785
  350.      2000                5196
  351.      4000                3976
  352.      6000                3000
  353.      8000                1296
  354.     10000                1857
  355.     12000                 243
  356.     12289                 801
  357.  
  358.     Fig 1.  Decrease in the number of key2 candidates using varying
  359.     amounts of known plaintext.  These results are for the PKZIP
  360.     contest file and are fairly typical, though the entry 12000 is
  361.     unusually low.
  362.  
  363.  
  364. Subsection 3.3:  key1
  365.  
  366. From the list of (key2_{n}, key2_{n-1},...,key2_{2}) we can calculate
  367. the values of the most significant bytes the key1's by
  368.  
  369.       MSB(key1_{i+1}) =
  370.        (key2_{i+1} << 8) xor crcinvtab[MSB(key2_{i+1})] xor key2_{i}.
  371.  
  372. !!!
  373.  
  374. We receive the list (MSB(key1_{n}),MSB(key1_{n-1}),...,MSB(key1_{3}))
  375. (excluding MSB(key1_{2})).
  376.  
  377.       Given MSB(key1_{n}) and MSB(key1_{n-1}), we can calculate about
  378. 2^{16} values for the full values of key1_{n} and
  379. key1_{n-1}+LSB(key0_{n}).  This calculation can be done efficiently
  380. using lookup tables of size 256--1024.  Note that
  381.  
  382.       key1_{n-1}+LSB(key0_{n}) =
  383.         (key1_{n}-1) * 134775813^{-1} (mod 2^{32})
  384.  
  385. and that LSB(key0_{n}) is in the range 0,...,255. At this point we
  386. have about 2^{11} * 2^{16} = 2^{27} (or 2^{22} * 2^{16} = 2^{38})
  387. possible lists of key2's and key1_{n}. Note that in the remainder of
  388. the attack no additional complexity is added, and all the additional
  389. operations contain a fixed number of instructions for each of the
  390. already existing list.
  391.  
  392.       The values of key1_{n-1}+LSB(key0_{n}) are very close to the
  393. values of key1_{n-1} (since we lack only the 8-bit value
  394. LSB(key0_{n})). Thus, an average of only 256 * 2^{-8} = 1 possible
  395. value of key1_{n-1} that leads to the most significant byte of
  396. key1_{n-2} from the list. This value can be found efficiently using
  397. the same lookup tables used for finding key1_{n}, with only a few
  398. operations. Then, we remain with a similar situation, in which
  399. key1_{n-1} is known and we lack only eight bits of key1_{n-2}. We
  400. find key1_{n-2} with the same algorithm, and then find the rest of
  401. key1_{n-3}, key1_{n-4}, and so on with the same algorithm. We result
  402. with about 2^{27} possible lists, each containing the values of
  403. (key2_{n}, key2_{n-1},...,key2_{2}, and key1_{n}, key1_{n-
  404. 1},...,key1_{4}) (again, key1_{3} cannot be fully recovered since two
  405. successive values of MSB(key1) are required to find each value of
  406. key1).
  407.  
  408.  
  409. Subsection 3.4:
  410.  
  411. Given a list of (key1_{n}, key1_{n-1},...,key1_{4}), we can easily
  412. calculate the values of the least significant bytes of (key0_{n},
  413. key0_{n-1},...,key0_{5}) by
  414.  
  415.       LSB(key0_{i+1}) =
  416.         ((key1_{i+1}-1) * 134775813^{-1})-key1_{i}   (mod 2^{32}).
  417.  
  418. key0_{i+1} is calculated by
  419.  
  420.       key0_{i+1} <-- crc32(key0_{i},P_{i})
  421.         = (key0_{i} >> 8) xor crctab[LSB(key0_{i}) xor P_{i}].
  422.  
  423. Crc32 is a linear function, and from any four consecutive LSB(key0)
  424. values, together with the corresponding known plaintext bytes it is
  425. possible to recover the full four key0's. Moreover, given one full
  426. key0, it is possible to reconstruct all the other key0's by
  427. calculating forward and backward, when the plaintext bytes are given.
  428. Thus, we can now receive key0_{n},...,key0_{1} (this time including
  429. key0_{1}). We can now compare the values of the least significant
  430. bytes of key0_{n-4},...,key0_{n-7} to the corresponding values from
  431. the lists. Only a fraction of 2^{-32} of the lists satisfy the
  432. equality. Since we have only about 2^{27} possible lists, it is
  433. expected that only one list remain. This list must have the right
  434. values of the key0's, key1's, and key2's, and in particular the right
  435. values of key0_{n}, key1_{n} and key2_{n}. In total we need 12 known
  436. plaintext bytes for this analysis (except for reducing the number of
  437. key2 lists) since in the lists the values of LSB(key0_{i}) start with
  438. i=5, and n-7=5 ==> n=12.
  439.  
  440. If no reduction of the number of key2 lists is performed, 2^{38}
  441. lists  of (key0, key1, key2) remain at this point, rather than
  442. 2^{27}.  Thus, we need to compare five bytes
  443. key0_{n-4},...,key0_{n-8} in order to remain with only one list.  In
  444. this case, 13 known plaintext bytes are required for the whole
  445. attack, and the complexity of analysis is 2^{38}.
  446.  
  447. Subsection 3.5:  The Internal Representation of the Key
  448.  
  449. Given key0_{n}, key1_{n} and key2_{n}, it is possible to construct
  450. key0_{i}, key1_{i} and key2_{i} for any i<n using only the ciphertext
  451. bytes, without using the known plaintext, and even if the known
  452. plaintext starts in the middle of the encrypted file this
  453. construction works and provides also the unknown plaintext and the 12
  454. prepended bytes.  In particular it can find the internal
  455. representation of the key, denoted by key0_{1}, key1_{1} and key2_{1}
  456. (where the index denotes again the index in the encrypted text,
  457. rather than in the known plaintext).  The calculation is as follows:
  458.  
  459. (Equation 2)
  460.  
  461.   key2_{i} = crc32^{-1}(key2_{i+1},MSB(key1_{i+1}))
  462.   key1_{i} = ((key1_{i+1}-1) * 134775813^{-1}) -
  463.                   LSB(key0_{i+1})  (mod 2^32)
  464.   temp_{i} = key2_{i} | 3
  465.   key3_{i} = LSB((temp_{i} * (temp_{i} xor 1)) >> 8)
  466.      P_{i} = C_{i} xor key3_{i}
  467.   key0_{i} = crc32(key0_{i+1},P_{i})
  468.  
  469. The resulting value of (key0_{1},key1_{1},key2_{1}) is the internal
  470. representation of the key.  It is independent of the plaintext and
  471. the prepended bytes, and depends only on the key.  With this internal
  472. representation of the key we can decrypt any ciphertext encrypted
  473. under the same key.  The two bytes of crc32 (one byte in version
  474. 2.04g) which are included in the 12 prepended bytes allow further
  475. verification that the file is really encrypted under the found
  476. internal representation of the key.
  477.  
  478.  
  479. Subsection 3.6:  The Key (Password)
  480.  
  481. The internal representation of the key suffices to break the cipher.
  482. However, we can go even further and find the key itself from this
  483. internal representation with the complexities summarized in Table 2.
  484. The algorithm tries all key lengths 0, 1, 2, ..., up to some maximal
  485. length; for each key length it does as described in the following
  486. paragraphs.
  487.  
  488.  
  489. Table 2:  Complexity of finding the key itself
  490.  
  491.   -----------------------------------------------------------------
  492.   Key length    1-6   7     8      9     10     11     12     13
  493.   Complexity     1  2^{8} 2^{16} 2^{24} 2^{32} 2^{40} 2^{48} 2^{56}
  494.   -----------------------------------------------------------------
  495.  
  496. For l <= 4 it knows key0_{1-l} and key0_{1}.  Only l <= 4 key bytes
  497. are entered to the crc32 calculations that update key0_{1-l} into
  498. key0_{1}.  Crc32 is a linear function, and these l <= 4 key bytes can
  499. be recovered, just as key0_{n},...,key0_{n-3} recovered above.  Given
  500. the l key bytes, we reconstruct the internal representation, and
  501. verify that we get key1_{1} and key2_{1} as expected (key0_{1} must
  502. be as expected, due to the construction).  If the verification
  503. succeeds, we found the key (or an equivalent key).  Otherwise, we try
  504. the next key length.
  505.  
  506. For 5 <= l <= 6 we can calculate key1_{0}, key2_{0} and key2_{-1}, as
  507. in Equation 2.  Then, key2_{2-l},...,key2_{-2} can be recovered since
  508. they are also calculated with crc32, and depend on l-2 <= 4 unknown
  509. bytes (of key1's).  These unknown bytes MSB(key1_{2-l}),...,
  510. MSB(key1_{-1}) are also recovered at the same time.  key1_{1-l} is
  511. known.  Thus, we can receive an average of one possible value for
  512. key1_{2-l} and for key1_{3-l}, together with LSB(key0_{2-l}) and
  513. LSB(key0_{3-l}), using the same lookup tables used in the attack.
  514. From LSB(key0_{2-l}) and LSB(key0_{3-l}) and key0_{1-l}, we can
  515. complete key0_{2-l} and key0_{3-l} and get key_{1} and key_{2}.  The
  516. remaining l-2 key bytes are found by solving the l-2 <= 4 missing
  517. bytes of the crc32 as is done for the case of l <= 4.  Finally, we
  518. verify that the received key has the expected internal
  519. representation.  If so, we have found the key (or an equivalent key).
  520. Otherwise, we try the next key length.
  521.  
  522. For l>6, we try all the possible values of key_{1},...,key_{l-6},
  523. calculating key0_{-5}, key1_{-5} and key2_{-5}.  Then we used the l=6
  524. algorithm to find the remaining six key bytes.  In total we try about
  525. 2^{8 * (l-6)} keys.  Only a fraction of 2^{-64} of them pass the
  526. verification (2^{-32} due to each of key1 and key2).  Thus, we expect
  527. to remain with only the right key (or an equivalent) in trials of up
  528. to 13-byte keys.  Note that keys longer than 12 bytes will almost
  529. always have equivalents with up to 12 (or sometimes 13) bytes, since
  530. the internal representation is only 12-bytes long.
  531.  
  532.  
  533. SECTION 4:  Summary
  534.  
  535. In this paper we describe a new attack on the PKZIP stream cipher
  536. which finds the internal representation of the key, which suffices to
  537. decrypt the whole file and any other file which is encrypted by the
  538. same key.  This known plaintext attack breaks the cipher using 40
  539. (compressed) known plaintext bytes, or about the 200 first
  540. uncompressed bytes (if the file is compressed), with complexity
  541. 2^{34}.  Using about 10000 known plaintext bytes, the complexity is
  542. reduced to about 2^{27}.  Table 3 describes the complexity of the
  543. attack for various sizes of known plaintext.  The original key
  544. (password) can be constructed from the internal representation.  An
  545. implementation of this attack in software was applied against the
  546. PKZIP cipher contest.  It found the key "f7 30 69 89 77 b1 20" (in
  547. hexadecimal) within a few hours on a personal computer.
  548.  
  549.  
  550. Table 3:  Complexity of the attack by the size of the known plaintext
  551.  
  552.             Bytes      Complexity
  553.           -------      ----------
  554.                13        2^{38}
  555.                40        2^{34}
  556.               110        2^{32}
  557.               310        2^{31}
  558.               510        2^{30}
  559.              1000        2^{29}
  560.              4000        2^{28}
  561.             10000        2^{27}
  562.  
  563.  
  564. A variant of the attack requires only 13 known plaintext bytes, in
  565. price of a higher complexity 2^{38}.  Since the last two bytes (one
  566. in version 2.04g) of the 12 prepended bytes are always known, if the
  567. known plaintext portion of the file is in its beginning, the attack
  568. requires only 11 (12) known plaintext bytes of the compressed file.
  569. (In version 1.10 several additional prepended bytes might be
  570. predictable, thus the attack might actually require even fewer known
  571. plaintext bytes.)
  572.  
  573. We conclude that the PKZIP cipher is weak and that it should not be
  574. used to protect valuable information.
  575.  
  576.  
  577. [1] PKWARE, Inc., General Format of a ZIP File, technical note,
  578.       included in PKZIP 1.10 distribution (pkz110.exe: file
  579.       appnote.txt).
  580.  
  581.  
  582.