password(NULL),
random(NULL),
salt(NULL),
- ivArray(NULL),
table(NULL),
listeningPort(-1),
doEnd(false),
password(_password->acquireRef()),
random(new SecureRandom()),
salt(NULL),
- ivArray(NULL),
table(_table),
listeningPort(_listeningPort),
doEnd(false),
delete putslot;
if (salt)
delete salt;
- if (ivArray)
- delete ivArray;
if (password)
password->releaseRef();
if (random)
return buffer->array();
}
-void CloudComm::createIV() {
- if (ivArray == NULL) {
- ivArray = new Array<char>(CloudComm_IV_SIZE);
- random->nextBytes(ivArray);
- printf("Random bytes is generated: %d\n", ivArray->length());
- }
+Array<char> *CloudComm::createIV() {
+ Array<char> *ivArray = new Array<char>(CloudComm_IV_SIZE);
+ random->nextBytes(ivArray);
+ return ivArray;
}
Array<char> *AESEncrypt(Array<char> *ivBytes, AESKey *key, Array<char> *data) {
int64_t sequencenumber = slot->getSequenceNumber();
Array<char> *slotBytes = slot->encode(mac);
//Array<char> *ivBytes = slot->getSlotCryptIV();
- //Array<char> *chars = encryptSlotAndPrependIV(slotBytes, ivBytes);
- //delete ivBytes;
- createIV();
- Array<char> *chars = encryptSlotAndPrependIV(slotBytes, ivArray);
+ Array<char> *ivBytes = createIV();
+ Array<char> *chars = encryptSlotAndPrependIV(slotBytes, ivBytes);
+ delete ivBytes;
delete slotBytes;
IoTString *url = buildRequest(true, sequencenumber, max);
timer->startTime();
// Encrypt the data for sending
//Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
- //Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
- createIV();
- Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, ivArray);
+ Array<char> *iv = createIV();
+ Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
+ delete iv;
// Open a TCP socket connection to a local device
int socket = createSocket(host, port);
// Encrypt the data for sending
//Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
- //Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
- createIV();
- Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, ivArray);
+ Array<char> *iv = createIV();
+ Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
+ delete iv;
timer->startTime();
// Send data to output (length of data, the data)