Delete CRC. Przywrucono xxHash z pakietu LZ4. Dodano wstępną funkcję henerowania pliku HPP z kluczem i nonce.

This commit is contained in:
yanczi 2025-11-01 22:30:28 +01:00
parent a0a2f3e1d6
commit 967e1e9c13
12 changed files with 66 additions and 83 deletions

View file

@ -54,13 +54,9 @@ void EncryptionManager::saveKey(const std::string& path)
std::time_t now = std::time(nullptr);
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
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<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
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();
}