diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-09-07 22:04:21 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-09-07 22:04:21 +0200 |
commit | cbba4e772ec06dff01e6c14cb036895f1923125e (patch) | |
tree | 0ffae6c23de5ad6387db10401a453f6fec2d1c46 | |
parent | b1494a5d7b2744d3a8273b929d92fe112f0ae129 (diff) |
server: Add benchmarking mode to db module
-rw-r--r-- | db.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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); |