Clarify types in auth
[blerg.git] / common / auth.c
index a048c2f..a4a40cd 100644 (file)
@@ -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;