summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/passwd.c63
-rw-r--r--common/passwd.h4
-rw-r--r--plugin/eurephia.c2
3 files changed, 32 insertions, 37 deletions
diff --git a/common/passwd.c b/common/passwd.c
index 00cb322..2006602 100644
--- a/common/passwd.c
+++ b/common/passwd.c
@@ -428,7 +428,7 @@ char *eurephia_pwd_crypt(eurephiaCTX *ctx, const char *key, const char *salt) {
}
-char *passwdhash(pwdHASH hashalgo, const char *salt, const char *pwd) {
+char *eurephia_quick_hash(const char *salt, const char *pwd) {
SHA512Context sha;
uint8_t sha_res[SHA512_HASH_SIZE];
char *ret = NULL, *ptr = NULL, *tmp = NULL;
@@ -439,38 +439,35 @@ char *passwdhash(pwdHASH hashalgo, const char *salt, const char *pwd) {
return NULL;
}
- switch( hashalgo ) {
- case pwdSHA512:
- if( salt != NULL ) {
- tmp = (char *) malloc(strlen_nullsafe(salt) + len + 2);
- memset(tmp, 0, strlen_nullsafe(salt) + len + 2);
- sprintf(tmp, "%s%s", pwd, salt);
- } else {
- tmp = strdup_nullsafe(pwd);
- }
- // Generate SHA512 hash of password
- memset(&sha, 0, sizeof(SHA512Context));
- memset(&sha_res, 0, sizeof(sha_res));
- SHA512Init(&sha);
- SHA512Update(&sha, tmp, len);
- SHA512Final(&sha, sha_res);
-
- // Allocate memory for the return buffer
- ret = (char *) malloc((SHA512_HASH_SIZE*2)+3);
- memset(ret, 0,(SHA512_HASH_SIZE*2)+3);
- ptr = ret;
-
- // Generate a readable string of the hash
- for( i = 0; i < SHA512_HASH_SIZE; i++ ) {
- sprintf(ptr, "%02x", sha_res[i]);
- ptr += 2;
- }
-
- // Cleanup - remove hash data from memory
- memset(&sha, 0, sizeof(SHA512Context));
- memset(&sha_res, 0, sizeof(sha_res));
- free_nullsafe(tmp);
- break;
+ if( salt != NULL ) {
+ tmp = (char *) malloc(strlen_nullsafe(salt) + len + 2);
+ memset(tmp, 0, strlen_nullsafe(salt) + len + 2);
+ sprintf(tmp, "%s%s", pwd, salt);
+ } else {
+ tmp = strdup_nullsafe(pwd);
+ }
+ // Generate SHA512 hash of password
+ memset(&sha, 0, sizeof(SHA512Context));
+ memset(&sha_res, 0, sizeof(sha_res));
+ SHA512Init(&sha);
+ SHA512Update(&sha, tmp, len);
+ SHA512Final(&sha, sha_res);
+
+ // Allocate memory for the return buffer
+ ret = (char *) malloc((SHA512_HASH_SIZE*2)+3);
+ memset(ret, 0,(SHA512_HASH_SIZE*2)+3);
+ ptr = ret;
+
+ // Generate a readable string of the hash
+ for( i = 0; i < SHA512_HASH_SIZE; i++ ) {
+ sprintf(ptr, "%02x", sha_res[i]);
+ ptr += 2;
}
+
+ // Cleanup - remove hash data from memory
+ memset(&sha, 0, sizeof(SHA512Context));
+ memset(&sha_res, 0, sizeof(sha_res));
+ free_nullsafe(tmp);
+
return ret;
}
diff --git a/common/passwd.h b/common/passwd.h
index 0f05228..15ef70a 100644
--- a/common/passwd.h
+++ b/common/passwd.h
@@ -21,9 +21,7 @@
#ifndef PASSWD_H
#define PASSWD_H
-typedef enum { pwdSHA512 } pwdHASH;
-
char *eurephia_pwd_crypt(eurephiaCTX *ctx, const char *key, const char *salt);
-char *passwdhash(pwdHASH algo, const char *salt, const char *pwd);
+char *eurephia_quick_hash(const char *salt, const char *pwd);
#endif
diff --git a/plugin/eurephia.c b/plugin/eurephia.c
index cf0fce9..e52ca19 100644
--- a/plugin/eurephia.c
+++ b/plugin/eurephia.c
@@ -386,7 +386,7 @@ int eurephia_userauth(eurephiaCTX *ctx, const char **env)
}
// Check if we have a valid password cached
- chkpwd = passwdhash(pwdSHA512, ctx->server_salt, passwd);
+ chkpwd = eurephia_quick_hash(ctx->server_salt, passwd);
// Get an authentication session, which is not a real session ticket
// but it uses almost the same system