edits
[iotcloud.git] / version2 / src / C / CloudComm.cc
index b91fa4ad45d0542c2eb3fc1bbbccb14ea27a34ee..3b5fb970199962959a18895dc03824a3b923ebf4 100644 (file)
@@ -9,6 +9,7 @@
 #include "Slot.h"
 #include "Crypto.h"
 #include "ByteBuffer.h"
+#include "aes.h"
 #include <sys/socket.h>
 #include <unistd.h>
 
@@ -97,7 +98,7 @@ void CloudComm::initCrypt() {
        try {
                key = initKey();
                password = NULL;// drop password
-               mac = Mac_getInstance("HmacSHA256");
+               mac = new Mac();
                mac->init(key);
        } catch (Exception *e) {
                throw new Error("Failed To Initialize Ciphers");
@@ -246,11 +247,15 @@ Array<char> *CloudComm::createIV(int64_t machineId, int64_t localSequenceNumber)
 }
 
 Array<char> *AESEncrypt(Array<char> *ivBytes, AESKey *key, Array<char> *data) {
-       return NULL;
+       Array<char> * output=new Array<char>(data->length());
+       aes_encrypt_ctr((BYTE *)data->internalArray(), data->length(), (BYTE *) output->internalArray(), (WORD *)key->getKey()->internalArray(), key->getKey()->length()/(sizeof(WORD)/sizeof(BYTE)), (BYTE *)ivBytes->internalArray());
+       return output;
 }
 
 Array<char> *AESDecrypt(Array<char> *ivBytes, AESKey *key, Array<char> *data) {
-       return NULL;
+       Array<char> * output=new Array<char>(data->length());
+       aes_decrypt_ctr((BYTE *)data->internalArray(), data->length(), (BYTE *)output->internalArray(), (WORD *)key->getKey()->internalArray(), key->getKey()->length()/(sizeof(WORD)/sizeof(BYTE)), (BYTE *)ivBytes->internalArray());
+       return output;
 }
 
 Array<char> *CloudComm::encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes) {