I've tried multithreading AES however it seems to crash in every once the
limit of the buffer. But I am curious why does this crash because I don't
understand why.
#ifndef _code_h_
#define _code_h_
#include <iostream>
#include <string>
#include <thread>
#include <Windows.h>
#include <stdio.h>
#include <vector>
#include <stdlib.h>
#include <fstream>
#include <array>
#include "lib/aes.h"
#include "lib/modes.h"
#include "lib/filters.h"
using namespace std;
using namespace CryptoPP;
void debugNote(string note,int value)
{
bool debugMode = false;
if(debugMode)
{
cout << note << " " << value << endl;
}
}
class stringAesCypher
{
public:
void encode (string data,string Skey,string &out)
{
byte key[16];
byte iv[16];
string bin;
string theKey(Skey);
int i(0);
theKey.append("t;rke;tlrke65409654ytr");
while(i != 16)
{
key[i] = theKey[i];
iv[i] = theKey[i];
i++;
}
// Encryptor
CryptoPP::ECB_Mode< CryptoPP::AES >::Encryption
//Encryptor( key, sizeof(key), iv );
Encryptor( key, sizeof(key));
// Encryption
CryptoPP::StringSource( data, true,
new CryptoPP::StreamTransformationFilter( Encryptor,
new CryptoPP::StringSink( out )
) // StreamTransformationFilter
); // StringSource
}
void decode (string CT,string Skey,string &out)
{
byte key[16];
byte iv[16];
string bin;
string theKey(Skey);
int i(0);
theKey.append("t;rke;tlrke65409654ytr");
while(i != 16)
{
key[i] = theKey[i];
iv[i] = theKey[i];
i++;
}
// Decryptor
CryptoPP::ECB_Mode< CryptoPP::AES >::Decryption
// Decryptor( key, sizeof(key), iv );
Decryptor( key, sizeof(key) );
// Decryption
CryptoPP::StringSource( CT, true,
new CryptoPP::StreamTransformationFilter( Decryptor,
new CryptoPP::StringSink( out )
) // StreamTransformationFilter
); // StringSource
}
};
class Core
{
private:
string theMainBuffer;
string ram[8];
long int encodeSize,decodeSize,bufferSize;
string mode;
string key;
size_t count;
int getSizeOfString(string theString)
{
return theString.length();
}
void cores(int rRam)
{
string ramTemp("");
stringAesCypher Code;
if(ram[rRam].length() != 0)
{
if(mode == "E")
{
Code.encode(ram[rRam],key,ramTemp);
}
if(mode == "D")
{
Code.decode(ram[rRam],key,ramTemp);
}
ram[rRam] = ramTemp;
debugNote("Cores active",rRam);
}
}
void startCores()
{
thread t1(&Core::cores,this,0);
thread t2(&Core::cores,this,1);
thread t3(&Core::cores,this,2);
thread t4(&Core::cores,this,3);
thread t5(&Core::cores,this,4);
thread t6(&Core::cores,this,5);
thread t7(&Core::cores,this,6);
thread t8(&Core::cores,this,7);
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
t6.join();
t7.join();
t8.join();
debugNote("Starting Cores",0);
}
void unSplitData()
{
theMainBuffer = "";
theMainBuffer.resize(0);
for(int i = 0; i != 8; i++)
{
theMainBuffer.append(ram[i]);
}
}
// This function is fucked
void splitData()
{
int div(count / 8);
int shift(0);
for(int i = 0; i != 8; i++)
{
ram[i] = theMainBuffer.substr(shift,div);
shift = shift + div;
}
debugNote("data out",0);
}
void wipeData()
{
for(int i = 0; i != 8; i++)
{
ram[i] = "";
}
}
public:
Core();
void setMode(string theMode)
{
mode = theMode;
}
void setKey(string theKey)
{
key = theKey;
}
void readFile(string inputFileName,string outputFileName)
{
int theSize(0);
if(mode == "E"){theSize = encodeSize;}
if(mode == "D"){theSize = decodeSize;}
// Size and file streams
ifstream fileStreamIn(inputFileName,ios::binary);
ofstream fileStreamOut(outputFileName,ios::binary);
// The main loop
while(fileStreamIn)
{
fileStreamIn.read(&theMainBuffer.front(),theSize);//
Reads
count = fileStreamIn.gcount();// Read ammount
theMainBuffer.resize(count);
wipeData();
splitData();
startCores();
unSplitData();
fileStreamOut.write(theMainBuffer.c_str(),theMainBuffer.
length()); // write
cout << "Buffer and read size " << theMainBuffer.length
() << " " << count << endl;
theMainBuffer = "";
}
fileStreamIn.close();
fileStreamOut.close();
}
};
Core::Core()
{
encodeSize = 100000000;
decodeSize = 100000128;
bufferSize = 100000138;
theMainBuffer.resize(bufferSize);
}
#endif
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.