MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / constantTimeEquals

Function constantTimeEquals

app/src/Misc/PasswordHash.cpp:37–48  ·  view source on GitHub ↗

* @brief Constant-time byte-wise equality check that does not short-circuit. */

Source from the content-addressed store, hash-verified

35 * @brief Constant-time byte-wise equality check that does not short-circuit.
36 */
37static bool constantTimeEquals(const QByteArray& a, const QByteArray& b)
38{
39 if (a.size() != b.size())
40 return false;
41
42 unsigned char diff = 0;
43 const int n = a.size();
44 for (int i = 0; i < n; ++i)
45 diff |= static_cast<unsigned char>(a[i]) ^ static_cast<unsigned char>(b[i]);
46
47 return diff == 0;
48}
49
50/**
51 * @brief Generates kSaltLen bytes of cryptographically strong randomness.

Callers 2

verifyTokenMethod · 0.85
verifyPasswordMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected