Word

Trait Word 

Source
pub trait Word:
    Num
    + BitXor
    + WrappingAdd
    + WrappingSub
    + PrimInt
    + NumCast
    + Debug
    + Zeroize
where Self: Sized,
{ const P: Self; const Q: Self; const BITS: usize = _; // Required methods fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>; fn to_le_bytes(&self) -> Vec<u8> ; }
Expand description

RC5 Word

This is one of the parameters of the RC5 algorithm. It is the size of the words that the algorithm operates on. By default all sensible word sizes are implemented (16/32/64/128).

If you want to use a different word size to support more exotic architectures, you can implement this trait for the type that you want to use as a word.

the following operations are required to be implemented by any type that wants to act as a word:

  • zero
  • bitor
  • bitxor
  • wrapping_add
  • wrapping_sub
  • rotate_left
  • rotate_right
    • shr
    • shl

Luckily all those methods are implemented for all Rust primitive types by the num crate, so you can just use those.

Also the type must calculate it’s P and Q magic numbers according to this formula:

P = Odd((e − 2)2^w) Q = Odd((φ − 1)2^w)

where e is the base of natural logarithms and φ is the golden ratio and w is the word size.

Required Associated Constants§

Source

const P: Self

Source

const Q: Self

Provided Associated Constants§

Source

const BITS: usize = _

This is the W parameter of the RC5 algorithm.

Required Methods§

Source

fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>

Converts a little endian byte slice to a word

Source

fn to_le_bytes(&self) -> Vec<u8>

Converts a word to a little endian byte slice

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Word for u16

Source§

const P: u16 = 47_073u16

Source§

const Q: u16 = 40_503u16

Source§

fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>

Source§

fn to_le_bytes(&self) -> Vec<u8>

Source§

impl Word for u32

Source§

const P: u32 = 3_084_996_963u32

Source§

const Q: u32 = 2_654_435_769u32

Source§

fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>

Source§

fn to_le_bytes(&self) -> Vec<u8>

Source§

impl Word for u64

Source§

const P: u64 = 13_249_961_062_380_153_451u64

Source§

const Q: u64 = 11_400_714_819_323_198_485u64

Source§

fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>

Source§

fn to_le_bytes(&self) -> Vec<u8>

Source§

impl Word for u128

Source§

const P: u128 = 244_418_640_704_343_410_224_161_820_979_800_372_167u128

Source§

const Q: u128 = 210_306_068_529_402_873_165_736_369_884_012_333_109u128

Source§

fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>

Source§

fn to_le_bytes(&self) -> Vec<u8>

Implementors§