diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2009-03-21 23:59:40 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-03-21 23:59:40 +0100 |
commit | 4327f9c0ee5f863b4e1552125338230f03768284 (patch) | |
tree | 6aad6d1435ef573c2021888cb827bd148b020895 /common/passwd.c | |
parent | 062a3c92343a5fa371f8637f8bca88aacca14cc4 (diff) | |
download | eurephia-4327f9c0ee5f863b4e1552125338230f03768284.tar.gz eurephia-4327f9c0ee5f863b4e1552125338230f03768284.tar.xz eurephia-4327f9c0ee5f863b4e1552125338230f03768284.zip |
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.
Diffstat (limited to 'common/passwd.c')
-rw-r--r-- | common/passwd.c | 63 |
1 files changed, 30 insertions, 33 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; } |