Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
659 changes: 165 additions & 494 deletions ext/lzma_sdk_wrapper/cpp_bridge.cpp

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions ext/lzma_sdk_wrapper/cpp_bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
#include <vector>
#include <memory>

/* 7-Zip SDK includes */
extern "C" {
#include "lzma_sdk/C/7z.h"
#include "lzma_sdk/C/7zAlloc.h"
#include "lzma_sdk/C/7zCrc.h"
#include "lzma_sdk/C/7zFile.h"
#include "lzma_sdk/C/7zVersion.h"
}

namespace LzmaSdkWrapper {

/**
Expand Down Expand Up @@ -72,6 +63,7 @@ class ArchiveReader : public ArchiveHandle {
std::string errorMessage;
std::string password;
std::string archivePath; // Store archive path for C++ API reopening
int archiveFormat; // Store format for GUID initialization (SZ_FORMAT_*)
SzProgressCallback progressCallback;
void* progressUserData;

Expand All @@ -80,9 +72,9 @@ class ArchiveReader : public ArchiveHandle {
std::vector<uint8_t> memoryBuffer; // Owned copy of archive data
void* memoryArchive; // IInArchive pointer for memory-based archives

// File-based C++ API cache (for password-protected archives)
void* fileArchive; // IInArchive pointer cached for file-based password extraction
void* fileStream; // IInStream pointer cached for file-based password extraction
// File-based C++ API cache
void* fileArchive; // IInArchive pointer for file-based archives
void* fileStream; // IInStream pointer for file-based archives
};

/**
Expand Down
28 changes: 16 additions & 12 deletions ext/lzma_sdk_wrapper/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def detect_platform
when :linux
$CXXFLAGS << " -std=c++11"
$CFLAGS << " -std=c11"
$LDFLAGS << " -lstdc++"
$LDFLAGS << " -lstdc++ -lpthread"

when :windows
if RbConfig::CONFIG["CC"] =~ /gcc|g\+\+/ # MinGW
Expand Down Expand Up @@ -137,6 +137,8 @@ def detect_platform
"lzma_sdk/CPP/7zip/Common",
"lzma_sdk/CPP/7zip/Archive/Common",
"lzma_sdk/CPP/7zip/Archive/7z",
"lzma_sdk/CPP/7zip/Archive/Zip",
"lzma_sdk/CPP/7zip/Archive/Tar",
"lzma_sdk/CPP/7zip/Compress",
"lzma_sdk/CPP/7zip/Crypto",
]
Expand All @@ -160,17 +162,19 @@ def detect_platform
# However, SOME Windows files are Windows-only (need ShlObj.h, CreateFileMapping, etc.)
# so we use a whitelist approach for cross-platform files:
windows_cross_platform = [
"FileDir.cpp", # Cross-platform directory operations
"FileFind.cpp", # Cross-platform file finding
"FileIO.cpp", # Cross-platform file I/O
"FileName.cpp", # Cross-platform filename handling
"PropVariant.cpp", # Cross-platform property variants
"PropVariantConv.cpp", # Cross-platform property conversion
"System.cpp", # Cross-platform system info
"TimeUtils.cpp", # Cross-platform time utilities
"ErrorMsg.cpp", # Cross-platform error messages
"FileSystem.cpp", # Cross-platform filesystem operations
"SystemInfo.cpp", # Cross-platform system information
"FileDir.cpp", # Cross-platform directory operations
"FileFind.cpp", # Cross-platform file finding
"FileIO.cpp", # Cross-platform file I/O
"FileName.cpp", # Cross-platform filename handling
"PropVariant.cpp", # Cross-platform property variants
"PropVariantConv.cpp", # Cross-platform property conversion
"PropVariantUtils.cpp", # Cross-platform property variant utilities (used by Zip handler)
"Synchronization.cpp", # Cross-platform synchronization (WFMO vtables needed by MemBlocks, OutMemStream)
"System.cpp", # Cross-platform system info
"TimeUtils.cpp", # Cross-platform time utilities
"ErrorMsg.cpp", # Cross-platform error messages
"FileSystem.cpp", # Cross-platform filesystem operations
"SystemInfo.cpp", # Cross-platform system information
]
windows_cross_platform.each do |file|
lzma_cpp_files << "lzma_sdk/CPP/Windows/#{file}"
Expand Down
105 changes: 105 additions & 0 deletions ext/lzma_sdk_wrapper/lzma_sdk/C/Blake2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* Blake2.h -- BLAKE2sp Hash
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This directory contains lzma_sdk files that were added for Zip support - ignore the source changes in lzma_sdk (unless you want to learn more about 7zip's SDK)

2024-01-17 : Igor Pavlov : Public domain */

#ifndef ZIP7_INC_BLAKE2_H
#define ZIP7_INC_BLAKE2_H

#include "7zTypes.h"

#if 0
#include "Compiler.h"
#include "CpuArch.h"
#if defined(MY_CPU_X86_OR_AMD64)
#if defined(__SSE2__) \
|| defined(_MSC_VER) && _MSC_VER > 1200 \
|| defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 30300) \
|| defined(__clang__) \
|| defined(__INTEL_COMPILER)
#include <emmintrin.h> // SSE2
#endif

#if defined(__AVX2__) \
|| defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40900) \
|| defined(Z7_APPLE_CLANG_VERSION) && (Z7_APPLE_CLANG_VERSION >= 40600) \
|| defined(Z7_LLVM_CLANG_VERSION) && (Z7_LLVM_CLANG_VERSION >= 30100) \
|| defined(Z7_MSC_VER_ORIGINAL) && (Z7_MSC_VER_ORIGINAL >= 1800) \
|| defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1400)
#include <immintrin.h>
#if defined(__clang__)
#include <avxintrin.h>
#include <avx2intrin.h>
#endif
#endif // avx2
#endif // MY_CPU_X86_OR_AMD64
#endif // 0

EXTERN_C_BEGIN

#define Z7_BLAKE2S_BLOCK_SIZE 64
#define Z7_BLAKE2S_DIGEST_SIZE 32
#define Z7_BLAKE2SP_PARALLEL_DEGREE 8
#define Z7_BLAKE2SP_NUM_STRUCT_WORDS 16

#if 1 || defined(Z7_BLAKE2SP_USE_FUNCTIONS)
typedef void (Z7_FASTCALL *Z7_BLAKE2SP_FUNC_COMPRESS)(UInt32 *states, const Byte *data, const Byte *end);
typedef void (Z7_FASTCALL *Z7_BLAKE2SP_FUNC_INIT)(UInt32 *states);
#endif

// it's required that CBlake2sp is aligned for 32-bytes,
// because the code can use unaligned access with sse and avx256.
// but 64-bytes alignment can be better.
MY_ALIGN(64)
typedef struct
{
union
{
#if 0
#if defined(MY_CPU_X86_OR_AMD64)
#if defined(__SSE2__) \
|| defined(_MSC_VER) && _MSC_VER > 1200 \
|| defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 30300) \
|| defined(__clang__) \
|| defined(__INTEL_COMPILER)
__m128i _pad_align_128bit[4];
#endif // sse2
#if defined(__AVX2__) \
|| defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40900) \
|| defined(Z7_APPLE_CLANG_VERSION) && (Z7_APPLE_CLANG_VERSION >= 40600) \
|| defined(Z7_LLVM_CLANG_VERSION) && (Z7_LLVM_CLANG_VERSION >= 30100) \
|| defined(Z7_MSC_VER_ORIGINAL) && (Z7_MSC_VER_ORIGINAL >= 1800) \
|| defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1400)
__m256i _pad_align_256bit[2];
#endif // avx2
#endif // x86
#endif // 0

void * _pad_align_ptr[8];
UInt32 _pad_align_32bit[16];
struct
{
unsigned cycPos;
unsigned _pad_unused;
#if 1 || defined(Z7_BLAKE2SP_USE_FUNCTIONS)
Z7_BLAKE2SP_FUNC_COMPRESS func_Compress_Fast;
Z7_BLAKE2SP_FUNC_COMPRESS func_Compress_Single;
Z7_BLAKE2SP_FUNC_INIT func_Init;
Z7_BLAKE2SP_FUNC_INIT func_Final;
#endif
} header;
} u;
// MY_ALIGN(64)
UInt32 states[Z7_BLAKE2SP_PARALLEL_DEGREE * Z7_BLAKE2SP_NUM_STRUCT_WORDS];
// MY_ALIGN(64)
UInt32 buf32[Z7_BLAKE2SP_PARALLEL_DEGREE * Z7_BLAKE2SP_NUM_STRUCT_WORDS * 2];
} CBlake2sp;

BoolInt Blake2sp_SetFunction(CBlake2sp *p, unsigned algo);
void Blake2sp_Init(CBlake2sp *p);
void Blake2sp_InitState(CBlake2sp *p);
void Blake2sp_Update(CBlake2sp *p, const Byte *data, size_t size);
void Blake2sp_Final(CBlake2sp *p, Byte *digest);
void z7_Black2sp_Prepare(void);

EXTERN_C_END

#endif
Loading