Bug fixes + tabbing
[iotcloud.git] / version2 / src / C / Crypto.cc
index e54d541..9fe1154 100644 (file)
@@ -2,12 +2,23 @@
 #include "pbkdf2-sha256.h"
 
 AESKey::AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength) {
-       key = new Array<char>(keyLength);
+       key = new Array<char>(keyLength / 8);
        PKCS5_PBKDF2_HMAC((unsigned char *) password->internalArray(), password->length(),
                                                                                (unsigned char *) salt->internalArray(), salt->length(),
-                                                                               iterationCount, keyLength, (unsigned char *) key->internalArray());
+                                                                               iterationCount, keyLength / 8, (unsigned char *) key->internalArray());
+       aes_key_setup((BYTE *)key->internalArray(), key_schedule, keyLength);
 }
 
 AESKey::~AESKey() {
+       bzero(key->internalArray(), key->length());
        delete key;
+       bzero(key_schedule, sizeof(key_schedule));
+}
+
+WORD *AESKey::getKeySchedule() {
+       return (WORD *) &key_schedule;
+}
+
+Array<char> *AESKey::getKey() {
+       return key;
 }