Struct cipher_magma::Magma

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

Block Cipher “Magma”

Implementations§

source§

impl Magma

source

pub const SUBSTITUTION_BOX_RFC7836: [u8; 128] = _

Substitution Box (S-Box) data according to Appendix C. RFC7836

Parameter set: id-tc26-gost-28147-param-Z

source

pub const SUBSTITUTION_BOX_RFC5831: [u8; 128] = _

Substitution Box (S-Box) data according to RFC5831

As per Appendix B of RFC8891 data values converted from little-endian to big-endian format.

OID: 1.2.643.2.2.30.0

source

pub const IV_GOST_R3413_2015: [u64; 3] = _

Initialization Vector (IV)

GOST R 34.13-2015

CTR Mode: Page 36, Section A.2.2, uses MSB(32) part of IV

OFB Mode: Page 37, Section A.2.3, uses MSB(128) part of IV

CFB Mode: Page 39, Section A.2.5, uses MSB(128) part of IV

source

pub fn new() -> Magma

Returns a new Magma by using RFC7836 based substitution box

Example
use cipher_magma::Magma;
let magma = Magma::new();
source

pub fn with_key(cipher_key: &[u32; 8]) -> Magma

Returns a new Magma initialized with given cipher key

Uses RFC7836 based substitution box

Arguments
  • cipher_key - A reference to [u32;8] array
Example
use cipher_magma::Magma;
let cipher_key: [u32;8] = [
    0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100, 0xf0f1f2f3, 0xf4f5f6f7, 0xf8f9fafb, 0xfcfdfeff
    ];
 
let magma = Magma::with_key(&cipher_key);
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 set_key(&mut self, cipher_key: &[u32; 8])

Sets the cipher key from [u32;8] array

Arguments
  • cipher_key - A reference to [u32;8] array
source

pub fn set_key_from_bytes(&mut self, cipher_key_bytes: &[u8])

Sets the cipher key from slice of u8 bytes

Arguments
  • cipher_key_bytes - A &[u8] slice with 32 byte elements
source

pub fn encrypt(&self, block_in: u64) -> u64

Returns encrypted block as u64 value

Arguments
  • block_in - a plaintext value as u64
source

pub fn decrypt(&self, block_in: u64) -> u64

Returns decrypted block as u64 value

Arguments
  • block_in - a ciphertext value as u64
source

pub fn cipher( &mut self, buf: &[u8], cipher_operation: &CipherOperation, cipher_mode: &CipherMode ) -> Vec<u8>

Returns resulting vector as Vec<u8>

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

Auto Trait Implementations§

§

impl RefUnwindSafe for Magma

§

impl Send for Magma

§

impl Sync for Magma

§

impl Unpin for Magma

§

impl UnwindSafe for Magma

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.