Botan 3.6.1
Crypto and TLS for C&
|
#include <ct_utils.h>
Public Member Functions | |
constexpr bool | as_bool () const |
constexpr | Choice (Choice &&other)=default |
constexpr | Choice (const Choice &other)=default |
constexpr Choice | operator! () const |
constexpr Choice | operator!= (const Choice &other) const |
constexpr Choice | operator&& (const Choice &other) const |
constexpr Choice & | operator= (Choice &&other) noexcept=default |
constexpr Choice & | operator= (const Choice &other) noexcept=default |
constexpr Choice | operator== (const Choice &other) const |
constexpr Choice | operator|| (const Choice &other) const |
constexpr uint32_t | value () const |
Return the masked value. | |
Static Public Member Functions | |
template<typename T > requires std::unsigned_integral<T> && (!std::same_as<bool, T>) | |
static constexpr Choice | from_int (T v) |
static constexpr Choice | no () |
static constexpr Choice | yes () |
A Choice is used for constant-time conditionals.
Internally it always is either |0| (all 0 bits) or |1| (all 1 bits) and measures are taken to block compilers from reasoning about the expected value of a Choice.
Definition at line 285 of file ct_utils.h.
|
constexprdefault |
Referenced by from_int(), no(), operator!(), operator!=(), operator&&(), operator||(), and yes().
|
constexprdefault |
|
inlineconstexpr |
Unsafe conversion to bool
This conversion itself is (probably) constant time, but once the choice is reduced to a simple bool, it's entirely possible for the compiler to perform range analysis on the values, since there are just the two. As a consequence even if the caller is not using this in an obviously branchy way (if(choice.as_bool()) ...
) a smart compiler may introduce branches depending on the value.
Definition at line 330 of file ct_utils.h.
Referenced by Botan::CT::Option< T >::as_optional_vartime(), and Botan::CT::Option< T >::value().
If v == 0 return an unset (false) Choice, otherwise a set Choice
Definition at line 292 of file ct_utils.h.
References Choice(), Botan::ct_is_zero(), T, and Botan::CT::value_barrier().
Referenced by Botan::CT::Mask< T >::as_choice().
|
inlinestaticconstexpr |
|
inlineconstexpr |
Definition at line 310 of file ct_utils.h.
|
inlineconstexpr |
Definition at line 318 of file ct_utils.h.
|
inlineconstexpr |
Return the masked value.
Definition at line 333 of file ct_utils.h.
References Botan::CT::value_barrier().
Referenced by Botan::CT::Mask< T >::from_choice(), operator!(), operator!=(), operator&&(), and operator||().
|
inlinestaticconstexpr |
Definition at line 306 of file ct_utils.h.
References Choice().
Referenced by Botan::CT::strip_leading_zeros().