Functions for constant time operations on data and testing of constant time annotations using valgrind.
More...
|
template<typename T > |
Mask< T > | conditional_copy_mem (T cnd, T *to, const T *from0, const T *from1, size_t elems) noexcept |
|
template<typename T > |
void | conditional_swap (bool cnd, T &x, T &y) noexcept |
|
template<typename T > |
void | conditional_swap_ptr (bool cnd, T &x, T &y) noexcept |
|
template<typename T > |
void | poison (const T *p, size_t n) |
| Use valgrind to mark the contents of memory as being undefined. More...
|
|
template<typename T > |
void | unpoison (const T *p, size_t n) |
|
template<typename T > |
void | unpoison (T &p) |
|
Functions for constant time operations on data and testing of constant time annotations using valgrind.
For more information about constant time programming see Wagner, Molnar, et al "The Program Counter Security Model"
(C) 2010 Falko Strenzke (C) 2015,2016,2018 Jack Lloyd (C) 2024 Sven Gothel
jaulib including this code is released under the MIT License (see COPYING) Botan itself is released under the Simplified BSD License (see COPYING)
template<typename T >
void jau::CT::poison |
( |
const T * |
p, |
|
|
size_t |
n |
|
) |
| |
|
inline |
Use valgrind to mark the contents of memory as being undefined.
Valgrind will accept operations which manipulate undefined values, but will warn if an undefined value is used to decided a conditional jump or a load/store address. So if we poison all of our inputs we can confirm that the operations in question are truly const time when compiled by whatever compiler is in use.
Even better, the VALGRIND_MAKE_MEM_* macros work even when the program is not run under valgrind (though with a few cycles of overhead, which is unfortunate in final binaries as these annotations tend to be used in fairly important loops).
This approach was first used in ctgrind (https://github.com/agl/ctgrind) but calling the valgrind mecheck API directly works just as well and doesn't require a custom patched valgrind.
Definition at line 46 of file ct_utils.hpp.