|
331 | 331 | //! this case. In the following example, we show how to use the batch API to |
332 | 332 | //! produce a single proof for 10 parallel VOPRF evaluations. |
333 | 333 | //! |
334 | | -//! This requires the crate feature `alloc`. |
335 | | -//! |
336 | 334 | //! First, the client produces 10 blindings, storing their resulting states and |
337 | 335 | //! messages: |
338 | 336 | //! |
339 | 337 | //! ``` |
340 | | -//! # #[cfg(feature = "alloc")] { |
341 | 338 | //! # #[cfg(feature = "ristretto255")] |
342 | 339 | //! # type Group = curve25519_dalek::ristretto::RistrettoPoint; |
343 | 340 | //! # #[cfg(feature = "ristretto255")] |
|
358 | 355 | //! client_states.push(client_blind_result.state); |
359 | 356 | //! client_messages.push(client_blind_result.message); |
360 | 357 | //! } |
| 358 | +//! ``` |
| 359 | +//! |
| 360 | +//! Next, the server calls the [VerifiableServer::batch_evaluate_prepare] and |
| 361 | +//! [VerifiableServer::batch_evaluate_finish] function on a set of client |
| 362 | +//! messages, to produce a corresponding set of messages to be returned to the |
| 363 | +//! client (returned in the same order), along with a single proof: |
| 364 | +//! |
| 365 | +//! ``` |
| 366 | +//! # #[cfg(feature = "ristretto255")] |
| 367 | +//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; |
| 368 | +//! # #[cfg(feature = "ristretto255")] |
| 369 | +//! # type Hash = sha2::Sha512; |
| 370 | +//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))] |
| 371 | +//! # type Group = p256_::ProjectivePoint; |
| 372 | +//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))] |
| 373 | +//! # type Hash = sha2::Sha256; |
| 374 | +//! # use voprf::{VerifiableServerBatchEvaluatePrepareResult, VerifiableServerBatchEvaluateFinishResult, VerifiableClient}; |
| 375 | +//! # use rand::{rngs::OsRng, RngCore}; |
| 376 | +//! # |
| 377 | +//! # let mut client_rng = OsRng; |
| 378 | +//! # let mut client_states = vec![]; |
| 379 | +//! # let mut client_messages = vec![]; |
| 380 | +//! # for _ in 0..10 { |
| 381 | +//! # let client_blind_result = VerifiableClient::<Group, Hash>::blind( |
| 382 | +//! # b"input", |
| 383 | +//! # &mut client_rng, |
| 384 | +//! # ).expect("Unable to construct client"); |
| 385 | +//! # client_states.push(client_blind_result.state); |
| 386 | +//! # client_messages.push(client_blind_result.message); |
361 | 387 | //! # } |
| 388 | +//! # use voprf::VerifiableServer; |
| 389 | +//! let mut server_rng = OsRng; |
| 390 | +//! # let server = VerifiableServer::<Group, Hash>::new(&mut server_rng) |
| 391 | +//! # .expect("Unable to construct server"); |
| 392 | +//! let VerifiableServerBatchEvaluatePrepareResult { |
| 393 | +//! prepared_evaluation_elements, |
| 394 | +//! t, |
| 395 | +//! } = server |
| 396 | +//! .batch_evaluate_prepare(client_messages.iter(), None) |
| 397 | +//! .expect("Unable to perform server batch evaluate"); |
| 398 | +//! let prepared_elements: Vec<_> = prepared_evaluation_elements.collect(); |
| 399 | +//! let VerifiableServerBatchEvaluateFinishResult { messages, proof } = VerifiableServer::batch_evaluate_finish(&mut server_rng, client_messages.iter(), &prepared_elements, &t) |
| 400 | +//! .expect("Unable to perform server batch evaluate"); |
| 401 | +//! let messages: Vec<_> = messages.collect(); |
362 | 402 | //! ``` |
363 | 403 | //! |
364 | | -//! Next, the server calls the [VerifiableServer::batch_evaluate] function on a |
365 | | -//! set of client messages, to produce a corresponding set of messages to be |
366 | | -//! returned to the client (returned in the same order), along with a single |
367 | | -//! proof: |
| 404 | +//! If [`alloc`] is available, [VerifiableServer::batch_evaluate] can be called |
| 405 | +//! to avoid having to collect output manually: |
368 | 406 | //! |
369 | 407 | //! ``` |
370 | 408 | //! # #[cfg(feature = "alloc")] { |
|
376 | 414 | //! # type Group = p256_::ProjectivePoint; |
377 | 415 | //! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))] |
378 | 416 | //! # type Hash = sha2::Sha256; |
379 | | -//! # use voprf::VerifiableClient; |
| 417 | +//! # use voprf::{VerifiableServerBatchEvaluateResult, VerifiableClient}; |
380 | 418 | //! # use rand::{rngs::OsRng, RngCore}; |
381 | 419 | //! # |
382 | 420 | //! # let mut client_rng = OsRng; |
|
394 | 432 | //! let mut server_rng = OsRng; |
395 | 433 | //! # let server = VerifiableServer::<Group, Hash>::new(&mut server_rng) |
396 | 434 | //! # .expect("Unable to construct server"); |
397 | | -//! let server_batch_evaluate_result = server |
| 435 | +//! let VerifiableServerBatchEvaluateResult { messages, proof } = server |
398 | 436 | //! .batch_evaluate(&mut server_rng, &client_messages, None) |
399 | 437 | //! .expect("Unable to perform server batch evaluate"); |
400 | 438 | //! # } |
|
415 | 453 | //! # type Group = p256_::ProjectivePoint; |
416 | 454 | //! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))] |
417 | 455 | //! # type Hash = sha2::Sha256; |
418 | | -//! # use voprf::VerifiableClient; |
| 456 | +//! # use voprf::{VerifiableServerBatchEvaluateResult, VerifiableClient}; |
419 | 457 | //! # use rand::{rngs::OsRng, RngCore}; |
420 | 458 | //! # |
421 | 459 | //! # let mut client_rng = OsRng; |
|
430 | 468 | //! # client_messages.push(client_blind_result.message); |
431 | 469 | //! # } |
432 | 470 | //! # use voprf::VerifiableServer; |
433 | | -//! let mut server_rng = OsRng; |
| 471 | +//! # let mut server_rng = OsRng; |
434 | 472 | //! # let server = VerifiableServer::<Group, Hash>::new(&mut server_rng) |
435 | 473 | //! # .expect("Unable to construct server"); |
436 | | -//! # let server_batch_evaluate_result = server.batch_evaluate( |
437 | | -//! # &mut server_rng, |
438 | | -//! # &client_messages, |
439 | | -//! # None, |
440 | | -//! # ).expect("Unable to perform server batch evaluate"); |
| 474 | +//! # let VerifiableServerBatchEvaluateResult { messages, proof } = server |
| 475 | +//! # .batch_evaluate(&mut server_rng, &client_messages, None) |
| 476 | +//! # .expect("Unable to perform server batch evaluate"); |
441 | 477 | //! let client_batch_finalize_result = VerifiableClient::batch_finalize( |
442 | 478 | //! &[b"input"; 10], |
443 | 479 | //! &client_states, |
444 | | -//! &server_batch_evaluate_result.messages, |
445 | | -//! &server_batch_evaluate_result.proof, |
| 480 | +//! &messages, |
| 481 | +//! &proof, |
446 | 482 | //! server.get_public_key(), |
447 | 483 | //! None, |
448 | 484 | //! ) |
@@ -527,7 +563,8 @@ pub use crate::group::Group; |
527 | 563 | pub use crate::voprf::VerifiableServerBatchEvaluateResult; |
528 | 564 | pub use crate::voprf::{ |
529 | 565 | BlindedElement, EvaluationElement, NonVerifiableClient, NonVerifiableClientBlindResult, |
530 | | - NonVerifiableServer, NonVerifiableServerEvaluateResult, Proof, VerifiableClient, |
531 | | - VerifiableClientBatchFinalizeResult, VerifiableClientBlindResult, VerifiableServer, |
532 | | - VerifiableServerEvaluateResult, |
| 566 | + NonVerifiableServer, NonVerifiableServerEvaluateResult, PreparedEvaluationElement, |
| 567 | + PreparedTscalar, Proof, VerifiableClient, VerifiableClientBatchFinalizeResult, |
| 568 | + VerifiableClientBlindResult, VerifiableServer, VerifiableServerBatchEvaluateFinishResult, |
| 569 | + VerifiableServerBatchEvaluatePrepareResult, VerifiableServerEvaluateResult, |
533 | 570 | }; |
0 commit comments