summaryrefslogtreecommitdiff
path: root/src/common/md5calc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/md5calc.c')
-rw-r--r--src/common/md5calc.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/md5calc.c b/src/common/md5calc.c
index 3f9ccdc41..bbace132b 100644
--- a/src/common/md5calc.c
+++ b/src/common/md5calc.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <openssl/sha.h>
/** @file
* Implementation of the md5 interface.
@@ -259,6 +260,29 @@ static void md5_salt(int len, char *output)
}
+/*******************************************************************************/
+// SHA256 wrappers [TMW2]
+void sha256_hash_string (unsigned char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65])
+{
+ int i = 0;
+
+ for(i = 0; i < SHA256_DIGEST_LENGTH; i++)
+ {
+ sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
+ }
+
+ outputBuffer[64] = 0;
+}
+
+void sha256_hash (const char* message, char* outputBuffer)
+{
+ unsigned char obuf[SHA256_DIGEST_LENGTH];
+ SHA256((const unsigned char*)(message), strlen(message), obuf);
+ sha256_hash_string(obuf, outputBuffer);
+}
+
+/*******************************************************************************/
+
/**
* Interface base initialization.
*/
@@ -268,4 +292,6 @@ void md5_defaults(void)
md5->binary = md5_buf2binary;
md5->string = md5_string;
md5->salt = md5_salt;
+ md5->sha256 = sha256_hash;
}
+