pub trait Word:
Num
+ BitXor
+ WrappingAdd
+ WrappingSub
+ PrimInt
+ NumCast
+ Debug
+ Zeroizewhere
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§
Provided Associated Constants§
Required Methods§
Sourcefn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>
fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>
Converts a little endian byte slice to a word
Sourcefn to_le_bytes(&self) -> Vec<u8> ⓘ
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.