Files
voprf-vx/src/lib.rs
T

530 lines
20 KiB
Rust
Raw Normal View History

2021-09-09 01:56:54 -07:00
// Copyright (c) Facebook, Inc. and its affiliates.
//
2021-09-27 18:53:06 -07:00
// This source code is licensed under both the MIT license found in the
// LICENSE-MIT file in the root directory of this source tree and the Apache
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
// of this source tree.
2021-09-09 01:56:54 -07:00
2021-09-15 17:49:31 -07:00
//! An implementation of a verifiable oblivious pseudorandom function (VOPRF)
//!
//! Note: This implementation is in sync with
//! [draft-irtf-cfrg-voprf-08](https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-08.html),
2021-09-20 00:17:53 -07:00
//! but this specification is subject to change, until the final version
//! published by the IETF.
2021-09-15 17:49:31 -07:00
//!
2021-09-20 00:17:53 -07:00
//! # Overview
2021-09-15 17:49:31 -07:00
//!
2021-12-23 01:17:03 +01:00
//! A verifiable oblivious pseudorandom function is a protocol that is evaluated
//! between a client and a server. They must first agree on a collection of
//! primitives to be kept consistent throughout protocol execution. These
//! include:
2021-09-20 00:17:53 -07:00
//! - a finite cyclic group along with a point representation, and
//! - a hashing function.
//!
//! We will use the following choices in this example:
//!
2021-12-23 07:50:48 +01:00
//! ```ignore
2022-01-21 22:52:09 +01:00
//! type CipherSuite = voprf::Ristretto255;
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ## Modes of Operation
//!
//! VOPRF can be used in two modes:
2021-12-23 01:17:03 +01:00
//! - [Base Mode](#base-mode), which corresponds to a normal OPRF evaluation
//! with no support for the verification of the OPRF outputs
//! - [Verifiable Mode](#verifiable-mode), which corresponds to an OPRF
//! evaluation where the outputs can be verified against a server public key
2021-09-20 00:17:53 -07:00
//!
2021-12-23 01:17:03 +01:00
//! In either mode, the protocol begins with a client blinding, followed by a
//! server evaluation, and finishes with a client finalization.
2021-09-20 00:17:53 -07:00
//!
//! ## Base Mode
//!
2021-12-23 01:17:03 +01:00
//! In base mode, a [NonVerifiableClient] interacts with a [NonVerifiableServer]
//! to compute the output of the VOPRF.
2021-09-20 00:17:53 -07:00
//!
//! ### Server Setup
//!
//! The protocol begins with a setup phase, in which the server must run
2021-12-23 01:17:03 +01:00
//! [NonVerifiableServer::new()] to produce an instance of itself. This instance
//! must be persisted on the server and used for online client evaluations.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-23 01:17:03 +01:00
//! use rand::rngs::OsRng;
//! use rand::RngCore;
2021-09-20 00:17:53 -07:00
//! use voprf::NonVerifiableServer;
//!
//! let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! let server = NonVerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-12-23 01:17:03 +01:00
//! .expect("Unable to construct server");
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ### Client Blinding
//!
//! In the first step, the client chooses an input, and runs
//! [NonVerifiableClient::blind] to produce a [NonVerifiableClientBlindResult],
//! which consists of a [BlindedElement] to be sent to the server and a
//! [NonVerifiableClient] which must be persisted on the client for the final
//! step of the VOPRF protocol.
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-23 01:17:03 +01:00
//! use rand::rngs::OsRng;
//! use rand::RngCore;
2021-09-20 00:17:53 -07:00
//! use voprf::NonVerifiableClient;
//!
//! let mut client_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! let client_blind_result = NonVerifiableClient::<CipherSuite>::blind(b"input", &mut client_rng)
2021-12-23 21:03:38 +01:00
//! .expect("Unable to construct client");
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ### Server Evaluation
//!
//! In the second step, the server takes as input the message from
//! [NonVerifiableClient::blind] (a [BlindedElement]), and runs
//! [NonVerifiableServer::evaluate] to produce a
//! [NonVerifiableServerEvaluateResult], which consists of an
//! [EvaluationElement] to be sent to the client.
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-09-20 00:17:53 -07:00
//! # use voprf::NonVerifiableClient;
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = NonVerifiableClient::<CipherSuite>::blind(
2021-12-23 21:03:38 +01:00
//! # b"input",
2021-09-20 00:17:53 -07:00
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # use voprf::NonVerifiableServer;
//! # let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = NonVerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-09-20 00:17:53 -07:00
//! # .expect("Unable to construct server");
2021-12-23 01:17:03 +01:00
//! let server_evaluate_result = server
//! .evaluate(&client_blind_result.message, None)
//! .expect("Unable to perform server evaluate");
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ### Client Finalization
//!
//! In the final step, the client takes as input the message from
//! [NonVerifiableServer::evaluate] (an [EvaluationElement]), and runs
2021-10-11 02:51:12 +02:00
//! [NonVerifiableClient::finalize] to produce an output for the protocol.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-09-20 00:17:53 -07:00
//! # use voprf::NonVerifiableClient;
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = NonVerifiableClient::<CipherSuite>::blind(
2021-12-23 21:03:38 +01:00
//! # b"input",
2021-09-20 00:17:53 -07:00
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # use voprf::NonVerifiableServer;
//! # let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = NonVerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-09-20 00:17:53 -07:00
//! # .expect("Unable to construct server");
//! # let server_evaluate_result = server.evaluate(
2021-12-21 20:17:02 +01:00
//! # &client_blind_result.message,
//! # None,
2021-09-20 00:17:53 -07:00
//! # ).expect("Unable to perform server evaluate");
2021-12-23 01:17:03 +01:00
//! let client_finalize_result = client_blind_result
//! .state
2021-12-23 21:03:38 +01:00
//! .finalize(b"input", &server_evaluate_result.message, None)
2021-12-23 01:17:03 +01:00
//! .expect("Unable to perform client finalization");
2021-09-20 00:17:53 -07:00
//!
2021-10-06 00:53:18 +02:00
//! println!("VOPRF output: {:?}", client_finalize_result.to_vec());
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ## Verifiable Mode
//!
2021-12-23 01:17:03 +01:00
//! In verifiable mode, a [VerifiableClient] interacts with a [VerifiableServer]
//! to compute the output of the VOPRF. In order to verify the server's
//! computation, the client checks a server-generated proof against the server's
//! public key. If the proof fails to verify, then the client does not receive
//! an output.
2021-09-20 00:17:53 -07:00
//!
//! In batch mode, a single proof can be used for multiple VOPRF evaluations.
2021-12-23 01:17:03 +01:00
//! See [the batching section](#batching) for more details on how to perform
//! batch evaluations.
2021-09-20 00:17:53 -07:00
//!
//! ### Server Setup
//!
//! The protocol begins with a setup phase, in which the server must run
2021-12-23 01:17:03 +01:00
//! [VerifiableServer::new()] to produce an instance of itself. This instance
//! must be persisted on the server and used for online client evaluations.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-23 01:17:03 +01:00
//! use rand::rngs::OsRng;
//! use rand::RngCore;
2021-09-20 00:17:53 -07:00
//! use voprf::VerifiableServer;
//!
//! let mut server_rng = OsRng;
2021-12-23 01:17:03 +01:00
//! let server =
2022-01-21 22:52:09 +01:00
//! VerifiableServer::<CipherSuite>::new(&mut server_rng).expect("Unable to construct server");
2021-09-20 00:17:53 -07:00
//!
//! // To be sent to the client
//! println!("Server public key: {:?}", server.get_public_key());
//! ```
//!
2021-12-23 01:17:03 +01:00
//! The public key should be sent to the client, since the client will need it
//! in the final step of the protocol in order to complete the evaluation of the
//! VOPRF.
2021-09-20 00:17:53 -07:00
//!
//! ### Client Blinding
//!
//! In the first step, the client chooses an input, and runs
2021-12-23 01:17:03 +01:00
//! [VerifiableClient::blind] to produce a [VerifiableClientBlindResult], which
//! consists of a [BlindedElement] to be sent to the server and a
//! [VerifiableClient] which must be persisted on the client for the final step
//! of the VOPRF protocol.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-23 01:17:03 +01:00
//! use rand::rngs::OsRng;
//! use rand::RngCore;
2021-09-20 00:17:53 -07:00
//! use voprf::VerifiableClient;
//!
//! let mut client_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! let client_blind_result = VerifiableClient::<CipherSuite>::blind(b"input", &mut client_rng)
2021-12-23 21:03:38 +01:00
//! .expect("Unable to construct client");
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ### Server Evaluation
//!
//! In the second step, the server takes as input the message from
//! [VerifiableClient::blind] (a [BlindedElement]), and runs
2021-12-23 01:17:03 +01:00
//! [VerifiableServer::evaluate] to produce a [VerifiableServerEvaluateResult],
//! which consists of an [EvaluationElement] to be sent to the client along with
//! a proof.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-09-20 00:17:53 -07:00
//! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = VerifiableClient::<CipherSuite>::blind(
2021-12-23 21:03:38 +01:00
//! # b"input",
2021-09-20 00:17:53 -07:00
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # use voprf::VerifiableServer;
//! # let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = VerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-09-20 00:17:53 -07:00
//! # .expect("Unable to construct server");
2021-12-23 01:17:03 +01:00
//! let server_evaluate_result = server
//! .evaluate(&mut server_rng, &client_blind_result.message, None)
//! .expect("Unable to perform server evaluate");
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ### Client Finalization
//!
//! In the final step, the client takes as input the message from
2021-12-23 01:17:03 +01:00
//! [VerifiableServer::evaluate] (an [EvaluationElement]), the proof, and the
//! server's public key, and runs [VerifiableClient::finalize] to produce an
//! output for the protocol.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-09-20 00:17:53 -07:00
//! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = VerifiableClient::<CipherSuite>::blind(
2021-12-23 21:03:38 +01:00
//! # b"input",
2021-09-20 00:17:53 -07:00
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # use voprf::VerifiableServer;
//! # let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = VerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-09-20 00:17:53 -07:00
//! # .expect("Unable to construct server");
//! # let server_evaluate_result = server.evaluate(
//! # &mut server_rng,
2021-12-21 20:17:02 +01:00
//! # &client_blind_result.message,
//! # None,
2021-09-20 00:17:53 -07:00
//! # ).expect("Unable to perform server evaluate");
2021-12-23 01:17:03 +01:00
//! let client_finalize_result = client_blind_result
//! .state
//! .finalize(
2021-12-23 21:03:38 +01:00
//! b"input",
2021-12-23 01:17:03 +01:00
//! &server_evaluate_result.message,
//! &server_evaluate_result.proof,
//! server.get_public_key(),
//! None,
//! )
//! .expect("Unable to perform client finalization");
2021-09-20 00:17:53 -07:00
//!
2021-10-06 00:53:18 +02:00
//! println!("VOPRF output: {:?}", client_finalize_result.to_vec());
2021-09-20 00:17:53 -07:00
//! ```
//!
//! # Advanced Usage
//!
//! There are two additional (and optional) extensions to the core VOPRF
//! protocol: support for batching of evaluations, and support for public
//! metadata.
//!
//! ## Batching
//!
2021-12-23 01:17:03 +01:00
//! It is sometimes desirable to generate only a single, constant-size proof for
//! an unbounded number of VOPRF evaluations (on arbitrary inputs).
//! [VerifiableClient] and [VerifiableServer] support a batch API for handling
//! this case. In the following example, we show how to use the batch API to
//! produce a single proof for 10 parallel VOPRF evaluations.
2021-09-20 00:17:53 -07:00
//!
2021-12-23 01:17:03 +01:00
//! First, the client produces 10 blindings, storing their resulting states and
//! messages:
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-09-20 00:17:53 -07:00
//! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! let mut client_rng = OsRng;
//! let mut client_states = vec![];
//! let mut client_messages = vec![];
//! for _ in 0..10 {
2022-01-21 22:52:09 +01:00
//! let client_blind_result = VerifiableClient::<CipherSuite>::blind(b"input", &mut client_rng)
2021-12-23 21:03:38 +01:00
//! .expect("Unable to construct client");
2021-09-20 00:17:53 -07:00
//! client_states.push(client_blind_result.state);
//! client_messages.push(client_blind_result.message);
//! }
2021-12-29 09:14:28 +01:00
//! ```
//!
//! Next, the server calls the [VerifiableServer::batch_evaluate_prepare] and
//! [VerifiableServer::batch_evaluate_finish] function on a set of client
//! messages, to produce a corresponding set of messages to be returned to the
//! client (returned in the same order), along with a single proof:
//!
//! ```
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-29 09:14:28 +01:00
//! # use voprf::{VerifiableServerBatchEvaluatePrepareResult, VerifiableServerBatchEvaluateFinishResult, VerifiableClient};
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
//! # let mut client_states = vec![];
//! # let mut client_messages = vec![];
//! # for _ in 0..10 {
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = VerifiableClient::<CipherSuite>::blind(
2021-12-29 09:14:28 +01:00
//! # b"input",
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # client_states.push(client_blind_result.state);
//! # client_messages.push(client_blind_result.message);
2021-12-23 21:03:38 +01:00
//! # }
2021-12-29 09:14:28 +01:00
//! # use voprf::VerifiableServer;
//! let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = VerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-12-29 09:14:28 +01:00
//! # .expect("Unable to construct server");
//! let VerifiableServerBatchEvaluatePrepareResult {
//! prepared_evaluation_elements,
//! t,
//! } = server
//! .batch_evaluate_prepare(client_messages.iter(), None)
//! .expect("Unable to perform server batch evaluate");
//! let prepared_elements: Vec<_> = prepared_evaluation_elements.collect();
//! let VerifiableServerBatchEvaluateFinishResult { messages, proof } = VerifiableServer::batch_evaluate_finish(&mut server_rng, client_messages.iter(), &prepared_elements, &t)
//! .expect("Unable to perform server batch evaluate");
//! let messages: Vec<_> = messages.collect();
2021-09-20 00:17:53 -07:00
//! ```
//!
2021-12-29 09:14:28 +01:00
//! If [`alloc`] is available, [VerifiableServer::batch_evaluate] can be called
//! to avoid having to collect output manually:
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 21:03:38 +01:00
//! # #[cfg(feature = "alloc")] {
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-29 09:14:28 +01:00
//! # use voprf::{VerifiableServerBatchEvaluateResult, VerifiableClient};
2021-09-20 00:17:53 -07:00
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
//! # let mut client_states = vec![];
//! # let mut client_messages = vec![];
//! # for _ in 0..10 {
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = VerifiableClient::<CipherSuite>::blind(
2021-12-23 21:03:38 +01:00
//! # b"input",
2021-09-20 00:17:53 -07:00
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # client_states.push(client_blind_result.state);
//! # client_messages.push(client_blind_result.message);
//! # }
//! # use voprf::VerifiableServer;
//! let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = VerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-09-20 00:17:53 -07:00
//! # .expect("Unable to construct server");
2021-12-29 09:14:28 +01:00
//! let VerifiableServerBatchEvaluateResult { messages, proof } = server
2021-12-23 01:17:03 +01:00
//! .batch_evaluate(&mut server_rng, &client_messages, None)
//! .expect("Unable to perform server batch evaluate");
2021-12-23 21:03:38 +01:00
//! # }
2021-09-20 00:17:53 -07:00
//! ```
//!
2021-12-23 01:17:03 +01:00
//! Then, the client calls [VerifiableClient::batch_finalize] on the client
//! states saved from the first step, along with the messages returned by the
//! server, along with the server's proof, in order to produce a vector of
//! outputs if the proof verifies correctly.
2021-09-20 00:17:53 -07:00
//!
//! ```
2021-12-23 21:03:38 +01:00
//! # #[cfg(feature = "alloc")] {
2021-12-23 07:50:48 +01:00
//! # #[cfg(feature = "ristretto255")]
2022-01-21 22:52:09 +01:00
//! # type CipherSuite = voprf::Ristretto255;
//! # #[cfg(not(feature = "ristretto255"))]
//! # type CipherSuite = p256::NistP256;
2021-12-29 09:14:28 +01:00
//! # use voprf::{VerifiableServerBatchEvaluateResult, VerifiableClient};
2021-09-20 00:17:53 -07:00
//! # use rand::{rngs::OsRng, RngCore};
//! #
//! # let mut client_rng = OsRng;
//! # let mut client_states = vec![];
//! # let mut client_messages = vec![];
//! # for _ in 0..10 {
2022-01-21 22:52:09 +01:00
//! # let client_blind_result = VerifiableClient::<CipherSuite>::blind(
2021-12-23 21:03:38 +01:00
//! # b"input",
2021-09-20 00:17:53 -07:00
//! # &mut client_rng,
//! # ).expect("Unable to construct client");
//! # client_states.push(client_blind_result.state);
//! # client_messages.push(client_blind_result.message);
//! # }
//! # use voprf::VerifiableServer;
2021-12-29 09:14:28 +01:00
//! # let mut server_rng = OsRng;
2022-01-21 22:52:09 +01:00
//! # let server = VerifiableServer::<CipherSuite>::new(&mut server_rng)
2021-09-20 00:17:53 -07:00
//! # .expect("Unable to construct server");
2021-12-29 09:14:28 +01:00
//! # let VerifiableServerBatchEvaluateResult { messages, proof } = server
//! # .batch_evaluate(&mut server_rng, &client_messages, None)
//! # .expect("Unable to perform server batch evaluate");
2021-09-20 00:17:53 -07:00
//! let client_batch_finalize_result = VerifiableClient::batch_finalize(
2021-12-23 21:03:38 +01:00
//! &[b"input"; 10],
//! &client_states,
2021-12-29 09:14:28 +01:00
//! &messages,
//! &proof,
2021-09-20 00:17:53 -07:00
//! server.get_public_key(),
//! None,
2021-12-23 01:17:03 +01:00
//! )
2021-12-23 21:03:38 +01:00
//! .expect("Unable to perform client batch finalization")
//! .collect::<Vec<_>>();
2021-09-20 00:17:53 -07:00
//!
2021-10-06 00:53:18 +02:00
//! println!("VOPRF batch outputs: {:?}", client_batch_finalize_result);
2021-12-23 21:03:38 +01:00
//! # }
2021-09-20 00:17:53 -07:00
//! ```
//!
//! ## Metadata
//!
//! The optional metadata parameter included in the protocol allows clients and
//! servers (of either mode) to cryptographically bind additional data to the
2021-12-23 01:17:03 +01:00
//! VOPRF output. This metadata is known to both parties at the start of the
//! protocol, and is inserted under the server's evaluate step and the client's
//! finalize step. This metadata can be constructed with some type of
//! higher-level domain separation to avoid cross-protocol attacks or related
//! issues.
2021-09-20 00:17:53 -07:00
//!
2021-12-23 01:17:03 +01:00
//! A custom metadata can be specified, for example, by:
//! `Some(b"custom metadata")`.
2021-09-20 00:17:53 -07:00
//!
//! # Features
//!
2021-12-23 21:03:38 +01:00
//! - The `alloc` feature requires Rusts [`alloc`] crate and enables batching
//! VOPRF evaluations.
//!
2021-12-23 01:17:03 +01:00
//! - The `serde` feature, enabled by default, provides convenience functions
//! for serializing and deserializing with [serde](https://serde.rs/).
//!
//! - The `danger` feature, disabled by default, exposes functions for setting
//! and getting internal values not available in the default API. These
//! functions are intended for use in by higher-level cryptographic protocols
//! that need access to these raw values and are able to perform the necessary
//! validations on them (such as being valid group elements).
//!
2022-01-21 22:52:09 +01:00
//! - The `ristretto255-ciphersuite` features enables using [`Ristretto255`] as
//! a [`CipherSuite`].
//!
2022-01-18 12:34:28 +01:00
//! - The `ristretto255` feature enables using [`Ristretto255`] as the
//! underlying group for the [Group] choice. A backend feature, which are
//! re-exported from [curve25519-dalek] and allow for selecting the
//! corresponding backend for the curve arithmetic used, has to be selected,
2022-01-21 22:52:09 +01:00
//! otherwise compilation will fail. The `ristretto255-u64` feature is
//! included as the default. Other features are mapped as `ristretto255-u32`,
//! `ristretto255-fiat-u64` and `ristretto255-fiat-u32`. Any `ristretto255-*`
2022-01-18 12:34:28 +01:00
//! backend feature will enable the `ristretto255` feature.
//!
2022-01-21 22:52:09 +01:00
//! - The `ristretto255-simd` feature is re-exported from [curve25519-dalek] and
2022-01-18 12:34:28 +01:00
//! enables parallel formulas, using either AVX2 or AVX512-IFMA. This will
2022-01-21 22:52:09 +01:00
//! automatically enable the `ristretto255-u64` feature and requires Rust
2021-12-23 01:17:03 +01:00
//! nightly.
2022-01-18 12:34:28 +01:00
//!
//! [curve25519-dalek]: (https://doc.dalek.rs/curve25519_dalek/index.html#backends-and-features)
2021-09-15 17:49:31 -07:00
2021-09-09 01:56:54 -07:00
#![deny(unsafe_code)]
2021-12-21 20:17:02 +01:00
#![no_std]
#![warn(clippy::cargo, missing_docs)]
#![allow(clippy::multiple_crate_versions)]
2021-09-09 01:56:54 -07:00
2021-12-23 21:03:38 +01:00
#[cfg(any(feature = "alloc", test))]
2021-09-09 01:56:54 -07:00
extern crate alloc;
2021-12-21 20:17:02 +01:00
#[cfg(feature = "std")]
extern crate std;
2022-01-21 22:52:09 +01:00
mod ciphersuite;
2021-12-25 22:54:27 +01:00
mod error;
mod group;
2022-01-21 22:52:09 +01:00
mod serialization;
mod util;
2021-09-20 00:17:53 -07:00
mod voprf;
2021-09-09 01:56:54 -07:00
#[cfg(test)]
mod tests;
2021-09-20 00:17:53 -07:00
// Exports
2022-01-21 22:52:09 +01:00
pub use crate::ciphersuite::CipherSuite;
2021-12-25 22:54:27 +01:00
pub use crate::error::{Error, Result};
pub use crate::group::Group;
2022-01-21 22:52:09 +01:00
#[cfg(feature = "ristretto255")]
pub use crate::group::Ristretto255;
pub use crate::serialization::{
BlindedElementLen, EvaluationElementLen, NonVerifiableClientLen, NonVerifiableServerLen,
ProofLen, VerifiableClientLen, VerifiableServerLen,
};
2021-12-25 22:54:27 +01:00
#[cfg(feature = "alloc")]
pub use crate::voprf::VerifiableServerBatchEvaluateResult;
2021-09-20 00:17:53 -07:00
pub use crate::voprf::{
2022-01-18 12:34:28 +01:00
BlindedElement, EvaluationElement, Mode, NonVerifiableClient, NonVerifiableClientBlindResult,
2021-12-29 09:14:28 +01:00
NonVerifiableServer, NonVerifiableServerEvaluateResult, PreparedEvaluationElement,
PreparedTscalar, Proof, VerifiableClient, VerifiableClientBatchFinalizeResult,
VerifiableClientBlindResult, VerifiableServer, VerifiableServerBatchEvaluateFinishResult,
VerifiableServerBatchEvaluatePrepareResult, VerifiableServerEvaluateResult,
2021-09-20 00:17:53 -07:00
};