Skip to content

Commit 234ec46

Browse files
Move timingSafeStrcmp to main
1 parent 4d0553e commit 234ec46

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/core/CNStructs.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ std::string U16toU8(char16_t* src, size_t max);
4949
size_t U8toU16(std::string src, char16_t* des, size_t max); // returns number of char16_t that was written at des
5050
time_t getTime();
5151
time_t getTimestamp();
52+
int timingSafeStrcmp(const char* a, const char* b);
5253
void terminate(int);
5354

5455
// The PROTOCOL_VERSION definition can be defined by the build system.

src/db/login.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1+
#include "core/CNStructs.hpp"
2+
13
#include "db/internal.hpp"
24

35
#include "bcrypt/BCrypt.hpp"
46

5-
static int timingSafeStrcmp(const char* a, const char* b) {
6-
int diff = 0;
7-
while (*a && *b) {
8-
diff |= *a++ ^ *b++;
9-
}
10-
diff |= *a;
11-
diff |= *b;
12-
return diff;
13-
}
14-
157
void Database::findAccount(Account* account, std::string login) {
168
std::lock_guard<std::mutex> lock(dbCrit);
179

src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ time_t getTimestamp() {
222222
return (time_t)value.count();
223223
}
224224

225+
// timing safe strcmp implementation for e.g. cookie validation
226+
int timingSafeStrcmp(const char* a, const char* b) {
227+
int diff = 0;
228+
while (*a && *b) {
229+
diff |= *a++ ^ *b++;
230+
}
231+
diff |= *a;
232+
diff |= *b;
233+
return diff;
234+
}
235+
225236
// convert integer timestamp (in s) to FF systime struct
226237
sSYSTEMTIME timeStampToStruct(uint64_t time) {
227238

0 commit comments

Comments
 (0)