Bug fixes + tabbing
[iotcloud.git] / version2 / src / C / Crypto.cc
index 3c66c90..9fe1154 100644 (file)
@@ -1 +1,24 @@
 #include "Crypto.h"
+#include "pbkdf2-sha256.h"
+
+AESKey::AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength) {
+       key = new Array<char>(keyLength / 8);
+       PKCS5_PBKDF2_HMAC((unsigned char *) password->internalArray(), password->length(),
+                                                                               (unsigned char *) salt->internalArray(), salt->length(),
+                                                                               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;
+}