aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/db.c b/db.c
index e58b284..6912cb4 100644
--- a/db.c
+++ b/db.c
@@ -17,6 +17,8 @@
#define MAX_DATABASE_SIZE_BYTES ((i64)2 * 1024 * 1024 * 1024)
+// #define INSECURE_PURE_SPEED
+
sqlite3 *database=NULL;
@@ -37,6 +39,13 @@ struct hashed_password {
static struct hashed_password hash_password(const char *pass) {
struct hashed_password result;
+#ifdef INSECURE_PURE_SPEED
+ int len = strlen(pass);
+ if (len > (int)crypto_pwhash_STRBYTES) len = crypto_pwhash_STRBYTES;
+ memcpy(result.str, pass, len);
+ memset(result.str + len, 0, sizeof result.str - len);
+ result.length = crypto_pwhash_STRBYTES;
+#else
int ret = crypto_pwhash_str(
result.str, pass, strlen(pass),
PASSHASH_OPSLIMIT, PASSHASH_MEMLIMIT);
@@ -45,6 +54,7 @@ static struct hashed_password hash_password(const char *pass) {
} else {
result.length = crypto_pwhash_STRBYTES;
}
+#endif
return result;
}
@@ -68,7 +78,13 @@ void db_init(void){
SQLITE(config, SQLITE_CONFIG_SERIALIZED);
SQLITE(initialize);
+#ifdef INSECURE_PURE_SPEED
+#warning INSECURE MODE, IN-MEMORY DATABASE, NO PASSWORDS CHECKED
+ fprintf(stderr, "WARNING: INSECURE MODE, IN-MEMORY DATABASE, NO PASSWORDS CHECKED\n");
+ SQLITE(open_v2, "db.db", &database,SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY, NULL);
+#else
SQLITE(open_v2, "db.db", &database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+#endif
SQLITE(busy_timeout, database, 500);
SQLITE(exec, database, "pragma foreign_keys = 1", NULL, NULL, NULL);
@@ -337,11 +353,17 @@ bool db_check_pass(i64 userid, const char *pass) {
passhash_sq = sqlite3_column_text(stmt, 0);
}
+#ifdef INSECURE_PURE_SPEED
+ (void)passhash_sq;
+ bool success = true;
+ bool rehash = false;
+#else
int ret = crypto_pwhash_str_verify((const char*)passhash_sq, pass, strlen(pass));
bool success = ret == 0;
bool rehash = success &&
crypto_pwhash_str_needs_rehash(
(const char*)passhash_sq, PASSHASH_OPSLIMIT, PASSHASH_MEMLIMIT);
+#endif
reset_stmt(stmt);