This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -101,6 +101,10 @@ SOURCE=.\DllExports.cpp
# End Source File
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"StdAfx.h"
# End Source File
@@ -109,26 +113,6 @@ SOURCE=.\StdAfx.cpp
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "7zip common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Common\InBuffer.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\InBuffer.h
# End Source File
# Begin Source File
SOURCE=..\..\Common\OutBuffer.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\OutBuffer.h
# End Source File
# End Group
# Begin Group "AES"
# PROP Default_Filter ""
@@ -215,9 +199,5 @@ SOURCE=.\MyAES.cpp
SOURCE=.\MyAES.h
# End Source File
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# End Target
# End Project

View File

@@ -5,16 +5,17 @@
#include "aescpp.h"
class CAES_CBCEncoder: public AESclass
class CAES_CBC: public AESclass
{
BYTE _prevBlock[16];
protected:
Byte _prevBlock[16];
public:
void Init(const BYTE *iv)
void Init(const Byte *iv)
{
for (int i = 0; i < 16; i++)
_prevBlock[i] = iv[i];
}
void ProcessData(BYTE *outBlock, const BYTE *inBlock)
void Encode(const Byte *inBlock, Byte *outBlock)
{
int i;
for (i = 0; i < 16; i++)
@@ -23,18 +24,8 @@ public:
for (i = 0; i < 16; i++)
_prevBlock[i] = outBlock[i];
}
};
class CAES_CBCCBCDecoder: public AESclass
{
BYTE _prevBlock[16];
public:
void Init(const BYTE *iv)
{
for (int i = 0; i < 16; i++)
_prevBlock[i] = iv[i];
}
void ProcessData(BYTE *outBlock, const BYTE *inBlock)
void Decode(const Byte *inBlock, Byte *outBlock)
{
dec_blk(inBlock, outBlock);
int i;

View File

@@ -2,87 +2,10 @@
#include "StdAfx.h"
#define INITGUID
#include "Common/MyInitGuid.h"
#include "Common/ComTry.h"
#include "../../ICoder.h"
#include "MyAES.h"
/*
// {23170F69-40C1-278B-0601-000000000100}
DEFINE_GUID(CLSID_CCrypto_AES_Encoder,
0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00);
// {23170F69-40C1-278B-0601-000000000000}
DEFINE_GUID(CLSID_CCrypto_AES_Decoder,
0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
*/
/*
#include "Interface/ICoder.h"
#include "Alien/Crypto/CryptoPP/crc.h"
#include "Alien/Crypto/CryptoPP/sha.h"
#include "Alien/Crypto/CryptoPP/md2.h"
#include "Alien/Crypto/CryptoPP/md5.h"
#include "Alien/Crypto/CryptoPP/ripemd.h"
#include "Alien/Crypto/CryptoPP/haval.h"
// #include "Alien/Crypto/CryptoPP/tiger.h"
using namespace CryptoPP;
#define CLSIDName(Name) CLSID_CCryptoHash ## Name
#define ClassName(Name) aClass ## Name
// {23170F69-40C1-278B-17??-000000000000}
#define MyClassID(Name, anID) DEFINE_GUID(CLSIDName(Name), \
0x23170F69, 0x40C1, 0x278B, 0x17, anID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
#define Pair(Name, anID) MyClassID(Name, anID)\
typedef CHash<Name, &CLSIDName(Name)> ClassName(Name);
Pair(CRC32, 1)
Pair(SHA1, 2)
Pair(SHA256, 3)
Pair(SHA384, 4)
Pair(SHA512, 5)
Pair(MD2, 6)
Pair(MD5, 7)
Pair(RIPEMD160, 8)
Pair(HAVAL, 9)
// Pair(Tiger, 18)
#define My_OBJECT_ENTRY(ID) OBJECT_ENTRY(CLSIDName(ID), ClassName(ID))
BEGIN_OBJECT_MAP(ObjectMap)
My_OBJECT_ENTRY(CRC32)
My_OBJECT_ENTRY(SHA1)
My_OBJECT_ENTRY(SHA256)
My_OBJECT_ENTRY(SHA384)
My_OBJECT_ENTRY(SHA512)
My_OBJECT_ENTRY(MD2)
My_OBJECT_ENTRY(MD5)
My_OBJECT_ENTRY(RIPEMD160)
My_OBJECT_ENTRY(HAVAL)
// My_OBJECT_ENTRY(Tiger)
END_OBJECT_MAP()
*/
/*
#define MyOBJECT_ENTRY(Name) \
OBJECT_ENTRY(CLSID_CCrypto ## Name ## _Encoder, C ## Name ## _Encoder) \
OBJECT_ENTRY(CLSID_CCrypto ## Name ## _Decoder, C ## Name ## _Decoder) \
BEGIN_OBJECT_MAP(ObjectMap)
MyOBJECT_ENTRY(_AES128_CBC)
MyOBJECT_ENTRY(_AES256_CBC)
END_OBJECT_MAP()
*/
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
@@ -91,13 +14,11 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
#define MY_CreateClass(n) \
if (*clsid == CLSID_CCrypto_ ## n ## _Encoder) { \
if (!correctInterface) \
return E_NOINTERFACE; \
coder = (ICompressCoder2 *)new C ## n ## _Encoder(); \
if (!correctInterface) return E_NOINTERFACE; \
filter = (ICompressFilter *)new C ## n ## _Encoder(); \
} else if (*clsid == CLSID_CCrypto_ ## n ## _Decoder){ \
if (!correctInterface) \
return E_NOINTERFACE; \
coder = (ICompressCoder2 *)new C ## n ## _Decoder(); \
if (!correctInterface) return E_NOINTERFACE; \
filter = (ICompressFilter *)new C ## n ## _Decoder(); \
}
STDAPI CreateObject(
@@ -107,15 +28,15 @@ STDAPI CreateObject(
{
COM_TRY_BEGIN
*outObject = 0;
int correctInterface = (*interfaceID == IID_ICompressCoder2);
CMyComPtr<ICompressCoder2> coder;
int correctInterface = (*interfaceID == IID_ICompressFilter);
CMyComPtr<ICompressFilter> filter;
MY_CreateClass(AES128_CBC)
else
MY_CreateClass(AES256_CBC)
else
return CLASS_E_CLASSNOTAVAILABLE;
*outObject = coder.Detach();
*outObject = filter.Detach();
return S_OK;
COM_TRY_END
}
@@ -173,12 +94,6 @@ STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
(const char *)method.Encoder, sizeof(GUID))) != 0)
value->vt = VT_BSTR;
return S_OK;
case NMethodPropID::kInStreams:
{
value->vt = VT_UI4;
value->ulVal = 3;
return S_OK;
}
}
return S_OK;
}

View File

@@ -1,4 +1,4 @@
// Crypto/Rar20/Encoder.h
// Crypto/AES/MyAES.cpp
#include "StdAfx.h"
@@ -6,193 +6,70 @@
#include "MyAES.h"
#include "Windows/Defs.h"
#include "Common/Defs.h"
#include "AES_CBC.h"
extern "C"
{
#include "aesopt.h"
static const int kAESBlockSize = 16;
extern "C"
{
#include "aesopt.h"
}
class CTabInit
{
public:
CTabInit()
{
gen_tabs();
}
CTabInit() { gen_tabs();}
} g_TabInit;
const int kBlockSize = 16;
static HRESULT Encode(
CInBuffer &inBuffer,
COutBuffer &outBuffer,
ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress,
UINT32 keySize)
STDMETHODIMP CAESFilter::Init()
{
try
{
if (numInStreams != 3 || numOutStreams != 1)
return E_INVALIDARG;
BYTE key[32];
BYTE iv[kBlockSize];
/*
int i;
for (i = 0; i < kBlockSize; i++)
iv[i] = 1;
for (i = 0; i < keySize; i++)
key[i] = 2;
RINOK(outStreams[1]->Write(iv, kBlockSize, NULL));
RINOK(outStreams[2]->Write(key, keySize, NULL));
*/
UINT32 processedSize;
RINOK(inStreams[1]->Read(iv, kBlockSize, &processedSize));
if (processedSize != kBlockSize)
return E_FAIL;
RINOK(inStreams[2]->Read(key, keySize, &processedSize));
if (processedSize != keySize)
return E_FAIL;
CAES_CBCEncoder encoder;
encoder.enc_key(key, keySize);
encoder.Init(iv);
inBuffer.Init(inStreams[0]);
outBuffer.Init(outStreams[0]);
UINT64 nowPos = 0, posPrev = 0;
while(true)
{
BYTE inBlock[kBlockSize], outBlock[kBlockSize];
UINT32 numBytes;
inBuffer.ReadBytes(inBlock, kBlockSize, numBytes);
for (int i = numBytes; i < kBlockSize; i++)
inBlock[i] = 0;
encoder.ProcessData(outBlock, inBlock);
outBuffer.WriteBytes(outBlock, kBlockSize);
nowPos += numBytes;
if (progress != NULL && (nowPos - posPrev) > (1 << 18))
{
UINT64 outSize = nowPos - numBytes + kBlockSize;
RINOK(progress->SetRatioInfo(&nowPos, &outSize));
posPrev = nowPos;
}
if (numBytes < kBlockSize)
break;
}
return outBuffer.Flush();
// inBuffer.ReleaseStream();
// outBuffer.ReleaseStream();
// return S_OK;
}
catch(const CInBufferException &e) { return e.ErrorCode; }
catch(const COutBufferException &e) { return e.ErrorCode; }
catch(...) { return E_FAIL; }
return S_OK;
}
static HRESULT Decode(
CInBuffer &inBuffer,
COutBuffer &outBuffer,
ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress,
UINT32 keySize)
STDMETHODIMP_(UInt32) CAESFilter::Filter(Byte *data, UInt32 size)
{
try
if (size > 0 && size < kAESBlockSize)
return kAESBlockSize;
UInt32 i;
for (i = 0; i + kAESBlockSize <= size; i += kAESBlockSize)
{
if (numInStreams != 3 || numOutStreams != 1)
return E_INVALIDARG;
BYTE key[32];
BYTE iv[kBlockSize];
UINT32 processedSize;
RINOK(inStreams[1]->Read(iv, kBlockSize, &processedSize));
if (processedSize != kBlockSize)
return E_FAIL;
RINOK(inStreams[2]->Read(key, keySize, &processedSize));
if (processedSize != keySize)
return E_FAIL;
CAES_CBCCBCDecoder decoder;
decoder.dec_key(key, keySize);
decoder.Init(iv);
inBuffer.Init(inStreams[0]);
outBuffer.Init(outStreams[0]);
const UINT64 *outSize = outSizes[0];
UINT64 nowPos = 0;
UINT64 posPrev = 0;
while(true)
{
BYTE inBlock[kBlockSize], outBlock[kBlockSize];
UINT32 numBytes;
inBuffer.ReadBytes(inBlock, kBlockSize, numBytes);
if (numBytes == 0)
break;
decoder.ProcessData(outBlock, inBlock);
UINT32 numBytesToWrite = kBlockSize;
if (outSize != 0)
numBytesToWrite = (UINT32)MyMin((*outSize - nowPos), UINT64(numBytesToWrite));
outBuffer.WriteBytes(outBlock, numBytesToWrite);
nowPos += numBytesToWrite;
if (progress != NULL && (nowPos - posPrev) > (1 << 18))
{
UINT64 inSize = inBuffer.GetProcessedSize();
RINOK(progress->SetRatioInfo(&inSize, &nowPos));
posPrev = nowPos;
}
if (outSize != 0)
if (nowPos >= *outSize)
break;
}
return outBuffer.Flush();
// inBuffer.ReleaseStream();
// outBuffer.ReleaseStream();
// return S_OK;
Byte outBlock[kAESBlockSize];
SubFilter(data + i, outBlock);
for (int j = 0; j < kAESBlockSize; j++)
data[i + j] = outBlock[j];
}
catch(const CInBufferException &e) { return e.ErrorCode; }
catch(const COutBufferException &e) { return e.ErrorCode; }
catch(...) { return E_FAIL; }
return i;
}
#define MyClassCryptoImp(Name, keySize) \
STDMETHODIMP C ## Name ## _Encoder::Code( \
ISequentialInStream **inStreams, const UINT64 **inSizes, UINT32 numInStreams, \
ISequentialOutStream **outStreams, const UINT64 **outSizes, UINT32 numOutStreams, \
ICompressProgressInfo *progress) \
{ \
return Encode(_inByte, _outByte, inStreams, inSizes, numInStreams, \
outStreams, outSizes, numOutStreams, progress, keySize); \
} \
STDMETHODIMP C ## Name ## _Decoder::Code( \
ISequentialInStream **inStreams, const UINT64 **inSizes, UINT32 numInStreams, \
ISequentialOutStream **outStreams, const UINT64 **outSizes, UINT32 numOutStreams, \
ICompressProgressInfo *progress) \
{ \
return Decode(_inByte, _outByte, inStreams, inSizes, numInStreams, \
outStreams, outSizes, numOutStreams, progress, keySize); \
STDMETHODIMP CAESFilter::SetInitVector(const Byte *data, UInt32 size)
{
if (size != 16)
return E_INVALIDARG;
AES.Init(data);
return S_OK;
}
MyClassCryptoImp(AES128_CBC, 16)
MyClassCryptoImp(AES256_CBC, 32)
STDMETHODIMP CAESEncoder::SetKey(const Byte *data, UInt32 size)
{
if (AES.enc_key(data, size) != aes_good)
return E_FAIL;
return S_OK;
}
void CAESEncoder::SubFilter(const Byte *inBlock, Byte *outBlock)
{
AES.Encode(inBlock, outBlock);
}
STDMETHODIMP CAESDecoder::SetKey(const Byte *data, UInt32 size)
{
if (AES.dec_key(data, size) != aes_good)
return E_FAIL;
return S_OK;
}
void CAESDecoder::SubFilter(const Byte *inBlock, Byte *outBlock)
{
AES.Decode(inBlock, outBlock);
}

View File

@@ -1,6 +1,4 @@
// Cipher/AES/MyAES.h
#pragma once
// Crypto/AES/MyAES.h
#ifndef __CIPHER_MYAES_H
#define __CIPHER_MYAES_H
@@ -9,37 +7,53 @@
#include "Common/MyCom.h"
#include "../../ICoder.h"
#include "../../IPassword.h"
#include "../../Common/InBuffer.h"
#include "../../Common/OutBuffer.h"
#include "AES_CBC.h"
// #include "Alien/Crypto/CryptoPP/algparam.h"
// #include "Alien/Crypto/CryptoPP/modes.h"
// #include "Alien/Crypto/CryptoPP/aes.h"
#define MyClassCrypto3(Name) \
class C ## Name: \
public ICompressCoder2, \
public CMyUnknownImp { \
CInBuffer _inByte; \
COutBuffer _outByte; \
public: \
MY_UNKNOWN_IMP \
STDMETHOD(Code)( \
ISequentialInStream **inStreams, const UINT64 **inSizes, UINT32 numInStreams, \
ISequentialOutStream **outStreams, const UINT64 **outSizes, UINT32 numOutStreams, \
ICompressProgressInfo *progress); \
class CAESFilter:
public ICompressFilter,
public ICryptoProperties,
public CMyUnknownImp
{
protected:
CAES_CBC AES;
// Byte Key[32];
// Byte IV[kAESBlockSize];
public:
MY_UNKNOWN_IMP1(ICryptoProperties)
STDMETHOD(Init)();
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
STDMETHOD(SetKey)(const Byte *data, UInt32 size) = 0;
STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
virtual void SubFilter(const Byte *inBlock, Byte *outBlock) = 0;
};
class CAESEncoder: public CAESFilter
{
public:
STDMETHOD(SetKey)(const Byte *data, UInt32 size);
virtual void SubFilter(const Byte *inBlock, Byte *outBlock);
};
class CAESDecoder: public CAESFilter
{
public:
STDMETHOD(SetKey)(const Byte *data, UInt32 size);
virtual void SubFilter(const Byte *inBlock, Byte *outBlock);
};
#define MyClassCrypto3E(Name) class C ## Name: public CAESEncoder { };
#define MyClassCrypto3D(Name) class C ## Name: public CAESDecoder { };
// {23170F69-40C1-278B-0601-000000000000}
#define MyClassCrypto2(Name, id, encodingId) \
DEFINE_GUID(CLSID_CCrypto_ ## Name, \
0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, id, 0x00, 0x00, 0x00, encodingId, 0x00); \
MyClassCrypto3(Name) \
0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, id, 0x00, 0x00, 0x00, encodingId, 0x00);
#define MyClassCrypto(Name, id) \
MyClassCrypto2(Name ## _Encoder, id, 0x01) \
MyClassCrypto2(Name ## _Decoder, id, 0x00)
MyClassCrypto3E(Name ## _Encoder) \
MyClassCrypto2(Name ## _Decoder, id, 0x00) \
MyClassCrypto3D(Name ## _Decoder) \
MyClassCrypto(AES128_CBC, 0x01)
MyClassCrypto(AES256_CBC, 0x81)

View File

@@ -1,3 +1,3 @@
// StdAfx.cpp
#include "stdafx.h"
#include "StdAfx.h"

View File

@@ -1,8 +1,8 @@
// stdafx.h
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#include "../../../Common/MyWindows.h"
#endif
#endif

View File

@@ -164,7 +164,7 @@
// 2003-09-16: Changed by Igor Pavlov. Check it.
// #if defined(__GNUC__) || defined(__GNU_LIBRARY__)
#if (defined(__GNUC__) || defined(__GNU_LIBRARY__)) && !defined(WIN32)
#if (defined(__GNUC__) || defined(__GNU_LIBRARY__)) && !defined(_WIN32)
# include <endian.h>
# include <byteswap.h>
@@ -183,7 +183,7 @@
# endif
#elif defined(_MSC_VER)
# include <stdlib.h>
#elif !defined(WIN32)
#elif !defined(_WIN32)
# include <stdlib.h>
# if !defined (_ENDIAN_H)
# include <sys/param.h>

View File

@@ -66,8 +66,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,9,2,0
PRODUCTVERSION 3,9,2,0
FILEVERSION 4,16,0,0
PRODUCTVERSION 4,16,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -84,15 +84,15 @@ BEGIN
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Igor Pavlov\0"
VALUE "FileDescription", "AES Crypto\0"
VALUE "FileVersion", "3, 9, 2, 0\0"
VALUE "FileDescription", "AES Crypto Codec\0"
VALUE "FileVersion", "4, 16, 0, 0\0"
VALUE "InternalName", "AES\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2005 Igor Pavlov\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "AES.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "7-Zip\0"
VALUE "ProductVersion", "3, 9, 2, 0\0"
VALUE "ProductVersion", "4, 16, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END