From 4327f9c0ee5f863b4e1552125338230f03768284 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Sat, 21 Mar 2009 23:59:40 +0100 Subject: Renamed passwdhash(...) function to eurephia_quick_hash(...) This to make it clearer that passwdhash(...) is not good for password hashing, but suitable when you need a quick hashing algorithm. The eurephia_quick_hash(...) are now used for password caching hashing, and is still suitable here since the salt used for the passwords are in memory only and never written to disk, as they are supposed to be temporary hashes. --- common/passwd.c | 63 +++++++++++++++++++++++++++------------------------------ common/passwd.h | 4 +--- 2 files changed, 31 insertions(+), 36 deletions(-) (limited to 'common') 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 -- cgit