Add key generation
authorbdemsky <bdemsky@uci.edu>
Fri, 2 Mar 2018 10:29:56 +0000 (02:29 -0800)
committerbdemsky <bdemsky@uci.edu>
Fri, 2 Mar 2018 10:29:56 +0000 (02:29 -0800)
version2/src/C/Crypto.cc
version2/src/C/Crypto.h
version2/src/C/pbkdf2-sha256.cc
version2/src/C/pbkdf2-sha256.h [new file with mode: 0644]

index 3c66c90..e54d541 100644 (file)
@@ -1 +1,13 @@
 #include "Crypto.h"
+#include "pbkdf2-sha256.h"
+
+AESKey::AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength) {
+       key = new Array<char>(keyLength);
+       PKCS5_PBKDF2_HMAC((unsigned char *) password->internalArray(), password->length(),
+                                                                               (unsigned char *) salt->internalArray(), salt->length(),
+                                                                               iterationCount, keyLength, (unsigned char *) key->internalArray());
+}
+
+AESKey::~AESKey() {
+       delete key;
+}
index 261e5a6..27c5b4c 100644 (file)
@@ -5,8 +5,9 @@
 class AESKey {
 public:
        AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength);
-
+       ~AESKey();
 private:
+       Array<char> * key;
 };
 
 #endif
index d014787..9e201f8 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "pbkdf2-sha256.h"
 
 typedef struct {
        unsigned long total[2]; /*!< number of bytes processed  */
diff --git a/version2/src/C/pbkdf2-sha256.h b/version2/src/C/pbkdf2-sha256.h
new file mode 100644 (file)
index 0000000..9a79572
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef PBKDF2_SHA256_H
+#define PBKDF2_SHA256_H
+
+void PKCS5_PBKDF2_HMAC(unsigned char *password, size_t plen,
+                                                                                        unsigned char *salt, size_t slen,
+                                                                                        const unsigned long iteration_count, const unsigned long key_length,
+                                                                                        unsigned char *output);
+
+#endif