diff options
Diffstat (limited to 'src/elogin/md5calc.c')
-rw-r--r-- | src/elogin/md5calc.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/elogin/md5calc.c b/src/elogin/md5calc.c index d5dbed3..a0d58e3 100644 --- a/src/elogin/md5calc.c +++ b/src/elogin/md5calc.c @@ -11,6 +11,8 @@ #include <string.h> #include <stdio.h> #include "mt_rand.h" +#include "common/memmgr.h" +#include <openssl/sha.h> #ifndef UINT_MAX #define UINT_MAX 4294967295U @@ -365,6 +367,54 @@ int pass_ok(const char *password, const char *crypted) return(0); } +/*******************************************************************************/ +// 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 (const char* message, char* outputBuffer) +{ + unsigned char obuf[SHA256_DIGEST_LENGTH]; + SHA256((const unsigned char*)(message), strlen(message), obuf); + sha256_hash_string(obuf, outputBuffer); +} + +// Hash a password with a salt. +char *SHA256_CRYPT(const char *key) +{ + char *md5str; + md5str = (char *)aMalloc((64+1)*sizeof(char)); + sha256(key, md5str); + + return(md5str); +} + +/*******************************************************************************/ + +int pass_sha256(const char *password, const char *crypted) +{ + if (!password || !crypted) + return 0; + + char *md5str; + md5str = (char *)aMalloc((64+1)*sizeof(char)); + sha256(password, md5str); + + if (!strcmp(crypted, md5str)) + return(1); + + return(0); +} + // [M|h]ashes up an IP address and a secret key // to return a hopefully unique masked IP. in_addr_t MD5_ip(char *secret, in_addr_t ip) |