Struct fdh::FullDomainHash [−][src]
Implementations
impl<H: Digest + Clone> FullDomainHash<H> where
H::OutputSize: Clone,
[src]
H::OutputSize: Clone,
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]
self,
initial_iv: u8,
min: &BigUint,
max: &BigUint
) -> Result<(Vec<u8>, u8), Error>
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]
self,
initial_iv: u8,
max: &BigUint
) -> Result<(Vec<u8>, u8), Error>
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]
self,
initial_iv: u8,
min: &BigUint
) -> Result<(Vec<u8>, u8), Error>
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]
self,
initial_iv: u8,
value_in_domain: C
) -> Result<(Vec<u8>, u8), Error>
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]
H::OutputSize: Clone,
fn clone(&self) -> FullDomainHash<H>ⓘNotable traits for FullDomainHash<H>
impl<H: Digest> Write for FullDomainHash<H>
[src]
Notable traits for FullDomainHash<H>
impl<H: Digest> Write for FullDomainHash<H>
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<H: Debug + Digest> Debug for FullDomainHash<H> where
H::OutputSize: Debug,
[src]
H::OutputSize: Debug,
impl<H: Default + Digest> Default for FullDomainHash<H> where
H::OutputSize: Default,
[src]
H::OutputSize: Default,
fn default() -> FullDomainHash<H>ⓘNotable traits for FullDomainHash<H>
impl<H: Digest> Write for FullDomainHash<H>
[src]
Notable traits for FullDomainHash<H>
impl<H: Digest> Write for FullDomainHash<H>
impl<H: Digest + Clone> ExtendableOutput for FullDomainHash<H> where
H::OutputSize: Clone,
[src]
H::OutputSize: Clone,
type Reader = Self
Reader
fn finalize_xof(self) -> Self::Reader
[src]
fn finalize_xof_reset(&mut self) -> Self::Reader
[src]
pub fn finalize_boxed(self, n: usize) -> Box<[u8], Global>
[src]
pub fn finalize_boxed_reset(&mut self, n: usize) -> Box<[u8], Global>
[src]
impl<H: Digest> Reset for FullDomainHash<H>
[src]
impl<H: Digest> Update for FullDomainHash<H>
[src]
fn update(&mut self, data: impl AsRef<[u8]>)
[src]
Digest input data
pub fn chain(self, data: impl AsRef<[u8]>) -> Self
[src]
impl<H: Digest + Clone> VariableOutput for FullDomainHash<H> where
H::OutputSize: Clone,
[src]
H::OutputSize: Clone,
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.
fn finalize_variable_reset(&mut self, f: impl FnOnce(&[u8]))
[src]
pub fn finalize_boxed(self) -> Box<[u8], Global>
[src]
pub fn finalize_boxed_reset(&mut self) -> Box<[u8], Global>
[src]
impl<H: Digest> Write for FullDomainHash<H>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
pub fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>
1.36.0[src]
pub fn is_write_vectored(&self) -> bool
[src]
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
pub fn write_all_vectored(
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
[src]
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
1.0.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
impl<H: Digest + Clone> XofReader for FullDomainHash<H> where
H::OutputSize: Clone,
[src]
H::OutputSize: Clone,
Auto Trait Implementations
impl<H> RefUnwindSafe for FullDomainHash<H> where
H: RefUnwindSafe,
<<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe,
[src]
H: RefUnwindSafe,
<<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe,
impl<H> Send for FullDomainHash<H> where
H: Send,
[src]
H: Send,
impl<H> Sync for FullDomainHash<H> where
H: Sync,
[src]
H: Sync,
impl<H> Unpin for FullDomainHash<H> where
H: Unpin,
<<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: Unpin,
[src]
H: Unpin,
<<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: Unpin,
impl<H> UnwindSafe for FullDomainHash<H> where
H: UnwindSafe,
<<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: UnwindSafe,
[src]
H: UnwindSafe,
<<H as Digest>::OutputSize as ArrayLength<u8>>::ArrayType: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,