Skip to content

Commit

Permalink
updated submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed Mar 24, 2023
1 parent cd8dd6f commit 75f41bc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,30 @@ clean:
@rm *.subject
@rm *.validator
@rm *.bthl
@rm FileCompare
@rm RandFile

temp-linux-test-flow:

@$(MAKE) compile CXX=clang++ TYPE=debug VERSION=portable
@$(MAKE) genkeys CXX=clang++
@$(MAKE) randfile CXX=clang++
@$(MAKE) encrypt_decrypt
@$(MAKE) checkfile CXX=clang++
@$(MAKE) vig_encrypt_decrypt
@./FileCompare
@$(MAKE) compile CXX=clang++ TYPE=debug_threads VERSION=portable
@$(MAKE) encrypt_decrypt
@./FileCompare
@$(MAKE) vig_encrypt_decrypt
@./FileCompare
@$(MAKE) compile CXX=clang++ TYPE=debug VERSION=aesni
@$(MAKE) encrypt_decrypt
@./FileCompare
@$(MAKE) vig_encrypt_decrypt
@./FileCompare
@$(MAKE) compile CXX=clang++ TYPE=debug_threads VERSION=aesni
@$(MAKE) encrypt_decrypt
@./FileCompare
@$(MAKE) vig_encrypt_decrypt
@./FileCompare
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

![Ubuntu](https://github.com/mrdcvlsc/bethela/actions/workflows/build-test.yml/badge.svg)

## **Compiles with C++14**

A simple terminal command line tool for symmetric encryption & decryption of any files

## **install in Linux**
Expand Down Expand Up @@ -52,8 +54,6 @@ make install
make uninstall
```

***If your system supports AES-NI(most modern computers does), use ```make aesni``` instead of just ```make```, this will significantly increase the performance by a very large amount***

</ul>

----------------------------------------------------
Expand Down Expand Up @@ -100,4 +100,4 @@ For more information about using AES and other info about the program use the co

```
bethela --help
```
```
2 changes: 1 addition & 1 deletion cryptos/Krypt
51 changes: 31 additions & 20 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ int main(int argc, char* args[])

auto encrypt_lambda = [&](size_t i) {
char* tbuffer = new char[BUFFER_BYTESIZE];
std::string infname(args[i]), outfname(args[i]+bconst::extension);
std::ifstream curr_file(infname,std::ios::binary);
std::string infname(args[i]), outfname(infname + bconst::extension);
std::ifstream curr_file(infname, std::ios::binary);

if (!curr_file.good()) {
std::cout <<
"The file : " << args[i] << "\n"
"The file : " << infname << "\n"
"was not encrypted...\n"
"it might be read protected, corrupted or non-existent...\n";
} else {
std::cout << "encrypting : " << args[i] << "...\n";
std::cout << "encrypting : " << infname << "...\n";

Krypt::Bytes* iv = keygen::random_bytestream_array(AES_BLOCKSIZE);

Expand All @@ -224,18 +224,21 @@ int main(int argc, char* args[])
output_file.write(reinterpret_cast<const char*>(iv),AES_BLOCKSIZE);

while (!curr_file.eof()) {
curr_file.read(tbuffer,BUFFER_BYTESIZE);
curr_file.read(tbuffer, BUFFER_BYTESIZE);
size_t read_buffer_size = curr_file.gcount();

if(!curr_file.eof() && read_buffer_size==BUFFER_BYTESIZE)
if(!curr_file.eof() && read_buffer_size == BUFFER_BYTESIZE)
{
Krypt::ByteArray cipher = blocksNoPadding.encrypt(reinterpret_cast<unsigned char*>(tbuffer),read_buffer_size,iv);
output_file.write(reinterpret_cast<char*>(cipher.array),cipher.length);
memcpy(iv,cipher.array+(BUFFER_BYTESIZE-AES_BLOCKSIZE),AES_BLOCKSIZE);
}
else if(curr_file.eof())
{
if(!read_buffer_size) continue;
if(!read_buffer_size) {
continue;
}

Krypt::ByteArray cipher = lastBlockKrypt.encrypt(reinterpret_cast<unsigned char*>(tbuffer),read_buffer_size,iv);
output_file.write(reinterpret_cast<char*>(cipher.array),cipher.length);
}
Expand All @@ -251,7 +254,7 @@ int main(int argc, char* args[])
memset((char*) tbuffer, 0x00, BUFFER_BYTESIZE);

delete [] iv;
CHECKIF_REPLACE(args[COMMAND],args[i]);
CHECKIF_REPLACE(args[COMMAND], infname);
}
delete [] tbuffer;
};
Expand All @@ -262,11 +265,13 @@ int main(int argc, char* args[])
std::cout << "------ set ------ \n";
std::vector<std::thread> threads;

for (size_t i = 0; i < processor_count; ++i) {
for (size_t i = 0; i < processor_count - 1; ++i) {
threads.push_back(std::thread(encrypt_lambda, file_tracker++));
}

for (size_t i = 0; i < processor_count; ++i) {
encrypt_lambda(file_tracker++);

for (size_t i = 0; i < processor_count - 1; ++i) {
threads[i].join();
}

Expand Down Expand Up @@ -304,24 +309,25 @@ int main(int argc, char* args[])
auto decrypt_lambda = [&](size_t i) {
char* tbuffer = new char[BUFFER_BYTESIZE];
char* filesig = new char[bconst::FILESIGNATURE.size()];

std::string infname(args[i]), outfname(args[i]);
outfname = outfname.substr(0,outfname.size()-bconst::extension.size());

std::ifstream curr_file(infname,std::ios::binary);
std::ifstream curr_file(infname, std::ios::binary);

if (!curr_file.good()) {
std::cout <<
"The file : " << args[i] << "\n"
"The file : " << infname << "\n"
"was not decrypted...\n"
"it might be read protected, corrupted or non-existent...\n";
} else {
std::cout << "decrypting : " << args[i] << "...\n";
std::cout << "decrypting : " << infname << "...\n";

curr_file.read(filesig,bconst::FILESIGNATURE.size());

if(memcmp(filesig,bconst::FILESIGNATURE.data(),bconst::FILESIGNATURE.size()))
{
std::cerr << "The file '" << args[i] << "' is not encrypted, no need to decrypt it!\n";
std::cerr << "The file '" << infname << "' is not encrypted, no need to decrypt it!\n";
}
else
{
Expand All @@ -343,9 +349,12 @@ int main(int argc, char* args[])
output_file.write(reinterpret_cast<char*>(recover.array),recover.length);
memcpy(iv,tbuffer+(BUFFER_BYTESIZE-AES_BLOCKSIZE),AES_BLOCKSIZE);
}
else if(curr_file.eof())
{
if(!read_buffer_size) continue;
else if (curr_file.eof()) {

if(!read_buffer_size) {
continue;
}

Krypt::ByteArray recover = lastBlockKrypt.decrypt(reinterpret_cast<unsigned char*>(tbuffer),read_buffer_size,iv);
output_file.write(reinterpret_cast<char*>(recover.array),recover.length);
}
Expand All @@ -360,7 +369,7 @@ int main(int argc, char* args[])
delete [] iv;

cnt++;
CHECKIF_REPLACE(args[COMMAND],args[i]);
CHECKIF_REPLACE(args[COMMAND], infname);
}

memset((char*) tbuffer, 0x00, BUFFER_BYTESIZE);
Expand All @@ -378,11 +387,13 @@ int main(int argc, char* args[])
std::cout << "------ set ------ \n";
std::vector<std::thread> threads;

for (size_t i = 0; i < processor_count; ++i) {
for (size_t i = 0; i < processor_count - 1; ++i) {
threads.push_back(std::thread(decrypt_lambda, file_tracker++));
}

for (size_t i = 0; i < processor_count; ++i) {
decrypt_lambda(file_tracker++);

for (size_t i = 0; i < processor_count - 1; ++i) {
threads[i].join();
}

Expand Down

0 comments on commit 75f41bc

Please sign in to comment.