Skip to main content

Residue

Struct Residue 

Source
pub struct Residue<'f, T: MontStorage, P: Personality = Nct> { /* private fields */ }
Expand description

A value in Field<T, P>, stored implicitly in Montgomery form.

The 'f lifetime brand ties this residue to its parent Field; the P parameter ties it to the parent’s algorithm personality. The borrow checker rejects code that uses a residue after its Field is dropped, or that mixes residues across personalities. See module docs for the covariance caveat.

Implementations§

Source§

impl<T: MontStorage, P: Personality> Residue<'_, T, P>

Source

pub fn mont_value(&self) -> &T

Returns a reference to the underlying Montgomery-form value.

Escape hatch. Intended for downstream specialization layers (e.g. Curve25519Field) that implement fast paths reading the raw limbs. General consumers should not call this — use the methods on Field instead.

Source§

impl<'f, T> Residue<'f, T, Ct>

Source

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

Conditionally swap two residues in constant time.

If choice is set, a and b exchange Montgomery-form values; otherwise both are left unchanged. The operation is branchless.

This is the primitive used by Montgomery ladders (x25519 scalar multiplication, RSA blinded exponentiation). It is the only residue swap that should appear in such a ladder; std::mem::swap is not guaranteed to be branchless.

Source§

impl<'f, T> Residue<'f, T, Ct>

Source

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

Constant-time equality on the underlying Montgomery values.

Use in place of derived PartialEq on Ct paths where the equality outcome must not leak through timing (ML-KEM decapsulation tag check, ed25519 signature verification).

Trait Implementations§

Source§

impl<'f, T: Clone + MontStorage, P: Clone + Personality> Clone for Residue<'f, T, P>

Source§

fn clone(&self) -> Residue<'f, T, P>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'f, T: Debug + MontStorage, P: Debug + Personality> Debug for Residue<'f, T, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'f, T: MontStorage, P: Personality> Drop for Residue<'f, T, P>

Available on crate feature zeroize only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'f, T: Eq + MontStorage, P: Eq + Personality> Eq for Residue<'f, T, P>

Source§

impl<'f, T: PartialEq + MontStorage, P: PartialEq + Personality> PartialEq for Residue<'f, T, P>

Source§

fn eq(&self, other: &Residue<'f, T, P>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'f, T: PartialEq + MontStorage, P: PartialEq + Personality> StructuralPartialEq for Residue<'f, T, P>

Source§

impl<'f, T: MontStorage, P: Personality> Zeroize for Residue<'f, T, P>

Available on crate feature zeroize only.
Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<'f, T: MontStorage, P: Personality> ZeroizeOnDrop for Residue<'f, T, P>

Available on crate feature zeroize only.

Auto Trait Implementations§

§

impl<'f, T, P> Freeze for Residue<'f, T, P>
where T: Freeze,

§

impl<'f, T, P> RefUnwindSafe for Residue<'f, T, P>
where T: RefUnwindSafe,

§

impl<'f, T, P> Send for Residue<'f, T, P>
where T: Send,

§

impl<'f, T, P> Sync for Residue<'f, T, P>
where T: Sync,

§

impl<'f, T, P> Unpin for Residue<'f, T, P>
where T: Unpin,

§

impl<'f, T, P> UnsafeUnpin for Residue<'f, T, P>
where T: UnsafeUnpin,

§

impl<'f, T, P> UnwindSafe for Residue<'f, T, P>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MontStorage for T
where T: Zeroize,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.