Skip to main content

ConstantTimeDiv

Trait ConstantTimeDiv 

Source
pub(crate) trait ConstantTimeDiv: Unsigned {
    const CT_DIV_SHIFT: usize;
    const CT_DIV_MULTIPLIER: u64;

    // Provided method
    fn ct_div(x: u32) -> u32 { ... }
}
Expand description

Constant-time division by a compile-time constant divisor.

This trait provides a constant-time alternative to the hardware division instruction, which has variable timing based on operand values. Uses Barrett reduction to compute x / M where M is a compile-time constant.

Required Associated Constants§

Source

const CT_DIV_SHIFT: usize

Bit shift for Barrett reduction, chosen to provide sufficient precision

Source

const CT_DIV_MULTIPLIER: u64

Precomputed multiplier: ceil(2^SHIFT / M)

Provided Methods§

Source

fn ct_div(x: u32) -> u32

Perform constant-time division of x by Self::U32 Requires: x < Q (the field modulus, ~2^23)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§