+ MD5Init(&ctx);
+ MD5Update(&ctx, username, strlen(username));
+ MD5Update(&ctx, password, strlen(password));
+ MD5Final((unsigned char *)givenpw, &ctx);
+
+ if (strncmp(givenpw, epw, MD5_DIGEST_SIZE) == 0)
+ return 1;
+ else
+ return 0;
+}
+
+int auth_get_data(const char *username, void *data, size_t data_len) {
+ char filename[FILENAME_MAX];
+ int fd;
+ int len = 0;
+
+ if (!valid_name(username))
+ return 0;
+
+ snprintf(filename, FILENAME_MAX, "%s/%s/auth", blergconf.data_path, username);
+ fd = open(filename, O_RDONLY);
+ if (fd == -1)
+ return 0;
+ flock(fd, LOCK_SH);
+ len = read(fd, data, data_len);
+ flock(fd, LOCK_UN);
+ close(fd);
+
+ if (len < 0) {
+ perror("auth_get_data");
+ return 0;
+ } else if (len < data_len) {
+ fprintf(stderr, "Short read getting auth data\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+int auth_check_scrypt(struct auth_v2 *auth, const char *username, const char *password) {
+ unsigned char givenpw[SCRYPT_OUTPUT_SIZE];
+ int r;
+
+ r = crypto_scrypt((const uint8_t *)password, strlen(password), auth->salt, SCRYPT_SALT_SIZE, SCRYPT_N, SCRYPT_r, SCRYPT_p, givenpw, SCRYPT_OUTPUT_SIZE);
+ if (r != 0) {
+ fprintf(stderr, "Failure in scrypt for %s\n", username);
+ return 0;
+ }
+
+ if (memcmp(givenpw, auth->password, SCRYPT_OUTPUT_SIZE) == 0)