* contrib/hbziparch/_features.h
* contrib/hbziparch/_platform.h
* contrib/hbziparch/Aes.cpp
* contrib/hbziparch/Aes.h
* contrib/hbziparch/BaseLibCompressor.cpp
* contrib/hbziparch/BaseLibCompressor.h
* contrib/hbziparch/BytesWriter.h
* contrib/hbziparch/Bzip2Compressor.cpp
* contrib/hbziparch/Bzip2Compressor.h
* contrib/hbziparch/DeflateCompressor.cpp
* contrib/hbziparch/DeflateCompressor.h
* contrib/hbziparch/DirEnumerator.cpp
* contrib/hbziparch/DirEnumerator.h
* contrib/hbziparch/FileFilter.cpp
* contrib/hbziparch/FileFilter.h
* contrib/hbziparch/FileInfo.h
* contrib/hbziparch/Hmac.cpp
* contrib/hbziparch/Hmac.h
* contrib/hbziparch/RandomPool.cpp
* contrib/hbziparch/RandomPool.h
* contrib/hbziparch/Sha1.cpp
* contrib/hbziparch/Sha1.h
* contrib/hbziparch/std_mfc.h
* contrib/hbziparch/std_stl.h
* contrib/hbziparch/Wildcard.cpp
* contrib/hbziparch/Wildcard.h
* contrib/hbziparch/ZipAbstractFile.h
* contrib/hbziparch/ZipAesCryptograph.cpp
* contrib/hbziparch/ZipAesCryptograph.h
* contrib/hbziparch/ZipArchive.cpp
* contrib/hbziparch/ZipArchive.h
* contrib/hbziparch/ZipAutoBuffer.cpp
* contrib/hbziparch/ZipAutoBuffer.h
* contrib/hbziparch/ZipBaseException.h
* contrib/hbziparch/ZipCallback.h
* contrib/hbziparch/ZipCallbackProvider.h
* contrib/hbziparch/ZipCentralDir.cpp
* contrib/hbziparch/ZipCentralDir.h
* contrib/hbziparch/ZipCollections.h
* contrib/hbziparch/ZipCollections_mfc.h
* contrib/hbziparch/ZipCollections_stl.h
* contrib/hbziparch/ZipCompatibility.cpp
* contrib/hbziparch/ZipCompatibility.h
* contrib/hbziparch/ZipCompressor.cpp
* contrib/hbziparch/ZipCompressor.h
* contrib/hbziparch/ZipCrc32Cryptograph.cpp
* contrib/hbziparch/ZipCrc32Cryptograph.h
* contrib/hbziparch/ZipCryptograph.cpp
* contrib/hbziparch/ZipCryptograph.h
* contrib/hbziparch/ZipException.cpp
* contrib/hbziparch/ZipException.h
* contrib/hbziparch/ZipExtraData.cpp
* contrib/hbziparch/ZipExtraData.h
* contrib/hbziparch/ZipExtraField.cpp
* contrib/hbziparch/ZipExtraField.h
* contrib/hbziparch/ZipFile.h
* contrib/hbziparch/ZipFile_mfc.cpp
* contrib/hbziparch/ZipFile_mfc.h
* contrib/hbziparch/ZipFile_stl.cpp
* contrib/hbziparch/ZipFile_stl.h
* contrib/hbziparch/ZipFileHeader.cpp
* contrib/hbziparch/ZipFileHeader.h
* contrib/hbziparch/ZipFileMapping.h
* contrib/hbziparch/ZipFileMapping_lnx.h
* contrib/hbziparch/ZipFileMapping_win.h
* contrib/hbziparch/ZipMemFile.cpp
* contrib/hbziparch/ZipMemFile.h
* contrib/hbziparch/ZipMutex.h
* contrib/hbziparch/ZipMutex_lnx.h
* contrib/hbziparch/ZipMutex_win.h
* contrib/hbziparch/ZipPathComponent.h
* contrib/hbziparch/ZipPlatform.h
* contrib/hbziparch/ZipPlatformComm.cpp
* contrib/hbziparch/ZipStorage.cpp
* contrib/hbziparch/ZipStorage.h
* contrib/hbziparch/ZipString.h
* contrib/hbziparch/ZipString_mfc.h
* contrib/hbziparch/ZipString_stl.h
* contrib/hbziparch/ZipStringStoreSettings.h
+ ZipArchive lib update finished.
; Pass 2/2
; Please test.
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// This source file is part of the ZipArchive library source distribution and
|
|
// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License
|
|
// as published by the Free Software Foundation; either version 2
|
|
// of the License, or (at your option) any later version.
|
|
//
|
|
// For the licensing details refer to the License.txt file.
|
|
//
|
|
// Web Site: http://www.artpol-software.com
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "ZipCrc32Cryptograph.h"
|
|
|
|
bool CZipCrc32Cryptograph::InitDecode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage)
|
|
{
|
|
CryptInitKeys(password);
|
|
CZipAutoBuffer buf(ZIPARCHIVE_ENCR_HEADER_LEN);
|
|
storage.Read(buf, ZIPARCHIVE_ENCR_HEADER_LEN, false);
|
|
BYTE b = 0;
|
|
for (int i = 0; i < ZIPARCHIVE_ENCR_HEADER_LEN; i++)
|
|
{
|
|
b = buf[i]; // only temporary
|
|
CryptDecode((char&)b);
|
|
}
|
|
// check the last byte
|
|
return currentFile.IsDataDescriptor() ?
|
|
(BYTE(currentFile.m_uModTime >> 8) == b) : (BYTE(currentFile.m_uCrc32 >> 24) == b);
|
|
}
|
|
|
|
void CZipCrc32Cryptograph::InitEncode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage)
|
|
{
|
|
CZipAutoBuffer buf(ZIPARCHIVE_ENCR_HEADER_LEN);
|
|
// use pseudo-crc since we don't know it yet
|
|
CryptInitKeys(password);
|
|
srand(UINT(time(NULL)));
|
|
// genereate pseudo-random sequence
|
|
char c;
|
|
char* buffer = (char*)buf;
|
|
for (int i = 0; i < ZIPARCHIVE_ENCR_HEADER_LEN - 2; i++)
|
|
{
|
|
int t1 = rand();
|
|
c = (char)((t1 >> 6) & 0xFF);
|
|
if (!c)
|
|
c = (char)(t1 & 0xFF);
|
|
CryptEncode(c);
|
|
buffer[i] = c;
|
|
|
|
}
|
|
long iCrc = (long)currentFile.m_uModTime << 16;
|
|
c = (char)((iCrc >> 16) & 0xFF);
|
|
CryptEncode(c);
|
|
buffer[ZIPARCHIVE_ENCR_HEADER_LEN - 2] = c;
|
|
c = (char)((iCrc >> 24) & 0xFF);
|
|
CryptEncode(c);
|
|
buffer[ZIPARCHIVE_ENCR_HEADER_LEN - 1] = c;
|
|
storage.Write(buf, ZIPARCHIVE_ENCR_HEADER_LEN, false);
|
|
currentFile.m_uComprSize += ZIPARCHIVE_ENCR_HEADER_LEN;
|
|
}
|
|
|
|
void CZipCrc32Cryptograph::CryptInitKeys(CZipAutoBuffer& password)
|
|
{
|
|
m_keys[0] = 305419896L;
|
|
m_keys[1] = 591751049L;
|
|
m_keys[2] = 878082192L;
|
|
for (DWORD i = 0; i < password.GetSize(); i++)
|
|
CryptUpdateKeys(password[i]);
|
|
}
|
|
|
|
void CZipCrc32Cryptograph::CryptUpdateKeys(char c)
|
|
{
|
|
m_keys[0] = CryptCRC32(m_keys[0], c);
|
|
m_keys[1] += m_keys[0] & 0xff;
|
|
m_keys[1] = m_keys[1] * 134775813L + 1;
|
|
c = char(m_keys[1] >> 24);
|
|
m_keys[2] = CryptCRC32(m_keys[2], c);
|
|
}
|
|
|