pub trait ConstantTimeEq {
    // Required method
    fn ct_eq(&self, other: &Self) -> Choice;

    // Provided method
    fn ct_ne(&self, other: &Self) -> Choice { ... }
}
Expand description

An Eq-like trait that produces a Choice instead of a bool.

Example

use subtle::ConstantTimeEq;
let x: u8 = 5;
let y: u8 = 13;

assert_eq!(x.ct_eq(&y).unwrap_u8(), 0);
assert_eq!(x.ct_eq(&x).unwrap_u8(), 1);

Required Methods§

source

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal.

The ct_eq function should execute in constant time.

Returns
  • Choice(1u8) if self == other;
  • Choice(0u8) if self != other.

Provided Methods§

source

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal.

The ct_ne function should execute in constant time.

Returns
  • Choice(0u8) if self == other;
  • Choice(1u8) if self != other.

Implementations on Foreign Types§

source§

impl<T> ConstantTimeEq for [T]where T: ConstantTimeEq,

source§

fn ct_eq(&self, _rhs: &[T]) -> Choice

Check whether two slices of ConstantTimeEq types are equal.

Note

This function short-circuits if the lengths of the input slices are different. Otherwise, it should execute in time independent of the slice contents.

Since arrays coerce to slices, this function works with fixed-size arrays:

let a: [u8; 8] = [0,1,2,3,4,5,6,7];
let b: [u8; 8] = [0,1,2,3,0,1,2,3];

let a_eq_a = a.ct_eq(&a);
let a_eq_b = a.ct_eq(&b);

assert_eq!(a_eq_a.unwrap_u8(), 1);
assert_eq!(a_eq_b.unwrap_u8(), 0);
source§

impl ConstantTimeEq for u8

source§

fn ct_eq(&self, other: &u8) -> Choice

source§

impl ConstantTimeEq for i32

source§

fn ct_eq(&self, other: &i32) -> Choice

source§

impl ConstantTimeEq for u64

source§

fn ct_eq(&self, other: &u64) -> Choice

source§

impl ConstantTimeEq for Ordering

Ordering is #[repr(i8)] making it possible to leverage i8::ct_eq.

source§

fn ct_eq(&self, other: &Ordering) -> Choice

source§

impl ConstantTimeEq for u128

source§

fn ct_eq(&self, other: &u128) -> Choice

source§

impl ConstantTimeEq for i8

source§

fn ct_eq(&self, other: &i8) -> Choice

source§

impl ConstantTimeEq for isize

source§

fn ct_eq(&self, other: &isize) -> Choice

source§

impl ConstantTimeEq for i64

source§

fn ct_eq(&self, other: &i64) -> Choice

source§

impl ConstantTimeEq for i16

source§

fn ct_eq(&self, other: &i16) -> Choice

source§

impl ConstantTimeEq for u16

source§

fn ct_eq(&self, other: &u16) -> Choice

source§

impl ConstantTimeEq for u32

source§

fn ct_eq(&self, other: &u32) -> Choice

source§

impl ConstantTimeEq for usize

source§

fn ct_eq(&self, other: &usize) -> Choice

source§

impl ConstantTimeEq for i128

source§

fn ct_eq(&self, other: &i128) -> Choice

Implementors§

source§

impl ConstantTimeEq for oberon::SecretKey

source§

impl ConstantTimeEq for Token

source§

impl ConstantTimeEq for G1Affine

source§

impl ConstantTimeEq for G1Projective

source§

impl ConstantTimeEq for G2Affine

source§

impl ConstantTimeEq for G2Projective

source§

impl ConstantTimeEq for Gt

source§

impl ConstantTimeEq for Scalar

§

impl ConstantTimeEq for Limb

source§

impl ConstantTimeEq for Choice

§

impl<C> ConstantTimeEq for NonZeroScalar<C>where C: CurveArithmetic,

§

impl<C> ConstantTimeEq for ScalarPrimitive<C>where C: Curve,

§

impl<C> ConstantTimeEq for oberon::inner_types::elliptic_curve::SecretKey<C>where C: Curve,

§

impl<MOD, const LIMBS: usize> ConstantTimeEq for Residue<MOD, LIMBS>where MOD: ResidueParams<LIMBS>,

§

impl<P> ConstantTimeEq for NonIdentity<P>where P: ConstantTimeEq,

§

impl<T> ConstantTimeEq for Checked<T>where T: ConstantTimeEq,

§

impl<T> ConstantTimeEq for NonZero<T>where T: Zero,

§

impl<T> ConstantTimeEq for Wrapping<T>where T: ConstantTimeEq,

source§

impl<T> ConstantTimeEq for CtOption<T>where T: ConstantTimeEq,

§

impl<const LIMBS: usize> ConstantTimeEq for Uint<LIMBS>