Skip to main content

PrecalcSecretKey

Struct PrecalcSecretKey 

Source
pub struct PrecalcSecretKey<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize>(/* private fields */);
Expand description

Precalculated secret key for use with precalc_* functions in crate::dryocbox::DryocBox.

Use precalc_* functions to encrypt or decrypt multiple messages between the same sender and receiver. They reuse this shared secret instead of repeating the public-key operation for every message.

Using precalculated secret keys is compatible with libsodium’s crypto_box_beforenm.

Implementations§

Source§

impl PrecalcSecretKey<Locked<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>>

Source

pub fn precalculate_locked<ThirdPartyPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>( third_party_public_key: &ThirdPartyPublicKey, secret_key: &SecretKey, ) -> Result<Self, Error>

Available on crate feature protected only.

Computes a heap-allocated, page-aligned, locked shared secret key for the given third_party_public_key and secret_key.

Compatible with libsodium’s crypto_box_beforenm.

§Errors

Returns an error if third_party_public_key is an unacceptable low-order point or the protected allocation cannot be locked.

§Panics

Panics if the page-aligned allocation cannot be created or its size cannot be represented with guard pages.

Source§

impl PrecalcSecretKey<LockedRO<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>>

Source

pub fn precalculate_readonly_locked<ThirdPartyPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>( third_party_public_key: &ThirdPartyPublicKey, secret_key: &SecretKey, ) -> Result<Self, Error>

Available on crate feature protected only.

Computes a heap-allocated, page-aligned, locked, read-only shared secret key for the given third_party_public_key and secret_key.

Compatible with libsodium’s crypto_box_beforenm.

§Errors

Returns an error if third_party_public_key is an unacceptable low-order point, the protected allocation cannot be locked, or its page permissions cannot be changed to read-only.

§Panics

Panics if the page-aligned allocation cannot be created or its size cannot be represented with guard pages.

Source§

impl PrecalcSecretKey<StackByteArray<CRYPTO_BOX_BEFORENMBYTES>>

Source

pub fn precalculate<ThirdPartyPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>( third_party_public_key: &ThirdPartyPublicKey, secret_key: &SecretKey, ) -> Result<Self, Error>

Computes a stack-allocated shared secret key for the given third_party_public_key and secret_key.

Compatible with libsodium’s crypto_box_beforenm.

§Errors

Returns an error if third_party_public_key is an unacceptable low-order point.

Trait Implementations§

Source§

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> ByteArray<CRYPTO_BOX_BEFORENMBYTES> for PrecalcSecretKey<InnerKey>

Source§

fn as_array(&self) -> &[u8; 32]

Returns a reference to the underlying fixed-length byte array.
Source§

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Bytes + Zeroize> Bytes for PrecalcSecretKey<InnerKey>

Source§

fn as_slice(&self) -> &[u8]

Returns a slice of the underlying bytes.
Source§

fn is_empty(&self) -> bool

Returns true if the array is empty.
Source§

fn len(&self) -> usize

Shorthand to retrieve the underlying length of the byte array.
Source§

impl<InnerKey: Clone + ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> Clone for PrecalcSecretKey<InnerKey>

Source§

fn clone(&self) -> PrecalcSecretKey<InnerKey>

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<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> Debug for PrecalcSecretKey<InnerKey>

Source§

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

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

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> Deref for PrecalcSecretKey<InnerKey>

Source§

type Target = InnerKey

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> DerefMut for PrecalcSecretKey<InnerKey>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> Drop for PrecalcSecretKey<InnerKey>

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<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> Eq for PrecalcSecretKey<InnerKey>

Source§

impl<InnerKey: MutByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> MutByteArray<CRYPTO_BOX_BEFORENMBYTES> for PrecalcSecretKey<InnerKey>

Source§

fn as_mut_array(&mut self) -> &mut [u8; 32]

Returns a mutable reference to the underlying fixed-length byte array.
Source§

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize + MutBytes> MutBytes for PrecalcSecretKey<InnerKey>

Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable slice to the underlying bytes.
Source§

fn copy_from_slice(&mut self, other: &[u8])

Copies into the underlying slice from other. Panics if lengths do not match.
Source§

impl<InnerKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize> PartialEq for PrecalcSecretKey<InnerKey>

Source§

fn eq(&self, other: &Self) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<InnerKey> Zeroize for PrecalcSecretKey<InnerKey>
where InnerKey: Zeroize + ByteArray<CRYPTO_BOX_BEFORENMBYTES>,

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.

Auto Trait Implementations§

§

impl<InnerKey> Freeze for PrecalcSecretKey<InnerKey>
where InnerKey: Freeze,

§

impl<InnerKey> RefUnwindSafe for PrecalcSecretKey<InnerKey>
where InnerKey: RefUnwindSafe,

§

impl<InnerKey> Send for PrecalcSecretKey<InnerKey>
where InnerKey: Send,

§

impl<InnerKey> Sync for PrecalcSecretKey<InnerKey>
where InnerKey: Sync,

§

impl<InnerKey> Unpin for PrecalcSecretKey<InnerKey>
where InnerKey: Unpin,

§

impl<InnerKey> UnsafeUnpin for PrecalcSecretKey<InnerKey>
where InnerKey: UnsafeUnpin,

§

impl<InnerKey> UnwindSafe for PrecalcSecretKey<InnerKey>
where InnerKey: 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<R> CryptoRng for R
where R: TryCryptoRng<Error = Infallible> + ?Sized,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<R> Rng for R
where R: TryRng<Error = Infallible> + ?Sized,

Source§

fn next_u32(&mut self) -> u32

Return the next random u32.
Source§

fn next_u64(&mut self) -> u64

Return the next random u64.
Source§

fn fill_bytes(&mut self, dst: &mut [u8])

Fill dest with random data. Read more
Source§

impl<R> RngCore for R
where R: Rng,

Source§

impl<R> RngExt for R
where R: Rng + ?Sized,

Source§

fn random<T>(&mut self) -> T

Return a random value via the StandardUniform distribution. Read more
Source§

fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>

Return an iterator over random variates Read more
Source§

fn random_range<T, R>(&mut self, range: R) -> T
where T: SampleUniform, R: SampleRange<T>,

Generate a random value in the given range. Read more
Source§

fn random_bool(&mut self, p: f64) -> bool

Return a bool with a probability p of being true. Read more
Source§

fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool

Return a bool with a probability of numerator/denominator of being true. Read more
Source§

fn sample<T, D>(&mut self, distr: D) -> T
where D: Distribution<T>,

Sample a new value, using the given distribution. Read more
Source§

fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>
where D: Distribution<T>, Self: Sized,

Create an iterator that generates values using the given distribution. Read more
Source§

fn fill<T>(&mut self, dest: &mut [T])
where T: Fill,

Fill any type implementing Fill with random data Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<R> TryCryptoRng for R
where R: DerefMut, <R as Deref>::Target: TryCryptoRng,

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.
Source§

impl<R> TryRng for R
where R: DerefMut, <R as Deref>::Target: TryRng,

Source§

type Error = <<R as Deref>::Target as TryRng>::Error

The type returned in the event of a RNG error. Read more
Source§

fn try_next_u32(&mut self) -> Result<u32, <R as TryRng>::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, <R as TryRng>::Error>

Return the next random u64.
Source§

fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), <R as TryRng>::Error>

Fill dst entirely with random data.
Source§

impl<R> TryRngCore for R
where R: TryRng,

Source§

type Error = <R as TryRng>::Error

👎Deprecated since 0.10.0:

use TryRng instead

Error type.