pub struct Challenge<'a, R: RngCore + CryptoRng, C>where
    C: Fn(&mut RecordingRng<'a, R>) -> Vec<u8>,
{ /* private fields */ }
Expand description

A benaloh challenge that wraps untrusted computation in a way that can be challanged.

Implementations§

Create a new benaloh challenge with the given RNG and untrusted computation.

While this method takes a closure, it is generally recommended to create a separate untrusted_computation function and wrap it in the closure.

Example:
fn untrusted_computation<R: Rng>(rng: &mut R, some_data: foo, other_data: bar) -> Vec<u8> {
 // Some unstrusted computation that uses an RNG and other data.
 // The results of this computation must be a vector of bytes.
};

let mut rng = rand::thread_rng();
let mut hasher = Sha256::new();
let foo = "foo";
let bar = "bar";

let mut challenge = benaloh_challenge::Challenge::new(&mut rng, |rng: _| {
   untrusted_computation(rng, &foo, &bar)
});

Note that in this example untrusted_computation is not given the original rng direcly. The RNG is first wrapped in a RecordingRNG befor being passed to untrusted_computation.

Commit the results and get the commitment

This method generates both the results and the commitment, so must be called before into_results() is called.

Challange the results, revealing the random factors and invalidating the results of the computaton.

The revealing random factors must be given to the challenging device so it may validate the commitment.

Get the results of the untrusted computation, discarding (zeroing) the secret random factors.

This method will panic if called before commit() is called (since commit() generates the results).

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.