Skip to content

Commit 030e27c

Browse files
committed
Add encryption algorithm and key derivation algorithm to the 7z format.
1 parent 117640f commit 030e27c

63 files changed

Lines changed: 5200 additions & 216 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Asm/arm64/7zAsm.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#if defined(__clang_major__) && __clang_major__ >= 20
55
// clang21 : error: identifier 'and' conflicts with a C++ keyword [-Wc++-keyword]
6-
// #pragma GCC diagnostic ignored "-Wc++-keyword" // clang 21
6+
#pragma GCC diagnostic ignored "-Wc++-keyword" // clang 21+
77
#pragma GCC diagnostic ignored "-Wc++-compat" // clang 12+
88
#endif
99

C/7zVersion.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#define MY_VERSION_CPU MY_VERSION
1111
#endif
1212

13-
#define MY_DATE "2026-04-27"
13+
#define MY_DATE "2026-06-12"
1414
#undef MY_COPYRIGHT
1515
#undef MY_VERSION_COPYRIGHT_DATE
16-
#define MY_AUTHOR_NAME "Igor Pavlov, Tino Reichardt, Sergey G. Brester"
16+
#define MY_AUTHOR_NAME "Igor Pavlov, Tino Reichardt, Sergey G. Brester, fzxx"
1717
#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"
18-
#define MY_COPYRIGHT_CR "Copyright (c) 1999- Igor Pavlov, 2016- Tino Reichardt, 2022- Sergey G. Brester"
18+
#define MY_COPYRIGHT_CR "Copyright (c) 1999- Igor Pavlov, 2016- Tino Reichardt, 2022- Sergey G. Brester, 2026- fzxx"
1919

2020
#ifdef USE_COPYRIGHT_CR
2121
#define MY_COPYRIGHT MY_COPYRIGHT_CR

C/7zVersion.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BEGIN \
3434
BEGIN \
3535
BLOCK "040904b0" \
3636
BEGIN \
37-
VALUE "CompanyName", "Igor Pavlov, Tino Reichardt" \
37+
VALUE "CompanyName", "Igor Pavlov, Tino Reichardt, Sergey G. Brester, fzxx" \
3838
VALUE "FileDescription", descr \
3939
VALUE "FileVersion", MY_VERSION \
4040
VALUE "InternalName", intName \

C/7zWindows.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Igor Pavlov : Public domain */
3333
#define RPC_NO_WINDOWS_H
3434
#endif
3535

36+
#if !defined(NOMINMAX) && !defined(__MINGW32__) && !defined(__MINGW64__)
37+
// NOMINMAX prevents min()/max() macros from conflicting with std::min/std::max
38+
#define NOMINMAX
39+
#endif
40+
3641
#if defined(__MINGW32__) || defined(__MINGW64__)
3742
// #if defined(__GNUC__) && !defined(__clang__)
3843
#include <windows.h>

CPP/7zip/7zip.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ $(FASTLZMA2_OBJS): ../../../../C/fast-lzma2/$(*B).c
283283
{../../Compress}.cpp{$O}.obj::
284284
$(COMPLB)
285285
{../../Crypto}.cpp{$O}.obj::
286-
$(CCOMPLB)
286+
$(COMPLB_O2)
287287
{../../../../C}.c{$O}.obj::
288288
$(CCOMPLB)
289289
{../../../../C/brotli}.c{$O}.obj::

CPP/7zip/7zip_gcc.mak

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,16 +828,30 @@ $O/7zAes.o: ../../Crypto/7zAes.cpp
828828
$(CXX) $(CXXFLAGS) $<
829829
$O/7zAesRegister.o: ../../Crypto/7zAesRegister.cpp
830830
$(CXX) $(CXXFLAGS) $<
831+
$O/7zKeyDerivation.o: ../../Crypto/7zKeyDerivation.cpp
832+
$(CXX) $(CXXFLAGS) $<
833+
$O/Ascon.o: ../../Crypto/Ascon.cpp
834+
$(CXX) $(CXXFLAGS) $<
835+
$O/Cascade.o: ../../Crypto/Cascade.cpp
836+
$(CXX) $(CXXFLAGS) $<
837+
$O/CascadeRegister.o: ../../Crypto/CascadeRegister.cpp
838+
$(CXX) $(CXXFLAGS) $<
839+
$O/HkdfBlake2sp.o: ../../Crypto/HkdfBlake2sp.cpp
840+
$(CXX) $(CXXFLAGS) $<
831841
$O/HmacSha1.o: ../../Crypto/HmacSha1.cpp
832842
$(CXX) $(CXXFLAGS) $<
833843
$O/HmacSha256.o: ../../Crypto/HmacSha256.cpp
834844
$(CXX) $(CXXFLAGS) $<
845+
$O/HmacSha512.o: ../../Crypto/HmacSha512.cpp
846+
$(CXX) $(CXXFLAGS) $<
835847
$O/MyAes.o: ../../Crypto/MyAes.cpp
836848
$(CXX) $(CXXFLAGS) $<
837849
$O/MyAesReg.o: ../../Crypto/MyAesReg.cpp
838850
$(CXX) $(CXXFLAGS) $<
839851
$O/Pbkdf2HmacSha1.o: ../../Crypto/Pbkdf2HmacSha1.cpp
840852
$(CXX) $(CXXFLAGS) $<
853+
$O/Pbkdf2HmacSha512.o: ../../Crypto/Pbkdf2HmacSha512.cpp
854+
$(CXX) $(CXXFLAGS) $<
841855
$O/RandGen.o: ../../Crypto/RandGen.cpp
842856
$(CXX) $(CXXFLAGS) $<
843857
$O/Rar20Crypto.o: ../../Crypto/Rar20Crypto.cpp
@@ -848,6 +862,14 @@ $O/RarAes.o: ../../Crypto/RarAes.cpp
848862
$(CXX) $(CXXFLAGS) $<
849863
$O/WzAes.o: ../../Crypto/WzAes.cpp
850864
$(CXX) $(CXXFLAGS) $<
865+
$O/XChaCha20.o: ../../Crypto/XChaCha20.cpp
866+
$(CXX) $(CXXFLAGS) $<
867+
$O/XChaCha20Register.o: ../../Crypto/XChaCha20Register.cpp
868+
$(CXX) $(CXXFLAGS) $<
869+
$O/XChaCha20Poly1305.o: ../../Crypto/XChaCha20Poly1305.cpp
870+
$(CXX) $(CXXFLAGS) $<
871+
$O/XChaCha20Poly1305Register.o: ../../Crypto/XChaCha20Poly1305Register.cpp
872+
$(CXX) $(CXXFLAGS) $<
851873
$O/ZipCrypto.o: ../../Crypto/ZipCrypto.cpp
852874
$(CXX) $(CXXFLAGS) $<
853875
$O/ZipStrong.o: ../../Crypto/ZipStrong.cpp

CPP/7zip/Archive/7z/7zCompressionMode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "../../Common/MethodId.h"
77
#include "../../Common/MethodProps.h"
88

9+
#include "7zHeader.h"
10+
911
namespace NArchive {
1012
namespace N7z {
1113

@@ -64,6 +66,7 @@ struct CCompressionMethodMode
6466

6567
UString Password; // _Wipe
6668
UInt64 MemoryUsageLimit;
69+
CMethodId EncryptionMethodId;
6770

6871
bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
6972
CCompressionMethodMode():
@@ -78,6 +81,7 @@ struct CCompressionMethodMode
7881
, NumThreadGroups(0)
7982
#endif
8083
, MemoryUsageLimit((UInt64)1 << 30)
84+
, EncryptionMethodId(k_AES)
8185
{}
8286

8387
#ifdef Z7_CPP_IS_SUPPORTED_default

CPP/7zip/Archive/7z/7zDecode.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,27 @@ HRESULT CDecoder::Decode(
584584
progress2 = new CDecProgress(compressProgress);
585585

586586
ISequentialOutStream *outStreamPointer = outStream;
587-
return _mixer->Code(inStreamPointers, &outStreamPointer,
587+
const HRESULT codeResult = _mixer->Code(inStreamPointers, &outStreamPointer,
588588
progress2 ? (ICompressProgressInfo *)progress2 : compressProgress,
589589
dataAfterEnd_Error);
590+
591+
if (codeResult == S_OK)
592+
{
593+
for (i = 0; i < folderInfo.Coders.Size(); i++)
594+
{
595+
Z7_DECL_CMyComPtr_QI_FROM(
596+
ICryptoAuthVerify,
597+
authVerify, _mixer->GetCoder(i).GetUnknown())
598+
if (authVerify)
599+
{
600+
Int32 authResult = 0;
601+
RINOK(authVerify->CryptoAuthVerify(&authResult))
602+
if (authResult != 0)
603+
return S_FALSE;
604+
}
605+
}
606+
}
607+
return codeResult;
590608
}
591609

592610
#ifdef USE_MIXER_ST

CPP/7zip/Archive/7z/7zEncode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ HRESULT CEncoder::EncoderConstr()
562562
throw 1;
563563

564564
CMethodFull method;
565-
method.Id = k_AES;
565+
method.Id = _options.EncryptionMethodId;
566566
method.NumStreams = 1;
567567
_options.Methods.Add(method);
568568

@@ -687,7 +687,7 @@ HRESULT CEncoder::EncoderConstr()
687687
{
688688
CMethodFull method;
689689
method.NumStreams = 1;
690-
method.Id = k_AES;
690+
method.Id = _options.EncryptionMethodId;
691691
_options.Methods.Add(method);
692692

693693
NCoderMixer2::CCoderStreamsInfo cod;

CPP/7zip/Archive/7z/7zHandler.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ bool CHandler::IsFolderEncrypted(CNum folderIndex) const
307307
for (unsigned j = 0; j < idSize; j++)
308308
id64 = ((id64 << 8) | longID[j]);
309309
inByte.SkipDataNoCheck(idSize);
310-
if (id64 == k_AES)
310+
if (id64 == k_AES
311+
|| id64 == k_XCHACHA20
312+
|| id64 == k_XCHACHA20_POLY1305
313+
|| id64 == k_AES_XCHACHA20_POLY1305
314+
|| id64 == k_AES_XCHACHA20_ASCON)
311315
return true;
312316
if ((mainByte & 0x20) != 0)
313317
inByte.SkipDataNoCheck(inByte.ReadNum());
@@ -706,6 +710,46 @@ HRESULT CHandler::ObtainBlockMethods(CNum folderIndex, PROPVARIANT *prop, CHandl
706710
ConvertUInt32ToString(numCyclesPower, s);
707711
}
708712
break;
713+
case k_XCHACHA20:
714+
if (info) continue;
715+
name = "XChaCha20";
716+
if (propsSize >= 1)
717+
{
718+
const Byte firstByte = props[0];
719+
const UInt32 numCyclesPower = firstByte & 0x3F;
720+
ConvertUInt32ToString(numCyclesPower, s);
721+
}
722+
break;
723+
case k_XCHACHA20_POLY1305:
724+
if (info) continue;
725+
name = "XChaCha20-Poly1305";
726+
if (propsSize >= 1)
727+
{
728+
const Byte firstByte = props[0];
729+
const UInt32 numCyclesPower = firstByte & 0x3F;
730+
ConvertUInt32ToString(numCyclesPower, s);
731+
}
732+
break;
733+
case k_AES_XCHACHA20_ASCON:
734+
if (info) continue;
735+
name = "AES+XChaCha20+Ascon";
736+
if (propsSize >= 1)
737+
{
738+
const Byte firstByte = props[0];
739+
const UInt32 numCyclesPower = firstByte & 0x3F;
740+
ConvertUInt32ToString(numCyclesPower, s);
741+
}
742+
break;
743+
case k_AES_XCHACHA20_POLY1305:
744+
if (info) continue;
745+
name = "AES+XChaCha20-Poly1305";
746+
if (propsSize >= 1)
747+
{
748+
const Byte firstByte = props[0];
749+
const UInt32 numCyclesPower = firstByte & 0x3F;
750+
ConvertUInt32ToString(numCyclesPower, s);
751+
}
752+
break;
709753
}
710754
}
711755

0 commit comments

Comments
 (0)