aboutsummaryrefslogtreecommitdiff
path: root/src/inspstring.cpp
diff options
context:
space:
mode:
authorGravatar Attila Molnar2014-06-28 18:25:05 +0200
committerGravatar Attila Molnar2014-06-28 18:25:05 +0200
commit098602163498b06ec865ab02625cc0ba19f43786 (patch)
tree0adb038340313f898056f7bdd00abafb937b4291 /src/inspstring.cpp
parentm_spanningtree Send the cert fingerprint message to opers only after successf... (diff)
Add InspIRCd::TimingSafeCompare() function that compares strings in a timing-safe way
Diffstat (limited to 'src/inspstring.cpp')
-rw-r--r--src/inspstring.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/inspstring.cpp b/src/inspstring.cpp
index 7fa4762c5..b59492738 100644
--- a/src/inspstring.cpp
+++ b/src/inspstring.cpp
@@ -108,3 +108,19 @@ std::string Base64ToBin(const std::string& data_str, const char* table)
}
return rv;
}
+
+bool InspIRCd::TimingSafeCompare(const std::string& one, const std::string& two)
+{
+ if (one.length() != two.length())
+ return false;
+
+ unsigned int diff = 0;
+ for (std::string::const_iterator i = one.begin(), j = two.begin(); i != one.end(); ++i, ++j)
+ {
+ unsigned char a = static_cast<unsigned char>(*i);
+ unsigned char b = static_cast<unsigned char>(*j);
+ diff |= a ^ b;
+ }
+
+ return (diff == 0);
+}