Struct cipher_magma::Magma
source · pub struct Magma { /* private fields */ }
Expand description
Block Cipher “Magma”
Implementations§
source§impl Magma
impl Magma
sourcepub const SUBSTITUTION_BOX_RFC7836: [u8; 128] = _
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
sourcepub const SUBSTITUTION_BOX_RFC5831: [u8; 128] = _
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
sourcepub const IV_GOST_R3413_2015: [u64; 3] = _
pub const IV_GOST_R3413_2015: [u64; 3] = _
Initialization Vector (IV)
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
sourcepub fn new() -> Magma
pub fn new() -> Magma
Returns a new Magma by using RFC7836 based substitution box
Example
use cipher_magma::Magma;
let magma = Magma::new();
sourcepub fn with_key(cipher_key: &[u32; 8]) -> Magma
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);
sourcepub fn set_substitution_box(&mut self, substitution_box: &[u8; 128])
pub fn set_substitution_box(&mut self, substitution_box: &[u8; 128])
sourcepub fn set_iv(&mut self, iv: &[u64])
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
sourcepub fn set_key_from_bytes(&mut self, cipher_key_bytes: &[u8])
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
sourcepub fn cipher(
&mut self,
buf: &[u8],
cipher_operation: &CipherOperation,
cipher_mode: &CipherMode
) -> Vec<u8>
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 datacipher_operation
- reference toCipherOperation
cipher_mode
- reference toCipherMode