mirror of https://github.com/hashcat/hashcat.git
parent
d08b5b04fa
commit
e365313a44
@ -0,0 +1,301 @@
|
||||
|
||||
MY_ARCH_2 = $(MY_ARCH)
|
||||
|
||||
MY_ASM = jwasm
|
||||
MY_ASM = asmc
|
||||
|
||||
PROGPATH = $(O)/$(PROG)
|
||||
|
||||
|
||||
# for object file
|
||||
CFLAGS_BASE_LIST = -c
|
||||
# for ASM file
|
||||
# CFLAGS_BASE_LIST = -S
|
||||
CFLAGS_BASE = $(MY_ARCH_2) -O2 $(CFLAGS_BASE_LIST) -Wall -Werror -Wextra $(CFLAGS_WARN) \
|
||||
-DNDEBUG -D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||
|
||||
|
||||
LDFLAGS_STATIC = -DNDEBUG
|
||||
# -static
|
||||
|
||||
ifdef SystemDrive
|
||||
IS_MINGW = 1
|
||||
endif
|
||||
|
||||
ifdef DEF_FILE
|
||||
|
||||
|
||||
ifdef IS_MINGW
|
||||
SHARED_EXT=.dll
|
||||
LDFLAGS = -shared -DEF $(DEF_FILE) $(LDFLAGS_STATIC)
|
||||
else
|
||||
SHARED_EXT=.so
|
||||
LDFLAGS = -shared -fPIC $(LDFLAGS_STATIC)
|
||||
CC_SHARED=-fPIC
|
||||
endif
|
||||
|
||||
|
||||
else
|
||||
|
||||
LDFLAGS = $(LDFLAGS_STATIC)
|
||||
# -s is not required for clang, do we need it for GGC ???
|
||||
# -s
|
||||
|
||||
#-static -static-libgcc -static-libstdc++
|
||||
|
||||
ifdef IS_MINGW
|
||||
SHARED_EXT=.exe
|
||||
else
|
||||
SHARED_EXT=
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
|
||||
PROGPATH = $(O)/$(PROG)$(SHARED_EXT)
|
||||
|
||||
|
||||
ifndef O
|
||||
O=_o
|
||||
endif
|
||||
|
||||
ifdef IS_MINGW
|
||||
|
||||
RM = del
|
||||
MY_MKDIR=mkdir
|
||||
LIB2 = -loleaut32 -luuid -ladvapi32 -lUser32
|
||||
|
||||
|
||||
CXXFLAGS_EXTRA = -DUNICODE -D_UNICODE
|
||||
# -Wno-delete-non-virtual-dtor
|
||||
|
||||
DEL_OBJ_EXE = -$(RM) $(O)\*.o $(O)\$(PROG).exe $(O)\$(PROG).dll
|
||||
|
||||
else
|
||||
|
||||
RM = rm -f
|
||||
MY_MKDIR=mkdir -p
|
||||
# CFLAGS_BASE := $(CFLAGS_BASE) -D_7ZIP_ST
|
||||
# CXXFLAGS_EXTRA = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||
|
||||
# LOCAL_LIBS=-lpthread
|
||||
# LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
|
||||
LIB2 = -lpthread -ldl
|
||||
|
||||
DEL_OBJ_EXE = -$(RM) $(PROGPATH) $(OBJS)
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
CFLAGS = $(LOCAL_FLAGS) $(CFLAGS_BASE2) $(CFLAGS_BASE) $(CC_SHARED) -o $@
|
||||
|
||||
|
||||
ifdef IS_X64
|
||||
AFLAGS_ABI = -elf64 -DABI_LINUX
|
||||
else
|
||||
AFLAGS_ABI = -elf -DABI_LINUX -DABI_CDECL
|
||||
# -DABI_CDECL
|
||||
# -DABI_LINUX
|
||||
# -DABI_CDECL
|
||||
endif
|
||||
AFLAGS = $(AFLAGS_ABI) -Fo$(O)/
|
||||
|
||||
|
||||
CXX_WARN_FLAGS =
|
||||
#-Wno-invalid-offsetof
|
||||
#-Wno-reorder
|
||||
|
||||
CXXFLAGS = $(LOCAL_FLAGS) $(CXXFLAGS_BASE2) $(CFLAGS_BASE) $(CXXFLAGS_EXTRA) $(CC_SHARED) -o $@ $(CXX_WARN_FLAGS)
|
||||
|
||||
all: $(O) $(PROGPATH)
|
||||
|
||||
$(O):
|
||||
$(MY_MKDIR) $(O)
|
||||
|
||||
$(PROGPATH): $(OBJS)
|
||||
$(CXX) -s -o $(PROGPATH) $(MY_ARCH_2) $(LDFLAGS) $(OBJS) $(MY_LIBS) $(LIB2)
|
||||
|
||||
|
||||
|
||||
ifndef NO_DEFAULT_RES
|
||||
$O/resource.o: resource.rc
|
||||
windres.exe $(RFLAGS) resource.rc $O/resource.o
|
||||
endif
|
||||
|
||||
|
||||
|
||||
$O/7zAlloc.o: ../../../C/7zAlloc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zArcIn.o: ../../../C/7zArcIn.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zBuf.o: ../../../C/7zBuf.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zBuf2.o: ../../../C/7zBuf2.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zCrc.o: ../../../C/7zCrc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zDec.o: ../../../C/7zDec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zFile.o: ../../../C/7zFile.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/7zStream.o: ../../../C/7zStream.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Aes.o: ../../../C/Aes.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Alloc.o: ../../../C/Alloc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Bcj2.o: ../../../C/Bcj2.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Bcj2Enc.o: ../../../C/Bcj2Enc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Blake2s.o: ../../../C/Blake2s.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Bra.o: ../../../C/Bra.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Bra86.o: ../../../C/Bra86.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/BraIA64.o: ../../../C/BraIA64.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/BwtSort.o: ../../../C/BwtSort.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
$O/CpuArch.o: ../../../C/CpuArch.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Delta.o: ../../../C/Delta.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/DllSecur.o: ../../../C/DllSecur.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/HuffEnc.o: ../../../C/HuffEnc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/LzFind.o: ../../../C/LzFind.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
# ifdef MT_FILES
|
||||
$O/LzFindMt.o: ../../../C/LzFindMt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
$O/Threads.o: ../../../C/Threads.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
# endif
|
||||
|
||||
$O/LzmaEnc.o: ../../../C/LzmaEnc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Lzma86Dec.o: ../../../C/Lzma86Dec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Lzma86Enc.o: ../../../C/Lzma86Enc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Lzma2Dec.o: ../../../C/Lzma2Dec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Lzma2DecMt.o: ../../../C/Lzma2DecMt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Lzma2Enc.o: ../../../C/Lzma2Enc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/LzmaLib.o: ../../../C/LzmaLib.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/MtCoder.o: ../../../C/MtCoder.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/MtDec.o: ../../../C/MtDec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd7.o: ../../../C/Ppmd7.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd7aDec.o: ../../../C/Ppmd7aDec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd7Dec.o: ../../../C/Ppmd7Dec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd7Enc.o: ../../../C/Ppmd7Enc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd8.o: ../../../C/Ppmd8.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd8Dec.o: ../../../C/Ppmd8Dec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Ppmd8Enc.o: ../../../C/Ppmd8Enc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Sha1.o: ../../../C/Sha1.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Sha256.o: ../../../C/Sha256.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Sort.o: ../../../C/Sort.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Xz.o: ../../../C/Xz.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/XzCrc64.o: ../../../C/XzCrc64.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
|
||||
ifdef USE_ASM
|
||||
ifdef IS_X64
|
||||
USE_X86_ASM=1
|
||||
else
|
||||
ifdef IS_X86
|
||||
USE_X86_ASM=1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef USE_X86_ASM
|
||||
$O/7zCrcOpt.o: ../../../Asm/x86/7zCrcOpt.asm
|
||||
$(MY_ASM) $(AFLAGS) $<
|
||||
$O/XzCrc64Opt.o: ../../../Asm/x86/XzCrc64Opt.asm
|
||||
$(MY_ASM) $(AFLAGS) $<
|
||||
$O/AesOpt.o: ../../../Asm/x86/AesOpt.asm
|
||||
$(MY_ASM) $(AFLAGS) $<
|
||||
$O/Sha1Opt.o: ../../../Asm/x86/Sha1Opt.asm
|
||||
$(MY_ASM) $(AFLAGS) $<
|
||||
$O/Sha256Opt.o: ../../../Asm/x86/Sha256Opt.asm
|
||||
$(MY_ASM) $(AFLAGS) $<
|
||||
else
|
||||
$O/7zCrcOpt.o: ../../7zCrcOpt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/XzCrc64Opt.o: ../../XzCrc64Opt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Sha1Opt.o: ../../Sha1Opt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/Sha256Opt.o: ../../Sha256Opt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/AesOpt.o: ../../AesOpt.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
endif
|
||||
|
||||
|
||||
ifdef USE_LZMA_DEC_ASM
|
||||
|
||||
ifdef IS_X64
|
||||
$O/LzmaDecOpt.o: ../../../Asm/x86/LzmaDecOpt.asm
|
||||
$(MY_ASM) $(AFLAGS) $<
|
||||
endif
|
||||
|
||||
ifdef IS_ARM64
|
||||
$O/LzmaDecOpt.o: ../../../Asm/arm64/LzmaDecOpt.S ../../../Asm/arm64/7zAsm.S
|
||||
$(CC) $(CFLAGS) $<
|
||||
endif
|
||||
|
||||
$O/LzmaDec.o: ../../LzmaDec.c
|
||||
$(CC) $(CFLAGS) -D_LZMA_DEC_OPT $<
|
||||
|
||||
else
|
||||
|
||||
$O/LzmaDec.o: ../../LzmaDec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
$O/XzDec.o: ../../../C/XzDec.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/XzEnc.o: ../../../C/XzEnc.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/XzIn.o: ../../../C/XzIn.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
|
||||
$O/7zMain.o: ../../../C/Util/7z/7zMain.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
$O/LzmaUtil.o: ../../../C/Util/Lzma/LzmaUtil.c
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
-$(DEL_OBJ_EXE)
|
@ -1,184 +1,776 @@
|
||||
/* AesOpt.c -- Intel's AES
|
||||
2017-06-08 : Igor Pavlov : Public domain */
|
||||
/* AesOpt.c -- AES optimized code for x86 AES hardware instructions
|
||||
2021-04-01 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include "CpuArch.h"
|
||||
|
||||
#ifdef MY_CPU_X86_OR_AMD64
|
||||
#if (_MSC_VER > 1500) || (_MSC_FULL_VER >= 150030729)
|
||||
#define USE_INTEL_AES
|
||||
|
||||
#if defined(__clang__)
|
||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 8)
|
||||
#define USE_INTEL_AES
|
||||
#define ATTRIB_AES __attribute__((__target__("aes")))
|
||||
#if (__clang_major__ >= 8)
|
||||
#define USE_INTEL_VAES
|
||||
#define ATTRIB_VAES __attribute__((__target__("aes,vaes,avx2")))
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
|
||||
#define USE_INTEL_AES
|
||||
#ifndef __AES__
|
||||
#define ATTRIB_AES __attribute__((__target__("aes")))
|
||||
#endif
|
||||
#if (__GNUC__ >= 8)
|
||||
#define USE_INTEL_VAES
|
||||
#define ATTRIB_VAES __attribute__((__target__("aes,vaes,avx2")))
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
#if (__INTEL_COMPILER >= 1110)
|
||||
#define USE_INTEL_AES
|
||||
#if (__INTEL_COMPILER >= 1900)
|
||||
#define USE_INTEL_VAES
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#if (_MSC_VER > 1500) || (_MSC_FULL_VER >= 150030729)
|
||||
#define USE_INTEL_AES
|
||||
#if (_MSC_VER >= 1910)
|
||||
#define USE_INTEL_VAES
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIB_AES
|
||||
#define ATTRIB_AES
|
||||
#endif
|
||||
#ifndef ATTRIB_VAES
|
||||
#define ATTRIB_VAES
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_INTEL_AES
|
||||
|
||||
#include <wmmintrin.h>
|
||||
|
||||
void MY_FAST_CALL AesCbc_Encode_Intel(__m128i *p, __m128i *data, size_t numBlocks)
|
||||
#ifndef USE_INTEL_VAES
|
||||
#define AES_TYPE_keys __m128i
|
||||
#define AES_TYPE_data __m128i
|
||||
#endif
|
||||
|
||||
#define AES_FUNC_START(name) \
|
||||
void MY_FAST_CALL name(__m128i *p, __m128i *data, size_t numBlocks)
|
||||
|
||||
#define AES_FUNC_START2(name) \
|
||||
AES_FUNC_START (name); \
|
||||
ATTRIB_AES \
|
||||
AES_FUNC_START (name)
|
||||
|
||||
#define MM_OP(op, dest, src) dest = op(dest, src);
|
||||
#define MM_OP_m(op, src) MM_OP(op, m, src);
|
||||
|
||||
#define MM_XOR( dest, src) MM_OP(_mm_xor_si128, dest, src);
|
||||
#define AVX_XOR(dest, src) MM_OP(_mm256_xor_si256, dest, src);
|
||||
|
||||
|
||||
AES_FUNC_START2 (AesCbc_Encode_HW)
|
||||
{
|
||||
__m128i m = *p;
|
||||
const __m128i k0 = p[2];
|
||||
const __m128i k1 = p[3];
|
||||
const UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
|
||||
for (; numBlocks != 0; numBlocks--, data++)
|
||||
{
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
|
||||
const __m128i *w = p + 3;
|
||||
m = _mm_xor_si128(m, *data);
|
||||
m = _mm_xor_si128(m, p[2]);
|
||||
UInt32 r = numRounds2;
|
||||
const __m128i *w = p + 4;
|
||||
__m128i temp = *data;
|
||||
MM_XOR (temp, k0);
|
||||
MM_XOR (m, temp);
|
||||
MM_OP_m (_mm_aesenc_si128, k1);
|
||||
do
|
||||
{
|
||||
m = _mm_aesenc_si128(m, w[0]);
|
||||
m = _mm_aesenc_si128(m, w[1]);
|
||||
MM_OP_m (_mm_aesenc_si128, w[0]);
|
||||
MM_OP_m (_mm_aesenc_si128, w[1]);
|
||||
w += 2;
|
||||
}
|
||||
while (--numRounds2 != 0);
|
||||
m = _mm_aesenc_si128(m, w[0]);
|
||||
m = _mm_aesenclast_si128(m, w[1]);
|
||||
while (--r);
|
||||
MM_OP_m (_mm_aesenclast_si128, w[0]);
|
||||
*data = m;
|
||||
}
|
||||
*p = m;
|
||||
}
|
||||
|
||||
#define NUM_WAYS 3
|
||||
|
||||
#define AES_OP_W(op, n) { \
|
||||
const __m128i t = w[n]; \
|
||||
m0 = op(m0, t); \
|
||||
m1 = op(m1, t); \
|
||||
m2 = op(m2, t); \
|
||||
}
|
||||
#define WOP_1(op)
|
||||
#define WOP_2(op) WOP_1 (op) op (m1, 1);
|
||||
#define WOP_3(op) WOP_2 (op) op (m2, 2);
|
||||
#define WOP_4(op) WOP_3 (op) op (m3, 3);
|
||||
#ifdef MY_CPU_AMD64
|
||||
#define WOP_5(op) WOP_4 (op) op (m4, 4);
|
||||
#define WOP_6(op) WOP_5 (op) op (m5, 5);
|
||||
#define WOP_7(op) WOP_6 (op) op (m6, 6);
|
||||
#define WOP_8(op) WOP_7 (op) op (m7, 7);
|
||||
#endif
|
||||
/*
|
||||
#define WOP_9(op) WOP_8 (op) op (m8, 8);
|
||||
#define WOP_10(op) WOP_9 (op) op (m9, 9);
|
||||
#define WOP_11(op) WOP_10(op) op (m10, 10);
|
||||
#define WOP_12(op) WOP_11(op) op (m11, 11);
|
||||
#define WOP_13(op) WOP_12(op) op (m12, 12);
|
||||
#define WOP_14(op) WOP_13(op) op (m13, 13);
|
||||
*/
|
||||
|
||||
#ifdef MY_CPU_AMD64
|
||||
#define NUM_WAYS 8
|
||||
#define WOP_M1 WOP_8
|
||||
#else
|
||||
#define NUM_WAYS 4
|
||||
#define WOP_M1 WOP_4
|
||||
#endif
|
||||
|
||||
#define WOP(op) op (m0, 0); WOP_M1(op)
|
||||
|
||||
|
||||
#define DECLARE_VAR(reg, ii) __m128i reg
|
||||
#define LOAD_data( reg, ii) reg = data[ii];
|
||||
#define STORE_data( reg, ii) data[ii] = reg;
|
||||
#if (NUM_WAYS > 1)
|
||||
#define XOR_data_M1(reg, ii) MM_XOR (reg, data[ii- 1]);
|
||||
#endif
|
||||
|
||||
#define AVX__DECLARE_VAR(reg, ii) __m256i reg
|
||||
#define AVX__LOAD_data( reg, ii) reg = ((const __m256i *)(const void *)data)[ii];
|
||||
#define AVX__STORE_data( reg, ii) ((__m256i *)(void *)data)[ii] = reg;
|
||||
#define AVX__XOR_data_M1(reg, ii) AVX_XOR (reg, (((const __m256i *)(const void *)(data - 1))[ii]));
|
||||
|
||||
#define MM_OP_key(op, reg) MM_OP(op, reg, key);
|
||||
|
||||
#define AES_DEC( reg, ii) MM_OP_key (_mm_aesdec_si128, reg)
|
||||
#define AES_DEC_LAST( reg, ii) MM_OP_key (_mm_aesdeclast_si128, reg)
|
||||
#define AES_ENC( reg, ii) MM_OP_key (_mm_aesenc_si128, reg)
|
||||
#define AES_ENC_LAST( reg, ii) MM_OP_key (_mm_aesenclast_si128, reg)
|
||||
#define AES_XOR( reg, ii) MM_OP_key (_mm_xor_si128, reg)
|
||||
|
||||
|
||||
#define AES_DEC(n) AES_OP_W(_mm_aesdec_si128, n)
|
||||
#define AES_DEC_LAST(n) AES_OP_W(_mm_aesdeclast_si128, n)
|
||||
#define AES_ENC(n) AES_OP_W(_mm_aesenc_si128, n)
|
||||
#define AES_ENC_LAST(n) AES_OP_W(_mm_aesenclast_si128, n)
|
||||
#define AVX__AES_DEC( reg, ii) MM_OP_key (_mm256_aesdec_epi128, reg)
|
||||
#define AVX__AES_DEC_LAST( reg, ii) MM_OP_key (_mm256_aesdeclast_epi128, reg)
|
||||
#define AVX__AES_ENC( reg, ii) MM_OP_key (_mm256_aesenc_epi128, reg)
|
||||
#define AVX__AES_ENC_LAST( reg, ii) MM_OP_key (_mm256_aesenclast_epi128, reg)
|
||||
#define AVX__AES_XOR( reg, ii) MM_OP_key (_mm256_xor_si256, reg)
|
||||
|
||||
void MY_FAST_CALL AesCbc_Decode_Intel(__m128i *p, __m128i *data, size_t numBlocks)
|
||||
#define CTR_START(reg, ii) MM_OP (_mm_add_epi64, ctr, one); reg = ctr;
|
||||
#define CTR_END( reg, ii) MM_XOR (data[ii], reg);
|
||||
|
||||
#define AVX__CTR_START(reg, ii) MM_OP (_mm256_add_epi64, ctr2, two); reg = _mm256_xor_si256(ctr2, key);
|
||||
#define AVX__CTR_END( reg, ii) AVX_XOR (((__m256i *)(void *)data)[ii], reg);
|
||||
|
||||
#define WOP_KEY(op, n) { \
|
||||
const __m128i key = w[n]; \
|
||||
WOP(op); }
|
||||
|
||||
#define AVX__WOP_KEY(op, n) { \
|
||||
const __m256i key = w[n]; \
|
||||
WOP(op); }
|
||||
|
||||
|
||||
#define WIDE_LOOP_START \
|
||||
dataEnd = data + numBlocks; \
|
||||
if (numBlocks >= NUM_WAYS) \
|
||||
{ dataEnd -= NUM_WAYS; do { \
|
||||
|
||||
|
||||
#define WIDE_LOOP_END \
|
||||
data += NUM_WAYS; \
|
||||
} while (data <= dataEnd); \
|
||||
dataEnd += NUM_WAYS; } \
|
||||
|
||||
|
||||
#define SINGLE_LOOP \
|
||||
for (; data < dataEnd; data++)
|
||||
|
||||
|
||||
#define NUM_AES_KEYS_MAX 15
|
||||
|
||||
#define WIDE_LOOP_START_AVX(OP) \
|
||||
dataEnd = data + numBlocks; \
|
||||
if (numBlocks >= NUM_WAYS * 2) \
|
||||
{ __m256i keys[NUM_AES_KEYS_MAX]; \
|
||||
UInt32 ii; \
|
||||
OP \
|
||||
for (ii = 0; ii < numRounds; ii++) \
|
||||
keys[ii] = _mm256_broadcastsi128_si256(p[ii]); \
|
||||
dataEnd -= NUM_WAYS * 2; do { \
|
||||
|
||||
|
||||
#define WIDE_LOOP_END_AVX(OP) \
|
||||
data += NUM_WAYS * 2; \
|
||||
} while (data <= dataEnd); \
|
||||
dataEnd += NUM_WAYS * 2; \
|
||||
OP \
|
||||
_mm256_zeroupper(); \
|
||||
} \
|
||||
|
||||
/* MSVC for x86: If we don't call _mm256_zeroupper(), and -arch:IA32 is not specified,
|
||||
MSVC still can insert vzeroupper instruction. */
|
||||
|
||||
|
||||
AES_FUNC_START2 (AesCbc_Decode_HW)
|
||||
{
|
||||
__m128i iv = *p;
|
||||
for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS)
|
||||
const __m128i *wStart = p + *(const UInt32 *)(p + 1) * 2 + 2 - 1;
|
||||
const __m128i *dataEnd;
|
||||
p += 2;
|
||||
|
||||
WIDE_LOOP_START
|
||||
{
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p + 1);
|
||||
const __m128i *w = p + numRounds2 * 2;
|
||||
__m128i m0, m1, m2;
|
||||
const __m128i *w = wStart;
|
||||
|
||||
WOP (DECLARE_VAR)
|
||||
WOP (LOAD_data);
|
||||
WOP_KEY (AES_XOR, 1)
|
||||
|
||||
do
|
||||
{
|
||||
const __m128i t = w[2];
|
||||
m0 = _mm_xor_si128(t, data[0]);
|
||||
m1 = _mm_xor_si128(t, data[1]);
|
||||
m2 = _mm_xor_si128(t, data[2]);
|
||||
WOP_KEY (AES_DEC, 0)
|
||||
w--;
|
||||
}
|
||||
numRounds2--;
|
||||
while (w != p);
|
||||
WOP_KEY (AES_DEC_LAST, 0)
|
||||
|
||||
MM_XOR (m0, iv);
|
||||
WOP_M1 (XOR_data_M1)
|
||||
iv = data[NUM_WAYS - 1];
|
||||
WOP (STORE_data);
|
||||
}
|
||||
WIDE_LOOP_END
|
||||
|
||||
SINGLE_LOOP
|
||||
{
|
||||
const __m128i *w = wStart - 1;
|
||||
__m128i m = _mm_xor_si128 (w[2], *data);
|
||||
do
|
||||
{
|
||||
AES_DEC(1)
|
||||
AES_DEC(0)
|
||||
MM_OP_m (_mm_aesdec_si128, w[1]);
|
||||
MM_OP_m (_mm_aesdec_si128, w[0]);
|
||||
w -= 2;
|
||||
}
|
||||
while (--numRounds2 != 0);
|
||||
AES_DEC(1)
|
||||
AES_DEC_LAST(0)
|
||||
while (w != p);
|
||||
MM_OP_m (_mm_aesdec_si128, w[1]);
|
||||
MM_OP_m (_mm_aesdeclast_si128, w[0]);
|
||||
|
||||
MM_XOR (m, iv);
|
||||
iv = *data;
|
||||
*data = m;
|
||||
}
|
||||
|
||||
p[-2] = iv;
|
||||
}
|
||||
|
||||
|
||||
AES_FUNC_START2 (AesCtr_Code_HW)
|
||||
{
|
||||
__m128i ctr = *p;
|
||||
UInt32 numRoundsMinus2 = *(const UInt32 *)(p + 1) * 2 - 1;
|
||||
const __m128i *dataEnd;
|
||||
__m128i one = _mm_cvtsi32_si128(1);
|
||||
|
||||
p += 2;
|
||||
|
||||
WIDE_LOOP_START
|
||||
{
|
||||
const __m128i *w = p;
|
||||
UInt32 r = numRoundsMinus2;
|
||||
WOP (DECLARE_VAR)
|
||||
WOP (CTR_START);
|
||||
WOP_KEY (AES_XOR, 0)
|
||||
w += 1;
|
||||
do
|
||||
{
|
||||
__m128i t;
|
||||
t = _mm_xor_si128(m0, iv); iv = data[0]; data[0] = t;
|
||||
t = _mm_xor_si128(m1, iv); iv = data[1]; data[1] = t;
|
||||
t = _mm_xor_si128(m2, iv); iv = data[2]; data[2] = t;
|
||||
WOP_KEY (AES_ENC, 0)
|
||||
w += 1;
|
||||
}
|
||||
while (--r);
|
||||
WOP_KEY (AES_ENC_LAST, 0)
|
||||
|
||||
WOP (CTR_END);
|
||||
}
|
||||
for (; numBlocks != 0; numBlocks--, data++)
|
||||
WIDE_LOOP_END
|
||||
|
||||
SINGLE_LOOP
|
||||
{
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p - 2 + 1) - 1;
|
||||
const __m128i *w = p;
|
||||
__m128i m;
|
||||
MM_OP (_mm_add_epi64, ctr, one);
|
||||
m = _mm_xor_si128 (ctr, p[0]);
|
||||
w += 1;
|
||||
do
|
||||
{
|
||||
MM_OP_m (_mm_aesenc_si128, w[0]);
|
||||
MM_OP_m (_mm_aesenc_si128, w[1]);
|
||||
w += 2;
|
||||
}
|
||||
while (--numRounds2);
|
||||
MM_OP_m (_mm_aesenc_si128, w[0]);
|
||||
MM_OP_m (_mm_aesenclast_si128, w[1]);
|
||||
MM_XOR (*data, m);
|
||||
}
|
||||
|
||||
p[-2] = ctr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef USE_INTEL_VAES
|
||||
|
||||
#if defined(__clang__) && defined(_MSC_VER)
|
||||
#define __SSE4_2__
|
||||
#define __AES__
|
||||
#define __AVX__
|
||||
#define __AVX2__
|
||||
#define __VAES__
|
||||
#define __AVX512F__
|
||||
#define __AVX512VL__
|
||||
#endif
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
#define VAES_FUNC_START2(name) \
|
||||
AES_FUNC_START (name); \
|
||||
ATTRIB_VAES \
|
||||
AES_FUNC_START (name)
|
||||
|
||||
VAES_FUNC_START2 (AesCbc_Decode_HW_256)
|
||||
{
|
||||
__m128i iv = *p;
|
||||
const __m128i *dataEnd;
|
||||
UInt32 numRounds = *(const UInt32 *)(p + 1) * 2 + 1;
|
||||
p += 2;
|
||||
|
||||
WIDE_LOOP_START_AVX(;)
|
||||
{
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p + 1);
|
||||
const __m128i *w = p + numRounds2 * 2;
|
||||
__m128i m = _mm_xor_si128(w[2], *data);
|
||||
numRounds2--;
|
||||
const __m256i *w = keys + numRounds - 2;
|
||||
|
||||
WOP (AVX__DECLARE_VAR)
|
||||
WOP (AVX__LOAD_data);
|
||||
AVX__WOP_KEY (AVX__AES_XOR, 1)
|
||||
|
||||
do
|
||||
{
|
||||
m = _mm_aesdec_si128(m, w[1]);
|
||||
m = _mm_aesdec_si128(m, w[0]);
|
||||
AVX__WOP_KEY (AVX__AES_DEC, 0)
|
||||
w--;
|
||||
}
|
||||
while (w != keys);
|
||||
AVX__WOP_KEY (AVX__AES_DEC_LAST, 0)
|
||||
|
||||
AVX_XOR (m0, _mm256_setr_m128i(iv, data[0]));
|
||||
WOP_M1 (AVX__XOR_data_M1)
|
||||
iv = data[NUM_WAYS * 2 - 1];
|
||||
WOP (AVX__STORE_data);
|
||||
}
|
||||
WIDE_LOOP_END_AVX(;)
|
||||
|
||||
SINGLE_LOOP
|
||||
{
|
||||
const __m128i *w = p + *(const UInt32 *)(p + 1 - 2) * 2 + 1 - 3;
|
||||
__m128i m = _mm_xor_si128 (w[2], *data);
|
||||
do
|
||||
{
|
||||
MM_OP_m (_mm_aesdec_si128, w[1]);
|
||||
MM_OP_m (_mm_aesdec_si128, w[0]);
|
||||
w -= 2;
|
||||
}
|
||||
while (--numRounds2 != 0);
|
||||
m = _mm_aesdec_si128(m, w[1]);
|
||||
m = _mm_aesdeclast_si128(m, w[0]);
|
||||
while (w != p);
|
||||
MM_OP_m (_mm_aesdec_si128, w[1]);
|
||||
MM_OP_m (_mm_aesdeclast_si128, w[0]);
|
||||
|
||||
m = _mm_xor_si128(m, iv);
|
||||
MM_XOR (m, iv);
|
||||
iv = *data;
|
||||
*data = m;
|
||||
}
|
||||
*p = iv;
|
||||
|
||||
p[-2] = iv;
|
||||
}
|
||||
|
||||
void MY_FAST_CALL AesCtr_Code_Intel(__m128i *p, __m128i *data, size_t numBlocks)
|
||||
|
||||
/*
|
||||
SSE2: _mm_cvtsi32_si128 : movd
|
||||
AVX: _mm256_setr_m128i : vinsertf128
|
||||
AVX2: _mm256_add_epi64 : vpaddq ymm, ymm, ymm
|
||||
_mm256_extracti128_si256 : vextracti128
|
||||
_mm256_broadcastsi128_si256 : vbroadcasti128
|
||||
*/
|
||||
|
||||
#define AVX__CTR_LOOP_START \
|
||||
ctr2 = _mm256_setr_m128i(_mm_sub_epi64(ctr, one), ctr); \
|
||||
two = _mm256_setr_m128i(one, one); \
|
||||
two = _mm256_add_epi64(two, two); \
|
||||
|
||||
// two = _mm256_setr_epi64x(2, 0, 2, 0);
|
||||
|
||||
#define AVX__CTR_LOOP_ENC \
|
||||
ctr = _mm256_extracti128_si256 (ctr2, 1); \
|
||||
|
||||
VAES_FUNC_START2 (AesCtr_Code_HW_256)
|
||||
{
|
||||
__m128i ctr = *p;
|
||||
__m128i one;
|
||||
one.m128i_u64[0] = 1;
|
||||
one.m128i_u64[1] = 0;
|
||||
for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS)
|
||||
UInt32 numRounds = *(const UInt32 *)(p + 1) * 2 + 1;
|
||||
const __m128i *dataEnd;
|
||||
__m128i one = _mm_cvtsi32_si128(1);
|
||||
__m256i ctr2, two;
|
||||
p += 2;
|
||||
|
||||
WIDE_LOOP_START_AVX (AVX__CTR_LOOP_START)
|
||||
{
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
|
||||
const __m128i *w = p;
|
||||
__m128i m0, m1, m2;
|
||||
{
|
||||
const __m128i t = w[2];
|
||||
ctr = _mm_add_epi64(ctr, one); m0 = _mm_xor_si128(ctr, t);
|
||||
ctr = _mm_add_epi64(ctr, one); m1 = _mm_xor_si128(ctr, t);
|
||||
ctr = _mm_add_epi64(ctr, one); m2 = _mm_xor_si128(ctr, t);
|
||||
}
|
||||
w += 3;
|
||||
const __m256i *w = keys;
|
||||
UInt32 r = numRounds - 2;
|
||||
WOP (AVX__DECLARE_VAR)
|
||||
AVX__WOP_KEY (AVX__CTR_START, 0);
|
||||
|
||||
w += 1;
|
||||
do
|
||||
{
|
||||
AES_ENC(0)
|
||||
AES_ENC(1)
|
||||
w += 2;
|
||||
AVX__WOP_KEY (AVX__AES_ENC, 0)
|
||||
w += 1;
|
||||
}
|
||||
while (--numRounds2 != 0);
|
||||
AES_ENC(0)
|
||||
AES_ENC_LAST(1)
|
||||
data[0] = _mm_xor_si128(data[0], m0);
|
||||
data[1] = _mm_xor_si128(data[1], m1);
|
||||
data[2] = _mm_xor_si128(data[2], m2);
|
||||
while (--r);
|
||||
AVX__WOP_KEY (AVX__AES_ENC_LAST, 0)
|
||||
|
||||
WOP (AVX__CTR_END);
|
||||
}
|
||||
for (; numBlocks != 0; numBlocks--, data++)
|
||||
WIDE_LOOP_END_AVX (AVX__CTR_LOOP_ENC)
|
||||
|
||||
SINGLE_LOOP
|
||||
{
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
|
||||
UInt32 numRounds2 = *(const UInt32 *)(p - 2 + 1) - 1;
|
||||
const __m128i *w = p;
|
||||
__m128i m;
|
||||
ctr = _mm_add_epi64(ctr, one);
|
||||
m = _mm_xor_si128(ctr, p[2]);
|
||||
w += 3;
|
||||
MM_OP (_mm_add_epi64, ctr, one);
|
||||
m = _mm_xor_si128 (ctr, p[0]);
|
||||
w += 1;
|
||||
do
|
||||
{
|
||||
m = _mm_aesenc_si128(m, w[0]);
|
||||
m = _mm_aesenc_si128(m, w[1]);
|
||||
MM_OP_m (_mm_aesenc_si128, w[0]);
|
||||
MM_OP_m (_mm_aesenc_si128, w[1]);
|
||||
w += 2;
|
||||
}
|
||||
while (--numRounds2 != 0);
|
||||
m = _mm_aesenc_si128(m, w[0]);
|
||||
m = _mm_aesenclast_si128(m, w[1]);
|
||||
*data = _mm_xor_si128(*data, m);
|
||||
while (--numRounds2);
|
||||
MM_OP_m (_mm_aesenc_si128, w[0]);
|
||||
MM_OP_m (_mm_aesenclast_si128, w[1]);
|
||||
MM_XOR (*data, m);
|
||||
}
|
||||
*p = ctr;
|
||||
|
||||
p[-2] = ctr;
|
||||
}
|
||||
|
||||
#endif // USE_INTEL_VAES
|
||||
|
||||
#else // USE_INTEL_AES
|
||||
|
||||
/* no USE_INTEL_AES */
|
||||
|
||||
#pragma message("AES HW_SW stub was used")
|
||||
|
||||
#define AES_TYPE_keys UInt32
|
||||
#define AES_TYPE_data Byte
|
||||
|
||||
#define AES_FUNC_START(name) \
|
||||
void MY_FAST_CALL name(UInt32 *p, Byte *data, size_t numBlocks) \
|
||||
|
||||
#define AES_COMPAT_STUB(name) \
|
||||
AES_FUNC_START(name); \
|
||||
AES_FUNC_START(name ## _HW) \
|
||||
{ name(p, data, numBlocks); }
|
||||
|
||||
AES_COMPAT_STUB (AesCbc_Encode)
|
||||
AES_COMPAT_STUB (AesCbc_Decode)
|
||||
AES_COMPAT_STUB (AesCtr_Code)
|
||||
|
||||
#endif // USE_INTEL_AES
|
||||
|
||||
|
||||
#ifndef USE_INTEL_VAES
|
||||
|
||||
#pragma message("VAES HW_SW stub was used")
|
||||
|
||||
#define VAES_COMPAT_STUB(name) \
|
||||
void MY_FAST_CALL name ## _256(UInt32 *p, Byte *data, size_t numBlocks); \
|
||||
void MY_FAST_CALL name ## _256(UInt32 *p, Byte *data, size_t numBlocks) \
|
||||
{ name((AES_TYPE_keys *)(void *)p, (AES_TYPE_data *)(void *)data, numBlocks); }
|
||||
|
||||
VAES_COMPAT_STUB (AesCbc_Decode_HW)
|
||||
VAES_COMPAT_STUB (AesCtr_Code_HW)
|
||||
|
||||
#endif // ! USE_INTEL_VAES
|
||||
|
||||
|
||||
#elif defined(MY_CPU_ARM_OR_ARM64) && defined(MY_CPU_LE)
|
||||
|
||||
#if defined(__clang__)
|
||||
#if (__clang_major__ >= 8) // fix that check
|
||||
#define USE_HW_AES
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#if (__GNUC__ >= 6) // fix that check
|
||||
#define USE_HW_AES
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#if _MSC_VER >= 1910
|
||||
#define USE_HW_AES
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_HW_AES
|
||||
|
||||
// #pragma message("=== AES HW === ")
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#ifdef MY_CPU_ARM64
|
||||
#define ATTRIB_AES __attribute__((__target__("+crypto")))
|
||||
#else
|
||||
#define ATTRIB_AES __attribute__((__target__("fpu=crypto-neon-fp-armv8")))
|
||||
#endif
|
||||
#else
|
||||
// _MSC_VER
|
||||
// for arm32
|
||||
#define _ARM_USE_NEW_NEON_INTRINSICS
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIB_AES
|
||||
#define ATTRIB_AES
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(MY_CPU_ARM64)
|
||||
#include <arm64_neon.h>
|
||||
#else
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
typedef uint8x16_t v128;
|
||||
|
||||
#define AES_FUNC_START(name) \
|
||||
void MY_FAST_CALL name(v128 *p, v128 *data, size_t numBlocks)
|
||||
|
||||
#define AES_FUNC_START2(name) \
|
||||
AES_FUNC_START (name); \
|
||||
ATTRIB_AES \
|
||||
AES_FUNC_START (name)
|
||||
|
||||
#define MM_OP(op, dest, src) dest = op(dest, src);
|
||||
#define MM_OP_m(op, src) MM_OP(op, m, src);
|
||||
#define MM_OP1_m(op) m = op(m);
|
||||
|
||||
void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);
|
||||
void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);
|
||||
void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);
|
||||
#define MM_XOR( dest, src) MM_OP(veorq_u8, dest, src);
|
||||
#define MM_XOR_m( src) MM_XOR(m, src);
|
||||
|
||||
void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *p, Byte *data, size_t numBlocks)
|
||||
#define AES_E_m(k) MM_OP_m (vaeseq_u8, k);
|
||||
#define AES_E_MC_m(k) AES_E_m (k); MM_OP1_m(vaesmcq_u8);
|
||||
|
||||
|
||||
AES_FUNC_START2 (AesCbc_Encode_HW)
|
||||
{
|
||||
AesCbc_Encode(p, data, numBlocks);
|
||||
v128 m = *p;
|
||||
const v128 k0 = p[2];
|
||||
const v128 k1 = p[3];
|
||||
const v128 k2 = p[4];
|
||||
const v128 k3 = p[5];
|
||||
const v128 k4 = p[6];
|
||||
const v128 k5 = p[7];
|
||||
const v128 k6 = p[8];
|
||||
const v128 k7 = p[9];
|
||||
const v128 k8 = p[10];
|
||||
const v128 k9 = p[11];
|
||||
const UInt32 numRounds2 = *(const UInt32 *)(p + 1);
|
||||
const v128 *w = p + ((size_t)numRounds2 * 2);
|
||||
const v128 k_z1 = w[1];
|
||||
const v128 k_z0 = w[2];
|
||||
for (; numBlocks != 0; numBlocks--, data++)
|
||||
{
|
||||
MM_XOR_m (*data);
|
||||
AES_E_MC_m (k0)
|
||||
AES_E_MC_m (k1)
|
||||
AES_E_MC_m (k2)
|
||||
AES_E_MC_m (k3)
|
||||
AES_E_MC_m (k4)
|
||||
AES_E_MC_m (k5)
|
||||
AES_E_MC_m (k6)
|
||||
AES_E_MC_m (k7)
|
||||
AES_E_MC_m (k8)
|
||||
if (numRounds2 >= 6)
|
||||
{
|
||||
AES_E_MC_m (k9)
|
||||
AES_E_MC_m (p[12])
|
||||
if (numRounds2 != 6)
|
||||
{
|
||||
AES_E_MC_m (p[13])
|
||||
AES_E_MC_m (p[14])
|
||||
}
|
||||
}
|
||||
AES_E_m (k_z1);
|
||||
MM_XOR_m (k_z0);
|
||||
*data = m;
|
||||
}
|
||||
*p = m;
|
||||
}
|
||||
|
||||
void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *p, Byte *data, size_t numBlocks)
|
||||
|
||||
#define WOP_1(op)
|
||||
#define WOP_2(op) WOP_1 (op) op (m1, 1);
|
||||
#define WOP_3(op) WOP_2 (op) op (m2, 2);
|
||||
#define WOP_4(op) WOP_3 (op) op (m3, 3);
|
||||
#define WOP_5(op) WOP_4 (op) op (m4, 4);
|
||||
#define WOP_6(op) WOP_5 (op) op (m5, 5);
|
||||
#define WOP_7(op) WOP_6 (op) op (m6, 6);
|
||||
#define WOP_8(op) WOP_7 (op) op (m7, 7);
|
||||
|
||||
#define NUM_WAYS 8
|
||||
#define WOP_M1 WOP_8
|
||||
|
||||
#define WOP(op) op (m0, 0); WOP_M1(op)
|
||||
|
||||
#define DECLARE_VAR(reg, ii) v128 reg
|
||||
#define LOAD_data( reg, ii) reg = data[ii];
|
||||
#define STORE_data( reg, ii) data[ii] = reg;
|
||||
#if (NUM_WAYS > 1)
|
||||
#define XOR_data_M1(reg, ii) MM_XOR (reg, data[ii- 1]);
|
||||
#endif
|
||||
|
||||
#define MM_OP_key(op, reg) MM_OP (op, reg, key);
|
||||
|
||||
#define AES_D_m(k) MM_OP_m (vaesdq_u8, k);
|
||||
#define AES_D_IMC_m(k) AES_D_m (k); MM_OP1_m (vaesimcq_u8);
|
||||
|
||||
#define AES_XOR( reg, ii) MM_OP_key (veorq_u8, reg)
|
||||
#define AES_D( reg, ii) MM_OP_key (vaesdq_u8, reg)
|
||||
#define AES_E( reg, ii) MM_OP_key (vaeseq_u8, reg)
|
||||
|
||||
#define AES_D_IMC( reg, ii) AES_D (reg, ii); reg = vaesimcq_u8(reg)
|
||||
#define AES_E_MC( reg, ii) AES_E (reg, ii); reg = vaesmcq_u8(reg)
|
||||
|
||||
#define CTR_START(reg, ii) MM_OP (vaddq_u64, ctr, one); reg = vreinterpretq_u8_u64(ctr);
|
||||
#define CTR_END( reg, ii) MM_XOR (data[ii], reg);
|
||||
|
||||
#define WOP_KEY(op, n) { \
|
||||
const v128 key = w[n]; \
|
||||
WOP(op); }
|
||||
|
||||
#define WIDE_LOOP_START \
|
||||
dataEnd = data + numBlocks; \
|
||||
if (numBlocks >= NUM_WAYS) \
|
||||
{ dataEnd -= NUM_WAYS; do { \
|
||||
|
||||
#define WIDE_LOOP_END \
|
||||
data += NUM_WAYS; \
|
||||
} while (data <= dataEnd); \
|
||||
dataEnd += NUM_WAYS; } \
|
||||
|
||||
#define SINGLE_LOOP \
|
||||
for (; data < dataEnd; data++)
|
||||
|
||||
|
||||
AES_FUNC_START2 (AesCbc_Decode_HW)
|
||||
{
|
||||
AesCbc_Decode(p, data, numBlocks);
|
||||
v128 iv = *p;
|
||||
const v128 *wStart = p + ((size_t)*(const UInt32 *)(p + 1)) * 2;
|
||||
const v128 *dataEnd;
|
||||
p += 2;
|
||||
|
||||
WIDE_LOOP_START
|
||||
{
|
||||
const v128 *w = wStart;
|
||||
WOP (DECLARE_VAR)
|
||||
WOP (LOAD_data);
|
||||
WOP_KEY (AES_D_IMC, 2)
|
||||
do
|
||||
{
|
||||
WOP_KEY (AES_D_IMC, 1)
|
||||
WOP_KEY (AES_D_IMC, 0)
|
||||
w -= 2;
|
||||
}
|
||||
while (w != p);
|
||||
WOP_KEY (AES_D, 1)
|
||||
WOP_KEY (AES_XOR, 0)
|
||||
MM_XOR (m0, iv);
|
||||
WOP_M1 (XOR_data_M1)
|
||||
iv = data[NUM_WAYS - 1];
|
||||
WOP (STORE_data);
|
||||
}
|
||||
WIDE_LOOP_END
|
||||
|
||||
SINGLE_LOOP
|
||||
{
|
||||
const v128 *w = wStart;
|
||||
v128 m = *data;
|
||||
AES_D_IMC_m (w[2])
|
||||
do
|
||||
{
|
||||
AES_D_IMC_m (w[1]);
|
||||
AES_D_IMC_m (w[0]);
|
||||
w -= 2;
|
||||
}
|
||||
while (w != p);
|
||||
AES_D_m (w[1]);
|
||||
MM_XOR_m (w[0]);
|
||||
MM_XOR_m (iv);
|
||||
iv = *data;
|
||||
*data = m;
|
||||
}
|
||||
|
||||
p[-2] = iv;
|
||||
}
|
||||
|
||||
void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *p, Byte *data, size_t numBlocks)
|
||||
|
||||
AES_FUNC_START2 (AesCtr_Code_HW)
|
||||
{
|
||||
AesCtr_Code(p, data, numBlocks);
|
||||
uint64x2_t ctr = vreinterpretq_u64_u8(*p);
|
||||
const v128 *wEnd = p + ((size_t)*(const UInt32 *)(p + 1)) * 2;
|
||||
const v128 *dataEnd;
|
||||
uint64x2_t one = vdupq_n_u64(0);
|
||||
one = vsetq_lane_u64(1, one, 0);
|
||||
p += 2;
|
||||
|
||||
WIDE_LOOP_START
|
||||
{
|
||||
const v128 *w = p;
|
||||
WOP (DECLARE_VAR)
|
||||
WOP (CTR_START);
|
||||
do
|
||||
{
|
||||
WOP_KEY (AES_E_MC, 0)
|
||||
WOP_KEY (AES_E_MC, 1)
|
||||
w += 2;
|
||||
}
|
||||
while (w != wEnd);
|
||||
WOP_KEY (AES_E_MC, 0)
|
||||
WOP_KEY (AES_E, 1)
|
||||
WOP_KEY (AES_XOR, 2)
|
||||
WOP (CTR_END);
|
||||
}
|
||||
WIDE_LOOP_END
|
||||
|
||||
SINGLE_LOOP
|
||||
{
|
||||
const v128 *w = p;
|
||||
v128 m;
|
||||
CTR_START (m, 0);
|
||||
do
|
||||
{
|
||||
AES_E_MC_m (w[0]);
|
||||
AES_E_MC_m (w[1]);
|
||||
w += 2;
|
||||
}
|
||||
while (w != wEnd);
|
||||
AES_E_MC_m (w[0]);
|
||||
AES_E_m (w[1]);
|
||||
MM_XOR_m (w[2]);
|
||||
CTR_END (m, 0);
|
||||
}
|
||||
|
||||
p[-2] = vreinterpretq_u8_u64(ctr);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // USE_HW_AES
|
||||
|
||||
#endif // MY_CPU_ARM_OR_ARM64
|
||||
|
@ -1,57 +1,34 @@
|
||||
/* LzHash.h -- HASH functions for LZ algorithms
|
||||
2015-04-12 : Igor Pavlov : Public domain */
|
||||
2019-10-30 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZ_HASH_H
|
||||
#define __LZ_HASH_H
|
||||
|
||||
/*
|
||||
(kHash2Size >= (1 << 8)) : Required
|
||||
(kHash3Size >= (1 << 16)) : Required
|
||||
*/
|
||||
|
||||
#define kHash2Size (1 << 10)
|
||||
#define kHash3Size (1 << 16)
|
||||
#define kHash4Size (1 << 20)
|
||||
// #define kHash4Size (1 << 20)
|
||||
|
||||
#define kFix3HashSize (kHash2Size)
|
||||
#define kFix4HashSize (kHash2Size + kHash3Size)
|
||||
#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
|
||||
|
||||
#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);
|
||||
|
||||
#define HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
h2 = temp & (kHash2Size - 1); \
|
||||
hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
|
||||
|
||||
#define HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
h2 = temp & (kHash2Size - 1); \
|
||||
temp ^= ((UInt32)cur[2] << 8); \
|
||||
h3 = temp & (kHash3Size - 1); \
|
||||
hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
|
||||
|
||||
#define HASH5_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
h2 = temp & (kHash2Size - 1); \
|
||||
temp ^= ((UInt32)cur[2] << 8); \
|
||||
h3 = temp & (kHash3Size - 1); \
|
||||
temp ^= (p->crc[cur[3]] << 5); \
|
||||
h4 = temp & (kHash4Size - 1); \
|
||||
hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }
|
||||
|
||||
/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
|
||||
#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
|
||||
|
||||
|
||||
#define MT_HASH2_CALC \
|
||||
h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
|
||||
|
||||
#define MT_HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
h2 = temp & (kHash2Size - 1); \
|
||||
h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
|
||||
|
||||
#define MT_HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
h2 = temp & (kHash2Size - 1); \
|
||||
temp ^= ((UInt32)cur[2] << 8); \
|
||||
h3 = temp & (kHash3Size - 1); \
|
||||
h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
|
||||
// #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
|
||||
|
||||
/*
|
||||
We use up to 3 crc values for hash:
|
||||
crc0
|
||||
crc1 << Shift_1
|
||||
crc2 << Shift_2
|
||||
(Shift_1 = 5) and (Shift_2 = 10) is good tradeoff.
|
||||
Small values for Shift are not good for collision rate.
|
||||
Big value for Shift_2 increases the minimum size
|
||||
of hash table, that will be slow for small files.
|
||||
*/
|
||||
|
||||
#define kLzHash_CrcShift_1 5
|
||||
#define kLzHash_CrcShift_2 10
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,26 +1,76 @@
|
||||
/* Sha256.h -- SHA-256 Hash
|
||||
2013-01-18 : Igor Pavlov : Public domain */
|
||||
2021-01-01 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __CRYPTO_SHA256_H
|
||||
#define __CRYPTO_SHA256_H
|
||||
#ifndef __7Z_SHA256_H
|
||||
#define __7Z_SHA256_H
|
||||
|
||||
#include "7zTypes.h"
|
||||
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
#define SHA256_DIGEST_SIZE 32
|
||||
#define SHA256_NUM_BLOCK_WORDS 16
|
||||
#define SHA256_NUM_DIGEST_WORDS 8
|
||||
|
||||
#define SHA256_BLOCK_SIZE (SHA256_NUM_BLOCK_WORDS * 4)
|
||||
#define SHA256_DIGEST_SIZE (SHA256_NUM_DIGEST_WORDS * 4)
|
||||
|
||||
typedef void (MY_FAST_CALL *SHA256_FUNC_UPDATE_BLOCKS)(UInt32 state[8], const Byte *data, size_t numBlocks);
|
||||
|
||||
/*
|
||||
if (the system supports different SHA256 code implementations)
|
||||
{
|
||||
(CSha256::func_UpdateBlocks) will be used
|
||||
(CSha256::func_UpdateBlocks) can be set by
|
||||
Sha256_Init() - to default (fastest)
|
||||
Sha256_SetFunction() - to any algo
|
||||
}
|
||||
else
|
||||
{
|
||||
(CSha256::func_UpdateBlocks) is ignored.
|
||||
}
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UInt32 state[8];
|
||||
SHA256_FUNC_UPDATE_BLOCKS func_UpdateBlocks;
|
||||
UInt64 count;
|
||||
Byte buffer[64];
|
||||
UInt64 __pad_2[2];
|
||||
UInt32 state[SHA256_NUM_DIGEST_WORDS];
|
||||
|
||||
Byte buffer[SHA256_BLOCK_SIZE];
|
||||
} CSha256;
|
||||
|
||||
|
||||
#define SHA256_ALGO_DEFAULT 0
|
||||
#define SHA256_ALGO_SW 1
|
||||
#define SHA256_ALGO_HW 2
|
||||
|
||||
/*
|
||||
Sha256_SetFunction()
|
||||
return:
|
||||
0 - (algo) value is not supported, and func_UpdateBlocks was not changed
|
||||
1 - func_UpdateBlocks was set according (algo) value.
|
||||
*/
|
||||
|
||||
BoolInt Sha256_SetFunction(CSha256 *p, unsigned algo);
|
||||
|
||||
void Sha256_InitState(CSha256 *p);
|
||||
void Sha256_Init(CSha256 *p);
|
||||
void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
|
||||
void Sha256_Final(CSha256 *p, Byte *digest);
|
||||
|
||||
|
||||
|
||||
|
||||
// void MY_FAST_CALL Sha256_UpdateBlocks(UInt32 state[8], const Byte *data, size_t numBlocks);
|
||||
|
||||
/*
|
||||
call Sha256Prepare() once at program start.
|
||||
It prepares all supported implementations, and detects the fastest implementation.
|
||||
*/
|
||||
|
||||
void Sha256Prepare(void);
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,373 @@
|
||||
/* Sha256Opt.c -- SHA-256 optimized code for SHA-256 hardware instructions
|
||||
2021-04-01 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if (_MSC_VER < 1900) && (_MSC_VER >= 1200)
|
||||
// #define USE_MY_MM
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "CpuArch.h"
|
||||
|
||||
#ifdef MY_CPU_X86_OR_AMD64
|
||||
#if defined(__clang__)
|
||||
#if (__clang_major__ >= 8) // fix that check
|
||||
#define USE_HW_SHA
|
||||
#ifndef __SHA__
|
||||
#define ATTRIB_SHA __attribute__((__target__("sha,ssse3")))
|
||||
#if defined(_MSC_VER)
|
||||
// SSSE3: for clang-cl:
|
||||
#include <tmmintrin.h>
|
||||
#define __SHA__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#if (__GNUC__ >= 8) // fix that check
|
||||
#define USE_HW_SHA
|
||||
#ifndef __SHA__
|
||||
#define ATTRIB_SHA __attribute__((__target__("sha,ssse3")))
|
||||
// #pragma GCC target("sha,ssse3")
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
#if (__INTEL_COMPILER >= 1800) // fix that check
|
||||
#define USE_HW_SHA
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#ifdef USE_MY_MM
|
||||
#define USE_VER_MIN 1300
|
||||
#else
|
||||
#define USE_VER_MIN 1910
|
||||
#endif
|
||||
#if _MSC_VER >= USE_VER_MIN
|
||||
#define USE_HW_SHA
|
||||
#endif
|
||||
#endif
|
||||
// #endif // MY_CPU_X86_OR_AMD64
|
||||
|
||||
#ifdef USE_HW_SHA
|
||||
|
||||
// #pragma message("Sha256 HW")
|
||||
// #include <wmmintrin.h>
|
||||
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||
#include <immintrin.h>
|
||||
#else
|
||||
#include <emmintrin.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
||||
// #include <intrin.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_MY_MM
|
||||
#include "My_mm.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
SHA256 uses:
|
||||
SSE2:
|
||||
_mm_loadu_si128
|
||||
_mm_storeu_si128
|
||||
_mm_set_epi32
|
||||
_mm_add_epi32
|
||||
_mm_shuffle_epi32 / pshufd
|
||||
|
||||
|
||||
|
||||
SSSE3:
|
||||
_mm_shuffle_epi8 / pshufb
|
||||
_mm_alignr_epi8
|
||||
SHA:
|
||||
_mm_sha256*
|
||||
*/
|
||||
|
||||
// K array must be aligned for 16-bytes at least.
|
||||
// The compiler can look align attribute and selects
|
||||
// movdqu - for code without align attribute
|
||||
// movdqa - for code with align attribute
|
||||
extern
|
||||
MY_ALIGN(64)
|
||||
const UInt32 SHA256_K_ARRAY[64];
|
||||
|
||||
#define K SHA256_K_ARRAY
|
||||
|
||||
|
||||
#define ADD_EPI32(dest, src) dest = _mm_add_epi32(dest, src);
|
||||
#define SHA256_MSG1(dest, src) dest = _mm_sha256msg1_epu32(dest, src);
|
||||
#define SHA25G_MSG2(dest, src) dest = _mm_sha256msg2_epu32(dest, src);
|
||||
|
||||
|
||||
#define LOAD_SHUFFLE(m, k) \
|
||||
m = _mm_loadu_si128((const __m128i *)(const void *)(data + (k) * 16)); \
|
||||
m = _mm_shuffle_epi8(m, mask); \
|
||||
|
||||
#define SM1(g0, g1, g2, g3) \
|
||||
SHA256_MSG1(g3, g0); \
|
||||
|
||||
#define SM2(g0, g1, g2, g3) \
|
||||
tmp = _mm_alignr_epi8(g1, g0, 4); \
|
||||
ADD_EPI32(g2, tmp); \
|
||||
SHA25G_MSG2(g2, g1); \
|
||||
|
||||
// #define LS0(k, g0, g1, g2, g3) LOAD_SHUFFLE(g0, k)
|
||||
// #define LS1(k, g0, g1, g2, g3) LOAD_SHUFFLE(g1, k+1)
|
||||
|
||||
|
||||
#define NNN(g0, g1, g2, g3)
|
||||
|
||||
|
||||
#define RND2(t0, t1) \
|
||||
t0 = _mm_sha256rnds2_epu32(t0, t1, msg);
|
||||
|
||||
#define RND2_0(m, k) \
|
||||
msg = _mm_add_epi32(m, *(const __m128i *) (const void *) &K[(k) * 4]); \
|
||||
RND2(state0, state1); \
|
||||
msg = _mm_shuffle_epi32(msg, 0x0E); \
|
||||
|
||||
|
||||
#define RND2_1 \
|
||||
RND2(state1, state0); \
|
||||
|
||||
|
||||
// We use scheme with 3 rounds ahead for SHA256_MSG1 / 2 rounds ahead for SHA256_MSG2
|
||||
|
||||
#define R4(k, g0, g1, g2, g3, OP0, OP1) \
|
||||
RND2_0(g0, k); \
|
||||
OP0(g0, g1, g2, g3); \
|
||||
RND2_1; \
|
||||
OP1(g0, g1, g2, g3); \
|
||||
|
||||
#define R16(k, OP0, OP1, OP2, OP3, OP4, OP5, OP6, OP7) \
|
||||
R4 ( (k)*4+0, m0, m1, m2, m3, OP0, OP1 ) \
|
||||
R4 ( (k)*4+1, m1, m2, m3, m0, OP2, OP3 ) \
|
||||
R4 ( (k)*4+2, m2, m3, m0, m1, OP4, OP5 ) \
|
||||
R4 ( (k)*4+3, m3, m0, m1, m2, OP6, OP7 ) \
|
||||
|
||||
#define PREPARE_STATE \
|
||||
tmp = _mm_shuffle_epi32(state0, 0x1B); /* abcd */ \
|
||||
state0 = _mm_shuffle_epi32(state1, 0x1B); /* efgh */ \
|
||||
state1 = state0; \
|
||||
state0 = _mm_unpacklo_epi64(state0, tmp); /* cdgh */ \
|
||||
state1 = _mm_unpackhi_epi64(state1, tmp); /* abef */ \
|
||||
|
||||
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[8], const Byte *data, size_t numBlocks);
|
||||
#ifdef ATTRIB_SHA
|
||||
ATTRIB_SHA
|
||||
#endif
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[8], const Byte *data, size_t numBlocks)
|
||||
{
|
||||
const __m128i mask = _mm_set_epi32(0x0c0d0e0f, 0x08090a0b, 0x04050607, 0x00010203);
|
||||
__m128i tmp;
|
||||
__m128i state0, state1;
|
||||
|
||||
if (numBlocks == 0)
|
||||
return;
|
||||
|
||||
state0 = _mm_loadu_si128((const __m128i *) (const void *) &state[0]);
|
||||
state1 = _mm_loadu_si128((const __m128i *) (const void *) &state[4]);
|
||||
|
||||
PREPARE_STATE
|
||||
|
||||
do
|
||||
{
|
||||
__m128i state0_save, state1_save;
|
||||
__m128i m0, m1, m2, m3;
|
||||
__m128i msg;
|
||||
// #define msg tmp
|
||||
|
||||
state0_save = state0;
|
||||
state1_save = state1;
|
||||
|
||||
LOAD_SHUFFLE (m0, 0)
|
||||
LOAD_SHUFFLE (m1, 1)
|
||||
LOAD_SHUFFLE (m2, 2)
|
||||
LOAD_SHUFFLE (m3, 3)
|
||||
|
||||
|
||||
|
||||
R16 ( 0, NNN, NNN, SM1, NNN, SM1, SM2, SM1, SM2 );
|
||||
R16 ( 1, SM1, SM2, SM1, SM2, SM1, SM2, SM1, SM2 );
|
||||
R16 ( 2, SM1, SM2, SM1, SM2, SM1, SM2, SM1, SM2 );
|
||||
R16 ( 3, SM1, SM2, NNN, SM2, NNN, NNN, NNN, NNN );
|
||||
|
||||
ADD_EPI32(state0, state0_save);
|
||||
ADD_EPI32(state1, state1_save);
|
||||
|
||||
data += 64;
|
||||
}
|
||||
while (--numBlocks);
|
||||
|
||||
PREPARE_STATE
|
||||
|
||||
_mm_storeu_si128((__m128i *) (void *) &state[0], state0);
|
||||
_mm_storeu_si128((__m128i *) (void *) &state[4], state1);
|
||||
}
|
||||
|
||||
#endif // USE_HW_SHA
|
||||
|
||||
#elif defined(MY_CPU_ARM_OR_ARM64)
|
||||
|
||||
#if defined(__clang__)
|
||||
#if (__clang_major__ >= 8) // fix that check
|
||||
#define USE_HW_SHA
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#if (__GNUC__ >= 6) // fix that check
|
||||
#define USE_HW_SHA
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#if _MSC_VER >= 1910
|
||||
#define USE_HW_SHA
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_HW_SHA
|
||||
|
||||
// #pragma message("=== Sha256 HW === ")
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#ifdef MY_CPU_ARM64
|
||||
#define ATTRIB_SHA __attribute__((__target__("+crypto")))
|
||||
#else
|
||||
#define ATTRIB_SHA __attribute__((__target__("fpu=crypto-neon-fp-armv8")))
|
||||
#endif
|
||||
#else
|
||||
// _MSC_VER
|
||||
// for arm32
|
||||
#define _ARM_USE_NEW_NEON_INTRINSICS
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(MY_CPU_ARM64)
|
||||
#include <arm64_neon.h>
|
||||
#else
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
typedef uint32x4_t v128;
|
||||
// typedef __n128 v128; // MSVC
|
||||
|
||||
#ifdef MY_CPU_BE
|
||||
#define MY_rev32_for_LE(x)
|
||||
#else
|
||||
#define MY_rev32_for_LE(x) x = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(x)))
|
||||
#endif
|
||||
|
||||
#define LOAD_128(_p) (*(const v128 *)(const void *)(_p))
|
||||
#define STORE_128(_p, _v) *(v128 *)(void *)(_p) = (_v)
|
||||
|
||||
#define LOAD_SHUFFLE(m, k) \
|
||||
m = LOAD_128((data + (k) * 16)); \
|
||||
MY_rev32_for_LE(m); \
|
||||
|
||||
// K array must be aligned for 16-bytes at least.
|
||||
extern
|
||||
MY_ALIGN(64)
|
||||
const UInt32 SHA256_K_ARRAY[64];
|
||||
|
||||
#define K SHA256_K_ARRAY
|
||||
|
||||
|
||||
#define SHA256_SU0(dest, src) dest = vsha256su0q_u32(dest, src);
|
||||
#define SHA25G_SU1(dest, src2, src3) dest = vsha256su1q_u32(dest, src2, src3);
|
||||
|
||||
#define SM1(g0, g1, g2, g3) SHA256_SU0(g3, g0)
|
||||
#define SM2(g0, g1, g2, g3) SHA25G_SU1(g2, g0, g1)
|
||||
#define NNN(g0, g1, g2, g3)
|
||||
|
||||
|
||||
#define R4(k, g0, g1, g2, g3, OP0, OP1) \
|
||||
msg = vaddq_u32(g0, *(const v128 *) (const void *) &K[(k) * 4]); \
|
||||
tmp = state0; \
|
||||
state0 = vsha256hq_u32( state0, state1, msg ); \
|
||||
state1 = vsha256h2q_u32( state1, tmp, msg ); \
|
||||
OP0(g0, g1, g2, g3); \
|
||||
OP1(g0, g1, g2, g3); \
|
||||
|
||||
|
||||
#define R16(k, OP0, OP1, OP2, OP3, OP4, OP5, OP6, OP7) \
|
||||
R4 ( (k)*4+0, m0, m1, m2, m3, OP0, OP1 ) \
|
||||
R4 ( (k)*4+1, m1, m2, m3, m0, OP2, OP3 ) \
|
||||
R4 ( (k)*4+2, m2, m3, m0, m1, OP4, OP5 ) \
|
||||
R4 ( (k)*4+3, m3, m0, m1, m2, OP6, OP7 ) \
|
||||
|
||||
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[8], const Byte *data, size_t numBlocks);
|
||||
#ifdef ATTRIB_SHA
|
||||
ATTRIB_SHA
|
||||
#endif
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[8], const Byte *data, size_t numBlocks)
|
||||
{
|
||||
v128 state0, state1;
|
||||
|
||||
if (numBlocks == 0)
|
||||
return;
|
||||
|
||||
state0 = LOAD_128(&state[0]);
|
||||
state1 = LOAD_128(&state[4]);
|
||||
|
||||
do
|
||||
{
|
||||
v128 state0_save, state1_save;
|
||||
v128 m0, m1, m2, m3;
|
||||
v128 msg, tmp;
|
||||
|
||||
state0_save = state0;
|
||||
state1_save = state1;
|
||||
|
||||
LOAD_SHUFFLE (m0, 0)
|
||||
LOAD_SHUFFLE (m1, 1)
|
||||
LOAD_SHUFFLE (m2, 2)
|
||||
LOAD_SHUFFLE (m3, 3)
|
||||
|
||||
R16 ( 0, NNN, NNN, SM1, NNN, SM1, SM2, SM1, SM2 );
|
||||
R16 ( 1, SM1, SM2, SM1, SM2, SM1, SM2, SM1, SM2 );
|
||||
R16 ( 2, SM1, SM2, SM1, SM2, SM1, SM2, SM1, SM2 );
|
||||
R16 ( 3, SM1, SM2, NNN, SM2, NNN, NNN, NNN, NNN );
|
||||
|
||||
state0 = vaddq_u32(state0, state0_save);
|
||||
state1 = vaddq_u32(state1, state1_save);
|
||||
|
||||
data += 64;
|
||||
}
|
||||
while (--numBlocks);
|
||||
|
||||
STORE_128(&state[0], state0);
|
||||
STORE_128(&state[4], state1);
|
||||
}
|
||||
|
||||
#endif // USE_HW_SHA
|
||||
|
||||
#endif // MY_CPU_ARM_OR_ARM64
|
||||
|
||||
|
||||
#ifndef USE_HW_SHA
|
||||
|
||||
// #error Stop_Compiling_UNSUPPORTED_SHA
|
||||
// #include <stdlib.h>
|
||||
|
||||
// #include "Sha256.h"
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks(UInt32 state[8], const Byte *data, size_t numBlocks);
|
||||
|
||||
#pragma message("Sha256 HW-SW stub was used")
|
||||
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[8], const Byte *data, size_t numBlocks);
|
||||
void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[8], const Byte *data, size_t numBlocks)
|
||||
{
|
||||
Sha256_UpdateBlocks(state, data, numBlocks);
|
||||
/*
|
||||
UNUSED_VAR(state);
|
||||
UNUSED_VAR(data);
|
||||
UNUSED_VAR(numBlocks);
|
||||
exit(1);
|
||||
return;
|
||||
*/
|
||||
}
|
||||
|
||||
#endif
|
@ -1,75 +1,34 @@
|
||||
PROG = 7zDec
|
||||
CXX = gcc
|
||||
LIB =
|
||||
RM = rm -f
|
||||
CFLAGS = -c -O2 -Wall
|
||||
|
||||
OBJS = 7zMain.o 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o CpuArch.o Delta.o LzmaDec.o Lzma2Dec.o Bra.o Bra86.o BraIA64.o Bcj2.o Ppmd7.o Ppmd7Dec.o 7zFile.o 7zStream.o
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)
|
||||
|
||||
7zMain.o: 7zMain.c
|
||||
$(CXX) $(CFLAGS) 7zMain.c
|
||||
|
||||
7zAlloc.o: ../../7zAlloc.c
|
||||
$(CXX) $(CFLAGS) ../../7zAlloc.c
|
||||
|
||||
7zArcIn.o: ../../7zArcIn.c
|
||||
$(CXX) $(CFLAGS) ../../7zArcIn.c
|
||||
|
||||
7zBuf.o: ../../7zBuf.c
|
||||
$(CXX) $(CFLAGS) ../../7zBuf.c
|
||||
|
||||
7zBuf2.o: ../../7zBuf2.c
|
||||
$(CXX) $(CFLAGS) ../../7zBuf2.c
|
||||
|
||||
7zCrc.o: ../../7zCrc.c
|
||||
$(CXX) $(CFLAGS) ../../7zCrc.c
|
||||
|
||||
7zCrcOpt.o: ../../7zCrc.c
|
||||
$(CXX) $(CFLAGS) ../../7zCrcOpt.c
|
||||
|
||||
7zDec.o: ../../7zDec.c
|
||||
$(CXX) $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT ../../7zDec.c
|
||||
|
||||
CpuArch.o: ../../CpuArch.c
|
||||
$(CXX) $(CFLAGS) ../../CpuArch.c
|
||||
|
||||
Delta.o: ../../Delta.c
|
||||
$(CXX) $(CFLAGS) ../../Delta.c
|
||||
|
||||
LzmaDec.o: ../../LzmaDec.c
|
||||
$(CXX) $(CFLAGS) ../../LzmaDec.c
|
||||
|
||||
Lzma2Dec.o: ../../Lzma2Dec.c
|
||||
$(CXX) $(CFLAGS) ../../Lzma2Dec.c
|
||||
|
||||
Bra.o: ../../Bra.c
|
||||
$(CXX) $(CFLAGS) ../../Bra.c
|
||||
|
||||
Bra86.o: ../../Bra86.c
|
||||
$(CXX) $(CFLAGS) ../../Bra86.c
|
||||
|
||||
BraIA64.o: ../../BraIA64.c
|
||||
$(CXX) $(CFLAGS) ../../BraIA64.c
|
||||
|
||||
Bcj2.o: ../../Bcj2.c
|
||||
$(CXX) $(CFLAGS) ../../Bcj2.c
|
||||
|
||||
Ppmd7.o: ../../Ppmd7.c
|
||||
$(CXX) $(CFLAGS) ../../Ppmd7.c
|
||||
|
||||
Ppmd7Dec.o: ../../Ppmd7Dec.c
|
||||
$(CXX) $(CFLAGS) ../../Ppmd7Dec.c
|
||||
|
||||
7zFile.o: ../../7zFile.c
|
||||
$(CXX) $(CFLAGS) ../../7zFile.c
|
||||
|
||||
7zStream.o: ../../7zStream.c
|
||||
$(CXX) $(CFLAGS) ../../7zStream.c
|
||||
|
||||
clean:
|
||||
-$(RM) $(PROG) $(OBJS)
|
||||
PROG = 7zdec
|
||||
|
||||
LOCAL_FLAGS = -D_7ZIP_PPMD_SUPPPORT
|
||||
|
||||
include ../../../CPP/7zip/LzmaDec_gcc.mak
|
||||
|
||||
|
||||
OBJS = \
|
||||
$(LZMA_DEC_OPT_OBJS) \
|
||||
$O/Bcj2.o \
|
||||
$O/Bra.o \
|
||||
$O/Bra86.o \
|
||||
$O/BraIA64.o \
|
||||
$O/CpuArch.o \
|
||||
$O/Delta.o \
|
||||
$O/Lzma2Dec.o \
|
||||
$O/LzmaDec.o \
|
||||
$O/Ppmd7.o \
|
||||
$O/Ppmd7Dec.o \
|
||||
$O/7zCrc.o \
|
||||
$O/7zCrcOpt.o \
|
||||
$O/Sha256.o \
|
||||
$O/Sha256Opt.o \
|
||||
$O/7zAlloc.o \
|
||||
$O/7zArcIn.o \
|
||||
$O/7zBuf.o \
|
||||
$O/7zBuf2.o \
|
||||
$O/7zDec.o \
|
||||
$O/7zMain.o \
|
||||
$O/7zFile.o \
|
||||
$O/7zStream.o \
|
||||
|
||||
|
||||
include ../../7zip_gcc_c.mak
|
||||
|
@ -1,44 +1,19 @@
|
||||
PROG = lzma
|
||||
CXX = g++
|
||||
LIB =
|
||||
RM = rm -f
|
||||
CFLAGS = -c -O2 -Wall -D_7ZIP_ST
|
||||
PROG = 7lzma
|
||||
|
||||
OBJS = \
|
||||
LzmaUtil.o \
|
||||
Alloc.o \
|
||||
LzFind.o \
|
||||
LzmaDec.o \
|
||||
LzmaEnc.o \
|
||||
7zFile.o \
|
||||
7zStream.o \
|
||||
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)
|
||||
|
||||
LzmaUtil.o: LzmaUtil.c
|
||||
$(CXX) $(CFLAGS) LzmaUtil.c
|
||||
|
||||
Alloc.o: ../../Alloc.c
|
||||
$(CXX) $(CFLAGS) ../../Alloc.c
|
||||
include ../../../CPP/7zip/LzmaDec_gcc.mak
|
||||
|
||||
LzFind.o: ../../LzFind.c
|
||||
$(CXX) $(CFLAGS) ../../LzFind.c
|
||||
|
||||
LzmaDec.o: ../../LzmaDec.c
|
||||
$(CXX) $(CFLAGS) ../../LzmaDec.c
|
||||
|
||||
LzmaEnc.o: ../../LzmaEnc.c
|
||||
$(CXX) $(CFLAGS) ../../LzmaEnc.c
|
||||
|
||||
7zFile.o: ../../7zFile.c
|
||||
$(CXX) $(CFLAGS) ../../7zFile.c
|
||||
|
||||
7zStream.o: ../../7zStream.c
|
||||
$(CXX) $(CFLAGS) ../../7zStream.c
|
||||
|
||||
clean:
|
||||
-$(RM) $(PROG) $(OBJS)
|
||||
OBJS = \
|
||||
$(LZMA_DEC_OPT_OBJS) \
|
||||
$O/7zFile.o \
|
||||
$O/7zStream.o \
|
||||
$O/Alloc.o \
|
||||
$O/LzFind.o \
|
||||
$O/LzFindMt.o \
|
||||
$O/LzmaDec.o \
|
||||
$O/LzmaEnc.o \
|
||||
$O/LzmaUtil.o \
|
||||
$O/Threads.o \
|
||||
|
||||
|
||||
include ../../7zip_gcc_c.mak
|
||||
|
@ -0,0 +1,11 @@
|
||||
PLATFORM=
|
||||
O=b/c
|
||||
IS_X64=
|
||||
IS_X86=
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=
|
||||
USE_ASM=
|
||||
CC=$(CROSS_COMPILE)clang
|
||||
CXX=$(CROSS_COMPILE)clang++
|
||||
USE_CLANG=1
|
@ -0,0 +1,11 @@
|
||||
PLATFORM=arm64
|
||||
O=b/c_$(PLATFORM)
|
||||
IS_X64=
|
||||
IS_X86=
|
||||
IS_ARM64=1
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)clang
|
||||
CXX=$(CROSS_COMPILE)clang++
|
||||
USE_CLANG=1
|
@ -0,0 +1,12 @@
|
||||
PLATFORM=x64
|
||||
O=b/c_$(PLATFORM)
|
||||
IS_X64=1
|
||||
IS_X86=
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)clang
|
||||
CXX=$(CROSS_COMPILE)clang++
|
||||
USE_CLANG=1
|
||||
|
@ -0,0 +1,12 @@
|
||||
PLATFORM=x86
|
||||
O=b/c_$(PLATFORM)
|
||||
IS_X64=
|
||||
IS_X86=1
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=-m32
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)clang
|
||||
CXX=$(CROSS_COMPILE)clang++
|
||||
USE_CLANG=1
|
||||
|
@ -0,0 +1,12 @@
|
||||
PLATFORM=
|
||||
O=b/g
|
||||
IS_X64=
|
||||
IS_X86=
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=
|
||||
USE_ASM=
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
CXX=$(CROSS_COMPILE)g++
|
||||
|
||||
# -march=armv8-a+crc+crypto
|
@ -0,0 +1,12 @@
|
||||
PLATFORM=arm64
|
||||
O=b/g_$(PLATFORM)
|
||||
IS_X64=
|
||||
IS_X86=
|
||||
IS_ARM64=1
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=-mtune=cortex-a53
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
CXX=$(CROSS_COMPILE)g++
|
||||
|
||||
# -march=armv8-a+crc+crypto
|
@ -0,0 +1,10 @@
|
||||
PLATFORM=x64
|
||||
O=b/g_$(PLATFORM)
|
||||
IS_X64=1
|
||||
IS_X86=
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
CXX=$(CROSS_COMPILE)g++
|
@ -0,0 +1,11 @@
|
||||
PLATFORM=x86
|
||||
O=b/g_$(PLATFORM)
|
||||
IS_X64=
|
||||
IS_X86=1
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=-m32
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
CXX=$(CROSS_COMPILE)g++
|
||||
|
@ -0,0 +1,11 @@
|
||||
PLATFORM=arm64
|
||||
O=b/m_$(PLATFORM)
|
||||
IS_X64=
|
||||
IS_X86=
|
||||
IS_ARM64=1
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=-arch arm64
|
||||
USE_ASM=1
|
||||
CC=$(CROSS_COMPILE)clang
|
||||
CXX=$(CROSS_COMPILE)clang++
|
||||
USE_CLANG=1
|
@ -0,0 +1,11 @@
|
||||
PLATFORM=x64
|
||||
O=b/m_$(PLATFORM)
|
||||
IS_X64=1
|
||||
IS_X86=
|
||||
IS_ARM64=
|
||||
CROSS_COMPILE=
|
||||
MY_ARCH=-arch x86_64
|
||||
USE_ASM=
|
||||
CC=$(CROSS_COMPILE)clang
|
||||
CXX=$(CROSS_COMPILE)clang++
|
||||
USE_CLANG=1
|
@ -0,0 +1,37 @@
|
||||
CFLAGS_WARN_CLANG_3_8_UNIQ = \
|
||||
-Wno-reserved-id-macro \
|
||||
-Wno-old-style-cast \
|
||||
-Wno-c++11-long-long \
|
||||
-Wno-unused-macros \
|
||||
|
||||
CFLAGS_WARN_CLANG_3_8 = \
|
||||
$(CFLAGS_WARN_CLANG_3_8_UNIQ) \
|
||||
-Weverything \
|
||||
-Wno-extra-semi \
|
||||
-Wno-sign-conversion \
|
||||
-Wno-language-extension-token \
|
||||
-Wno-global-constructors \
|
||||
-Wno-non-virtual-dtor \
|
||||
-Wno-switch-enum \
|
||||
-Wno-covered-switch-default \
|
||||
-Wno-cast-qual \
|
||||
-Wno-padded \
|
||||
-Wno-exit-time-destructors \
|
||||
-Wno-weak-vtables \
|
||||
|
||||
CFLAGS_WARN_CLANG_12= $(CFLAGS_WARN_CLANG_3_8) \
|
||||
-Wno-extra-semi-stmt \
|
||||
-Wno-zero-as-null-pointer-constant \
|
||||
-Wno-deprecated-dynamic-exception-spec \
|
||||
-Wno-c++98-compat-pedantic \
|
||||
-Wno-atomic-implicit-seq-cst \
|
||||
-Wconversion \
|
||||
-Wno-sign-conversion \
|
||||
|
||||
CFLAGS_WARN_1 = \
|
||||
-Wno-deprecated-copy-dtor \
|
||||
|
||||
|
||||
|
||||
|
||||
CFLAGS_WARN = $(CFLAGS_WARN_CLANG_12) $(CFLAGS_WARN_1)
|
@ -0,0 +1,37 @@
|
||||
CFLAGS_WARN_CLANG_3_8_UNIQ = \
|
||||
-Wno-reserved-id-macro \
|
||||
-Wno-old-style-cast \
|
||||
-Wno-c++11-long-long \
|
||||
-Wno-unused-macros \
|
||||
|
||||
CFLAGS_WARN_CLANG_3_8 = \
|
||||
$(CFLAGS_WARN_CLANG_3_8_UNIQ) \
|
||||
-Weverything \
|
||||
-Wno-extra-semi \
|
||||
-Wno-sign-conversion \
|
||||
-Wno-language-extension-token \
|
||||
-Wno-global-constructors \
|
||||
-Wno-non-virtual-dtor \
|
||||
-Wno-switch-enum \
|
||||
-Wno-covered-switch-default \
|
||||
-Wno-cast-qual \
|
||||
-Wno-padded \
|
||||
-Wno-exit-time-destructors \
|
||||
-Wno-weak-vtables \
|
||||
|
||||
CFLAGS_WARN_CLANG_12= $(CFLAGS_WARN_CLANG_3_8) \
|
||||
-Wno-extra-semi-stmt \
|
||||
-Wno-zero-as-null-pointer-constant \
|
||||
-Wno-deprecated-dynamic-exception-spec \
|
||||
-Wno-c++98-compat-pedantic \
|
||||
-Wno-atomic-implicit-seq-cst \
|
||||
-Wconversion \
|
||||
-Wno-sign-conversion \
|
||||
|
||||
CFLAGS_WARN_MAC = \
|
||||
-Wno-poison-system-directories \
|
||||
-Wno-c++11-long-long \
|
||||
-Wno-atomic-implicit-seq-cst \
|
||||
|
||||
|
||||
CFLAGS_WARN = $(CFLAGS_WARN_CLANG_12) $(CFLAGS_WARN_MAC)
|
@ -0,0 +1,53 @@
|
||||
CFLAGS_WARN_GCC_4_5 = \
|
||||
|
||||
CFLAGS_WARN_GCC_6 = \
|
||||
-Waddress \
|
||||
-Waggressive-loop-optimizations \
|
||||
-Wattributes \
|
||||
-Wbool-compare \
|
||||
-Wcast-align \
|
||||
-Wcomment \
|
||||
-Wdiv-by-zero \
|
||||
-Wduplicated-cond \
|
||||
-Wformat-contains-nul \
|
||||
-Winit-self \
|
||||
-Wint-to-pointer-cast \
|
||||
-Wunused \
|
||||
-Wunused-macros \
|
||||
|
||||
# -Wno-strict-aliasing
|
||||
|
||||
CFLAGS_WARN_GCC_9 = \
|
||||
-Waddress \
|
||||
-Waddress-of-packed-member \
|
||||
-Waggressive-loop-optimizations \
|
||||
-Wattributes \
|
||||
-Wbool-compare \
|
||||
-Wbool-operation \
|
||||
-Wcast-align \
|
||||
-Wcast-align=strict \
|
||||
-Wcomment \
|
||||
-Wdangling-else \
|
||||
-Wdiv-by-zero \
|
||||
-Wduplicated-branches \
|
||||
-Wduplicated-cond \
|
||||
-Wformat-contains-nul \
|
||||
-Wimplicit-fallthrough=5 \
|
||||
-Winit-self \
|
||||
-Wint-in-bool-context \
|
||||
-Wint-to-pointer-cast \
|
||||
-Wunused \
|
||||
-Wunused-macros \
|
||||
-Wconversion \
|
||||
|
||||
# -Wno-sign-conversion \
|
||||
|
||||
CFLAGS_WARN_GCC_PPMD_UNALIGNED = \
|
||||
-Wno-strict-aliasing \
|
||||
|
||||
|
||||
CFLAGS_WARN = $(CFLAGS_WARN_GCC_9) \
|
||||
|
||||
# $(CFLAGS_WARN_GCC_PPMD_UNALIGNED)
|
||||
|
||||
|
@ -0,0 +1,469 @@
|
||||
7z Format description (18.06)
|
||||
----------------------------
|
||||
|
||||
This file contains description of 7z archive format.
|
||||
7z archive can contain files compressed with any method.
|
||||
See "Methods.txt" for description for defined compressing methods.
|
||||
|
||||
|
||||
Format structure Overview
|
||||
-------------------------
|
||||
|
||||
Some fields can be optional.
|
||||
|
||||
Archive structure
|
||||
~~~~~~~~~~~~~~~~~
|
||||
SignatureHeader
|
||||
[PackedStreams]
|
||||
[PackedStreamsForHeaders]
|
||||
[
|
||||
Header
|
||||
or
|
||||
{
|
||||
Packed Header
|
||||
HeaderInfo
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
Header structure
|
||||
~~~~~~~~~~~~~~~~
|
||||
{
|
||||
ArchiveProperties
|
||||
AdditionalStreams
|
||||
{
|
||||
PackInfo
|
||||
{
|
||||
PackPos
|
||||
NumPackStreams
|
||||
Sizes[NumPackStreams]
|
||||
CRCs[NumPackStreams]
|
||||
}
|
||||
CodersInfo
|
||||
{
|
||||
NumFolders
|
||||
Folders[NumFolders]
|
||||
{
|
||||
NumCoders
|
||||
CodersInfo[NumCoders]
|
||||
{
|
||||
ID
|
||||
NumInStreams;
|
||||
NumOutStreams;
|
||||
PropertiesSize
|
||||
Properties[PropertiesSize]
|
||||
}
|
||||
NumBindPairs
|
||||
BindPairsInfo[NumBindPairs]
|
||||
{
|
||||
InIndex;
|
||||
OutIndex;
|
||||
}
|
||||
PackedIndices
|
||||
}
|
||||
UnPackSize[Folders][Folders.NumOutstreams]
|
||||
CRCs[NumFolders]
|
||||
}
|
||||
SubStreamsInfo
|
||||
{
|
||||
NumUnPackStreamsInFolders[NumFolders];
|
||||
UnPackSizes[]
|
||||
CRCs[]
|
||||
}
|
||||
}
|
||||
MainStreamsInfo
|
||||
{
|
||||
(Same as in AdditionalStreams)
|
||||
}
|
||||
FilesInfo
|
||||
{
|
||||
NumFiles
|
||||
Properties[]
|
||||
{
|
||||
ID
|
||||
Size
|
||||
Data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HeaderInfo structure
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
(Same as in AdditionalStreams)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Notes about Notation and encoding
|
||||
---------------------------------
|
||||
|
||||
7z uses little endian encoding.
|
||||
|
||||
7z archive format has optional headers that are marked as
|
||||
[]
|
||||
Header
|
||||
[]
|
||||
|
||||
REAL_UINT64 means real UINT64.
|
||||
|
||||
UINT64 means real UINT64 encoded with the following scheme:
|
||||
|
||||
Size of encoding sequence depends from first byte:
|
||||
First_Byte Extra_Bytes Value
|
||||
(binary)
|
||||
0xxxxxxx : ( xxxxxxx )
|
||||
10xxxxxx BYTE y[1] : ( xxxxxx << (8 * 1)) + y
|
||||
110xxxxx BYTE y[2] : ( xxxxx << (8 * 2)) + y
|
||||
...
|
||||
1111110x BYTE y[6] : ( x << (8 * 6)) + y
|
||||
11111110 BYTE y[7] : y
|
||||
11111111 BYTE y[8] : y
|
||||
|
||||
|
||||
|
||||
Property IDs
|
||||
------------
|
||||
|
||||
0x00 = kEnd
|
||||
|
||||
0x01 = kHeader
|
||||
|
||||
0x02 = kArchiveProperties
|
||||
|
||||
0x03 = kAdditionalStreamsInfo
|
||||
0x04 = kMainStreamsInfo
|
||||
0x05 = kFilesInfo
|
||||
|
||||
0x06 = kPackInfo
|
||||
0x07 = kUnPackInfo
|
||||
0x08 = kSubStreamsInfo
|
||||
|
||||
0x09 = kSize
|
||||
0x0A = kCRC
|
||||
|
||||
0x0B = kFolder
|
||||
|
||||
0x0C = kCodersUnPackSize
|
||||
0x0D = kNumUnPackStream
|
||||
|
||||
0x0E = kEmptyStream
|
||||
0x0F = kEmptyFile
|
||||
0x10 = kAnti
|
||||
|
||||
0x11 = kName
|
||||
0x12 = kCTime
|
||||
0x13 = kATime
|
||||
0x14 = kMTime
|
||||
0x15 = kWinAttributes
|
||||
0x16 = kComment
|
||||
|
||||
0x17 = kEncodedHeader
|
||||
|
||||
0x18 = kStartPos
|
||||
0x19 = kDummy
|
||||
|
||||
|
||||
7z format headers
|
||||
-----------------
|
||||
|
||||
SignatureHeader
|
||||
~~~~~~~~~~~~~~~
|
||||
BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
|
||||
|
||||
ArchiveVersion
|
||||
{
|
||||
BYTE Major; // now = 0
|
||||
BYTE Minor; // now = 4
|
||||
};
|
||||
|
||||
UINT32 StartHeaderCRC;
|
||||
|
||||
StartHeader
|
||||
{
|
||||
REAL_UINT64 NextHeaderOffset
|
||||
REAL_UINT64 NextHeaderSize
|
||||
UINT32 NextHeaderCRC
|
||||
}
|
||||
|
||||
|
||||
...........................
|
||||
|
||||
|
||||
ArchiveProperties
|
||||
~~~~~~~~~~~~~~~~~
|
||||
BYTE NID::kArchiveProperties (0x02)
|
||||
for (;;)
|
||||
{
|
||||
BYTE PropertyType;
|
||||
if (aType == 0)
|
||||
break;
|
||||
UINT64 PropertySize;
|
||||
BYTE PropertyData[PropertySize];
|
||||
}
|
||||
|
||||
|
||||
Digests (NumStreams)
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
BYTE AllAreDefined
|
||||
if (AllAreDefined == 0)
|
||||
{
|
||||
for(NumStreams)
|
||||
BIT Defined
|
||||
}
|
||||
UINT32 CRCs[NumDefined]
|
||||
|
||||
|
||||
PackInfo
|
||||
~~~~~~~~~~~~
|
||||
BYTE NID::kPackInfo (0x06)
|
||||
UINT64 PackPos
|
||||
UINT64 NumPackStreams
|
||||
|
||||
[]
|
||||
BYTE NID::kSize (0x09)
|
||||
UINT64 PackSizes[NumPackStreams]
|
||||
[]
|
||||
|
||||
[]
|
||||
BYTE NID::kCRC (0x0A)
|
||||
PackStreamDigests[NumPackStreams]
|
||||
[]
|
||||
|
||||
BYTE NID::kEnd
|
||||
|
||||
|
||||
Folder
|
||||
~~~~~~
|
||||
UINT64 NumCoders;
|
||||
for (NumCoders)
|
||||
{
|
||||
BYTE
|
||||
{
|
||||
0:3 CodecIdSize
|
||||
4: Is Complex Coder
|
||||
5: There Are Attributes
|
||||
6: Reserved
|
||||
7: There are more alternative methods. (Not used anymore, must be 0).
|
||||
}
|
||||
BYTE CodecId[CodecIdSize]
|
||||
if (Is Complex Coder)
|
||||
{
|
||||
UINT64 NumInStreams;
|
||||
UINT64 NumOutStreams;
|
||||
}
|
||||
if (There Are Attributes)
|
||||
{
|
||||
UINT64 PropertiesSize
|
||||
BYTE Properties[PropertiesSize]
|
||||
}
|
||||
}
|
||||
|
||||
NumBindPairs = NumOutStreamsTotal - 1;
|
||||
|
||||
for (NumBindPairs)
|
||||
{
|
||||
UINT64 InIndex;
|
||||
UINT64 OutIndex;
|
||||
}
|
||||
|
||||
NumPackedStreams = NumInStreamsTotal - NumBindPairs;
|
||||
if (NumPackedStreams > 1)
|
||||
for(NumPackedStreams)
|
||||
{
|
||||
UINT64 Index;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Coders Info
|
||||
~~~~~~~~~~~
|
||||
|
||||
BYTE NID::kUnPackInfo (0x07)
|
||||
|
||||
|
||||
BYTE NID::kFolder (0x0B)
|
||||
UINT64 NumFolders
|
||||
BYTE External
|
||||
switch(External)
|
||||
{
|
||||
case 0:
|
||||
Folders[NumFolders]
|
||||
case 1:
|
||||
UINT64 DataStreamIndex
|
||||
}
|
||||
|
||||
|
||||
BYTE ID::kCodersUnPackSize (0x0C)
|
||||
for(Folders)
|
||||
for(Folder.NumOutStreams)
|
||||
UINT64 UnPackSize;
|
||||
|
||||
|
||||
[]
|
||||
BYTE NID::kCRC (0x0A)
|
||||
UnPackDigests[NumFolders]
|
||||
[]
|
||||
|
||||
|
||||
|
||||
BYTE NID::kEnd
|
||||
|
||||
|
||||
|
||||
SubStreams Info
|
||||
~~~~~~~~~~~~~~
|
||||
BYTE NID::kSubStreamsInfo; (0x08)
|
||||
|
||||
[]
|
||||
BYTE NID::kNumUnPackStream; (0x0D)
|
||||
UINT64 NumUnPackStreamsInFolders[NumFolders];
|
||||
[]
|
||||
|
||||
|
||||
[]
|
||||
BYTE NID::kSize (0x09)
|
||||
UINT64 UnPackSizes[]
|
||||
[]
|
||||
|
||||
|
||||
[]
|
||||
BYTE NID::kCRC (0x0A)
|
||||
Digests[Number of streams with unknown CRC]
|
||||
[]
|
||||
|
||||
|
||||
BYTE NID::kEnd
|
||||
|
||||
|
||||
Streams Info
|
||||
~~~~~~~~~~~~
|
||||
|
||||
[]
|
||||
PackInfo
|
||||
[]
|
||||
|
||||
|
||||
[]
|
||||
CodersInfo
|
||||
[]
|
||||
|
||||
|
||||
[]
|
||||
SubStreamsInfo
|
||||
[]
|
||||
|
||||
BYTE NID::kEnd
|
||||
|
||||
|
||||
FilesInfo
|
||||
~~~~~~~~~
|
||||
BYTE NID::kFilesInfo; (0x05)
|
||||
UINT64 NumFiles
|
||||
|
||||
for (;;)
|
||||
{
|
||||
BYTE PropertyType;
|
||||
if (aType == 0)
|
||||
break;
|
||||
|
||||
UINT64 Size;
|
||||
|
||||
switch(PropertyType)
|
||||
{
|
||||
kEmptyStream: (0x0E)
|
||||
for(NumFiles)
|
||||
BIT IsEmptyStream
|
||||
|
||||
kEmptyFile: (0x0F)
|
||||
for(EmptyStreams)
|
||||
BIT IsEmptyFile
|
||||
|
||||
kAnti: (0x10)
|
||||
for(EmptyStreams)
|
||||
BIT IsAntiFile
|
||||
|
||||
case kCTime: (0x12)
|
||||
case kATime: (0x13)
|
||||
case kMTime: (0x14)
|
||||
BYTE AllAreDefined
|
||||
if (AllAreDefined == 0)
|
||||
{
|
||||
for(NumFiles)
|
||||
BIT TimeDefined
|
||||
}
|
||||
BYTE External;
|
||||
if(External != 0)
|
||||
UINT64 DataIndex
|
||||
[]
|
||||
for(Definded Items)
|
||||
REAL_UINT64 Time
|
||||
[]
|
||||
|
||||
kNames: (0x11)
|
||||
BYTE External;
|
||||
if(External != 0)
|
||||
UINT64 DataIndex
|
||||
[]
|
||||
for(Files)
|
||||
{
|
||||
wchar_t Names[NameSize];
|
||||
wchar_t 0;
|
||||
}
|
||||
[]
|
||||
|
||||
kAttributes: (0x15)
|
||||
BYTE AllAreDefined
|
||||
if (AllAreDefined == 0)
|
||||
{
|
||||
for(NumFiles)
|
||||
BIT AttributesAreDefined
|
||||
}
|
||||
BYTE External;
|
||||
if(External != 0)
|
||||
UINT64 DataIndex
|
||||
[]
|
||||
for(Definded Attributes)
|
||||
UINT32 Attributes
|
||||
[]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Header
|
||||
~~~~~~
|
||||
BYTE NID::kHeader (0x01)
|
||||
|
||||
[]
|
||||
ArchiveProperties
|
||||
[]
|
||||
|
||||
[]
|
||||
BYTE NID::kAdditionalStreamsInfo; (0x03)
|
||||
StreamsInfo
|
||||
[]
|
||||
|
||||
[]
|
||||
BYTE NID::kMainStreamsInfo; (0x04)
|
||||
StreamsInfo
|
||||
[]
|
||||
|
||||
[]
|
||||
FilesInfo
|
||||
[]
|
||||
|
||||
BYTE NID::kEnd
|
||||
|
||||
|
||||
HeaderInfo
|
||||
~~~~~~~~~~
|
||||
[]
|
||||
BYTE NID::kEncodedHeader; (0x17)
|
||||
StreamsInfo for Encoded Header
|
||||
[]
|
||||
|
||||
|
||||
---
|
||||
End of document
|
@ -0,0 +1,173 @@
|
||||
7-Zip method IDs for 7z and xz archives
|
||||
---------------------------------------
|
||||
|
||||
Version: 18.06
|
||||
Date: 2018-06-30
|
||||
|
||||
Each compression or crypto method in 7z is associated with unique binary value (ID).
|
||||
The length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).
|
||||
|
||||
xz and 7z formats use same ID map.
|
||||
|
||||
If you want to add some new ID, you have two ways:
|
||||
1) Write request for allocating IDs to 7-Zip developers.
|
||||
2) Generate 8-bytes ID:
|
||||
|
||||
3F ZZ ZZ ZZ ZZ ZZ MM MM
|
||||
|
||||
3F - Prefix for random IDs (1 byte)
|
||||
ZZ ZZ ZZ ZZ ZZ - Developer ID (5 bytes). Use real random bytes.
|
||||
|
||||
MM MM - Method ID (2 bytes)
|
||||
|
||||
You can notify 7-Zip developers about your Developer ID / Method ID.
|
||||
|
||||
Note: Use new ID, if old codec can not decode data encoded with new version.
|
||||
|
||||
|
||||
List of defined IDs
|
||||
-------------------
|
||||
|
||||
00 - Copy
|
||||
|
||||
03 - Delta
|
||||
04 - BCJ (x86)
|
||||
05 - PPC (big-endian)
|
||||
06 - IA64
|
||||
07 - ARM (little-endian)
|
||||
08 - ARMT (little-endian)
|
||||
09 - SPARC
|
||||
|
||||
21 - LZMA2
|
||||
|
||||
02.. - Common
|
||||
03 [Swap]
|
||||
- 2 Swap2
|
||||
- 4 Swap4
|
||||
|
||||
03.. - 7z
|
||||
01 -
|
||||
01 - LZMA
|
||||
|
||||
03 - [Branch Codecs]
|
||||
01 - [x86 Codecs]
|
||||
03 - BCJ
|
||||
1B - BCJ2 (4 packed streams)
|
||||
02 -
|
||||
05 - PPC (big-endian)
|
||||
03 -
|
||||
01 - Alpha
|
||||
04 -
|
||||
01 - IA64
|
||||
05 -
|
||||
01 - ARM (little-endian)
|
||||
06 -
|
||||
05 - M68 (big-endian)
|
||||
07 -
|
||||
01 - ARMT (little-endian)
|
||||
08 -
|
||||
05 - SPARC
|
||||
|
||||
04 -
|
||||
01 - PPMD
|
||||
|
||||
7F -
|
||||
01 - experimental method.
|
||||
|
||||
|
||||
04.. - Misc codecs
|
||||
|
||||
00 - Reserved
|
||||
|
||||
01 - [Zip]
|
||||
00 - Copy (not used. Use {00} instead)
|
||||
01 - Shrink
|
||||
06 - Implode
|
||||
08 - Deflate
|
||||
09 - Deflate64
|
||||
0A - Imploding
|
||||
0C - BZip2 (not used. Use {040202} instead)
|
||||
0E - LZMA (LZMA-zip)
|
||||
5F - xz
|
||||
60 - Jpeg
|
||||
61 - WavPack
|
||||
62 - PPMd (PPMd-zip)
|
||||
63 - wzAES
|
||||
|
||||
02 -
|
||||
02 - BZip2
|
||||
|
||||
03 - [Rar]
|
||||
01 - Rar1
|
||||
02 - Rar2
|
||||
03 - Rar3
|
||||
05 - Rar5
|
||||
|
||||
04 - [Arj]
|
||||
01 - Arj(1,2,3)
|
||||
02 - Arj4
|
||||
|
||||
05 - [Z]
|
||||
|
||||
06 - [Lzh]
|
||||
|
||||
07 - Reserved for 7z
|
||||
|
||||
08 - [Cab]
|
||||
|
||||
09 - [NSIS]
|
||||
01 - DeflateNSIS
|
||||
02 - BZip2NSIS
|
||||
|
||||
F7 - External codecs (that are not included to 7-Zip)
|
||||
|
||||
0x xx - reserved
|
||||
|
||||
10 xx - reserved (LZHAM)
|
||||
01 - LZHAM
|
||||
|
||||
11 xx - reserved (Tino Reichardt)
|
||||
01 - ZSTD
|
||||
02 - BROTLI
|
||||
04 - LZ4
|
||||
05 - LZ5
|
||||
06 - LIZARD
|
||||
|
||||
12 xx - reserverd (Denis Anisimov)
|
||||
|
||||
01 - WavPack2
|
||||
FE - eSplitter
|
||||
FF - RawSplitter
|
||||
|
||||
|
||||
06.. - Crypto
|
||||
|
||||
F0 - Ciphers without hashing algo
|
||||
|
||||
01 - [AES]
|
||||
0x - AES-128
|
||||
4x - AES-192
|
||||
8x - AES-256
|
||||
Cx - AES
|
||||
|
||||
x0 - ECB
|
||||
x1 - CBC
|
||||
x2 - CFB
|
||||
x3 - OFB
|
||||
x4 - CTR
|
||||
|
||||
F1 - Combine Ciphers
|
||||
|
||||
01 - [Zip]
|
||||
01 - ZipCrypto (Main Zip crypto algo)
|
||||
|
||||
03 - [RAR]
|
||||
02 -
|
||||
03 - Rar29AES (AES-128 + modified SHA-1)
|
||||
|
||||
07 - [7z]
|
||||
01 - 7zAES (AES-256 + SHA-256)
|
||||
|
||||
|
||||
---
|
||||
End of document
|
@ -0,0 +1,166 @@
|
||||
7-Zip for installers 9.38
|
||||
-------------------------
|
||||
|
||||
7-Zip is a file archiver for Windows NT/2000/2003/2008/XP/Vista/7/8/10.
|
||||
|
||||
7-Zip for installers is part of LZMA SDK.
|
||||
LZMA SDK is written and placed in the public domain by Igor Pavlov.
|
||||
|
||||
It's allowed to join 7-Zip SFX module with another software.
|
||||
It's allowed to change resources of 7-Zip's SFX modules.
|
||||
|
||||
|
||||
HOW to use
|
||||
-----------
|
||||
|
||||
7zr.exe is reduced version of 7za.exe of 7-Zip.
|
||||
7zr.exe supports only format with these codecs: LZMA, LZMA2, BCJ, BCJ2, ARM, Copy.
|
||||
|
||||
Example of compressing command for installation packages:
|
||||
|
||||
7zr a archive.7z files
|
||||
|
||||
7zSD.sfx is SFX module for installers. 7zSD.sfx uses msvcrt.dll.
|
||||
|
||||
SFX modules for installers allow to create installation program.
|
||||
Such module extracts archive to temp folder and then runs specified program and removes
|
||||
temp files after program finishing. Self-extract archive for installers must be created
|
||||
as joining 3 files: SFX_Module, Installer_Config, 7z_Archive.
|
||||
Installer_Config is optional file. You can use the following command to create installer
|
||||
self-extract archive:
|
||||
|
||||
copy /b 7zSD.sfx + config.txt + archive.7z archive.exe
|
||||
|
||||
The smallest installation package size can be achieved, if installation files was
|
||||
uncompressed before including to 7z archive.
|
||||
|
||||
-y switch for installer module (at runtime) specifies quiet mode for extracting.
|
||||
|
||||
Installer Config file format
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Config file contains commands for Installer. File begins from string
|
||||
;!@Install@!UTF-8! and ends with ;!@InstallEnd@!. File must be written
|
||||
in UTF-8 encoding. File contains string pairs:
|
||||
|
||||
ID_String="Value"
|
||||
|
||||
ID_String Description
|
||||
|
||||
Title Title for messages
|
||||
BeginPrompt Begin Prompt message
|
||||
Progress Value can be "yes" or "no". Default value is "yes".
|
||||
RunProgram Command for executing. Default value is "setup.exe".
|
||||
Substring %%T will be replaced with path to temporary
|
||||
folder, where files were extracted
|
||||
Directory Directory prefix for "RunProgram". Default value is ".\\"
|
||||
ExecuteFile Name of file for executing
|
||||
ExecuteParameters Parameters for "ExecuteFile"
|
||||
|
||||
|
||||
You can omit any string pair.
|
||||
|
||||
There are two ways to run program: RunProgram and ExecuteFile.
|
||||
Use RunProgram, if you want to run some program from .7z archive.
|
||||
Use ExecuteFile, if you want to open some document from .7z archive or
|
||||
if you want to execute some command from Windows.
|
||||
|
||||
If you use RunProgram and if you specify empty directory prefix: Directory="",
|
||||
the system searches for the executable file in the following sequence:
|
||||
|
||||
1. The directory from which the application (installer) loaded.
|
||||
2. The temporary folder, where files were extracted.
|
||||
3. The Windows system directory.
|
||||
|
||||
|
||||
Config file Examples
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
;!@Install@!UTF-8!
|
||||
Title="7-Zip 4.00"
|
||||
BeginPrompt="Do you want to install the 7-Zip 4.00?"
|
||||
RunProgram="setup.exe"
|
||||
;!@InstallEnd@!
|
||||
|
||||
|
||||
|
||||
;!@Install@!UTF-8!
|
||||
Title="7-Zip 4.00"
|
||||
BeginPrompt="Do you want to install the 7-Zip 4.00?"
|
||||
ExecuteFile="7zip.msi"
|
||||
;!@InstallEnd@!
|
||||
|
||||
|
||||
|
||||
;!@Install@!UTF-8!
|
||||
Title="7-Zip 4.01 Update"
|
||||
BeginPrompt="Do you want to install the 7-Zip 4.01 Update?"
|
||||
ExecuteFile="msiexec.exe"
|
||||
ExecuteParameters="/i 7zip.msi REINSTALL=ALL REINSTALLMODE=vomus"
|
||||
;!@InstallEnd@!
|
||||
|
||||
|
||||
|
||||
Small SFX modules for installers
|
||||
--------------------------------
|
||||
|
||||
7zS2.sfx - small SFX module (GUI version)
|
||||
7zS2con.sfx - small SFX module (Console version)
|
||||
|
||||
Small SFX modules support this codecs: LZMA, LZMA2, BCJ, BCJ2, ARM, COPY
|
||||
|
||||
Small SFX module is similar to common SFX module for installers.
|
||||
The difference (what's new in small version):
|
||||
- Smaller size (30 KB vs 100 KB)
|
||||
- C source code instead of Ñ++
|
||||
- No installer Configuration file
|
||||
- No extracting progress window
|
||||
- It decompresses solid 7z blocks (it can be whole 7z archive) to RAM.
|
||||
So user that calls SFX installer must have free RAM of size of largest
|
||||
solid 7z block (size of 7z archive at simplest case).
|
||||
|
||||
How to use
|
||||
----------
|
||||
|
||||
copy /b 7zS2.sfx + archive.7z sfx.exe
|
||||
|
||||
When you run installer sfx module (sfx.exe)
|
||||
1) It creates "7zNNNNNNNN" temp folder in system temp folder.
|
||||
2) It extracts .7z archive to that folder
|
||||
3) It executes one file from "7zNNNNNNNN" temp folder.
|
||||
4) It removes "7zNNNNNNNN" temp folder
|
||||
|
||||
You can send parameters to installer, and installer will transfer them to extracted .exe file.
|
||||
|
||||
Small SFX uses 3 levels of priorities to select file to execute:
|
||||
|
||||
1) Files in root folder have higher priority than files in subfolders.
|
||||
2) File extension priorities (from high to low priority order):
|
||||
bat, cmd, exe, inf, msi, cab (under Windows CE), html, htm
|
||||
3) File name priorities (from high to low priority order):
|
||||
setup, install, run, start
|
||||
|
||||
Windows CE (ARM) version of 7zS2.sfx is included to 7-Zip for Windows Mobile package.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
1) To create compressed console 7-Zip:
|
||||
|
||||
7zr a c.7z 7z.exe 7z.dll -mx
|
||||
copy /b 7zS2con.sfx + c.7z 7zCompr.exe
|
||||
7zCompr.exe b -md22
|
||||
|
||||
|
||||
2) To create compressed GUI 7-Zip:
|
||||
|
||||
7zr a g.7z 7zg.exe 7z.dll -mx
|
||||
copy /b 7zS2.sfx + g.7z 7zgCompr.exe
|
||||
7zgCompr.exe b -md22
|
||||
|
||||
|
||||
3) To open some file:
|
||||
|
||||
7zr a h.7z readme.txt -mx
|
||||
copy /b 7zS2.sfx + h.7z 7zTxt.exe
|
||||
7zTxt.exe
|
@ -0,0 +1,484 @@
|
||||
HISTORY of the LZMA SDK
|
||||
-----------------------
|
||||
|
||||
21.02 alpha 2021-05-06
|
||||
-------------------------
|
||||
- The command line version of 7-Zip for macOS was released.
|
||||
- The speed for LZMA and LZMA2 decompression in arm64 versions for macOS and Linux
|
||||
was increased by 20%-60%.
|
||||
|
||||
|
||||
21.01 alpha 2021-03-09
|
||||
-------------------------
|
||||
- The command line version of 7-Zip for Linux was released.
|
||||
- The improvements for speed of ARM64 version using hardware CPU instructions
|
||||
for AES, CRC-32, SHA-1 and SHA-256.
|
||||
- Some bugs were fixed.
|
||||
|
||||
|
||||
20.02 alpha 2020-08-08
|
||||
-------------------------
|
||||
- The default number of LZMA2 chunks per solid block in 7z archive was increased to 64.
|
||||
It allows to increase the compression speed for big 7z archives, if there is a big number
|
||||
of CPU cores and threads.
|
||||
- The speed of PPMd compressing/decompressing was increased for 7z archives.
|
||||
- The new -ssp switch. If the switch -ssp is specified, 7-Zip doesn't allow the system
|
||||
to modify "Last Access Time" property of source files for archiving and hashing operations.
|
||||
- Some bugs were fixed.
|
||||
|
||||
|
||||
20.00 alpha 2020-02-06
|
||||
-------------------------
|
||||
- 7-Zip now supports new optional match finders for LZMA/LZMA2 compression: bt5 and hc5,
|
||||
that can work faster than bt4 and hc4 match finders for the data with big redundancy.
|
||||
- The compression ratio was improved for Fast and Fastest compression levels with the
|
||||
following default settings:
|
||||
- Fastest level (-mx1) : hc5 match finder with 256 KB dictionary.
|
||||
- Fast level (-mx3) : hc5 match finder with 4 MB dictionary.
|
||||
- Minor speed optimizations in multithreaded LZMA/LZMA2 compression for Normal/Maximum/Ultra
|
||||
compression levels.
|
||||
|
||||
|
||||
19.00 2019-02-21
|
||||
-------------------------
|
||||
- Encryption strength for 7z archives was increased:
|
||||
the size of random initialization vector was increased from 64-bit to 128-bit,
|
||||
and the pseudo-random number generator was improved.
|
||||
- The bug in 7zIn.c code was fixed.
|
||||
|
||||
|
||||
18.06 2018-12-30
|
||||
-------------------------
|
||||
- The speed for LZMA/LZMA2 compressing was increased by 3-10%,
|
||||
and there are minor changes in compression ratio.
|
||||
- Some bugs were fixed.
|
||||
- The bug in 7-Zip 18.02-18.05 was fixed:
|
||||
There was memory leak in multithreading xz decoder - XzDecMt_Decode(),
|
||||
if xz stream contains only one block.
|
||||
- The changes for MSVS compiler makefiles:
|
||||
- the makefiles now use "PLATFORM" macroname with values (x64, x86, arm64)
|
||||
instead of "CPU" macroname with values (AMD64, ARM64).
|
||||
- the makefiles by default now use static version of the run-time library.
|
||||
|
||||
|
||||
18.05 2018-04-30
|
||||
-------------------------
|
||||
- The speed for LZMA/LZMA2 compressing was increased
|
||||
by 8% for fastest/fast compression levels and
|
||||
by 3% for normal/maximum compression levels.
|
||||
- Previous versions of 7-Zip could work incorrectly in "Large memory pages" mode in
|
||||
Windows 10 because of some BUG with "Large Pages" in Windows 10.
|
||||
Now 7-Zip doesn't use "Large Pages" on Windows 10 up to revision 1709 (16299).
|
||||
- The BUG was fixed in Lzma2Enc.c
|
||||
Lzma2Enc_Encode2() function worked incorretly,
|
||||
if (inStream == NULL) and the number of block threads is more than 1.
|
||||
|
||||
|
||||
18.03 beta 2018-03-04
|
||||
-------------------------
|
||||
- Asm\x86\LzmaDecOpt.asm: new optimized LZMA decoder written in asm
|
||||
for x64 with about 30% higher speed than main version of LZMA decoder written in C.
|
||||
- The speed for single-thread LZMA/LZMA2 decoder written in C was increased by 3%.
|
||||
- 7-Zip now can use multi-threading for 7z/LZMA2 decoding,
|
||||
if there are multiple independent data chunks in LZMA2 stream.
|
||||
- 7-Zip now can use multi-threading for xz decoding,
|
||||
if there are multiple blocks in xz stream.
|
||||
|
||||
|
||||
18.01 2019-01-28
|
||||
-------------------------
|
||||
- The BUG in 17.01 - 18.00 beta was fixed:
|
||||
XzDec.c : random block unpacking and XzUnpacker_IsBlockFinished()
|
||||
didn't work correctly for xz archives without checksum (CRC).
|
||||
|
||||
|
||||
18.00 beta 2019-01-10
|
||||
-------------------------
|
||||
- The BUG in xz encoder was fixed:
|
||||
There was memory leak of 16 KB for each file compressed with
|
||||
xz compression method, if additional filter was used.
|
||||
|
||||
|
||||
17.01 beta 2017-08-28
|
||||
-------------------------
|
||||
- Minor speed optimization for LZMA2 (xz and 7z) multi-threading compression.
|
||||
7-Zip now uses additional memory buffers for multi-block LZMA2 compression.
|
||||
CPU utilization was slightly improved.
|
||||
- 7-zip now creates multi-block xz archives by default. Block size can be
|
||||
specified with -ms[Size]{m|g} switch.
|
||||
- xz decoder now can unpack random block from multi-block xz archives.
|
||||
- 7-Zip command line: @listfile now doesn't work after -- switch.
|
||||
Use -i@listfile before -- switch instead.
|
||||
- The BUGs were fixed:
|
||||
7-Zip 17.00 beta crashed for commands that write anti-item to 7z archive.
|
||||
|
||||
|
||||
17.00 beta 2017-04-29
|
||||
-------------------------
|
||||
- NewHandler.h / NewHandler.cpp:
|
||||
now it redefines operator new() only for old MSVC compilers (_MSC_VER < 1900).
|
||||
- C/7zTypes.h : the names of variables in interface structures were changed (vt).
|
||||
- Some bugs were fixed. 7-Zip could crash in some cases.
|
||||
- Some internal changes in code.
|
||||
|
||||
|
||||
16.04 2016-10-04
|
||||
-------------------------
|
||||
- The bug was fixed in DllSecur.c.
|
||||
|
||||
|
||||
16.03 2016-09-28
|
||||
-------------------------
|
||||
- SFX modules now use some protection against DLL preloading attack.
|
||||
- Some bugs in 7z code were fixed.
|
||||
|
||||
|
||||
16.02 2016-05-21
|
||||
-------------------------
|
||||
- The BUG in 16.00 - 16.01 was fixed:
|
||||
Split Handler (SplitHandler.cpp) returned incorrect
|
||||
total size value (kpidSize) for split archives.
|
||||
|
||||
|
||||
16.01 2016-05-19
|
||||
-------------------------
|
||||
- Some internal changes to reduce the number of compiler warnings.
|
||||
|
||||
|
||||
16.00 2016-05-10
|
||||
-------------------------
|
||||
- Some bugs were fixed.
|
||||
|
||||
|
||||
15.12 2015-11-19
|
||||
-------------------------
|
||||
- The BUG in C version of 7z decoder was fixed:
|
||||
7zDec.c : SzDecodeLzma2()
|
||||
7z decoder could mistakenly report about decoding error for some 7z archives
|
||||
that use LZMA2 compression method.
|
||||
The probability to get that mistaken decoding error report was about
|
||||
one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size).
|
||||
- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:
|
||||
7zArcIn.c : SzReadHeader2()
|
||||
7z decoder worked incorrectly for 7z archives that contain
|
||||
empty solid blocks, that can be placed to 7z archive, if some file is
|
||||
unavailable for reading during archive creation.
|
||||
|
||||
|
||||
15.09 beta 2015-10-16
|
||||
-------------------------
|
||||
- The BUG in LZMA / LZMA2 encoding code was fixed.
|
||||
The BUG in LzFind.c::MatchFinder_ReadBlock() function.
|
||||
If input data size is larger than (4 GiB - dictionary_size),
|
||||
the following code worked incorrectly:
|
||||
- LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions
|
||||
for compressing from memory to memory.
|
||||
That BUG is not related to LZMA encoder version that works via streams.
|
||||
- LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if
|
||||
default value of chunk size (CLzma2EncProps::blockSize) is changed
|
||||
to value larger than (4 GiB - dictionary_size).
|
||||
|
||||
|
||||
9.38 beta 2015-01-03
|
||||
-------------------------
|
||||
- The BUG in 9.31-9.37 was fixed:
|
||||
IArchiveGetRawProps interface was disabled for 7z archives.
|
||||
- The BUG in 9.26-9.36 was fixed:
|
||||
Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.
|
||||
|
||||
|
||||
9.36 beta 2014-12-26
|
||||
-------------------------
|
||||
- The BUG in command line version was fixed:
|
||||
7-Zip created temporary archive in current folder during update archive
|
||||
operation, if -w{Path} switch was not specified.
|
||||
The fixed 7-Zip creates temporary archive in folder that contains updated archive.
|
||||
- The BUG in 9.33-9.35 was fixed:
|
||||
7-Zip silently ignored file reading errors during 7z or gz archive creation,
|
||||
and the created archive contained only part of file that was read before error.
|
||||
The fixed 7-Zip stops archive creation and it reports about error.
|
||||
|
||||
|
||||
9.35 beta 2014-12-07
|
||||
-------------------------
|
||||
- 7zr.exe now support AES encryption.
|
||||
- SFX mudules were added to LZMA SDK
|
||||
- Some bugs were fixed.
|
||||
|
||||
|
||||
9.21 beta 2011-04-11
|
||||
-------------------------
|
||||
- New class FString for file names at file systems.
|
||||
- Speed optimization in CRC code for big-endian CPUs.
|
||||
- The BUG in Lzma2Dec.c was fixed:
|
||||
Lzma2Decode function didn't work.
|
||||
|
||||
|
||||
9.18 beta 2010-11-02
|
||||
-------------------------
|
||||
- New small SFX module for installers (SfxSetup).
|
||||
|
||||
|
||||
9.12 beta 2010-03-24
|
||||
-------------------------
|
||||
- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,
|
||||
if more than 10 threads were used (or more than 20 threads in some modes).
|
||||
|
||||
|
||||
9.11 beta 2010-03-15
|
||||
-------------------------
|
||||
- PPMd compression method support
|
||||
|
||||
|
||||
9.09 2009-12-12
|
||||
-------------------------
|
||||
- The bug was fixed:
|
||||
Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c
|
||||
incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.
|
||||
- Some bugs were fixed
|
||||
|
||||
|
||||
9.06 2009-08-17
|
||||
-------------------------
|
||||
- Some changes in ANSI-C 7z Decoder interfaces.
|
||||
|
||||
|
||||
9.04 2009-05-30
|
||||
-------------------------
|
||||
- LZMA2 compression method support
|
||||
- xz format support
|
||||
|
||||
|
||||
4.65 2009-02-03
|
||||
-------------------------
|
||||
- Some minor fixes
|
||||
|
||||
|
||||
4.63 2008-12-31
|
||||
-------------------------
|
||||
- Some minor fixes
|
||||
|
||||
|
||||
4.61 beta 2008-11-23
|
||||
-------------------------
|
||||
- The bug in ANSI-C LZMA Decoder was fixed:
|
||||
If encoded stream was corrupted, decoder could access memory
|
||||
outside of allocated range.
|
||||
- Some changes in ANSI-C 7z Decoder interfaces.
|
||||
- LZMA SDK is placed in the public domain.
|
||||
|
||||
|
||||
4.60 beta 2008-08-19
|
||||
-------------------------
|
||||
- Some minor fixes.
|
||||
|
||||
|
||||
4.59 beta 2008-08-13
|
||||
-------------------------
|
||||
- The bug was fixed:
|
||||
LZMA Encoder in fast compression mode could access memory outside of
|
||||
allocated range in some rare cases.
|
||||
|
||||
|
||||
4.58 beta 2008-05-05
|
||||
-------------------------
|
||||
- ANSI-C LZMA Decoder was rewritten for speed optimizations.
|
||||
- ANSI-C LZMA Encoder was included to LZMA SDK.
|
||||
- C++ LZMA code now is just wrapper over ANSI-C code.
|
||||
|
||||
|
||||
4.57 2007-12-12
|
||||
-------------------------
|
||||
- Speed optimizations in Ñ++ LZMA Decoder.
|
||||
- Small changes for more compatibility with some C/C++ compilers.
|
||||
|
||||
|
||||
4.49 beta 2007-07-05
|
||||
-------------------------
|
||||
- .7z ANSI-C Decoder:
|
||||
- now it supports BCJ and BCJ2 filters
|
||||
- now it supports files larger than 4 GB.
|
||||
- now it supports "Last Write Time" field for files.
|
||||
- C++ code for .7z archives compressing/decompressing from 7-zip
|
||||
was included to LZMA SDK.
|
||||
|
||||
|
||||
4.43 2006-06-04
|
||||
-------------------------
|
||||
- Small changes for more compatibility with some C/C++ compilers.
|
||||
|
||||
|
||||
4.42 2006-05-15
|
||||
-------------------------
|
||||
- Small changes in .h files in ANSI-C version.
|
||||
|
||||
|
||||
4.39 beta 2006-04-14
|
||||
-------------------------
|
||||
- The bug in versions 4.33b:4.38b was fixed:
|
||||
C++ version of LZMA encoder could not correctly compress
|
||||
files larger than 2 GB with HC4 match finder (-mfhc4).
|
||||
|
||||
|
||||
4.37 beta 2005-04-06
|
||||
-------------------------
|
||||
- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined.
|
||||
|
||||
|
||||
4.35 beta 2005-03-02
|
||||
-------------------------
|
||||
- The bug was fixed in C++ version of LZMA Decoder:
|
||||
If encoded stream was corrupted, decoder could access memory
|
||||
outside of allocated range.
|
||||
|
||||
|
||||
4.34 beta 2006-02-27
|
||||
-------------------------
|
||||
- Compressing speed and memory requirements for compressing were increased
|
||||
- LZMA now can use only these match finders: HC4, BT2, BT3, BT4
|
||||
|
||||
|
||||
4.32 2005-12-09
|
||||
-------------------------
|
||||
- Java version of LZMA SDK was included
|
||||
|
||||
|
||||
4.30 2005-11-20
|
||||
-------------------------
|
||||
- Compression ratio was improved in -a2 mode
|
||||
- Speed optimizations for compressing in -a2 mode
|
||||
- -fb switch now supports values up to 273
|
||||
- The bug in 7z_C (7zIn.c) was fixed:
|
||||
It used Alloc/Free functions from different memory pools.
|
||||
So if program used two memory pools, it worked incorrectly.
|
||||
- 7z_C: .7z format supporting was improved
|
||||
- LZMA# SDK (C#.NET version) was included
|
||||
|
||||
|
||||
4.27 (Updated) 2005-09-21
|
||||
-------------------------
|
||||
- Some GUIDs/interfaces in C++ were changed.
|
||||
IStream.h:
|
||||
ISequentialInStream::Read now works as old ReadPart
|
||||
ISequentialOutStream::Write now works as old WritePart
|
||||
|
||||
|
||||
4.27 2005-08-07
|
||||
-------------------------
|
||||
- The bug in LzmaDecodeSize.c was fixed:
|
||||
if _LZMA_IN_CB and _LZMA_OUT_READ were defined,
|
||||
decompressing worked incorrectly.
|
||||
|
||||
|
||||
4.26 2005-08-05
|
||||
-------------------------
|
||||
- Fixes in 7z_C code and LzmaTest.c:
|
||||
previous versions could work incorrectly,
|
||||
if malloc(0) returns 0
|
||||
|
||||
|
||||
4.23 2005-06-29
|
||||
-------------------------
|
||||
- Small fixes in C++ code
|
||||
|
||||
|
||||
4.22 2005-06-10
|
||||
-------------------------
|
||||
- Small fixes
|
||||
|
||||
|
||||
4.21 2005-06-08
|
||||
-------------------------
|
||||
- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed
|
||||
- New additional version of ANSI-C LZMA Decoder with zlib-like interface:
|
||||
- LzmaStateDecode.h
|
||||
- LzmaStateDecode.c
|
||||
- LzmaStateTest.c
|
||||
- ANSI-C LZMA Decoder now can decompress files larger than 4 GB
|
||||
|
||||
|
||||
4.17 2005-04-18
|
||||
-------------------------
|
||||
- New example for RAM->RAM compressing/decompressing:
|
||||
LZMA + BCJ (filter for x86 code):
|
||||
- LzmaRam.h
|
||||
- LzmaRam.cpp
|
||||
- LzmaRamDecode.h
|
||||
- LzmaRamDecode.c
|
||||
- -f86 switch for lzma.exe
|
||||
|
||||
|
||||
4.16 2005-03-29
|
||||
-------------------------
|
||||
- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder):
|
||||
If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,
|
||||
decoder could access memory outside of allocated range.
|
||||
- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).
|
||||
Old version of LZMA Decoder now is in file LzmaDecodeSize.c.
|
||||
LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c
|
||||
- Small speed optimization in LZMA C++ code
|
||||
- filter for SPARC's code was added
|
||||
- Simplified version of .7z ANSI-C Decoder was included
|
||||
|
||||
|
||||
4.06 2004-09-05
|
||||
-------------------------
|
||||
- The bug in v4.05 was fixed:
|
||||
LZMA-Encoder didn't release output stream in some cases.
|
||||
|
||||
|
||||
4.05 2004-08-25
|
||||
-------------------------
|
||||
- Source code of filters for x86, IA-64, ARM, ARM-Thumb
|
||||
and PowerPC code was included to SDK
|
||||
- Some internal minor changes
|
||||
|
||||
|
||||
4.04 2004-07-28
|
||||
-------------------------
|
||||
- More compatibility with some C++ compilers
|
||||
|
||||
|
||||
4.03 2004-06-18
|
||||
-------------------------
|
||||
- "Benchmark" command was added. It measures compressing
|
||||
and decompressing speed and shows rating values.
|
||||
Also it checks hardware errors.
|
||||
|
||||
|
||||
4.02 2004-06-10
|
||||
-------------------------
|
||||
- C++ LZMA Encoder/Decoder code now is more portable
|
||||
and it can be compiled by GCC on Linux.
|
||||
|
||||
|
||||
4.01 2004-02-15
|
||||
-------------------------
|
||||
- Some detection of data corruption was enabled.
|
||||
LzmaDecode.c / RangeDecoderReadByte
|
||||
.....
|
||||
{
|
||||
rd->ExtraBytes = 1;
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
|
||||
4.00 2004-02-13
|
||||
-------------------------
|
||||
- Original version of LZMA SDK
|
||||
|
||||
|
||||
|
||||
HISTORY of the LZMA
|
||||
-------------------
|
||||
2001-2008: Improvements to LZMA compressing/decompressing code,
|
||||
keeping compatibility with original LZMA format
|
||||
1996-2001: Development of LZMA compression format
|
||||
|
||||
Some milestones:
|
||||
|
||||
2001-08-30: LZMA compression was added to 7-Zip
|
||||
1999-01-02: First version of 7-Zip was released
|
||||
|
||||
|
||||
End of document
|
@ -0,0 +1,357 @@
|
||||
LZMA SDK 21.02
|
||||
--------------
|
||||
|
||||
LZMA SDK provides the documentation, samples, header files,
|
||||
libraries, and tools you need to develop applications that
|
||||
use 7z / LZMA / LZMA2 / XZ compression.
|
||||
|
||||
LZMA is an improved version of famous LZ77 compression algorithm.
|
||||
It was improved in way of maximum increasing of compression ratio,
|
||||
keeping high decompression speed and low memory requirements for
|
||||
decompressing.
|
||||
|
||||
LZMA2 is a LZMA based compression method. LZMA2 provides better
|
||||
multithreading support for compression than LZMA and some other improvements.
|
||||
|
||||
7z is a file format for data compression and file archiving.
|
||||
7z is a main file format for 7-Zip compression program (www.7-zip.org).
|
||||
7z format supports different compression methods: LZMA, LZMA2 and others.
|
||||
7z also supports AES-256 based encryption.
|
||||
|
||||
XZ is a file format for data compression that uses LZMA2 compression.
|
||||
XZ format provides additional features: SHA/CRC check, filters for
|
||||
improved compression ratio, splitting to blocks and streams,
|
||||
|
||||
|
||||
|
||||
LICENSE
|
||||
-------
|
||||
|
||||
LZMA SDK is written and placed in the public domain by Igor Pavlov.
|
||||
|
||||
Some code in LZMA SDK is based on public domain code from another developers:
|
||||
1) PPMd var.H (2001): Dmitry Shkarin
|
||||
2) SHA-256: Wei Dai (Crypto++ library)
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute the
|
||||
original LZMA SDK code, either in source code form or as a compiled binary, for
|
||||
any purpose, commercial or non-commercial, and by any means.
|
||||
|
||||
LZMA SDK code is compatible with open source licenses, for example, you can
|
||||
include it to GNU GPL or GNU LGPL code.
|
||||
|
||||
|
||||
LZMA SDK Contents
|
||||
-----------------
|
||||
|
||||
Source code:
|
||||
|
||||
- C / C++ / C# / Java - LZMA compression and decompression
|
||||
- C / C++ - LZMA2 compression and decompression
|
||||
- C / C++ - XZ compression and decompression
|
||||
- C - 7z decompression
|
||||
- C++ - 7z compression and decompression
|
||||
- C - small SFXs for installers (7z decompression)
|
||||
- C++ - SFXs and SFXs for installers (7z decompression)
|
||||
|
||||
Precomiled binaries:
|
||||
|
||||
- console programs for lzma / 7z / xz compression and decompression
|
||||
- SFX modules for installers.
|
||||
|
||||
|
||||
UNIX/Linux version
|
||||
------------------
|
||||
To compile C++ version of file->file LZMA encoding, go to directory
|
||||
CPP/7zip/Bundles/LzmaCon
|
||||
and call make to recompile it:
|
||||
make -f makefile.gcc clean all
|
||||
|
||||
In some UNIX/Linux versions you must compile LZMA with static libraries.
|
||||
To compile with static libraries, you can use
|
||||
LIB = -lm -static
|
||||
|
||||
Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):
|
||||
|
||||
http://p7zip.sourceforge.net/
|
||||
|
||||
|
||||
Files
|
||||
-----
|
||||
|
||||
DOC/7zC.txt - 7z ANSI-C Decoder description
|
||||
DOC/7zFormat.txt - 7z Format description
|
||||
DOC/installer.txt - information about 7-Zip for installers
|
||||
DOC/lzma.txt - LZMA compression description
|
||||
DOC/lzma-sdk.txt - LZMA SDK description (this file)
|
||||
DOC/lzma-history.txt - history of LZMA SDK
|
||||
DOC/lzma-specification.txt - Specification of LZMA
|
||||
DOC/Methods.txt - Compression method IDs for .7z
|
||||
|
||||
bin/installer/ - example script to create installer that uses SFX module,
|
||||
|
||||
bin/7zdec.exe - simplified 7z archive decoder
|
||||
bin/7zr.exe - 7-Zip console program (reduced version)
|
||||
bin/x64/7zr.exe - 7-Zip console program (reduced version) (x64 version)
|
||||
bin/lzma.exe - file->file LZMA encoder/decoder for Windows
|
||||
bin/7zS2.sfx - small SFX module for installers (GUI version)
|
||||
bin/7zS2con.sfx - small SFX module for installers (Console version)
|
||||
bin/7zSD.sfx - SFX module for installers.
|
||||
|
||||
|
||||
7zDec.exe
|
||||
---------
|
||||
7zDec.exe is simplified 7z archive decoder.
|
||||
It supports only LZMA, LZMA2, and PPMd methods.
|
||||
7zDec decodes whole solid block from 7z archive to RAM.
|
||||
The RAM consumption can be high.
|
||||
|
||||
|
||||
|
||||
|
||||
Source code structure
|
||||
---------------------
|
||||
|
||||
|
||||
Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)
|
||||
|
||||
C/ - C files (compression / decompression and other)
|
||||
Util/
|
||||
7z - 7z decoder program (decoding 7z files)
|
||||
Lzma - LZMA program (file->file LZMA encoder/decoder).
|
||||
LzmaLib - LZMA library (.DLL for Windows)
|
||||
SfxSetup - small SFX module for installers
|
||||
|
||||
CPP/ -- CPP files
|
||||
|
||||
Common - common files for C++ projects
|
||||
Windows - common files for Windows related code
|
||||
|
||||
7zip - files related to 7-Zip
|
||||
|
||||
Archive - files related to archiving
|
||||
|
||||
Common - common files for archive handling
|
||||
7z - 7z C++ Encoder/Decoder
|
||||
|
||||
Bundles - Modules that are bundles of other modules (files)
|
||||
|
||||
Alone7z - 7zr.exe: Standalone 7-Zip console program (reduced version)
|
||||
Format7zExtractR - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.
|
||||
Format7zR - 7zr.dll: Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2
|
||||
LzmaCon - lzma.exe: LZMA compression/decompression
|
||||
LzmaSpec - example code for LZMA Specification
|
||||
SFXCon - 7zCon.sfx: Console 7z SFX module
|
||||
SFXSetup - 7zS.sfx: 7z SFX module for installers
|
||||
SFXWin - 7z.sfx: GUI 7z SFX module
|
||||
|
||||
Common - common files for 7-Zip
|
||||
|
||||
Compress - files for compression/decompression
|
||||
|
||||
Crypto - files for encryption / decompression
|
||||
|
||||
UI - User Interface files
|
||||
|
||||
Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
|
||||
Common - Common UI files
|
||||
Console - Code for console program (7z.exe)
|
||||
Explorer - Some code from 7-Zip Shell extension
|
||||
FileManager - Some GUI code from 7-Zip File Manager
|
||||
GUI - Some GUI code from 7-Zip
|
||||
|
||||
|
||||
CS/ - C# files
|
||||
7zip
|
||||
Common - some common files for 7-Zip
|
||||
Compress - files related to compression/decompression
|
||||
LZ - files related to LZ (Lempel-Ziv) compression algorithm
|
||||
LZMA - LZMA compression/decompression
|
||||
LzmaAlone - file->file LZMA compression/decompression
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
|
||||
Java/ - Java files
|
||||
SevenZip
|
||||
Compression - files related to compression/decompression
|
||||
LZ - files related to LZ (Lempel-Ziv) compression algorithm
|
||||
LZMA - LZMA compression/decompression
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
|
||||
|
||||
Note:
|
||||
Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.
|
||||
7-Zip's source code can be downloaded from 7-Zip's SourceForge page:
|
||||
|
||||
http://sourceforge.net/projects/sevenzip/
|
||||
|
||||
|
||||
|
||||
LZMA features
|
||||
-------------
|
||||
- Variable dictionary size (up to 1 GB)
|
||||
- Estimated compressing speed: about 2 MB/s on 2 GHz CPU
|
||||
- Estimated decompressing speed:
|
||||
- 20-30 MB/s on modern 2 GHz cpu
|
||||
- 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)
|
||||
- Small memory requirements for decompressing (16 KB + DictionarySize)
|
||||
- Small code size for decompressing: 5-8 KB
|
||||
|
||||
LZMA decoder uses only integer operations and can be
|
||||
implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
|
||||
|
||||
Some critical operations that affect the speed of LZMA decompression:
|
||||
1) 32*16 bit integer multiply
|
||||
2) Mispredicted branches (penalty mostly depends from pipeline length)
|
||||
3) 32-bit shift and arithmetic operations
|
||||
|
||||
The speed of LZMA decompressing mostly depends from CPU speed.
|
||||
Memory speed has no big meaning. But if your CPU has small data cache,
|
||||
overall weight of memory speed will slightly increase.
|
||||
|
||||
|
||||
How To Use
|
||||
----------
|
||||
|
||||
Using LZMA encoder/decoder executable
|
||||
--------------------------------------
|
||||
|
||||
Usage: LZMA <e|d> inputFile outputFile [<switches>...]
|
||||
|
||||
e: encode file
|
||||
|
||||
d: decode file
|
||||
|
||||
b: Benchmark. There are two tests: compressing and decompressing
|
||||
with LZMA method. Benchmark shows rating in MIPS (million
|
||||
instructions per second). Rating value is calculated from
|
||||
measured speed and it is normalized with Intel's Core 2 results.
|
||||
Also Benchmark checks possible hardware errors (RAM
|
||||
errors in most cases). Benchmark uses these settings:
|
||||
(-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
|
||||
Also you can change the number of iterations. Example for 30 iterations:
|
||||
LZMA b 30
|
||||
Default number of iterations is 10.
|
||||
|
||||
<Switches>
|
||||
|
||||
|
||||
-a{N}: set compression mode 0 = fast, 1 = normal
|
||||
default: 1 (normal)
|
||||
|
||||
d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB)
|
||||
The maximum value for dictionary size is 1 GB = 2^30 bytes.
|
||||
Dictionary size is calculated as DictionarySize = 2^N bytes.
|
||||
For decompressing file compressed by LZMA method with dictionary
|
||||
size D = 2^N you need about D bytes of memory (RAM).
|
||||
|
||||
-fb{N}: set number of fast bytes - [5, 273], default: 128
|
||||
Usually big number gives a little bit better compression ratio
|
||||
and slower compression process.
|
||||
|
||||
-lc{N}: set number of literal context bits - [0, 8], default: 3
|
||||
Sometimes lc=4 gives gain for big files.
|
||||
|
||||
-lp{N}: set number of literal pos bits - [0, 4], default: 0
|
||||
lp switch is intended for periodical data when period is
|
||||
equal 2^N. For example, for 32-bit (4 bytes)
|
||||
periodical data you can use lp=2. Often it's better to set lc0,
|
||||
if you change lp switch.
|
||||
|
||||
-pb{N}: set number of pos bits - [0, 4], default: 2
|
||||
pb switch is intended for periodical data
|
||||
when period is equal 2^N.
|
||||
|
||||
-mf{MF_ID}: set Match Finder. Default: bt4.
|
||||
Algorithms from hc* group doesn't provide good compression
|
||||
ratio, but they often works pretty fast in combination with
|
||||
fast mode (-a0).
|
||||
|
||||
Memory requirements depend from dictionary size
|
||||
(parameter "d" in table below).
|
||||
|
||||
MF_ID Memory Description
|
||||
|
||||
bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing.
|
||||
bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing.
|
||||
bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing.
|
||||
hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing.
|
||||
|
||||
-eos: write End Of Stream marker. By default LZMA doesn't write
|
||||
eos marker, since LZMA decoder knows uncompressed size
|
||||
stored in .lzma file header.
|
||||
|
||||
-si: Read data from stdin (it will write End Of Stream marker).
|
||||
-so: Write data to stdout
|
||||
|
||||
|
||||
Examples:
|
||||
|
||||
1) LZMA e file.bin file.lzma -d16 -lc0
|
||||
|
||||
compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
|
||||
and 0 literal context bits. -lc0 allows to reduce memory requirements
|
||||
for decompression.
|
||||
|
||||
|
||||
2) LZMA e file.bin file.lzma -lc0 -lp2
|
||||
|
||||
compresses file.bin to file.lzma with settings suitable
|
||||
for 32-bit periodical data (for example, ARM or MIPS code).
|
||||
|
||||
3) LZMA d file.lzma file.bin
|
||||
|
||||
decompresses file.lzma to file.bin.
|
||||
|
||||
|
||||
Compression ratio hints
|
||||
-----------------------
|
||||
|
||||
Recommendations
|
||||
---------------
|
||||
|
||||
To increase the compression ratio for LZMA compressing it's desirable
|
||||
to have aligned data (if it's possible) and also it's desirable to locate
|
||||
data in such order, where code is grouped in one place and data is
|
||||
grouped in other place (it's better than such mixing: code, data, code,
|
||||
data, ...).
|
||||
|
||||
|
||||
Filters
|
||||
-------
|
||||
You can increase the compression ratio for some data types, using
|
||||
special filters before compressing. For example, it's possible to
|
||||
increase the compression ratio on 5-10% for code for those CPU ISAs:
|
||||
x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
|
||||
|
||||
You can find C source code of such filters in C/Bra*.* files
|
||||
|
||||
You can check the compression ratio gain of these filters with such
|
||||
7-Zip commands (example for ARM code):
|
||||
No filter:
|
||||
7z a a1.7z a.bin -m0=lzma
|
||||
|
||||
With filter for little-endian ARM code:
|
||||
7z a a2.7z a.bin -m0=arm -m1=lzma
|
||||
|
||||
It works in such manner:
|
||||
Compressing = Filter_encoding + LZMA_encoding
|
||||
Decompressing = LZMA_decoding + Filter_decoding
|
||||
|
||||
Compressing and decompressing speed of such filters is very high,
|
||||
so it will not increase decompressing time too much.
|
||||
Moreover, it reduces decompression time for LZMA_decoding,
|
||||
since compression ratio with filtering is higher.
|
||||
|
||||
These filters convert CALL (calling procedure) instructions
|
||||
from relative offsets to absolute addresses, so such data becomes more
|
||||
compressible.
|
||||
|
||||
For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
http://www.7-zip.org
|
||||
http://www.7-zip.org/sdk.html
|
||||
http://www.7-zip.org/support.html
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,328 @@
|
||||
LZMA compression
|
||||
----------------
|
||||
Version: 9.35
|
||||
|
||||
This file describes LZMA encoding and decoding functions written in C language.
|
||||
|
||||
LZMA is an improved version of famous LZ77 compression algorithm.
|
||||
It was improved in way of maximum increasing of compression ratio,
|
||||
keeping high decompression speed and low memory requirements for
|
||||
decompressing.
|
||||
|
||||
Note: you can read also LZMA Specification (lzma-specification.txt from LZMA SDK)
|
||||
|
||||
Also you can look source code for LZMA encoding and decoding:
|
||||
C/Util/Lzma/LzmaUtil.c
|
||||
|
||||
|
||||
LZMA compressed file format
|
||||
---------------------------
|
||||
Offset Size Description
|
||||
0 1 Special LZMA properties (lc,lp, pb in encoded form)
|
||||
1 4 Dictionary size (little endian)
|
||||
5 8 Uncompressed size (little endian). -1 means unknown size
|
||||
13 Compressed data
|
||||
|
||||
|
||||
|
||||
ANSI-C LZMA Decoder
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
|
||||
If you want to use old interfaces you can download previous version of LZMA SDK
|
||||
from sourceforge.net site.
|
||||
|
||||
To use ANSI-C LZMA Decoder you need the following files:
|
||||
1) LzmaDec.h + LzmaDec.c + 7zTypes.h + Precomp.h + Compiler.h
|
||||
|
||||
Look example code:
|
||||
C/Util/Lzma/LzmaUtil.c
|
||||
|
||||
|
||||
Memory requirements for LZMA decoding
|
||||
-------------------------------------
|
||||
|
||||
Stack usage of LZMA decoding function for local variables is not
|
||||
larger than 200-400 bytes.
|
||||
|
||||
LZMA Decoder uses dictionary buffer and internal state structure.
|
||||
Internal state structure consumes
|
||||
state_size = (4 + (1.5 << (lc + lp))) KB
|
||||
by default (lc=3, lp=0), state_size = 16 KB.
|
||||
|
||||
|
||||
How To decompress data
|
||||
----------------------
|
||||
|
||||
LZMA Decoder (ANSI-C version) now supports 2 interfaces:
|
||||
1) Single-call Decompressing
|
||||
2) Multi-call State Decompressing (zlib-like interface)
|
||||
|
||||
You must use external allocator:
|
||||
Example:
|
||||
void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
|
||||
void SzFree(void *p, void *address) { p = p; free(address); }
|
||||
ISzAlloc alloc = { SzAlloc, SzFree };
|
||||
|
||||
You can use p = p; operator to disable compiler warnings.
|
||||
|
||||
|
||||
Single-call Decompressing
|
||||
-------------------------
|
||||
When to use: RAM->RAM decompressing
|
||||
Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
|
||||
Compile defines: no defines
|
||||
Memory Requirements:
|
||||
- Input buffer: compressed size
|
||||
- Output buffer: uncompressed size
|
||||
- LZMA Internal Structures: state_size (16 KB for default settings)
|
||||
|
||||
Interface:
|
||||
int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
In:
|
||||
dest - output data
|
||||
destLen - output data size
|
||||
src - input data
|
||||
srcLen - input data size
|
||||
propData - LZMA properties (5 bytes)
|
||||
propSize - size of propData buffer (5 bytes)
|
||||
finishMode - It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
You can use LZMA_FINISH_END, when you know that
|
||||
current output buffer covers last bytes of stream.
|
||||
alloc - Memory allocator.
|
||||
|
||||
Out:
|
||||
destLen - processed output size
|
||||
srcLen - processed input size
|
||||
|
||||
Output:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
|
||||
If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
|
||||
Multi-call State Decompressing (zlib-like interface)
|
||||
----------------------------------------------------
|
||||
|
||||
When to use: file->file decompressing
|
||||
Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
|
||||
|
||||
Memory Requirements:
|
||||
- Buffer for input stream: any size (for example, 16 KB)
|
||||
- Buffer for output stream: any size (for example, 16 KB)
|
||||
- LZMA Internal Structures: state_size (16 KB for default settings)
|
||||
- LZMA dictionary (dictionary size is encoded in LZMA properties header)
|
||||
|
||||
1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
|
||||
unsigned char header[LZMA_PROPS_SIZE + 8];
|
||||
ReadFile(inFile, header, sizeof(header)
|
||||
|
||||
2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
|
||||
|
||||
CLzmaDec state;
|
||||
LzmaDec_Constr(&state);
|
||||
res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
|
||||
if (res != SZ_OK)
|
||||
return res;
|
||||
|
||||
3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
|
||||
|
||||
LzmaDec_Init(&state);
|
||||
for (;;)
|
||||
{
|
||||
...
|
||||
int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
4) Free all allocated structures
|
||||
LzmaDec_Free(&state, &g_Alloc);
|
||||
|
||||
Look example code:
|
||||
C/Util/Lzma/LzmaUtil.c
|
||||
|
||||
|
||||
How To compress data
|
||||
--------------------
|
||||
|
||||
Compile files:
|
||||
7zTypes.h
|
||||
Threads.h
|
||||
LzmaEnc.h
|
||||
LzmaEnc.c
|
||||
LzFind.h
|
||||
LzFind.c
|
||||
LzFindMt.h
|
||||
LzFindMt.c
|
||||
LzHash.h
|
||||
|
||||
Memory Requirements:
|
||||
- (dictSize * 11.5 + 6 MB) + state_size
|
||||
|
||||
Lzma Encoder can use two memory allocators:
|
||||
1) alloc - for small arrays.
|
||||
2) allocBig - for big arrays.
|
||||
|
||||
For example, you can use Large RAM Pages (2 MB) in allocBig allocator for
|
||||
better compression speed. Note that Windows has bad implementation for
|
||||
Large RAM Pages.
|
||||
It's OK to use same allocator for alloc and allocBig.
|
||||
|
||||
|
||||
Single-call Compression with callbacks
|
||||
--------------------------------------
|
||||
|
||||
Look example code:
|
||||
C/Util/Lzma/LzmaUtil.c
|
||||
|
||||
When to use: file->file compressing
|
||||
|
||||
1) you must implement callback structures for interfaces:
|
||||
ISeqInStream
|
||||
ISeqOutStream
|
||||
ICompressProgress
|
||||
ISzAlloc
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
||||
CFileSeqInStream inStream;
|
||||
CFileSeqOutStream outStream;
|
||||
|
||||
inStream.funcTable.Read = MyRead;
|
||||
inStream.file = inFile;
|
||||
outStream.funcTable.Write = MyWrite;
|
||||
outStream.file = outFile;
|
||||
|
||||
|
||||
2) Create CLzmaEncHandle object;
|
||||
|
||||
CLzmaEncHandle enc;
|
||||
|
||||
enc = LzmaEnc_Create(&g_Alloc);
|
||||
if (enc == 0)
|
||||
return SZ_ERROR_MEM;
|
||||
|
||||
|
||||
3) initialize CLzmaEncProps properties;
|
||||
|
||||
LzmaEncProps_Init(&props);
|
||||
|
||||
Then you can change some properties in that structure.
|
||||
|
||||
4) Send LZMA properties to LZMA Encoder
|
||||
|
||||
res = LzmaEnc_SetProps(enc, &props);
|
||||
|
||||
5) Write encoded properties to header
|
||||
|
||||
Byte header[LZMA_PROPS_SIZE + 8];
|
||||
size_t headerSize = LZMA_PROPS_SIZE;
|
||||
UInt64 fileSize;
|
||||
int i;
|
||||
|
||||
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
|
||||
fileSize = MyGetFileLength(inFile);
|
||||
for (i = 0; i < 8; i++)
|
||||
header[headerSize++] = (Byte)(fileSize >> (8 * i));
|
||||
MyWriteFileAndCheck(outFile, header, headerSize)
|
||||
|
||||
6) Call encoding function:
|
||||
res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
|
||||
NULL, &g_Alloc, &g_Alloc);
|
||||
|
||||
7) Destroy LZMA Encoder Object
|
||||
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
|
||||
|
||||
|
||||
If callback function return some error code, LzmaEnc_Encode also returns that code
|
||||
or it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS.
|
||||
|
||||
|
||||
Single-call RAM->RAM Compression
|
||||
--------------------------------
|
||||
|
||||
Single-call RAM->RAM Compression is similar to Compression with callbacks,
|
||||
but you provide pointers to buffers instead of pointers to stream callbacks:
|
||||
|
||||
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
Return code:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
|
||||
|
||||
|
||||
Defines
|
||||
-------
|
||||
|
||||
_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
|
||||
|
||||
_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for
|
||||
some structures will be doubled in that case.
|
||||
|
||||
_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit.
|
||||
|
||||
_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type.
|
||||
|
||||
|
||||
_7ZIP_PPMD_SUPPPORT - Define it if you don't want to support PPMD method in AMSI-C .7z decoder.
|
||||
|
||||
|
||||
C++ LZMA Encoder/Decoder
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
C++ LZMA code use COM-like interfaces. So if you want to use it,
|
||||
you can study basics of COM/OLE.
|
||||
C++ LZMA code is just wrapper over ANSI-C code.
|
||||
|
||||
|
||||
C++ Notes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
|
||||
you must check that you correctly work with "new" operator.
|
||||
7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
|
||||
So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
|
||||
operator new(size_t size)
|
||||
{
|
||||
void *p = ::malloc(size);
|
||||
if (p == 0)
|
||||
throw CNewException();
|
||||
return p;
|
||||
}
|
||||
If you use MSCV that throws exception for "new" operator, you can compile without
|
||||
"NewHandler.cpp". So standard exception will be used. Actually some code of
|
||||
7-Zip catches any exception in internal code and converts it to HRESULT code.
|
||||
So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
|
||||
|
||||
---
|
||||
|
||||
http://www.7-zip.org
|
||||
http://www.7-zip.org/sdk.html
|
||||
http://www.7-zip.org/support.html
|
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _WINDOWS_H
|
||||
#define _WINDOWS_H
|
||||
|
||||
// This is a workaround for files asking to include Windows.h instead of windows.h
|
||||
// The problem is that MinGW provides only windows.h
|
||||
// LZMA SDK will fail to cross compile for Windows on Linux
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif // _WINDOWS_H
|
Loading…
Reference in new issue