00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00021 #if !defined(ZIPARCHIVE_ZIPCRC32CRYPTOGRAPH_DOT_H)
00022 #define ZIPARCHIVE_ZIPCRC32CRYPTOGRAPH_DOT_H
00023
00024 #if _MSC_VER > 1000
00025 #pragma once
00026 #endif
00027
00028 #include "zlib/zlib.h"
00029
00030 #include "ZipCryptograph.h"
00031 #include "ZipFileHeader.h"
00032 #include "ZipStorage.h"
00033
00034
00035 #define ZIPARCHIVE_ENCR_HEADER_LEN 12
00036
00043 class ZIP_API CZipCrc32Cryptograph : public CZipCryptograph
00044 {
00045 public:
00046 CZipCrc32Cryptograph(){}
00047
00048 bool InitDecode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage);
00049 void InitEncode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage);
00050 void Decode(char* pBuffer, DWORD uSize)
00051 {
00052 for (DWORD i = 0; i < uSize; i++)
00053 CryptDecode(pBuffer[i]);
00054 }
00055 void Encode(char* pBuffer, DWORD uSize)
00056 {
00057 for (DWORD i = 0; i < uSize; i++)
00058 CryptEncode(pBuffer[i]);
00059 }
00060
00061 bool CanHandle(int iEncryptionMethod)
00062 {
00063 return iEncryptionMethod == CZipCryptograph::encStandard;
00064 }
00065
00069 static DWORD GetEncryptedInfoSizeBeforeData()
00070 {
00071 return ZIPARCHIVE_ENCR_HEADER_LEN;
00072 }
00073
00077 static DWORD GetEncryptedInfoSizeAfterData()
00078 {
00079 return 0;
00080 }
00081
00085 static const unsigned long* GetCRCTable()
00086 {
00087 return zarch_get_crc_table();
00088 }
00089 private:
00090
00091 void CryptDecode(char &c)
00092 {
00093 c ^= CryptDecryptByte();
00094 CryptUpdateKeys(c);
00095 }
00096
00097 char CryptDecryptByte()
00098 {
00099 int temp = (m_keys[2] & 0xffff) | 2;
00100 return (char)(((temp * (temp ^ 1)) >> 8) & 0xff);
00101 }
00102 void CryptInitKeys(CZipAutoBuffer& password);
00103 void CryptUpdateKeys(char c);
00104 DWORD CryptCRC32(DWORD l, char c)
00105 {
00106 const unsigned long* CRC_TABLE = zarch_get_crc_table();
00107 return CRC_TABLE[(l ^ c) & 0xff] ^ (l >> 8);
00108 }
00109 void CryptEncode(char &c)
00110 {
00111 char t = CryptDecryptByte();
00112 CryptUpdateKeys(c);
00113 c ^= t;
00114 }
00115 DWORD m_keys[3];
00116 public:
00117 ~CZipCrc32Cryptograph(){}
00118 };
00119
00120 #endif