Struct fdh::FullDomainHash[][src]

pub struct FullDomainHash<H: Digest> { /* fields omitted */ }

Implementations

impl<H: Digest + Clone> FullDomainHash<H> where
    H::OutputSize: Clone
[src]

pub fn with_iv(output_size: usize, iv: u8) -> Self[src]

Create new hasher instance with the given output size and initialization vector.

The final hash will be FDH(M) = HASH(M||IV) || HASH(M||IV+1) || ... || HASH(M||IV+N) where HASH is any hash function, M is the message, || denotes concatenation, IV is the initialization vector, and N is the number of cycles requires for the output length.

If the initialization vector is large enough, it will "wrap around" from xFF to x00 using modular addition.

pub fn results_between(
    self,
    initial_iv: u8,
    min: &BigUint,
    max: &BigUint
) -> Result<(Vec<u8>, u8), Error>
[src]

Search for a digest value that is numerically within the provided range by iterating over initial suffixes. Return the resulting digest and initialization value.

Example

use sha2::Sha512;
use fdh::{FullDomainHash, Update, VariableOutput};
use num_bigint::BigUint;

// Get a full domain hash that is a mere 8 bytes (64 bits) long.
let mut hasher = FullDomainHash::<Sha512>::new(8).unwrap();
hasher.update(b"ATTACKATDAWN");
let min = BigUint::from(10u64);
let max = BigUint::from(5_000_000_000_000_000_000u64); // about half of u64 max.

let (digest, iv) = hasher.results_between(0, &min, &max).unwrap();

pub fn results_lt(
    self,
    initial_iv: u8,
    max: &BigUint
) -> Result<(Vec<u8>, u8), Error>
[src]

Get a digest value that is less than the specified maximum value.

This is useful when the full-domain-hash needs to be less than some value, for example modulus n in RSA-FDH.

pub fn results_gt(
    self,
    initial_iv: u8,
    min: &BigUint
) -> Result<(Vec<u8>, u8), Error>
[src]

Get a digest value that is more than the specified maximum value.

pub fn results_in_domain<C: Fn(&[u8]) -> bool>(
    self,
    initial_iv: u8,
    value_in_domain: C
) -> Result<(Vec<u8>, u8), Error>
[src]

Get a digest value that is within the domain specified by the passed closure.

Example

use sha2::Sha512;
use fdh::{FullDomainHash, Update, VariableOutput};
use num_bigint::BigUint;
use num_integer::Integer;

// Get a full domain hash that is odd
let mut hasher = FullDomainHash::<Sha512>::new(64).unwrap();
hasher.update(b"ATTACKATDAWN");

let (digest, iv) = hasher.results_in_domain(0, |digest| BigUint::from_bytes_be(digest).is_odd()).unwrap();

Trait Implementations

impl<H: Clone + Digest> Clone for FullDomainHash<H> where
    H::OutputSize: Clone
[src]

impl<H: Debug + Digest> Debug for FullDomainHash<H> where
    H::OutputSize: Debug
[src]

impl<H: Default + Digest> Default for FullDomainHash<H> where
    H::OutputSize: Default
[src]

impl<H: Digest + Clone> ExtendableOutput for FullDomainHash<H> where
    H::OutputSize: Clone
[src]

type Reader = Self

Reader

impl<H: Digest> Reset for FullDomainHash<H>[src]

fn reset(&mut self)[src]

Reset the hasher, discarding all internal state.

impl<H: Digest> Update for FullDomainHash<H>[src]

fn update(&mut self, data: impl AsRef<[u8]>)[src]

Digest input data

impl<H: Digest + Clone> VariableOutput for FullDomainHash<H> where
    H::OutputSize: Clone
[src]

fn new(output_size: usize) -> Result<Self, InvalidOutputSize>[src]

Create new hasher instance with the given output size.

fn output_size(&self) -> usize[src]

Get output size of the hasher instance.

fn finalize_variable(mut self: Self, f: impl FnOnce(&[u8]))[src]

Retrieve result via closure and consume hasher.

Closure is guaranteed to be called, length of the buffer passed to it will be equal to output_size.

impl<H: Digest> Write for FullDomainHash<H>[src]

impl<H: Digest + Clone> XofReader for FullDomainHash<H> where
    H::OutputSize: Clone
[src]

Auto Trait Implementations

impl<H> RefUnwindSafe for FullDomainHash<H> where
    H: RefUnwindSafe,
    <<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe
[src]

impl<H> Send for FullDomainHash<H> where
    H: Send
[src]

impl<H> Sync for FullDomainHash<H> where
    H: Sync
[src]

impl<H> Unpin for FullDomainHash<H> where
    H: Unpin,
    <<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: Unpin
[src]

impl<H> UnwindSafe for FullDomainHash<H> where
    H: UnwindSafe,
    <<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,