mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-15 08:11:46 -06:00
4.27 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
31e7b924e8
commit
d66cf2fcf3
@@ -17,7 +17,8 @@ namespace NRar29 {
|
||||
|
||||
CDecoder::CDecoder():
|
||||
_thereIsSalt(false),
|
||||
_needCalculate(true)
|
||||
_needCalculate(true),
|
||||
_rar350Mode(false)
|
||||
{
|
||||
for (int i = 0; i < sizeof(_salt); i++)
|
||||
_salt[i] = 0;
|
||||
@@ -53,8 +54,12 @@ STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const int kMaxPasswordLength = 127 * 2;
|
||||
|
||||
STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
|
||||
{
|
||||
if (size > kMaxPasswordLength)
|
||||
size = kMaxPasswordLength;
|
||||
bool same = false;
|
||||
if (size == buffer.GetCapacity())
|
||||
{
|
||||
@@ -104,10 +109,9 @@ void CDecoder::Calculate()
|
||||
{
|
||||
if (_needCalculate)
|
||||
{
|
||||
const int MAXPASSWORD = 128;
|
||||
const int SALT_SIZE = 8;
|
||||
const int kSaltSize = 8;
|
||||
|
||||
Byte rawPassword[2 * MAXPASSWORD+ SALT_SIZE];
|
||||
Byte rawPassword[kMaxPasswordLength + kSaltSize];
|
||||
|
||||
memcpy(rawPassword, buffer, buffer.GetCapacity());
|
||||
|
||||
@@ -115,24 +119,24 @@ void CDecoder::Calculate()
|
||||
|
||||
if (_thereIsSalt)
|
||||
{
|
||||
memcpy(rawPassword + rawLength, _salt, SALT_SIZE);
|
||||
rawLength += SALT_SIZE;
|
||||
memcpy(rawPassword + rawLength, _salt, kSaltSize);
|
||||
rawLength += kSaltSize;
|
||||
}
|
||||
|
||||
CSHA1 sha;
|
||||
sha.Init();
|
||||
|
||||
|
||||
// seems rar reverts hash for sha.
|
||||
const int hashRounds = 0x40000;
|
||||
int i;
|
||||
for (i = 0; i < hashRounds; i++)
|
||||
{
|
||||
sha.Update(rawPassword, rawLength);
|
||||
sha.Update(rawPassword, rawLength, _rar350Mode);
|
||||
Byte pswNum[3];
|
||||
pswNum[0] = (Byte)i;
|
||||
pswNum[1] = (Byte)(i >> 8);
|
||||
pswNum[2] = (Byte)(i >> 16);
|
||||
sha.Update(pswNum, 3);
|
||||
sha.Update(pswNum, 3, _rar350Mode);
|
||||
if (i % (hashRounds / 16) == 0)
|
||||
{
|
||||
CSHA1 shaTemp = sha;
|
||||
|
||||
Reference in New Issue
Block a user