From 65363bdbdec43b2efd906d8fa848fc4d69c529d2 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Sat, 22 Mar 2014 16:12:01 -0500 Subject: [PATCH] Clarify types in auth --- common/auth.c | 14 ++++++++------ common/auth.h | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/auth.c b/common/auth.c index a048c2f..a4a40cd 100644 --- a/common/auth.c +++ b/common/auth.c @@ -7,9 +7,11 @@ #include #include #include +#include #include #include "config.h" #include "configuration.h" +#include "database.h" #include "auth.h" #include "util.h" #include "md5.h" @@ -17,7 +19,7 @@ int auth_set_password(const char *username, const char *password) { char filename[FILENAME_MAX]; unsigned char pwhash[SCRYPT_OUTPUT_SIZE]; - unsigned char salt[SCRYPT_SALT_SIZE]; + uint8_t salt[SCRYPT_SALT_SIZE]; int fd, n, r; if (!valid_name(username) || !blerg_exists(username)) @@ -36,7 +38,7 @@ int auth_set_password(const char *username, const char *password) { read(fd, salt, SCRYPT_SALT_SIZE); close(fd); - r = crypto_scrypt(password, n, salt, SCRYPT_SALT_SIZE, SCRYPT_N, SCRYPT_r, SCRYPT_p, pwhash, SCRYPT_OUTPUT_SIZE); + r = crypto_scrypt((const uint8_t *)password, n, salt, SCRYPT_SALT_SIZE, SCRYPT_N, SCRYPT_r, SCRYPT_p, pwhash, SCRYPT_OUTPUT_SIZE); if (r != 0) { fprintf(stderr, "Failure in scrypt for %s\n", username); return 0; @@ -109,7 +111,7 @@ int auth_get_password(const char *username, char *password) { return 1; } -int auth_get_salt(const char *username, char *salt) { +int auth_get_salt(const char *username, uint8_t *salt) { char filename[FILENAME_MAX]; int fd, len; @@ -128,7 +130,7 @@ int auth_get_salt(const char *username, char *salt) { int auth_check_password_v0(const char *username, const char *password) { char epw[MD5_DIGEST_SIZE + 1]; - unsigned char givenpw[MD5_DIGEST_SIZE]; + char givenpw[MD5_DIGEST_SIZE]; struct MD5Context ctx; if (auth_get_password(username, epw) == 0) @@ -137,7 +139,7 @@ int auth_check_password_v0(const char *username, const char *password) { MD5Init(&ctx); MD5Update(&ctx, username, strlen(username)); MD5Update(&ctx, password, strlen(password)); - MD5Final(givenpw, &ctx); + MD5Final((unsigned char *)givenpw, &ctx); if (strncmp(givenpw, epw, MD5_DIGEST_SIZE) == 0) return 1; @@ -147,7 +149,7 @@ int auth_check_password_v0(const char *username, const char *password) { int auth_check_password_v1(const char *username, const char *password) { unsigned char epw[SCRYPT_OUTPUT_SIZE]; - unsigned char esalt[SCRYPT_SALT_SIZE]; + uint8_t esalt[SCRYPT_SALT_SIZE]; unsigned char givenpw[SCRYPT_OUTPUT_SIZE]; int r; diff --git a/common/auth.h b/common/auth.h index 24fd293..9d3fe49 100644 --- a/common/auth.h +++ b/common/auth.h @@ -4,6 +4,8 @@ #ifndef _AUTH_H #define _AUTH_H +#include + #define TOKEN_SIZE 16 #define MAX_PASSWORD_LENGTH 64 #define SCRYPT_SALT_SIZE 8 @@ -15,7 +17,7 @@ int auth_set_password(const char *username, const char *password); int auth_get_password_version(const char *username); int auth_get_password(const char *username, char *password); -int auth_get_salt(const char *username, char *salt); +int auth_get_salt(const char *username, uint8_t *salt); int auth_check_password(const char *username, const char *password); char * auth_login(const char *username, const char *password); int auth_logout(const char *username, const char *token); -- 2.25.1