edits
authorbdemsky <bdemsky@uci.edu>
Thu, 29 Mar 2018 18:27:55 +0000 (11:27 -0700)
committerbdemsky <bdemsky@uci.edu>
Thu, 29 Mar 2018 18:27:55 +0000 (11:27 -0700)
version2/src/C/CloudComm.cpp
version2/src/C/SecureRandom.cpp
version2/src/C/Test.ino
version2/src/C/TimingSingleton.h
version2/src/C/Transaction.cpp
version2/src/C/common.h
version2/src/C/hashtable.h
version2/src/C/pbkdf2-sha256.cpp

index 3e649c380e86fb319eeb1c1e169882e86bcea14f..9ecbd97a05cdf7deeebe003f58e7301ef012d5d5 100755 (executable)
@@ -36,12 +36,6 @@ CloudComm::CloudComm() :
 {
 }
 
-void *threadWrapper(void *cloud) {
-       CloudComm *c = (CloudComm *) cloud;
-       c->localServerWorkerFunction();
-       return NULL;
-}
-
 /**
  * Constructor for actual use. Takes in the url and password.
  */
@@ -143,7 +137,7 @@ void loopWrite(TCPClient * client, char *array, int bytestowrite) {
                        byteswritten += bytes;
                        bytestowrite -= bytes;
                } else {
-                       printf("Error in write\n");
+                       //printf("Error in write\n");
                        exit(-1);
                }
        }
@@ -157,7 +151,7 @@ void loopRead(TCPClient * client, char *array, int bytestoread) {
                        bytesread += bytes;
                        bytestoread -= bytes;
                } else {
-                       printf("Error in read\n");
+                       //printf("Error in read\n");
                        exit(-1);
                }
        }
@@ -165,7 +159,7 @@ void loopRead(TCPClient * client, char *array, int bytestoread) {
 
 WebConnection openURL(IoTString *url) {
        if (url->length() < 7 || memcmp(url->internalBytes()->internalArray(), "http://", 7)) {
-               printf("BOGUS URL\n");
+               //printf("BOGUS URL\n");
                exit(-1);
        }
        int i = 7;
@@ -174,14 +168,14 @@ WebConnection openURL(IoTString *url) {
                        break;
 
        if ( i == url->length()) {
-               printf("ERROR in openURL\n");
+               //printf("ERROR in openURL\n");
                exit(-1);
        }
 
        char *host = (char *) malloc(i - 6);
        memcpy(host, &url->internalBytes()->internalArray()[7], i - 7);
        host[i - 7] = 0;
-       printf("%s\n", host);
+       //printf("%s\n", host);
 
        char *message = (char *)malloc(sizeof("POST  HTTP/1.1\r\n") + sizeof("Host: \r\n") + 2 * url->length());
 
@@ -215,12 +209,7 @@ TCPClient createSocket(IoTString *name, int port) {
        char *host = (char *) malloc(name->length() + 1);
        memcpy(host, name->internalBytes()->internalArray(), name->length());
        host[name->length()] = 0;
-       printf("%s\n", host);
-       /* How big is the message? */
-
-       /* create the socket */
-       int sockfd = socket(AF_INET, SOCK_STREAM, 0);
-       if (sockfd < 0) {printf("ERROR opening socket\n"); exit(-1);}
+       //printf("%s\n", host);
 
        /* lookup the ip address */
        TCPClient client;
@@ -232,15 +221,6 @@ TCPClient createSocket(IoTString *name, int port) {
        return client;
 }
 
-TCPServer createSocket(int port) {
-       int fd;
-       TCPServer server = TCPServer(port);
-       server.begin();
-
-       return server;
-}
-
-
 void writeSocketData(TCPClient * fd, Array<char> *data) {
        loopWrite(fd, data->internalArray(), data->length());
 }
@@ -299,7 +279,7 @@ void readLine(WebConnection *wc, char *response, int numBytes) {
                if (bytes <= 0)
                        break;
                if (offset == (numBytes - 1)) {
-                       printf("Response too long");
+                       //printf("Response too long");
                        exit(-1);
                }
                response[offset++] = newchar;
@@ -314,7 +294,7 @@ int getResponseCode(WebConnection *wc) {
        readLine(wc, response, sizeof(response));
        int ver1 = 0, ver2 = 0, respcode = 0;
        sscanf(response, "HTTP/%d.%d %d", &ver1, &ver2, &respcode);
-       printf("Response code %d\n", respcode);
+       //printf("Response code %d\n", respcode);
        return respcode;
 }
 
@@ -642,7 +622,7 @@ Array<char> *CloudComm::sendLocalData(Array<char> *sendData, int64_t localSequen
        if (salt == NULL)
                return NULL;
        //      try {
-               printf("Passing Locally\n");
+       //printf("Passing Locally\n");
                mac->update(sendData, 0, sendData->length());
                Array<char> *genmac = mac->doFinal();
                Array<char> *totalData = new Array<char>(sendData->length() + genmac->length());
@@ -689,71 +669,6 @@ Array<char> *CloudComm::sendLocalData(Array<char> *sendData, int64_t localSequen
        return NULL;
 }
 
-void CloudComm::localServerWorkerFunction() {
-       /*      int inputSocket = -1;
-       
-       try {
-               // Local server socket
-               inputSocket = createSocket(listeningPort);
-       } catch (Exception *e) {
-               throw new Error("Local server setup failure...");
-       }
-       
-       while (!doEnd) {
-               try {
-                       // Accept incoming socket
-                       int socket = acceptSocket(inputSocket);
-                       
-                       // Get the encrypted data from the server
-                       int dataSize = readSocketInt(socket);
-                       Array<char> *readData = new Array<char>(dataSize);
-                       readSocketData(socket, readData);
-                       timer->endTime();
-                       
-                       // Decrypt the data
-                       readData = stripIVAndDecryptSlot(readData);
-                       mac->update(readData, 0, readData->length() - CloudComm_HMAC_SIZE);
-                       Array<char> *genmac = mac->doFinal();
-                       Array<char> *recmac = new Array<char>(CloudComm_HMAC_SIZE);
-                       System_arraycopy(readData, readData->length() - recmac->length(), recmac, 0, recmac->length());
-
-                       if (!recmac->equals(genmac))
-                               //                              throw new Error("Local Error: Invalid HMAC!  Potential Attack!");
-                               error("Local Error: Invalid HMAC!  Potential Attack!\n");
-
-                       Array<char> *returnData = new Array<char>(readData->length() - recmac->length());
-                       System_arraycopy(readData, 0, returnData, 0, returnData->length());
-
-                       // Process the data
-                       Array<char> *sendData = table->acceptDataFromLocal(returnData);
-                       mac->update(sendData, 0, sendData->length());
-                       Array<char> *realmac = mac->doFinal();
-                       Array<char> *totalData = new Array<char>(sendData->length() + realmac->length());
-                       System_arraycopy(sendData, 0, totalData, 0, sendData->length());
-                       System_arraycopy(realmac, 0, totalData, sendData->length(), realmac->length());
-
-                       // Encrypt the data for sending
-                       Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
-                       Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
-
-                       timer->startTime();
-                       // Send data to output (length of data, the data)
-                       writeSocketInt(socket, encryptedData->length());
-                       writeSocketData(socket, encryptedData);
-                       close(socket);
-               } catch (Exception *e) {
-               }
-       }
-       
-       if (inputSocket != -1) {
-               try {
-                       close(inputSocket);
-               } catch (Exception *e) {
-                       throw new Error("Local server close failure...");
-               }
-               }*/
-}
-
 void CloudComm::closeCloud() {
        doEnd = true;
 
index 9336b338394d388b0c0c0f568364eb28a0703d05..6cf331b7a9acb3f13df04837fd52f96ed623a41a 100755 (executable)
@@ -1,14 +1,18 @@
 #include "SecureRandom.h"
 #include <stdlib.h>
+#include "application.h"
 //#include <bsd/stdlib.h>
 
 SecureRandom::SecureRandom() {
 }
 
 void SecureRandom::nextBytes(Array<char> *array) {
-       arc4random_buf(array->internalArray(), array->length());
+       uint len = array->length();
+       for(uint i=0; i<len; i++) {
+               array->internalArray()[i] = (char) random(256);
+       }
 }
 
 int32_t SecureRandom::nextInt(int32_t val) {
-       return arc4random_uniform(val);
+       return random(val);
 }
index 43780813f895ad24c8eb432970176bc2fc36dab6..1d31229e9cb97b942f05c8be315328e3e41606c6 100644 (file)
@@ -20,18 +20,14 @@ void setup() {
        IoTString * password = new IoTString("reallysecret");
        t1 = new Table(baseurl, password, 321, -1);
        t1->initTable();
-       printf("T1 Ready\n");
 
        t2 = new Table(baseurl, password, 351, -1);
        t2->update();
-       printf("T2 Ready\n");
 
        delete baseurl; delete password;
 
        // Make the Keys
-       printf("Setting up keys\n");
        for (int i = 0; i < NUMBER_OF_TESTS; i++) {
-               printf("%d\n",i);
                char buffer[80];
                sprintf(buffer, "a%d", i);
                IoTString *ia = new IoTString(buffer);
@@ -56,9 +52,7 @@ void setup() {
 void loop() {
        
        // Do Updates for the keys
-       printf("Setting Key-Values...\n");
        for (int i = 0; i < NUMBER_OF_TESTS; i++) {
-               printf("%d\n", i);
                char buffer[80];
                sprintf(buffer, "a%d", i);
                IoTString * iKeyA = new IoTString(buffer);
@@ -97,11 +91,9 @@ void loop() {
                delete iKeyD; delete iValueD;
        }
        
-       printf("Updating Clients...\n");
        t1->update();
        t2->update();
        
-       printf("Checking Key-Values...\n");
        for (int i = 0; i < NUMBER_OF_TESTS; i++) {
                char buffer[80];
                sprintf(buffer, "a%d", i);
@@ -131,42 +123,42 @@ void loop() {
                IoTString *testValD2 = t2->getCommitted(iKeyD);
                
                if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
-                       printf("Key-Value t1 incorrect: keyA\n");
+               //                      printf("Key-Value t1 incorrect: keyA\n");
                        foundError = true;
                }
                
                if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
-                       printf("Key-Value t1 incorrect: keyB\n");
+               //                      printf("Key-Value t1 incorrect: keyB\n");
                        foundError = true;
                }
 
                if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) {
-                       printf("Key-Value t1 incorrect: keyC\n");
+               //                      printf("Key-Value t1 incorrect: keyC\n");
                        foundError = true;
                }
                
                if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) {
-                       printf("Key-Value t1 incorrect: keyD\n");
+               //                      printf("Key-Value t1 incorrect: keyD\n");
                        foundError = true;
                }
                
                if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) {
-                       printf("Key-Value t2 incorrect: keyA     testValA2\n");
+               //                      printf("Key-Value t2 incorrect: keyA     testValA2\n");
                        foundError = true;
                }
                
                if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) {
-                       printf("Key-Value t2 incorrect: keyB     testValB2\n");
+//                     printf("Key-Value t2 incorrect: keyB     testValB2\n");
                        foundError = true;
                }
                
                if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) {
-                       printf("Key-Value t2 incorrect: keyC     testValC2\n");
+               //                      printf("Key-Value t2 incorrect: keyC     testValC2\n");
                        foundError = true;
                }
                
                if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) {
-                       printf("Key-Value t2 incorrect: keyD     testValD2\n");
+//                     printf("Key-Value t2 incorrect: keyD     testValD2\n");
                        foundError = true;
                }
                delete iKeyA; delete iValueA;
@@ -183,15 +175,14 @@ void loop() {
                TransactionStatus * status = transStatusList->get(i);
                if (status->getStatus() != TransactionStatus_StatusCommitted) {
                        foundError = true;
-                       printf("Status error\n");
+//                     printf("Status error\n");
                }
                delete status;
        }
        
        if (foundError) {
-               printf("Found Errors...\n");
+//             printf("Found Errors...\n");
        } else {
-               printf("No Errors Found...\n");
        }
 
        transStatusList->clear();
index c9189c2f8a887a6417bc709517aa921523856cd4..945f90ae6a0a70b191dc615a575a2ab5f5886627 100755 (executable)
@@ -15,8 +15,7 @@ public:
        int64_t nanoTime() {
                int64_t time;
                struct timeval tv;
-               gettimeofday(&tv, NULL);
-               return tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+               return 0;
        }
 
        void startTime() {
@@ -32,8 +31,5 @@ public:
        }
 };
 
-TimingSingleton t_singleton;
-TimingSingleton *TimingSingleton_getInstance() {
-       return &t_singleton;
-}
+TimingSingleton * TimingSingleton_getInstance();
 #endif
index e11bbc8d208557e1e72779dd8bb5469be35e995b..ed31b775bfa4be9a549f94adbc717aab418c1745 100755 (executable)
@@ -58,7 +58,7 @@ Transaction::~Transaction() {
 
 void Transaction::addPartEncode(TransactionPart *newPart) {
        newPart->acquireRef();
-       printf("Add part %d\n", newPart->getPartNumber());
+       //printf("Add part %d\n", newPart->getPartNumber());
        TransactionPart *old = parts->setExpand(newPart->getPartNumber(), newPart);
        if (old == NULL) {
                partCount++;
@@ -327,9 +327,9 @@ bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *, uintptr_t, 0,
 
 
                                if (kv != NULL) {
-                                       printf("%s      %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
+                                       //printf("%s      %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
                                } else {
-                                       printf("%s      null\n", kvGuard->getValue()->internalBytes()->internalArray());
+                                       //printf("%s      null\n", kvGuard->getValue()->internalBytes()->internalArray());
                                }
                                delete kvit;
                                return false;
index 134c13be3be89cbbb4037f81db936a8237f5fe2d..d6aff0a982f10cc886274a4a7cea34df8713fc72 100755 (executable)
@@ -4,13 +4,10 @@
 
 //typedef uint32_t uint;
 #define CMEMALLOC ;
-#define model_print printf
 #define ASSERT(expr) \
        do {                         \
                if (!(expr)) {                                                      \
-                       fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
-                       /* print_trace(); // Trace printing may cause dynamic memory allocation */ \
-                       exit(EXIT_FAILURE);                                               \
+                       exit(EXIT_FAILURE);                                                                                                                                                                                             \
                }                                                                   \
        } while (0)
 
@@ -20,7 +17,6 @@
 
 #define myerror(msg)                                                                                                                   \
        do {                                                                                                                                                                    \
-               printf(msg);                                                                                                                            \
                exit(-1);                                                                                                                                               \
        } while(0)                                                                                                                                              
                
index 868060c17417cf6b1c71d2ca8c18c23d7384b67b..e82874680981b741db3f8a7806955a092257bbde 100755 (executable)
@@ -412,7 +412,6 @@ public:
                unsigned int oldcapacity = capacity;
 
                if ((newtable = (struct Hashlistnode<_Key, _Val> *)ourcalloc(newsize, sizeof(struct Hashlistnode<_Key, _Val>))) == NULL) {
-                       model_print("calloc error %s %d\n", __FILE__, __LINE__);
                        exit(EXIT_FAILURE);
                }
 
index 2a78fa0d57244513d6fcd8fdc4d9f6e2914b258e..01156408baf63ce2c99e7ac6bbc5db552ecf7c02 100755 (executable)
@@ -649,7 +649,6 @@ typedef struct {
 
 int do_test(testvector *tv)
 {
-       printf("Started %s\n", tv->t);
        fflush(stdout);
        char *key = malloc(tv->dkLen);
        if (key == 0) {
@@ -684,7 +683,8 @@ int main()
                k = i < 3;
 
                if (verbose != 0)
-                       printf("  SHA-%d test #%d: ", 256 - k * 32, j + 1);
+                       ;
+                       //                      printf("  SHA-%d test #%d: ", 256 - k * 32, j + 1);
 
                sha2_starts(&ctx, k);
 
@@ -701,25 +701,25 @@ int main()
 
                if (memcmp(sha2sum, sha2_test_sum[i], 32 - k * 4) != 0) {
                        if (verbose != 0)
-                               printf("failed\n");
+                               ;
+                       //printf("failed\n");
 
                        return (1);
                }
 
                if (verbose != 0)
-                       printf("passed\n");
+                       ;//printf("passed\n");
        }
 
        if (verbose != 0)
-               printf("\n");
+               ;//printf("\n");
 
        for (i = 0; i < 14; i++) {
                j = i % 7;
                k = i < 7;
 
                if (verbose != 0)
-                       printf("  HMAC-SHA-%d test #%d: ", 256 - k * 32,
-                                                j + 1);
+                       ;//printf("  HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1);
 
                if (j == 5 || j == 6) {
                        memset(buf, '\xAA', buflen = 131);
@@ -737,17 +737,17 @@ int main()
 
                if (memcmp(sha2sum, sha2_hmac_test_sum[i], buflen) != 0) {
                        if (verbose != 0)
-                               printf("failed\n");
+                               ;//printf("failed\n");
 
                        return (1);
                }
 
                if (verbose != 0)
-                       printf("passed\n");
+                       ;//printf("passed\n");
        }
 
        if (verbose != 0)
-               printf("\n");
+               ;//printf("\n");
 
        testvector *tv = 0;
        int res = 0;
@@ -764,7 +764,7 @@ int main()
        tv = &t1;
        res = do_test(tv);
        if (res != 0) {
-               printf("%s failed\n", tv->t);
+               ;//printf("%s failed\n", tv->t);
                return res;
        }
 
@@ -781,7 +781,7 @@ int main()
        tv = &t2;
        res = do_test(tv);
        if (res != 0) {
-               printf("%s failed\n", tv->t);
+               ;//printf("%s failed\n", tv->t);
                return res;
        }
 
@@ -798,7 +798,7 @@ int main()
        tv = &t3;
        res = do_test(tv);
        if (res != 0) {
-               printf("%s failed\n", tv->t);
+               ;//printf("%s failed\n", tv->t);
                return res;
        }
 
@@ -815,7 +815,7 @@ int main()
        tv = &t4;
        // res = do_test(tv);
        if (res != 0) {
-               printf("%s failed\n", tv->t);
+               ;//printf("%s failed\n", tv->t);
                return res;
        }
 
@@ -834,7 +834,7 @@ int main()
        tv = &t5;
        res = do_test(tv);
        if (res != 0) {
-               printf("%s failed\n", tv->t);
+               ;//printf("%s failed\n", tv->t);
                return res;
        }
 
@@ -849,7 +849,7 @@ int main()
        tv = &t6;
        res = do_test(tv);
        if (res != 0) {
-               printf("%s failed\n", tv->t);
+               ;//printf("%s failed\n", tv->t);
                return res;
        }