Add HMAC
authorbdemsky <bdemsky@uci.edu>
Fri, 2 Mar 2018 16:24:33 +0000 (08:24 -0800)
committerbdemsky <bdemsky@uci.edu>
Fri, 2 Mar 2018 16:24:33 +0000 (08:24 -0800)
version2/src/C/CloudComm.cc
version2/src/C/Crypto.cc
version2/src/C/Crypto.h
version2/src/C/Mac.h
version2/src/C/pbkdf2-sha256.cc
version2/src/C/pbkdf2-sha256.h

index b91fa4a..d1ba7ca 100644 (file)
@@ -97,7 +97,7 @@ void CloudComm::initCrypt() {
        try {
                key = initKey();
                password = NULL;// drop password
        try {
                key = initKey();
                password = NULL;// drop password
-               mac = Mac_getInstance("HmacSHA256");
+               mac = new Mac();
                mac->init(key);
        } catch (Exception *e) {
                throw new Error("Failed To Initialize Ciphers");
                mac->init(key);
        } catch (Exception *e) {
                throw new Error("Failed To Initialize Ciphers");
index e54d541..9b1da86 100644 (file)
@@ -11,3 +11,7 @@ AESKey::AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int
 AESKey::~AESKey() {
        delete key;
 }
 AESKey::~AESKey() {
        delete key;
 }
+
+Array<char> * AESKey::getKey() {
+       return key;
+}
index 27c5b4c..8f64573 100644 (file)
@@ -6,6 +6,8 @@ class AESKey {
 public:
        AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength);
        ~AESKey();
 public:
        AESKey(Array<char> *password, Array<char> *salt, int iterationCount, int keyLength);
        ~AESKey();
+       Array<char> * getKey();
+       
 private:
        Array<char> * key;
 };
 private:
        Array<char> * key;
 };
index 67543f0..cb6193b 100644 (file)
@@ -1,13 +1,15 @@
 #ifndef MAC_H
 #define MAC_H
 #include "common.h"
 #ifndef MAC_H
 #define MAC_H
 #include "common.h"
+#include "pbkdf2-sha256.h"
 
 class Mac {
 public:
 
 class Mac {
 public:
+       Mac();
        void update(Array<char> *array, int32_t offset, int32_t len);
        Array<char> *doFinal();
        void init(AESKey *key);
        void update(Array<char> *array, int32_t offset, int32_t len);
        Array<char> *doFinal();
        void init(AESKey *key);
+ private:
+       sha2_context ctx;
 };
 };
-
-Mac *Mac_getInstance(const char *);
 #endif
 #endif
index 9e201f8..cd8abeb 100644 (file)
 #include <stdlib.h>
 #include "pbkdf2-sha256.h"
 
 #include <stdlib.h>
 #include "pbkdf2-sha256.h"
 
-typedef struct {
-       unsigned long total[2]; /*!< number of bytes processed  */
-       unsigned long state[8]; /*!< intermediate digest state  */
-       unsigned char buffer[64];       /*!< data block being processed */
-
-       unsigned char ipad[64]; /*!< HMAC: inner padding        */
-       unsigned char opad[64]; /*!< HMAC: outer padding        */
-       int is224;              /*!< 0 => SHA-256, else SHA-224 */
-} sha2_context;
-
 /*
  * 32-bit integer manipulation macros (big endian)
  */
 /*
  * 32-bit integer manipulation macros (big endian)
  */
index 9a79572..183ac25 100644 (file)
@@ -1,6 +1,25 @@
 #ifndef PBKDF2_SHA256_H
 #define PBKDF2_SHA256_H
 
 #ifndef PBKDF2_SHA256_H
 #define PBKDF2_SHA256_H
 
+typedef struct {
+       unsigned long total[2]; /*!< number of bytes processed  */
+       unsigned long state[8]; /*!< intermediate digest state  */
+       unsigned char buffer[64];       /*!< data block being processed */
+
+       unsigned char ipad[64]; /*!< HMAC: inner padding        */
+       unsigned char opad[64]; /*!< HMAC: outer padding        */
+       int is224;              /*!< 0 => SHA-256, else SHA-224 */
+} sha2_context;
+
+void sha2_starts( sha2_context *ctx, int is224 );
+void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen );
+void sha2_finish( sha2_context *ctx, unsigned char output[32] );
+
+void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, size_t keylen, int is224 );
+void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, size_t ilen );
+void sha2_hmac_finish( sha2_context *ctx, unsigned char output[32] );
+
+
 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,
 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,