Struct MagmaStream

Source
pub struct MagmaStream {
    pub core: Magma,
    /* private fields */
}
Expand description

Magma stream ciphering operations

Fields§

§core: Magma

The core block-cipher

Implementations§

Source§

impl MagmaStream

Source

pub fn new<T>(key: T, cipher_mode: CipherMode) -> Self
where CipherKey: From<T>,

Returns a new MagmaStream initialized with given cipher key and cipher mode

Uses RFC7836 based substitution box

§Arguments
  • key - array [u32;8] or [u8;32]
  • cipher_mode - a `CipherMode’ value
§Example
use cipher_magma::{MagmaStream, CipherMode};
let key: [u32;8] = [
    0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100, 0xf0f1f2f3, 0xf4f5f6f7, 0xf8f9fafb, 0xfcfdfeff
    ];
let magma = MagmaStream::new(key, CipherMode::CBC);

Or

use cipher_magma::{MagmaStream, CipherMode};
let key: [u8;32] = [
    0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
    0x00, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd,
    0xfe, 0xff,
    ];
let magma = MagmaStream::new(key, CipherMode::CBC);
Source

pub fn set_key<T>(&mut self, key: T)
where CipherKey: From<T>,

Sets the cipher key from array

§Arguments
  • key - a [u8;32]' or [u32;8]` array
Source

pub fn set_mode(&mut self, cipher_mode: CipherMode)

Sets the cipher mode

§Arguments
  • cipher_mode - a `CipherMode’ value
Source

pub fn set_substitution_box(&mut self, substitution_box: &[u8; 128])

Sets the substitution box

§Arguments
  • substitution_box - A reference to [u8;128] array
Source

pub fn set_iv(&mut self, iv: &[u64])

Sets the Initialization Vector (IV)

§Arguments
  • iv - A slice to &[u64] array

Attention: CTR Mode uses only the MSB(32) part of IV

Source

pub fn reset_context(&mut self)

Resets the context of stream ciphering

Source

pub fn reset_feedback(&mut self)

Resets the feedback state of stream ciphering

Source

pub fn get_mode(&self) -> CipherMode

Returns current CipherMode

Source

pub fn encrypt(&mut self, buf: &[u8]) -> Vec<u8>

Returns encrypted vector as Vec<u8>

§Arguments
  • buf - a slice of &[u8] input data
  • cipher_mode - reference to CipherMode
Source

pub fn decrypt(&mut self, buf: &[u8]) -> Vec<u8>

Returns a decrypted vector as Vec<u8>

§Arguments
  • buf - a slice of &[u8] input data
  • cipher_mode - reference to CipherMode

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.