#ifndef MAC_H
#define MAC_H
#include "common.h"
+#include "pbkdf2-sha256.h"
class Mac {
public:
+ Mac();
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
#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)
*/
#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,