mirror of
https://git.tesses.org/tesses50/tessesframework.git
synced 2026-11-29 01:01:54 +00:00
Fix NX, add constant time compare, add TF_Span
This commit is contained in:
@@ -377,4 +377,20 @@ bool RandomBytes(std::vector<uint8_t> &output, std::string personal_str) {
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
bool ConstantEquals(const TF_Span<uint8_t> left, const TF_Span<uint8_t> right)
|
||||
{
|
||||
if (left.size() != right.size()) return false;
|
||||
if (left.empty()) return true;
|
||||
|
||||
const auto* pa = left.data();
|
||||
const auto* pb = right.data();
|
||||
const auto n = left.size();
|
||||
|
||||
uint8_t diff = 0;
|
||||
for (size_t i = 0; i < n; i++)
|
||||
diff |= pa[i] ^ pb[i];
|
||||
|
||||
return diff == 0;
|
||||
}
|
||||
|
||||
} // namespace Tesses::Framework::Crypto
|
||||
|
||||
Reference in New Issue
Block a user