Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '7zip/Crypto/RarAES/RarAES.cpp')
-rwxr-xr-x7zip/Crypto/RarAES/RarAES.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/7zip/Crypto/RarAES/RarAES.cpp b/7zip/Crypto/RarAES/RarAES.cpp
index 16a48349..00699158 100755
--- a/7zip/Crypto/RarAES/RarAES.cpp
+++ b/7zip/Crypto/RarAES/RarAES.cpp
@@ -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;