UpdatedDecryp

Dependencies:   BahlDecrypModified CyaSSL mbed nRF51822

Fork of Decryptulator by Mobius IoT

Committer:
vbahl2
Date:
Tue May 09 03:06:55 2017 +0000
Revision:
13:8b706583610a
UpdatedDecryp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vbahl2 13:8b706583610a 1 #include "LookupTable.h"
vbahl2 13:8b706583610a 2 #include "sfh_mbed.h"
vbahl2 13:8b706583610a 3
vbahl2 13:8b706583610a 4 #include <iostream>
vbahl2 13:8b706583610a 5 #define LOOKUP_TABLE_SIZE 30000
vbahl2 13:8b706583610a 6
vbahl2 13:8b706583610a 7 LookupTable::LookupTable(void){
vbahl2 13:8b706583610a 8 //uint32_t * lookupTable = new int[INITIAL_LOOKUP_TABLE_SIZE];
vbahl2 13:8b706583610a 9 LookupTableStruct = new (nothrow) pair<BLEProtocol::AddressBytes_t, unsigned char *> * [LOOKUP_TABLE_SIZE];
vbahl2 13:8b706583610a 10
vbahl2 13:8b706583610a 11 if(this->LookupTableStruct == NULL){
vbahl2 13:8b706583610a 12 printf("Exception ignored, uncomment 'nothrow' for more efficient code\n\n");
vbahl2 13:8b706583610a 13 }
vbahl2 13:8b706583610a 14
vbahl2 13:8b706583610a 15 }
vbahl2 13:8b706583610a 16
vbahl2 13:8b706583610a 17 void LookupTable::clearLookupTable(void){
vbahl2 13:8b706583610a 18 for(uint32_t i = 0; i < LOOKUP_TABLE_SIZE; i++){
vbahl2 13:8b706583610a 19 delete LookupTableStruct[i];
vbahl2 13:8b706583610a 20 }
vbahl2 13:8b706583610a 21 delete [] LookupTableStruct;
vbahl2 13:8b706583610a 22 }
vbahl2 13:8b706583610a 23
vbahl2 13:8b706583610a 24 LookupTable::~LookupTable(void){
vbahl2 13:8b706583610a 25 clearLookupTable();
vbahl2 13:8b706583610a 26 }
vbahl2 13:8b706583610a 27
vbahl2 13:8b706583610a 28
vbahl2 13:8b706583610a 29 int LookupTable::insertValue(BLEProtocol::AddressBytes_t scanned_ble_address, unsigned char * encryptedCounter){
vbahl2 13:8b706583610a 30
vbahl2 13:8b706583610a 31 if(scanned_ble_address == NULL || encryptedCounter == NULL)
vbahl2 13:8b706583610a 32 return -1; //Error
vbahl2 13:8b706583610a 33
vbahl2 13:8b706583610a 34 // map<const char * data,
vbahl2 13:8b706583610a 35 uint32_t hasehdBLEAddress = hash((const char *) scanned_ble_address, 6);
vbahl2 13:8b706583610a 36 //uint32_t hashedCounter = hash(encryptedCounter,sizeof(encryptedCounter));
vbahl2 13:8b706583610a 37
vbahl2 13:8b706583610a 38 //map<BLEProtocol::AddressBytes_t, unsigned char *> indirectMap;
vbahl2 13:8b706583610a 39 uint32_t index = hasehdBLEAddress % LOOKUP_TABLE_SIZE;
vbahl2 13:8b706583610a 40 pair<BLEProtocol::AddressBytes_t, unsigned char *> tableValue;// = make_pair (scanned_ble_address,encryptedCounter); // (scanned_ble_address, encryptedCounter);
vbahl2 13:8b706583610a 41 //tableValue = make_pair(scanned_ble_address,encryptedCounter);
vbahl2 13:8b706583610a 42 tableValue = pair<BLEProtocol::AddressBytes_t, unsigned char *>(scanned_ble_address,encryptedCounter);
vbahl2 13:8b706583610a 43 LookupTableStruct[index] = &tableValue;
vbahl2 13:8b706583610a 44
vbahl2 13:8b706583610a 45 return 0; //Success
vbahl2 13:8b706583610a 46 }