diff options
Diffstat (limited to 'CPP')
95 files changed, 1039 insertions, 4862 deletions
diff --git a/CPP/7zip/Archive/7z/7zHandler.h b/CPP/7zip/Archive/7z/7zHandler.h index 95e53340..1006f204 100755 --- a/CPP/7zip/Archive/7z/7zHandler.h +++ b/CPP/7zip/Archive/7z/7zHandler.h @@ -25,17 +25,6 @@ struct CRef int ItemIndex; }; -/* -struct CRef2 -{ - CRecordVector<CRef> Refs; - UInt64 UnPackSize; - UInt64 PackSize; - UInt64 StartPos; - CRef2(): UnPackSize(0), PackSize(0), StartPos(0) {} -}; -*/ - struct CVolume { int StartRef2Index; @@ -44,10 +33,6 @@ struct CVolume }; #endif -// {23170F69-40C1-278A-1000-000110070000} -DEFINE_GUID(CLSID_CFormat7z, - 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00); - #ifndef __7Z_SET_PROPERTIES #ifdef EXTRACT_ONLY @@ -93,26 +78,7 @@ public: MY_QUERYINTERFACE_END MY_ADDREF_RELEASE - - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) #ifdef _7Z_VOL STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream); @@ -123,14 +89,7 @@ public: #endif #ifndef EXTRACT_ONLY - // IOutArchiveHandler - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - - STDMETHOD(GetFileTimeType)(UInt32 *type); - - // ISetProperties - + INTERFACE_IOutArchive(;) #endif DECL_ISetCompressCodecsInfo diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp index c9150898..4f867708 100755 --- a/CPP/7zip/Archive/7z/7zIn.cpp +++ b/CPP/7zip/Archive/7z/7zIn.cpp @@ -19,6 +19,35 @@ extern "C" namespace NArchive { namespace N7z { +class CInArchiveException {}; + +static void ThrowException() { throw CInArchiveException(); } +static inline void ThrowEndOfData() { ThrowException(); } +static inline void ThrowUnsupported() { ThrowException(); } +static inline void ThrowIncorrect() { ThrowException(); } +static inline void ThrowUnsupportedVersion() { ThrowException(); } + +/* +class CInArchiveException +{ +public: + enum CCauseType + { + kUnsupportedVersion = 0, + kUnsupported, + kIncorrect, + kEndOfData, + } Cause; + CInArchiveException(CCauseType cause): Cause(cause) {}; +}; + +static void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); } +static void ThrowEndOfData() { ThrowException(CInArchiveException::kEndOfData); } +static void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); } +static void ThrowIncorrect() { ThrowException(CInArchiveException::kIncorrect); } +static void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); } +*/ + class CStreamSwitch { CInArchive *_archive; @@ -29,7 +58,7 @@ public: void Remove(); void Set(CInArchive *archive, const Byte *data, size_t size); void Set(CInArchive *archive, const CByteBuffer &byteBuffer); - HRESULT Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector); + void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector); }; void CStreamSwitch::Remove() @@ -54,174 +83,156 @@ void CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer) Set(archive, byteBuffer, byteBuffer.GetCapacity()); } -HRESULT CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector) +void CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector) { Remove(); - Byte external; - RINOK(archive->ReadByte(external)); + Byte external = archive->ReadByte(); if (external != 0) { - CNum dataIndex; - RINOK(archive->ReadNum(dataIndex)); + int dataIndex = (int)archive->ReadNum(); + if (dataIndex < 0 || dataIndex >= dataVector->Size()) + ThrowIncorrect(); Set(archive, (*dataVector)[dataIndex]); } - return S_OK; } - -CInArchiveException::CInArchiveException(CCauseType cause): - Cause(cause) -{} +#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__) +#define SZ_LITTLE_ENDIAN_UNALIGN +#endif -HRESULT CInArchive::ReadDirect(IInStream *stream, void *data, UInt32 size, - UInt32 *processedSize) -{ - UInt32 realProcessedSize; - HRESULT result = ReadStream(stream, data, size, &realProcessedSize); - if(processedSize != NULL) - *processedSize = realProcessedSize; - _position += realProcessedSize; - return result; -} +#ifdef SZ_LITTLE_ENDIAN_UNALIGN +static inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; } +static inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; } +static inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; } +#else +static inline UInt16 GetUInt16FromMem(const Byte *p) { return p[0] | ((UInt16)p[1] << 8); } +static inline UInt32 GetUInt32FromMem(const Byte *p) { return p[0] | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16) | ((UInt32)p[3] << 24); } +static inline UInt64 GetUInt64FromMem(const Byte *p) { return GetUInt32FromMem(p) | ((UInt64)GetUInt32FromMem(p + 4) << 32); } +#endif -HRESULT CInArchive::ReadDirect(void *data, UInt32 size, UInt32 *processedSize) +Byte CInByte2::ReadByte() { - return ReadDirect(_stream, data, size, processedSize); + if (_pos >= _size) + ThrowEndOfData(); + return _buffer[_pos++]; } -HRESULT CInArchive::SafeReadDirect(void *data, UInt32 size) +void CInByte2::ReadBytes(Byte *data, size_t size) { - UInt32 realProcessedSize; - RINOK(ReadDirect(data, size, &realProcessedSize)); - if (realProcessedSize != size) - throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive); - return S_OK; + if (size > _size - _pos) + ThrowEndOfData(); + for (size_t i = 0; i < size; i++) + data[i] = _buffer[_pos++]; } -HRESULT CInArchive::SafeReadDirectByte(Byte &b) +void CInByte2::SkeepData(UInt64 size) { - return SafeReadDirect(&b, 1); + if (size > _size - _pos) + ThrowEndOfData(); } -HRESULT CInArchive::SafeReadDirectUInt32(UInt32 &value, UInt32 &crc) +void CInByte2::SkeepData() { - value = 0; - for (int i = 0; i < 4; i++) - { - Byte b; - RINOK(SafeReadDirectByte(b)); - value |= (UInt32(b) << (8 * i)); - crc = CRC_UPDATE_BYTE(crc, b); - } - return S_OK; + SkeepData(ReadNumber()); } -HRESULT CInArchive::SafeReadDirectUInt64(UInt64 &value, UInt32 &crc) +UInt64 CInByte2::ReadNumber() { - value = 0; - for (int i = 0; i < 8; i++) - { - Byte b; - RINOK(SafeReadDirectByte(b)); - value |= (UInt64(b) << (8 * i)); - crc = CRC_UPDATE_BYTE(crc, b); - } - return S_OK; -} - -HRESULT CInArchive::ReadNumber(UInt64 &value) -{ - Byte firstByte; - RINOK(ReadByte(firstByte)); + if (_pos >= _size) + ThrowEndOfData(); + Byte firstByte = _buffer[_pos++]; Byte mask = 0x80; - value = 0; + UInt64 value = 0; for (int i = 0; i < 8; i++) { if ((firstByte & mask) == 0) { UInt64 highPart = firstByte & (mask - 1); value += (highPart << (i * 8)); - return S_OK; + return value; } - Byte b; - RINOK(ReadByte(b)); - value |= (UInt64(b) << (8 * i)); + if (_pos >= _size) + ThrowEndOfData(); + value |= ((UInt64)_buffer[_pos++] << (8 * i)); mask >>= 1; } - return S_OK; + return value; } -HRESULT CInArchive::ReadNum(CNum &value) +CNum CInByte2::ReadNum() { - UInt64 value64; - RINOK(ReadNumber(value64)); - if (value64 > kNumMax) - return E_FAIL; - value = (CNum)value64; - return S_OK; + UInt64 value = ReadNumber(); + if (value > kNumMax) + ThrowUnsupported(); + return (CNum)value; } -HRESULT CInArchive::ReadUInt32(UInt32 &value) +UInt32 CInByte2::ReadUInt32() { - value = 0; - for (int i = 0; i < 4; i++) - { - Byte b; - RINOK(ReadByte(b)); - value |= (UInt32(b) << (8 * i)); - } - return S_OK; + if (_pos + 4 > _size) + ThrowEndOfData(); + UInt32 res = GetUInt32FromMem(_buffer + _pos); + _pos += 4; + return res; } -HRESULT CInArchive::ReadUInt64(UInt64 &value) +UInt64 CInByte2::ReadUInt64() { - value = 0; - for (int i = 0; i < 8; i++) - { - Byte b; - RINOK(ReadByte(b)); - value |= (UInt64(b) << (8 * i)); - } - return S_OK; + if (_pos + 8 > _size) + ThrowEndOfData(); + UInt64 res = GetUInt64FromMem(_buffer + _pos); + _pos += 8; + return res; } -static inline bool TestSignatureCandidate(const void *testBytes) +void CInByte2::ReadString(UString &s) { - for (int i = 0; i < kSignatureSize; i++) - if (((const Byte *)testBytes)[i] != kSignature[i]) - return false; - return true; + const Byte *buf = _buffer + _pos; + size_t rem = (_size - _pos) / 2; + { + size_t i; + for (i = 0; i < rem; i += 2) + if (buf[i] == 0 && buf[i + 1] == 0) + break; + if (i == rem) + ThrowEndOfData(); + rem = i; + } + int len = (int)(rem / 2); + if (len < 0 || (size_t)len * 2 != rem) + ThrowUnsupported(); + wchar_t *p = s.GetBuffer(len); + int i; + for (i = 0; i < len; i++, buf += 2) + p[i] = (wchar_t)GetUInt16FromMem(buf); + p[i] = 0; + s.ReleaseBuffer(len); + _pos += rem + 2; } -#ifdef _7Z_VOL -static inline bool TestFinishSignatureCandidate(const void *testBytes) +static inline bool TestSignatureCandidate(const Byte *p) { for (int i = 0; i < kSignatureSize; i++) - if (((const Byte *)testBytes)[i] != kFinishSignature[i]) + if (p[i] != kSignature[i]) return false; - return true; + return (p[0x1A] == 0 && p[0x1B] == 0); } -#endif HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit) { - _position = _arhiveBeginStreamPosition; - RINOK(stream->Seek(_arhiveBeginStreamPosition, STREAM_SEEK_SET, NULL)); - - Byte signature[kSignatureSize]; UInt32 processedSize; - RINOK(ReadDirect(stream, signature, kSignatureSize, &processedSize)); - if(processedSize != kSignatureSize) + RINOK(ReadStream(stream, _header, kHeaderSize, &processedSize)); + if (processedSize != kHeaderSize) return S_FALSE; - if (TestSignatureCandidate(signature)) + if (TestSignatureCandidate(_header)) return S_OK; CByteBuffer byteBuffer; const UInt32 kBufferSize = (1 << 16); byteBuffer.SetCapacity(kBufferSize); Byte *buffer = byteBuffer; - UInt32 numPrevBytes = kSignatureSize - 1; - memmove(buffer, signature + 1, numPrevBytes); + UInt32 numPrevBytes = kHeaderSize - 1; + memcpy(buffer, _header + 1, numPrevBytes); UInt64 curTestPos = _arhiveBeginStreamPosition + 1; for (;;) { @@ -229,18 +240,18 @@ HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *search if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit) break; UInt32 numReadBytes = kBufferSize - numPrevBytes; - RINOK(ReadDirect(stream, buffer + numPrevBytes, numReadBytes, &processedSize)); + RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize)); UInt32 numBytesInBuffer = numPrevBytes + processedSize; - if (numBytesInBuffer < kSignatureSize) + if (numBytesInBuffer < kHeaderSize) break; - UInt32 numTests = numBytesInBuffer - kSignatureSize + 1; + UInt32 numTests = numBytesInBuffer - kHeaderSize + 1; for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++) { if (TestSignatureCandidate(buffer + pos)) { + memcpy(_header, buffer + pos, kHeaderSize); _arhiveBeginStreamPosition = curTestPos; - _position = curTestPos + kSignatureSize; - return stream->Seek(_position, STREAM_SEEK_SET, NULL); + return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL); } } numPrevBytes = numBytesInBuffer - numTests; @@ -249,76 +260,12 @@ HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *search return S_FALSE; } -// Out: _position must point to end of signature - -#ifdef _7Z_VOL -HRESULT CInArchive::FindFinishSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit) -{ - RINOK(stream->Seek(0, STREAM_SEEK_END, &_position)); - if (_position < kSignatureSize) - return S_FALSE; - - CByteBuffer byteBuffer; - const UInt32 kBufferSize = (1 << 18); - byteBuffer.SetCapacity(kBufferSize); - Byte *buffer = byteBuffer; - UInt32 numPrevBytes = 0; - UInt64 limitPos = 0; - if (searchHeaderSizeLimit != NULL) - if (*searchHeaderSizeLimit < _position) - limitPos = _position - *searchHeaderSizeLimit; - - while(_position >= limitPos) - { - UInt32 numReadBytes = kBufferSize - numPrevBytes; - if (numReadBytes > _position) - numReadBytes = (UInt32)_position; - UInt32 numBytesInBuffer = numPrevBytes + numReadBytes; - if (numBytesInBuffer < kSignatureSize) - return S_FALSE; - _position -= numReadBytes; - RINOK(stream->Seek(_position, STREAM_SEEK_SET, &_position)); - UInt32 startPos = kBufferSize - numBytesInBuffer; - UInt32 processedSize; - RINOK(ReadDirect(stream, buffer + startPos, numReadBytes, &processedSize)); - if (processedSize != numReadBytes) - return S_FALSE; - _position -= processedSize; - for(UInt32 pos = kBufferSize; pos >= startPos + kSignatureSize; pos--) - { - if (TestFinishSignatureCandidate(buffer + pos - kSignatureSize)) - { - _position += pos - startPos; - return stream->Seek(_position, STREAM_SEEK_SET, NULL); - } - } - numPrevBytes = kSignatureSize - 1; - memmove(buffer + kBufferSize - numPrevBytes, buffer + startPos + 1, numPrevBytes); - } - return S_FALSE; -} -#endif - // S_FALSE means that file is not archive HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit) { Close(); RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition)) - _position = _arhiveBeginStreamPosition; - #ifdef _7Z_VOL - HRESULT result = FindFinishSignature(stream, searchHeaderSizeLimit); - if (result == S_OK) - _finishSignature = true; - else - { - if (result != S_FALSE) - return result; - _finishSignature = false; - RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit)); - } - #else RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit)); - #endif _stream = stream; return S_OK; } @@ -328,40 +275,19 @@ void CInArchive::Close() _stream.Release(); } -HRESULT CInArchive::SkeepData(UInt64 size) -{ - for (UInt64 i = 0; i < size; i++) - { - Byte temp; - RINOK(ReadByte(temp)); - } - return S_OK; -} - -HRESULT CInArchive::SkeepData() -{ - UInt64 size; - RINOK(ReadNumber(size)); - return SkeepData(size); -} - -HRESULT CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */) +void CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */) { for (;;) { - UInt64 type; - RINOK(ReadID(type)); - if (type == NID::kEnd) + if (ReadID() == NID::kEnd) break; SkeepData(); } - return S_OK; } -HRESULT CInArchive::GetNextFolderItem(CFolder &folder) +void CInArchive::GetNextFolderItem(CFolder &folder) { - CNum numCoders; - RINOK(ReadNum(numCoders)); + CNum numCoders = ReadNum(); folder.Coders.Clear(); folder.Coders.Reserve((int)numCoders); @@ -374,13 +300,12 @@ HRESULT CInArchive::GetNextFolderItem(CFolder &folder) CCoderInfo &coder = folder.Coders.Back(); { - Byte mainByte = 0; - RINOK(ReadByte(mainByte)); + Byte mainByte = ReadByte(); int idSize = (mainByte & 0xF); - BYTE longID[15]; - RINOK(ReadBytes(longID, idSize)); + Byte longID[15]; + ReadBytes(longID, idSize); if (idSize > 8) - return S_FALSE; + ThrowUnsupported(); UInt64 id = 0; for (int j = 0; j < idSize; j++) id |= (UInt64)longID[idSize - 1 - j] << (8 * j); @@ -388,8 +313,8 @@ HRESULT CInArchive::GetNextFolderItem(CFolder &folder) if ((mainByte & 0x10) != 0) { - RINOK(ReadNum(coder.NumInStreams)); - RINOK(ReadNum(coder.NumOutStreams)); + coder.NumInStreams = ReadNum(); + coder.NumOutStreams = ReadNum(); } else { @@ -398,28 +323,26 @@ HRESULT CInArchive::GetNextFolderItem(CFolder &folder) } if ((mainByte & 0x20) != 0) { - CNum propertiesSize = 0; - RINOK(ReadNum(propertiesSize)); + CNum propertiesSize = ReadNum(); coder.Properties.SetCapacity((size_t)propertiesSize); - RINOK(ReadBytes((Byte *)coder.Properties, (size_t)propertiesSize)); + ReadBytes((Byte *)coder.Properties, (size_t)propertiesSize); } if ((mainByte & 0x80) != 0) - return S_FALSE; + ThrowUnsupported(); } numInStreams += coder.NumInStreams; numOutStreams += coder.NumOutStreams; } CNum numBindPairs; - // RINOK(ReadNumber(numBindPairs)); numBindPairs = numOutStreams - 1; folder.BindPairs.Clear(); folder.BindPairs.Reserve(numBindPairs); for (i = 0; i < numBindPairs; i++) { CBindPair bindPair; - RINOK(ReadNum(bindPair.InIndex)); - RINOK(ReadNum(bindPair.OutIndex)); + bindPair.InIndex = ReadNum(); + bindPair.OutIndex = ReadNum(); folder.BindPairs.Add(bindPair); } @@ -436,78 +359,65 @@ HRESULT CInArchive::GetNextFolderItem(CFolder &folder) } else for(i = 0; i < numPackedStreams; i++) - { - CNum packStreamInfo; - RINOK(ReadNum(packStreamInfo)); - folder.PackStreams.Add(packStreamInfo); - } - - return S_OK; + folder.PackStreams.Add(ReadNum()); } -HRESULT CInArchive::WaitAttribute(UInt64 attribute) +void CInArchive::WaitAttribute(UInt64 attribute) { for (;;) { - UInt64 type; - RINOK(ReadID(type)); + UInt64 type = ReadID(); if (type == attribute) - return S_OK; + return; if (type == NID::kEnd) - return S_FALSE; - RINOK(SkeepData()); + ThrowIncorrect(); + SkeepData(); } } -HRESULT CInArchive::ReadHashDigests(int numItems, +void CInArchive::ReadHashDigests(int numItems, CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests) { - RINOK(ReadBoolVector2(numItems, digestsDefined)); + ReadBoolVector2(numItems, digestsDefined); digests.Clear(); digests.Reserve(numItems); for(int i = 0; i < numItems; i++) { UInt32 crc = 0; if (digestsDefined[i]) - RINOK(ReadUInt32(crc)); + crc = ReadUInt32(); digests.Add(crc); } - return S_OK; } -HRESULT CInArchive::ReadPackInfo( +void CInArchive::ReadPackInfo( UInt64 &dataOffset, CRecordVector<UInt64> &packSizes, CRecordVector<bool> &packCRCsDefined, CRecordVector<UInt32> &packCRCs) { - RINOK(ReadNumber(dataOffset)); - CNum numPackStreams; - RINOK(ReadNum(numPackStreams)); + dataOffset = ReadNumber(); + CNum numPackStreams = ReadNum(); - RINOK(WaitAttribute(NID::kSize)); + WaitAttribute(NID::kSize); packSizes.Clear(); packSizes.Reserve(numPackStreams); - for(CNum i = 0; i < numPackStreams; i++) - { - UInt64 size; - RINOK(ReadNumber(size)); - packSizes.Add(size); - } + for (CNum i = 0; i < numPackStreams; i++) + packSizes.Add(ReadNumber()); UInt64 type; for (;;) { - RINOK(ReadID(type)); + type = ReadID(); if (type == NID::kEnd) break; if (type == NID::kCRC) { - RINOK(ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs)); + ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs); continue; } - RINOK(SkeepData()); + SkeepData(); } if (packCRCsDefined.IsEmpty()) { @@ -521,56 +431,49 @@ HRESULT CInArchive::ReadPackInfo( packCRCs.Add(0); } } - return S_OK; } -HRESULT CInArchive::ReadUnPackInfo( +void CInArchive::ReadUnPackInfo( const CObjectVector<CByteBuffer> *dataVector, CObjectVector<CFolder> &folders) { - RINOK(WaitAttribute(NID::kFolder)); - CNum numFolders; - RINOK(ReadNum(numFolders)); + WaitAttribute(NID::kFolder); + CNum numFolders = ReadNum(); { CStreamSwitch streamSwitch; - RINOK(streamSwitch.Set(this, dataVector)); + streamSwitch.Set(this, dataVector); folders.Clear(); - folders.Reserve((UInt32)numFolders); + folders.Reserve(numFolders); for(CNum i = 0; i < numFolders; i++) { folders.Add(CFolder()); - RINOK(GetNextFolderItem(folders.Back())); + GetNextFolderItem(folders.Back()); } } - RINOK(WaitAttribute(NID::kCodersUnPackSize)); + WaitAttribute(NID::kCodersUnPackSize); CNum i; - for(i = 0; i < numFolders; i++) + for (i = 0; i < numFolders; i++) { CFolder &folder = folders[i]; CNum numOutStreams = folder.GetNumOutStreams(); folder.UnPackSizes.Reserve(numOutStreams); - for(CNum j = 0; j < numOutStreams; j++) - { - UInt64 unPackSize; - RINOK(ReadNumber(unPackSize)); - folder.UnPackSizes.Add(unPackSize); - } + for (CNum j = 0; j < numOutStreams; j++) + folder.UnPackSizes.Add(ReadNumber()); } for (;;) { - UInt64 type; - RINOK(ReadID(type)); + UInt64 type = ReadID(); if (type == NID::kEnd) - return S_OK; + return; if (type == NID::kCRC) { CRecordVector<bool> crcsDefined; CRecordVector<UInt32> crcs; - RINOK(ReadHashDigests(numFolders, crcsDefined, crcs)); + ReadHashDigests(numFolders, crcsDefined, crcs); for(i = 0; i < numFolders; i++) { CFolder &folder = folders[i]; @@ -579,11 +482,11 @@ HRESULT CInArchive::ReadUnPackInfo( } continue; } - RINOK(SkeepData()); + SkeepData(); } } -HRESULT CInArchive::ReadSubStreamsInfo( +void CInArchive::ReadSubStreamsInfo( const CObjectVector<CFolder> &folders, CRecordVector<CNum> &numUnPackStreamsInFolders, CRecordVector<UInt64> &unPackSizes, @@ -595,22 +498,18 @@ HRESULT CInArchive::ReadSubStreamsInfo( UInt64 type; for (;;) { - RINOK(ReadID(type)); + type = ReadID(); if (type == NID::kNumUnPackStream) { for(int i = 0; i < folders.Size(); i++) - { - CNum value; - RINOK(ReadNum(value)); - numUnPackStreamsInFolders.Add(value); - } + numUnPackStreamsInFolders.Add(ReadNum()); continue; } if (type == NID::kCRC || type == NID::kSize) break; if (type == NID::kEnd) break; - RINOK(SkeepData()); + SkeepData(); } if (numUnPackStreamsInFolders.IsEmpty()) @@ -627,21 +526,16 @@ HRESULT CInArchive::ReadSubStreamsInfo( continue; UInt64 sum = 0; for (CNum j = 1; j < numSubstreams; j++) - { - UInt64 size; if (type == NID::kSize) { - RINOK(ReadNumber(size)); + UInt64 size = ReadNumber(); unPackSizes.Add(size); sum += size; } - } unPackSizes.Add(folders[i].GetUnPackSize() - sum); } if (type == NID::kSize) - { - RINOK(ReadID(type)); - } + type = ReadID(); int numDigests = 0; int numDigestsTotal = 0; @@ -659,7 +553,7 @@ HRESULT CInArchive::ReadSubStreamsInfo( { CRecordVector<bool> digestsDefined2; CRecordVector<UInt32> digests2; - RINOK(ReadHashDigests(numDigests, digestsDefined2, digests2)); + ReadHashDigests(numDigests, digestsDefined2, digests2); int digestIndex = 0; for (i = 0; i < folders.Size(); i++) { @@ -690,17 +584,15 @@ HRESULT CInArchive::ReadSubStreamsInfo( digests.Add(0); } } - return S_OK; + return; } else - { - RINOK(SkeepData()); - } - RINOK(ReadID(type)); + SkeepData(); + type = ReadID(); } } -HRESULT CInArchive::ReadStreamsInfo( +void CInArchive::ReadStreamsInfo( const CObjectVector<CByteBuffer> *dataVector, UInt64 &dataOffset, CRecordVector<UInt64> &packSizes, @@ -714,52 +606,32 @@ HRESULT CInArchive::ReadStreamsInfo( { for (;;) { - UInt64 type; - RINOK(ReadID(type)); + UInt64 type = ReadID(); switch(type) { case NID::kEnd: - return S_OK; + return; case NID::kPackInfo: { - RINOK(ReadPackInfo(dataOffset, packSizes, - packCRCsDefined, packCRCs)); + ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs); break; } case NID::kUnPackInfo: { - RINOK(ReadUnPackInfo(dataVector, folders)); + ReadUnPackInfo(dataVector, folders); break; } case NID::kSubStreamsInfo: { - RINOK(ReadSubStreamsInfo(folders, numUnPackStreamsInFolders, - unPackSizes, digestsDefined, digests)); + ReadSubStreamsInfo(folders, numUnPackStreamsInFolders, + unPackSizes, digestsDefined, digests); break; } } } } -HRESULT CInArchive::ReadFileNames(CObjectVector<CFileItem> &files) -{ - for(int i = 0; i < files.Size(); i++) - { - UString &name = files[i].Name; - name.Empty(); - for (;;) - { - wchar_t c; - RINOK(ReadWideCharLE(c)); - if (c == L'\0') - break; - name += c; - } - } - return S_OK; -} - -HRESULT CInArchive::ReadBoolVector(int numItems, CBoolVector &v) +void CInArchive::ReadBoolVector(int numItems, CBoolVector &v) { v.Clear(); v.Reserve(numItems); @@ -769,36 +641,36 @@ HRESULT CInArchive::ReadBoolVector(int numItems, CBoolVector &v) { if (mask == 0) { - RINOK(ReadByte(b)); + b = ReadByte(); mask = 0x80; } v.Add((b & mask) != 0); mask >>= 1; } - return S_OK; } -HRESULT CInArchive::ReadBoolVector2(int numItems, CBoolVector &v) +void CInArchive::ReadBoolVector2(int numItems, CBoolVector &v) { - Byte allAreDefined; - RINOK(ReadByte(allAreDefined)); + Byte allAreDefined = ReadByte(); if (allAreDefined == 0) - return ReadBoolVector(numItems, v); + { + ReadBoolVector(numItems, v); + return; + } v.Clear(); v.Reserve(numItems); for (int i = 0; i < numItems; i++) v.Add(true); - return S_OK; } -HRESULT CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector, +void CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector, CObjectVector<CFileItem> &files, UInt64 type) { CBoolVector boolVector; - RINOK(ReadBoolVector2(files.Size(), boolVector)) + ReadBoolVector2(files.Size(), boolVector); CStreamSwitch streamSwitch; - RINOK(streamSwitch.Set(this, &dataVector)); + streamSwitch.Set(this, &dataVector); for(int i = 0; i < files.Size(); i++) { @@ -809,11 +681,8 @@ HRESULT CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector, bool defined = boolVector[i]; if (defined) { - UInt32 low, high; - RINOK(ReadUInt32(low)); - RINOK(ReadUInt32(high)); - fileTime.dwLowDateTime = low; - fileTime.dwHighDateTime = high; + fileTime.dwLowDateTime = ReadUInt32(); + fileTime.dwHighDateTime = ReadUInt32(); } switch(type) { @@ -834,7 +703,6 @@ HRESULT CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector, break; } } - return S_OK; } HRESULT CInArchive::ReadAndDecodePackedStreams( @@ -856,7 +724,7 @@ HRESULT CInArchive::ReadAndDecodePackedStreams( CRecordVector<bool> digestsDefined; CRecordVector<UInt32> digests; - RINOK(ReadStreamsInfo(NULL, + ReadStreamsInfo(NULL, dataOffset, packSizes, packCRCsDefined, @@ -865,7 +733,7 @@ HRESULT CInArchive::ReadAndDecodePackedStreams( numUnPackStreamsInFolders, unPackSizes, digestsDefined, - digests)); + digests); // database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader; @@ -883,16 +751,15 @@ HRESULT CInArchive::ReadAndDecodePackedStreams( const CFolder &folder = folders[i]; dataVector.Add(CByteBuffer()); CByteBuffer &data = dataVector.Back(); - UInt64 unPackSize = folder.GetUnPackSize(); - if (unPackSize > kNumMax) - return E_FAIL; - if (unPackSize > 0xFFFFFFFF) - return E_FAIL; - data.SetCapacity((size_t)unPackSize); + UInt64 unPackSize64 = folder.GetUnPackSize(); + size_t unPackSize = (size_t)unPackSize64; + if (unPackSize != unPackSize64) + ThrowUnsupported(); + data.SetCapacity(unPackSize); CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2; CMyComPtr<ISequentialOutStream> outStream = outStreamSpec; - outStreamSpec->Init(data, (size_t)unPackSize); + outStreamSpec->Init(data, unPackSize); HRESULT result = decoder.Decode( EXTERNAL_CODECS_LOC_VARS @@ -908,8 +775,8 @@ HRESULT CInArchive::ReadAndDecodePackedStreams( RINOK(result); if (folder.UnPackCRCDefined) - if (CrcCalc(data, (UInt32)unPackSize) != folder.UnPackCRC) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + if (CrcCalc(data, unPackSize) != folder.UnPackCRC) + ThrowIncorrect(); for (int j = 0; j < folder.PackStreams.Size(); j++) dataStartPos += packSizes[packIndex++]; } @@ -924,13 +791,12 @@ HRESULT CInArchive::ReadHeader( #endif ) { - UInt64 type; - RINOK(ReadID(type)); + UInt64 type = ReadID(); if (type == NID::kArchiveProperties) { - RINOK(ReadArchiveProperties(database.ArchiveInfo)); - RINOK(ReadID(type)); + ReadArchiveProperties(database.ArchiveInfo); + type = ReadID(); } CObjectVector<CByteBuffer> dataVector; @@ -948,7 +814,7 @@ HRESULT CInArchive::ReadHeader( ); RINOK(result); database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader; - RINOK(ReadID(type)); + type = ReadID(); } CRecordVector<UInt64> unPackSizes; @@ -957,7 +823,7 @@ HRESULT CInArchive::ReadHeader( if (type == NID::kMainStreamsInfo) { - RINOK(ReadStreamsInfo(&dataVector, + ReadStreamsInfo(&dataVector, database.ArchiveInfo.DataStartPosition, database.PackSizes, database.PackCRCsDefined, @@ -966,9 +832,9 @@ HRESULT CInArchive::ReadHeader( database.NumUnPackStreamsVector, unPackSizes, digestsDefined, - digests)); + digests); database.ArchiveInfo.DataStartPosition += database.ArchiveInfo.StartPositionAfterHeader; - RINOK(ReadID(type)); + type = ReadID(); } else { @@ -987,10 +853,9 @@ HRESULT CInArchive::ReadHeader( if (type == NID::kEnd) return S_OK; if (type != NID::kFilesInfo) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + ThrowIncorrect(); - CNum numFiles; - RINOK(ReadNum(numFiles)); + CNum numFiles = ReadNum(); database.Files.Reserve(numFiles); CNum i; for(i = 0; i < numFiles; i++) @@ -1010,73 +875,56 @@ HRESULT CInArchive::ReadHeader( CBoolVector antiFileVector; CNum numEmptyStreams = 0; - // int sizePrev = -1; - // int posPrev = 0; - for (;;) { - /* - if (sizePrev >= 0) - if (sizePrev != _inByteBack->GetProcessedSize() - posPrev) - throw 2; - */ - UInt64 type; - RINOK(ReadID(type)); + UInt64 type = ReadID(); if (type == NID::kEnd) break; - UInt64 size; - RINOK(ReadNumber(size)); - - // sizePrev = size; - // posPrev = _inByteBack->GetProcessedSize(); - + UInt64 size = ReadNumber(); database.ArchiveInfo.FileInfoPopIDs.Add(type); switch(type) { case NID::kName: { CStreamSwitch streamSwitch; - RINOK(streamSwitch.Set(this, &dataVector)); - RINOK(ReadFileNames(database.Files)) + streamSwitch.Set(this, &dataVector); + for(int i = 0; i < database.Files.Size(); i++) + _inByteBack->ReadString(database.Files[i].Name); break; } case NID::kWinAttributes: { CBoolVector boolVector; - RINOK(ReadBoolVector2(database.Files.Size(), boolVector)) + ReadBoolVector2(database.Files.Size(), boolVector); CStreamSwitch streamSwitch; - RINOK(streamSwitch.Set(this, &dataVector)); + streamSwitch.Set(this, &dataVector); for(i = 0; i < numFiles; i++) { CFileItem &file = database.Files[i]; file.AreAttributesDefined = boolVector[i]; if (file.AreAttributesDefined) - { - RINOK(ReadUInt32(file.Attributes)); - } + file.Attributes = ReadUInt32(); } break; } case NID::kStartPos: { CBoolVector boolVector; - RINOK(ReadBoolVector2(database.Files.Size(), boolVector)) + ReadBoolVector2(database.Files.Size(), boolVector); CStreamSwitch streamSwitch; - RINOK(streamSwitch.Set(this, &dataVector)); + streamSwitch.Set(this, &dataVector); for(i = 0; i < numFiles; i++) { CFileItem &file = database.Files[i]; file.IsStartPosDefined = boolVector[i]; if (file.IsStartPosDefined) - { - RINOK(ReadUInt64(file.StartPos)); - } + file.StartPos = ReadUInt64(); } break; } case NID::kEmptyStream: { - RINOK(ReadBoolVector(numFiles, emptyStreamVector)) + ReadBoolVector(numFiles, emptyStreamVector); for (i = 0; i < (CNum)emptyStreamVector.Size(); i++) if (emptyStreamVector[i]) numEmptyStreams++; @@ -1091,25 +939,25 @@ HRESULT CInArchive::ReadHeader( } case NID::kEmptyFile: { - RINOK(ReadBoolVector(numEmptyStreams, emptyFileVector)) + ReadBoolVector(numEmptyStreams, emptyFileVector); break; } case NID::kAnti: { - RINOK(ReadBoolVector(numEmptyStreams, antiFileVector)) + ReadBoolVector(numEmptyStreams, antiFileVector); break; } case NID::kCreationTime: case NID::kLastWriteTime: case NID::kLastAccessTime: { - RINOK(ReadTime(dataVector, database.Files, type)) + ReadTime(dataVector, database.Files, type); break; } default: { database.ArchiveInfo.FileInfoPopIDs.DeleteBack(); - RINOK(SkeepData(size)); + SkeepData(size); } } } @@ -1191,7 +1039,7 @@ void CArchiveDatabaseEx::FillFolderStartFileIndex() for (;;) { if (folderIndex >= Folders.Size()) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + ThrowIncorrect(); FolderStartFileIndex.Add(i); // check it if (NumUnPackStreamsVector[folderIndex] != 0) break; @@ -1210,7 +1058,7 @@ void CArchiveDatabaseEx::FillFolderStartFileIndex() } } -HRESULT CInArchive::ReadDatabase( +HRESULT CInArchive::ReadDatabase2( DECL_EXTERNAL_CODECS_LOC_VARS CArchiveDatabaseEx &database #ifndef _NO_CRYPTO @@ -1221,30 +1069,17 @@ HRESULT CInArchive::ReadDatabase( database.Clear(); database.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition; + database.ArchiveInfo.Version.Major = _header[6]; + database.ArchiveInfo.Version.Minor = _header[7]; - RINOK(SafeReadDirect(&database.ArchiveInfo.Version.Major, 1)); - RINOK(SafeReadDirect(&database.ArchiveInfo.Version.Minor, 1)); if (database.ArchiveInfo.Version.Major != kMajorVersion) - throw CInArchiveException(CInArchiveException::kUnsupportedVersion); - - #ifdef _7Z_VOL - if (_finishSignature) - { - RINOK(_stream->Seek(_position - (4 + kFinishHeaderSize) - - (kSignatureSize + 2), STREAM_SEEK_SET, &_position)); - } - #endif + ThrowUnsupportedVersion(); - UInt32 crcFromArchive; - UInt64 nextHeaderOffset; - UInt64 nextHeaderSize; - UInt32 nextHeaderCRC; - UInt32 crc = CRC_INIT_VAL; - UInt32 temp = 0; - RINOK(SafeReadDirectUInt32(crcFromArchive, temp)); - RINOK(SafeReadDirectUInt64(nextHeaderOffset, crc)); - RINOK(SafeReadDirectUInt64(nextHeaderSize, crc)); - RINOK(SafeReadDirectUInt32(nextHeaderCRC, crc)); + UInt32 crcFromArchive = GetUInt32FromMem(_header + 8); + UInt64 nextHeaderOffset = GetUInt64FromMem(_header + 0xC); + UInt64 nextHeaderSize = GetUInt64FromMem(_header + 0x14); + UInt32 nextHeaderCRC = GetUInt32FromMem(_header + 0x1C); + UInt32 crc = CrcCalc(_header + 0xC, 20); #ifdef FORMAT_7Z_RECOVERY if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0) @@ -1260,7 +1095,7 @@ HRESULT CInArchive::ReadDatabase( RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2)); UInt32 realProcessedSize; - RINOK(ReadDirect(buf, (UInt32)kCheckSize, &realProcessedSize)); + RINOK(_stream->Read(buf, (UInt32)kCheckSize, &realProcessedSize)); int i; for (i = (int)realProcessedSize - 2; i >= 0; i--) @@ -1271,46 +1106,36 @@ HRESULT CInArchive::ReadDatabase( nextHeaderSize = realProcessedSize - i; nextHeaderOffset = cur2 - cur + i; nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize); - RINOK(_stream->Seek(cur, STREAM_SEEK_SET, &_position)); + RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL)); } #endif #ifdef FORMAT_7Z_RECOVERY - crcFromArchive = CRC_GET_DIGEST(crc); + crcFromArchive = crc; #endif - #ifdef _7Z_VOL - UInt64 archiveStartOffset; // data offset from end if that struct - UInt64 additionalStartBlockSize; // start signature & start header size - if (_finishSignature) - { - RINOK(SafeReadDirectUInt64(archiveStartOffset)); - crc.UpdateUInt64(archiveStartOffset); - RINOK(SafeReadDirectUInt64(additionalStartBlockSize)); - crc.UpdateUInt64(additionalStartBlockSize); - database.ArchiveInfo.StartPositionAfterHeader = _position + archiveStartOffset; - } - else - #endif - { - database.ArchiveInfo.StartPositionAfterHeader = _position; - } - if (CRC_GET_DIGEST(crc) != crcFromArchive) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + database.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize; + + if (crc != crcFromArchive) + ThrowIncorrect(); if (nextHeaderSize == 0) return S_OK; - if (nextHeaderSize >= 0xFFFFFFFF) - return E_FAIL; + if (nextHeaderSize > (UInt64)0xFFFFFFFF) + return S_FALSE; - RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, &_position)); + RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL)); CByteBuffer buffer2; buffer2.SetCapacity((size_t)nextHeaderSize); - RINOK(SafeReadDirect(buffer2, (UInt32)nextHeaderSize)); + + UInt32 realProcessedSize; + RINOK(_stream->Read(buffer2, (UInt32)nextHeaderSize, &realProcessedSize)); + if (realProcessedSize != (UInt32)nextHeaderSize) + return S_FALSE; if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + ThrowIncorrect(); CStreamSwitch streamSwitch; streamSwitch.Set(this, buffer2); @@ -1319,12 +1144,11 @@ HRESULT CInArchive::ReadDatabase( for (;;) { - UInt64 type; - RINOK(ReadID(type)); + UInt64 type = ReadID(); if (type == NID::kHeader) break; if (type != NID::kEncodedHeader) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + ThrowIncorrect(); HRESULT result = ReadAndDecodePackedStreams( EXTERNAL_CODECS_LOC_VARS database.ArchiveInfo.StartPositionAfterHeader, @@ -1338,7 +1162,7 @@ HRESULT CInArchive::ReadDatabase( if (dataVector.Size() == 0) return S_OK; if (dataVector.Size() > 1) - throw CInArchiveException(CInArchiveException::kIncorrectHeader); + ThrowIncorrect(); streamSwitch.Remove(); streamSwitch.Set(this, dataVector.Front()); } @@ -1352,4 +1176,24 @@ HRESULT CInArchive::ReadDatabase( ); } +HRESULT CInArchive::ReadDatabase( + DECL_EXTERNAL_CODECS_LOC_VARS + CArchiveDatabaseEx &database + #ifndef _NO_CRYPTO + , ICryptoGetTextPassword *getTextPassword + #endif + ) +{ + try + { + return ReadDatabase2( + EXTERNAL_CODECS_LOC_VARS database + #ifndef _NO_CRYPTO + , getTextPassword + #endif + ); + } + catch(CInArchiveException &) { return S_FALSE; } +} + }} diff --git a/CPP/7zip/Archive/7z/7zIn.h b/CPP/7zip/Archive/7z/7zIn.h index 927c23f9..47cd3b35 100755 --- a/CPP/7zip/Archive/7z/7zIn.h +++ b/CPP/7zip/Archive/7z/7zIn.h @@ -3,32 +3,17 @@ #ifndef __7Z_IN_H #define __7Z_IN_H +#include "../../../Common/MyCom.h" #include "../../IStream.h" #include "../../IPassword.h" - #include "../../Common/CreateCoder.h" - -#include "../../../Common/MyCom.h" #include "../../Common/InBuffer.h" -#include "7zHeader.h" #include "7zItem.h" namespace NArchive { namespace N7z { -class CInArchiveException -{ -public: - enum CCauseType - { - kUnsupportedVersion = 0, - kUnexpectedEndOfArchive = 0, - kIncorrectHeader, - } Cause; - CInArchiveException(CCauseType cause); -}; - struct CInArchiveInfo { CArchiveVersion Version; @@ -43,7 +28,6 @@ struct CInArchiveInfo } }; - struct CArchiveDatabaseEx: public CArchiveDatabase { CInArchiveInfo ArchiveInfo; @@ -76,8 +60,7 @@ struct CArchiveDatabaseEx: public CArchiveDatabase UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const { return ArchiveInfo.DataStartPosition + - PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + - indexInFolder]; + PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder]; } UInt64 GetFolderFullPackSize(int folderIndex) const @@ -117,44 +100,33 @@ public: _size = size; _pos = 0; } - bool ReadByte(Byte &b) - { - if(_pos >= _size) - return false; - b = _buffer[_pos++]; - return true; - } - void ReadBytes(void *data, size_t size, size_t &processedSize) - { - for(processedSize = 0; processedSize < size && _pos < _size; processedSize++) - ((Byte *)data)[processedSize] = _buffer[_pos++]; - } - - bool ReadBytes(void *data, size_t size) - { - size_t processedSize; - ReadBytes(data, size, processedSize); - return (processedSize == size); - } - - size_t GetProcessedSize() const { return _pos; } + Byte ReadByte(); + void ReadBytes(Byte *data, size_t size); + void SkeepData(UInt64 size); + void SkeepData(); + UInt64 ReadNumber(); + CNum ReadNum(); + UInt32 ReadUInt32(); + UInt64 ReadUInt64(); + void ReadString(UString &s); }; class CStreamSwitch; + +const UInt32 kHeaderSize = 32; + class CInArchive { friend class CStreamSwitch; CMyComPtr<IInStream> _stream; - #ifdef _7Z_VOL - bool _finishSignature; - #endif CObjectVector<CInByte2> _inByteVector; CInByte2 *_inByteBack; UInt64 _arhiveBeginStreamPosition; - UInt64 _position; + + Byte _header[kHeaderSize]; void AddByteStream(const Byte *buffer, size_t size) { @@ -171,80 +143,42 @@ class CInArchive } private: - HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive - #ifdef _7Z_VOL - HRESULT FindFinishSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive - #endif - - HRESULT ReadFileNames(CObjectVector<CFileItem> &files); - - HRESULT ReadDirect(IInStream *stream, void *data, UInt32 size, - UInt32 *processedSize); - HRESULT ReadDirect(void *data, UInt32 size, UInt32 *processedSize); - HRESULT SafeReadDirect(void *data, UInt32 size); - HRESULT SafeReadDirectByte(Byte &b); - HRESULT SafeReadDirectUInt32(UInt32 &value, UInt32 &crc); - HRESULT SafeReadDirectUInt64(UInt64 &value, UInt32 &crc); - - HRESULT ReadBytes(void *data, size_t size) - { - if (!_inByteBack->ReadBytes(data, size)) - return E_FAIL; - return S_OK; - } - - HRESULT ReadByte(Byte &b) - { - if (!_inByteBack->ReadByte(b)) - return E_FAIL; - return S_OK; - } - - HRESULT ReadWideCharLE(wchar_t &c) - { - Byte b1 = 0; - if (!_inByteBack->ReadByte(b1)) - return E_FAIL; - Byte b2 = 0; - if (!_inByteBack->ReadByte(b2)) - return E_FAIL; - c = (wchar_t)(((wchar_t)(b2) << 8) + b1); - return S_OK; - } - - HRESULT ReadNumber(UInt64 &value); - HRESULT ReadNum(CNum &value); - HRESULT ReadID(UInt64 &value) { return ReadNumber(value); } - HRESULT ReadUInt32(UInt32 &value); - HRESULT ReadUInt64(UInt64 &value); + HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); - HRESULT SkeepData(UInt64 size); - HRESULT SkeepData(); - HRESULT WaitAttribute(UInt64 attribute); - - HRESULT ReadArchiveProperties(CInArchiveInfo &archiveInfo); - HRESULT GetNextFolderItem(CFolder &itemInfo); - HRESULT ReadHashDigests(int numItems, + void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); } + Byte ReadByte() { return _inByteBack->ReadByte(); } + UInt64 ReadNumber() { return _inByteBack->ReadNumber(); } + CNum ReadNum() { return _inByteBack->ReadNum(); } + UInt64 ReadID() { return _inByteBack->ReadNumber(); } + UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); } + UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); } + void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); } + void SkeepData() { _inByteBack->SkeepData(); } + void WaitAttribute(UInt64 attribute); + + void ReadArchiveProperties(CInArchiveInfo &archiveInfo); + void GetNextFolderItem(CFolder &itemInfo); + void ReadHashDigests(int numItems, CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests); - HRESULT ReadPackInfo( + void ReadPackInfo( UInt64 &dataOffset, CRecordVector<UInt64> &packSizes, CRecordVector<bool> &packCRCsDefined, CRecordVector<UInt32> &packCRCs); - HRESULT ReadUnPackInfo( + void ReadUnPackInfo( const CObjectVector<CByteBuffer> *dataVector, CObjectVector<CFolder> &folders); - HRESULT ReadSubStreamsInfo( + void ReadSubStreamsInfo( const CObjectVector<CFolder> &folders, CRecordVector<CNum> &numUnPackStreamsInFolders, CRecordVector<UInt64> &unPackSizes, CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests); - HRESULT ReadStreamsInfo( + void ReadStreamsInfo( const CObjectVector<CByteBuffer> *dataVector, UInt64 &dataOffset, CRecordVector<UInt64> &packSizes, @@ -257,10 +191,9 @@ private: CRecordVector<UInt32> &digests); - HRESULT GetNextFileItem(CFileItem &itemInfo); - HRESULT ReadBoolVector(int numItems, CBoolVector &v); - HRESULT ReadBoolVector2(int numItems, CBoolVector &v); - HRESULT ReadTime(const CObjectVector<CByteBuffer> &dataVector, + void ReadBoolVector(int numItems, CBoolVector &v); + void ReadBoolVector2(int numItems, CBoolVector &v); + void ReadTime(const CObjectVector<CByteBuffer> &dataVector, CObjectVector<CFileItem> &files, UInt64 type); HRESULT ReadAndDecodePackedStreams( DECL_EXTERNAL_CODECS_LOC_VARS @@ -277,6 +210,13 @@ private: ,ICryptoGetTextPassword *getTextPassword #endif ); + HRESULT ReadDatabase2( + DECL_EXTERNAL_CODECS_LOC_VARS + CArchiveDatabaseEx &database + #ifndef _NO_CRYPTO + ,ICryptoGetTextPassword *getTextPassword + #endif + ); public: HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive void Close(); diff --git a/CPP/7zip/Archive/Arj/ArjHandler.h b/CPP/7zip/Archive/Arj/ArjHandler.h index 58e67401..1f43808a 100755 --- a/CPP/7zip/Archive/Arj/ArjHandler.h +++ b/CPP/7zip/Archive/Arj/ArjHandler.h @@ -17,24 +17,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *inStream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *callback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *anExtractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) CHandler(); private: diff --git a/CPP/7zip/Archive/BZip2/BZip2Handler.h b/CPP/7zip/Archive/BZip2/BZip2Handler.h index 96854eca..4a45e52f 100755 --- a/CPP/7zip/Archive/BZip2/BZip2Handler.h +++ b/CPP/7zip/Archive/BZip2/BZip2Handler.h @@ -53,32 +53,9 @@ public: MY_QUERYINTERFACE_END MY_ADDREF_RELEASE - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); + INTERFACE_IInArchive(;) + INTERFACE_IOutArchive(;) - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - // IOutArchiveHandler - - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - STDMETHOD(GetFileTimeType)(UInt32 *type); - - // ISetProperties STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties); DECL_ISetCompressCodecsInfo diff --git a/CPP/7zip/Archive/Cab/CabHandler.h b/CPP/7zip/Archive/Cab/CabHandler.h index f5b6e39c..e17c3a7d 100755 --- a/CPP/7zip/Archive/Cab/CabHandler.h +++ b/CPP/7zip/Archive/Cab/CabHandler.h @@ -17,24 +17,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CMvDatabaseEx m_Database; diff --git a/CPP/7zip/Archive/Chm/ChmHandler.h b/CPP/7zip/Archive/Chm/ChmHandler.h index 82eeb290..09113b8f 100755 --- a/CPP/7zip/Archive/Chm/ChmHandler.h +++ b/CPP/7zip/Archive/Chm/ChmHandler.h @@ -17,24 +17,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CFilesDatabase m_Database; diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp index bff689dd..a297eb7f 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +++ b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp @@ -26,13 +26,13 @@ void CCoder2::Code(ICompressProgressInfo *progress) { if (InSizePointers[i] != NULL) InSizePointers[i] = &InSizes[i]; - InStreamPointers.Add(InStreams[i]); + InStreamPointers.Add((ISequentialInStream *)InStreams[i]); } for (i = 0; i < NumOutStreams; i++) { if (OutSizePointers[i] != NULL) OutSizePointers[i] = &OutSizes[i]; - OutStreamPointers.Add(OutStreams[i]); + OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]); } if (Coder) Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0], diff --git a/CPP/7zip/Archive/Cpio/CpioHandler.h b/CPP/7zip/Archive/Cpio/CpioHandler.h index eed1a06a..e9320e61 100755 --- a/CPP/7zip/Archive/Cpio/CpioHandler.h +++ b/CPP/7zip/Archive/Cpio/CpioHandler.h @@ -18,24 +18,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CObjectVector<CItemEx> m_Items; diff --git a/CPP/7zip/Archive/Deb/DebHandler.h b/CPP/7zip/Archive/Deb/DebHandler.h index 4419dcdd..297a91be 100755 --- a/CPP/7zip/Archive/Deb/DebHandler.h +++ b/CPP/7zip/Archive/Deb/DebHandler.h @@ -18,24 +18,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CObjectVector<CItemEx> _items; diff --git a/CPP/7zip/Archive/GZip/GZipHandler.h b/CPP/7zip/Archive/GZip/GZipHandler.h index c1f8968b..3f5a1acd 100755 --- a/CPP/7zip/Archive/GZip/GZipHandler.h +++ b/CPP/7zip/Archive/GZip/GZipHandler.h @@ -30,34 +30,9 @@ public: MY_QUERYINTERFACE_END MY_ADDREF_RELEASE - STDMETHOD(Open)(IInStream *inStream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); + INTERFACE_IInArchive(;) + INTERFACE_IOutArchive(;) - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - // IOutArchive - - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - - STDMETHOD(GetFileTimeType)(UInt32 *timeType); - - // ISetProperties STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties); DECL_ISetCompressCodecsInfo diff --git a/CPP/7zip/Archive/IArchive.h b/CPP/7zip/Archive/IArchive.h index 3ef26a75..5fe20a72 100755 --- a/CPP/7zip/Archive/IArchive.h +++ b/CPP/7zip/Archive/IArchive.h @@ -111,28 +111,28 @@ ARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50) }; +/* +IInArchive::Extract: + indices must be sorted + numItems = 0xFFFFFFFF means "all files" + testMode != 0 means "test files without writing to outStream" +*/ + +#define INTERFACE_IInArchive(x) \ + STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \ + STDMETHOD(Close)() x; \ + STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \ + STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \ + STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \ + STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \ + STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \ + STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \ + STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \ + STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; + ARCHIVE_INTERFACE(IInArchive, 0x60) { - STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback) PURE; - STDMETHOD(Close)() PURE; - STDMETHOD(GetNumberOfItems)(UInt32 *numItems) PURE; - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE; - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback) PURE; - // indices must be sorted - // numItems = 0xFFFFFFFF means all files - // testMode != 0 means "test files operation" - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) PURE; - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) PURE; - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) PURE; - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) PURE; - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) PURE; + INTERFACE_IInArchive(PURE) }; @@ -156,11 +156,13 @@ ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82) }; +#define INTERFACE_IOutArchive(x) \ + STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \ + STDMETHOD(GetFileTimeType)(UInt32 *type) x; + ARCHIVE_INTERFACE(IOutArchive, 0xA0) { - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback) PURE; - STDMETHOD(GetFileTimeType)(UInt32 *type) PURE; + INTERFACE_IOutArchive(PURE) }; diff --git a/CPP/7zip/Archive/Iso/IsoHandler.h b/CPP/7zip/Archive/Iso/IsoHandler.h index 07d75844..5750cbc9 100755 --- a/CPP/7zip/Archive/Iso/IsoHandler.h +++ b/CPP/7zip/Archive/Iso/IsoHandler.h @@ -14,40 +14,14 @@ namespace NIso { class CHandler: public IInArchive, - // public IOutArchive, public CMyUnknownImp { public: MY_UNKNOWN_IMP1( IInArchive - // IOutArchive ) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - /* - // IOutArchive - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - STDMETHOD(GetFileTimeType)(UInt32 *type); - */ + INTERFACE_IInArchive(;) private: CMyComPtr<IInStream> _inStream; diff --git a/CPP/7zip/Archive/Lzh/LzhHandler.h b/CPP/7zip/Archive/Lzh/LzhHandler.h index 35929793..2caf21fd 100755 --- a/CPP/7zip/Archive/Lzh/LzhHandler.h +++ b/CPP/7zip/Archive/Lzh/LzhHandler.h @@ -17,24 +17,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *inStream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *callback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *anExtractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) CHandler(); private: diff --git a/CPP/7zip/Archive/Nsis/NsisHandler.h b/CPP/7zip/Archive/Nsis/NsisHandler.h index e180f70d..82e76139 100755 --- a/CPP/7zip/Archive/Nsis/NsisHandler.h +++ b/CPP/7zip/Archive/Nsis/NsisHandler.h @@ -32,16 +32,7 @@ public: MY_QUERYINTERFACE_END MY_ADDREF_RELEASE - STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback); - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType); - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) DECL_ISetCompressCodecsInfo }; diff --git a/CPP/7zip/Archive/Nsis/NsisIn.cpp b/CPP/7zip/Archive/Nsis/NsisIn.cpp index 8797a8e7..aa1e456f 100755 --- a/CPP/7zip/Archive/Nsis/NsisIn.cpp +++ b/CPP/7zip/Archive/Nsis/NsisIn.cpp @@ -57,9 +57,11 @@ void CInArchive::ReadBlockHeader(CBlockHeader &bh) static int CompareItems(void *const *p1, void *const *p2, void * /* param */) { - RINOZ(MyCompare( - (**(const CItem **)p1).Pos, - (**(const CItem **)p2).Pos)); + const CItem &i1 = **(CItem **)p1; + const CItem &i2 = **(CItem **)p2; + RINOZ(MyCompare(i1.Pos, i2.Pos)); + RINOZ(i1.Prefix.Compare(i2.Prefix)); + RINOZ(i1.Name.Compare(i2.Name)); return 0; } @@ -903,6 +905,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh) { Items.Sort(CompareItems, 0); int i; + if (IsSolid) for (i = 0; i + 1 < Items.Size();) { if (Items[i].Pos == Items[i + 1].Pos) diff --git a/CPP/7zip/Archive/RPM/RpmHandler.h b/CPP/7zip/Archive/RPM/RpmHandler.h index ed0717f3..c78e8ce3 100755 --- a/CPP/7zip/Archive/RPM/RpmHandler.h +++ b/CPP/7zip/Archive/RPM/RpmHandler.h @@ -16,24 +16,7 @@ class CHandler: public: MY_UNKNOWN_IMP1(IInArchive) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CMyComPtr<IInStream> m_InStream; diff --git a/CPP/7zip/Archive/Rar/RarHandler.h b/CPP/7zip/Archive/Rar/RarHandler.h index 96d5d241..811802a9 100755 --- a/CPP/7zip/Archive/Rar/RarHandler.h +++ b/CPP/7zip/Archive/Rar/RarHandler.h @@ -23,24 +23,7 @@ public: MY_QUERYINTERFACE_END MY_ADDREF_RELEASE - STDMETHOD(Open)(IInStream *aStream, - const UInt64 *aMaxCheckStartPosition, - IArchiveOpenCallback *anOpenArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *anExtractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) DECL_ISetCompressCodecsInfo diff --git a/CPP/7zip/Archive/Split/SplitHandler.h b/CPP/7zip/Archive/Split/SplitHandler.h index 65071cfd..79e63353 100755 --- a/CPP/7zip/Archive/Split/SplitHandler.h +++ b/CPP/7zip/Archive/Split/SplitHandler.h @@ -19,35 +19,10 @@ class CHandler: public: MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream); - // IOutArchiveHandler - /* - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - - STDMETHOD(GetFileTimeType)(UInt32 *type); - */ - private: UString _subName; UString _name; diff --git a/CPP/7zip/Archive/Tar/TarHandler.h b/CPP/7zip/Archive/Tar/TarHandler.h index 7b6e3a40..8332fbfe 100755 --- a/CPP/7zip/Archive/Tar/TarHandler.h +++ b/CPP/7zip/Archive/Tar/TarHandler.h @@ -22,29 +22,8 @@ public: IOutArchive ) - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - // IOutArchive - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - STDMETHOD(GetFileTimeType)(UInt32 *type); + INTERFACE_IInArchive(;) + INTERFACE_IOutArchive(;) private: CObjectVector<CItemEx> _items; diff --git a/CPP/7zip/Archive/Wim/WimHandler.h b/CPP/7zip/Archive/Wim/WimHandler.h index 5142d785..25567743 100755 --- a/CPP/7zip/Archive/Wim/WimHandler.h +++ b/CPP/7zip/Archive/Wim/WimHandler.h @@ -28,25 +28,7 @@ class CHandler: { public: MY_UNKNOWN_IMP1(IInArchive) - - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CDatabase m_Database; diff --git a/CPP/7zip/Archive/Wim/WimIn.cpp b/CPP/7zip/Archive/Wim/WimIn.cpp index e99cb37b..80ac1954 100755 --- a/CPP/7zip/Archive/Wim/WimIn.cpp +++ b/CPP/7zip/Archive/Wim/WimIn.cpp @@ -11,6 +11,8 @@ #include "../Common/OutStreamWithSha1.h" +#include "../../../../C/CpuArch.h" + #include "WimIn.h" namespace NArchive{ @@ -26,11 +28,7 @@ static HRESULT ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size) return (realProcessedSize == size) ? S_OK : S_FALSE; } -#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__) -#define WIM_LITTLE_ENDIAN_UNALIGN -#endif - -#ifdef WIM_LITTLE_ENDIAN_UNALIGN +#ifdef LITTLE_ENDIAN_UNALIGN static inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; } static inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; } static inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; } diff --git a/CPP/7zip/Archive/Z/ZHandler.h b/CPP/7zip/Archive/Z/ZHandler.h index 21165390..e8b3b8c5 100755 --- a/CPP/7zip/Archive/Z/ZHandler.h +++ b/CPP/7zip/Archive/Z/ZHandler.h @@ -15,25 +15,7 @@ class CHandler: { public: MY_UNKNOWN_IMP1(IInArchive) - - STDMETHOD(Open)(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *extractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); + INTERFACE_IInArchive(;) private: CMyComPtr<IInStream> _stream; diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp index c1185363..84269599 100755 --- a/CPP/7zip/Archive/Zip/ZipHandler.cpp +++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp @@ -31,6 +31,10 @@ #include "../../Crypto/Zip/ZipCipher.h" #include "../../Crypto/WzAES/WzAES.h" +#ifdef ZIP_STRONG_SUPORT +#include "../../Crypto/ZipStrong/ZipStrong.h" +#endif + using namespace NWindows; using namespace NTime; @@ -47,22 +51,22 @@ const wchar_t *kHostOS[] = L"AMIGA", L"VMS", L"Unix", - L"VM_CMS", - L"Atari", // what if it's a minix filesystem? [cjh] - L"HPFS", // filesystem used by OS/2 (and NT 3.x) - L"Mac", - L"Z_System", - L"CPM", - L"TOPS20", // pkzip 2.50 NTFS - L"NTFS", // filesystem used by Windows NT - L"QDOS ", // SMS/QDOS - L"Acorn", // Archimedes Acorn RISC OS - L"VFAT", // filesystem used by Windows 95, NT + L"VM/CMS", + L"Atari", + L"HPFS", + L"Macintosh", + L"Z-System", + L"CP/M", + L"TOPS-20", + L"NTFS", + L"SMS/QDOS", + L"Acorn", + L"VFAT", L"MVS", - L"BeOS", // hybrid POSIX/database filesystem - // BeBOX or PowerMac + L"BeOS", L"Tandem", - L"THEOS" + L"OS/400", + L"OS/X" }; @@ -120,6 +124,33 @@ const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]); const wchar_t *kPPMdMethod = L"PPMd"; const wchar_t *kAESMethod = L"AES"; const wchar_t *kZipCryptoMethod = L"ZipCrypto"; +const wchar_t *kStrongCryptoMethod = L"StrongCrypto"; + +struct CStrongCryptoPair +{ + UInt16 Id; + const wchar_t *Name; +}; + +CStrongCryptoPair g_StrongCryptoPairs[] = +{ + { NStrongCryptoFlags::kDES, L"DES" }, + { NStrongCryptoFlags::kRC2old, L"RC2a" }, + { NStrongCryptoFlags::k3DES168, L"3DES-168" }, + { NStrongCryptoFlags::k3DES112, L"3DES-112" }, + { NStrongCryptoFlags::kAES128, L"pkAES-128" }, + { NStrongCryptoFlags::kAES192, L"pkAES-192" }, + { NStrongCryptoFlags::kAES256, L"pkAES-256" }, + { NStrongCryptoFlags::kRC2, L"RC2" }, + { NStrongCryptoFlags::kBlowfish, L"Blowfish" }, + { NStrongCryptoFlags::kTwofish, L"Twofish" }, + { NStrongCryptoFlags::kRC4, L"RC4" } +}; + +STATPROPSTG kArcProperties[] = +{ + { NULL, kpidComment, VT_BSTR} +}; CHandler::CHandler(): m_ArchiveIsOpen(false) @@ -127,9 +158,33 @@ CHandler::CHandler(): InitMethodProperties(); } -STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) +static void StringToProp(const CByteBuffer &data, UINT codePage, NWindows::NCOM::CPropVariant &propVariant) { - value->vt = VT_EMPTY; + int size = (int)data.GetCapacity(); + if (size <= 0) + return; + AString s; + char *p = s.GetBuffer(size + 1); + memcpy(p, (const Byte *)data, size); + p[size] = '\0'; + s.ReleaseBuffer(); + propVariant = MultiByteToUnicodeString(s, codePage); +} + +STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +{ + COM_TRY_BEGIN + NWindows::NCOM::CPropVariant propVariant; + switch(propID) + { + case kpidComment: + { + StringToProp(m_Archive.m_ArchiveInfo.Comment, CP_ACP, propVariant); + break; + } + } + propVariant.Detach(value); + COM_TRY_END return S_OK; } @@ -142,7 +197,7 @@ STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) { - if(index >= sizeof(kProperties) / sizeof(kProperties[0])) + if (index >= sizeof(kProperties) / sizeof(kProperties[0])) return E_INVALIDARG; const STATPROPSTG &srcItem = kProperties[index]; *propID = srcItem.propid; @@ -153,14 +208,20 @@ STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) { - *numProperties = 0; + *numProperties = sizeof(kArcProperties) / sizeof(kArcProperties[0]); return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, - BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, + BSTR * name, PROPID * propID, VARTYPE *varType) { - return E_NOTIMPL; + if (index >= sizeof(kArcProperties) / sizeof(kArcProperties[0])) + return E_INVALIDARG; + const STATPROPSTG &srcItem = kArcProperties[index]; + *propID = srcItem.propid; + *varType = srcItem.vt; + *name = 0; + return S_OK; } STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) @@ -169,23 +230,12 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) return S_OK; } -static void MyStrNCpy(char *dest, const char *src, int size) -{ - for (int i = 0; i < size; i++) - { - char c = src[i]; - dest[i] = c; - if (c == 0) - break; - } -} - -STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *aValue) +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN NWindows::NCOM::CPropVariant propVariant; const CItemEx &item = m_Items[index]; - switch(aPropID) + switch(propID) { case kpidPath: propVariant = NItemName::GetOSName2( @@ -202,15 +252,15 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *a break; case kpidLastWriteTime: { - FILETIME aLocalFileTime, anUTCFileTime; - if (DosTimeToFileTime(item.Time, aLocalFileTime)) + FILETIME localFileTime, utcFileTime; + if (DosTimeToFileTime(item.Time, localFileTime)) { - if (!LocalFileTimeToFileTime(&aLocalFileTime, &anUTCFileTime)) - anUTCFileTime.dwHighDateTime = anUTCFileTime.dwLowDateTime = 0; + if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime)) + utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0; } else - anUTCFileTime.dwHighDateTime = anUTCFileTime.dwLowDateTime = 0; - propVariant = anUTCFileTime; + utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0; + propVariant = utcFileTime; break; } case kpidAttributes: @@ -221,16 +271,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *a break; case kpidComment: { - int size = (int)item.Comment.GetCapacity(); - if (size > 0) - { - AString s; - char *p = s.GetBuffer(size + 1); - MyStrNCpy(p, (const char *)(const Byte *)item.Comment, size); - p[size] = '\0'; - s.ReleaseBuffer(); - propVariant = MultiByteToUnicodeString(s, item.GetCodePage()); - } + StringToProp(item.Comment, item.GetCodePage(), propVariant); break; } case kpidCRC: @@ -259,7 +300,28 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *a } else { - method += kZipCryptoMethod; + if (item.IsStrongEncrypted()) + { + CStrongCryptoField f; + bool finded = false; + if (item.CentralExtra.GetStrongCryptoField(f)) + { + for (int i = 0; i < sizeof(g_StrongCryptoPairs) / sizeof(g_StrongCryptoPairs[0]); i++) + { + const CStrongCryptoPair &pair = g_StrongCryptoPairs[i]; + if (f.AlgId == pair.Id) + { + method += pair.Name; + finded = true; + break; + } + } + } + if (!finded) + method += kStrongCryptoMethod; + } + else + method += kZipCryptoMethod; method += L" "; } } @@ -281,7 +343,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *a (kHostOS[item.MadeByVersion.HostOS]) : kUnknownOS; break; } - propVariant.Detach(aValue); + propVariant.Detach(value); return S_OK; COM_TRY_END } @@ -353,6 +415,10 @@ class CZipDecoder NCrypto::NWzAES::CDecoder *_aesDecoderSpec; CMyComPtr<ICompressFilter> _zipCryptoDecoder; CMyComPtr<ICompressFilter> _aesDecoder; + #ifdef ZIP_STRONG_SUPORT + NCrypto::NZipStrong::CDecoder *_zsDecoderSpec; + CMyComPtr<ICompressFilter> _zsDecoder; + #endif CFilterCoder *filterStreamSpec; CMyComPtr<ISequentialInStream> filterStream; CMyComPtr<ICryptoGetTextPassword> getTextPassword; @@ -383,8 +449,27 @@ HRESULT CZipDecoder::Decode( bool needCRC = true; bool aesMode = false; + #ifdef ZIP_STRONG_SUPORT + bool pkAesMode = false; + #endif UInt16 methodId = item.CompressionMethod; if (item.IsEncrypted()) + { + if (item.IsStrongEncrypted()) + { + #ifdef ZIP_STRONG_SUPORT + CStrongCryptoField f; + if (item.CentralExtra.GetStrongCryptoField(f)) + { + pkAesMode = true; + } + if (!pkAesMode) + #endif + { + res = NArchive::NExtract::NOperationResult::kUnSupportedMethod; + return S_OK; + } + } if (methodId == NFileHeader::NCompressionMethod::kWzAES) { CWzAesExtraField aesField; @@ -394,8 +479,9 @@ HRESULT CZipDecoder::Decode( needCRC = aesField.NeedCrc(); } } + } - COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;; + COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC; CMyComPtr<ISequentialOutStream> outStream = outStreamSpec; outStreamSpec->SetStream(realOutStream); outStreamSpec->Init(needCRC); @@ -434,6 +520,17 @@ HRESULT CZipDecoder::Decode( Byte properties = aesField.Strength; RINOK(_aesDecoderSpec->SetDecoderProperties2(&properties, 1)); } + #ifdef ZIP_STRONG_SUPORT + else if (pkAesMode) + { + if (!_zsDecoder) + { + _zsDecoderSpec = new NCrypto::NZipStrong::CDecoder; + _zsDecoder = _zsDecoderSpec; + } + cryptoFilter = _zsDecoder; + } + #endif else { if (!_zipCryptoDecoder) @@ -454,7 +551,11 @@ HRESULT CZipDecoder::Decode( CMyComBSTR password; RINOK(getTextPassword->CryptoGetTextPassword(&password)); AString charPassword; - if (aesMode) + if (aesMode + #ifdef ZIP_STRONG_SUPORT + || pkAesMode + #endif + ) { charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_ACP); /* @@ -566,6 +667,12 @@ HRESULT CZipDecoder::Decode( { RINOK(_aesDecoderSpec->ReadHeader(inStream)); } + #ifdef ZIP_STRONG_SUPORT + else if (pkAesMode) + { + RINOK(_zsDecoderSpec->ReadHeader(inStream)); + } + #endif else { RINOK(_zipCryptoDecoderSpec->ReadHeader(inStream)); diff --git a/CPP/7zip/Archive/Zip/ZipHandler.h b/CPP/7zip/Archive/Zip/ZipHandler.h index f7bf4cf1..28f44196 100755 --- a/CPP/7zip/Archive/Zip/ZipHandler.h +++ b/CPP/7zip/Archive/Zip/ZipHandler.h @@ -34,31 +34,9 @@ public: MY_QUERYINTERFACE_END MY_ADDREF_RELEASE - STDMETHOD(Open)(IInStream *aStream, - const UInt64 *aMaxCheckStartPosition, - IArchiveOpenCallback *anOpenArchiveCallback); - STDMETHOD(Close)(); - STDMETHOD(GetNumberOfItems)(UInt32 *numItems); - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); - STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, - Int32 testMode, IArchiveExtractCallback *anExtractCallback); - - STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value); - - STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties); - STDMETHOD(GetPropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties); - STDMETHOD(GetArchivePropertyInfo)(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType); - - // IOutArchive - STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, - IArchiveUpdateCallback *updateCallback); - STDMETHOD(GetFileTimeType)(UInt32 *timeType); - - // ISetProperties + INTERFACE_IInArchive(;) + INTERFACE_IOutArchive(;) + STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties); DECL_ISetCompressCodecsInfo diff --git a/CPP/7zip/Archive/Zip/ZipHeader.h b/CPP/7zip/Archive/Zip/ZipHeader.h index ac98ea76..8ce2718a 100755 --- a/CPP/7zip/Archive/Zip/ZipHeader.h +++ b/CPP/7zip/Archive/Zip/ZipHeader.h @@ -86,6 +86,7 @@ namespace NFileHeader enum { kZip64 = 0x01, + kStrongEncrypt = 0x17, kWzAES = 0x9901 }; } @@ -157,8 +158,9 @@ namespace NFileHeader const int kNumUsedBits = 4; const int kUsedBitsMask = (1 << kNumUsedBits) - 1; - const int kEncryptedMask = 1 << 0; - const int kDescriptorUsedMask = 1 << 3; + const int kEncrypted = 1 << 0; + const int kDescriptorUsedMask = 1 << 3; + const int kStrongEncrypted = 1 << 6; const int kImplodeDictionarySizeMask = 1 << 1; const int kImplodeLiteralsOnMask = 1 << 2; @@ -173,8 +175,7 @@ namespace NFileHeader { enum EEnum { - kFAT = 0, // filesystem used by MS-DOS, OS/2, Win32 - // pkzip 2.50 (FAT / VFAT / FAT32 file systems) + kFAT = 0, kAMIGA = 1, kVMS = 2, // VAX/VMS kUnix = 3, @@ -191,11 +192,10 @@ namespace NFileHeader kVFAT = 14, // filesystem used by Windows 95, NT kMVS = 15, kBeOS = 16, // hybrid POSIX/database filesystem - // BeBOX or PowerMac kTandem = 17, - kTHEOS = 18 + kOS400 = 18, + kOSX = 19 }; - // const int kNumHostSystems = 19; } namespace NUnixAttribute { diff --git a/CPP/7zip/Archive/Zip/ZipIn.h b/CPP/7zip/Archive/Zip/ZipIn.h index 80de2272..62be592b 100755 --- a/CPP/7zip/Archive/Zip/ZipIn.h +++ b/CPP/7zip/Archive/Zip/ZipIn.h @@ -64,7 +64,6 @@ class CInArchive UInt32 m_Signature; UInt64 m_StreamStartPosition; UInt64 m_Position; - CInArchiveInfo m_ArchiveInfo; AString m_NameBuffer; HRESULT Seek(UInt64 offset); @@ -95,6 +94,8 @@ class CInArchive HRESULT ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize); HRESULT ReadLocalsAndCd(CObjectVector<CItemEx> &items, CProgressVirt *progress, UInt64 &cdOffset); public: + CInArchiveInfo m_ArchiveInfo; + HRESULT ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *progress); HRESULT ReadLocalItemAfterCdItem(CItemEx &item); HRESULT ReadLocalItemAfterCdItemFull(CItemEx &item); diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp index 86c2764b..480a1abb 100755 --- a/CPP/7zip/Archive/Zip/ZipItem.cpp +++ b/CPP/7zip/Archive/Zip/ZipItem.cpp @@ -19,14 +19,9 @@ bool operator!=(const CVersion &v1, const CVersion &v2) return !(v1 == v2); } -bool CLocalItem::IsEncrypted() const -{ return (Flags & NFileHeader::NFlags::kEncryptedMask) != 0; } -bool CLocalItem::HasDescriptor() const - { return (Flags & NFileHeader::NFlags::kDescriptorUsedMask) != 0; } - bool CLocalItem::IsImplodeBigDictionary() const { -if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded) + if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded) throw 12312212; return (Flags & NFileHeader::NFlags::kImplodeDictionarySizeMask) != 0; } @@ -130,6 +125,6 @@ void CLocalItem::SetBitMask(int bitMask, bool enable) } void CLocalItem::SetEncrypted(bool encrypted) - { SetBitMask(NFileHeader::NFlags::kEncryptedMask, encrypted); } + { SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); } }} diff --git a/CPP/7zip/Archive/Zip/ZipItem.h b/CPP/7zip/Archive/Zip/ZipItem.h index 4a7a47f1..2395a37a 100755 --- a/CPP/7zip/Archive/Zip/ZipItem.h +++ b/CPP/7zip/Archive/Zip/ZipItem.h @@ -67,6 +67,43 @@ struct CWzAesExtraField } }; +namespace NStrongCryptoFlags +{ + const UInt16 kDES = 0x6601; + const UInt16 kRC2old = 0x6602; + const UInt16 k3DES168 = 0x6603; + const UInt16 k3DES112 = 0x6609; + const UInt16 kAES128 = 0x660E; + const UInt16 kAES192 = 0x660F; + const UInt16 kAES256 = 0x6610; + const UInt16 kRC2 = 0x6702; + const UInt16 kBlowfish = 0x6720; + const UInt16 kTwofish = 0x6721; + const UInt16 kRC4 = 0x6801; +} + +struct CStrongCryptoField +{ + UInt16 Format; + UInt16 AlgId; + UInt16 BitLen; + UInt16 Flags; + + bool ParseFromSubBlock(const CExtraSubBlock &sb) + { + if (sb.ID != NFileHeader::NExtraID::kStrongEncrypt) + return false; + const Byte *p = (const Byte *)sb.Data; + if (sb.Data.GetCapacity() < 8) + return false; + Format = (((UInt16)p[1]) << 8) | p[0]; + AlgId = (((UInt16)p[3]) << 8) | p[2]; + BitLen = (((UInt16)p[5]) << 8) | p[4]; + Flags = (((UInt16)p[7]) << 8) | p[6]; + return (Format == 2); + } +}; + struct CExtraBlock { CObjectVector<CExtraSubBlock> SubBlocks; @@ -80,19 +117,34 @@ struct CExtraBlock } bool GetWzAesField(CWzAesExtraField &aesField) const { - // size_t res = 0; for (int i = 0; i < SubBlocks.Size(); i++) if (aesField.ParseFromSubBlock(SubBlocks[i])) return true; return false; } + bool GetStrongCryptoField(CStrongCryptoField &f) const + { + for (int i = 0; i < SubBlocks.Size(); i++) + if (f.ParseFromSubBlock(SubBlocks[i])) + return true; + return false; + } + bool HasWzAesField() const { CWzAesExtraField aesField; return GetWzAesField(aesField); } + /* + bool HasStrongCryptoField() const + { + CStrongCryptoField f; + return GetStrongCryptoField(f); + } + */ + void RemoveUnknownSubBlocks() { for (int i = SubBlocks.Size() - 1; i >= 0;) @@ -122,7 +174,8 @@ public: CExtraBlock LocalExtra; - bool IsEncrypted() const; + bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; } + bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; }; bool IsImplodeBigDictionary() const; bool IsImplodeLiteralsOn() const; @@ -131,7 +184,8 @@ public: bool IgnoreItem() const { return false; } UInt32 GetWinAttributes() const; - bool HasDescriptor() const; + bool HasDescriptor() const { return (Flags & NFileHeader::NFlags::kDescriptorUsedMask) != 0; } + private: void SetFlagBits(int startBitNumber, int numBits, int value); diff --git a/CPP/7zip/Bundles/Alone/Alone.dsp b/CPP/7zip/Bundles/Alone/Alone.dsp index 6250c0bd..49a7f037 100755 --- a/CPP/7zip/Bundles/Alone/Alone.dsp +++ b/CPP/7zip/Bundles/Alone/Alone.dsp @@ -2067,97 +2067,6 @@ SOURCE=..\..\Crypto\Zip\ZipCrypto.h # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\AES\aes.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\AES_CBC.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescpp.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescrypt.c - -!IF "$(CFG)" == "Alone - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aeskey.c - -!IF "$(CFG)" == "Alone - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aesopt.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aestab.c - -!IF "$(CFG)" == "Alone - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - SOURCE=..\..\Crypto\AES\MyAES.cpp !IF "$(CFG)" == "Alone - Win32 Release" @@ -2460,6 +2369,38 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h # End Source File # End Group # End Group +# Begin Group "C-Crypto" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.c + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.h +# End Source File +# End Group # Begin Source File SOURCE=..\..\..\..\C\7zCrc.c diff --git a/CPP/7zip/Bundles/Alone/makefile b/CPP/7zip/Bundles/Alone/makefile index ee881a01..de5f7e3f 100755 --- a/CPP/7zip/Bundles/Alone/makefile +++ b/CPP/7zip/Bundles/Alone/makefile @@ -250,11 +250,6 @@ COMPRESS_Z_OBJS = \ AES_OPT_OBJS = \ $O\MyAES.obj \ -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - CRYPTO_HASH_OBJS = \ $O\HmacSha1.obj \ $O\Pbkdf2HmacSha1.obj \ @@ -286,6 +281,9 @@ C_BRANCH_OBJS = \ $O\BranchSPARC.obj \ $O\BranchX86.obj \ +C_CRYPTO = \ + $O\Aes.obj \ + !include "../../Crc2.mak" OBJS = \ @@ -327,11 +325,11 @@ OBJS = \ $O\RangeCoderBit.obj \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ $(CRYPTO_HASH_OBJS) \ $(CRYPTO_ZIP_OBJS) \ $(CRYPTO_WZAES_OBJS) \ $O\QuantumDecoder.obj \ + $(C_CRYPTO) \ $(CRC_OBJS) \ $O\resource.res @@ -408,8 +406,6 @@ $O\QuantumDecoder.obj: ../../Compress/Quantum/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) -$(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) $(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp @@ -427,4 +423,6 @@ $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c $(COMPL_O2) $O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c $(COMPL_O2) +$(C_CRYPTO): ../../../../C/Crypto/$(*B).c + $(COMPL_O2) !include "../../Crc.mak"
\ No newline at end of file diff --git a/CPP/7zip/Bundles/Format7z/makefile b/CPP/7zip/Bundles/Format7z/makefile index e690dd3a..04bad9fd 100755 --- a/CPP/7zip/Bundles/Format7z/makefile +++ b/CPP/7zip/Bundles/Format7z/makefile @@ -132,11 +132,6 @@ PPMD_OPT_OBJS = \ AES_OPT_OBJS = \ $O\MyAES.obj \ -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - CRYPTO_HASH_OBJS = \ $O\RandGen.obj \ $O\Sha1.obj \ @@ -158,6 +153,9 @@ C_BRANCH_OBJS = \ $O\BranchSPARC.obj \ $O\BranchX86.obj \ +C_CRYPTO = \ + $O\Aes.obj \ + !include "../../Crc2.mak" OBJS = \ @@ -185,8 +183,8 @@ OBJS = \ $O\RangeCoderBit.obj \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ $(CRYPTO_HASH_OBJS) \ + $(C_CRYPTO) \ $(CRC_OBJS) \ $O\resource.res @@ -233,8 +231,6 @@ $O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) -$(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) $(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp @@ -246,5 +242,7 @@ $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c $(COMPL_O2) $(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c $(COMPL_O2) +$(C_CRYPTO): ../../../../C/Crypto/$(*B).c + $(COMPL_O2) !include "../../Crc.mak" diff --git a/CPP/7zip/Bundles/Format7zExtract/makefile b/CPP/7zip/Bundles/Format7zExtract/makefile index a2362869..10bec119 100755 --- a/CPP/7zip/Bundles/Format7zExtract/makefile +++ b/CPP/7zip/Bundles/Format7zExtract/makefile @@ -118,11 +118,6 @@ PPMD_OPT_OBJS = \ AES_OPT_OBJS = \ $O\MyAES.obj \ -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - CRYPTO_HASH_OBJS = \ $O\Sha256.obj \ @@ -138,6 +133,9 @@ C_BRANCH_OBJS = \ $O\BranchSPARC.obj \ $O\BranchX86.obj \ +C_CRYPTO = \ + $O\Aes.obj \ + !include "../../Crc2.mak" OBJS = \ @@ -161,10 +159,10 @@ OBJS = \ $(PPMD_OPT_OBJS) \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ $(CRYPTO_HASH_OBJS) \ $(C_OBJS) \ $(C_BRANCH_OBJS) \ + $(C_CRYPTO) \ $(CRC_OBJS) \ $O\resource.res @@ -208,8 +206,6 @@ $(PPMD_OPT_OBJS): ../../Compress/PPMD/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) -$(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) $(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp @@ -218,5 +214,7 @@ $(C_OBJS): ../../../../C/$(*B).c $(COMPL_O2) $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c $(COMPL_O2) +$(C_CRYPTO): ../../../../C/Crypto/$(*B).c + $(COMPL_O2) !include "../../Crc.mak" diff --git a/CPP/7zip/Bundles/Format7zF/Format7z.dsp b/CPP/7zip/Bundles/Format7zF/Format7z.dsp index 0f8407cc..66dfd29b 100755 --- a/CPP/7zip/Bundles/Format7zF/Format7z.dsp +++ b/CPP/7zip/Bundles/Format7zF/Format7z.dsp @@ -841,70 +841,6 @@ SOURCE=..\..\Compress\Lzh\LzhDecoder.h # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\AES\aes.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\AES_CBC.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescpp.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescrypt.c - -!IF "$(CFG)" == "7z - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7z - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aeskey.c - -!IF "$(CFG)" == "7z - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7z - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aesopt.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aestab.c - -!IF "$(CFG)" == "7z - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7z - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - SOURCE=..\..\Crypto\AES\MyAES.cpp !IF "$(CFG)" == "7z - Win32 Release" @@ -1110,6 +1046,10 @@ SOURCE=..\..\Crypto\Zip\ZipCrypto.cpp SOURCE=..\..\Crypto\Zip\ZipCrypto.h # End Source File # End Group +# Begin Group "ZipStrong" + +# PROP Default_Filter "" +# End Group # End Group # Begin Group "7zip Common" @@ -1479,6 +1419,30 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h # End Source File # End Group # End Group +# Begin Group "Crypto-C" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.c + +!IF "$(CFG)" == "7z - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "7z - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.h +# End Source File +# End Group # Begin Source File SOURCE=..\..\..\..\C\7zCrc.c @@ -1510,6 +1474,10 @@ SOURCE=..\..\..\..\C\Alloc.h # End Source File # Begin Source File +SOURCE=..\..\..\..\C\CpuArch.h +# End Source File +# Begin Source File + SOURCE=..\..\..\..\C\IStream.h # End Source File # Begin Source File diff --git a/CPP/7zip/Bundles/Format7zF/makefile b/CPP/7zip/Bundles/Format7zF/makefile index 0f3bf3d1..00e3e43d 100755 --- a/CPP/7zip/Bundles/Format7zF/makefile +++ b/CPP/7zip/Bundles/Format7zF/makefile @@ -282,11 +282,6 @@ COMPRESS_Z_OBJS = \ AES_OPT_OBJS = \ $O\MyAES.obj \ -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - CRYPTO_HASH_OBJS = \ $O\HmacSha1.obj \ $O\Pbkdf2HmacSha1.obj \ @@ -326,6 +321,9 @@ C_BRANCH_OBJS = \ $O\BranchSPARC.obj \ $O\BranchX86.obj \ +C_CRYPTO = \ + $O\Aes.obj \ + !include "../../Crc2.mak" OBJS = \ @@ -375,12 +373,12 @@ OBJS = \ $(C_OBJS) \ $(C_LZ_OBJS) \ $(C_BRANCH_OBJS) \ + $(C_CRYPTO) \ $O\HuffmanEncode.obj \ $O\BlockSort.obj \ $O\RangeCoderBit.obj \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ $(CRYPTO_ZIP_OBJS) \ $(CRYPTO_WZAES_OBJS) \ $(CRYPTO_HASH_OBJS) \ @@ -484,8 +482,6 @@ $O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) -$(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) $(CRYPTO_ZIP_OBJS): ../../Crypto/Zip/$(*B).cpp @@ -507,5 +503,7 @@ $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c $(COMPL_O2) $O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c $(COMPL_O2) +$(C_CRYPTO): ../../../../C/Crypto/$(*B).c + $(COMPL_O2) !include "../../Crc.mak" diff --git a/CPP/7zip/Bundles/Format7zR/makefile b/CPP/7zip/Bundles/Format7zR/makefile index 972c6eb1..6e96a8a2 100755 --- a/CPP/7zip/Bundles/Format7zR/makefile +++ b/CPP/7zip/Bundles/Format7zR/makefile @@ -146,10 +146,6 @@ OBJS = \ $(C_LZ_OBJS) \ $(C_BRANCH_OBJS) \ $O\RangeCoderBit.obj \ - $(7ZAES_OPT_OBJS) \ - $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ - $(CRYPTO_HASH_OBJS) \ $O\resource.res diff --git a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp index 163b9298..a0d21d0e 100755 --- a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp +++ b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp @@ -360,37 +360,6 @@ SOURCE=..\..\Crypto\7zAES\7zAESRegister.cpp # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\AES\aes.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\AES_CBC.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescpp.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescrypt.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aeskey.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aesopt.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aestab.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - SOURCE=..\..\Crypto\AES\MyAES.cpp # End Source File # Begin Source File @@ -783,6 +752,19 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h # End Source File # End Group +# Begin Group "C Crypto" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.h +# End Source File +# End Group # Begin Source File SOURCE=..\..\..\..\C\7zCrc.c diff --git a/CPP/7zip/Bundles/SFXCon/makefile b/CPP/7zip/Bundles/SFXCon/makefile index b6c13088..dbe07baa 100755 --- a/CPP/7zip/Bundles/SFXCon/makefile +++ b/CPP/7zip/Bundles/SFXCon/makefile @@ -109,11 +109,6 @@ PPMD_OPT_OBJS = \ AES_OPT_OBJS = \ $O\MyAES.obj \ -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - CRYPTO_HASH_OBJS = \ $O\Sha256.obj \ @@ -124,6 +119,9 @@ C_OBJS = \ C_BRANCH_OBJS = \ $O\BranchX86.obj \ +C_CRYPTO = \ + $O\Aes.obj \ + !include "../../Crc2.mak" OBJS = \ @@ -143,10 +141,10 @@ OBJS = \ $(PPMD_OPT_OBJS) \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ $(CRYPTO_HASH_OBJS) \ $(C_OBJS) \ $(C_BRANCH_OBJS) \ + $(C_CRYPTO) \ $(CRC_OBJS) \ $O\resource.res @@ -184,15 +182,15 @@ $(PPMD_OPT_OBJS): ../../Compress/PPMD/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL) -$(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O1_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL) $(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp $(COMPL) $(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) + $(COMPL_O1) $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c - $(COMPL_O2) + $(COMPL_O1) +$(C_CRYPTO): ../../../../C/Crypto/$(*B).c + $(COMPL_O1) !include "../../Crc.mak" diff --git a/CPP/7zip/Bundles/SFXSetup/makefile b/CPP/7zip/Bundles/SFXSetup/makefile index e773ba41..99104f67 100755 --- a/CPP/7zip/Bundles/SFXSetup/makefile +++ b/CPP/7zip/Bundles/SFXSetup/makefile @@ -171,10 +171,8 @@ $O\ProgressDialog.obj: ../../FileManager/Resource/ProgressDialog/$(*B).cpp $(COMPL) $(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) - + $(COMPL_O1) $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c - $(COMPL_O2) + $(COMPL_O1) !include "../../Crc.mak" - diff --git a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp index 23bdf2de..8ce4146d 100755 --- a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp +++ b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp @@ -340,37 +340,6 @@ SOURCE=..\..\Compress\Copy\CopyRegister.cpp # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\AES\aes.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\AES_CBC.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescpp.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aescrypt.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aeskey.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aesopt.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\AES\aestab.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - SOURCE=..\..\Crypto\AES\MyAES.cpp # End Source File # Begin Source File @@ -879,6 +848,19 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h # End Source File # End Group +# Begin Group "C Crypto" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Crypto\Aes.h +# End Source File +# End Group # Begin Source File SOURCE=..\..\..\..\C\7zCrc.c diff --git a/CPP/7zip/Bundles/SFXWin/makefile b/CPP/7zip/Bundles/SFXWin/makefile index aab98921..733d804f 100755 --- a/CPP/7zip/Bundles/SFXWin/makefile +++ b/CPP/7zip/Bundles/SFXWin/makefile @@ -114,11 +114,6 @@ PPMD_OPT_OBJS = \ AES_OPT_OBJS = \ $O\MyAES.obj \ -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - CRYPTO_HASH_OBJS = \ $O\Sha256.obj \ @@ -129,6 +124,9 @@ C_OBJS = \ C_BRANCH_OBJS = \ $O\BranchX86.obj \ +C_CRYPTO = \ + $O\Aes.obj \ + !include "../../Crc2.mak" OBJS = \ @@ -151,7 +149,6 @@ OBJS = \ $(CRYPTO_HASH_OBJS) \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ $O\MyMessages.obj \ $O\MessagesDialog.obj \ $O\OverwriteDialog.obj \ @@ -160,6 +157,7 @@ OBJS = \ $(C_OBJS) \ $(C_BRANCH_OBJS) \ $(CRC_OBJS) \ + $(C_CRYPTO) \ $O\resource.res @@ -204,8 +202,6 @@ $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL) $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL) -$(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O1_W3) $O\MyMessages.obj: ../../UI/Explorer/MyMessages.cpp $(COMPL) @@ -218,9 +214,10 @@ $O\PasswordDialog.obj: ../../FileManager/Resource/PasswordDialog/$(*B).cpp $O\ProgressDialog.obj: ../../FileManager/Resource/ProgressDialog/$(*B).cpp $(COMPL) $(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) + $(COMPL_O1) $(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c - $(COMPL_O2) + $(COMPL_O1) +$(C_CRYPTO): ../../../../C/Crypto/$(*B).c + $(COMPL_O1) !include "../../Crc.mak" -
\ No newline at end of file diff --git a/CPP/7zip/Common/FilterCoder.cpp b/CPP/7zip/Common/FilterCoder.cpp index 35c344c3..fd89d0e1 100755 --- a/CPP/7zip/Common/FilterCoder.cpp +++ b/CPP/7zip/Common/FilterCoder.cpp @@ -10,7 +10,7 @@ extern "C" #include "../../Common/Defs.h" #include "StreamUtils.h" -static const int kBufferSize = 1 << 17; +static const UInt32 kBufferSize = 1 << 17; CFilterCoder::CFilterCoder() { diff --git a/CPP/7zip/Compress/Rar/Rar1Decoder.cpp b/CPP/7zip/Compress/Rar/Rar1Decoder.cpp index c30443de..f19b14f4 100755 --- a/CPP/7zip/Compress/Rar/Rar1Decoder.cpp +++ b/CPP/7zip/Compress/Rar/Rar1Decoder.cpp @@ -1,7 +1,6 @@ // Rar1Decoder.cpp -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #include "StdAfx.h" diff --git a/CPP/7zip/Compress/Rar/Rar1Decoder.h b/CPP/7zip/Compress/Rar/Rar1Decoder.h index bdaf4d85..840b466d 100755 --- a/CPP/7zip/Compress/Rar/Rar1Decoder.h +++ b/CPP/7zip/Compress/Rar/Rar1Decoder.h @@ -1,7 +1,6 @@ // Rar15Decoder.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #ifndef __RAR10_DECODER_H #define __RAR10_DECODER_H diff --git a/CPP/7zip/Compress/Rar/Rar2Decoder.cpp b/CPP/7zip/Compress/Rar/Rar2Decoder.cpp index 43473695..152c388b 100755 --- a/CPP/7zip/Compress/Rar/Rar2Decoder.cpp +++ b/CPP/7zip/Compress/Rar/Rar2Decoder.cpp @@ -1,7 +1,6 @@ // Rar2Decoder.cpp -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #include "StdAfx.h" diff --git a/CPP/7zip/Compress/Rar/Rar2Decoder.h b/CPP/7zip/Compress/Rar/Rar2Decoder.h index dfd0f816..9567de0a 100755 --- a/CPP/7zip/Compress/Rar/Rar2Decoder.h +++ b/CPP/7zip/Compress/Rar/Rar2Decoder.h @@ -1,7 +1,6 @@ // Rar2Decoder.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #ifndef __RAR2DECODER_H #define __RAR2DECODER_H diff --git a/CPP/7zip/Compress/Rar/Rar3Decoder.cpp b/CPP/7zip/Compress/Rar/Rar3Decoder.cpp index 77b73ba8..7f71d1d8 100755 --- a/CPP/7zip/Compress/Rar/Rar3Decoder.cpp +++ b/CPP/7zip/Compress/Rar/Rar3Decoder.cpp @@ -1,7 +1,6 @@ // Rar3Decoder.cpp -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #include "StdAfx.h" diff --git a/CPP/7zip/Compress/Rar/Rar3Decoder.h b/CPP/7zip/Compress/Rar/Rar3Decoder.h index ec07a4d3..178bf5db 100755 --- a/CPP/7zip/Compress/Rar/Rar3Decoder.h +++ b/CPP/7zip/Compress/Rar/Rar3Decoder.h @@ -1,7 +1,6 @@ // Rar3Decoder.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #ifndef __RAR3DECODER_H #define __RAR3DECODER_H diff --git a/CPP/7zip/Compress/Rar/Rar3Vm.cpp b/CPP/7zip/Compress/Rar/Rar3Vm.cpp index 6d0c176c..8222668b 100755 --- a/CPP/7zip/Compress/Rar/Rar3Vm.cpp +++ b/CPP/7zip/Compress/Rar/Rar3Vm.cpp @@ -1,7 +1,6 @@ // Rar3Vm.cpp -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives /* Note: diff --git a/CPP/7zip/Compress/Rar/Rar3Vm.h b/CPP/7zip/Compress/Rar/Rar3Vm.h index 99a4f624..d31fcd0a 100755 --- a/CPP/7zip/Compress/Rar/Rar3Vm.h +++ b/CPP/7zip/Compress/Rar/Rar3Vm.h @@ -1,7 +1,6 @@ // Rar3Vm.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver +// According to unRAR license, this code may not be used to develop +// a program that creates RAR archives #ifndef __RAR3VM_H #define __RAR3VM_H @@ -9,11 +8,10 @@ #include "Common/Types.h" #include "Common/MyVector.h" +#include "../../../../C/CpuArch.h" + #define RARVM_STANDARD_FILTERS -#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__) // || defined(_M_IA64) || defined(__ia64__) -// Define RARVM_LITTLE_ENDIAN_UNALIGN, if CPU is LITTLE_ENDIAN and if it supports -// unaligned 32-bit memory accesses. -// It's for speed optimization, if you are not sure, just don't define it. +#ifdef LITTLE_ENDIAN_UNALIGN #define RARVM_LITTLE_ENDIAN_UNALIGN #endif diff --git a/CPP/7zip/Crypto/7zAES/7zAES.cpp b/CPP/7zip/Crypto/7zAES/7zAES.cpp index d8d86fab..97332b44 100755 --- a/CPP/7zip/Crypto/7zAES/7zAES.cpp +++ b/CPP/7zip/Crypto/7zAES/7zAES.cpp @@ -167,7 +167,7 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) HRESULT CEncoder::CreateFilter() { - _aesFilter = new CAES_CBC_Encoder; + _aesFilter = new CAesCbcEncoder; return S_OK; } @@ -234,7 +234,7 @@ STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size) HRESULT CDecoder::CreateFilter() { - _aesFilter = new CAES_CBC_Decoder; + _aesFilter = new CAesCbcDecoder; return S_OK; } diff --git a/CPP/7zip/Crypto/7zAES/7zAES.dsp b/CPP/7zip/Crypto/7zAES/7zAES.dsp deleted file mode 100755 index 868c0356..00000000 --- a/CPP/7zip/Crypto/7zAES/7zAES.dsp +++ /dev/null @@ -1,330 +0,0 @@ -# Microsoft Developer Studio Project File - Name="7zAES" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=7zAES - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "7zAES.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "7zAES.mak" CFG="7zAES - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "7zAES - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "7zAES - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "7zAES_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"StdAfx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "NDEBUG" -# ADD RSC /l 0x419 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\7zAES.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "7zAES_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"StdAfx.h" /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "_DEBUG" -# ADD RSC /l 0x419 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\7zAES.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "7zAES - Win32 Release" -# Name "7zAES - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\..\Compress\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Compress\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 -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "Common" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\Common\NewHandler.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\NewHandler.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\Vector.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\Vector.h -# End Source File -# End Group -# Begin Group "7-Zip Common" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\Common\StreamObjects.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamObjects.h -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\StringConvert.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\StringConvert.h -# End Source File -# End Group -# Begin Group "Windows" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\Windows\Synchronization.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Windows\Synchronization.h -# End Source File -# End Group -# Begin Group "Hash" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Hash\RotateDefs.h -# End Source File -# Begin Source File - -SOURCE=..\Hash\Sha256.cpp - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\Hash\Sha256.h -# End Source File -# End Group -# Begin Group "Ñ" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# End Group -# Begin Group "AES" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\AES\aes.h -# End Source File -# Begin Source File - -SOURCE=..\AES\AES_CBC.h -# End Source File -# Begin Source File - -SOURCE=..\AES\aescpp.h -# End Source File -# Begin Source File - -SOURCE=..\AES\aescrypt.c - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\AES\aeskey.c - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\AES\aesopt.h -# End Source File -# Begin Source File - -SOURCE=..\AES\aestab.c - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\AES\MyAES.cpp - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\AES\MyAES.h -# End Source File -# End Group -# Begin Source File - -SOURCE=.\7zAES.cpp - -!IF "$(CFG)" == "7zAES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7zAES - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\7zAES.h -# End Source File -# Begin Source File - -SOURCE=.\7zAESRegister.cpp -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Crypto/7zAES/7zAES.dsw b/CPP/7zip/Crypto/7zAES/7zAES.dsw deleted file mode 100755 index 08efbad8..00000000 --- a/CPP/7zip/Crypto/7zAES/7zAES.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "7zAES"=.\7zAES.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Crypto/7zAES/makefile b/CPP/7zip/Crypto/7zAES/makefile deleted file mode 100755 index d060d4ee..00000000 --- a/CPP/7zip/Crypto/7zAES/makefile +++ /dev/null @@ -1,72 +0,0 @@ -PROG = 7zAES.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -LIBS = $(LIBS) oleaut32.lib user32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -7ZAES_OPT_OBJS = \ - $O\7zAES.obj \ - $O\7zAESRegister.obj \ - -AES_OPT_OBJS = \ - $O\MyAES.obj \ - -AES_ORIG_OBJS = \ - $O\aescrypt.obj \ - $O\aeskey.obj \ - $O\aestab.obj \ - -CRYPTO_HASH_OBJS = \ - $O\Sha256.obj \ - -COMMON_OBJS = \ - $O\NewHandler.obj \ - $O\StringConvert.obj \ - $O\Vector.obj \ - -WIN_OBJS = \ - $O\Synchronization.obj - -7ZIP_COMMON_OBJS = \ - $O\StreamObjects.obj \ - $O\StreamUtils.obj \ - -C_OBJS = \ - $O\Alloc.obj \ - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(7ZAES_OPT_OBJS) \ - $(AES_OPT_OBJS) \ - $(AES_ORIG_OBJS) \ - $(CRYPTO_HASH_OBJS) \ - $(COMMON_OBJS) \ - $(WIN_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $(C_OBJS) \ - $O\resource.res - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../../Compress/$(*B).cpp - $(COMPL) -$(AES_OPT_OBJS): ../AES/$(*B).cpp - $(COMPL_O2) -$(AES_ORIG_OBJS): ../AES/$(*B).c - $(COMPL_O2_W3) -$(7ZAES_OPT_OBJS): $(*B).cpp - $(COMPL_O2) -$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp - $(COMPL_O2) -$(COMMON_OBJS): ../../../Common/$(*B).cpp - $(COMPL) -$(WIN_OBJS): ../../../Windows/$(*B).cpp - $(COMPL) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) diff --git a/CPP/7zip/Crypto/7zAES/resource.rc b/CPP/7zip/Crypto/7zAES/resource.rc deleted file mode 100755 index 24d428de..00000000 --- a/CPP/7zip/Crypto/7zAES/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("7zAES Codec", "7zAES") diff --git a/CPP/7zip/Crypto/AES/AES.dsp b/CPP/7zip/Crypto/AES/AES.dsp deleted file mode 100755 index d039be77..00000000 --- a/CPP/7zip/Crypto/AES/AES.dsp +++ /dev/null @@ -1,203 +0,0 @@ -# Microsoft Developer Studio Project File - Name="AES" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=AES - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "AES.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "AES.mak" CFG="AES - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "AES - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "AES - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "AES - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AES_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AES_EXPORTS" /Yu"StdAfx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "NDEBUG" -# ADD RSC /l 0x419 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\AES.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "AES - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AES_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AES_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "_DEBUG" -# ADD RSC /l 0x419 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\AES.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "AES - Win32 Release" -# Name "AES - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -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 -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "AES" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\aes.h -# End Source File -# Begin Source File - -SOURCE=.\aescpp.h -# End Source File -# Begin Source File - -SOURCE=.\aescrypt.c - -!IF "$(CFG)" == "AES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "AES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\aeskey.c - -!IF "$(CFG)" == "AES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "AES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\aesopt.h -# End Source File -# Begin Source File - -SOURCE=.\aestab.c - -!IF "$(CFG)" == "AES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "AES - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# End Group -# Begin Source File - -SOURCE=.\AES_CBC.h -# End Source File -# Begin Source File - -SOURCE=.\MyAES.cpp - -!IF "$(CFG)" == "AES - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "AES - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\MyAES.h -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Crypto/AES/AES.dsw b/CPP/7zip/Crypto/AES/AES.dsw deleted file mode 100755 index 7fa9d07b..00000000 --- a/CPP/7zip/Crypto/AES/AES.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "AES"=.\AES.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Crypto/AES/AES_CBC.h b/CPP/7zip/Crypto/AES/AES_CBC.h deleted file mode 100755 index fa3485a9..00000000 --- a/CPP/7zip/Crypto/AES/AES_CBC.h +++ /dev/null @@ -1,39 +0,0 @@ -// AES_CBC.h - -#ifndef __AES_CBC_H -#define __AES_CBC_H - -#include "aescpp.h" - -class CAES_CBC: public AESclass -{ -protected: - Byte _prevBlock[16]; -public: - void Init(const Byte *iv) - { - for (int i = 0; i < 16; i++) - _prevBlock[i] = iv[i]; - } - void Encode(const Byte *inBlock, Byte *outBlock) - { - int i; - for (i = 0; i < 16; i++) - _prevBlock[i] ^= inBlock[i]; - enc_blk(_prevBlock, outBlock); - for (i = 0; i < 16; i++) - _prevBlock[i] = outBlock[i]; - } - - void Decode(const Byte *inBlock, Byte *outBlock) - { - dec_blk(inBlock, outBlock); - int i; - for (i = 0; i < 16; i++) - outBlock[i] ^= _prevBlock[i]; - for (i = 0; i < 16; i++) - _prevBlock[i] = inBlock[i]; - } -}; - -#endif diff --git a/CPP/7zip/Crypto/AES/DllExports.cpp b/CPP/7zip/Crypto/AES/DllExports.cpp deleted file mode 100755 index 7c21ac5c..00000000 --- a/CPP/7zip/Crypto/AES/DllExports.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// DLLExports.cpp - -#include "StdAfx.h" - -#include "Common/MyInitGuid.h" -#include "Common/ComTry.h" -#include "MyAES.h" - -extern "C" -BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) -{ - return TRUE; -} - -#define MY_CreateClass(n) \ -if (*clsid == CLSID_CCrypto_ ## 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; \ - filter = (ICompressFilter *)new C ## n ## _Decoder(); \ - } - -STDAPI CreateObject( - const GUID *clsid, - const GUID *interfaceID, - void **outObject) -{ - COM_TRY_BEGIN - *outObject = 0; - int correctInterface = (*interfaceID == IID_ICompressFilter); - CMyComPtr<ICompressFilter> filter; - - MY_CreateClass(AES_CBC) - else - MY_CreateClass(AES_ECB) - else - return CLASS_E_CLASSNOTAVAILABLE; - *outObject = filter.Detach(); - return S_OK; - COM_TRY_END -} - -struct CAESMethodItem -{ - char ID[3]; - const wchar_t *UserName; - const GUID *Decoder; - const GUID *Encoder; -}; - -#define METHOD_ITEM(Name, id, UserName) \ - { { 0x06, 0x01, id }, UserName, \ - &CLSID_CCrypto_ ## Name ## _Decoder, \ - &CLSID_CCrypto_ ## Name ## _Encoder } - - -static CAESMethodItem g_Methods[] = -{ - METHOD_ITEM(AES_ECB, (char)(unsigned char)0xC0, L"AES-ECB"), - METHOD_ITEM(AES_CBC, (char)(unsigned char)0xC1, L"AES") -}; - -STDAPI GetNumberOfMethods(UINT32 *numMethods) -{ - *numMethods = sizeof(g_Methods) / sizeof(g_Methods[1]); - return S_OK; -} - -STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value) -{ - if (index > sizeof(g_Methods) / sizeof(g_Methods[1])) - return E_INVALIDARG; - VariantClear((tagVARIANT *)value); - const CAESMethodItem &method = g_Methods[index]; - switch(propID) - { - case NMethodPropID::kID: - if ((value->bstrVal = ::SysAllocStringByteLen(method.ID, - sizeof(method.ID))) != 0) - value->vt = VT_BSTR; - return S_OK; - case NMethodPropID::kName: - if ((value->bstrVal = ::SysAllocString(method.UserName)) != 0) - value->vt = VT_BSTR; - return S_OK; - case NMethodPropID::kDecoder: - if ((value->bstrVal = ::SysAllocStringByteLen( - (const char *)method.Decoder, sizeof(GUID))) != 0) - value->vt = VT_BSTR; - return S_OK; - case NMethodPropID::kEncoder: - if ((value->bstrVal = ::SysAllocStringByteLen( - (const char *)method.Encoder, sizeof(GUID))) != 0) - value->vt = VT_BSTR; - return S_OK; - } - return S_OK; -} - diff --git a/CPP/7zip/Crypto/AES/MyAES.cpp b/CPP/7zip/Crypto/AES/MyAES.cpp index 359caa25..926e8969 100755 --- a/CPP/7zip/Crypto/AES/MyAES.cpp +++ b/CPP/7zip/Crypto/AES/MyAES.cpp @@ -2,93 +2,56 @@ #include "StdAfx.h" -#include "windows.h" - #include "MyAES.h" -#include "Windows/Defs.h" -#include "AES_CBC.h" +namespace NCrypto { -static const int kAESBlockSize = 16; +struct CAesTabInit { CAesTabInit() { AesGenTables();} } g_AesTabInit; -extern "C" -{ -#include "aesopt.h" -} +STDMETHODIMP CAesCbcEncoder::Init() { return S_OK; } -class CTabInit +STDMETHODIMP_(UInt32) CAesCbcEncoder::Filter(Byte *data, UInt32 size) { -public: - CTabInit() { gen_tabs();} -} g_TabInit; - -STDMETHODIMP CAESFilter::Init() { return S_OK; } + return AesCbcEncode(&Aes, data, size); +} -STDMETHODIMP_(UInt32) CAESFilter::Filter(Byte *data, UInt32 size) -{ - if (size > 0 && size < kAESBlockSize) - return kAESBlockSize; - UInt32 i; - for (i = 0; i + kAESBlockSize <= size; i += kAESBlockSize) - { - Byte outBlock[kAESBlockSize]; - SubFilter(data + i, outBlock); - for (int j = 0; j < kAESBlockSize; j++) - data[i + j] = outBlock[j]; - } - return i; +STDMETHODIMP CAesCbcEncoder::SetKey(const Byte *data, UInt32 size) +{ + if ((size & 0x7) != 0 || size < 16 || size > 32) + return E_INVALIDARG; + AesSetKeyEncode(&Aes.aes, data, size); + return S_OK; } -STDMETHODIMP CAESFilter::SetInitVector(const Byte *data, UInt32 size) +STDMETHODIMP CAesCbcEncoder::SetInitVector(const Byte *data, UInt32 size) { - if (size != 16) + if (size != AES_BLOCK_SIZE) return E_INVALIDARG; - AES.Init(data); + AesCbcInit(&Aes, data); return S_OK; } -STDMETHODIMP CAESEncoder::SetKey(const Byte *data, UInt32 size) - { return (AES.enc_key(data, size) == aes_good) ? S_OK: E_FAIL; } - -void CAESEncoder::SubFilter(const Byte *inBlock, Byte *outBlock) - { AES.Encode(inBlock, outBlock); } - -STDMETHODIMP CAESDecoder::SetKey(const Byte *data, UInt32 size) - { return (AES.dec_key(data, size) == aes_good) ? S_OK: E_FAIL; } - -void CAESDecoder::SubFilter(const Byte *inBlock, Byte *outBlock) - { AES.Decode(inBlock, outBlock); } +STDMETHODIMP CAesCbcDecoder::Init() { return S_OK; } -//////////////////////////// -// ECB mode - -STDMETHODIMP CAesEcbFilter::Init() { return S_OK; } -STDMETHODIMP CAesEcbFilter::SetInitVector(const Byte * /* data */, UInt32 size) - { return (size == 0) ? S_OK: E_INVALIDARG; } - -STDMETHODIMP_(UInt32) CAesEcbFilter::Filter(Byte *data, UInt32 size) +STDMETHODIMP_(UInt32) CAesCbcDecoder::Filter(Byte *data, UInt32 size) { - if (size > 0 && size < kAESBlockSize) - return kAESBlockSize; - UInt32 i; - for (i = 0; i + kAESBlockSize <= size; i += kAESBlockSize) - { - Byte outBlock[kAESBlockSize]; - SubFilter(data + i, outBlock); - for (int j = 0; j < kAESBlockSize; j++) - data[i + j] = outBlock[j]; - } - return i; + return AesCbcDecode(&Aes, data, size); } -STDMETHODIMP CAesEcbEncoder::SetKey(const Byte *data, UInt32 size) - { return (AES.enc_key(data, size) == aes_good) ? S_OK: E_FAIL; } - -void CAesEcbEncoder::SubFilter(const Byte *inBlock, Byte *outBlock) - { AES.enc_blk(inBlock, outBlock); } +STDMETHODIMP CAesCbcDecoder::SetKey(const Byte *data, UInt32 size) +{ + if ((size & 0x7) != 0 || size < 16 || size > 32) + return E_INVALIDARG; + AesSetKeyDecode(&Aes.aes, data, size); + return S_OK; +} -STDMETHODIMP CAesEcbDecoder::SetKey(const Byte *data, UInt32 size) - { return (AES.dec_key(data, size) == aes_good) ? S_OK: E_FAIL; } +STDMETHODIMP CAesCbcDecoder::SetInitVector(const Byte *data, UInt32 size) +{ + if (size != AES_BLOCK_SIZE) + return E_INVALIDARG; + AesCbcInit(&Aes, data); + return S_OK; +} -void CAesEcbDecoder::SubFilter(const Byte *inBlock, Byte *outBlock) - { AES.dec_blk(inBlock, outBlock); } +} diff --git a/CPP/7zip/Crypto/AES/MyAES.h b/CPP/7zip/Crypto/AES/MyAES.h index f58913ae..29bd83c6 100755 --- a/CPP/7zip/Crypto/AES/MyAES.h +++ b/CPP/7zip/Crypto/AES/MyAES.h @@ -7,100 +7,42 @@ #include "Common/MyCom.h" #include "../../ICoder.h" -#include "AES_CBC.h" -class CAESFilter: +extern "C" +{ +#include "../../../../C/Crypto/Aes.h" +} + +namespace NCrypto { + +class CAesCbcEncoder: public ICompressFilter, public ICryptoProperties, - public CMyUnknownImp + public CMyUnknownImp { -protected: - CAES_CBC AES; - // Byte Key[32]; - // Byte IV[kAESBlockSize]; + CAesCbc Aes; 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); + STDMETHOD(SetInitVector)(const Byte *data, UInt32 size); }; -#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); - -#define MyClassCrypto(Name, id) \ -MyClassCrypto2(Name ## _Encoder, id, 0x01) \ -MyClassCrypto3E(Name ## _Encoder) \ -MyClassCrypto2(Name ## _Decoder, id, 0x00) \ -MyClassCrypto3D(Name ## _Decoder) \ - -MyClassCrypto(AES_CBC, 0xC1) - -class CAesEcbFilter: +class CAesCbcDecoder: public ICompressFilter, public ICryptoProperties, - public CMyUnknownImp + public CMyUnknownImp { -protected: - AESclass AES; + CAesCbc Aes; 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 CAesEcbEncoder: public CAesEcbFilter -{ -public: - STDMETHOD(SetKey)(const Byte *data, UInt32 size); - virtual void SubFilter(const Byte *inBlock, Byte *outBlock); -}; - -class CAesEcbDecoder: public CAesEcbFilter -{ -public: STDMETHOD(SetKey)(const Byte *data, UInt32 size); - virtual void SubFilter(const Byte *inBlock, Byte *outBlock); + STDMETHOD(SetInitVector)(const Byte *data, UInt32 size); }; -#define MyClassCrypto3E_Ecb(Name) class C ## Name: public CAesEcbEncoder { }; -#define MyClassCrypto3D_Ecb(Name) class C ## Name: public CAesEcbDecoder { }; - -// {23170F69-40C1-278B-0601-000000000000} -#define MyClassCrypto2_Ecb(Name, id, encodingId) \ -DEFINE_GUID(CLSID_CCrypto_ ## Name, \ -0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, id, 0x00, 0x00, 0x00, encodingId, 0x00); - -#define MyClassCrypto_Ecb(Name, id) \ -MyClassCrypto2_Ecb(Name ## _Encoder, id, 0x01) \ -MyClassCrypto3E_Ecb(Name ## _Encoder) \ -MyClassCrypto2_Ecb(Name ## _Decoder, id, 0x00) \ -MyClassCrypto3D_Ecb(Name ## _Decoder) \ - -MyClassCrypto_Ecb(AES_ECB, 0xC0) +} #endif diff --git a/CPP/7zip/Crypto/AES/aes.h b/CPP/7zip/Crypto/AES/aes.h deleted file mode 100755 index 9aaba978..00000000 --- a/CPP/7zip/Crypto/AES/aes.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - ------------------------------------------------------------------------- - Copyright (c) 2001, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and fitness for purpose. - ------------------------------------------------------------------------- - Issue Date: 29/07/2002 - - This file contains the definitions required to use AES (Rijndael) in C. -*/ - -#ifndef _AES_H -#define _AES_H - -/* This include is used only to find 8 and 32 bit unsigned integer types */ - -#include "limits.h" - -#if UCHAR_MAX == 0xff /* an unsigned 8 bit type for internal AES use */ - typedef unsigned char aes_08t; -#else -#error Please define an unsigned 8 bit type in aes.h -#endif - -#if UINT_MAX == 0xffffffff /* an unsigned 32 bit type for internal AES use */ - typedef unsigned int aes_32t; -#elif ULONG_MAX == 0xffffffff - typedef unsigned long aes_32t; -#else -#error Please define an unsigned 32 bit type in aes.h -#endif - -/* BLOCK_SIZE is in BYTES: 16, 24, 32 or undefined for aes.c and 16, 20, - 24, 28, 32 or undefined for aespp.c. When left undefined a slower - version that provides variable block length is compiled. -*/ - -#define BLOCK_SIZE 16 - -/* key schedule length (in 32-bit words) */ - -#if !defined(BLOCK_SIZE) -#define KS_LENGTH 128 -#else -#define KS_LENGTH 4 * BLOCK_SIZE -#endif - -#if defined(__cplusplus) -extern "C" -{ -#endif - -typedef unsigned int aes_fret; /* type for function return value */ -#define aes_bad 0 /* bad function return value */ -#define aes_good 1 /* good function return value */ -#ifndef AES_DLL /* implement normal or DLL functions */ -#define aes_rval aes_fret -#else -#define aes_rval aes_fret __declspec(dllexport) _stdcall -#endif - - -typedef struct /* the AES context for encryption */ -{ aes_32t k_sch[KS_LENGTH]; /* the encryption key schedule */ - aes_32t n_rnd; /* the number of cipher rounds */ - aes_32t n_blk; /* the number of bytes in the state */ -} aes_ctx; - -#if !defined(BLOCK_SIZE) -aes_rval aes_blk_len(unsigned int blen, aes_ctx cx[1]); -#endif - -aes_rval aes_enc_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]); -aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]); - -aes_rval aes_dec_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]); -aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/CPP/7zip/Crypto/AES/aescpp.h b/CPP/7zip/Crypto/AES/aescpp.h deleted file mode 100755 index 93e3c8b0..00000000 --- a/CPP/7zip/Crypto/AES/aescpp.h +++ /dev/null @@ -1,55 +0,0 @@ - -/* - ------------------------------------------------------------------------- - Copyright (c) 2001, Dr Brian Gladman <brg@gladman.uk.net>, Worcester, UK. - All rights reserved. - - TERMS - - Redistribution and use in source and binary forms, with or without - modification, are permitted subject to the following conditions: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. The copyright holder's name must not be used to endorse or promote - any products derived from this software without his specific prior - written permission. - - This software is provided 'as is' with no express or implied warranties - of correctness or fitness for purpose. - ------------------------------------------------------------------------- - Issue Date: 21/01/2002 - - This file contains the definitions required to use AES (Rijndael) in C++. -*/ - -#ifndef _AESCPP_H -#define _AESCPP_H - -#include "aes.h" - -class AESclass -{ aes_ctx cx[1]; -public: -#if defined(BLOCK_SIZE) - AESclass() { cx->n_blk = BLOCK_SIZE; cx->n_rnd = 0; } -#else - AESclass(unsigned int blen = 16) { cx->n_blk = blen; cx->n_rnd = 0; } - aes_rval blk_len(unsigned int blen) { return aes_blk_len(blen, cx); } -#endif - aes_rval enc_key(const unsigned char in_key[], unsigned int klen) - { return aes_enc_key(in_key, klen, cx); } - aes_rval dec_key(const unsigned char in_key[], unsigned int klen) - { return aes_dec_key(in_key, klen, cx); } - aes_rval enc_blk(const unsigned char in_blk[], unsigned char out_blk[]) - { return aes_enc_blk(in_blk, out_blk, cx); } - aes_rval dec_blk(const unsigned char in_blk[], unsigned char out_blk[]) - { return aes_dec_blk(in_blk, out_blk, cx); } -}; - -#endif diff --git a/CPP/7zip/Crypto/AES/aescrypt.c b/CPP/7zip/Crypto/AES/aescrypt.c deleted file mode 100755 index 095a61c4..00000000 --- a/CPP/7zip/Crypto/AES/aescrypt.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - ------------------------------------------------------------------------- - Copyright (c) 2001, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and fitness for purpose. - ------------------------------------------------------------------------- - Issue Date: 29/07/2002 - - This file contains the code for implementing encryption and decryption - for AES (Rijndael) for block and key sizes of 16, 24 and 32 bytes. It - can optionally be replaced by code written in assembler using NASM. -*/ - -#include "aesopt.h" - -#if defined(BLOCK_SIZE) && (BLOCK_SIZE & 7) -#error An illegal block size has been specified. -#endif - -#define unused 77 /* Sunset Strip */ - -#define si(y,x,k,c) s(y,c) = word_in(x + 4 * c) ^ k[c] -#define so(y,x,c) word_out(y + 4 * c, s(x,c)) - -#if BLOCK_SIZE == 16 - -#if defined(ARRAYS) -#define locals(y,x) x[4],y[4] -#else -#define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3 - /* - the following defines prevent the compiler requiring the declaration - of generated but unused variables in the fwd_var and inv_var macros - */ -#define b04 unused -#define b05 unused -#define b06 unused -#define b07 unused -#define b14 unused -#define b15 unused -#define b16 unused -#define b17 unused -#endif -#define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ - s(y,2) = s(x,2); s(y,3) = s(x,3); -#define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); si(y,x,k,3) -#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) -#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3) - -#elif BLOCK_SIZE == 24 - -#if defined(ARRAYS) -#define locals(y,x) x[6],y[6] -#else -#define locals(y,x) x##0,x##1,x##2,x##3,x##4,x##5, \ - y##0,y##1,y##2,y##3,y##4,y##5 -#define b06 unused -#define b07 unused -#define b16 unused -#define b17 unused -#endif -#define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ - s(y,2) = s(x,2); s(y,3) = s(x,3); \ - s(y,4) = s(x,4); s(y,5) = s(x,5); -#define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); \ - si(y,x,k,3); si(y,x,k,4); si(y,x,k,5) -#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); \ - so(y,x,3); so(y,x,4); so(y,x,5) -#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); \ - rm(y,x,k,3); rm(y,x,k,4); rm(y,x,k,5) -#else - -#if defined(ARRAYS) -#define locals(y,x) x[8],y[8] -#else -#define locals(y,x) x##0,x##1,x##2,x##3,x##4,x##5,x##6,x##7, \ - y##0,y##1,y##2,y##3,y##4,y##5,y##6,y##7 -#endif -#define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ - s(y,2) = s(x,2); s(y,3) = s(x,3); \ - s(y,4) = s(x,4); s(y,5) = s(x,5); \ - s(y,6) = s(x,6); s(y,7) = s(x,7); - -#if BLOCK_SIZE == 32 - -#define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); si(y,x,k,3); \ - si(y,x,k,4); si(y,x,k,5); si(y,x,k,6); si(y,x,k,7) -#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3); \ - so(y,x,4); so(y,x,5); so(y,x,6); so(y,x,7) -#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3); \ - rm(y,x,k,4); rm(y,x,k,5); rm(y,x,k,6); rm(y,x,k,7) -#else - -#define state_in(y,x,k) \ -switch(nc) \ -{ case 8: si(y,x,k,7); si(y,x,k,6); \ - case 6: si(y,x,k,5); si(y,x,k,4); \ - case 4: si(y,x,k,3); si(y,x,k,2); \ - si(y,x,k,1); si(y,x,k,0); \ -} - -#define state_out(y,x) \ -switch(nc) \ -{ case 8: so(y,x,7); so(y,x,6); \ - case 6: so(y,x,5); so(y,x,4); \ - case 4: so(y,x,3); so(y,x,2); \ - so(y,x,1); so(y,x,0); \ -} - -#if defined(FAST_VARIABLE) - -#define round(rm,y,x,k) \ -switch(nc) \ -{ case 8: rm(y,x,k,7); rm(y,x,k,6); \ - rm(y,x,k,5); rm(y,x,k,4); \ - rm(y,x,k,3); rm(y,x,k,2); \ - rm(y,x,k,1); rm(y,x,k,0); \ - break; \ - case 6: rm(y,x,k,5); rm(y,x,k,4); \ - rm(y,x,k,3); rm(y,x,k,2); \ - rm(y,x,k,1); rm(y,x,k,0); \ - break; \ - case 4: rm(y,x,k,3); rm(y,x,k,2); \ - rm(y,x,k,1); rm(y,x,k,0); \ - break; \ -} -#else - -#define round(rm,y,x,k) \ -switch(nc) \ -{ case 8: rm(y,x,k,7); rm(y,x,k,6); \ - case 6: rm(y,x,k,5); rm(y,x,k,4); \ - case 4: rm(y,x,k,3); rm(y,x,k,2); \ - rm(y,x,k,1); rm(y,x,k,0); \ -} - -#endif - -#endif -#endif - -#if defined(ENCRYPTION) - -/* I am grateful to Frank Yellin for the following construction - (and that for decryption) which, given the column (c) of the - output state variable, gives the input state variables which - are needed in its computation for each row (r) of the state. - - For the fixed block size options, compilers should be able to - reduce this complex expression (and the equivalent one for - decryption) to a static variable reference at compile time. - But for variable block size code, there will be some limbs on - which conditional clauses will be returned. -*/ - -/* y = output word, x = input word, r = row, c = column for r = 0, - 1, 2 and 3 = column accessed for row r. -*/ - -#define fwd_var(x,r,c)\ - ( r == 0 ? \ - ( c == 0 ? s(x,0) \ - : c == 1 ? s(x,1) \ - : c == 2 ? s(x,2) \ - : c == 3 ? s(x,3) \ - : c == 4 ? s(x,4) \ - : c == 5 ? s(x,5) \ - : c == 6 ? s(x,6) \ - : s(x,7))\ - : r == 1 ? \ - ( c == 0 ? s(x,1) \ - : c == 1 ? s(x,2) \ - : c == 2 ? s(x,3) \ - : c == 3 ? nc == 4 ? s(x,0) : s(x,4) \ - : c == 4 ? s(x,5) \ - : c == 5 ? nc == 8 ? s(x,6) : s(x,0) \ - : c == 6 ? s(x,7) \ - : s(x,0))\ - : r == 2 ? \ - ( c == 0 ? nc == 8 ? s(x,3) : s(x,2) \ - : c == 1 ? nc == 8 ? s(x,4) : s(x,3) \ - : c == 2 ? nc == 4 ? s(x,0) : nc == 8 ? s(x,5) : s(x,4) \ - : c == 3 ? nc == 4 ? s(x,1) : nc == 8 ? s(x,6) : s(x,5) \ - : c == 4 ? nc == 8 ? s(x,7) : s(x,0) \ - : c == 5 ? nc == 8 ? s(x,0) : s(x,1) \ - : c == 6 ? s(x,1) \ - : s(x,2))\ - : \ - ( c == 0 ? nc == 8 ? s(x,4) : s(x,3) \ - : c == 1 ? nc == 4 ? s(x,0) : nc == 8 ? s(x,5) : s(x,4) \ - : c == 2 ? nc == 4 ? s(x,1) : nc == 8 ? s(x,6) : s(x,5) \ - : c == 3 ? nc == 4 ? s(x,2) : nc == 8 ? s(x,7) : s(x,0) \ - : c == 4 ? nc == 8 ? s(x,0) : s(x,1) \ - : c == 5 ? nc == 8 ? s(x,1) : s(x,2) \ - : c == 6 ? s(x,2) \ - : s(x,3))) - -#if defined(FT4_SET) -#undef dec_fmvars -#define dec_fmvars -#define fwd_rnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,ft_tab,fwd_var,rf1,c) -#elif defined(FT1_SET) -#undef dec_fmvars -#define dec_fmvars -#define fwd_rnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,upr,ft_tab,fwd_var,rf1,c) -#else -#define fwd_rnd(y,x,k,c) s(y,c) = fwd_mcol(no_table(x,s_box,fwd_var,rf1,c)) ^ (k)[c] -#endif - -#if defined(FL4_SET) -#define fwd_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,fl_tab,fwd_var,rf1,c) -#elif defined(FL1_SET) -#define fwd_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,ups,fl_tab,fwd_var,rf1,c) -#else -#define fwd_lrnd(y,x,k,c) s(y,c) = no_table(x,s_box,fwd_var,rf1,c) ^ (k)[c] -#endif - -aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]) -{ aes_32t locals(b0, b1); - const aes_32t *kp = cx->k_sch; - dec_fmvars /* declare variables for fwd_mcol() if needed */ - - if(!(cx->n_blk & 1)) return aes_bad; - - state_in(b0, in_blk, kp); - -#if (ENC_UNROLL == FULL) - - kp += (cx->n_rnd - 9) * nc; - - switch(cx->n_rnd) - { - case 14: round(fwd_rnd, b1, b0, kp - 4 * nc); - round(fwd_rnd, b0, b1, kp - 3 * nc); - case 12: round(fwd_rnd, b1, b0, kp - 2 * nc); - round(fwd_rnd, b0, b1, kp - nc); - case 10: round(fwd_rnd, b1, b0, kp ); - round(fwd_rnd, b0, b1, kp + nc); - round(fwd_rnd, b1, b0, kp + 2 * nc); - round(fwd_rnd, b0, b1, kp + 3 * nc); - round(fwd_rnd, b1, b0, kp + 4 * nc); - round(fwd_rnd, b0, b1, kp + 5 * nc); - round(fwd_rnd, b1, b0, kp + 6 * nc); - round(fwd_rnd, b0, b1, kp + 7 * nc); - round(fwd_rnd, b1, b0, kp + 8 * nc); - round(fwd_lrnd, b0, b1, kp + 9 * nc); - } -#else - -#if (ENC_UNROLL == PARTIAL) - { aes_32t rnd; - for(rnd = 0; rnd < (cx->n_rnd >> 1) - 1; ++rnd) - { - kp += nc; - round(fwd_rnd, b1, b0, kp); - kp += nc; - round(fwd_rnd, b0, b1, kp); - } - kp += nc; - round(fwd_rnd, b1, b0, kp); -#else - { aes_32t rnd, *p0 = b0, *p1 = b1, *pt; - for(rnd = 0; rnd < cx->n_rnd - 1; ++rnd) - { - kp += nc; - round(fwd_rnd, p1, p0, kp); - pt = p0, p0 = p1, p1 = pt; - } -#endif - kp += nc; - round(fwd_lrnd, b0, b1, kp); - } -#endif - - state_out(out_blk, b0); - return aes_good; -} - -#endif - -#if defined(DECRYPTION) - -#define inv_var(x,r,c) \ - ( r == 0 ? \ - ( c == 0 ? s(x,0) \ - : c == 1 ? s(x,1) \ - : c == 2 ? s(x,2) \ - : c == 3 ? s(x,3) \ - : c == 4 ? s(x,4) \ - : c == 5 ? s(x,5) \ - : c == 6 ? s(x,6) \ - : s(x,7))\ - : r == 1 ? \ - ( c == 0 ? nc == 4 ? s(x,3) : nc == 8 ? s(x,7) : s(x,5) \ - : c == 1 ? s(x,0) \ - : c == 2 ? s(x,1) \ - : c == 3 ? s(x,2) \ - : c == 4 ? s(x,3) \ - : c == 5 ? s(x,4) \ - : c == 6 ? s(x,5) \ - : s(x,6))\ - : r == 2 ? \ - ( c == 0 ? nc == 4 ? s(x,2) : nc == 8 ? s(x,5) : s(x,4) \ - : c == 1 ? nc == 4 ? s(x,3) : nc == 8 ? s(x,6) : s(x,5) \ - : c == 2 ? nc == 8 ? s(x,7) : s(x,0) \ - : c == 3 ? nc == 8 ? s(x,0) : s(x,1) \ - : c == 4 ? nc == 8 ? s(x,1) : s(x,2) \ - : c == 5 ? nc == 8 ? s(x,2) : s(x,3) \ - : c == 6 ? s(x,3) \ - : s(x,4))\ - : \ - ( c == 0 ? nc == 4 ? s(x,1) : nc == 8 ? s(x,4) : s(x,3) \ - : c == 1 ? nc == 4 ? s(x,2) : nc == 8 ? s(x,5) : s(x,4) \ - : c == 2 ? nc == 4 ? s(x,3) : nc == 8 ? s(x,6) : s(x,5) \ - : c == 3 ? nc == 8 ? s(x,7) : s(x,0) \ - : c == 4 ? nc == 8 ? s(x,0) : s(x,1) \ - : c == 5 ? nc == 8 ? s(x,1) : s(x,2) \ - : c == 6 ? s(x,2) \ - : s(x,3))) - -#if defined(IT4_SET) -#undef dec_imvars -#define dec_imvars -#define inv_rnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,it_tab,inv_var,rf1,c) -#elif defined(IT1_SET) -#undef dec_imvars -#define dec_imvars -#define inv_rnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,upr,it_tab,inv_var,rf1,c) -#else -#define inv_rnd(y,x,k,c) s(y,c) = inv_mcol(no_table(x,inv_s_box,inv_var,rf1,c) ^ (k)[c]) -#endif - -#if defined(IL4_SET) -#define inv_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,il_tab,inv_var,rf1,c) -#elif defined(IL1_SET) -#define inv_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,ups,il_tab,inv_var,rf1,c) -#else -#define inv_lrnd(y,x,k,c) s(y,c) = no_table(x,inv_s_box,inv_var,rf1,c) ^ (k)[c] -#endif - -aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]) -{ aes_32t locals(b0, b1); - const aes_32t *kp = cx->k_sch + nc * cx->n_rnd; - dec_imvars /* declare variables for inv_mcol() if needed */ - - if(!(cx->n_blk & 2)) return aes_bad; - - state_in(b0, in_blk, kp); - -#if (DEC_UNROLL == FULL) - - kp = cx->k_sch + 9 * nc; - switch(cx->n_rnd) - { - case 14: round(inv_rnd, b1, b0, kp + 4 * nc); - round(inv_rnd, b0, b1, kp + 3 * nc); - case 12: round(inv_rnd, b1, b0, kp + 2 * nc); - round(inv_rnd, b0, b1, kp + nc ); - case 10: round(inv_rnd, b1, b0, kp ); - round(inv_rnd, b0, b1, kp - nc); - round(inv_rnd, b1, b0, kp - 2 * nc); - round(inv_rnd, b0, b1, kp - 3 * nc); - round(inv_rnd, b1, b0, kp - 4 * nc); - round(inv_rnd, b0, b1, kp - 5 * nc); - round(inv_rnd, b1, b0, kp - 6 * nc); - round(inv_rnd, b0, b1, kp - 7 * nc); - round(inv_rnd, b1, b0, kp - 8 * nc); - round(inv_lrnd, b0, b1, kp - 9 * nc); - } -#else - -#if (DEC_UNROLL == PARTIAL) - { aes_32t rnd; - for(rnd = 0; rnd < (cx->n_rnd >> 1) - 1; ++rnd) - { - kp -= nc; - round(inv_rnd, b1, b0, kp); - kp -= nc; - round(inv_rnd, b0, b1, kp); - } - kp -= nc; - round(inv_rnd, b1, b0, kp); -#else - { aes_32t rnd, *p0 = b0, *p1 = b1, *pt; - for(rnd = 0; rnd < cx->n_rnd - 1; ++rnd) - { - kp -= nc; - round(inv_rnd, p1, p0, kp); - pt = p0, p0 = p1, p1 = pt; - } -#endif - kp -= nc; - round(inv_lrnd, b0, b1, kp); - } -#endif - - state_out(out_blk, b0); - return aes_good; -} - -#endif diff --git a/CPP/7zip/Crypto/AES/aeskey.c b/CPP/7zip/Crypto/AES/aeskey.c deleted file mode 100755 index d281e1a8..00000000 --- a/CPP/7zip/Crypto/AES/aeskey.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - ------------------------------------------------------------------------- - Copyright (c) 2001, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and fitness for purpose. - ------------------------------------------------------------------------- - Issue Date: 29/07/2002 - - This file contains the code for implementing the key schedule for AES - (Rijndael) for block and key sizes of 16, 24, and 32 bytes. -*/ - -#include "aesopt.h" - -#if defined(BLOCK_SIZE) && (BLOCK_SIZE & 7) -#error An illegal block size has been specified. -#endif - -/* Subroutine to set the block size (if variable) in bytes, legal - values being 16, 24 and 32. -*/ - -#if !defined(BLOCK_SIZE) - -aes_rval aes_blk_len(unsigned int blen, aes_ctx cx[1]) -{ -#if !defined(FIXED_TABLES) - if(!tab_init) gen_tabs(); -#endif - - if((blen & 7) || blen < 16 || blen > 32) - { - cx->n_blk = 0; return aes_bad; - } - - cx->n_blk = blen; - return aes_good; -} - -#endif - -/* Initialise the key schedule from the user supplied key. The key - length is now specified in bytes - 16, 24 or 32 as appropriate. - This corresponds to bit lengths of 128, 192 and 256 bits, and - to Nk values of 4, 6 and 8 respectively. - - The following macros implement a single cycle in the key - schedule generation process. The number of cycles needed - for each cx->n_col and nk value is: - - nk = 4 5 6 7 8 - ------------------------------ - cx->n_col = 4 10 9 8 7 7 - cx->n_col = 5 14 11 10 9 9 - cx->n_col = 6 19 15 12 11 11 - cx->n_col = 7 21 19 16 13 14 - cx->n_col = 8 29 23 19 17 14 -*/ - -#define ke4(k,i) \ -{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ rcon_tab[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ - k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ -} -#define kel4(k,i) \ -{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ rcon_tab[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ - k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ -} - -#define ke6(k,i) \ -{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ - k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ - k[6*(i)+10] = ss[4] ^= ss[3]; k[6*(i)+11] = ss[5] ^= ss[4]; \ -} -#define kel6(k,i) \ -{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ - k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ -} - -#define ke8(k,i) \ -{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ - k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ - k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); k[8*(i)+13] = ss[5] ^= ss[4]; \ - k[8*(i)+14] = ss[6] ^= ss[5]; k[8*(i)+15] = ss[7] ^= ss[6]; \ -} -#define kel8(k,i) \ -{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ - k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ -} - -#if defined(ENCRYPTION_KEY_SCHEDULE) - -aes_rval aes_enc_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]) -{ aes_32t ss[8]; - -#if !defined(FIXED_TABLES) - if(!tab_init) gen_tabs(); -#endif - -#if !defined(BLOCK_SIZE) - if(!cx->n_blk) cx->n_blk = 16; -#else - cx->n_blk = BLOCK_SIZE; -#endif - - cx->n_blk = (cx->n_blk & ~3) | 1; - - cx->k_sch[0] = ss[0] = word_in(in_key ); - cx->k_sch[1] = ss[1] = word_in(in_key + 4); - cx->k_sch[2] = ss[2] = word_in(in_key + 8); - cx->k_sch[3] = ss[3] = word_in(in_key + 12); - -#if (BLOCK_SIZE == 16) && (ENC_UNROLL != NONE) - - switch(klen) - { - case 16: ke4(cx->k_sch, 0); ke4(cx->k_sch, 1); - ke4(cx->k_sch, 2); ke4(cx->k_sch, 3); - ke4(cx->k_sch, 4); ke4(cx->k_sch, 5); - ke4(cx->k_sch, 6); ke4(cx->k_sch, 7); - ke4(cx->k_sch, 8); kel4(cx->k_sch, 9); - cx->n_rnd = 10; break; - case 24: cx->k_sch[4] = ss[4] = word_in(in_key + 16); - cx->k_sch[5] = ss[5] = word_in(in_key + 20); - ke6(cx->k_sch, 0); ke6(cx->k_sch, 1); - ke6(cx->k_sch, 2); ke6(cx->k_sch, 3); - ke6(cx->k_sch, 4); ke6(cx->k_sch, 5); - ke6(cx->k_sch, 6); kel6(cx->k_sch, 7); - cx->n_rnd = 12; break; - case 32: cx->k_sch[4] = ss[4] = word_in(in_key + 16); - cx->k_sch[5] = ss[5] = word_in(in_key + 20); - cx->k_sch[6] = ss[6] = word_in(in_key + 24); - cx->k_sch[7] = ss[7] = word_in(in_key + 28); - ke8(cx->k_sch, 0); ke8(cx->k_sch, 1); - ke8(cx->k_sch, 2); ke8(cx->k_sch, 3); - ke8(cx->k_sch, 4); ke8(cx->k_sch, 5); - kel8(cx->k_sch, 6); - cx->n_rnd = 14; break; - default: cx->n_rnd = 0; return aes_bad; - } -#else - { aes_32t i, l; - cx->n_rnd = ((klen >> 2) > nc ? (klen >> 2) : nc) + 6; - l = (nc * cx->n_rnd + nc - 1) / (klen >> 2); - - switch(klen) - { - case 16: for(i = 0; i < l; ++i) - ke4(cx->k_sch, i); - break; - case 24: cx->k_sch[4] = ss[4] = word_in(in_key + 16); - cx->k_sch[5] = ss[5] = word_in(in_key + 20); - for(i = 0; i < l; ++i) - ke6(cx->k_sch, i); - break; - case 32: cx->k_sch[4] = ss[4] = word_in(in_key + 16); - cx->k_sch[5] = ss[5] = word_in(in_key + 20); - cx->k_sch[6] = ss[6] = word_in(in_key + 24); - cx->k_sch[7] = ss[7] = word_in(in_key + 28); - for(i = 0; i < l; ++i) - ke8(cx->k_sch, i); - break; - default: cx->n_rnd = 0; return aes_bad; - } - } -#endif - - return aes_good; -} - -#endif - -#if defined(DECRYPTION_KEY_SCHEDULE) - -#if (DEC_ROUND != NO_TABLES) -#define d_vars dec_imvars -#define ff(x) inv_mcol(x) -#else -#define ff(x) (x) -#define d_vars -#endif - -#if 1 -#define kdf4(k,i) \ -{ ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; ss[1] = ss[1] ^ ss[3]; ss[2] = ss[2] ^ ss[3]; ss[3] = ss[3]; \ - ss[4] = ls_box(ss[(i+3) % 4], 3) ^ rcon_tab[i]; ss[i % 4] ^= ss[4]; \ - ss[4] ^= k[4*(i)]; k[4*(i)+4] = ff(ss[4]); ss[4] ^= k[4*(i)+1]; k[4*(i)+5] = ff(ss[4]); \ - ss[4] ^= k[4*(i)+2]; k[4*(i)+6] = ff(ss[4]); ss[4] ^= k[4*(i)+3]; k[4*(i)+7] = ff(ss[4]); \ -} -#define kd4(k,i) \ -{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ rcon_tab[i]; ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \ - k[4*(i)+4] = ss[4] ^= k[4*(i)]; k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \ - k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \ -} -#define kdl4(k,i) \ -{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ rcon_tab[i]; ss[i % 4] ^= ss[4]; \ - k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; k[4*(i)+5] = ss[1] ^ ss[3]; \ - k[4*(i)+6] = ss[0]; k[4*(i)+7] = ss[1]; \ -} -#else -#define kdf4(k,i) \ -{ ss[0] ^= ls_box(ss[3],3) ^ rcon_tab[i]; k[4*(i)+ 4] = ff(ss[0]); ss[1] ^= ss[0]; k[4*(i)+ 5] = ff(ss[1]); \ - ss[2] ^= ss[1]; k[4*(i)+ 6] = ff(ss[2]); ss[3] ^= ss[2]; k[4*(i)+ 7] = ff(ss[3]); \ -} -#define kd4(k,i) \ -{ ss[4] = ls_box(ss[3],3) ^ rcon_tab[i]; \ - ss[0] ^= ss[4]; ss[4] = ff(ss[4]); k[4*(i)+ 4] = ss[4] ^= k[4*(i)]; \ - ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[4] ^= k[4*(i)+ 1]; \ - ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[4] ^= k[4*(i)+ 2]; \ - ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[4] ^= k[4*(i)+ 3]; \ -} -#define kdl4(k,i) \ -{ ss[0] ^= ls_box(ss[3],3) ^ rcon_tab[i]; k[4*(i)+ 4] = ss[0]; ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[1]; \ - ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[2]; ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[3]; \ -} -#endif - -#define kdf6(k,i) \ -{ ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; k[6*(i)+ 6] = ff(ss[0]); ss[1] ^= ss[0]; k[6*(i)+ 7] = ff(ss[1]); \ - ss[2] ^= ss[1]; k[6*(i)+ 8] = ff(ss[2]); ss[3] ^= ss[2]; k[6*(i)+ 9] = ff(ss[3]); \ - ss[4] ^= ss[3]; k[6*(i)+10] = ff(ss[4]); ss[5] ^= ss[4]; k[6*(i)+11] = ff(ss[5]); \ -} -#define kd6(k,i) \ -{ ss[6] = ls_box(ss[5],3) ^ rcon_tab[i]; \ - ss[0] ^= ss[6]; ss[6] = ff(ss[6]); k[6*(i)+ 6] = ss[6] ^= k[6*(i)]; \ - ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[6] ^= k[6*(i)+ 1]; \ - ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[6] ^= k[6*(i)+ 2]; \ - ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[6] ^= k[6*(i)+ 3]; \ - ss[4] ^= ss[3]; k[6*(i)+10] = ss[6] ^= k[6*(i)+ 4]; \ - ss[5] ^= ss[4]; k[6*(i)+11] = ss[6] ^= k[6*(i)+ 5]; \ -} -#define kdl6(k,i) \ -{ ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; k[6*(i)+ 6] = ss[0]; ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[1]; \ - ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[2]; ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[3]; \ -} - -#define kdf8(k,i) \ -{ ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; k[8*(i)+ 8] = ff(ss[0]); ss[1] ^= ss[0]; k[8*(i)+ 9] = ff(ss[1]); \ - ss[2] ^= ss[1]; k[8*(i)+10] = ff(ss[2]); ss[3] ^= ss[2]; k[8*(i)+11] = ff(ss[3]); \ - ss[4] ^= ls_box(ss[3],0); k[8*(i)+12] = ff(ss[4]); ss[5] ^= ss[4]; k[8*(i)+13] = ff(ss[5]); \ - ss[6] ^= ss[5]; k[8*(i)+14] = ff(ss[6]); ss[7] ^= ss[6]; k[8*(i)+15] = ff(ss[7]); \ -} -#define kd8(k,i) \ -{ aes_32t g = ls_box(ss[7],3) ^ rcon_tab[i]; \ - ss[0] ^= g; g = ff(g); k[8*(i)+ 8] = g ^= k[8*(i)]; \ - ss[1] ^= ss[0]; k[8*(i)+ 9] = g ^= k[8*(i)+ 1]; \ - ss[2] ^= ss[1]; k[8*(i)+10] = g ^= k[8*(i)+ 2]; \ - ss[3] ^= ss[2]; k[8*(i)+11] = g ^= k[8*(i)+ 3]; \ - g = ls_box(ss[3],0); \ - ss[4] ^= g; g = ff(g); k[8*(i)+12] = g ^= k[8*(i)+ 4]; \ - ss[5] ^= ss[4]; k[8*(i)+13] = g ^= k[8*(i)+ 5]; \ - ss[6] ^= ss[5]; k[8*(i)+14] = g ^= k[8*(i)+ 6]; \ - ss[7] ^= ss[6]; k[8*(i)+15] = g ^= k[8*(i)+ 7]; \ -} -#define kdl8(k,i) \ -{ ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; k[8*(i)+ 8] = ss[0]; ss[1] ^= ss[0]; k[8*(i)+ 9] = ss[1]; \ - ss[2] ^= ss[1]; k[8*(i)+10] = ss[2]; ss[3] ^= ss[2]; k[8*(i)+11] = ss[3]; \ -} - -aes_rval aes_dec_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]) -{ aes_32t ss[8]; - d_vars - -#if !defined(FIXED_TABLES) - if(!tab_init) gen_tabs(); -#endif - -#if !defined(BLOCK_SIZE) - if(!cx->n_blk) cx->n_blk = 16; -#else - cx->n_blk = BLOCK_SIZE; -#endif - - cx->n_blk = (cx->n_blk & ~3) | 2; - - cx->k_sch[0] = ss[0] = word_in(in_key ); - cx->k_sch[1] = ss[1] = word_in(in_key + 4); - cx->k_sch[2] = ss[2] = word_in(in_key + 8); - cx->k_sch[3] = ss[3] = word_in(in_key + 12); - -#if (BLOCK_SIZE == 16) && (DEC_UNROLL != NONE) - - switch(klen) - { - case 16: kdf4(cx->k_sch, 0); kd4(cx->k_sch, 1); - kd4(cx->k_sch, 2); kd4(cx->k_sch, 3); - kd4(cx->k_sch, 4); kd4(cx->k_sch, 5); - kd4(cx->k_sch, 6); kd4(cx->k_sch, 7); - kd4(cx->k_sch, 8); kdl4(cx->k_sch, 9); - cx->n_rnd = 10; break; - case 24: cx->k_sch[4] = ff(ss[4] = word_in(in_key + 16)); - cx->k_sch[5] = ff(ss[5] = word_in(in_key + 20)); - kdf6(cx->k_sch, 0); kd6(cx->k_sch, 1); - kd6(cx->k_sch, 2); kd6(cx->k_sch, 3); - kd6(cx->k_sch, 4); kd6(cx->k_sch, 5); - kd6(cx->k_sch, 6); kdl6(cx->k_sch, 7); - cx->n_rnd = 12; break; - case 32: cx->k_sch[4] = ff(ss[4] = word_in(in_key + 16)); - cx->k_sch[5] = ff(ss[5] = word_in(in_key + 20)); - cx->k_sch[6] = ff(ss[6] = word_in(in_key + 24)); - cx->k_sch[7] = ff(ss[7] = word_in(in_key + 28)); - kdf8(cx->k_sch, 0); kd8(cx->k_sch, 1); - kd8(cx->k_sch, 2); kd8(cx->k_sch, 3); - kd8(cx->k_sch, 4); kd8(cx->k_sch, 5); - kdl8(cx->k_sch, 6); - cx->n_rnd = 14; break; - default: cx->n_rnd = 0; return aes_bad; - } -#else - { aes_32t i, l; - cx->n_rnd = ((klen >> 2) > nc ? (klen >> 2) : nc) + 6; - l = (nc * cx->n_rnd + nc - 1) / (klen >> 2); - - switch(klen) - { - case 16: - for(i = 0; i < l; ++i) - ke4(cx->k_sch, i); - break; - case 24: cx->k_sch[4] = ss[4] = word_in(in_key + 16); - cx->k_sch[5] = ss[5] = word_in(in_key + 20); - for(i = 0; i < l; ++i) - ke6(cx->k_sch, i); - break; - case 32: cx->k_sch[4] = ss[4] = word_in(in_key + 16); - cx->k_sch[5] = ss[5] = word_in(in_key + 20); - cx->k_sch[6] = ss[6] = word_in(in_key + 24); - cx->k_sch[7] = ss[7] = word_in(in_key + 28); - for(i = 0; i < l; ++i) - ke8(cx->k_sch, i); - break; - default: cx->n_rnd = 0; return aes_bad; - } -#if (DEC_ROUND != NO_TABLES) - for(i = nc; i < nc * cx->n_rnd; ++i) - cx->k_sch[i] = inv_mcol(cx->k_sch[i]); -#endif - } -#endif - - return aes_good; -} - -#endif diff --git a/CPP/7zip/Crypto/AES/aesopt.h b/CPP/7zip/Crypto/AES/aesopt.h deleted file mode 100755 index bcad345f..00000000 --- a/CPP/7zip/Crypto/AES/aesopt.h +++ /dev/null @@ -1,839 +0,0 @@ -/* - ------------------------------------------------------------------------- - Copyright (c) 2001, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and fitness for purpose. - ------------------------------------------------------------------------- - Issue Date: 29/07/2002 - - This file contains the compilation options for AES (Rijndael) and code - that is common across encryption, key scheduling and table generation. - - OPERATION - - These source code files implement the AES algorithm Rijndael designed by - Joan Daemen and Vincent Rijmen. The version in aes.c is designed for - block and key sizes of 128, 192 and 256 bits (16, 24 and 32 bytes) while - that in aespp.c provides for block and keys sizes of 128, 160, 192, 224 - and 256 bits (16, 20, 24, 28 and 32 bytes). This file is a common header - file for these two implementations and for aesref.c, which is a reference - implementation. - - This version is designed for flexibility and speed using operations on - 32-bit words rather than operations on bytes. It provides aes_both fixed - and dynamic block and key lengths and can also run with either big or - little endian internal byte order (see aes.h). It inputs block and key - lengths in bytes with the legal values being 16, 24 and 32 for aes.c and - 16, 20, 24, 28 and 32 for aespp.c - - THE CIPHER INTERFACE - - aes_08t (an unsigned 8-bit type) - aes_32t (an unsigned 32-bit type) - aes_fret (a signed 16 bit type for function return values) - aes_good (value != 0, a good return) - aes_bad (value == 0, an error return) - struct aes_ctx (structure for the cipher encryption context) - struct aes_ctx (structure for the cipher decryption context) - aes_rval the function return type (aes_fret if not DLL) - - C subroutine calls: - - aes_rval aes_blk_len(unsigned int blen, aes_ctx cx[1]); - aes_rval aes_enc_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]); - aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]); - - aes_rval aes_dec_len(unsigned int blen, aes_ctx cx[1]); - aes_rval aes_dec_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]); - aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]); - - IMPORTANT NOTE: If you are using this C interface and your compiler does - not set the memory used for objects to zero before use, you will need to - ensure that cx.s_flg is set to zero before using these subroutine calls. - - C++ aes class subroutines: - - class AESclass for encryption - class AESclass for decryption - - aes_rval len(unsigned int blen = 16); - aes_rval key(const unsigned char in_key[], unsigned int klen); - aes_rval blk(const unsigned char in_blk[], unsigned char out_blk[]); - - aes_rval len(unsigned int blen = 16); - aes_rval key(const unsigned char in_key[], unsigned int klen); - aes_rval blk(const unsigned char in_blk[], unsigned char out_blk[]); - - The block length inputs to set_block and set_key are in numbers of - BYTES, not bits. The calls to subroutines must be made in the above - order but multiple calls can be made without repeating earlier calls - if their parameters have not changed. If the cipher block length is - variable but set_blk has not been called before cipher operations a - value of 16 is assumed (that is, the AES block size). In contrast to - earlier versions the block and key length parameters are now checked - for correctness and the encryption and decryption routines check to - ensure that an appropriate key has been set before they are called. - - COMPILATION - - The files used to provide AES (Rijndael) are - - a. aes.h for the definitions needed for use in C. - b. aescpp.h for the definitions needed for use in C++. - c. aesopt.h for setting compilation options (also includes common - code). - d. aescrypt.c for encryption and decrytpion, or - e. aescrypt.asm for encryption and decryption using assembler code. - f. aeskey.c for key scheduling. - g. aestab.c for table loading or generation. - - The assembler code uses the NASM assembler. The above files provice - block and key lengths of 16, 24 and 32 bytes (128, 192 and 256 bits). - If aescrypp.c and aeskeypp.c are used instead of aescrypt.c and - aeskey.c respectively, the block and key lengths can then be 16, 20, - 24, 28 or 32 bytes. However this code has not been optimised to the - same extent and is hence slower (esepcially for the AES block size - of 16 bytes). - - To compile AES (Rijndael) for use in C code use aes.h and exclude - the AES_DLL define in aes.h - - To compile AES (Rijndael) for use in in C++ code use aescpp.h and - exclude the AES_DLL define in aes.h - - To compile AES (Rijndael) in C as a Dynamic Link Library DLL) use - aes.h, include the AES_DLL define and compile the DLL. If using - the test files to test the DLL, exclude aes.c from the test build - project and compile it with the same defines as used for the DLL - (ensure that the DLL path is correct) - - CONFIGURATION OPTIONS (here and in aes.h) - - a. define BLOCK_SIZE in aes.h to set the cipher block size (16, 24 - or 32 for the standard code, or 16, 20, 24, 28 or 32 for the - extended code) or leave this undefined for dynamically variable - block size (this will result in much slower code). - b. set AES_DLL in aes.h if AES (Rijndael) is to be compiled as a DLL - c. You may need to set PLATFORM_BYTE_ORDER to define the byte order. - d. If you want the code to run in a specific internal byte order, then - INTERNAL_BYTE_ORDER must be set accordingly. - e. set other configuration options decribed below. -*/ - -#ifndef _AESOPT_H -#define _AESOPT_H - -/* START OF CONFIGURATION OPTIONS - - USE OF DEFINES - - Later in this section there are a number of defines that control the - operation of the code. In each section, the purpose of each define is - explained so that the relevant form can be included or excluded by - setting either 1's or 0's respectively on the branches of the related - #if clauses. -*/ - -/* 1. PLATFORM SPECIFIC INCLUDES */ - -#if defined( __CRYPTLIB__ ) && !defined( INC_ALL ) && !defined( INC_CHILD ) -#include "crypt/aes.h" -#else - #include "aes.h" -#endif - -// 2003-09-16: Changed by Igor Pavlov. Check it. -// #if defined(__GNUC__) || defined(__GNU_LIBRARY__) -#if (defined(__GNUC__) || defined(__GNU_LIBRARY__)) && !defined(_WIN32) - -# include <endian.h> -# include <byteswap.h> -#elif defined(__CRYPTLIB__) -# if defined( INC_ALL ) -# include "crypt.h" -# elif defined( INC_CHILD ) -# include "../crypt.h" -# else -# include "crypt.h" -# endif -# if defined(DATA_LITTLEENDIAN) -# define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -# else -# define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -# endif -#elif defined(_MSC_VER) -# include <stdlib.h> -#elif !defined(_WIN32) -# include <stdlib.h> -# if !defined (_ENDIAN_H) -# include <sys/param.h> -# else -# include _ENDIAN_H -# endif -#endif - -/* 2. BYTE ORDER IN 32-BIT WORDS - - To obtain the highest speed on processors with 32-bit words, this code - needs to determine the order in which bytes are packed into such words. - The following block of code is an attempt to capture the most obvious - ways in which various environemnts define byte order. It may well fail, - in which case the definitions will need to be set by editing at the - points marked **** EDIT HERE IF NECESSARY **** below. -*/ -#define AES_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ -#define AES_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ - -#if !defined(PLATFORM_BYTE_ORDER) -#if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN) -# if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) -# if defined(BYTE_ORDER) -# if (BYTE_ORDER == LITTLE_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -# elif (BYTE_ORDER == BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -# endif -# endif -# elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -# elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -# endif -#elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN) -# if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) -# if defined(_BYTE_ORDER) -# if (_BYTE_ORDER == _LITTLE_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -# elif (_BYTE_ORDER == _BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -# endif -# endif -# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -# elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -# endif -#elif 0 /* **** EDIT HERE IF NECESSARY **** */ -#define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -#elif 0 /* **** EDIT HERE IF NECESSARY **** */ -#define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -#elif (('1234' >> 24) == '1') -# define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN -#elif (('4321' >> 24) == '1') -# define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN -#endif -#endif - -#if !defined(PLATFORM_BYTE_ORDER) -# error Please set undetermined byte order (lines 233 or 235 of aesopt.h). -#endif - -/* 3. ASSEMBLER SUPPORT - - If the assembler code is used for encryption and decryption this file only - provides key scheduling so the following defines are used -*/ -#ifdef AES_ASM -#define ENCRYPTION_KEY_SCHEDULE -#define DECRYPTION_KEY_SCHEDULE -#else - -/* 4. FUNCTIONS REQUIRED - - This implementation provides five main subroutines which provide for - setting block length, setting encryption and decryption keys and for - encryption and decryption. When the assembler code is not being used - the following definition blocks allow the selection of the routines - that are to be included in the compilation. -*/ -#if 1 -#define ENCRYPTION_KEY_SCHEDULE -#endif - -#if 1 -#define DECRYPTION_KEY_SCHEDULE -#endif - -#if 1 -#define ENCRYPTION -#endif - -#if 1 -#define DECRYPTION -#endif - -#endif - -/* 5. BYTE ORDER WITHIN 32 BIT WORDS - - The fundamental data processing units in Rijndael are 8-bit bytes. The - input, output and key input are all enumerated arrays of bytes in which - bytes are numbered starting at zero and increasing to one less than the - number of bytes in the array in question. This enumeration is only used - for naming bytes and does not imply any adjacency or order relationship - from one byte to another. When these inputs and outputs are considered - as bit sequences, bits 8*n to 8*n+7 of the bit sequence are mapped to - byte[n] with bit 8n+i in the sequence mapped to bit 7-i within the byte. - In this implementation bits are numbered from 0 to 7 starting at the - numerically least significant end of each byte (bit n represents 2^n). - - However, Rijndael can be implemented more efficiently using 32-bit - words by packing bytes into words so that bytes 4*n to 4*n+3 are placed - into word[n]. While in principle these bytes can be assembled into words - in any positions, this implementation only supports the two formats in - which bytes in adjacent positions within words also have adjacent byte - numbers. This order is called big-endian if the lowest numbered bytes - in words have the highest numeric significance and little-endian if the - opposite applies. - - This code can work in either order irrespective of the order used by the - machine on which it runs. Normally the internal byte order will be set - to the order of the processor on which the code is to be run but this - define can be used to reverse this in special situations -*/ -#if 1 -#define INTERNAL_BYTE_ORDER PLATFORM_BYTE_ORDER -#elif defined(AES_LITTLE_ENDIAN) -#define INTERNAL_BYTE_ORDER AES_LITTLE_ENDIAN -#elif defined(AES_BIG_ENDIAN) -#define INTERNAL_BYTE_ORDER AES_BIG_ENDIAN -#endif - -/* 6. FAST INPUT/OUTPUT OPERATIONS. - - On some machines it is possible to improve speed by transferring the - bytes in the input and output arrays to and from the internal 32-bit - variables by addressing these arrays as if they are arrays of 32-bit - words. On some machines this will always be possible but there may - be a large performance penalty if the byte arrays are not aligned on - the normal word boundaries. On other machines this technique will - lead to memory access errors when such 32-bit word accesses are not - properly aligned. The option SAFE_IO avoids such problems but will - often be slower on those machines that support misaligned access - (especially so if care is taken to align the input and output byte - arrays on 32-bit word boundaries). If SAFE_IO is not defined it is - assumed that access to byte arrays as if they are arrays of 32-bit - words will not cause problems when such accesses are misaligned. -*/ -#if 1 -#define SAFE_IO -#endif - -/* 7. LOOP UNROLLING - - The code for encryption and decrytpion cycles through a number of rounds - that can be implemented either in a loop or by expanding the code into a - long sequence of instructions, the latter producing a larger program but - one that will often be much faster. The latter is called loop unrolling. - There are also potential speed advantages in expanding two iterations in - a loop with half the number of iterations, which is called partial loop - unrolling. The following options allow partial or full loop unrolling - to be set independently for encryption and decryption -*/ -#if 1 -#define ENC_UNROLL FULL -#elif 0 -#define ENC_UNROLL PARTIAL -#else -#define ENC_UNROLL NONE -#endif - -// 7-Zip: Small size for SFX -#ifdef _SFX -#define DEC_UNROLL NONE -#else - -#if 1 -#define DEC_UNROLL FULL -#elif 0 -#define DEC_UNROLL PARTIAL -#else -#define DEC_UNROLL NONE -#endif - -#endif - -/* 8. FIXED OR DYNAMIC TABLES - - When this section is included the tables used by the code are comipled - statically into the binary file. Otherwise they are computed once when - the code is first used. -*/ -#if 0 -#define FIXED_TABLES -#endif - -/* 9. FAST FINITE FIELD OPERATIONS - - If this section is included, tables are used to provide faster finite - field arithmetic (this has no effect if FIXED_TABLES is defined). -*/ -#if 1 -#define FF_TABLES -#endif - -/* 10. INTERNAL STATE VARIABLE FORMAT - - The internal state of Rijndael is stored in a number of local 32-bit - word varaibles which can be defined either as an array or as individual - names variables. Include this section if you want to store these local - varaibles in arrays. Otherwise individual local variables will be used. -*/ -#if 1 -#define ARRAYS -#endif - -/* In this implementation the columns of the state array are each held in - 32-bit words. The state array can be held in various ways: in an array - of words, in a number of individual word variables or in a number of - processor registers. The following define maps a variable name x and - a column number c to the way the state array variable is to be held. - The first define below maps the state into an array x[c] whereas the - second form maps the state into a number of individual variables x0, - x1, etc. Another form could map individual state colums to machine - register names. -*/ - -#if defined(ARRAYS) -#define s(x,c) x[c] -#else -#define s(x,c) x##c -#endif - -/* 11. VARIABLE BLOCK SIZE SPEED - - This section is only relevant if you wish to use the variable block - length feature of the code. Include this section if you place more - emphasis on speed rather than code size. -*/ -#if 1 -#define FAST_VARIABLE -#endif - -/* 12. INTERNAL TABLE CONFIGURATION - - This cipher proceeds by repeating in a number of cycles known as 'rounds' - which are implemented by a round function which can optionally be speeded - up using tables. The basic tables are each 256 32-bit words, with either - one or four tables being required for each round function depending on - how much speed is required. The encryption and decryption round functions - are different and the last encryption and decrytpion round functions are - different again making four different round functions in all. - - This means that: - 1. Normal encryption and decryption rounds can each use either 0, 1 - or 4 tables and table spaces of 0, 1024 or 4096 bytes each. - 2. The last encryption and decryption rounds can also use either 0, 1 - or 4 tables and table spaces of 0, 1024 or 4096 bytes each. - - Include or exclude the appropriate definitions below to set the number - of tables used by this implementation. -*/ - -#if 1 /* set tables for the normal encryption round */ -#define ENC_ROUND FOUR_TABLES -#elif 0 -#define ENC_ROUND ONE_TABLE -#else -#define ENC_ROUND NO_TABLES -#endif - -#if 1 /* set tables for the last encryption round */ -#define LAST_ENC_ROUND FOUR_TABLES -#elif 0 -#define LAST_ENC_ROUND ONE_TABLE -#else -#define LAST_ENC_ROUND NO_TABLES -#endif - -#if 1 /* set tables for the normal decryption round */ -#define DEC_ROUND FOUR_TABLES -#elif 0 -#define DEC_ROUND ONE_TABLE -#else -#define DEC_ROUND NO_TABLES -#endif - -#if 1 /* set tables for the last decryption round */ -#define LAST_DEC_ROUND FOUR_TABLES -#elif 0 -#define LAST_DEC_ROUND ONE_TABLE -#else -#define LAST_DEC_ROUND NO_TABLES -#endif - -/* The decryption key schedule can be speeded up with tables in the same - way that the round functions can. Include or exclude the following - defines to set this requirement. -*/ -#if 1 -#define KEY_SCHED FOUR_TABLES -#elif 0 -#define KEY_SCHED ONE_TABLE -#else -#define KEY_SCHED NO_TABLES -#endif - -/* END OF CONFIGURATION OPTIONS */ - -#define NO_TABLES 0 /* DO NOT CHANGE */ -#define ONE_TABLE 1 /* DO NOT CHANGE */ -#define FOUR_TABLES 4 /* DO NOT CHANGE */ -#define NONE 0 /* DO NOT CHANGE */ -#define PARTIAL 1 /* DO NOT CHANGE */ -#define FULL 2 /* DO NOT CHANGE */ - -#if defined(BLOCK_SIZE) && ((BLOCK_SIZE & 3) || BLOCK_SIZE < 16 || BLOCK_SIZE > 32) -#error An illegal block size has been specified. -#endif - -#if !defined(BLOCK_SIZE) -#define RC_LENGTH 29 -#else -#define RC_LENGTH 5 * BLOCK_SIZE / 4 - (BLOCK_SIZE == 16 ? 10 : 11) -#endif - -/* Disable at least some poor combinations of options */ - -#if ENC_ROUND == NO_TABLES && LAST_ENC_ROUND != NO_TABLES -#undef LAST_ENC_ROUND -#define LAST_ENC_ROUND NO_TABLES -#elif ENC_ROUND == ONE_TABLE && LAST_ENC_ROUND == FOUR_TABLES -#undef LAST_ENC_ROUND -#define LAST_ENC_ROUND ONE_TABLE -#endif - -#if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE -#undef ENC_UNROLL -#define ENC_UNROLL NONE -#endif - -#if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES -#undef LAST_DEC_ROUND -#define LAST_DEC_ROUND NO_TABLES -#elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES -#undef LAST_DEC_ROUND -#define LAST_DEC_ROUND ONE_TABLE -#endif - -#if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE -#undef DEC_UNROLL -#define DEC_UNROLL NONE -#endif - -/* upr(x,n): rotates bytes within words by n positions, moving bytes to - higher index positions with wrap around into low positions - ups(x,n): moves bytes by n positions to higher index positions in - words but without wrap around - bval(x,n): extracts a byte from a word - - NOTE: The definitions given here are intended only for use with - unsigned variables and with shift counts that are compile - time constants -*/ - -#if (INTERNAL_BYTE_ORDER == AES_LITTLE_ENDIAN) -#if defined(_MSC_VER) -#define upr(x,n) _lrotl((aes_32t)(x), 8 * (n)) -#else -#define upr(x,n) ((aes_32t)(x) << 8 * (n) | (aes_32t)(x) >> 32 - 8 * (n)) -#endif -#define ups(x,n) ((aes_32t)(x) << 8 * (n)) -#define bval(x,n) ((aes_08t)((x) >> 8 * (n))) -#define bytes2word(b0, b1, b2, b3) \ - (((aes_32t)(b3) << 24) | ((aes_32t)(b2) << 16) | ((aes_32t)(b1) << 8) | (b0)) -#endif - -#if (INTERNAL_BYTE_ORDER == AES_BIG_ENDIAN) -#define upr(x,n) ((aes_32t)(x) >> 8 * (n) | (aes_32t)(x) << 32 - 8 * (n)) -#define ups(x,n) ((aes_32t)(x) >> 8 * (n))) -#define bval(x,n) ((aes_08t)((x) >> 24 - 8 * (n))) -#define bytes2word(b0, b1, b2, b3) \ - (((aes_32t)(b0) << 24) | ((aes_32t)(b1) << 16) | ((aes_32t)(b2) << 8) | (b3)) -#endif - -#if defined(SAFE_IO) - -#define word_in(x) bytes2word((x)[0], (x)[1], (x)[2], (x)[3]) -#define word_out(x,v) { (x)[0] = bval(v,0); (x)[1] = bval(v,1); \ - (x)[2] = bval(v,2); (x)[3] = bval(v,3); } - -#elif (INTERNAL_BYTE_ORDER == PLATFORM_BYTE_ORDER) - -#define word_in(x) *(aes_32t*)(x) -#define word_out(x,v) *(aes_32t*)(x) = (v) - -#else - -#if !defined(bswap_32) -#if !defined(_MSC_VER) -#define _lrotl(x,n) ((aes_32t)(x) << n | (aes_32t)(x) >> 32 - n) -#endif -#define bswap_32(x) ((_lrotl((x),8) & 0x00ff00ff) | (_lrotl((x),24) & 0xff00ff00)) -#endif - -#define word_in(x) bswap_32(*(aes_32t*)(x)) -#define word_out(x,v) *(aes_32t*)(x) = bswap_32(v) - -#endif - -/* the finite field modular polynomial and elements */ - -#define WPOLY 0x011b -#define BPOLY 0x1b - -/* multiply four bytes in GF(2^8) by 'x' {02} in parallel */ - -#define m1 0x80808080 -#define m2 0x7f7f7f7f -#define FFmulX(x) ((((x) & m2) << 1) ^ ((((x) & m1) >> 7) * BPOLY)) - -/* The following defines provide alternative definitions of FFmulX that might - give improved performance if a fast 32-bit multiply is not available. Note - that a temporary variable u needs to be defined where FFmulX is used. - -#define FFmulX(x) (u = (x) & m1, u |= (u >> 1), ((x) & m2) << 1) ^ ((u >> 3) | (u >> 6)) -#define m4 (0x01010101 * BPOLY) -#define FFmulX(x) (u = (x) & m1, ((x) & m2) << 1) ^ ((u - (u >> 7)) & m4) -*/ - -/* Work out which tables are needed for the different options */ - -#ifdef AES_ASM -#ifdef ENC_ROUND -#undef ENC_ROUND -#endif -#define ENC_ROUND FOUR_TABLES -#ifdef LAST_ENC_ROUND -#undef LAST_ENC_ROUND -#endif -#define LAST_ENC_ROUND FOUR_TABLES -#ifdef DEC_ROUND -#undef DEC_ROUND -#endif -#define DEC_ROUND FOUR_TABLES -#ifdef LAST_DEC_ROUND -#undef LAST_DEC_ROUND -#endif -#define LAST_DEC_ROUND FOUR_TABLES -#ifdef KEY_SCHED -#undef KEY_SCHED -#define KEY_SCHED FOUR_TABLES -#endif -#endif - -#if defined(ENCRYPTION) || defined(AES_ASM) -#if ENC_ROUND == ONE_TABLE -#define FT1_SET -#elif ENC_ROUND == FOUR_TABLES -#define FT4_SET -#else -#define SBX_SET -#endif -#if LAST_ENC_ROUND == ONE_TABLE -#define FL1_SET -#elif LAST_ENC_ROUND == FOUR_TABLES -#define FL4_SET -#elif !defined(SBX_SET) -#define SBX_SET -#endif -#endif - -#if defined(DECRYPTION) || defined(AES_ASM) -#if DEC_ROUND == ONE_TABLE -#define IT1_SET -#elif DEC_ROUND == FOUR_TABLES -#define IT4_SET -#else -#define ISB_SET -#endif -#if LAST_DEC_ROUND == ONE_TABLE -#define IL1_SET -#elif LAST_DEC_ROUND == FOUR_TABLES -#define IL4_SET -#elif !defined(ISB_SET) -#define ISB_SET -#endif -#endif - -#if defined(ENCRYPTION_KEY_SCHEDULE) || defined(DECRYPTION_KEY_SCHEDULE) -#if KEY_SCHED == ONE_TABLE -#define LS1_SET -#define IM1_SET -#elif KEY_SCHED == FOUR_TABLES -#define LS4_SET -#define IM4_SET -#elif !defined(SBX_SET) -#define SBX_SET -#endif -#endif - -#ifdef FIXED_TABLES -#define prefx extern const -#else -#define prefx extern -extern aes_08t tab_init; -void gen_tabs(void); -#endif - -prefx aes_32t rcon_tab[29]; - -#ifdef SBX_SET -prefx aes_08t s_box[256]; -#endif - -#ifdef ISB_SET -prefx aes_08t inv_s_box[256]; -#endif - -#ifdef FT1_SET -prefx aes_32t ft_tab[256]; -#endif - -#ifdef FT4_SET -prefx aes_32t ft_tab[4][256]; -#endif - -#ifdef FL1_SET -prefx aes_32t fl_tab[256]; -#endif - -#ifdef FL4_SET -prefx aes_32t fl_tab[4][256]; -#endif - -#ifdef IT1_SET -prefx aes_32t it_tab[256]; -#endif - -#ifdef IT4_SET -prefx aes_32t it_tab[4][256]; -#endif - -#ifdef IL1_SET -prefx aes_32t il_tab[256]; -#endif - -#ifdef IL4_SET -prefx aes_32t il_tab[4][256]; -#endif - -#ifdef LS1_SET -#ifdef FL1_SET -#undef LS1_SET -#else -prefx aes_32t ls_tab[256]; -#endif -#endif - -#ifdef LS4_SET -#ifdef FL4_SET -#undef LS4_SET -#else -prefx aes_32t ls_tab[4][256]; -#endif -#endif - -#ifdef IM1_SET -prefx aes_32t im_tab[256]; -#endif - -#ifdef IM4_SET -prefx aes_32t im_tab[4][256]; -#endif - -/* Set the number of columns in nc. Note that it is important - that nc is a constant which is known at compile time if the - highest speed version of the code is needed. -*/ - -#if defined(BLOCK_SIZE) -#define nc (BLOCK_SIZE >> 2) -#else -#define nc (cx->n_blk >> 2) -#endif - -/* generic definitions of Rijndael macros that use tables */ - -#define no_table(x,box,vf,rf,c) bytes2word( \ - box[bval(vf(x,0,c),rf(0,c))], \ - box[bval(vf(x,1,c),rf(1,c))], \ - box[bval(vf(x,2,c),rf(2,c))], \ - box[bval(vf(x,3,c),rf(3,c))]) - -#define one_table(x,op,tab,vf,rf,c) \ - ( tab[bval(vf(x,0,c),rf(0,c))] \ - ^ op(tab[bval(vf(x,1,c),rf(1,c))],1) \ - ^ op(tab[bval(vf(x,2,c),rf(2,c))],2) \ - ^ op(tab[bval(vf(x,3,c),rf(3,c))],3)) - -#define four_tables(x,tab,vf,rf,c) \ - ( tab[0][bval(vf(x,0,c),rf(0,c))] \ - ^ tab[1][bval(vf(x,1,c),rf(1,c))] \ - ^ tab[2][bval(vf(x,2,c),rf(2,c))] \ - ^ tab[3][bval(vf(x,3,c),rf(3,c))]) - -#define vf1(x,r,c) (x) -#define rf1(r,c) (r) -#define rf2(r,c) ((r-c)&3) - -/* perform forward and inverse column mix operation on four bytes in long word x in */ -/* parallel. NOTE: x must be a simple variable, NOT an expression in these macros. */ - -#define dec_fmvars -#if defined(FM4_SET) /* not currently used */ -#define fwd_mcol(x) four_tables(x,fm_tab,vf1,rf1,0) -#elif defined(FM1_SET) /* not currently used */ -#define fwd_mcol(x) one_table(x,upr,fm_tab,vf1,rf1,0) -#else -#undef dec_fmvars -#define dec_fmvars aes_32t f1, f2; -#define fwd_mcol(x) (f1 = (x), f2 = FFmulX(f1), f2 ^ upr(f1 ^ f2, 3) ^ upr(f1, 2) ^ upr(f1, 1)) -#endif - -#define dec_imvars -#if defined(IM4_SET) -#define inv_mcol(x) four_tables(x,im_tab,vf1,rf1,0) -#elif defined(IM1_SET) -#define inv_mcol(x) one_table(x,upr,im_tab,vf1,rf1,0) -#else -#undef dec_imvars -#define dec_imvars aes_32t f2, f4, f8, f9; -#define inv_mcol(x) \ - (f9 = (x), f2 = FFmulX(f9), f4 = FFmulX(f2), f8 = FFmulX(f4), f9 ^= f8, \ - f2 ^= f4 ^ f8 ^ upr(f2 ^ f9,3) ^ upr(f4 ^ f9,2) ^ upr(f9,1)) -#endif - -#if defined(FL4_SET) -#define ls_box(x,c) four_tables(x,fl_tab,vf1,rf2,c) -#elif defined(LS4_SET) -#define ls_box(x,c) four_tables(x,ls_tab,vf1,rf2,c) -#elif defined(FL1_SET) -#define ls_box(x,c) one_table(x,upr,fl_tab,vf1,rf2,c) -#elif defined(LS1_SET) -#define ls_box(x,c) one_table(x,upr,ls_tab,vf1,rf2,c) -#else -#define ls_box(x,c) no_table(x,s_box,vf1,rf2,c) -#endif - -#endif diff --git a/CPP/7zip/Crypto/AES/aestab.c b/CPP/7zip/Crypto/AES/aestab.c deleted file mode 100755 index de1d7eea..00000000 --- a/CPP/7zip/Crypto/AES/aestab.c +++ /dev/null @@ -1,494 +0,0 @@ -/* - ------------------------------------------------------------------------- - Copyright (c) 2001, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and fitness for purpose. - ------------------------------------------------------------------------- - Issue Date: 29/07/2002 -*/ - -#include "aesopt.h" - -#if defined(FIXED_TABLES) || !defined(FF_TABLES) - -/* finite field arithmetic operations */ - -#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) -#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) -#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \ - ^ (((x>>5) & 4) * WPOLY)) -#define f3(x) (f2(x) ^ x) -#define f9(x) (f8(x) ^ x) -#define fb(x) (f8(x) ^ f2(x) ^ x) -#define fd(x) (f8(x) ^ f4(x) ^ x) -#define fe(x) (f8(x) ^ f4(x) ^ f2(x)) - -#endif - -#if defined(FIXED_TABLES) - -#define sb_data(w) \ - w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ - w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ - w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ - w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ - w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ - w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ - w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ - w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ - w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ - w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ - w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ - w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ - w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ - w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ - w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ - w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ - w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ - w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ - w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ - w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ - w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ - w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ - w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ - w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ - w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ - w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ - w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ - w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ - w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ - w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ - w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ - w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) - -#define isb_data(w) \ - w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\ - w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\ - w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\ - w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\ - w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\ - w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\ - w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\ - w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\ - w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\ - w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\ - w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\ - w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\ - w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\ - w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\ - w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\ - w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\ - w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\ - w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\ - w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\ - w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\ - w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\ - w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\ - w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\ - w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\ - w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\ - w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\ - w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\ - w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\ - w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\ - w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\ - w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\ - w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d), - -#define mm_data(w) \ - w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\ - w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\ - w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\ - w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\ - w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\ - w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\ - w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\ - w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\ - w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\ - w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\ - w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\ - w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\ - w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\ - w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\ - w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\ - w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\ - w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\ - w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\ - w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\ - w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\ - w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\ - w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\ - w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\ - w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\ - w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\ - w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\ - w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\ - w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\ - w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\ - w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\ - w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\ - w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) - -#define h0(x) (x) - -/* These defines are used to ensure tables are generated in the - right format depending on the internal byte order required -*/ - -#define w0(p) bytes2word(p, 0, 0, 0) -#define w1(p) bytes2word(0, p, 0, 0) -#define w2(p) bytes2word(0, 0, p, 0) -#define w3(p) bytes2word(0, 0, 0, p) - -/* Number of elements required in this table for different - block and key lengths is: - - Rcon Table key length (bytes) - Length 16 20 24 28 32 - --------------------- - block 16 | 10 9 8 7 7 - length 20 | 14 11 10 9 9 - (bytes) 24 | 19 15 12 11 11 - 28 | 24 19 16 13 13 - 32 | 29 23 19 17 14 - - this table can be a table of bytes if the key schedule - code is adjusted accordingly -*/ - -#define u0(p) bytes2word(f2(p), p, p, f3(p)) -#define u1(p) bytes2word(f3(p), f2(p), p, p) -#define u2(p) bytes2word(p, f3(p), f2(p), p) -#define u3(p) bytes2word(p, p, f3(p), f2(p)) - -#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) -#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) -#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) -#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) - -const aes_32t rcon_tab[29] = -{ - w0(0x01), w0(0x02), w0(0x04), w0(0x08), - w0(0x10), w0(0x20), w0(0x40), w0(0x80), - w0(0x1b), w0(0x36), w0(0x6c), w0(0xd8), - w0(0xab), w0(0x4d), w0(0x9a), w0(0x2f), - w0(0x5e), w0(0xbc), w0(0x63), w0(0xc6), - w0(0x97), w0(0x35), w0(0x6a), w0(0xd4), - w0(0xb3), w0(0x7d), w0(0xfa), w0(0xef), - w0(0xc5) -}; - -#ifdef SBX_SET -const aes_08t s_box[256] = { sb_data(h0) }; -#endif -#ifdef ISB_SET -const aes_08t inv_s_box[256] = { isb_data(h0) }; -#endif - -#ifdef FT1_SET -const aes_32t ft_tab[256] = { sb_data(u0) }; -#endif -#ifdef FT4_SET -const aes_32t ft_tab[4][256] = - { { sb_data(u0) }, { sb_data(u1) }, { sb_data(u2) }, { sb_data(u3) } }; -#endif - -#ifdef FL1_SET -const aes_32t fl_tab[256] = { sb_data(w0) }; -#endif -#ifdef FL4_SET -const aes_32t fl_tab[4][256] = - { { sb_data(w0) }, { sb_data(w1) }, { sb_data(w2) }, { sb_data(w3) } }; -#endif - -#ifdef IT1_SET -const aes_32t it_tab[256] = { isb_data(v0) }; -#endif -#ifdef IT4_SET -const aes_32t it_tab[4][256] = - { { isb_data(v0) }, { isb_data(v1) }, { isb_data(v2) }, { isb_data(v3) } }; -#endif - -#ifdef IL1_SET -const aes_32t il_tab[256] = { isb_data(w0) }; -#endif -#ifdef IL4_SET -const aes_32t il_tab[4][256] = - { { isb_data(w0) }, { isb_data(w1) }, { isb_data(w2) }, { isb_data(w3) } }; -#endif - -#ifdef LS1_SET -const aes_32t ls_tab[256] = { sb_data(w0) }; -#endif -#ifdef LS4_SET -const aes_32t ls_tab[4][256] = - { { sb_data(w0) }, { sb_data(w1) }, { sb_data(w2) }, { sb_data(w3) } }; -#endif - -#ifdef IM1_SET -const aes_32t im_tab[256] = { mm_data(v0) }; -#endif -#ifdef IM4_SET -const aes_32t im_tab[4][256] = - { { mm_data(v0) }, { mm_data(v1) }, { mm_data(v2) }, { mm_data(v3) } }; -#endif - -#else /* dynamic table generation */ - -aes_08t tab_init = 0; - -#define const - -aes_32t rcon_tab[29]; - -#ifdef SBX_SET -aes_08t s_box[256]; -#endif -#ifdef ISB_SET -aes_08t inv_s_box[256]; -#endif - -#ifdef FT1_SET -aes_32t ft_tab[256]; -#endif -#ifdef FT4_SET -aes_32t ft_tab[4][256]; -#endif - -#ifdef FL1_SET -aes_32t fl_tab[256]; -#endif -#ifdef FL4_SET -aes_32t fl_tab[4][256]; -#endif - -#ifdef IT1_SET -aes_32t it_tab[256]; -#endif -#ifdef IT4_SET -aes_32t it_tab[4][256]; -#endif - -#ifdef IL1_SET -aes_32t il_tab[256]; -#endif -#ifdef IL4_SET -aes_32t il_tab[4][256]; -#endif - -#ifdef LS1_SET -aes_32t ls_tab[256]; -#endif -#ifdef LS4_SET -aes_32t ls_tab[4][256]; -#endif - -#ifdef IM1_SET -aes_32t im_tab[256]; -#endif -#ifdef IM4_SET -aes_32t im_tab[4][256]; -#endif - -#if !defined(FF_TABLES) - -/* Generate the tables for the dynamic table option - - It will generally be sensible to use tables to compute finite - field multiplies and inverses but where memory is scarse this - code might sometimes be better. But it only has effect during - initialisation so its pretty unimportant in overall terms. -*/ - -/* return 2 ^ (n - 1) where n is the bit number of the highest bit - set in x with x in the range 1 < x < 0x00000200. This form is - used so that locals within fi can be bytes rather than words -*/ - -static aes_08t hibit(const aes_32t x) -{ aes_08t r = (aes_08t)((x >> 1) | (x >> 2)); - - r |= (r >> 2); - r |= (r >> 4); - return (r + 1) >> 1; -} - -/* return the inverse of the finite field element x */ - -static aes_08t fi(const aes_08t x) -{ aes_08t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; - - if(x < 2) return x; - - for(;;) - { - if(!n1) return v1; - - while(n2 >= n1) - { - n2 /= n1; p2 ^= p1 * n2; v2 ^= v1 * n2; n2 = hibit(p2); - } - - if(!n2) return v2; - - while(n1 >= n2) - { - n1 /= n2; p1 ^= p2 * n1; v1 ^= v2 * n1; n1 = hibit(p1); - } - } -} - -#else - -/* define the finite field multiplies required for Rijndael */ - -#define f2(x) ((x) ? pow[log[x] + 0x19] : 0) -#define f3(x) ((x) ? pow[log[x] + 0x01] : 0) -#define f9(x) ((x) ? pow[log[x] + 0xc7] : 0) -#define fb(x) ((x) ? pow[log[x] + 0x68] : 0) -#define fd(x) ((x) ? pow[log[x] + 0xee] : 0) -#define fe(x) ((x) ? pow[log[x] + 0xdf] : 0) -#define fi(x) ((x) ? pow[255 - log[x]]: 0) - -#endif - -/* The forward and inverse affine transformations used in the S-box */ - -#define fwd_affine(x) \ - (w = (aes_32t)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(aes_08t)(w^(w>>8))) - -#define inv_affine(x) \ - (w = (aes_32t)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(aes_08t)(w^(w>>8))) - -void gen_tabs(void) -{ aes_32t i, w; - -#if defined(FF_TABLES) - - aes_08t pow[512], log[256]; - - /* log and power tables for GF(2^8) finite field with - WPOLY as modular polynomial - the simplest primitive - root is 0x03, used here to generate the tables - */ - - i = 0; w = 1; - do - { - pow[i] = (aes_08t)w; - pow[i + 255] = (aes_08t)w; - log[w] = (aes_08t)i++; - w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0); - } - while (w != 1); - -#endif - - for(i = 0, w = 1; i < RC_LENGTH; ++i) - { - rcon_tab[i] = bytes2word(w, 0, 0, 0); - w = f2(w); - } - - for(i = 0; i < 256; ++i) - { aes_08t b; - - b = fwd_affine(fi((aes_08t)i)); - w = bytes2word(f2(b), b, b, f3(b)); - -#ifdef SBX_SET - s_box[i] = b; -#endif - -#ifdef FT1_SET /* tables for a normal encryption round */ - ft_tab[i] = w; -#endif -#ifdef FT4_SET - ft_tab[0][i] = w; - ft_tab[1][i] = upr(w,1); - ft_tab[2][i] = upr(w,2); - ft_tab[3][i] = upr(w,3); -#endif - w = bytes2word(b, 0, 0, 0); - -#ifdef FL1_SET /* tables for last encryption round (may also */ - fl_tab[i] = w; /* be used in the key schedule) */ -#endif -#ifdef FL4_SET - fl_tab[0][i] = w; - fl_tab[1][i] = upr(w,1); - fl_tab[2][i] = upr(w,2); - fl_tab[3][i] = upr(w,3); -#endif - -#ifdef LS1_SET /* table for key schedule if fl_tab above is */ - ls_tab[i] = w; /* not of the required form */ -#endif -#ifdef LS4_SET - ls_tab[0][i] = w; - ls_tab[1][i] = upr(w,1); - ls_tab[2][i] = upr(w,2); - ls_tab[3][i] = upr(w,3); -#endif - - b = fi(inv_affine((aes_08t)i)); - w = bytes2word(fe(b), f9(b), fd(b), fb(b)); - -#ifdef IM1_SET /* tables for the inverse mix column operation */ - im_tab[b] = w; -#endif -#ifdef IM4_SET - im_tab[0][b] = w; - im_tab[1][b] = upr(w,1); - im_tab[2][b] = upr(w,2); - im_tab[3][b] = upr(w,3); -#endif - -#ifdef ISB_SET - inv_s_box[i] = b; -#endif -#ifdef IT1_SET /* tables for a normal decryption round */ - it_tab[i] = w; -#endif -#ifdef IT4_SET - it_tab[0][i] = w; - it_tab[1][i] = upr(w,1); - it_tab[2][i] = upr(w,2); - it_tab[3][i] = upr(w,3); -#endif - w = bytes2word(b, 0, 0, 0); -#ifdef IL1_SET /* tables for last decryption round */ - il_tab[i] = w; -#endif -#ifdef IL4_SET - il_tab[0][i] = w; - il_tab[1][i] = upr(w,1); - il_tab[2][i] = upr(w,2); - il_tab[3][i] = upr(w,3); -#endif - } - - tab_init = 1; -} - -#endif diff --git a/CPP/7zip/Crypto/AES/makefile b/CPP/7zip/Crypto/AES/makefile deleted file mode 100755 index 28f99965..00000000 --- a/CPP/7zip/Crypto/AES/makefile +++ /dev/null @@ -1,31 +0,0 @@ -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_W3) diff --git a/CPP/7zip/Crypto/AES/resource.rc b/CPP/7zip/Crypto/AES/resource.rc deleted file mode 100755 index 1ea1bfe7..00000000 --- a/CPP/7zip/Crypto/AES/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("AES Codec", "AES") diff --git a/CPP/7zip/Crypto/RarAES/RarAES.cpp b/CPP/7zip/Crypto/RarAES/RarAES.cpp index 9adeedc5..f978e275 100755 --- a/CPP/7zip/Crypto/RarAES/RarAES.cpp +++ b/CPP/7zip/Crypto/RarAES/RarAES.cpp @@ -1,12 +1,11 @@ // RarAES.cpp -// This code is based on UnRar sources +// Note: you must include Crypto/AES/MyAES.cpp to project to initialize AES tables #include "StdAfx.h" #include "RarAES.h" #include "../../Common/MethodId.h" #include "../Hash/Sha1.h" -#include "../AES/MyAES.h" namespace NCrypto { namespace NRar29 { @@ -77,19 +76,14 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size) STDMETHODIMP CDecoder::Init() { Calculate(); - if (!_aesFilter) - _aesFilter = new CAES_CBC_Decoder; - CMyComPtr<ICryptoProperties> cp; - RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp)); - RINOK(cp->SetKey(aesKey, 16)); - RINOK(cp->SetInitVector(aesInit, 16)); - _aesFilter->Init(); + AesSetKeyDecode(&Aes.aes, aesKey, kRarAesKeySize); + AesCbcInit(&Aes, aesInit); return S_OK; } STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) { - return _aesFilter->Filter(data, size); + return AesCbcDecode(&Aes, data, size); } void CDecoder::Calculate() diff --git a/CPP/7zip/Crypto/RarAES/RarAES.h b/CPP/7zip/Crypto/RarAES/RarAES.h index d52557f6..6d960d76 100755 --- a/CPP/7zip/Crypto/RarAES/RarAES.h +++ b/CPP/7zip/Crypto/RarAES/RarAES.h @@ -10,9 +10,16 @@ #include "../../ICoder.h" #include "../../IPassword.h" +extern "C" +{ +#include "../../../../C/Crypto/Aes.h" +} + namespace NCrypto { namespace NRar29 { +const kRarAesKeySize = 16; + class CDecoder: public ICompressFilter, public ICompressSetDecoderProperties2, @@ -22,11 +29,11 @@ class CDecoder: Byte _salt[8]; bool _thereIsSalt; CByteBuffer buffer; - Byte aesKey[16]; - Byte aesInit[16]; + Byte aesKey[kRarAesKeySize]; + Byte aesInit[AES_BLOCK_SIZE]; bool _needCalculate; - CMyComPtr<ICompressFilter> _aesFilter; + CAesCbc Aes; bool _rar350Mode; diff --git a/CPP/7zip/Crypto/WzAES/WzAES.cpp b/CPP/7zip/Crypto/WzAES/WzAES.cpp index 693989cc..106f2d94 100755 --- a/CPP/7zip/Crypto/WzAES/WzAES.cpp +++ b/CPP/7zip/Crypto/WzAES/WzAES.cpp @@ -2,6 +2,8 @@ /* This code implements Brian Gladman's scheme specified in password Based File Encryption Utility. + +Note: you must include Crypto/AES/MyAES.cpp to project to initialize AES tables */ #include "StdAfx.h" @@ -14,8 +16,6 @@ specified in password Based File Encryption Utility. #include "WzAES.h" -#include "../AES/MyAES.h" - // define it if you don't want to use speed-optimized version of Pbkdf2HmacSha1 // #define _NO_WZAES_OPTIMIZATIONS @@ -35,20 +35,24 @@ STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size) return S_OK; } +#define SetUi32(p, d) { UInt32 x = (d); (p)[0] = (Byte)x; (p)[1] = (Byte)(x >> 8); \ + (p)[2] = (Byte)(x >> 16); (p)[3] = (Byte)(x >> 24); } + void CBaseCoder::EncryptData(Byte *data, UInt32 size) { unsigned int pos = _blockPos; for (; size > 0; size--) { - if (pos == kAesBlockSize) + if (pos == AES_BLOCK_SIZE) { - int j; - for (j = 0; j < 8 && ++_counter[j] == 0; j++); - for (j = 0; j < 8; j++) - _buffer[j] = _counter[j]; - for (; j < kAesBlockSize; j++) - _buffer[j] = 0; - _aesFilter->Filter(_buffer, kAesBlockSize); + if (++_counter[0] == 0) + _counter[1]++; + UInt32 outBuf[4]; + AesEncode32(_counter, outBuf, Aes.rkey, Aes.numRounds2); + SetUi32(_buffer, outBuf[0]); + SetUi32(_buffer + 4, outBuf[1]); + SetUi32(_buffer + 8, outBuf[2]); + SetUi32(_buffer + 12, outBuf[3]); pos = 0; } *data++ ^= _buffer[pos++]; @@ -107,14 +111,12 @@ STDMETHODIMP CBaseCoder::Init() _hmac.SetKey(buf + keySize, keySize); memcpy(_key.PwdVerifComputed, buf + 2 * keySize, kPwdVerifCodeSize); - _blockPos = kAesBlockSize; - for (int i = 0; i < 8; i++) + _blockPos = AES_BLOCK_SIZE; + for (int i = 0; i < 4; i++) _counter[i] = 0; - RINOK(CreateFilters()); - CMyComPtr<ICryptoProperties> cp; - RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp)); - return cp->SetKey(buf, keySize); + AesSetKeyEncode(&Aes, buf, keySize); + return S_OK; } static HRESULT SafeWrite(ISequentialOutStream *outStream, const Byte *data, UInt32 size) @@ -218,12 +220,4 @@ STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) return size; } - -HRESULT CBaseCoder::CreateFilters() -{ - if (!_aesFilter) - _aesFilter = new CAES_ECB_Encoder; - return S_OK; -} - }} diff --git a/CPP/7zip/Crypto/WzAES/WzAES.h b/CPP/7zip/Crypto/WzAES/WzAES.h index 10df3045..72a493a1 100755 --- a/CPP/7zip/Crypto/WzAES/WzAES.h +++ b/CPP/7zip/Crypto/WzAES/WzAES.h @@ -21,10 +21,14 @@ specified in password Based File Encryption Utility: #include "../../ICoder.h" #include "../../IPassword.h" +extern "C" +{ +#include "../../../../C/Crypto/Aes.h" +} + namespace NCrypto { namespace NWzAES { -const unsigned int kAesBlockSize = 16; const unsigned int kSaltSizeMax = 16; const unsigned int kMacSize = 10; @@ -56,17 +60,16 @@ class CBaseCoder: { protected: CKeyInfo _key; - Byte _counter[8]; - Byte _buffer[kAesBlockSize]; + UInt32 _counter[AES_BLOCK_SIZE / 4]; + Byte _buffer[AES_BLOCK_SIZE]; NSha1::CHmac _hmac; unsigned int _blockPos; Byte _pwdVerifFromArchive[kPwdVerifCodeSize]; void EncryptData(Byte *data, UInt32 size); - CMyComPtr<ICompressFilter> _aesFilter; + CAes Aes; - HRESULT CreateFilters(); public: STDMETHOD(Init)(); STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) = 0; diff --git a/CPP/7zip/FileManager/PanelListNotify.cpp b/CPP/7zip/FileManager/PanelListNotify.cpp index 44bb3e8b..9e319cce 100755 --- a/CPP/7zip/FileManager/PanelListNotify.cpp +++ b/CPP/7zip/FileManager/PanelListNotify.cpp @@ -136,6 +136,10 @@ LRESULT CPanel::SetItemText(LVITEMW &item) else s = ConvertPropertyToString(propVariant, propID, false); + { + s.Replace(wchar_t(0xA), L' '); + s.Replace(wchar_t(0xD), L' '); + } int size = item.cchTextMax; if(size > 0) { diff --git a/CPP/7zip/MyVersion.h b/CPP/7zip/MyVersion.h index fbfa0d7d..c6f952ac 100755 --- a/CPP/7zip/MyVersion.h +++ b/CPP/7zip/MyVersion.h @@ -1,8 +1,8 @@ #define MY_VER_MAJOR 4 -#define MY_VER_MINOR 49 +#define MY_VER_MINOR 50 #define MY_VER_BUILD 0 -#define MY_VERSION "4.49 beta" -#define MY_7ZIP_VERSION "7-Zip 4.49 beta" -#define MY_DATE "2007-07-11" +#define MY_VERSION "4.50 beta" +#define MY_7ZIP_VERSION "7-Zip 4.50 beta" +#define MY_DATE "2007-07-24" #define MY_COPYRIGHT "Copyright (c) 1999-2007 Igor Pavlov" #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE diff --git a/CPP/7zip/UI/Client7z/Client7z.cpp b/CPP/7zip/UI/Client7z/Client7z.cpp index 43aec4f8..a04b6eb0 100755 --- a/CPP/7zip/UI/Client7z/Client7z.cpp +++ b/CPP/7zip/UI/Client7z/Client7z.cpp @@ -6,9 +6,6 @@ #include "Common/StringConvert.h" #include "Common/IntToString.h" -#include "../../Common/FileStreams.h" -#include "../../Archive/IArchive.h" -#include "../../IPassword.h" #include "Windows/PropVariant.h" #include "Windows/PropVariantConversions.h" @@ -17,13 +14,24 @@ #include "Windows/FileName.h" #include "Windows/FileFind.h" +#include "../../Common/FileStreams.h" +#include "../../Archive/IArchive.h" +#include "../../IPassword.h" +#include "../../MyVersion.h" + + // {23170F69-40C1-278A-1000-000110070000} DEFINE_GUID(CLSID_CFormat7z, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00); using namespace NWindows; -static const char *kCopyrightString = "7-Zip (7za.DLL client example) (c) 1999-2007 Igor Pavlov 2007-03-30\n"; +#define kDllName "7z.dll" + +static const char *kCopyrightString = MY_7ZIP_VERSION +" (" kDllName " client) " +MY_COPYRIGHT " " MY_DATE; + static const char *kHelpString = "Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\n" "Examples:\n" @@ -115,12 +123,12 @@ public: CArchiveOpenCallback() : PasswordIsDefined(false) {} }; -STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 *files, const UInt64 *bytes) +STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */) { return S_OK; } -STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 *files, const UInt64 *bytes) +STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */) { return S_OK; } @@ -211,12 +219,12 @@ void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &di NFile::NName::NormalizeDirPathPrefix(_directoryPath); } -STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size) +STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */) { return S_OK; } -STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue) +STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */) { return S_OK; } @@ -244,6 +252,9 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, _filePath = fullPath; } + if (askExtractMode != NArchive::NExtract::NAskMode::kExtract) + return S_OK; + { // Get Attributes NCOM::CPropVariant propVariant; @@ -481,23 +492,23 @@ public: } }; -STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size) +STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */) { return S_OK; } -STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue) +STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */) { return S_OK; } -STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **enumerator) +STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */) { return E_NOTIMPL; } -STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, +STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */, Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive) { if(newData != NULL) @@ -602,7 +613,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream return S_OK; } -STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult) +STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */) { m_NeedBeClosed = true; return S_OK; @@ -679,7 +690,7 @@ main(int argc, char* argv[]) return 1; } NWindows::NDLL::CLibrary library; - if (!library.Load(TEXT("7za.dll"))) + if (!library.Load(TEXT(kDllName))) { PrintStringLn("Can not load library"); return 1; @@ -843,7 +854,7 @@ main(int argc, char* argv[]) extractCallbackSpec->PasswordIsDefined = false; // extractCallbackSpec->PasswordIsDefined = true; // extractCallbackSpec->Password = L"1"; - archive->Extract(0, (UInt32)(Int32)(-1), false, extractCallback); + archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback); } } return 0; diff --git a/CPP/7zip/UI/Client7z/makefile b/CPP/7zip/UI/Client7z/makefile index 6c806267..226c36a2 100755 --- a/CPP/7zip/UI/Client7z/makefile +++ b/CPP/7zip/UI/Client7z/makefile @@ -36,7 +36,7 @@ OBJS = \ !include "../../../Build.mak" $(CONSOLE_OBJS): $(*B).cpp - $(COMPL_O1_W3) + $(COMPL) $(COMMON_OBJS): ../../../Common/$(*B).cpp $(COMPL) $(WIN_OBJS): ../../../Windows/$(*B).cpp diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index d16d6166..ac0e55e5 100755 --- a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -24,6 +24,8 @@ #include "SortUtils.h" #include "EnumDirItems.h" +extern bool g_CaseSensitive; + #if _MSC_VER >= 1400 #define MY_isatty_fileno(x) _isatty(_fileno(x)) #else @@ -67,7 +69,8 @@ enum Enum kLargePages, kCharSet, kTechMode, - kShareForWrite + kShareForWrite, + kCaseSensitive }; } @@ -131,7 +134,8 @@ static const CSwitchForm kSwitchForms[] = { L"SLP", NSwitchType::kUnLimitedPostString, false, 0}, { L"SCS", NSwitchType::kUnLimitedPostString, false, 0}, { L"SLT", NSwitchType::kSimple, false }, - { L"SSW", NSwitchType::kSimple, false } + { L"SSW", NSwitchType::kSimple, false }, + { L"SSC", NSwitchType::kPostChar, false, 0, 0, L"-" } }; static const CCommandForm g_CommandForms[] = @@ -746,6 +750,9 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) options.TechMode = parser[NKey::kTechMode].ThereIs; + if (parser[NKey::kCaseSensitive].ThereIs) + g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0); + NRecursedType::EEnum recursedType; if (parser[NKey::kRecursed].ThereIs) recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex); @@ -865,7 +872,7 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) archivePathsFull.Add(fullPath); } CIntVector indices; - SortStringsToIndices(archivePathsFull, indices); + SortFileNames(archivePathsFull, indices); options.ArchivePathsSorted.Reserve(indices.Size()); options.ArchivePathsFullSorted.Reserve(indices.Size()); for (i = 0; i < indices.Size(); i++) diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.h b/CPP/7zip/UI/Common/ArchiveCommandLine.h index 7183de9b..5f54b064 100755 --- a/CPP/7zip/UI/Common/ArchiveCommandLine.h +++ b/CPP/7zip/UI/Common/ArchiveCommandLine.h @@ -31,7 +31,7 @@ namespace NRecursedType { enum EEnum { kRecursed, kWildCardOnlyRecursed, - kNonRecursed, + kNonRecursed };} struct CArchiveCommand diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp index 05520fed..bd0dfef6 100755 --- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp +++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp @@ -118,21 +118,9 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre _isSplit = false; UString fullPath; - { - NCOM::CPropVariant prop; - RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop)); - - if(prop.vt == VT_EMPTY) - fullPath = _itemDefaultName; - else - { - if(prop.vt != VT_BSTR) - return E_FAIL; - fullPath = prop.bstrVal; - } - } - // UString fullPathCorrect = GetCorrectPath(fullPath); + RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath)); + _filePath = fullPath; { @@ -147,14 +135,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre } } - { - NCOM::CPropVariant prop; - RINOK(_archiveHandler->GetProperty(index, kpidEncrypted, &prop)); - if (prop.vt == VT_BOOL) - _encrypted = VARIANT_BOOLToBool(prop.boolVal); - else if (prop.vt != VT_EMPTY) - return E_FAIL; - } + RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted)); if(askExtractMode == NArchive::NExtract::NAskMode::kExtract) { @@ -176,7 +157,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre else { if (prop.vt != VT_UI4) - throw "incorrect item"; + return E_FAIL; _processedFileInfo.Attributes = prop.ulVal; _processedFileInfo.AttributesAreDefined = true; } @@ -202,54 +183,45 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre } bool isAnti = false; - { - NCOM::CPropVariant prop; - RINOK(_archiveHandler->GetProperty(index, kpidIsAnti, &prop)); - if (prop.vt == VT_BOOL) - isAnti = VARIANT_BOOLToBool(prop.boolVal); - } + RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti)); UStringVector pathParts; SplitPathToParts(fullPath, pathParts); if(pathParts.IsEmpty()) return E_FAIL; - UString processedPath; + int numRemovePathParts = 0; switch(_pathMode) { case NExtract::NPathMode::kFullPathnames: - { - processedPath = fullPath; break; - } case NExtract::NPathMode::kCurrentPathnames: { - // for incorrect paths: "/dir1/dir2/file" - int numRemovePathParts = _removePathParts.Size(); - if(pathParts.Size() <= numRemovePathParts) + numRemovePathParts = _removePathParts.Size(); + if (pathParts.Size() <= numRemovePathParts) return E_FAIL; - for(int i = 0; i < numRemovePathParts; i++) - if(_removePathParts[i].CompareNoCase(pathParts[i]) != 0) + for (int i = 0; i < numRemovePathParts; i++) + if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0) return E_FAIL; - pathParts.Delete(0, numRemovePathParts); - processedPath = MakePathNameFromParts(pathParts); break; } case NExtract::NPathMode::kNoPathnames: { - processedPath = pathParts.Back(); - pathParts.Delete(0, pathParts.Size() - 1); // Test it!! + numRemovePathParts = pathParts.Size() - 1; break; } } - processedPath = GetCorrectPath(processedPath); - if(!_processedFileInfo.IsDirectory) - pathParts.DeleteBack(); - + pathParts.Delete(0, numRemovePathParts); MakeCorrectPath(pathParts); - + UString processedPath = MakePathNameFromParts(pathParts); if (!isAnti) { + if (!_processedFileInfo.IsDirectory) + { + if (!pathParts.IsEmpty()) + pathParts.DeleteBack(); + } + if (!pathParts.IsEmpty()) { UString fullPathNew; @@ -309,7 +281,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre _overwriteMode = NExtract::NOverwriteMode::kAutoRename; break; default: - throw 20413; + return E_FAIL; } } } @@ -341,10 +313,10 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre else if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath)) { - UString message = UString(kCantDeleteOutputFile) + - fullProcessedPath; + UString message = UString(kCantDeleteOutputFile) + fullProcessedPath; RINOK(_extractCallback2->MessageError(message)); - return E_FAIL; + return S_OK; + // return E_FAIL; } } } diff --git a/CPP/7zip/UI/Common/ExtractingFilePath.cpp b/CPP/7zip/UI/Common/ExtractingFilePath.cpp index cfd4ae79..86234ac3 100755 --- a/CPP/7zip/UI/Common/ExtractingFilePath.cpp +++ b/CPP/7zip/UI/Common/ExtractingFilePath.cpp @@ -5,74 +5,76 @@ static UString ReplaceIncorrectChars(const UString &s) { + #ifdef _WIN32 UString res; for (int i = 0; i < s.Length(); i++) { wchar_t c = s[i]; - #ifdef _WIN32 if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>' || c == '|' || c == ':' || c == '"') c = '_'; - #endif res += c; } return res; + #else + return s; + #endif } -static void ReplaceDisk(UString &s) +#ifdef _WIN32 +static const wchar_t *g_ReservedNames[] = { - int i; - for (i = 0; i < s.Length(); i++) - if (s[i] != ' ') - break; - if (s.Length() > i + 1) - { - if (s[i + 1] == L':') - { - s.Delete(i + 1); - // s.Insert(i + 1, L'_'); - } - } + L"CON", L"PRN", L"AUX", L"NUL" +}; + +static bool CheckTail(const UString &name, int len) +{ + int dotPos = name.Find(L'.'); + if (dotPos < 0) + dotPos = name.Length(); + UString s = name.Left(dotPos); + s.TrimRight(); + return (s.Length() != len); } -UString GetCorrectFileName(const UString &path) +static bool CheckNameNum(const UString &name, const wchar_t *reservedName) { - UString result = path; - { - UString test = path; - test.Trim(); - if (test == L"..") - result.Replace(L"..", L""); - } - ReplaceDisk(result); - return result; + int len = MyStringLen(reservedName); + if (name.Length() <= len) + return true; + if (name.Left(len).CompareNoCase(reservedName) != 0) + return true; + wchar_t c = name[len]; + if (c < L'0' || c > L'9') + return true; + return CheckTail(name, len + 1); } -UString GetCorrectPath(const UString &path) +static bool IsSupportedName(const UString &name) { - UString result = path; - int first; - for (first = 0; first < result.Length(); first++) - if (result[first] != ' ') - break; - while(result.Length() > first) + for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++) { - if ( - #ifdef _WIN32 - result[first] == L'\\' || - #endif - result[first] == L'/') - { - result.Delete(first); + const wchar_t *reservedName = g_ReservedNames[i]; + int len = MyStringLen(reservedName); + if (name.Length() < len) continue; - } - break; + if (name.Left(len).CompareNoCase(reservedName) != 0) + continue; + if (!CheckTail(name, len)) + return false; } - #ifdef _WIN32 - result.Replace(L"..\\", L""); - #endif - result.Replace(L"../", L""); + if (!CheckNameNum(name, L"COM")) + return false; + return CheckNameNum(name, L"LPT"); +} +#endif - ReplaceDisk(result); +static UString GetCorrectFileName(const UString &path) +{ + UString result = path; + UString test = path; + // test.Trim(); + if (test == L"..") + result.Replace(L"..", L""); return ReplaceIncorrectChars(result); } @@ -85,6 +87,13 @@ void MakeCorrectPath(UStringVector &pathParts) if (s.IsEmpty()) pathParts.Delete(i); else + { + #ifdef _WIN32 + if (!IsSupportedName(s)) + s = (UString)L"_" + s; + #endif i++; + } } } + diff --git a/CPP/7zip/UI/Common/ExtractingFilePath.h b/CPP/7zip/UI/Common/ExtractingFilePath.h index efc8a0e4..a86a6a9b 100755 --- a/CPP/7zip/UI/Common/ExtractingFilePath.h +++ b/CPP/7zip/UI/Common/ExtractingFilePath.h @@ -5,8 +5,6 @@ #include "Common/MyString.h" -UString GetCorrectFileName(const UString &path); -UString GetCorrectPath(const UString &path); void MakeCorrectPath(UStringVector &pathParts); #endif diff --git a/CPP/7zip/UI/Common/OpenArchive.cpp b/CPP/7zip/UI/Common/OpenArchive.cpp index 795b86e7..ed02130e 100755 --- a/CPP/7zip/UI/Common/OpenArchive.cpp +++ b/CPP/7zip/UI/Common/OpenArchive.cpp @@ -55,7 +55,7 @@ HRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, return S_OK; } -static HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result) +HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result) { NCOM::CPropVariant prop; RINOK(archive->GetProperty(index, propID, &prop)); diff --git a/CPP/7zip/UI/Common/OpenArchive.h b/CPP/7zip/UI/Common/OpenArchive.h index a857b9de..412b2e3b 100755 --- a/CPP/7zip/UI/Common/OpenArchive.h +++ b/CPP/7zip/UI/Common/OpenArchive.h @@ -14,6 +14,7 @@ HRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result); HRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result); HRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, const FILETIME &defaultFileTime, FILETIME &fileTime); +HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result); HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result); HRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result); diff --git a/CPP/7zip/UI/Common/SortUtils.cpp b/CPP/7zip/UI/Common/SortUtils.cpp index 616472ff..061e7773 100755 --- a/CPP/7zip/UI/Common/SortUtils.cpp +++ b/CPP/7zip/UI/Common/SortUtils.cpp @@ -3,60 +3,15 @@ #include "StdAfx.h" #include "SortUtils.h" -#include "Common/Types.h" - -/* -template <class T> -void TSortRefDown(T *p, UInt32 k, UInt32 size, int (*compare)(const T*, const T*, void *), void *param) -{ - T temp = p[k]; - for (;;) - { - UInt32 s = (k << 1); - if (s > size) - break; - if (s < size && compare(p + s + 1, p + s, param) > 0) - s++; - if (compare(&temp, p + s, param) >= 0) - break; - p[k] = p[s]; - k = s; - } - p[k] = temp; -} - -template <class T> -void TSort(T* p, UInt32 size, int (*compare)(const T*, const T*, void *), void *param) -{ - if (size <= 1) - return; - p--; - { - UInt32 i = size / 2; - do - TSortRefDown(p, i, size, compare, param); - while(--i != 0); - } - do - { - T temp = p[size]; - p[size--] = p[1]; - p[1] = temp; - TSortRefDown(p, 1, size, compare, param); - } - while (size > 1); -} -*/ +#include "Common/Wildcard.h" static int CompareStrings(const int *p1, const int *p2, void *param) { const UStringVector &strings = *(const UStringVector *)param; - const UString &s1 = strings[*p1]; - const UString &s2 = strings[*p2]; - return s1.CompareNoCase(s2); + return CompareFileNames(strings[*p1], strings[*p2]); } -void SortStringsToIndices(const UStringVector &strings, CIntVector &indices) +void SortFileNames(const UStringVector &strings, CIntVector &indices) { indices.Clear(); int numItems = strings.Size(); @@ -64,17 +19,4 @@ void SortStringsToIndices(const UStringVector &strings, CIntVector &indices) for(int i = 0; i < numItems; i++) indices.Add(i); indices.Sort(CompareStrings, (void *)&strings); - // TSort(&indices.Front(), indices.Size(), CompareStrings, (void *)&strings); -} - -/* -void SortStrings(const UStringVector &src, UStringVector &dest) -{ - CIntVector indices; - SortStringsToIndices(src, indices); - dest.Clear(); - dest.Reserve(indices.Size()); - for (int i = 0; i < indices.Size(); i++) - dest.Add(src[indices[i]]); } -*/ diff --git a/CPP/7zip/UI/Common/SortUtils.h b/CPP/7zip/UI/Common/SortUtils.h index 2fb8ddef..e1522461 100755 --- a/CPP/7zip/UI/Common/SortUtils.h +++ b/CPP/7zip/UI/Common/SortUtils.h @@ -5,7 +5,6 @@ #include "Common/MyString.h" -void SortStringsToIndices(const UStringVector &strings, CIntVector &indices); -// void SortStrings(const UStringVector &src, UStringVector &dest); +void SortFileNames(const UStringVector &strings, CIntVector &indices); #endif diff --git a/CPP/7zip/UI/Common/TempFiles.cpp b/CPP/7zip/UI/Common/TempFiles.cpp index 3e604aea..eeaec180 100755 --- a/CPP/7zip/UI/Common/TempFiles.cpp +++ b/CPP/7zip/UI/Common/TempFiles.cpp @@ -14,7 +14,7 @@ void CTempFiles::Clear() { while(!Paths.IsEmpty()) { - NDirectory::DeleteFileAlways(Paths.Back()); + NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back()); Paths.DeleteBack(); } } diff --git a/CPP/7zip/UI/Common/UpdatePair.cpp b/CPP/7zip/UI/Common/UpdatePair.cpp index dd51646f..b4fb2a15 100755 --- a/CPP/7zip/UI/Common/UpdatePair.cpp +++ b/CPP/7zip/UI/Common/UpdatePair.cpp @@ -5,6 +5,7 @@ #include <time.h> #include "Common/Defs.h" +#include "Common/Wildcard.h" #include "Windows/Time.h" #include "UpdatePair.h" @@ -60,20 +61,10 @@ static const char *kSameTimeChangedSizeCollisionMessaged = "Collision between files with same date/time and different sizes:\n"; */ -static inline int MyFileNameCompare(const UString &s1, const UString &s2) -{ - return - #ifdef _WIN32 - s1.CompareNoCase(s2); - #else - s1.Compare(s2); - #endif -} - static void TestDuplicateString(const UStringVector &strings, const CIntVector &indices) { for(int i = 0; i + 1 < indices.Size(); i++) - if (MyFileNameCompare(strings[indices[i]], strings[indices[i + 1]]) == 0) + if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0) { UString message = kDuplicateFileNameMessage; message += L"\n"; @@ -97,13 +88,13 @@ void GetUpdatePairInfoList( int i; for(i = 0; i < numDirItems; i++) dirNames.Add(dirItems[i].Name); - SortStringsToIndices(dirNames, dirIndices); + SortFileNames(dirNames, dirIndices); TestDuplicateString(dirNames, dirIndices); int numArchiveItems = archiveItems.Size(); for(i = 0; i < numArchiveItems; i++) archiveNames.Add(archiveItems[i].Name); - SortStringsToIndices(archiveNames, archiveIndices); + SortFileNames(archiveNames, archiveIndices); TestDuplicateString(archiveNames, archiveIndices); int dirItemIndex = 0, archiveItemIndex = 0; @@ -114,7 +105,7 @@ void GetUpdatePairInfoList( archiveItemIndex2 = archiveIndices[archiveItemIndex]; const CDirItem &dirItem = dirItems[dirItemIndex2]; const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2]; - int compareResult = MyFileNameCompare(dirItem.Name, archiveItem.Name); + int compareResult = CompareFileNames(dirItem.Name, archiveItem.Name); if (compareResult < 0) { pair.State = NUpdateArchive::NPairState::kOnlyOnDisk; diff --git a/CPP/7zip/UI/Console/List.cpp b/CPP/7zip/UI/Console/List.cpp index 48b8506a..0958a3e5 100755 --- a/CPP/7zip/UI/Console/List.cpp +++ b/CPP/7zip/UI/Console/List.cpp @@ -335,6 +335,9 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive, else { UString s = ConvertPropertyToString(propVariant, fieldInfo.PropID); + s.Replace(wchar_t(0xA), L' '); + s.Replace(wchar_t(0xD), L' '); + if (techMode) g_StdOut << s; else @@ -457,8 +460,19 @@ HRESULT ListArchives( const UString defaultItemName = archiveLink.GetDefaultItemName(); if (enableHeaders) + { g_StdOut << endl << kListing << archiveName << endl << endl; + NCOM::CPropVariant propVariant; + RINOK(archive->GetArchiveProperty(kpidComment, &propVariant)); + if (propVariant.vt != VT_EMPTY) + { + UString s = ConvertPropertyToString(propVariant, kpidComment); + if (!s.IsEmpty()) + g_StdOut << "Comment:\n" << s << "\n\n"; + } + } + if (enableHeaders && !techMode) { fieldPrinter.PrintTitle(); diff --git a/CPP/7zip/UI/Console/Main.cpp b/CPP/7zip/UI/Console/Main.cpp index 97c117ce..17eb29ec 100755 --- a/CPP/7zip/UI/Console/Main.cpp +++ b/CPP/7zip/UI/Console/Main.cpp @@ -106,6 +106,7 @@ static const char *kHelpString = " -si[{name}]: read data from stdin\n" " -slt: show technical information for l (List) command\n" " -so: write data to stdout\n" + " -ssc[-]: set sensitive case mode\n" " -ssw: compress shared files\n" " -t{Type}: Set type of archive\n" " -v{Size}[b|k|m|g]: Create volumes\n" diff --git a/CPP/Build.mak b/CPP/Build.mak index aea13a71..d2595560 100755 --- a/CPP/Build.mak +++ b/CPP/Build.mak @@ -39,9 +39,6 @@ CFLAGS_O1 = $(CFLAGS) -O1 -W3 CFLAGS_O2 = $(CFLAGS) -O2 -W3 !ENDIF -CFLAGS_O1_W3 = $(CFLAGS) -O1 -W3 -CFLAGS_O2_W3 = $(CFLAGS) -O2 -W3 - LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF !IFDEF DEF_FILE @@ -52,8 +49,6 @@ PROGPATH = $O\$(PROG) COMPL_O1 = $(CPP) $(CFLAGS_O1) $** COMPL_O2 = $(CPP) $(CFLAGS_O2) $** -COMPL_O1_W3 = $(CPP) $(CFLAGS_O1_W3) $** -COMPL_O2_W3 = $(CPP) $(CFLAGS_O2_W3) $** COMPL_PCH = $(CPP) $(CFLAGS_O1) -Yc"StdAfx.h" -Fp$O/a.pch $** COMPL = $(CPP) $(CFLAGS_O1) -Yu"StdAfx.h" -Fp$O/a.pch $** diff --git a/CPP/Common/Wildcard.cpp b/CPP/Common/Wildcard.cpp index 2e938375..93dfd833 100755 --- a/CPP/Common/Wildcard.cpp +++ b/CPP/Common/Wildcard.cpp @@ -4,6 +4,13 @@ #include "Wildcard.h" +bool g_CaseSensitive = + #ifdef _WIN32 + false; + #else + true; + #endif + static const wchar_t kAnyCharsChar = L'*'; static const wchar_t kAnyCharChar = L'?'; @@ -29,6 +36,13 @@ static inline bool IsCharDirLimiter(wchar_t c) c == kDirDelimiter2); } +int CompareFileNames(const UString &s1, const UString &s2) +{ + if (g_CaseSensitive) + return s1.Compare(s2); + return s1.CompareNoCase(s2); +} + // ----------------------------------------- // this function tests is name matches mask // ? - any wchar_t or empty @@ -67,10 +81,12 @@ static bool EnhancedMaskTest(const UString &mask, int maskPos, { wchar_t c = name[namePos]; if (maskChar != c) -#ifdef _WIN32 - if (MyCharUpper(maskChar) != MyCharUpper(c)) -#endif + { + if (g_CaseSensitive) return false; + else if (MyCharUpper(maskChar) != MyCharUpper(c)) + return false; + } return EnhancedMaskTest(mask, maskPos + 1, name, namePos + 1); } } @@ -200,7 +216,7 @@ bool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const int CCensorNode::FindSubNode(const UString &name) const { for (int i = 0; i < SubNodes.Size(); i++) - if (SubNodes[i].Name.CompareNoCase(name) == 0) + if (CompareFileNames(SubNodes[i].Name, name) == 0) return i; return -1; } @@ -360,7 +376,7 @@ void CCensorNode::ExtendExclude(const CCensorNode &fromNodes) int CCensor::FindPrefix(const UString &prefix) const { for (int i = 0; i < Pairs.Size(); i++) - if (Pairs[i].Prefix.CompareNoCase(prefix) == 0) + if (CompareFileNames(Pairs[i].Prefix, prefix) == 0) return i; return -1; } diff --git a/CPP/Common/Wildcard.h b/CPP/Common/Wildcard.h index 55c9744e..6d4cbcec 100755 --- a/CPP/Common/Wildcard.h +++ b/CPP/Common/Wildcard.h @@ -5,6 +5,8 @@ #include "MyString.h" +int CompareFileNames(const UString &s1, const UString &s2); + void SplitPathToParts(const UString &path, UStringVector &pathParts); void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name); UString ExtractDirPrefixFromPath(const UString &path); diff --git a/CPP/Windows/FileIO.cpp b/CPP/Windows/FileIO.cpp index adfbec3d..effd4862 100755 --- a/CPP/Windows/FileIO.cpp +++ b/CPP/Windows/FileIO.cpp @@ -31,8 +31,11 @@ bool GetLongPathBase(LPCWSTR s, UString &res) if (len < 1 || c == L'\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.')) return true; UString curDir; + bool isAbs = false; if (len > 3) - if (s[1] != L':' || s[2] != L'\\' || !(c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z')) + isAbs = (s[1] == L':' && s[2] == L'\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z')); + + if (!isAbs) { DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1)); curDir.ReleaseBuffer(); diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h index 7edc6827..a46a5688 100755 --- a/CPP/Windows/Thread.h +++ b/CPP/Windows/Thread.h @@ -3,8 +3,6 @@ #ifndef __WINDOWS_THREAD_H #define __WINDOWS_THREAD_H -#include <process.h> - #include "Defs.h" extern "C" |