ChaChaStream

Struct ChaChaStream 

Source
pub struct ChaChaStream<const ROUNDS: u32> { /* private fields */ }
Expand description

The Osom imlementation of ChaCha algorithm, as defined in RFC 8439.

ChaChaStream is cryptographically secure block stream.

Note that the recommended ROUNDS value is 20.

Implementations§

Source§

impl<const ROUNDS: u32> ChaChaStream<ROUNDS>

Source

pub fn from_seed(seed: u128) -> Self

Creates a new ChaChaStream from a given seed. This method puts the seed into the key, and passes 0 as the nonce.

For better control use Self::from_arrays or Self::from_slices.

Source

pub fn from_arrays(key: [u8; 32], nonce: [u8; 12]) -> Self

Creates a new ChaChaStream from a given key and nonce.

Source

pub fn from_slices(key: &[u8], nonce: &[u8]) -> Self

Creates a new ChaChaStream from a given key and nonce slices.

Source

pub fn from_slices_and_counter(key: &[u8], nonce: &[u8], counter: u32) -> Self

Creates a new ChaChaStream from a given key, nonce slices and internal counter.

§Panics

Panics if the key or nonce is not of size 32 or 8 respectively. Also when counter is u32::MAX.

Source

pub fn next_u32_block(&mut self) -> [u32; 16]

Generates the next chacha block.

§Panics

When the internal counter overflows, i.e. when this function is called more than u32::MAX times.

Source

pub fn serialize_block(block: &[u32; 16]) -> [u8; 64]

Serializes the given chacha block, by applying little endian encoding to each element.

Trait Implementations§

Source§

impl<const ROUNDS: u32> BlockStream for ChaChaStream<ROUNDS>

Source§

const BLOCK_SIZE: u32 = 64u32

The size of the block in bytes.
Source§

type BlockType = [u8; 64]

The actual type of the block. Read more
Source§

fn next_block(&mut self) -> Self::BlockType

Generates the next block.
Source§

impl<const ROUNDS: u32> Clone for ChaChaStream<ROUNDS>

Source§

fn clone(&self) -> ChaChaStream<ROUNDS>

Returns a duplicate 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<const ROUNDS: u32> Debug for ChaChaStream<ROUNDS>

Source§

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

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

impl<const ROUNDS: u32> PartialEq for ChaChaStream<ROUNDS>

Source§

fn eq(&self, other: &ChaChaStream<ROUNDS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const ROUNDS: u32> ReprC for ChaChaStream<ROUNDS>

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<const ROUNDS: u32> Seedable<u128> for ChaChaStream<ROUNDS>

Source§

fn with_seed(seed: u128) -> Self

Creates a new instance from a given seed.
Source§

impl<const ROUNDS: u32> Seedable<u64> for ChaChaStream<ROUNDS>

Source§

fn with_seed(seed: u64) -> Self

Creates a new instance from a given seed.
Source§

impl<const ROUNDS: u32> Copy for ChaChaStream<ROUNDS>

Source§

impl<const ROUNDS: u32> Eq for ChaChaStream<ROUNDS>

Source§

impl<const ROUNDS: u32> StructuralPartialEq for ChaChaStream<ROUNDS>

Auto Trait Implementations§

§

impl<const ROUNDS: u32> Freeze for ChaChaStream<ROUNDS>

§

impl<const ROUNDS: u32> RefUnwindSafe for ChaChaStream<ROUNDS>

§

impl<const ROUNDS: u32> Send for ChaChaStream<ROUNDS>

§

impl<const ROUNDS: u32> Sync for ChaChaStream<ROUNDS>

§

impl<const ROUNDS: u32> Unpin for ChaChaStream<ROUNDS>

§

impl<const ROUNDS: u32> UnwindSafe for ChaChaStream<ROUNDS>

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