diff options
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; } |