Struct seekable_stream_cipher::ascon::StreamCipher

source ·
pub struct StreamCipher { /* private fields */ }
Expand description

An ASCON-based seekable stream cipher.

Implementations§

source§

impl StreamCipher

source

pub const KEY_LENGTH: usize = 32usize

The key length in bytes

source

pub fn new(key: &[u8; 32], context: impl AsRef<[u8]>) -> Self

Create a new state with the given key and context.

The key must be 32 bytes long, and must be randomly generated, for example using rand::thread_rng().gen::<[u8; 32]>() or getrandom::getrandom().

The context is optional can be of any length. It is used to improve multi-user security.

source

pub fn fill( &self, out: &mut [u8], start_offset: u64, ) -> Result<(), &'static str>

Fill the given buffer with the keystream starting at the given offset.

The offset is in bytes.

The key stream is deterministic: the same key, context and offset will always produce the same output.

source

pub fn apply_keystream( &self, out: &mut [u8], start_offset: u64, ) -> Result<(), &'static str>

Encrypt or decrypt the given buffer in place, given the offset.

The buffer is modified in place. The offset is in bytes.

The key stream is deterministic: the same key, context and offset will always produce the same output. This function is equivalent to calling fill and then XORing the output with the input.

§Caveats
  • There is no integrity.
  • An adversary can flip arbitrary bits in the ciphertext and the corresponding bits in the plaintext will be flipped when decrypted.

Trait Implementations§

source§

impl Clone for StreamCipher

source§

fn clone(&self) -> StreamCipher

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Copy for StreamCipher

Auto Trait Implementations§

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>,

§

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>,

§

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.