Skip to main content

SecretScalar

Struct SecretScalar 

Source
pub struct SecretScalar<T: SecureSanitize> { /* private fields */ }
Expand description

Owned secret-controlled scalar with clear-on-drop storage.

This type intentionally has no generic borrow or exposure closure. Reviewed data-oblivious operations are provided through trait-bounded methods, while conversion back to an ordinary value is a consuming, reason-bearing declassification.

Clearing covers this wrapper’s live storage. Rust moves, compiler-created temporaries, registers, and caller-created copies remain outside that guarantee.

Implementations§

Source§

impl<T: SecureSanitize> SecretScalar<T>

Source

pub const fn new(value: T) -> Self

Wrap a secret-controlled scalar.

Source

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

Compare two wrapped scalars without declassifying the result.

Source

pub fn ct_cmp(&self, other: &Self) -> CtOrdering
where T: ConstantTimeOrd,

Order two wrapped scalars without declassifying the result.

Source

pub fn conditional_select(left: &Self, right: &Self, choice: Choice) -> Self

Select one wrapped scalar without consuming either source.

The returned wrapper owns a third value. Both source wrappers remain live and retain their independent clear-on-drop obligations.

Source

pub fn declassify(self, reason: &'static str) -> T

Explicitly reveal this scalar as a normal value.

The caller assumes responsibility for sanitizing the returned value. The consumed wrapper is left empty so its destructor cannot clean the moved value a second time.

Trait Implementations§

Source§

impl<T: SecureSanitize> Debug for SecretScalar<T>

Source§

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

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

impl<T: SecureSanitize> Drop for SecretScalar<T>

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<T: SecureSanitize> SecureSanitize for SecretScalar<T>

Source§

fn secure_sanitize(&mut self)

Clear the sensitive bytes owned by this value.

Auto Trait Implementations§

§

impl<T> Forget for SecretScalar<T>

§

impl<T> Freeze for SecretScalar<T>
where Option<T>: Freeze,

§

impl<T> Move for SecretScalar<T>

§

impl<T> RefUnwindSafe for SecretScalar<T>

§

impl<T> Send for SecretScalar<T>
where Option<T>: Send,

§

impl<T> Sync for SecretScalar<T>
where Option<T>: Sync,

§

impl<T> Unpin for SecretScalar<T>
where Option<T>: Unpin,

§

impl<T> UnsafeUnpin for SecretScalar<T>
where Option<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for SecretScalar<T>
where Option<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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.