pub struct Cipher<B, W, const N: usize>where
W: Word,
B: BlockCipher<W, N>,{ /* private fields */ }Expand description
§Cipher
A high‐level cipher wrapper type that contains a control block It provides byte‐stream handling and cryptographic operation modes dispatch.
§Generics
B: Control-Block, e.g.RC5ControlBlock<W>.W: Underlying type which implements a Word trait.N: number of words per block (for RC5, always 2).
Implementations§
Source§impl<B, W, const N: usize> Cipher<B, W, N>where
W: Word,
B: BlockCipher<W, N>,
impl<B, W, const N: usize> Cipher<B, W, N>where
W: Word,
B: BlockCipher<W, N>,
Sourcepub fn new(block: B) -> Self
pub fn new(block: B) -> Self
Create a new Cipher wrapping the given block‐cipher instance.
§Example
use rc5_block::{RC5ControlBlock, Cipher};
let rc5_control_block = RC5ControlBlock::<u32>::new("SECRET_KEY", 12).unwrap();
let cipher = Cipher::new(rc5_control_block);Sourcepub fn encrypt(
&self,
pt: &[u8],
mode: OperationMode<W, N>,
) -> Result<Vec<u8>, Reason>
pub fn encrypt( &self, pt: &[u8], mode: OperationMode<W, N>, ) -> Result<Vec<u8>, Reason>
Encrypt plain-text bytes under selected cryptographic operation mode and returns cipher-text bytes.
This takes the plain-text as their bytes reference. It supports various encryption flows based on operation modes such as:
ECB: Electronic-code-book mode.CBC: Cipher-block-chain mode.CTR: Counter mode.
Encryption might fail for various reasons, either due to padding or etc, that’s why this function is fallible.
It returns ciphered bytes, or Reason of failure as an err.
Sourcepub fn decrypt(
&self,
ct: &[u8],
mode: OperationMode<W, N>,
) -> Result<Vec<u8>, Reason>
pub fn decrypt( &self, ct: &[u8], mode: OperationMode<W, N>, ) -> Result<Vec<u8>, Reason>
Decrypt cipher-text bytes under selected cryptographic operation mode and returns plain-text bytes.
This takes the plain-text as their bytes reference. It supports various encryption flows based on operation modes such as:
ECB: Electronic-code-book mode.CBC: Cipher-block-chain mode.CTR: Counter mode.
Decryption might fail for various reasons, either due to padding or etc, that’s why this function is fallible.
It returns plain bytes, or Reason of failure as an err.
Sourcepub fn parse_iv_from_hex<V>(&self, iv_hex: V) -> Result<[W; N], Reason>
pub fn parse_iv_from_hex<V>(&self, iv_hex: V) -> Result<[W; N], Reason>
Parse an IV from a hex‐encoded string, validating length = block size. Parsing may fail if the hex-string is not equal to blcok size.
Returns a result contain iv block or failure reason as an err.
Sourcepub fn parse_nonce_counter_from_hex<V>(
&self,
nonce_hex: V,
counter_hex: V,
) -> Result<[W; N], Reason>
pub fn parse_nonce_counter_from_hex<V>( &self, nonce_hex: V, counter_hex: V, ) -> Result<[W; N], Reason>
Parses nonce and counter from their respective hex-encoded strings.
Parse may fail if the hex-string is not equal to word-size.
Sourcepub fn control_block(&self) -> &B
pub fn control_block(&self) -> &B
Returns an immutable access to control-block of block-cipher underlying the cipher.