Crate consistenttime

Source
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.