From 967e1e9c136ef29f89eff8bb2daf16fefb910020 Mon Sep 17 00:00:00 2001 From: yanczi Date: Sat, 1 Nov 2025 22:30:28 +0100 Subject: [PATCH] =?UTF-8?q?Delete=20CRC.=20Przywrucono=20xxHash=20z=20paki?= =?UTF-8?q?etu=20LZ4.=20Dodano=20wst=C4=99pn=C4=85=20funkcj=C4=99=20henero?= =?UTF-8?q?wania=20pliku=20HPP=20z=20kluczem=20i=20nonce.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CreateCargo.cpp | 22 ++++++---------------- CreateCargo.h | 6 +----- DataStruct.h | 4 +--- EncryptionManager.cpp | 33 +++++++++++++++++++-------------- EncryptionManager.h | 4 ++-- ExtractCargo.cpp | 14 ++------------ ExtractCargo.h | 8 ++------ license/crc/LICENSE_1_0.txt | 23 ----------------------- license/xxhash/LICENSE.txt | 26 ++++++++++++++++++++++++++ test.hpp | 5 +++++ test.key | Bin 58 -> 70 bytes voidcmd.vcxproj | 4 ++-- 12 files changed, 66 insertions(+), 83 deletions(-) delete mode 100644 license/crc/LICENSE_1_0.txt create mode 100644 license/xxhash/LICENSE.txt create mode 100644 test.hpp diff --git a/CreateCargo.cpp b/CreateCargo.cpp index 6feb2f5..35c6a2b 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -174,8 +174,8 @@ uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector CreateCargo::ComputingHeadFiles() f.close(); //Tworzenie hashu CRC - uint32_t crc = crc32(buffor); + const uint64_t crc = XXH64(buffor.data(), buffor.size(), VERSION); //Kompresjia std::vector zip; @@ -333,16 +333,6 @@ uint64_t CreateCargo::fnv64(const std::string& data) return hash; } -//----------------------------------------------------------------------------- -// Wygenerój CRC32 HASH integralności -//----------------------------------------------------------------------------- -uint32_t CreateCargo::crc32(const std::vector& buffer) -{ - boost::crc_32_type crc; - crc.process_bytes(buffer.data(), buffer.size()); - return crc.checksum(); -} - //----------------------------------------------------------------------------- // Sprawdzanie czy plik znajduje się na liście //----------------------------------------------------------------------------- @@ -454,7 +444,7 @@ bool CreateCargo::WriteCargo() cargo.close(); // Zapisywanie klucza szyfrującego - //crypt.saveKey(catalogPath); + crypt.saveKey(catalogPath); std::cout << "The container was successfully created! " << cargoFile << std::endl; diff --git a/CreateCargo.h b/CreateCargo.h index edacd6f..9c2090b 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -30,11 +30,10 @@ #include #include #include -#include +#include #include "DataStruct.h" #include "Txtpp.h" -#include "xxhash.h" #include "CompressingManager.h" #include "EncryptionManager.h" @@ -124,9 +123,6 @@ private: // Wygenerój FNV-1a HASH uint64_t fnv64(const std::string& data); - // CRC - uint32_t crc32(const std::vector&); - // Rozdzielanie paternu od ścieżki void ExtPatternAndPathDetection(const std::vector&, std::vector&, std::vector&); diff --git a/DataStruct.h b/DataStruct.h index 8013a50..5d42cff 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -21,8 +21,6 @@ #include #include -#include - #define EXTENSION "pak" #define SIGNATURE "XPAK" @@ -64,6 +62,6 @@ struct FilesTable uint64_t hashName; uint64_t offset; uint32_t size; - uint32_t crc; + uint64_t crc; uint8_t isZip; }; \ No newline at end of file diff --git a/EncryptionManager.cpp b/EncryptionManager.cpp index 6c07730..415d54a 100644 --- a/EncryptionManager.cpp +++ b/EncryptionManager.cpp @@ -54,13 +54,9 @@ void EncryptionManager::saveKey(const std::string& path) std::time_t now = std::time(nullptr); const uint32_t time = static_cast(now); - // Przekonwertuj array z kluczem i nonce na vector char - std::vector keyVec(reinterpret_cast(key.data()), reinterpret_cast(key.data()) + key.size()); - std::vector nonceVec(reinterpret_cast(nonce.data()), reinterpret_cast(nonce.data()) + nonce.size()); - // Wygeneruj crc kluczy - const uint16_t crcKey = crc16(keyVec); - const uint16_t crcNonce = crc16(nonceVec); + const uint64_t crcKey = XXH64(key.data(), key.size(), 0); + const uint64_t crcNonce = XXH64(nonce.data(), nonce.size(), 0); // Zapisz ten śmietnik do pliku KEY std::ofstream file(path + ".key", std::ios::binary); @@ -77,18 +73,27 @@ void EncryptionManager::saveKey(const std::string& path) if (!file.good()) { std::cout << "Dupa nie zapisało" << std::endl; } file.close(); + + saveCppHeadFile(path); +} + +// Generowanie pliku nagłówkowego CPP z kluczem i nonce +void EncryptionManager::saveCppHeadFile(const std::string& path) +{ + const std::string headerText = + "// Plik wygenerowany przy wykorzystaniu exPAK\n\n" + "// Klucz deszyfrujący\n" + "const std::array key{};\n\n" + "// Ciąg nonce\n" + "const std::array nonce{};"; + + std::ofstream file(path + ".hpp"); + file << headerText; + file.close(); } // Wczytaj klucz void EncryptionManager::loadKey(const std::string& path) { -} - -// Wygeneruj CRC16 -uint16_t EncryptionManager::crc16(const std::vector& buffer) -{ - boost::crc_16_type crc; - crc.process_bytes(buffer.data(), buffer.size()); - return crc.checksum(); } \ No newline at end of file diff --git a/EncryptionManager.h b/EncryptionManager.h index da0fd7b..aa4e7ab 100644 --- a/EncryptionManager.h +++ b/EncryptionManager.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "DataStruct.h" class EncryptionManager @@ -28,5 +28,5 @@ private: bool keyReady; void generateKeys(); - uint16_t crc16(const std::vector&); + void saveCppHeadFile(const std::string&); }; \ No newline at end of file diff --git a/ExtractCargo.cpp b/ExtractCargo.cpp index 6cdf136..bf5e028 100644 --- a/ExtractCargo.cpp +++ b/ExtractCargo.cpp @@ -114,9 +114,9 @@ bool ExtractCargo::CheckCargoFile() //----------------------------------------------------------------------------- // Sprawdzanie sumy kontrolnej //----------------------------------------------------------------------------- -bool ExtractCargo::HashValid(const std::vector& data, const uint32_t& crc) +bool ExtractCargo::HashValid(const std::vector& data, const uint64_t& crc) { - uint32_t actualCrc = crc32(data); + uint64_t actualCrc = XXH64(data.data(), data.size(), VERSION); if (actualCrc != crc) { @@ -126,16 +126,6 @@ bool ExtractCargo::HashValid(const std::vector& data, const uint32_t& crc) return true; } -//----------------------------------------------------------------------------- -// Wygenerój CRC32 HASH integralności -//----------------------------------------------------------------------------- -uint32_t ExtractCargo::crc32(const std::vector& buffer) -{ - boost::crc_32_type crc; - crc.process_bytes(buffer.data(), buffer.size()); - return crc.checksum(); -} - //----------------------------------------------------------------------------- // Pobieranie nagłówków plików //----------------------------------------------------------------------------- diff --git a/ExtractCargo.h b/ExtractCargo.h index 411d160..e7d89b3 100644 --- a/ExtractCargo.h +++ b/ExtractCargo.h @@ -28,10 +28,9 @@ #include #include #include -#include +#include #include "DataStruct.h" -#include "xxhash.h" #include "CompressingManager.h" class ExtractCargo { @@ -69,10 +68,7 @@ private: void LoadFilesTable(); // Sprawdzanie sumy kontrolnej - bool HashValid(const std::vector&, const uint32_t&); - - // CRC - uint32_t crc32(const std::vector&); + bool HashValid(const std::vector&, const uint64_t&); // Utwórz katalog void CreateDirections(std::filesystem::path); diff --git a/license/crc/LICENSE_1_0.txt b/license/crc/LICENSE_1_0.txt deleted file mode 100644 index 36b7cd9..0000000 --- a/license/crc/LICENSE_1_0.txt +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/license/xxhash/LICENSE.txt b/license/xxhash/LICENSE.txt new file mode 100644 index 0000000..52b4c4e --- /dev/null +++ b/license/xxhash/LICENSE.txt @@ -0,0 +1,26 @@ +xxHash Library +Copyright (c) 2012-2021 Yann Collet +All rights reserved. + +BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/test.hpp b/test.hpp new file mode 100644 index 0000000..0751f98 --- /dev/null +++ b/test.hpp @@ -0,0 +1,5 @@ +// Plik wygenerowany przy wykorzystaniu exPAK + +const std::array key{}; + +const std::array nonce{}; \ No newline at end of file diff --git a/test.key b/test.key index c0ae0e0a614053c87cb412e1d755a9a5e38634f1..ca8b832c0c4b4d58d76f5a30dd725112bab2f559 100644 GIT binary patch literal 70 zcmV-M0J;BIOGQ~^00?jfX`LZ-b?(yL%k1P&8aTt{?`|uB%hA{}^s_Cbh==dJcN`L< cKv)sbXaQYV?VnTP#-K(bNB{r; literal 58 zcmV-A0LA}UOGQ~^0J!=8Xf^?59f1hhsV;2!Y5H+e(6toDy9#Yb6FCoIX9(83RvbMi QYRlK{K=_YqXLWO6ed?bX{r~^~ diff --git a/voidcmd.vcxproj b/voidcmd.vcxproj index b3a2f71..0d62872 100644 --- a/voidcmd.vcxproj +++ b/voidcmd.vcxproj @@ -104,7 +104,7 @@ _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 - 3rd\crc\include;3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include + 3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include;3rd\xxhash\include Console @@ -122,7 +122,7 @@ NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 - 3rd\crc\include;3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include + 3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include Console