This commit is contained in:
Igor Pavlov
2021-07-22 23:00:14 +01:00
committed by Kornel
parent 4a960640a3
commit 585698650f
619 changed files with 34904 additions and 10859 deletions

View File

@@ -9,6 +9,7 @@
#endif
#include "Rar5Aes.h"
#include "HmacSha256.h"
namespace NCrypto {
namespace NRar5 {
@@ -122,6 +123,7 @@ void CDecoder::SetPassword(const Byte *data, size_t size)
if (size != _password.Size() || memcmp(data, _password, size) != 0)
{
_needCalc = true;
_password.Wipe();
_password.CopyFrom(data, size);
}
}
@@ -132,28 +134,31 @@ STDMETHODIMP CDecoder::Init()
CalcKey_and_CheckPassword();
RINOK(SetKey(_key, kAesKeySize));
RINOK(SetInitVector(_iv, AES_BLOCK_SIZE));
return CAesCbcCoder::Init();
return CAesCoder::Init();
}
UInt32 CDecoder::Hmac_Convert_Crc32(UInt32 crc) const
{
MY_ALIGN (16)
NSha256::CHmac ctx;
ctx.SetKey(_hashKey, NSha256::kDigestSize);
Byte v[4];
SetUi32(v, crc);
ctx.Update(v, 4);
Byte h[NSha256::kDigestSize];
ctx.Final(h);
UInt32 v;
SetUi32(&v, crc);
ctx.Update((const Byte *)&v, 4);
MY_ALIGN (16)
UInt32 h[SHA256_NUM_DIGEST_WORDS];
ctx.Final((Byte *)h);
crc = 0;
for (unsigned i = 0; i < NSha256::kDigestSize; i++)
crc ^= (UInt32)h[i] << ((i & 3) * 8);
for (unsigned i = 0; i < SHA256_NUM_DIGEST_WORDS; i++)
crc ^= (UInt32)GetUi32(h + i);
return crc;
};
void CDecoder::Hmac_Convert_32Bytes(Byte *data) const
{
MY_ALIGN (16)
NSha256::CHmac ctx;
ctx.SetKey(_hashKey, NSha256::kDigestSize);
ctx.Update(data, NSha256::kDigestSize);
@@ -190,13 +195,16 @@ bool CDecoder::CalcKey_and_CheckPassword()
{
// Pbkdf HMAC-SHA-256
MY_ALIGN (16)
NSha256::CHmac baseCtx;
baseCtx.SetKey(_password, _password.Size());
NSha256::CHmac ctx = baseCtx;
ctx.Update(_salt, sizeof(_salt));
MY_ALIGN (16)
Byte u[NSha256::kDigestSize];
MY_ALIGN (16)
Byte key[NSha256::kDigestSize];
u[0] = 0;