pub trait ConstantTimeSelect: Clone {
    // Required method
    fn ct_select(a: &Self, b: &Self, choice: Choice) -> Self;

    // Provided methods
    fn ct_assign(&mut self, other: &Self, choice: Choice) { ... }
    fn ct_swap(a: &mut Self, b: &mut Self, choice: Choice) { ... }
}
Expand description

Trait for types which are conditionally selectable in constant time, similar to (and blanket impl’d for) subtle’s ConditionallySelectable trait, but without the Copy bound which allows it to be impl’d for heap allocated types such as BoxedUint.

It also provides generic implementations of conditional assignment and conditional swaps.

Required Methods§

source

fn ct_select(a: &Self, b: &Self, choice: Choice) -> Self

Select a or b according to choice.

Returns
  • a if choice == Choice(0);
  • b if choice == Choice(1).

Provided Methods§

source

fn ct_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign other to self, according to choice.

source

fn ct_swap(a: &mut Self, b: &mut Self, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ConstantTimeSelect for BoxedUint

Available on crate feature alloc only.

NOTE: can’t impl subtle’s ConditionallySelectable trait due to its Copy bound

source§

impl<T: ConditionallySelectable> ConstantTimeSelect for T