Naprawiono problem z nie grenerowaniem klucza szyfrującego
This commit is contained in:
parent
29b2460910
commit
fd42a5812a
8 changed files with 23 additions and 17 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -380,4 +380,5 @@ test7/
|
||||||
test8/
|
test8/
|
||||||
test9/
|
test9/
|
||||||
test10/
|
test10/
|
||||||
testx/
|
testx/
|
||||||
|
testv/
|
||||||
|
|
@ -13,7 +13,7 @@ ChunkManager::~ChunkManager()
|
||||||
// Dzielenie vectora na chunki dokładnie po 128KB
|
// Dzielenie vectora na chunki dokładnie po 128KB
|
||||||
// Kompresowanie chunków bez nagłówka
|
// Kompresowanie chunków bez nagłówka
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
std::vector<char> ChunkManager::chunked(const std::vector<char>& raw, const bool& encrypt)
|
std::vector<char> ChunkManager::chunked(const std::vector<char>& raw, const bool& compress, const bool& encrypt)
|
||||||
{
|
{
|
||||||
//std::vector<BlockSize> blockSizes;
|
//std::vector<BlockSize> blockSizes;
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ std::vector<char> ChunkManager::compress_data(const std::vector<char>& input)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Dekompresja blokowa
|
// Dekompresja blokowa
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
std::vector<char> ChunkManager::dechunked(const std::vector<char>& zip, const bool& encrypt)
|
std::vector<char> ChunkManager::dechunked(const std::vector<char>& zip, const bool& compress, const bool& encrypt)
|
||||||
{
|
{
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
const uint16_t chunkLen = getIntFromVector<uint16_t>(zip, offset);
|
const uint16_t chunkLen = getIntFromVector<uint16_t>(zip, offset);
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ public:
|
||||||
~ChunkManager();
|
~ChunkManager();
|
||||||
|
|
||||||
// Kompresja danych
|
// Kompresja danych
|
||||||
std::vector<char> chunked(const std::vector<char>&, const bool&);
|
std::vector<char> chunked(const std::vector<char>&, const bool&, const bool&);
|
||||||
|
|
||||||
// Dekompresja
|
// Dekompresja
|
||||||
std::vector<char> dechunked(const std::vector<char>&, const bool&);
|
std::vector<char> dechunked(const std::vector<char>&, const bool&, const bool&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EncryptionManager eman;
|
EncryptionManager eman;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ CreateCargo::CreateCargo()
|
||||||
, version(VERSION)
|
, version(VERSION)
|
||||||
, methodFlags(0)
|
, methodFlags(0)
|
||||||
, offset(0)
|
, offset(0)
|
||||||
|
, hppKey(false)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
@ -87,9 +88,9 @@ bool CreateCargo::Create(const std::string& path, const int16_t& flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zapisywanie klucza szyfruj¹cego
|
// Zapisywanie klucza szyfruj¹cego
|
||||||
if (flag == 2 || flag == 3)
|
if (flag == 2 || flag == 3 || encList.size() > 0)
|
||||||
{
|
{
|
||||||
crypt.saveKey(catalogPath);
|
crypt.saveKey(catalogPath, hppKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -194,15 +195,15 @@ void CreateCargo::computingBytes(const int16_t& flag, std::vector<char>& input,
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
output = cm.chunked(input, false);
|
output = cm.chunked(input, true, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
output = crypt.encrypt(input);
|
output = cm.chunked(input, false, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
output = crypt.encrypt(cm.chunked(input, false));
|
output = cm.chunked(input, true, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -287,6 +288,8 @@ void CreateCargo::GetFilters(const std::string& filterFile)
|
||||||
|
|
||||||
// Lista plików do pominiêcia
|
// Lista plików do pominiêcia
|
||||||
ignoreList = jslist[KEY_IGNORE].get<std::vector<std::string>>();
|
ignoreList = jslist[KEY_IGNORE].get<std::vector<std::string>>();
|
||||||
|
|
||||||
|
hppKey = jslist["keyhpp"];
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ private:
|
||||||
std::vector<std::string> filesList;
|
std::vector<std::string> filesList;
|
||||||
|
|
||||||
EncryptionManager crypt;
|
EncryptionManager crypt;
|
||||||
|
bool hppKey;
|
||||||
|
|
||||||
// listy wyj¹tków
|
// listy wyj¹tków
|
||||||
std::vector<std::string> ignoreList;
|
std::vector<std::string> ignoreList;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ EncryptionManager::EncryptionManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
keyReady = false;
|
keyReady = false;
|
||||||
|
generateKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> EncryptionManager::encrypt(const std::vector<char>& raw)
|
std::vector<char> EncryptionManager::encrypt(const std::vector<char>& raw)
|
||||||
|
|
@ -15,7 +16,7 @@ std::vector<char> EncryptionManager::encrypt(const std::vector<char>& raw)
|
||||||
std::vector<char> crypt(raw.size());
|
std::vector<char> crypt(raw.size());
|
||||||
|
|
||||||
// Generowanie kluczy
|
// Generowanie kluczy
|
||||||
generateKeys();
|
// generateKeys();
|
||||||
|
|
||||||
if (crypto_stream_chacha20_ietf_xor_ic(
|
if (crypto_stream_chacha20_ietf_xor_ic(
|
||||||
reinterpret_cast<unsigned char*>(crypt.data()),
|
reinterpret_cast<unsigned char*>(crypt.data()),
|
||||||
|
|
@ -40,7 +41,7 @@ void EncryptionManager::generateKeys()
|
||||||
keyReady = true;
|
keyReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncryptionManager::saveKey(const std::string& path)
|
void EncryptionManager::saveKey(const std::string& path, bool hpp)
|
||||||
{
|
{
|
||||||
const int sig = SIGNATURE_KEY_FILE;
|
const int sig = SIGNATURE_KEY_FILE;
|
||||||
const short ver = VERSION;
|
const short ver = VERSION;
|
||||||
|
|
@ -73,7 +74,7 @@ void EncryptionManager::saveKey(const std::string& path)
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
//saveCppHeadFile(path);
|
if (hpp) {saveCppHeadFile(path);}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generowanie pliku nag³ówkowego CPP z kluczem i nonce
|
// Generowanie pliku nag³ówkowego CPP z kluczem i nonce
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public:
|
||||||
std::vector<char> encrypt(const std::vector<char>&);
|
std::vector<char> encrypt(const std::vector<char>&);
|
||||||
std::vector<char> decrypt(const std::vector<char>&);
|
std::vector<char> decrypt(const std::vector<char>&);
|
||||||
|
|
||||||
void saveKey(const std::string&);
|
void saveKey(const std::string&, bool);
|
||||||
void loadKey(const std::string&);
|
void loadKey(const std::string&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -144,15 +144,15 @@ void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<ch
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
output = cm.dechunked(input, false);
|
output = cm.dechunked(input, true, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
output = eman.decrypt(input);
|
output = cm.dechunked(input, false, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
output = cm.dechunked(input, false);
|
output = cm.dechunked(input, true, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue