mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
AK: Add constant time equality and zero check to UFixedBigInt
This commit is contained in:
parent
590dcb0581
commit
3d561abe15
Notes:
sideshowbarker
2024-07-17 17:13:57 +09:00
Author: https://github.com/msvisser Commit: https://github.com/SerenityOS/serenity/commit/3d561abe15 Pull-request: https://github.com/SerenityOS/serenity/pull/12851 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard
1 changed files with 26 additions and 0 deletions
|
@ -764,6 +764,32 @@ public:
|
|||
return log2() / base.log2();
|
||||
}
|
||||
|
||||
constexpr u64 fold_or() const requires(IsSame<T, u64>)
|
||||
{
|
||||
return m_low | m_high;
|
||||
}
|
||||
constexpr u64 fold_or() const requires(!IsSame<T, u64>)
|
||||
{
|
||||
return m_low.fold_or() | m_high.fold_or();
|
||||
}
|
||||
constexpr bool is_zero_constant_time() const
|
||||
{
|
||||
return fold_or() == 0;
|
||||
}
|
||||
|
||||
constexpr u64 fold_xor_pair(R& other) const requires(IsSame<T, u64>)
|
||||
{
|
||||
return (m_low ^ other.low()) | (m_high ^ other.high());
|
||||
}
|
||||
constexpr u64 fold_xor_pair(R& other) const requires(!IsSame<T, u64>)
|
||||
{
|
||||
return (m_low.fold_xor_pair(other.low())) | (m_high.fold_xor_pair(other.high()));
|
||||
}
|
||||
constexpr bool is_equal_to_constant_time(R& other)
|
||||
{
|
||||
return fold_xor_pair(other) == 0;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_low;
|
||||
T m_high;
|
||||
|
|
Loading…
Add table
Reference in a new issue