Skip to main content

Encryptor

Struct Encryptor 

Source
pub struct Encryptor<C: Config<F, T>, F: PrimeField256, const T: usize, const R: usize> { /* private fields */ }
Expand description

Encrypts an arbitrary number of field elements in batches of R using the Poseidon permutation with state size T.

R must be T - 1 (the last element is reserved for capacity).

This symmetric cipher is implemented using the Poseidon PRP as a block cipher in duplex sponge mode, which is similar to CFB. The key lives in the capacity element.

Implementations§

Source§

impl<C: Config<F, T>, F: PrimeField256, const T: usize, const R: usize> Encryptor<C, F, T, R>

Source

pub fn with_nonce(key: F, nonce: F) -> Self

Constructs an Encryptor with the specified key and nonce.

WARNING: NEVER reuse the same (key, nonce) pair to encrypt two or more different messages, as doing so would leak information about the plaintexts!

Source

pub fn new(key: F) -> Self

Constructs an Encryptor with the specified key and a securely generated fresh nonce.

You can retrieve the nonce by calling Self::nonce.

Source

pub fn nonce(&self) -> F

Returns the nonce used by the Encryptor.

This can be transmitted publicly along with the ciphertext and will be needed to construct the Decryptor.

Source

pub fn encrypt(&mut self, block: [F; R]) -> [F; R]

Encrypts a block of R field elements.

Source

pub fn finalize(self) -> F

Performs the final checksumming.

Trait Implementations§

Source§

impl<C: Debug + Config<F, T>, F: Debug + PrimeField256, const T: usize, const R: usize> Debug for Encryptor<C, F, T, R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, F, const T: usize, const R: usize> Freeze for Encryptor<C, F, T, R>

§

impl<C, F, const T: usize, const R: usize> RefUnwindSafe for Encryptor<C, F, T, R>

§

impl<C, F, const T: usize, const R: usize> Send for Encryptor<C, F, T, R>

§

impl<C, F, const T: usize, const R: usize> Sync for Encryptor<C, F, T, R>

§

impl<C, F, const T: usize, const R: usize> Unpin for Encryptor<C, F, T, R>

§

impl<C, F, const T: usize, const R: usize> UnsafeUnpin for Encryptor<C, F, T, R>

§

impl<C, F, const T: usize, const R: usize> UnwindSafe for Encryptor<C, F, T, R>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, <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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V