summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2022-02-05 23:54:49 -0300
committerJesusaves <cpntb1@ymail.com>2022-02-05 23:54:49 -0300
commitca7b441512d5b2a67ecfa3f602a16729b7c100d9 (patch)
tree7a9dc332334a1153038d88b79d83aa2e2091b048 /src/common
parent5a4bd61515039879debc668c1934341b4bb7cbf6 (diff)
downloadhercules-ca7b441512d5b2a67ecfa3f602a16729b7c100d9.tar.gz
hercules-ca7b441512d5b2a67ecfa3f602a16729b7c100d9.tar.bz2
hercules-ca7b441512d5b2a67ecfa3f602a16729b7c100d9.tar.xz
hercules-ca7b441512d5b2a67ecfa3f602a16729b7c100d9.zip
OpenSSL is now required to build. Implement a SHA256 interface. Log chat as SHA256.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/md5calc.c26
-rw-r--r--src/common/md5calc.h7
2 files changed, 33 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;
}
+
diff --git a/src/common/md5calc.h b/src/common/md5calc.h
index bd06f1fbc..26e4fa567 100644
--- a/src/common/md5calc.h
+++ b/src/common/md5calc.h
@@ -55,6 +55,13 @@ struct md5_interface {
* @param[out] output The output buffer (at least len bytes available).
*/
void (*salt) (int len, char *output);
+
+ /**
+ * Generates a sha256 hash
+ */
+ void (*sha256) (const char* message, char* outputBuffer);
+
+
};
#ifdef HERCULES_CORE