Skip to main content

Rc6Engine

Struct Rc6Engine 

Source
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, &params)?;
let mut ciphertext = [0; RC6_BLOCK_BYTES];
engine.process_block(&plaintext, &mut ciphertext)?;

engine.init(CipherDirection::Decrypt, &params)?;
let mut recovered = [0; RC6_BLOCK_BYTES];
engine.process_block(&ciphertext, &mut recovered)?;
assert_eq!(recovered, plaintext);

Implementations§

Source§

impl Rc6Engine

Source

pub const fn new() -> Self

Creates an engine with no key installed. Constant time.

Trait Implementations§

Source§

impl BlockCipher for Rc6Engine

Source§

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>

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

The engine’s processing error, such as crate::BlockError.
Source§

impl<P: KeyParams + ?Sized> BlockCipherInit<P> for Rc6Engine

Source§

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

The engine’s initialization error, such as crate::InitError.
Source§

impl Default for Rc6Engine

Source§

fn default() -> Self

Same as new. Constant time.

Source§

impl Display for Rc6Engine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Writes "RC6". Constant time.

Source§

impl Drop for Rc6Engine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.