diff --git a/src/centralized_telescope/algorithm.rs b/src/centralized_telescope/algorithm.rs index 4acee0d5..3fb2d7f0 100644 --- a/src/centralized_telescope/algorithm.rs +++ b/src/centralized_telescope/algorithm.rs @@ -11,14 +11,14 @@ use blake2::{Blake2s256, Digest}; /// Alba's proving algorithm, based on a depth-first search algorithm. /// Calls up to setup.max_retries times the prove_index function and returns an empty /// proof if no suitable candidate is found. -pub fn prove(setup: &Setup, prover_set: &[Element]) -> Option { +pub(super) fn prove(setup: &Setup, prover_set: &[Element]) -> Option { // Run prove_index up to max_retries times (0..setup.max_retries).find_map(|retry_counter| prove_index(setup, prover_set, retry_counter).1) } /// Alba's verification algorithm, returns true if the proof is /// successfully verified, following the DFS verification, false otherwise. -pub fn verify(setup: &Setup, proof: &Proof) -> bool { +pub(super) fn verify(setup: &Setup, proof: &Proof) -> bool { if proof.search_counter >= setup.search_width || proof.retry_counter >= setup.max_retries || proof.element_sequence.len() as u64 != setup.proof_size diff --git a/src/centralized_telescope/mod.rs b/src/centralized_telescope/mod.rs index 76b293d5..5fa2ca28 100644 --- a/src/centralized_telescope/mod.rs +++ b/src/centralized_telescope/mod.rs @@ -1,7 +1,7 @@ //! ALBA's bounded DFS scheme using Blake2b as hash function. //! (c.f. Section 3.2.2 of Alba paper) -pub mod algorithm; +mod algorithm; pub mod init; @@ -14,3 +14,8 @@ mod round; pub mod setup; mod types; + +mod wrapper; + +// Re-exports +pub use wrapper::Wrapper as CentralizedTelescope; diff --git a/src/centralized_telescope/wrapper.rs b/src/centralized_telescope/wrapper.rs new file mode 100644 index 00000000..5c8799b3 --- /dev/null +++ b/src/centralized_telescope/wrapper.rs @@ -0,0 +1,38 @@ +use super::algorithm; +use super::init::make_setup; +use super::params::Params; +use super::proof::Proof; +use super::setup::Setup; +use crate::utils::types::Element; + +/// The main ALBA struct with prove and verify functions. +#[derive(Debug, Clone, Copy)] +pub struct Wrapper { + setup: Setup, +} + +impl Wrapper { + /// Initialize ALBA with `Params`. + pub fn create(params: &Params) -> Self { + let setup = make_setup(params); + Self::create_unsafe(&setup) + } + + /// This function is unsafe to use and should be avoided. + /// Initialize ALBA with `Setup`. + pub fn create_unsafe(setup: &Setup) -> Self { + Self { setup: *setup } + } + + /// Alba's proving algorithm, based on a depth-first search algorithm. + /// Returns either a `Proof` or `None` if no proof is found. + pub fn prove(&self, prover_set: &[Element]) -> Option { + algorithm::prove(&self.setup, prover_set) + } + + /// Alba's verification algorithm. + /// Returns true if and only if the proof is successfully verified. + pub fn verify(&self, proof: &Proof) -> bool { + algorithm::verify(&self.setup, proof) + } +}