[][src]Struct fdh::FullDomainHash

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

Methods

impl<H: Digest + Clone> FullDomainHash<H>[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, Input, 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.input(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(&BigUint) -> 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, Input, 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.input(b"ATTACKATDAWN");

let (digest, iv) = hasher.results_in_domain(0, |check_digest| check_digest.is_odd()).unwrap();

Trait Implementations

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

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

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

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

fn write_vectored(&mut self, bufs: &[IoVec]) -> Result<usize, Error>[src]

🔬 This is a nightly-only experimental API. (iovec)

Like write, except that it writes from a slice of buffers. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
[src]

Attempts to write an entire buffer into this writer. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

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

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

Digest input data

fn chain<B>(self, data: B) -> Self where
    B: AsRef<[u8]>, 
[src]

Digest input data in a chained manner.

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

fn reset(&mut self)[src]

Reset the hasher, discarding all internal state.

impl<H: Digest + Clone> VariableOutput for FullDomainHash<H>[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 variable_result<F: FnOnce(&[u8])>(self, f: F)[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.

You should probably use vec_result() instead.

fn vec_result(self) -> Vec<u8>[src]

Retrieve result into vector and consume hasher.

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

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

type Reader = Self

fn vec_result(self, n: usize) -> Vec<u8>[src]

Retrieve result into vector of specified length.

Auto Trait Implementations

impl<H> Send for FullDomainHash<H> where
    H: Send,
    <H as Digest>::OutputSize: ArrayLength<u8>, 

impl<H> Sync for FullDomainHash<H> where
    H: Sync,
    <H as Digest>::OutputSize: ArrayLength<u8>, 

Blanket Implementations

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto 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<T, U> Into for T where
    U: From<T>, 
[src]

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

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

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

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

type Owned = T

impl<T> Same for T

type Output = T

Should always be Self