Botan 3.1.1
Crypto and TLS for C&
|
#include <ct_utils.h>
Public Member Functions | |
T | if_not_set_return (T x) const |
T | if_set_return (T x) const |
void | if_set_zero_out (T buf[], size_t elems) |
bool | is_set () const |
Mask (const Mask< T > &other)=default | |
template<typename U > | |
Mask (Mask< U > o) | |
Mask< T > & | operator&= (Mask< T > o) |
Mask< T > & | operator= (const Mask< T > &other)=default |
Mask< T > & | operator^= (Mask< T > o) |
Mask< T > & | operator|= (Mask< T > o) |
Mask< T > | operator~ () const |
T | select (T x, T y) const |
T | select_and_unpoison (T x, T y) const |
Mask< T > | select_mask (Mask< T > x, Mask< T > y) const |
void | select_n (T output[], const T x[], const T y[], size_t len) const |
T | unpoisoned_value () const |
T | value () const |
Static Public Member Functions | |
static Mask< T > | cleared () |
template<typename U > | |
static Mask< T > | expand (Mask< U > m) |
static Mask< T > | expand (T v) |
static Mask< T > | is_any_of (T v, std::initializer_list< T > accepted) |
static Mask< T > | is_equal (T x, T y) |
static Mask< T > | is_gt (T x, T y) |
static Mask< T > | is_gte (T x, T y) |
static Mask< T > | is_lt (T x, T y) |
static Mask< T > | is_lte (T x, T y) |
static Mask< T > | is_within_range (T v, T l, T u) |
static Mask< T > | is_zero (T x) |
static Mask< T > | set () |
Friends | |
Mask< T > | operator& (Mask< T > x, Mask< T > y) |
Mask< T > | operator^ (Mask< T > x, Mask< T > y) |
Mask< T > | operator| (Mask< T > x, Mask< T > y) |
A Mask type used for constant-time operations. A Mask<T> always has value either 0 (all bits cleared) or ~0 (all bits set). All operations in a Mask<T> are intended to compile to code which does not contain conditional jumps. This must be verified with tooling (eg binary disassembly or using valgrind) since you never know what a compiler might do.
Definition at line 83 of file ct_utils.h.
|
default |
|
inlinestatic |
Return a Mask<T> with all bits cleared
Definition at line 104 of file ct_utils.h.
Referenced by Botan::low_zero_bits(), Botan::oaep_find_delim(), Botan::OneAndZeros_Padding::unpad(), and Botan::EME_PKCS1v15::unpad().
|
inlinestatic |
Return a Mask<T> which is set if m is set
Definition at line 115 of file ct_utils.h.
References T, and Botan::CT::Mask< T >::value().
Return a Mask<T> which is set if v is != 0
Definition at line 109 of file ct_utils.h.
Referenced by Botan::bigint_cnd_abs(), Botan::bigint_cnd_add(), Botan::bigint_cnd_sub(), Botan::bigint_cnd_swap(), Botan::bigint_ct_is_lt(), Botan::bigint_shl1(), Botan::bigint_shl2(), Botan::bigint_shr1(), Botan::bigint_shr2(), Botan::BigInt::cond_flip_sign(), Botan::CT::conditional_assign_mem(), Botan::CT::conditional_copy_mem(), Botan::CT::conditional_swap(), Botan::CT::copy_output(), Botan::BigInt::ct_cond_assign(), Botan::ct_divide_word(), Botan::gcd(), Botan::low_zero_bits(), Botan::redc_p521(), Botan::Sodium::sodium_is_zero(), Botan::ANSI_X923_Padding::unpad(), and Botan::OneAndZeros_Padding::unpad().
|
inline |
Return x if the mask is cleared, or otherwise zero
Definition at line 223 of file ct_utils.h.
Referenced by Botan::CT::Mask< T >::if_set_zero_out(), and Botan::EME_PKCS1v15::unpad().
|
inline |
Return x if the mask is set, or otherwise zero
Definition at line 218 of file ct_utils.h.
Referenced by Botan::oaep_find_delim().
|
inline |
If this mask is set, zero out buf, otherwise do nothing
Definition at line 253 of file ct_utils.h.
References Botan::CT::Mask< T >::if_not_set_return().
|
inlinestatic |
Definition at line 159 of file ct_utils.h.
References Botan::expand_top_bit(), and T.
Return a Mask<T> which is set if x == y
Definition at line 128 of file ct_utils.h.
References Botan::CT::Mask< T >::is_zero(), and T.
Referenced by Botan::bigint_cmp(), Botan::bigint_ct_is_lt(), Botan::TLS::check_tls_cbc_padding(), Botan::CT::copy_output(), Botan::PK_Decryptor::decrypt_or_random(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::oaep_find_delim(), Botan::redc_p521(), Botan::Sodium::sodium_compare(), Botan::PKCS7_Padding::unpad(), Botan::OneAndZeros_Padding::unpad(), Botan::ESP_Padding::unpad(), and Botan::vartime_divide().
Return a Mask<T> which is set if x > y
Definition at line 138 of file ct_utils.h.
References Botan::CT::Mask< T >::is_lt().
Referenced by Botan::CT::copy_output(), Botan::PKCS7_Padding::unpad(), Botan::ANSI_X923_Padding::unpad(), and Botan::ESP_Padding::unpad().
Return a Mask<T> which is set if x >= y
Definition at line 148 of file ct_utils.h.
Referenced by Botan::ct_divide_word(), Botan::PKCS7_Padding::unpad(), and Botan::ANSI_X923_Padding::unpad().
Return a Mask<T> which is set if x < y
Definition at line 133 of file ct_utils.h.
Referenced by Botan::bigint_cmp(), Botan::bigint_ct_is_lt(), Botan::TLS::check_tls_cbc_padding(), Botan::CT::Mask< T >::is_gt(), and Botan::Sodium::sodium_compare().
Return a Mask<T> which is set if x <= y
Definition at line 143 of file ct_utils.h.
Referenced by Botan::TLS::check_tls_cbc_padding().
|
inline |
Return true iff this mask is set
Definition at line 271 of file ct_utils.h.
References Botan::CT::Mask< T >::unpoisoned_value().
|
inlinestatic |
Definition at line 150 of file ct_utils.h.
References Botan::expand_top_bit(), and T.
Return a Mask<T> which is set if v is == 0 or cleared otherwise
Definition at line 123 of file ct_utils.h.
Referenced by Botan::CT::all_zeros(), Botan::bigint_cmp(), Botan::bigint_ct_is_eq(), Botan::bigint_ct_is_lt(), Botan::ct_compare_u8(), Botan::BigInt::ct_reduce_below(), Botan::CT::Mask< T >::is_equal(), Botan::oaep_find_delim(), Botan::CT::strip_leading_zeros(), Botan::OneAndZeros_Padding::unpad(), Botan::ESP_Padding::unpad(), and Botan::EME_PKCS1v15::unpad().
AND-combine two masks
Definition at line 174 of file ct_utils.h.
References Botan::CT::Mask< T >::value().
|
default |
XOR-combine two masks
Definition at line 182 of file ct_utils.h.
References Botan::CT::Mask< T >::value().
OR-combine two masks
Definition at line 190 of file ct_utils.h.
References Botan::CT::Mask< T >::value().
|
inline |
Negate this mask
Definition at line 213 of file ct_utils.h.
References Botan::CT::Mask< T >::value().
If this mask is set, return x, otherwise return y
Definition at line 228 of file ct_utils.h.
References Botan::choose(), and Botan::CT::Mask< T >::value().
Referenced by Botan::bigint_cnd_add_or_sub(), Botan::bigint_cnd_addsub(), Botan::CT::Mask< T >::select_and_unpoison(), Botan::CT::Mask< T >::select_mask(), and Botan::CT::Mask< T >::select_n().
Definition at line 230 of file ct_utils.h.
References Botan::CT::Mask< T >::select(), T, and Botan::CT::unpoison().
|
inline |
If this mask is set, return x, otherwise return y
Definition at line 239 of file ct_utils.h.
References Botan::CT::Mask< T >::select(), and Botan::CT::Mask< T >::value().
|
inline |
Conditionally set output to x or y, depending on if mask is set or cleared (resp)
Definition at line 245 of file ct_utils.h.
References Botan::CT::Mask< T >::select().
|
inlinestatic |
Return a Mask<T> with all bits set
Definition at line 99 of file ct_utils.h.
References T.
Referenced by Botan::oaep_find_delim(), and Botan::CT::strip_leading_zeros().
|
inline |
Return the value of the mask, unpoisoned
Definition at line 262 of file ct_utils.h.
References T, Botan::CT::unpoison(), and Botan::CT::Mask< T >::value().
Referenced by Botan::CT::Mask< T >::is_set().
|
inline |
Return the underlying value of the mask
Definition at line 276 of file ct_utils.h.
Referenced by Botan::CT::Mask< T >::expand(), Botan::CT::Mask< T >::operator&=(), Botan::CT::Mask< T >::operator^=(), Botan::CT::Mask< T >::operator|=(), Botan::CT::Mask< T >::operator~(), Botan::CT::Mask< T >::select(), Botan::CT::Mask< T >::select_mask(), and Botan::CT::Mask< T >::unpoisoned_value().
AND-combine two masks
Definition at line 198 of file ct_utils.h.
XOR-combine two masks
Definition at line 203 of file ct_utils.h.
OR-combine two masks
Definition at line 208 of file ct_utils.h.