pub struct Rc6Engine { /* private fields */ }Expand description
RC6-32/20 engine with a 16-byte block and a 1- to 255-byte key.
Constant time on processors with fixed-latency rotations and 32-bit multiplication, such as mainstream x86, x86-64 and AArch64; processors without a barrel shifter or with early-terminating multipliers can leak secret data. The expanded key is wiped when replaced and on drop.
§Example
use tc_block_cipher::{BlockCipher, BlockCipherInit, CipherDirection};
use tc_block_cipher::KeyRef;
use tc_rc_cipher::{RC6_BLOCK_BYTES, Rc6Engine};
let mut engine = Rc6Engine::new();
let params = KeyRef::new(&[0x42; 16]);
let plaintext = [0x11; RC6_BLOCK_BYTES];
engine.init(CipherDirection::Encrypt, ¶ms)?;
let mut ciphertext = [0; RC6_BLOCK_BYTES];
engine.process_block(&plaintext, &mut ciphertext)?;
engine.init(CipherDirection::Decrypt, ¶ms)?;
let mut recovered = [0; RC6_BLOCK_BYTES];
engine.process_block(&ciphertext, &mut recovered)?;
assert_eq!(recovered, plaintext);Implementations§
Trait Implementations§
Source§impl BlockCipher for Rc6Engine
impl BlockCipher for Rc6Engine
Source§fn block_size(&self) -> usize
fn block_size(&self) -> usize
Returns 16, the block size in bytes. Constant time.
Source§fn process_block(
&mut self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, BlockError>
fn process_block( &mut self, input: &[u8], output: &mut [u8], ) -> Result<usize, BlockError>
Encrypts or decrypts one 16-byte block from input into output and
returns 16.
Returns NotInitialised before a successful init, or BufferTooShort
when either buffer is shorter than 16 bytes; output is left untouched
on error. Constant time on processors with fixed-latency
rotations and 32-bit multiplication, such as mainstream x86, x86-64 and
AArch64.
Source§type Error = BlockError
type Error = BlockError
crate::BlockError.Source§impl<P: KeyParams + ?Sized> BlockCipherInit<P> for Rc6Engine
impl<P: KeyParams + ?Sized> BlockCipherInit<P> for Rc6Engine
Source§fn init(
&mut self,
direction: CipherDirection,
params: &P,
) -> Result<(), InitError>
fn init( &mut self, direction: CipherDirection, params: &P, ) -> Result<(), InitError>
Installs a 1- to 255-byte key for direction.
On error the previous key and direction stay in use. Constant time on processors with fixed-latency rotations and 32-bit multiplication, such as mainstream x86, x86-64 and AArch64.
Source§type Error = InitError
type Error = InitError
crate::InitError.