Delete CRC. Przywrucono xxHash z pakietu LZ4. Dodano wstępną funkcję henerowania pliku HPP z kluczem i nonce.
This commit is contained in:
parent
a0a2f3e1d6
commit
967e1e9c13
12 changed files with 66 additions and 83 deletions
|
|
@ -174,8 +174,8 @@ uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector<cha
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
output = std::move(input);
|
//output = std::move(input);
|
||||||
//output = crypt.encrypt(input);
|
output = crypt.encrypt(input);
|
||||||
return RAW_FILE;
|
return RAW_FILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -188,8 +188,8 @@ uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector<cha
|
||||||
return ZIP_FILE;
|
return ZIP_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = std::move(input);
|
//output = std::move(input);
|
||||||
//output = crypt.encrypt(input);
|
output = crypt.encrypt(input);
|
||||||
return RAW_FILE;
|
return RAW_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +226,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
//Tworzenie hashu CRC
|
//Tworzenie hashu CRC
|
||||||
uint32_t crc = crc32(buffor);
|
const uint64_t crc = XXH64(buffor.data(), buffor.size(), VERSION);
|
||||||
|
|
||||||
//Kompresjia
|
//Kompresjia
|
||||||
std::vector<char> zip;
|
std::vector<char> zip;
|
||||||
|
|
@ -333,16 +333,6 @@ uint64_t CreateCargo::fnv64(const std::string& data)
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Wygenerój CRC32 HASH integralnoœci
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
uint32_t CreateCargo::crc32(const std::vector<char>& buffer)
|
|
||||||
{
|
|
||||||
boost::crc_32_type crc;
|
|
||||||
crc.process_bytes(buffer.data(), buffer.size());
|
|
||||||
return crc.checksum();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sprawdzanie czy plik znajduje się na liście
|
// Sprawdzanie czy plik znajduje się na liście
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -454,7 +444,7 @@ bool CreateCargo::WriteCargo()
|
||||||
cargo.close();
|
cargo.close();
|
||||||
|
|
||||||
// Zapisywanie klucza szyfrującego
|
// Zapisywanie klucza szyfrującego
|
||||||
//crypt.saveKey(catalogPath);
|
crypt.saveKey(catalogPath);
|
||||||
|
|
||||||
std::cout << "The container was successfully created! " << cargoFile << std::endl;
|
std::cout << "The container was successfully created! " << cargoFile << std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,10 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/crc.hpp>
|
#include <xxhash.h>
|
||||||
|
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "Txtpp.h"
|
#include "Txtpp.h"
|
||||||
#include "xxhash.h"
|
|
||||||
#include "CompressingManager.h"
|
#include "CompressingManager.h"
|
||||||
#include "EncryptionManager.h"
|
#include "EncryptionManager.h"
|
||||||
|
|
||||||
|
|
@ -124,9 +123,6 @@ private:
|
||||||
// Wygenerój FNV-1a HASH
|
// Wygenerój FNV-1a HASH
|
||||||
uint64_t fnv64(const std::string& data);
|
uint64_t fnv64(const std::string& data);
|
||||||
|
|
||||||
// CRC
|
|
||||||
uint32_t crc32(const std::vector<char>&);
|
|
||||||
|
|
||||||
// Rozdzielanie paternu od œcie¿ki
|
// Rozdzielanie paternu od œcie¿ki
|
||||||
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/crc.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
#define EXTENSION "pak"
|
#define EXTENSION "pak"
|
||||||
#define SIGNATURE "XPAK"
|
#define SIGNATURE "XPAK"
|
||||||
|
|
@ -64,6 +62,6 @@ struct FilesTable
|
||||||
uint64_t hashName;
|
uint64_t hashName;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t crc;
|
uint64_t crc;
|
||||||
uint8_t isZip;
|
uint8_t isZip;
|
||||||
};
|
};
|
||||||
|
|
@ -54,13 +54,9 @@ void EncryptionManager::saveKey(const std::string& path)
|
||||||
std::time_t now = std::time(nullptr);
|
std::time_t now = std::time(nullptr);
|
||||||
const uint32_t time = static_cast<uint32_t>(now);
|
const uint32_t time = static_cast<uint32_t>(now);
|
||||||
|
|
||||||
// Przekonwertuj array z kluczem i nonce na vector char
|
|
||||||
std::vector<char> keyVec(reinterpret_cast<const char*>(key.data()), reinterpret_cast<const char*>(key.data()) + key.size());
|
|
||||||
std::vector<char> nonceVec(reinterpret_cast<const char*>(nonce.data()), reinterpret_cast<const char*>(nonce.data()) + nonce.size());
|
|
||||||
|
|
||||||
// Wygeneruj crc kluczy
|
// Wygeneruj crc kluczy
|
||||||
const uint16_t crcKey = crc16(keyVec);
|
const uint64_t crcKey = XXH64(key.data(), key.size(), 0);
|
||||||
const uint16_t crcNonce = crc16(nonceVec);
|
const uint64_t crcNonce = XXH64(nonce.data(), nonce.size(), 0);
|
||||||
|
|
||||||
// Zapisz ten œmietnik do pliku KEY
|
// Zapisz ten œmietnik do pliku KEY
|
||||||
std::ofstream file(path + ".key", std::ios::binary);
|
std::ofstream file(path + ".key", std::ios::binary);
|
||||||
|
|
@ -77,6 +73,23 @@ void EncryptionManager::saveKey(const std::string& path)
|
||||||
if (!file.good()) { std::cout << "Dupa nie zapisa³o" << std::endl; }
|
if (!file.good()) { std::cout << "Dupa nie zapisa³o" << std::endl; }
|
||||||
|
|
||||||
file.close();
|
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<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> key{};\n\n"
|
||||||
|
"// Ci¹g nonce\n"
|
||||||
|
"const std::array<unsigned char, crypto_stream_chacha20_ietf_NONCEBYTES> nonce{};";
|
||||||
|
|
||||||
|
std::ofstream file(path + ".hpp");
|
||||||
|
file << headerText;
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wczytaj klucz
|
// Wczytaj klucz
|
||||||
|
|
@ -84,11 +97,3 @@ void EncryptionManager::loadKey(const std::string& path)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wygeneruj CRC16
|
|
||||||
uint16_t EncryptionManager::crc16(const std::vector<char>& buffer)
|
|
||||||
{
|
|
||||||
boost::crc_16_type crc;
|
|
||||||
crc.process_bytes(buffer.data(), buffer.size());
|
|
||||||
return crc.checksum();
|
|
||||||
}
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/crc.hpp>
|
#include <xxhash.h>
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
|
|
||||||
class EncryptionManager
|
class EncryptionManager
|
||||||
|
|
@ -28,5 +28,5 @@ private:
|
||||||
bool keyReady;
|
bool keyReady;
|
||||||
|
|
||||||
void generateKeys();
|
void generateKeys();
|
||||||
uint16_t crc16(const std::vector<char>&);
|
void saveCppHeadFile(const std::string&);
|
||||||
};
|
};
|
||||||
|
|
@ -114,9 +114,9 @@ bool ExtractCargo::CheckCargoFile()
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sprawdzanie sumy kontrolnej
|
// Sprawdzanie sumy kontrolnej
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool ExtractCargo::HashValid(const std::vector<char>& data, const uint32_t& crc)
|
bool ExtractCargo::HashValid(const std::vector<char>& data, const uint64_t& crc)
|
||||||
{
|
{
|
||||||
uint32_t actualCrc = crc32(data);
|
uint64_t actualCrc = XXH64(data.data(), data.size(), VERSION);
|
||||||
|
|
||||||
if (actualCrc != crc)
|
if (actualCrc != crc)
|
||||||
{
|
{
|
||||||
|
|
@ -126,16 +126,6 @@ bool ExtractCargo::HashValid(const std::vector<char>& data, const uint32_t& crc)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Wygenerój CRC32 HASH integralnoœci
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
uint32_t ExtractCargo::crc32(const std::vector<char>& buffer)
|
|
||||||
{
|
|
||||||
boost::crc_32_type crc;
|
|
||||||
crc.process_bytes(buffer.data(), buffer.size());
|
|
||||||
return crc.checksum();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Pobieranie nagłówków plików
|
// Pobieranie nagłówków plików
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,9 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/crc.hpp>
|
#include <xxhash.h>
|
||||||
|
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "xxhash.h"
|
|
||||||
#include "CompressingManager.h"
|
#include "CompressingManager.h"
|
||||||
|
|
||||||
class ExtractCargo {
|
class ExtractCargo {
|
||||||
|
|
@ -69,10 +68,7 @@ private:
|
||||||
void LoadFilesTable();
|
void LoadFilesTable();
|
||||||
|
|
||||||
// Sprawdzanie sumy kontrolnej
|
// Sprawdzanie sumy kontrolnej
|
||||||
bool HashValid(const std::vector<char>&, const uint32_t&);
|
bool HashValid(const std::vector<char>&, const uint64_t&);
|
||||||
|
|
||||||
// CRC
|
|
||||||
uint32_t crc32(const std::vector<char>&);
|
|
||||||
|
|
||||||
// Utwórz katalog
|
// Utwórz katalog
|
||||||
void CreateDirections(std::filesystem::path);
|
void CreateDirections(std::filesystem::path);
|
||||||
|
|
|
||||||
|
|
@ -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.
|
|
||||||
26
license/xxhash/LICENSE.txt
Normal file
26
license/xxhash/LICENSE.txt
Normal file
|
|
@ -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.
|
||||||
5
test.hpp
Normal file
5
test.hpp
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
// Plik wygenerowany przy wykorzystaniu exPAK
|
||||||
|
|
||||||
|
const std::array<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> key{};
|
||||||
|
|
||||||
|
const std::array<unsigned char, crypto_stream_chacha20_ietf_NONCEBYTES> nonce{};
|
||||||
BIN
test.key
BIN
test.key
Binary file not shown.
|
|
@ -104,7 +104,7 @@
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<AdditionalIncludeDirectories>3rd\crc\include;3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include;3rd\xxhash\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<AdditionalIncludeDirectories>3rd\crc\include;3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue