Skip to main content

Rc564Engine

Struct Rc564Engine 

Source
pub struct Rc564Engine { /* private fields */ }
Expand description

RC5-64 engine with a 16-byte block.

It takes a 1- to 255-byte key and 0 to 255 rounds from Rc5Params; Rc5ParamsRef is the ready-made implementation.

Constant time on processors with operand-independent rotations, such as mainstream x86, x86-64 and AArch64; other processors can leak through data-dependent rotation counts. The expanded key is wiped when replaced and on drop.

§Example

use tc_block_cipher::{BlockCipher, BlockCipherInit, CipherDirection};
use tc_rc_cipher::{RC5_64_BLOCK_BYTES, Rc564Engine, Rc5ParamsRef};

let mut engine = Rc564Engine::new();
let params = Rc5ParamsRef::with_default_rounds(&[0x42; 16]);
let plaintext = [0x11; RC5_64_BLOCK_BYTES];

engine.init(CipherDirection::Encrypt, &params)?;
let mut ciphertext = [0; RC5_64_BLOCK_BYTES];
engine.process_block(&plaintext, &mut ciphertext)?;

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

Implementations§

Source§

impl Rc564Engine

Source

pub const fn new() -> Self

Creates an uninitialised engine. Constant time: no key is inspected.

Trait Implementations§

Source§

impl BlockCipher for Rc564Engine

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 operand-independent rotations, such as mainstream x86, x86-64 and AArch64.

Source§

type Error = BlockError

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

impl<P: Rc5Params + ?Sized> BlockCipherInit<P> for Rc564Engine

Source§

fn init( &mut self, direction: CipherDirection, params: &P, ) -> Result<(), InitError>

Installs a 1- to 255-byte key and 0 to 255 rounds for direction.

On error the previous key and direction stay in use. Constant time on processors with operand-independent rotations, 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 Rc564Engine

Source§

fn default() -> Self

Creates an uninitialised engine. Constant time: no key is inspected.

Source§

impl Display for Rc564Engine

Source§

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

Writes the algorithm name without inspecting key material. Constant time with respect to the key; output timing depends on the formatter.

Source§

impl Drop for Rc564Engine

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.