#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"
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))
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;
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;
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)
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;
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;
#ifndef _AUTH_H
#define _AUTH_H
+#include <stdint.h>
+
#define TOKEN_SIZE 16
#define MAX_PASSWORD_LENGTH 64
#define SCRYPT_SALT_SIZE 8
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);