BLE Application to open a Garage door

Dependencies:   BLE_API Crypto RNG mbed nRF51822

Fork of BLE_LED by Bluetooth Low Energy

Revision:
13:bc1be947b497
Parent:
12:eaee29bfa1c7
--- a/SecurityService.h	Wed Aug 26 00:59:07 2015 +0000
+++ b/SecurityService.h	Sun Aug 30 01:06:17 2015 +0000
@@ -2,7 +2,7 @@
 #define __BLE_SECURITY_SERVICE_H__
 
 #include "Crypto.h"
-
+#include "Random.h"
 
 class SecurityService {
 public:
@@ -22,8 +22,10 @@
     }
     void init(char *shared_key) {
         //Initialize AES
+        uint8_t new_iv[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+        memcpy(iv, new_iv,16);
+        ble.gattServer().write(SecurityIV.getValueHandle(), (uint8_t *)iv, 16*sizeof(uint8_t));    
         setKey(shared_key);
-        genIV();    
     }
 
     void decode(uint8_t *out, uint8_t *in, uint32_t len) {
@@ -38,9 +40,9 @@
     } 
 
     void genIV() {
-        //TODO RANDOM THIS:
-        uint8_t new_iv[16] = { 0xA2, 0x68, 0x56, 0x36, 0x52, 0x18, 0x71, 0xD0, 0x23, 0x06, 0xE2, 0xEB, 0x8F, 0x70, 0x27, 0xB3 };
-        memcpy(iv, new_iv,16);
+        Random rnd;
+        rnd.init();
+        rnd.getBytes(iv, 16);
         ble.gattServer().write(SecurityIV.getValueHandle(), (uint8_t *)iv, 16*sizeof(uint8_t));    
     }