It has been long time I did not use c++ and I have some basic errors. Can you tell me why I get Segmentation Fault from my generic code? When I use int as a array type, it works perfectly but when I change it with "Trapdoor" type, it gives me Seg Fault.
array<array<int, colN>, rowN> SmartIds::createMatrix() {
array<array<int, colN> , rowN> a;
for(int i = 0; i < rowN; i++) {
a[i] = createTrapdoors();
}
//sort(a.begin(), a.end());
return a;
}
Below code generates seg fault
array<array<Trapdoor, colN>, rowN> SmartIds::createMatrix() {
array<array<Trapdoor, colN> , rowN> a;
for(int i = 0; i < rowN; i++) {
a[i] = createTrapdoors();
}
//sort(a.begin(), a.end());
return a;
}
I call my function like below;
auto i = createMatrix();
Trapdoor.cpp class
#include "Trapdoor.h"
#include <cryptopp/pwdbased.h>
using namespace std;
Trapdoor::Trapdoor() {
// TODO Auto-generated constructor stub
key = nullptr;
seed = nullptr;
iv = nullptr;
counter = 0;
}
Trapdoor::Trapdoor(byte* keyy, byte* ivv) {
key = keyy;
seed = keyy;
iv = ivv;
counter = 0;
}
Trapdoor::~Trapdoor() {
// TODO Auto-generated destructor stub
delete iv;
delete key;
delete seed;
}
void Trapdoor::deriveKeywithCounter() {
SecByteBlock derived(32);
PKCS5_PBKDF2_HMAC<SHA1> kdf;
//kdf.DeriveKey(derived.data(), derived.size(), 0, (byte*)b->data(), sizeof(b), NULL, 0, 100);
memset(iv, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH);
counter++;
}
int Trapdoor::getCounter() {
return counter;
}