mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-10 22:07:08 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -3,11 +3,6 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/StreamObjects.h"
|
||||
#include "../../Archive/Common/CoderLoader.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
#include "RarAES.h"
|
||||
#include "sha1.h"
|
||||
|
||||
@@ -28,16 +23,13 @@ CDecoder::CDecoder():
|
||||
_salt[i] = 0;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
|
||||
{
|
||||
bool thereIsSaltPrev = _thereIsSalt;
|
||||
_thereIsSalt = false;
|
||||
UINT32 processedSize;
|
||||
BYTE salt[8];
|
||||
RINOK(inStream->Read(salt, sizeof(salt), &processedSize));
|
||||
if (processedSize == 0)
|
||||
_thereIsSalt = false;
|
||||
if (processedSize != sizeof(salt))
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
if (size < 8)
|
||||
return E_INVALIDARG;
|
||||
_thereIsSalt = true;
|
||||
bool same = false;
|
||||
@@ -47,7 +39,7 @@ STDMETHODIMP CDecoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
if (_thereIsSalt)
|
||||
{
|
||||
for (int i = 0; i < sizeof(_salt); i++)
|
||||
if (_salt[i] != salt[i])
|
||||
if (_salt[i] != data[i])
|
||||
{
|
||||
same = false;
|
||||
break;
|
||||
@@ -55,19 +47,19 @@ STDMETHODIMP CDecoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < sizeof(_salt); i++)
|
||||
_salt[i] = salt[i];
|
||||
_salt[i] = data[i];
|
||||
if (!_needCalculate && !same)
|
||||
_needCalculate = true;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::CryptoSetPassword(const BYTE *data, UINT32 size)
|
||||
STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
|
||||
{
|
||||
bool same = false;
|
||||
if (size == buffer.GetCapacity())
|
||||
{
|
||||
same = true;
|
||||
for (UINT32 i = 0; i < size; i++)
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
if (data[i] != buffer[i])
|
||||
{
|
||||
same = false;
|
||||
@@ -81,16 +73,41 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const BYTE *data, UINT32 size)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UINT64 const *inSize,
|
||||
const UINT64 *outSize,ICompressProgressInfo *progress)
|
||||
STDMETHODIMP CDecoder::Init()
|
||||
{
|
||||
Calculate();
|
||||
CreateFilter();
|
||||
CMyComPtr<ICryptoProperties> cp;
|
||||
RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp));
|
||||
RINOK(cp->SetKey(aesKey, 16));
|
||||
RINOK(cp->SetInitVector(aesInit, 16));
|
||||
_aesFilter->Init();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDecoder::CreateFilter()
|
||||
{
|
||||
if (_aesFilter)
|
||||
return S_OK;
|
||||
TCHAR aesLibPath[MAX_PATH + 64];
|
||||
GetCryptoFolderPrefix(aesLibPath);
|
||||
lstrcat(aesLibPath, TEXT("AES.dll"));
|
||||
return _aesLib.LoadAndCreateFilter(aesLibPath, CLSID_CCrypto_AES128_Decoder, &_aesFilter);
|
||||
}
|
||||
|
||||
STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
return _aesFilter->Filter(data, size);
|
||||
}
|
||||
|
||||
void CDecoder::Calculate()
|
||||
{
|
||||
if (_needCalculate)
|
||||
{
|
||||
const MAXPASSWORD = 128;
|
||||
const SALT_SIZE = 8;
|
||||
const int MAXPASSWORD = 128;
|
||||
const int SALT_SIZE = 8;
|
||||
|
||||
BYTE rawPassword[2 * MAXPASSWORD+ SALT_SIZE];
|
||||
Byte rawPassword[2 * MAXPASSWORD+ SALT_SIZE];
|
||||
|
||||
memcpy(rawPassword, buffer, buffer.GetCapacity());
|
||||
|
||||
@@ -110,27 +127,36 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
for (i = 0; i < hashRounds; i++)
|
||||
{
|
||||
hash_process(&c, rawPassword, rawLength);
|
||||
BYTE pswNum[3];
|
||||
pswNum[0] = (BYTE)i;
|
||||
pswNum[1] = (BYTE)(i >> 8);
|
||||
pswNum[2] = (BYTE)(i >> 16);
|
||||
Byte pswNum[3];
|
||||
pswNum[0] = (Byte)i;
|
||||
pswNum[1] = (Byte)(i >> 8);
|
||||
pswNum[2] = (Byte)(i >> 16);
|
||||
hash_process(&c, pswNum, 3);
|
||||
if (i % (hashRounds / 16) == 0)
|
||||
{
|
||||
hash_context tempc = c;
|
||||
UINT32 digest[5];
|
||||
UInt32 digest[5];
|
||||
hash_final(&tempc, digest);
|
||||
aesInit[i / (hashRounds / 16)] = (BYTE)digest[4];
|
||||
aesInit[i / (hashRounds / 16)] = (Byte)digest[4];
|
||||
}
|
||||
}
|
||||
UINT32 digest[5];
|
||||
UInt32 digest[5];
|
||||
hash_final(&c, digest);
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int j = 0; j < 4; j++)
|
||||
aesKey[i * 4 + j] = (BYTE)(digest[i] >> (j * 8));
|
||||
aesKey[i * 4 + j] = (Byte)(digest[i] >> (j * 8));
|
||||
}
|
||||
_needCalculate = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UInt64 const *inSize,
|
||||
const UInt64 *outSize,ICompressProgressInfo *progress)
|
||||
{
|
||||
Calculate();
|
||||
TCHAR aesLibPath[MAX_PATH + 64];
|
||||
GetCryptoFolderPrefix(aesLibPath);
|
||||
lstrcat(aesLibPath, TEXT("AES.dll"));
|
||||
@@ -147,11 +173,12 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
keyStreamSpec->Init(aesKey, 16);
|
||||
|
||||
ISequentialInStream *inStreams[3] = { inStream, ivStream, keyStream };
|
||||
UINT64 ivSize = 16;
|
||||
UINT64 keySize = 16;
|
||||
const UINT64 *inSizes[3] = { inSize, &ivSize, &ivSize, };
|
||||
UInt64 ivSize = 16;
|
||||
UInt64 keySize = 16;
|
||||
const UInt64 *inSizes[3] = { inSize, &ivSize, &ivSize, };
|
||||
return aesDecoder->Code(inStreams, inSizes, 3,
|
||||
&outStream, &outSize, 1, progress);
|
||||
}
|
||||
*/
|
||||
|
||||
}}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../IPassword.h"
|
||||
#include "../../Archive/Common/CoderLoader.h"
|
||||
|
||||
#include "Common/Types.h"
|
||||
#include "Common/Buffer.h"
|
||||
@@ -14,31 +15,37 @@ namespace NCrypto {
|
||||
namespace NRar29 {
|
||||
|
||||
class CDecoder:
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties,
|
||||
public ICompressFilter,
|
||||
public ICompressSetDecoderProperties2,
|
||||
public ICryptoSetPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE _salt[8];
|
||||
Byte _salt[8];
|
||||
bool _thereIsSalt;
|
||||
CByteBuffer buffer;
|
||||
BYTE aesKey[16];
|
||||
BYTE aesInit[16];
|
||||
Byte aesKey[16];
|
||||
Byte aesInit[16];
|
||||
bool _needCalculate;
|
||||
|
||||
CCoderLibrary _aesLib;
|
||||
CMyComPtr<ICompressFilter> _aesFilter;
|
||||
|
||||
void Calculate();
|
||||
HRESULT CreateFilter();
|
||||
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP2(
|
||||
ICryptoSetPassword,
|
||||
ICompressSetDecoderProperties)
|
||||
ICompressSetDecoderProperties2)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, UINT64 const *inSize,
|
||||
const UINT64 *outSize,ICompressProgressInfo *progress);
|
||||
STDMETHOD(Init)();
|
||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
|
||||
|
||||
STDMETHOD(CryptoSetPassword)(const BYTE *aData, UINT32 aSize);
|
||||
STDMETHOD(CryptoSetPassword)(const Byte *aData, UInt32 aSize);
|
||||
|
||||
// ICompressSetDecoderProperties
|
||||
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream);
|
||||
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
|
||||
|
||||
CDecoder();
|
||||
};
|
||||
|
||||
8
7zip/Crypto/RarAES/StdAfx.h
Executable file
8
7zip/Crypto/RarAES/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
||||
@@ -52,12 +52,12 @@ By Steve Reid <steve@edmweb.com>
|
||||
|
||||
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
||||
|
||||
void SHA1Transform(UINT32 state[5], unsigned char buffer[64])
|
||||
void SHA1Transform(UInt32 state[5], unsigned char buffer[64])
|
||||
{
|
||||
UINT32 a, b, c, d, e;
|
||||
UInt32 a, b, c, d, e;
|
||||
typedef union {
|
||||
unsigned char c[64];
|
||||
UINT32 l[16];
|
||||
UInt32 l[16];
|
||||
} CHAR64LONG16;
|
||||
CHAR64LONG16* block;
|
||||
#ifdef SHA1HANDSOFF
|
||||
@@ -82,7 +82,7 @@ void SHA1Transform(UINT32 state[5], unsigned char buffer[64])
|
||||
}
|
||||
pinit=true;
|
||||
}
|
||||
UINT32 s[5];
|
||||
UInt32 s[5];
|
||||
for (int I=0;I<sizeof(s)/sizeof(s[0]);I++)
|
||||
s[I]=state[I];
|
||||
|
||||
@@ -159,7 +159,7 @@ void hash_initial(hash_context* context)
|
||||
void hash_process( hash_context * context, unsigned char * data, unsigned len )
|
||||
{
|
||||
unsigned int i, j;
|
||||
UINT32 blen = ((UINT32)len)<<3;
|
||||
UInt32 blen = ((UInt32)len)<<3;
|
||||
|
||||
j = (context->count[0] >> 3) & 63;
|
||||
if ((context->count[0] += blen) < blen ) context->count[1]++;
|
||||
@@ -180,9 +180,9 @@ void hash_process( hash_context * context, unsigned char * data, unsigned len )
|
||||
|
||||
/* Add padding and return the message digest. */
|
||||
|
||||
void hash_final( hash_context* context, UINT32 digest[5] )
|
||||
void hash_final( hash_context* context, UInt32 digest[5] )
|
||||
{
|
||||
UINT32 i, j;
|
||||
UInt32 i, j;
|
||||
unsigned char finalcount[8];
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
|
||||
@@ -4,16 +4,18 @@
|
||||
#ifndef _RAR_SHA1_
|
||||
#define _RAR_SHA1_
|
||||
|
||||
#include "../../../Common/Types.h"
|
||||
|
||||
#define HW 5
|
||||
|
||||
typedef struct {
|
||||
UINT32 state[5];
|
||||
UINT32 count[2];
|
||||
UInt32 state[5];
|
||||
UInt32 count[2];
|
||||
unsigned char buffer[64];
|
||||
} hash_context;
|
||||
|
||||
void hash_initial( hash_context * c );
|
||||
void hash_process( hash_context * c, unsigned char * data, unsigned len );
|
||||
void hash_final( hash_context * c, UINT32[HW] );
|
||||
void hash_final( hash_context * c, UInt32[HW] );
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user