Skip to main content

FF1

Struct FF1 

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

An FF1 cipher: a key, a radix and optional configuration, validated once.

Every input is validated before any computation, with the same rules, order and messages as the fpr-ff1 Python package; see Error.

An instance holds only its configuration. No cipher context is cached: each call builds its own AES key schedule, so an instance may be shared freely between threads.

Implementations§

Source§

impl FF1

Source

pub fn new(key: &[u8], radix: u32) -> Result<FF1, Error>

An FF1 cipher with no alphabet, an empty default tweak and no tweak bounds. Equivalent to FF1::builder(key, radix).build().

key must be 16, 24 or 32 bytes; radix must satisfy 2 <= radix < 2**16.

Source

pub fn builder(key: &[u8], radix: u32) -> Builder<'_>

Start configuring an FF1 cipher with an alphabet, a default tweak or tweak-length bounds.

Source

pub fn encrypt_numerals( &self, x: &[u16], tweak: Option<&[u8]>, ) -> Result<Vec<u16>, Error>

Encrypt a numeral sequence (SP 800-38G Algorithm 7). Each numeral must be less than the radix. tweak of None uses the default tweak.

Source

pub fn decrypt_numerals( &self, x: &[u16], tweak: Option<&[u8]>, ) -> Result<Vec<u16>, Error>

Decrypt a numeral sequence (SP 800-38G Algorithm 8). Each numeral must be less than the radix. tweak of None uses the default tweak.

Source

pub fn encrypt(&self, s: &str, tweak: Option<&[u8]>) -> Result<String, Error>

Encrypt a string over the configured alphabet.

Source

pub fn decrypt(&self, s: &str, tweak: Option<&[u8]>) -> Result<String, Error>

Decrypt a string over the configured alphabet.

Source

pub fn min_length(&self) -> usize

The shortest input accepted for this radix: the smallest n with radix**n >= 1_000_000 (6 for radix 10, 20 for radix 2).

Source

pub fn max_length(&self) -> u64

The longest input accepted: 2**32 - 1, since SP 800-38G requires maxlen < 2**32.

Trait Implementations§

Source§

impl Clone for FF1

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FF1

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for FF1

§

impl RefUnwindSafe for FF1

§

impl Send for FF1

§

impl Sync for FF1

§

impl Unpin for FF1

§

impl UnsafeUnpin for FF1

§

impl UnwindSafe for FF1

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.