ZipCrc32Cryptograph.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive library source distribution and
3 // is Copyrighted 2000 - 2013 by Artpol Software - Tadeusz Dracz
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // For the licensing details refer to the License.txt file.
11 //
12 // Web Site: http://www.artpol-software.com
14 
21 #if !defined(ZIPARCHIVE_ZIPCRC32CRYPTOGRAPH_DOT_H)
22 #define ZIPARCHIVE_ZIPCRC32CRYPTOGRAPH_DOT_H
23 
24 #if _MSC_VER > 1000
25  #pragma once
26 #endif
27 
28 #include "zlib/zlib.h"
29 
30 #include "ZipCryptograph.h"
31 #include "ZipFileHeader.h"
32 #include "ZipStorage.h"
33 
34 
35 #define ZIPARCHIVE_ENCR_HEADER_LEN 12
36 
43 class ZIP_API CZipCrc32Cryptograph : public CZipCryptograph
44 {
45 public:
47 
48  bool InitDecode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage, bool ignoreCheck);
49  void InitEncode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage);
50  void Decode(char* pBuffer, DWORD uSize)
51  {
52  for (DWORD i = 0; i < uSize; i++)
53  CryptDecode(pBuffer[i]);
54  }
55  void Encode(char* pBuffer, DWORD uSize)
56  {
57  for (DWORD i = 0; i < uSize; i++)
58  CryptEncode(pBuffer[i]);
59  }
60 
61  bool CanHandle(int iEncryptionMethod)
62  {
63  return iEncryptionMethod == CZipCryptograph::encStandard;
64  }
65 
70  {
71  return ZIPARCHIVE_ENCR_HEADER_LEN;
72  }
73 
78  {
79  return 0;
80  }
81 
85  static const z_crc_t* GetCRCTable()
86  {
87  return zarch_get_crc_table();
88  }
89 private:
90 
91  void CryptDecode(char &c)
92  {
93  c ^= CryptDecryptByte();
94  CryptUpdateKeys(c);
95  }
96 
97  char CryptDecryptByte()
98  {
99  int temp = (m_keys[2] & 0xffff) | 2;
100  return (char)(((temp * (temp ^ 1)) >> 8) & 0xff);
101  }
102  void CryptInitKeys(CZipAutoBuffer& password);
103  void CryptUpdateKeys(char c);
104  DWORD CryptCRC32(DWORD l, char c)
105  {
106  const z_crc_t* CRC_TABLE = zarch_get_crc_table();
107  return (DWORD)CRC_TABLE[(l ^ c) & 0xff] ^ (l >> 8);
108  }
109  void CryptEncode(char &c)
110  {
111  char t = CryptDecryptByte();
112  CryptUpdateKeys(c);
113  c ^= t;
114  }
115  DWORD m_keys[3];
116 public:
118 };
119 
120 #endif

The ZipArchive Library Copyright © 2000 - 2013 Artpol Software - Tadeusz Dracz. Generated at Fri Dec 13 2013 00:05:37.