Skip to main content

Salsa20

Struct Salsa20 

Source
pub struct Salsa20 { /* private fields */ }
Expand description

Salsa20 stream cipher (20-round variant).

Salsa20 keeps its 16-word state plus one cached 64-byte keystream block. apply_keystream XORs the generated stream into caller-owned buffers, so the same method handles both encryption and decryption.

Implementations§

Source§

impl Salsa20

Source

pub fn new(key: &[u8; 32], nonce: &[u8; 8]) -> Self

Create a Salsa20 instance with a 32-byte key and 8-byte nonce.

Source

pub fn with_key_bytes(key: &[u8], nonce: &[u8; 8]) -> Self

Create a Salsa20 instance with either a 16-byte or 32-byte key.

Source

pub fn with_counter(key: &[u8], nonce: &[u8; 8], counter: u64) -> Self

Create a Salsa20 instance at an arbitrary 64-byte block counter.

Source

pub fn new_wiping(key: &mut [u8; 32], nonce: &mut [u8; 8]) -> Self

Create with a 32-byte key and wipe the caller’s key and nonce buffers.

Source

pub fn with_key_bytes_wiping(key: &mut [u8], nonce: &mut [u8; 8]) -> Self

Create with a 16- or 32-byte key and wipe the caller’s key and nonce.

Source

pub fn apply_keystream(&mut self, buf: &mut [u8])

XOR the Salsa20 keystream into buf in place.

Source

pub fn fill(&mut self, buf: &mut [u8])

Fill buf with keystream bytes by XORing into the existing contents.

Source

pub fn keystream_block(&mut self) -> [u8; 64]

Return the next 64 bytes of keystream, respecting the current stream position.

Source

pub fn set_counter(&mut self, counter: u64)

Seek to a 64-byte block boundary.

Trait Implementations§

Source§

impl Drop for Salsa20

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl StreamCipher for Salsa20

Source§

fn fill(&mut self, buf: &mut [u8])

XOR keystream bytes into buf in place.
Source§

fn apply_keystream(&mut self, buf: &mut [u8])

Alias for Self::fill for callers that prefer this terminology.

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

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.