Calculating and storing password, salt, and key into EEPROM to not repeat this calcul...
[iotcloud.git] / version2 / src / C / Crypto.h
old mode 100644 (file)
new mode 100755 (executable)
index 27c5b4c..15931bd
@@ -1,13 +1,34 @@
 #ifndef CRYPTO_H
 #define CRYPTO_H
 #include "common.h"
+#include "aes.h"
+#include "application.h"       // Library for Particle/Arduino functions
+
+// Store these into EEPROM to avoid recalculating - crypto takes a lot of processing
+// We store the 3 items in this order: 
+// 1) SALT
+// 2) PASSWORD
+// 3) LEN
+#define SALT_LEN                       8               // 8 bytes
+#define PWD_LEN                                12              // 12 bytes
+#define KEY_LEN                                16              // 16 bytes
+#define ADDR_SALT                      0
+#define ADDR_PWD                       (ADDR_SALT + SALT_LEN)
+#define ADDR_KEY                       (ADDR_PWD + PWD_LEN)
+#define SALT_OFFSET                    0
+#define PWD_OFFSET                     (SALT_OFFSET + SALT_LEN)
+#define KEY_OFFSET                     (PWD_OFFSET + PWD_LEN)
 
 class AESKey {
 public:
        AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength);
        ~AESKey();
+       Array<char> *getKey();
+       WORD *getKeySchedule();
+
 private:
-       Array<char> * key;
+       Array<char> *key;
+       WORD key_schedule[60];
 };
 
 #endif