X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspstring.cpp;h=b5949273806b61a537dfb94227f25a8404f077d3;hb=8f5efbc7aa33b792e02d01e3288f553e6e98ccaa;hp=7fa4762c5b1b873bfe734f4eec2d66dc060716a9;hpb=1031f333332cf1b09db4fd632f141143ee637c34;p=user%2Fhenk%2Fcode%2Finspircd.git 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(*i); + unsigned char b = static_cast(*j); + diff |= a ^ b; + } + + return (diff == 0); +}