This commit is contained in:
Igor Pavlov
2014-11-23 00:00:00 +00:00
committed by Kornel Lesiński
parent 83f8ddcc5b
commit f08f4dcc3c
1158 changed files with 76451 additions and 35082 deletions

22
CPP/7zip/Crypto/7zAes.cpp Executable file → Normal file
View File

@@ -4,7 +4,7 @@
#include "../../../C/Sha256.h"
#include "Windows/Synchronization.h"
#include "../../Windows/Synchronization.h"
#include "../Common/StreamObjects.h"
#include "../Common/StreamUtils.h"
@@ -38,7 +38,7 @@ void CKeyInfo::CalculateDigest()
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.Size() && pos < kKeySize; i++)
Key[pos++] = Password[i];
for (; pos < kKeySize; pos++)
Key[pos] = 0;
@@ -52,7 +52,7 @@ void CKeyInfo::CalculateDigest()
for (UInt64 round = 0; round < numRounds; round++)
{
Sha256_Update(&sha, Salt, (size_t)SaltSize);
Sha256_Update(&sha, Password, Password.GetCapacity());
Sha256_Update(&sha, Password, Password.Size());
Sha256_Update(&sha, temp, 8);
for (int i = 0; i < 8; i++)
if (++(temp[i]) != 0)
@@ -64,7 +64,7 @@ void CKeyInfo::CalculateDigest()
bool CKeyInfoCache::Find(CKeyInfo &key)
{
for (int i = 0; i < Keys.Size(); i++)
FOR_VECTOR (i, Keys)
{
const CKeyInfo &cached = Keys[i];
if (key.IsEqualTo(cached))
@@ -72,10 +72,7 @@ bool CKeyInfoCache::Find(CKeyInfo &key)
for (int j = 0; j < kKeySize; j++)
key.Key[j] = cached.Key[j];
if (i != 0)
{
Keys.Insert(0, cached);
Keys.Delete(i+1);
}
Keys.MoveToFront(i);
return true;
}
}
@@ -170,7 +167,7 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
HRESULT CEncoder::CreateFilter()
{
_aesFilter = new CAesCbcEncoder;
_aesFilter = new CAesCbcEncoder(kKeySize);
return S_OK;
}
@@ -211,8 +208,7 @@ STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
{
_key.Password.SetCapacity((size_t)size);
memcpy(_key.Password, data, (size_t)size);
_key.Password.CopyFrom(data, (size_t)size);
return S_OK;
}
@@ -227,7 +223,7 @@ STDMETHODIMP CBaseCoder::Init()
RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp));
RINOK(cp->SetKey(_key.Key, sizeof(_key.Key)));
RINOK(cp->SetInitVector(_iv, sizeof(_iv)));
return S_OK;
return _aesFilter->Init();
}
STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size)
@@ -237,7 +233,7 @@ STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size)
HRESULT CDecoder::CreateFilter()
{
_aesFilter = new CAesCbcDecoder;
_aesFilter = new CAesCbcDecoder(kKeySize);
return S_OK;
}

10
CPP/7zip/Crypto/7zAes.h Executable file → Normal file
View File

@@ -3,9 +3,9 @@
#ifndef __CRYPTO_7Z_AES_H
#define __CRYPTO_7Z_AES_H
#include "Common/Buffer.h"
#include "Common/MyCom.h"
#include "Common/MyVector.h"
#include "../../Common/MyBuffer.h"
#include "../../Common/MyCom.h"
#include "../../Common/MyVector.h"
#include "../ICoder.h"
#include "../IPassword.h"
@@ -39,10 +39,10 @@ public:
class CKeyInfoCache
{
int Size;
unsigned Size;
CObjectVector<CKeyInfo> Keys;
public:
CKeyInfoCache(int size): Size(size) {}
CKeyInfoCache(unsigned size): Size(size) {}
bool Find(CKeyInfo &key);
// HRESULT Calculate(CKeyInfo &key);
void Add(CKeyInfo &key);

0
CPP/7zip/Crypto/7zAesRegister.cpp Executable file → Normal file
View File

0
CPP/7zip/Crypto/Codec.def Executable file → Normal file
View File

0
CPP/7zip/Crypto/HmacSha1.cpp Executable file → Normal file
View File

0
CPP/7zip/Crypto/HmacSha1.h Executable file → Normal file
View File

78
CPP/7zip/Crypto/MyAes.cpp Executable file → Normal file
View File

@@ -2,21 +2,34 @@
#include "StdAfx.h"
#include "../../../C/CpuArch.h"
#include "MyAes.h"
namespace NCrypto {
struct CAesTabInit { CAesTabInit() { AesGenTables();} } g_AesTabInit;
static struct CAesTabInit { CAesTabInit() { AesGenTables();} } g_AesTabInit;
CAesCbcCoder::CAesCbcCoder()
CAesCbcCoder::CAesCbcCoder(bool encodeMode, unsigned keySize):
_keySize(keySize),
_keyIsSet(false),
_encodeMode(encodeMode)
{
_offset = ((0 - (unsigned)(ptrdiff_t)_aes) & 0xF) / sizeof(UInt32);
memset(_iv, 0, AES_BLOCK_SIZE);
SetFunctions(0);
}
STDMETHODIMP CAesCbcCoder::Init() { return S_OK; }
STDMETHODIMP CAesCbcCoder::Init()
{
AesCbc_Init(_aes + _offset, _iv);
return _keyIsSet ? S_OK : E_FAIL;
}
STDMETHODIMP_(UInt32) CAesCbcCoder::Filter(Byte *data, UInt32 size)
{
if (!_keyIsSet)
return 0;
if (size == 0)
return 0;
if (size < AES_BLOCK_SIZE)
@@ -30,7 +43,11 @@ STDMETHODIMP CAesCbcCoder::SetKey(const Byte *data, UInt32 size)
{
if ((size & 0x7) != 0 || size < 16 || size > 32)
return E_INVALIDARG;
_setKeyFunc(_aes + _offset + 4, data, size);
if (_keySize != 0 && size != _keySize)
return E_INVALIDARG;
AES_SET_KEY_FUNC setKeyFunc = _encodeMode ? Aes_SetKey_Enc : Aes_SetKey_Dec;
setKeyFunc(_aes + _offset + 4, data, size);
_keyIsSet = true;
return S_OK;
}
@@ -38,11 +55,58 @@ STDMETHODIMP CAesCbcCoder::SetInitVector(const Byte *data, UInt32 size)
{
if (size != AES_BLOCK_SIZE)
return E_INVALIDARG;
AesCbc_Init(_aes + _offset, data);
memcpy(_iv, data, size);
CAesCbcCoder::Init(); // don't call virtual function here !!!
return S_OK;
}
CAesCbcEncoder::CAesCbcEncoder() { _codeFunc = g_AesCbc_Encode; _setKeyFunc = Aes_SetKey_Enc; }
CAesCbcDecoder::CAesCbcDecoder() { _codeFunc = g_AesCbc_Decode; _setKeyFunc = Aes_SetKey_Dec; }
EXTERN_C_BEGIN
void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);
void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);
void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);
void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
EXTERN_C_END
bool CAesCbcCoder::SetFunctions(UInt32 algo)
{
_codeFunc = _encodeMode ?
g_AesCbc_Encode :
g_AesCbc_Decode;
if (algo == 1)
{
_codeFunc = _encodeMode ?
AesCbc_Encode:
AesCbc_Decode;
}
if (algo == 2)
{
#ifdef MY_CPU_X86_OR_AMD64
if (g_AesCbc_Encode != AesCbc_Encode_Intel)
#endif
return false;
}
return true;
}
STDMETHODIMP CAesCbcCoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps)
{
for (UInt32 i = 0; i < numProps; i++)
{
const PROPVARIANT &prop = coderProps[i];
if (propIDs[i] == NCoderPropID::kDefaultProp)
{
if (prop.vt != VT_UI4)
return E_INVALIDARG;
if (!SetFunctions(prop.ulVal))
return E_NOTIMPL;
}
}
return S_OK;
}
}

26
CPP/7zip/Crypto/MyAes.h Executable file → Normal file
View File

@@ -14,24 +14,38 @@ namespace NCrypto {
class CAesCbcCoder:
public ICompressFilter,
public ICryptoProperties,
public ICompressSetCoderProperties,
public CMyUnknownImp
{
protected:
AES_CODE_FUNC _codeFunc;
AES_SET_KEY_FUNC _setKeyFunc;
unsigned _offset;
unsigned _keySize;
bool _keyIsSet;
bool _encodeMode;
UInt32 _aes[AES_NUM_IVMRK_WORDS + 3];
Byte _iv[AES_BLOCK_SIZE];
bool SetFunctions(UInt32 algo);
public:
CAesCbcCoder();
MY_UNKNOWN_IMP1(ICryptoProperties)
CAesCbcCoder(bool encodeMode, unsigned keySize);
MY_UNKNOWN_IMP2(ICryptoProperties, ICompressSetCoderProperties)
STDMETHOD(Init)();
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
STDMETHOD(SetKey)(const Byte *data, UInt32 size);
STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
};
struct CAesCbcEncoder: public CAesCbcCoder
{
CAesCbcEncoder(unsigned keySize = 0): CAesCbcCoder(true, keySize) {}
};
struct CAesCbcDecoder: public CAesCbcCoder
{
CAesCbcDecoder(unsigned keySize = 0): CAesCbcCoder(false, keySize) {}
};
struct CAesCbcEncoder: public CAesCbcCoder { CAesCbcEncoder(); };
struct CAesCbcDecoder: public CAesCbcCoder { CAesCbcDecoder(); };
}

View File

@@ -0,0 +1,19 @@
// MyAesReg.cpp
#include "StdAfx.h"
#include "../Common/RegisterCodec.h"
#include "MyAes.h"
static void *CreateCodecCbc() { return (void *)(ICompressFilter *)(new NCrypto::CAesCbcDecoder(32)); }
#ifndef EXTRACT_ONLY
static void *CreateCodecCbcOut() { return (void *)(ICompressFilter *)(new NCrypto::CAesCbcEncoder(32)); }
#else
#define CreateCodecCbcOut 0
#endif
static CCodecInfo g_CodecInfo =
{ CreateCodecCbc, CreateCodecCbcOut, 0x06F00181, L"AES256CBC", 1, true };
REGISTER_CODEC(AES256CBC)

0
CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp Executable file → Normal file
View File

3
CPP/7zip/Crypto/Pbkdf2HmacSha1.h Executable file → Normal file
View File

@@ -5,7 +5,8 @@
#define __CRYPTO_PBKDF2_HMAC_SHA1_H
#include <stddef.h>
#include "../../Common/Types.h"
#include "../../Common/MyTypes.h"
namespace NCrypto {
namespace NSha1 {

10
CPP/7zip/Crypto/RandGen.cpp Executable file → Normal file
View File

@@ -2,7 +2,7 @@
#include "StdAfx.h"
#include "Windows/Synchronization.h"
#include "../../Windows/Synchronization.h"
#include "RandGen.h"
@@ -44,7 +44,13 @@ void CRandomGenerator::Init()
HASH_UPD(pid);
#endif
for (unsigned i = 0; i < 1000; i++)
for (unsigned i = 0; i <
#ifdef _DEBUG
2;
#else
1000;
#endif
i++)
{
#ifdef _WIN32
LARGE_INTEGER v;

0
CPP/7zip/Crypto/RandGen.h Executable file → Normal file
View File

0
CPP/7zip/Crypto/Rar20Crypto.cpp Executable file → Normal file
View File

2
CPP/7zip/Crypto/Rar20Crypto.h Executable file → Normal file
View File

@@ -3,7 +3,7 @@
#ifndef __CRYPTO_RAR20_CRYPTO_H
#define __CRYPTO_RAR20_CRYPTO_H
#include "Common/MyCom.h"
#include "../../Common/MyCom.h"
#include "../ICoder.h"
#include "../IPassword.h"

16
CPP/7zip/Crypto/RarAes.cpp Executable file → Normal file
View File

@@ -10,6 +10,7 @@ namespace NCrypto {
namespace NRar29 {
CDecoder::CDecoder():
CAesCbcDecoder(kRarAesKeySize),
_thereIsSalt(false),
_needCalculate(true),
_rar350Mode(false)
@@ -55,7 +56,7 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
if (size > kMaxPasswordLength)
size = kMaxPasswordLength;
bool same = false;
if (size == buffer.GetCapacity())
if (size == buffer.Size())
{
same = true;
for (UInt32 i = 0; i < size; i++)
@@ -67,17 +68,16 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
}
if (!_needCalculate && !same)
_needCalculate = true;
buffer.SetCapacity(size);
memcpy(buffer, data, size);
buffer.CopyFrom(data, (size_t)size);
return S_OK;
}
STDMETHODIMP CDecoder::Init()
{
Calculate();
SetKey(aesKey, kRarAesKeySize);
AesCbc_Init(_aes + _offset, _aesInit);
return S_OK;
RINOK(SetKey(aesKey, kRarAesKeySize));
RINOK(SetInitVector(_aesInit, AES_BLOCK_SIZE));
return CAesCbcCoder::Init();
}
void CDecoder::Calculate()
@@ -88,9 +88,9 @@ void CDecoder::Calculate()
Byte rawPassword[kMaxPasswordLength + kSaltSize];
memcpy(rawPassword, buffer, buffer.GetCapacity());
memcpy(rawPassword, buffer, buffer.Size());
size_t rawLength = buffer.GetCapacity();
size_t rawLength = buffer.Size();
if (_thereIsSalt)
{

2
CPP/7zip/Crypto/RarAes.h Executable file → Normal file
View File

@@ -5,7 +5,7 @@
#include "../../../C/Aes.h"
#include "Common/Buffer.h"
#include "../../Common/MyBuffer.h"
#include "../IPassword.h"

18
CPP/7zip/Crypto/Sha1.cpp Executable file → Normal file
View File

@@ -117,7 +117,7 @@ void CContext::Update(const Byte *data, size_t size)
unsigned curBufferPos = _count2;
while (size--)
{
int pos = (int)(curBufferPos & 3);
unsigned pos = (curBufferPos & 3);
if (pos == 0)
_buffer[curBufferPos >> 2] = 0;
_buffer[curBufferPos >> 2] |= ((UInt32)*data++) << (8 * (3 - pos));
@@ -136,7 +136,7 @@ void CContext::UpdateRar(Byte *data, size_t size, bool rar350Mode)
unsigned curBufferPos = _count2;
while (size--)
{
int pos = (int)(curBufferPos & 3);
unsigned pos = (curBufferPos & 3);
if (pos == 0)
_buffer[curBufferPos >> 2] = 0;
_buffer[curBufferPos >> 2] |= ((UInt32)*data++) << (8 * (3 - pos));
@@ -145,13 +145,13 @@ void CContext::UpdateRar(Byte *data, size_t size, bool rar350Mode)
curBufferPos = 0;
CContextBase::UpdateBlock(_buffer, returnRes);
if (returnRes)
for (int i = 0; i < kBlockSizeInWords; i++)
for (unsigned i = 0; i < kBlockSizeInWords; i++)
{
UInt32 d = _buffer[i];
data[i * 4 + 0 - kBlockSize] = (Byte)(d);
data[i * 4 + 1 - kBlockSize] = (Byte)(d >> 8);
data[i * 4 + 2 - kBlockSize] = (Byte)(d >> 16);
data[i * 4 + 3 - kBlockSize] = (Byte)(d >> 24);
data[(int)i * 4 + 0 - (int)kBlockSize] = (Byte)(d);
data[(int)i * 4 + 1 - (int)kBlockSize] = (Byte)(d >> 8);
data[(int)i * 4 + 2 - (int)kBlockSize] = (Byte)(d >> 16);
data[(int)i * 4 + 3 - (int)kBlockSize] = (Byte)(d >> 24);
}
returnRes = rar350Mode;
}
@@ -163,7 +163,7 @@ void CContext::Final(Byte *digest)
{
const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 3);
unsigned curBufferPos = _count2;
int pos = (int)(curBufferPos & 3);
unsigned pos = (curBufferPos & 3);
curBufferPos >>= 2;
if (pos == 0)
_buffer[curBufferPos] = 0;
@@ -180,7 +180,7 @@ void CContext::Final(Byte *digest)
_buffer[curBufferPos++] = (UInt32)(lenInBits);
UpdateBlock();
int i;
unsigned i;
for (i = 0; i < kDigestSizeInWords; i++)
{
UInt32 state = _state[i] & 0xFFFFFFFF;

3
CPP/7zip/Crypto/Sha1.h Executable file → Normal file
View File

@@ -6,7 +6,8 @@
#define __CRYPTO_SHA1_H
#include <stddef.h>
#include "../../Common/Types.h"
#include "../../Common/MyTypes.h"
// Sha1 implementation in RAR before version 3.60 has bug:
// it changes data bytes in some cases.

View File

@@ -0,0 +1,55 @@
// Sha1Reg.cpp
#include "StdAfx.h"
#include "../../Common/MyCom.h"
#include "../ICoder.h"
#include "../Common/RegisterCodec.h"
#include "Sha1.h"
using namespace NCrypto;
using namespace NSha1;
class CSha1Hasher:
public IHasher,
public CMyUnknownImp
{
CContext _sha;
public:
CSha1Hasher() { Init(); }
MY_UNKNOWN_IMP
STDMETHOD_(void, Init)();
STDMETHOD_(void, Update)(const void *data, UInt32 size);
STDMETHOD_(void, Final)(Byte *digest);
STDMETHOD_(UInt32, GetDigestSize)();
};
STDMETHODIMP_(void) CSha1Hasher::Init()
{
_sha.Init();
}
STDMETHODIMP_(void) CSha1Hasher::Update(const void *data, UInt32 size)
{
_sha.Update((const Byte *)data, size);
}
STDMETHODIMP_(void) CSha1Hasher::Final(Byte *digest)
{
_sha.Final(digest);
}
STDMETHODIMP_(UInt32) CSha1Hasher::GetDigestSize()
{
return kDigestSize;
}
static IHasher *CreateHasher() { return new CSha1Hasher; }
static CHasherInfo g_HasherInfo = { CreateHasher, 0x201, L"SHA1", kDigestSize };
REGISTER_HASHER(Sha1)

2
CPP/7zip/Crypto/StdAfx.h Executable file → Normal file
View File

@@ -3,6 +3,6 @@
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../Common/MyWindows.h"
#include "../../Common/Common.h"
#endif

13
CPP/7zip/Crypto/WzAes.cpp Executable file → Normal file
View File

@@ -27,10 +27,9 @@ static const UInt32 kNumKeyGenIterations = 1000;
STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
{
if(size > kPasswordSizeMax)
if (size > kPasswordSizeMax)
return E_INVALIDARG;
_key.Password.SetCapacity(size);
memcpy(_key.Password, data, size);
_key.Password.CopyFrom(data, (size_t)size);
return S_OK;
}
@@ -59,7 +58,7 @@ STDMETHODIMP CBaseCoder::Init()
#ifdef _NO_WZAES_OPTIMIZATIONS
NSha1::Pbkdf2Hmac(
_key.Password, _key.Password.GetCapacity(),
_key.Password, _key.Password.Size(),
_key.Salt, _key.GetSaltSize(),
kNumKeyGenIterations,
buf, keysTotalSize);
@@ -72,7 +71,7 @@ STDMETHODIMP CBaseCoder::Init()
UInt32 saltSizeInWords = _key.GetSaltSize() / 4;
BytesToBeUInt32s(_key.Salt, salt, saltSizeInWords);
NSha1::Pbkdf2Hmac32(
_key.Password, _key.Password.GetCapacity(),
_key.Password, _key.Password.Size(),
salt, saltSizeInWords,
kNumKeyGenIterations,
buf32, key32SizeTotal);
@@ -85,8 +84,8 @@ STDMETHODIMP CBaseCoder::Init()
_hmac.SetKey(buf + keySize, keySize);
memcpy(_key.PwdVerifComputed, buf + 2 * keySize, kPwdVerifCodeSize);
AesCtr2_Init(&_aes);
Aes_SetKey_Enc(_aes.aes + _aes.offset + 8, buf, keySize);
AesCtr2_Init(&_aes);
return S_OK;
}
@@ -199,7 +198,7 @@ void AesCtr2_Code(CAesCtr2 *p, Byte *data, SizeT size)
pos = 0;
do
*data++ ^= buf[pos++];
while (--size != 0 && pos != AES_BLOCK_SIZE);
while (--size != 0);
}
p->pos = pos;
}

5
CPP/7zip/Crypto/WzAes.h Executable file → Normal file
View File

@@ -14,9 +14,8 @@ specified in password Based File Encryption Utility:
#include "../../../C/Aes.h"
#include "Common/Buffer.h"
#include "Common/MyCom.h"
#include "Common/MyVector.h"
#include "../../Common/MyBuffer.h"
#include "../../Common/MyCom.h"
#include "../ICoder.h"
#include "../IPassword.h"

0
CPP/7zip/Crypto/ZipCrypto.cpp Executable file → Normal file
View File

2
CPP/7zip/Crypto/ZipCrypto.h Executable file → Normal file
View File

@@ -3,7 +3,7 @@
#ifndef __CRYPTO_ZIP_CRYPTO_H
#define __CRYPTO_ZIP_CRYPTO_H
#include "Common/MyCom.h"
#include "../../Common/MyCom.h"
#include "../ICoder.h"
#include "../IPassword.h"

23
CPP/7zip/Crypto/ZipStrong.cpp Executable file → Normal file
View File

@@ -65,11 +65,16 @@ HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream, UInt32 /* crc */, UI
if (_ivSize == 0)
{
return E_NOTIMPL;
/* we don't know how to decode that case:
From Appnote: If IVSize is 0,then IV = CRC32 + Uncompressed File Size (as a 64 bit little-endian, unsigned integer value).
But it doesn't work. If you know solution, please write about it to 7-Zip developers. */
/*
SetUi32(_iv, crc);
for (int i = 0; i < 8; i++)
_iv[4 + i] = (Byte)(unpackSize >> (8 * i));
SetUi32(_iv + 12, 0);
memset(_iv, 0, 16);
// unpackSize += crc;
SetUi32(_iv + 0, crc);
SetUi64(_iv + 4, unpackSize);
*/
}
else if (_ivSize == 16)
@@ -83,10 +88,9 @@ HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream, UInt32 /* crc */, UI
const UInt32 kAlign = 16;
if (_remSize < 16 || _remSize > (1 << 18))
return E_NOTIMPL;
if (_remSize + kAlign > _buf.GetCapacity())
if (_remSize + kAlign > _buf.Size())
{
_buf.Free();
_buf.SetCapacity(_remSize + kAlign);
_buf.Alloc(_remSize + kAlign);
_bufAligned = (Byte *)((ptrdiff_t)((Byte *)_buf + kAlign - 1) & ~(ptrdiff_t)(kAlign - 1));
}
return ReadStream_FALSE(inStream, _bufAligned, _remSize);
@@ -135,7 +139,7 @@ HRESULT CDecoder::CheckPassword(bool &passwOK)
{
RINOK(SetKey(_key.MasterKey, _key.KeySize));
RINOK(SetInitVector(_iv, 16));
Init();
RINOK(Init());
Filter(p, rdSize);
}
@@ -157,7 +161,8 @@ HRESULT CDecoder::CheckPassword(bool &passwOK)
if (GetUi32(validData + validSize) != CrcCalc(validData, validSize))
return S_OK;
passwOK = true;
Init();
/* 9.31: The BUG in 9.24-9.30 was fixed.
We don't need to call CAesCbcCoder::Init() to reset IV for data. */
return S_OK;
}

2
CPP/7zip/Crypto/ZipStrong.h Executable file → Normal file
View File

@@ -3,7 +3,7 @@
#ifndef __CRYPTO_ZIP_STRONG_H
#define __CRYPTO_ZIP_STRONG_H
#include "Common/Buffer.h"
#include "../../Common/MyBuffer.h"
#include "../IPassword.h"