mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-16 04:11:49 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -1,4 +1,4 @@
|
||||
// 7z_AES.h
|
||||
// 7z_AES.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
@@ -28,7 +28,7 @@ bool CKeyInfo::IsEqualTo(const CKeyInfo &a) const
|
||||
{
|
||||
if (SaltSize != a.SaltSize || NumCyclesPower != a.NumCyclesPower)
|
||||
return false;
|
||||
for (UINT32 i = 0; i < SaltSize; i++)
|
||||
for (UInt32 i = 0; i < SaltSize; i++)
|
||||
if (Salt[i] != a.Salt[i])
|
||||
return false;
|
||||
return (Password == a.Password);
|
||||
@@ -38,40 +38,28 @@ void CKeyInfo::CalculateDigest()
|
||||
{
|
||||
if (NumCyclesPower == 0x3F)
|
||||
{
|
||||
UINT32 pos;
|
||||
UInt32 pos;
|
||||
for (pos = 0; pos < SaltSize; pos++)
|
||||
Key[pos] = Salt[pos];
|
||||
for (UINT32 i = 0; i < Password.GetCapacity() && pos < kKeySize; i++)
|
||||
for (UInt32 i = 0; i < Password.GetCapacity() && pos < kKeySize; i++)
|
||||
Key[pos++] = Password[i];
|
||||
for (; pos < kKeySize; pos++)
|
||||
Key[pos] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
CMyComPtr<ICryptoHash> sha;
|
||||
RINOK(sha.CoCreateInstance(CLSID_CCrypto_Hash_SHA256));
|
||||
RINOK(sha->Init());
|
||||
*/
|
||||
|
||||
NCrypto::NSHA256::SHA256 sha;
|
||||
const UINT64 numRounds = UINT64(1) << (NumCyclesPower);
|
||||
for (UINT64 round = 0; round < numRounds; round++)
|
||||
const UInt64 numRounds = UInt64(1) << (NumCyclesPower);
|
||||
Byte temp[8] = { 0,0,0,0,0,0,0,0 };
|
||||
for (UInt64 round = 0; round < numRounds; round++)
|
||||
{
|
||||
/*
|
||||
RINOK(sha->Update(Salt, SaltSize));
|
||||
RINOK(sha->Update(Password, Password.GetCapacity()));
|
||||
// change it if big endian;
|
||||
RINOK(sha->Update(&round, sizeof(round)));
|
||||
*/
|
||||
|
||||
// sha.Update(Salt, sizeof(Salt));
|
||||
sha.Update(Salt, SaltSize);
|
||||
sha.Update(Password, Password.GetCapacity());
|
||||
// change it if big endian;
|
||||
sha.Update((const BYTE *)&round, sizeof(round));
|
||||
sha.Update(temp, 8);
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (++(temp[i]) != 0)
|
||||
break;
|
||||
}
|
||||
// return sha->GetDigest(Key);
|
||||
sha.Final(Key);
|
||||
}
|
||||
}
|
||||
@@ -133,30 +121,30 @@ void CBase::CalculateDigest()
|
||||
|
||||
|
||||
/*
|
||||
static void GetRandomData(BYTE *data)
|
||||
static void GetRandomData(Byte *data)
|
||||
{
|
||||
// probably we don't need truly random.
|
||||
// it's enough to prevent dictionary attack;
|
||||
// but it gives some info about time when compressing
|
||||
// was made.
|
||||
UINT64 tempValue;
|
||||
UInt64 tempValue;
|
||||
SYSTEMTIME systemTime;
|
||||
FILETIME fileTime;
|
||||
::GetSystemTime(&systemTime);
|
||||
::SystemTimeToFileTime(&systemTime, &fileTime);
|
||||
tempValue = *(const UINT64 *)&fileTime;
|
||||
tempValue = *(const UInt64 *)&fileTime;
|
||||
LARGE_INTEGER counter;
|
||||
::QueryPerformanceCounter(&counter);
|
||||
tempValue += *(const UINT64 *)&counter;
|
||||
tempValue += (UINT64)(GetTickCount()) << 32;
|
||||
*(UINT64 *)data = tempValue;
|
||||
tempValue += *(const UInt64 *)&counter;
|
||||
tempValue += (UInt64)(GetTickCount()) << 32;
|
||||
*(UInt64 *)data = tempValue;
|
||||
}
|
||||
*/
|
||||
|
||||
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
|
||||
{
|
||||
_key.Init();
|
||||
for (UINT32 i = 0; i < sizeof(_iv); i++)
|
||||
for (UInt32 i = 0; i < sizeof(_iv); i++)
|
||||
_iv[i] = 0;
|
||||
|
||||
_key.SaltSize = 0;
|
||||
@@ -169,16 +157,16 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
|
||||
// _key.NumCyclesPower = 0x3F;
|
||||
_key.NumCyclesPower = 18;
|
||||
|
||||
BYTE firstByte = _key.NumCyclesPower |
|
||||
Byte firstByte = _key.NumCyclesPower |
|
||||
(((_key.SaltSize == 0) ? 0 : 1) << 7) |
|
||||
(((ivSize == 0) ? 0 : 1) << 6);
|
||||
RINOK(outStream->Write(&firstByte, sizeof(firstByte), NULL));
|
||||
RINOK(outStream->Write(&firstByte, 1, NULL));
|
||||
if (_key.SaltSize == 0 && ivSize == 0)
|
||||
return S_OK;
|
||||
BYTE saltSizeSpec = (_key.SaltSize == 0) ? 0 : (_key.SaltSize - 1);
|
||||
BYTE ivSizeSpec = (ivSize == 0) ? 0 : (ivSize - 1);
|
||||
BYTE secondByte = ((saltSizeSpec) << 4) | ivSizeSpec;
|
||||
RINOK(outStream->Write(&secondByte, sizeof(secondByte), NULL));
|
||||
Byte saltSizeSpec = (_key.SaltSize == 0) ? 0 : (_key.SaltSize - 1);
|
||||
Byte ivSizeSpec = (ivSize == 0) ? 0 : (ivSize - 1);
|
||||
Byte secondByte = ((saltSizeSpec) << 4) | ivSizeSpec;
|
||||
RINOK(outStream->Write(&secondByte, 1, NULL));
|
||||
if (_key.SaltSize > 0)
|
||||
{
|
||||
RINOK(outStream->Write(_key.Salt, _key.SaltSize, NULL));
|
||||
@@ -190,56 +178,40 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
|
||||
{
|
||||
_key.Init();
|
||||
for (int i = 0; i < sizeof(_iv); i++)
|
||||
UInt32 i;
|
||||
for (i = 0; i < sizeof(_iv); i++)
|
||||
_iv[i] = 0;
|
||||
UINT32 processedSize;
|
||||
BYTE firstByte;
|
||||
RINOK(inStream->Read(&firstByte, sizeof(firstByte), &processedSize));
|
||||
if (processedSize == 0)
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
UInt32 pos = 0;
|
||||
Byte firstByte = data[pos++];
|
||||
|
||||
_key.NumCyclesPower = firstByte & 0x3F;
|
||||
if ((firstByte & 0xC0) == 0)
|
||||
return S_OK;
|
||||
_key.SaltSize = (firstByte >> 7) & 1;
|
||||
UINT32 ivSize = (firstByte >> 6) & 1;
|
||||
UInt32 ivSize = (firstByte >> 6) & 1;
|
||||
|
||||
BYTE secondByte;
|
||||
RINOK(inStream->Read(&secondByte, sizeof(secondByte), &processedSize));
|
||||
if (processedSize == 0)
|
||||
if (pos >= size)
|
||||
return E_INVALIDARG;
|
||||
Byte secondByte = data[pos++];
|
||||
|
||||
_key.SaltSize += (secondByte >> 4);
|
||||
ivSize += (secondByte & 0x0F);
|
||||
|
||||
RINOK(inStream->Read(_key.Salt,
|
||||
_key.SaltSize, &processedSize));
|
||||
if (processedSize != _key.SaltSize)
|
||||
if (pos + _key.SaltSize + ivSize > size)
|
||||
return E_INVALIDARG;
|
||||
|
||||
RINOK(inStream->Read(_iv, ivSize, &processedSize));
|
||||
if (processedSize != ivSize)
|
||||
return E_INVALIDARG;
|
||||
|
||||
for (i = 0; i < _key.SaltSize; i++)
|
||||
_key.Salt[i] = data[pos++];
|
||||
for (i = 0; i < ivSize; i++)
|
||||
_iv[i] = data[pos++];
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::CryptoSetPassword(const BYTE *data, UINT32 size)
|
||||
{
|
||||
_key.Password.SetCapacity(size);
|
||||
memcpy(_key.Password, data, size);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::CryptoSetPassword(const BYTE *data, UINT32 size)
|
||||
STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
|
||||
{
|
||||
_key.Password.SetCapacity(size);
|
||||
memcpy(_key.Password, data, size);
|
||||
@@ -247,12 +219,12 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const BYTE *data, UINT32 size)
|
||||
}
|
||||
|
||||
/*
|
||||
static BYTE *WideToRaw(const wchar_t *src, BYTE *dest, int destSize=0x10000000)
|
||||
static Byte *WideToRaw(const wchar_t *src, Byte *dest, int destSize=0x10000000)
|
||||
{
|
||||
for (int i = 0; i < destSize; i++, src++)
|
||||
{
|
||||
dest[i * 2] = (BYTE)*src;
|
||||
dest[i * 2 + 1]= (BYTE)(*src >> 8);
|
||||
dest[i * 2] = (Byte)*src;
|
||||
dest[i * 2 + 1]= (Byte)(*src >> 8);
|
||||
if (*src == 0)
|
||||
break;
|
||||
}
|
||||
@@ -276,80 +248,57 @@ bool GetAESLibPath(TCHAR *path)
|
||||
}
|
||||
#endif
|
||||
|
||||
STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UINT64 const *inSize,
|
||||
const UINT64 *outSize,ICompressProgressInfo *progress)
|
||||
STDMETHODIMP CBaseCoder::Init()
|
||||
{
|
||||
CalculateDigest();
|
||||
|
||||
if (_aesEncoder == 0)
|
||||
if (_aesFilter == 0)
|
||||
{
|
||||
#ifdef CRYPTO_AES
|
||||
_aesEncoder = new CAES256_CBC_Encoder;
|
||||
#else
|
||||
if ((HMODULE)_aesEncoderLibrary == 0)
|
||||
{
|
||||
TCHAR filePath[MAX_PATH + 2];
|
||||
if (!GetAESLibPath(filePath))
|
||||
return ::GetLastError();
|
||||
RINOK(_aesEncoderLibrary.LoadAndCreateCoder2(filePath,
|
||||
CLSID_CCrypto_AES256_Encoder, &_aesEncoder));
|
||||
}
|
||||
#endif
|
||||
RINOK(CreateFilter());
|
||||
}
|
||||
|
||||
CSequentialInStreamImp *ivStreamSpec = new CSequentialInStreamImp;
|
||||
CMyComPtr<ISequentialInStream> ivStream(ivStreamSpec);
|
||||
ivStreamSpec->Init(_iv, sizeof(_iv));
|
||||
|
||||
CSequentialInStreamImp *keyStreamSpec = new CSequentialInStreamImp;
|
||||
CMyComPtr<ISequentialInStream> keyStream(keyStreamSpec);
|
||||
keyStreamSpec->Init(_key.Key, sizeof(_key.Key));
|
||||
|
||||
ISequentialInStream *inStreams[3] = { inStream, ivStream, keyStream };
|
||||
UINT64 ivSize = sizeof(_iv);
|
||||
UINT64 keySize = sizeof(_key.Key);
|
||||
const UINT64 *inSizes[3] = { inSize, &ivSize, &ivSize, };
|
||||
return _aesEncoder->Code(inStreams, inSizes, 3,
|
||||
&outStream, &outSize, 1, progress);
|
||||
CMyComPtr<ICryptoProperties> cp;
|
||||
RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp));
|
||||
RINOK(cp->SetKey(_key.Key, sizeof(_key.Key)));
|
||||
RINOK(cp->SetInitVector(_iv, sizeof(_iv)));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UINT64 const *inSize,
|
||||
const UINT64 *outSize,ICompressProgressInfo *progress)
|
||||
STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
CalculateDigest();
|
||||
return _aesFilter->Filter(data, size);
|
||||
}
|
||||
|
||||
if (_aesDecoder == 0)
|
||||
#ifndef CRYPTO_AES
|
||||
HRESULT CBaseCoder::CreateFilterFromDLL(REFCLSID clsID)
|
||||
{
|
||||
if (!_aesLibrary)
|
||||
{
|
||||
#ifdef CRYPTO_AES
|
||||
_aesDecoder = new CAES256_CBC_Decoder;
|
||||
#else
|
||||
if ((HMODULE)_aesDecoderLibrary == 0)
|
||||
{
|
||||
TCHAR filePath[MAX_PATH + 2];
|
||||
if (!GetAESLibPath(filePath))
|
||||
return ::GetLastError();
|
||||
RINOK(_aesDecoderLibrary.LoadAndCreateCoder2(filePath,
|
||||
CLSID_CCrypto_AES256_Decoder, &_aesDecoder));
|
||||
}
|
||||
#endif
|
||||
TCHAR filePath[MAX_PATH + 2];
|
||||
if (!GetAESLibPath(filePath))
|
||||
return ::GetLastError();
|
||||
return _aesLibrary.LoadAndCreateFilter(filePath, clsID, &_aesFilter);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
CSequentialInStreamImp *ivStreamSpec = new CSequentialInStreamImp;
|
||||
CMyComPtr<ISequentialInStream> ivStream(ivStreamSpec);
|
||||
ivStreamSpec->Init(_iv, sizeof(_iv));
|
||||
HRESULT CEncoder::CreateFilter()
|
||||
{
|
||||
#ifdef CRYPTO_AES
|
||||
_aesFilter = new CAES256_CBC_Encoder;
|
||||
return S_OK;
|
||||
#else
|
||||
return CreateFilterFromDLL(CLSID_CCrypto_AES256_Encoder);
|
||||
#endif
|
||||
}
|
||||
|
||||
CSequentialInStreamImp *keyStreamSpec = new CSequentialInStreamImp;
|
||||
CMyComPtr<ISequentialInStream> keyStream(keyStreamSpec);
|
||||
keyStreamSpec->Init(_key.Key, sizeof(_key.Key));
|
||||
|
||||
ISequentialInStream *inStreams[3] = { inStream, ivStream, keyStream };
|
||||
UINT64 ivSize = sizeof(_iv);
|
||||
UINT64 keySize = sizeof(_key.Key);
|
||||
const UINT64 *inSizes[3] = { inSize, &ivSize, &ivSize, };
|
||||
return _aesDecoder->Code(inStreams, inSizes, 3,
|
||||
&outStream, &outSize, 1, progress);
|
||||
HRESULT CDecoder::CreateFilter()
|
||||
{
|
||||
#ifdef CRYPTO_AES
|
||||
_aesFilter = new CAES256_CBC_Decoder;
|
||||
return S_OK;
|
||||
#else
|
||||
return CreateFilterFromDLL(CLSID_CCrypto_AES256_Decoder);
|
||||
#endif
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -122,6 +122,14 @@ SOURCE=.\StdAfx.h
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Alloc.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Alloc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -148,6 +156,14 @@ SOURCE=..\..\Common\StreamObjects.cpp
|
||||
|
||||
SOURCE=..\..\Common\StreamObjects.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringConvert.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringConvert.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Windows"
|
||||
|
||||
@@ -169,6 +185,14 @@ SOURCE=..\..\..\Windows\Synchronization.cpp
|
||||
SOURCE=..\..\..\Windows\Synchronization.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Archive Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\Common\CoderLoader.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\7zAES.cpp
|
||||
|
||||
@@ -32,18 +32,15 @@ class CKeyInfo
|
||||
{
|
||||
public:
|
||||
int NumCyclesPower;
|
||||
UINT32 SaltSize;
|
||||
BYTE Salt[16];
|
||||
UInt32 SaltSize;
|
||||
Byte Salt[16];
|
||||
CByteBuffer Password;
|
||||
BYTE Key[kKeySize];
|
||||
Byte Key[kKeySize];
|
||||
|
||||
bool IsEqualTo(const CKeyInfo &a) const;
|
||||
void CalculateDigest();
|
||||
|
||||
CKeyInfo()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
CKeyInfo() { Init(); }
|
||||
void Init()
|
||||
{
|
||||
NumCyclesPower = 0;
|
||||
@@ -69,69 +66,57 @@ class CBase
|
||||
CKeyInfoCache _cachedKeys;
|
||||
protected:
|
||||
CKeyInfo _key;
|
||||
BYTE _iv[16];
|
||||
Byte _iv[16];
|
||||
// int _ivSize;
|
||||
void CalculateDigest();
|
||||
CBase();
|
||||
};
|
||||
|
||||
class CEncoder:
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties,
|
||||
class CBaseCoder:
|
||||
public ICompressFilter,
|
||||
public ICryptoSetPassword,
|
||||
public ICompressWriteCoderProperties,
|
||||
public CMyUnknownImp,
|
||||
public CBase
|
||||
{
|
||||
MY_UNKNOWN_IMP3(
|
||||
ICryptoSetPassword,
|
||||
ICompressSetDecoderProperties,
|
||||
ICompressWriteCoderProperties
|
||||
)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UINT64 const *inSize,
|
||||
const UINT64 *outSize,ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(CryptoSetPassword)(const BYTE *aData, UINT32 aSize);
|
||||
|
||||
// ICompressSetDecoderProperties
|
||||
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream);
|
||||
|
||||
// ICompressWriteCoderProperties
|
||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||
|
||||
protected:
|
||||
#ifndef CRYPTO_AES
|
||||
CCoderLibrary _aesEncoderLibrary;
|
||||
CCoderLibrary _aesLibrary;
|
||||
#endif
|
||||
CMyComPtr<ICompressCoder2> _aesEncoder;
|
||||
CMyComPtr<ICompressFilter> _aesFilter;
|
||||
|
||||
virtual HRESULT CreateFilter() = 0;
|
||||
#ifndef CRYPTO_AES
|
||||
HRESULT CreateFilterFromDLL(REFCLSID clsID);
|
||||
#endif
|
||||
public:
|
||||
STDMETHOD(Init)();
|
||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
|
||||
|
||||
STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
|
||||
};
|
||||
|
||||
class CEncoder:
|
||||
public CBaseCoder,
|
||||
public ICompressWriteCoderProperties
|
||||
{
|
||||
virtual HRESULT CreateFilter();
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(
|
||||
ICryptoSetPassword,
|
||||
ICompressWriteCoderProperties)
|
||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||
};
|
||||
|
||||
class CDecoder:
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties,
|
||||
public ICryptoSetPassword,
|
||||
public CMyUnknownImp,
|
||||
public CBase
|
||||
public CBaseCoder,
|
||||
public ICompressSetDecoderProperties2
|
||||
{
|
||||
virtual HRESULT CreateFilter();
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(
|
||||
ICryptoSetPassword,
|
||||
ICompressSetDecoderProperties
|
||||
)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UINT64 const *inSize,
|
||||
const UINT64 *outSize,ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(CryptoSetPassword)(const BYTE *aData, UINT32 aSize);
|
||||
// ICompressSetDecoderProperties
|
||||
|
||||
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream);
|
||||
|
||||
#ifndef CRYPTO_AES
|
||||
CCoderLibrary _aesDecoderLibrary;
|
||||
#endif
|
||||
CMyComPtr<ICompressCoder2> _aesDecoder;
|
||||
ICompressSetDecoderProperties2)
|
||||
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "Common/MyInitGuid.h"
|
||||
#include "Common/ComTry.h"
|
||||
#include "7zAES.h"
|
||||
|
||||
@@ -35,23 +34,23 @@ STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
int correctInterface = (*iid == IID_ICompressCoder);
|
||||
CMyComPtr<ICompressCoder> coder;
|
||||
int correctInterface = (*iid == IID_ICompressFilter);
|
||||
CMyComPtr<ICompressFilter> filter;
|
||||
if (*clsid == CLSID_CCrypto7zAESDecoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCrypto::NSevenZ::CDecoder();
|
||||
filter = (ICompressFilter *)new NCrypto::NSevenZ::CDecoder();
|
||||
}
|
||||
else if (*clsid == CLSID_CCrypto7zAESEncoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCrypto::NSevenZ::CEncoder();
|
||||
filter = (ICompressFilter *)new NCrypto::NSevenZ::CEncoder();
|
||||
}
|
||||
else
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = coder.Detach();
|
||||
*outObject = filter.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crypto/HASH/SHA256/SHA256.cpp
|
||||
// Crypto/SHA256.cpp
|
||||
// This code is based on code from Wei Dai's Crypto++ library.
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -58,10 +58,10 @@ void SHA256::Init()
|
||||
#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3))
|
||||
#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10))
|
||||
|
||||
void SHA256::Transform(UINT32 *state, const UINT32 *data)
|
||||
void SHA256::Transform(UInt32 *state, const UInt32 *data)
|
||||
{
|
||||
UINT32 W[16];
|
||||
UINT32 T[8];
|
||||
UInt32 W[16];
|
||||
UInt32 T[8];
|
||||
/* Copy context->state[] to working vars */
|
||||
// memcpy(T, state, sizeof(T));
|
||||
for (int s = 0; s < 8; s++)
|
||||
@@ -101,7 +101,7 @@ void SHA256::Transform(UINT32 *state, const UINT32 *data)
|
||||
// memset(T, 0, sizeof(T));
|
||||
}
|
||||
|
||||
const UINT32 SHA256::K[64] = {
|
||||
const UInt32 SHA256::K[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
@@ -127,20 +127,20 @@ const UINT32 SHA256::K[64] = {
|
||||
|
||||
void SHA256::WriteByteBlock()
|
||||
{
|
||||
UINT32 data32[16];
|
||||
UInt32 data32[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
data32[i] = (UINT32(_buffer[i * 4]) << 24) +
|
||||
(UINT32(_buffer[i * 4 + 1]) << 16) +
|
||||
(UINT32(_buffer[i * 4 + 2]) << 8) +
|
||||
UINT32(_buffer[i * 4 + 3]);
|
||||
data32[i] = (UInt32(_buffer[i * 4]) << 24) +
|
||||
(UInt32(_buffer[i * 4 + 1]) << 16) +
|
||||
(UInt32(_buffer[i * 4 + 2]) << 8) +
|
||||
UInt32(_buffer[i * 4 + 3]);
|
||||
}
|
||||
Transform(m_digest, data32);
|
||||
}
|
||||
|
||||
void SHA256::Update(const BYTE *data, UINT32 size)
|
||||
void SHA256::Update(const Byte *data, UInt32 size)
|
||||
{
|
||||
UINT32 curBufferPos = UINT32(m_count) & 0x3F;
|
||||
UInt32 curBufferPos = UInt32(m_count) & 0x3F;
|
||||
while (size > 0)
|
||||
{
|
||||
while(curBufferPos < 64 && size > 0)
|
||||
@@ -157,10 +157,10 @@ void SHA256::Update(const BYTE *data, UINT32 size)
|
||||
}
|
||||
}
|
||||
|
||||
void SHA256::Final(BYTE *digest)
|
||||
void SHA256::Final(Byte *digest)
|
||||
{
|
||||
UINT64 lenInBits = (m_count << 3);
|
||||
UINT32 curBufferPos = UINT32(m_count) & 0x3F;
|
||||
UInt64 lenInBits = (m_count << 3);
|
||||
UInt32 curBufferPos = UInt32(m_count) & 0x3F;
|
||||
_buffer[curBufferPos++] = 0x80;
|
||||
while (curBufferPos != (64 - 8))
|
||||
{
|
||||
@@ -171,7 +171,7 @@ void SHA256::Final(BYTE *digest)
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
_buffer[curBufferPos++] = BYTE(lenInBits >> 56);
|
||||
_buffer[curBufferPos++] = Byte(lenInBits >> 56);
|
||||
lenInBits <<= 8;
|
||||
}
|
||||
WriteByteBlock();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crypto/SHA/SHA256.h
|
||||
// Crypto/SHA256.h
|
||||
|
||||
#ifndef __CRYPTO_SHA256_H
|
||||
#define __CRYPTO_SHA256_H
|
||||
@@ -10,19 +10,19 @@ namespace NSHA256 {
|
||||
|
||||
class SHA256
|
||||
{
|
||||
static const UINT32 K[64];
|
||||
static const UInt32 K[64];
|
||||
|
||||
UINT32 m_digest[8];
|
||||
UINT64 m_count;
|
||||
BYTE _buffer[64];
|
||||
static void Transform(UINT32 *digest, const UINT32 *data);
|
||||
UInt32 m_digest[8];
|
||||
UInt64 m_count;
|
||||
Byte _buffer[64];
|
||||
static void Transform(UInt32 *digest, const UInt32 *data);
|
||||
void WriteByteBlock();
|
||||
public:
|
||||
enum {DIGESTSIZE = 32};
|
||||
SHA256() { Init(); } ;
|
||||
void Init();
|
||||
void Update(const BYTE *data, UINT32 size);
|
||||
void Final(BYTE *digest);
|
||||
void Update(const Byte *data, UInt32 size);
|
||||
void Final(Byte *digest);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "StdAfx.h"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// stdafx.h
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -66,8 +66,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,2,0
|
||||
PRODUCTVERSION 3,9,2,0
|
||||
FILEVERSION 4,16,0,0
|
||||
PRODUCTVERSION 4,16,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -84,15 +84,15 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "7z-AES Crypto\0"
|
||||
VALUE "FileVersion", "3, 9, 2, 0\0"
|
||||
VALUE "FileDescription", "7z-AES Crypto Codec\0"
|
||||
VALUE "FileVersion", "4, 16, 0, 0\0"
|
||||
VALUE "InternalName", "7zAES\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2005 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "7zAES.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 9, 2, 0\0"
|
||||
VALUE "ProductVersion", "4, 16, 0, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
|
||||
Reference in New Issue
Block a user