4.25 beta

This commit is contained in:
Igor Pavlov
2005-08-01 00:00:00 +00:00
committed by Kornel Lesiński
parent 47f4915611
commit af1fe52701
359 changed files with 5969 additions and 9853 deletions

View File

@@ -1,8 +0,0 @@
; 7zAES.def
LIBRARY 7zAES.dll
EXPORTS
CreateObject PRIVATE
GetNumberOfMethods PRIVATE
GetMethodProperty PRIVATE

View File

@@ -93,7 +93,7 @@ LINK32=link.exe
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\7zAES.def
SOURCE=..\Codec.def
# End Source File
# Begin Source File
@@ -101,10 +101,6 @@ SOURCE=.\DllExports.cpp
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# Begin Source File

View File

@@ -138,7 +138,7 @@ void SHA256::WriteByteBlock()
Transform(m_digest, data32);
}
void SHA256::Update(const Byte *data, UInt32 size)
void SHA256::Update(const Byte *data, size_t size)
{
UInt32 curBufferPos = UInt32(m_count) & 0x3F;
while (size > 0)

View File

@@ -21,7 +21,7 @@ public:
enum {DIGESTSIZE = 32};
SHA256() { Init(); } ;
void Init();
void Update(const Byte *data, UInt32 size);
void Update(const Byte *data, size_t size);
void Final(Byte *digest);
};

46
7zip/Crypto/7zAES/makefile Executable file
View File

@@ -0,0 +1,46 @@
PROG = 7zAES.dll
DEF_FILE = ../Codec.def
CFLAGS = $(CFLAGS) -I ../../../
LIBS = $(LIBS) oleaut32.lib user32.lib
7ZAES_OBJS = \
$O\DllExports.obj \
7ZAES_OPT_OBJS = \
$O\7zAES.obj \
$O\SHA256.obj \
COMMON_OBJS = \
$O\Alloc.obj \
$O\NewHandler.obj \
$O\StringConvert.obj \
$O\Vector.obj \
WIN_OBJS = \
$O\DLL.obj \
$O\Synchronization.obj
7ZIP_COMMON_OBJS = \
$O\StreamObjects.obj \
OBJS = \
$O\StdAfx.obj \
$(7ZAES_OBJS) \
$(7ZAES_OPT_OBJS) \
$(COMMON_OBJS) \
$(WIN_OBJS) \
$(7ZIP_COMMON_OBJS) \
$O\resource.res
!include "../../../Build.mak"
$(7ZAES_OBJS): $(*B).cpp
$(COMPL)
$(7ZAES_OPT_OBJS): $(*B).cpp
$(COMPL)
$(COMMON_OBJS): ../../../Common/$(*B).cpp
$(COMPL)
$(WIN_OBJS): ../../../Windows/$(*B).cpp
$(COMPL)
$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
$(COMPL)

View File

@@ -1,15 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -1,121 +1,3 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,16,0,0
PRODUCTVERSION 4,16,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Igor Pavlov\0"
VALUE "FileDescription", "7z-AES Crypto Codec\0"
VALUE "FileVersion", "4, 16, 0, 0\0"
VALUE "InternalName", "7zAES\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2005 Igor Pavlov\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "7zAES.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "7-Zip\0"
VALUE "ProductVersion", "4, 16, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
#include "../../MyVersionInfo.rc"
MY_VERSION_INFO_DLL("7zAES Codec", "7zAES")

View File

@@ -93,7 +93,7 @@ LINK32=link.exe
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\AES.def
SOURCE=..\Codec.def
# End Source File
# Begin Source File

31
7zip/Crypto/AES/makefile Executable file
View File

@@ -0,0 +1,31 @@
PROG = AES.dll
DEF_FILE = ../Codec.def
CFLAGS = $(CFLAGS) -I ../../../
LIBS = $(LIBS) oleaut32.lib
AES_OBJS = \
$O\DllExports.obj \
AES_OPT_OBJS = \
$O\MyAES.obj \
AES_ORIG_OBJS = \
$O\aescrypt.obj \
$O\aeskey.obj \
$O\aestab.obj \
OBJS = \
$O\StdAfx.obj \
$(AES_OBJS) \
$(AES_OPT_OBJS) \
$(AES_ORIG_OBJS) \
$O\resource.res
!include "../../../Build.mak"
$(AES_OBJS): $(*B).cpp
$(COMPL)
$(AES_OPT_OBJS): $(*B).cpp
$(COMPL_O2)
$(AES_ORIG_OBJS): $(*B).c
$(COMPL_O2)

View File

@@ -1,15 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -1,121 +1,3 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,16,0,0
PRODUCTVERSION 4,16,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Igor Pavlov\0"
VALUE "FileDescription", "AES Crypto Codec\0"
VALUE "FileVersion", "4, 16, 0, 0\0"
VALUE "InternalName", "AES\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", "4, 16, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
#include "../../MyVersionInfo.rc"
MY_VERSION_INFO_DLL("AES Codec", "AES")

View File

@@ -1,7 +1,3 @@
; AES.def
LIBRARY AES.dll
EXPORTS
CreateObject PRIVATE
GetNumberOfMethods PRIVATE

View File

@@ -119,32 +119,38 @@ void CDecoder::Calculate()
rawLength += SALT_SIZE;
}
hash_context c;
hash_initial(&c);
CSHA1 sha;
sha.Init();
// seems rar reverts hash for sha.
const int hashRounds = 0x40000;
int i;
for (i = 0; i < hashRounds; i++)
{
hash_process(&c, rawPassword, rawLength);
sha.Update(rawPassword, rawLength);
Byte pswNum[3];
pswNum[0] = (Byte)i;
pswNum[1] = (Byte)(i >> 8);
pswNum[2] = (Byte)(i >> 16);
hash_process(&c, pswNum, 3);
sha.Update(pswNum, 3);
if (i % (hashRounds / 16) == 0)
{
hash_context tempc = c;
UInt32 digest[5];
hash_final(&tempc, digest);
aesInit[i / (hashRounds / 16)] = (Byte)digest[4];
CSHA1 shaTemp = sha;
Byte digest[20];
shaTemp.Final(digest);
aesInit[i / (hashRounds / 16)] = (Byte)digest[4 * 4 + 3];
}
}
UInt32 digest[5];
hash_final(&c, digest);
/*
// it's test message for sha
const char *message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
sha.Update((const Byte *)message, strlen(message));
*/
Byte digest[20];
sha.Final(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] = (digest[i * 4 + 3 - j]);
}
_needCalculate = false;
}

View File

@@ -1,111 +1,45 @@
// sha1.cpp
// This file from UnRar sources
// This file is based on public domain
// Steve Reid and Wei Dai's code from Crypto++
#include "StdAfx.h"
#include "sha1.h"
/*
SHA-1 in C
By Steve Reid <steve@edmweb.com>
100% Public Domain
static inline rotlFixed(UInt32 x, int n)
{
return (x << n) | (x >> (32 - n));
}
Test Vectors (from FIPS PUB 180-1)
"abc"
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#define blk0(i) (W[i] = data[i])
#define blk1(i) (W[i&15] = rotlFixed(W[(i+13)&15]^W[(i+8)&15]^W[(i+2)&15]^W[i&15],1))
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
#if defined(_M_IX86) || defined(_M_I86) || defined(__alpha)
#define LITTLE_ENDIAN
#else
#error "LITTLE_ENDIAN or BIG_ENDIAN must be defined"
#endif
#endif
/* #define SHA1HANDSOFF * Copies data before messing with it. */
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */
#ifdef LITTLE_ENDIAN
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|(rol(block->l[i],8)&0x00FF00FF))
#else
#define blk0(i) block->l[i]
#endif
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
^block->l[(i+2)&15]^block->l[i&15],1))
#define f1(x,y,z) (z^(x&(y^z)))
#define f2(x,y,z) (x^y^z)
#define f3(x,y,z) ((x&y)|(z&(x|y)))
#define f4(x,y,z) (x^y^z)
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) {z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);}
#define R1(v,w,x,y,z,i) {z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);}
#define R2(v,w,x,y,z,i) {z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);}
#define R3(v,w,x,y,z,i) {z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);}
#define R4(v,w,x,y,z,i) {z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);}
#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30);
#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30);
#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rotlFixed(v,5);w=rotlFixed(w,30);
#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rotlFixed(v,5);w=rotlFixed(w,30);
#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rotlFixed(v,5);w=rotlFixed(w,30);
/* Hash a single 512-bit block. This is the core of the algorithm. */
void SHA1Transform(UInt32 state[5], unsigned char buffer[64])
void CSHA1::Transform(const UInt32 data[16])
{
UInt32 a, b, c, d, e;
typedef union {
unsigned char c[64];
UInt32 l[16];
} CHAR64LONG16;
CHAR64LONG16* block;
#ifdef SHA1HANDSOFF
static unsigned char workspace[64];
block = (CHAR64LONG16*)workspace;
memcpy(block, buffer, 64);
#else
block = (CHAR64LONG16*)buffer;
#endif
#ifdef SFX_MODULE
static int pos[80][5];
static bool pinit=false;
if (!pinit)
{
for (int I=0,P=0;I<80;I++,P=(P ? P-1:4))
{
pos[I][0]=P;
pos[I][1]=(P+1)%5;
pos[I][2]=(P+2)%5;
pos[I][3]=(P+3)%5;
pos[I][4]=(P+4)%5;
}
pinit=true;
}
UInt32 s[5];
for (int I=0;I<sizeof(s)/sizeof(s[0]);I++)
s[I]=state[I];
for (int I=0;I<16;I++)
R0(s[pos[I][0]],s[pos[I][1]],s[pos[I][2]],s[pos[I][3]],s[pos[I][4]],I);
for (int I=16;I<20;I++)
R1(s[pos[I][0]],s[pos[I][1]],s[pos[I][2]],s[pos[I][3]],s[pos[I][4]],I);
for (int I=20;I<40;I++)
R2(s[pos[I][0]],s[pos[I][1]],s[pos[I][2]],s[pos[I][3]],s[pos[I][4]],I);
for (int I=40;I<60;I++)
R3(s[pos[I][0]],s[pos[I][1]],s[pos[I][2]],s[pos[I][3]],s[pos[I][4]],I);
for (int I=60;I<80;I++)
R4(s[pos[I][0]],s[pos[I][1]],s[pos[I][2]],s[pos[I][3]],s[pos[I][4]],I);
for (int I=0;I<sizeof(s)/sizeof(s[0]);I++)
state[I]+=s[I];
#else
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
UInt32 W[16];
/* Copy context->m_State[] to working vars */
a = m_State[0];
b = m_State[1];
c = m_State[2];
d = m_State[3];
e = m_State[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
@@ -127,88 +61,90 @@ void SHA1Transform(UInt32 state[5], unsigned char buffer[64])
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Add the working vars back into context.m_State[] */
m_State[0] += a;
m_State[1] += b;
m_State[2] += c;
m_State[3] += d;
m_State[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
memset(&a,0,sizeof(a));
#endif
}
void CSHA1::Init()
{
m_State[0] = 0x67452301;
m_State[1] = 0xEFCDAB89;
m_State[2] = 0x98BADCFE;
m_State[3] = 0x10325476;
m_State[4] = 0xC3D2E1F0;
m_Count = 0;
}
/* Initialize new context */
void hash_initial(hash_context* context)
void CSHA1::WriteByteBlock()
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
UInt32 data32[16];
for (int i = 0; i < 16; i++)
{
data32[i] =
(UInt32(_buffer[i * 4 + 0]) << 24) +
(UInt32(_buffer[i * 4 + 1]) << 16) +
(UInt32(_buffer[i * 4 + 2]) << 8) +
UInt32(_buffer[i * 4 + 3]);
}
Transform(data32);
}
/* Run your data through this. */
void hash_process( hash_context * context, unsigned char * data, unsigned len )
void CSHA1::Update(const Byte *data, size_t size)
{
unsigned int i, j;
UInt32 blen = ((UInt32)len)<<3;
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += blen) < blen ) context->count[1]++;
context->count[1] += (len >> 29);
if ((j + len) > 63) {
memcpy(&context->buffer[j], data, (i = 64-j));
SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
SHA1Transform(context->state, &data[i]);
UInt32 curBufferPos = UInt32(m_Count) & 0x3F;
while (size > 0)
{
while(curBufferPos < 64 && size > 0)
{
_buffer[curBufferPos++] = *data++;
m_Count++;
size--;
}
if (curBufferPos == 64)
{
curBufferPos = 0;
WriteByteBlock();
}
j = 0;
}
else i = 0;
if (len > i)
memcpy(&context->buffer[j], &data[i], len - i);
}
/* Add padding and return the message digest. */
void hash_final( hash_context* context, UInt32 digest[5] )
void CSHA1::Final(Byte *digest)
{
UInt32 i, j;
unsigned char finalcount[8];
for (i = 0; i < 8; i++) {
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
UInt64 lenInBits = (m_Count << 3);
UInt32 curBufferPos = UInt32(m_Count) & 0x3F;
_buffer[curBufferPos++] = 0x80;
while (curBufferPos != (64 - 8))
{
curBufferPos &= 0x3F;
if (curBufferPos == 0)
WriteByteBlock();
_buffer[curBufferPos++] = 0;
}
unsigned char ch='\200';
hash_process(context, &ch, 1);
while ((context->count[0] & 504) != 448) {
ch=0;
hash_process(context, &ch, 1);
for (int i = 0; i < 8; i++)
{
_buffer[curBufferPos++] = Byte(lenInBits >> 56);
lenInBits <<= 8;
}
hash_process(context, finalcount, 8); /* Should cause a SHA1Transform() */
for (i = 0; i < 5; i++) {
digest[i] = context->state[i] & 0xffffffff;
WriteByteBlock();
for (i = 0; i < 5; i++)
{
UInt32 state = m_State[i] & 0xffffffff;
*digest++ = state >> 24;
*digest++ = state >> 16;
*digest++ = state >> 8;
*digest++ = state;
}
/* Wipe variables */
memset(&i,0,sizeof(i));
memset(&j,0,sizeof(j));
memset(context->buffer, 0, 64);
memset(context->state, 0, 20);
memset(context->count, 0, 8);
memset(&finalcount, 0, 8);
#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
SHA1Transform(context->state, context->buffer);
#endif
Init();
}

View File

@@ -1,21 +1,27 @@
// sha1.h
// This file from UnRar sources
// This file is based on public domain
// Steve Reid and Wei Dai's code from Crypto++
#ifndef _RAR_SHA1_
#define _RAR_SHA1_
#ifndef __RAR_SHA1
#define __RAR_SHA1
#include <stddef.h>
#include "../../../Common/Types.h"
#define HW 5
typedef struct {
UInt32 state[5];
UInt32 count[2];
unsigned char buffer[64];
} hash_context;
struct CSHA1
{
UInt32 m_State[5];
UInt64 m_Count;
unsigned char _buffer[64];
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 Transform(const UInt32 data[16]);
void WriteByteBlock();
void Init();
void Update(const Byte *data, size_t size);
void Final(Byte *digest);
};
#endif

8
7zip/Crypto/makefile Executable file
View File

@@ -0,0 +1,8 @@
DIRS = \
7zAES\~ \
AES\~ \
all: $(DIRS)
$(DIRS):
!include "../SubBuild.mak"