commit:65363bdbdec43b2efd906d8fa848fc4d69c529d2
author:Chip Black
committer:Chip Black
date:Sat Mar 22 16:12:01 2014 -0500
parents:c1465d733ef80a19bff0056935dbf15539f122c7
Clarify types in auth
diff --git a/common/auth.c b/common/auth.c
line changes: +8/-6
index a048c2f..a4a40cd
--- a/common/auth.c
+++ b/common/auth.c
@@ -7,9 +7,11 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <crypto_scrypt.h>
 #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
line changes: +3/-1
index 24fd293..9d3fe49
--- a/common/auth.h
+++ b/common/auth.h
@@ -4,6 +4,8 @@
 #ifndef _AUTH_H
 #define _AUTH_H
 
+#include <stdint.h>
+
 #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);