Expand description
Consistent Time
The goal of this crate is to offer constant time functions which most cryptographic computing protocols require to prevent side channel timing attacks.
These algorithms are not implemented to be efficient. But to take the same number of processor cycles if their outcome/path is true, or false. The reference used for this crate is Go-Lang’s crypto/subtile Which implements a handful of constant time algorithms.
I took the liberity of generalizing them out to all unsigned sizes supported by Rust-Lang. Everything inside of this crate is defined as a macro. This makes writing the extremely repetive code for all types a lot easier.
There is internal unsafe code to handle converting bool
to u8
and vice versa. The machine instructions generated for these
operations involve no branches or comparison operators,
see the notes in the source code.
As of the most recent commit there has been an extreme divergence from the Go-Lang source. LLVM does MUCH heavier optimizations then Go-ASM does and some combat was necessary. As of
consistenttime = "0.2"
I am reasonably confident it provides the advertised guarantees.
Functions§
- ct_
copy_ u8 - Optional buffer copying
- ct_
copy_ u16 - Optional buffer copying
- ct_
copy_ u32 - Optional buffer copying
- ct_
copy_ u64 - Optional buffer copying
- ct_
copy_ usize - Optional buffer copying
- ct_
select_ u8 - Optional swapping.
- ct_
select_ u16 - Optional swapping.
- ct_
select_ u32 - Optional swapping.
- ct_
select_ u64 - Optional swapping.
- ct_
select_ usize - Optional swapping.
- ct_
u8_ eq - Tests if two values are equal in constant time.
- ct_
u8_ slice_ eq - Check the equality of slices.
- ct_
u16_ eq - Tests if two values are equal in constant time.
- ct_
u16_ slice_ eq - Check the equality of slices.
- ct_
u32_ eq - Tests if two values are equal in constant time.
- ct_
u32_ slice_ eq - Check the equality of slices.
- ct_
u64_ eq - Tests if two values are equal in constant time.
- ct_
u64_ slice_ eq - Check the equality of slices.
- ct_
usize_ eq - Tests if two values are equal in constant time.
- ct_
usize_ slice_ eq - Check the equality of slices.