Struct timing_shield::TpBool [] [src]

pub struct TpBool(_);

A boolean type that prevents its value from being leaked to attackers through timing information.

let protected = TpBool::protect(some_boolean);

// Use `protected` from now on instead of `some_boolean`

Use the protect method as early as possible in the computation for maximum protection:

// DANGEROUS:
let badly_protected_boolean = TpU8::protect(some_boolean as u8);

// Safe:
let protected = TpBool::protect(some_boolean).as_u8();

// DANGEROUS:
let badly_protected_value = TpBool::protect(byte1 == byte2);

// Safe:
let protected_bool = TpU8::protect(byte1).tp_eq(&TpU8::protect(byte2));

Note that & and | are provided instead of && and || because the usual boolean short-circuiting behaviour leaks information about the values of the booleans.

Methods

impl TpBool
[src]

Hide input behind a protective abstraction to prevent the value from being used in such a way that the value could leak out via a timing side channel.

let protected_bool = TpBool::protect(some_secret_bool);

// Use `protected_bool` instead of `some_secret_bool` to avoid timing leaks

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Casts from one number type to another, following the same conventions as Rust's as keyword.

Remove the timing protection and expose the raw boolean value. Once the boolean is exposed, it is the library user's responsibility to prevent timing leaks (if necessary). Note: this can be very difficult to do correctly with boolean values.

Commonly, this method is used when a value is safe to make public (e.g. the result of a signature verification).

Constant-time conditional swap. Swaps a and b if this boolean is true, otherwise has no effect. This operation is implemented without branching on the boolean value, and it will not leak information about whether the values were swapped.

Returns one of the arguments, depending on the value of this boolean. The return value is selected without branching on the boolean value, and no information about which value was selected will be leaked.

Trait Implementations

impl Clone for TpBool
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for TpBool
[src]

impl Not for TpBool
[src]

The resulting type after applying the ! operator

The method for the unary ! operator

impl BitAnd<TpBool> for TpBool
[src]

The resulting type after applying the & operator

The method for the & operator

impl BitAnd<bool> for TpBool
[src]

The resulting type after applying the & operator

The method for the & operator

impl BitOr<TpBool> for TpBool
[src]

The resulting type after applying the | operator

The method for the | operator

impl BitOr<bool> for TpBool
[src]

The resulting type after applying the | operator

The method for the | operator

impl BitXor<TpBool> for TpBool
[src]

The resulting type after applying the ^ operator

The method for the ^ operator

impl BitXor<bool> for TpBool
[src]

The resulting type after applying the ^ operator

The method for the ^ operator

impl BitAndAssign<TpBool> for TpBool
[src]

The method for the &= operator

impl BitAndAssign<bool> for TpBool
[src]

The method for the &= operator

impl BitOrAssign<TpBool> for TpBool
[src]

The method for the |= operator

impl BitOrAssign<bool> for TpBool
[src]

The method for the |= operator

impl BitXorAssign<TpBool> for TpBool
[src]

The method for the ^= operator

impl BitXorAssign<bool> for TpBool
[src]

The method for the ^= operator

impl TpEq<TpBool> for TpBool
[src]

Compare self with other for equality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more

Compare self with other for inequality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more

impl TpEq<bool> for TpBool
[src]

Compare self with other for equality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more

Compare self with other for inequality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more

impl TpCondSwap for TpBool
[src]

Swap a and b if and only if condition is true. Read more