From eeb830bf4d80a64b1652805c8cddd865ff918275 Mon Sep 17 00:00:00 2001 From: sinuio <> Date: Sat, 19 Feb 2022 01:26:45 -0800 Subject: [PATCH] added some comments --- pop-mpc/src/circuit/mod.rs | 1 + pop-mpc/src/circuit/parse.rs | 2 +- pop-mpc/src/element/boolean.rs | 1 + pop-mpc/src/element/mod.rs | 2 +- pop-mpc/src/garble/evaluator/half_gate.rs | 3 +++ pop-mpc/src/garble/evaluator/mod.rs | 1 + pop-mpc/src/garble/generator/mod.rs | 1 + 7 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pop-mpc/src/circuit/mod.rs b/pop-mpc/src/circuit/mod.rs index 17cc1b21c..9b5beeeb1 100644 --- a/pop-mpc/src/circuit/mod.rs +++ b/pop-mpc/src/circuit/mod.rs @@ -49,6 +49,7 @@ impl Circuit { } } + /// Evaluates the circuit in plaintext with the provided inputs pub fn eval(&self, inputs: Vec>) -> Result, CircuitEvalError> { let mut wires: Vec> = vec![None; self.nwires]; let inputs = inputs.concat(); diff --git a/pop-mpc/src/circuit/parse.rs b/pop-mpc/src/circuit/parse.rs index 8aae2f4f3..e301993de 100644 --- a/pop-mpc/src/circuit/parse.rs +++ b/pop-mpc/src/circuit/parse.rs @@ -22,7 +22,7 @@ fn line2vec<'a>(re: &Regex, line: &'a str) -> Result, CircuitParser impl Circuit { /// Parses circuit files in Bristol Fashion format as specified here: - /// https://homes.esat.kuleuven.be/~nsmart/MPC/ + /// `https://homes.esat.kuleuven.be/~nsmart/MPC/` pub fn parse(filename: &str) -> Result { let f = File::open(filename)?; let mut reader = BufReader::new(f); diff --git a/pop-mpc/src/element/boolean.rs b/pop-mpc/src/element/boolean.rs index 5e2ffd503..035dc96f0 100644 --- a/pop-mpc/src/element/boolean.rs +++ b/pop-mpc/src/element/boolean.rs @@ -3,6 +3,7 @@ use crate::gate::GateOps; pub type Bool = u8; +/// Implements circuit operations for boolean elements impl GateOps for Bool { /// XOR `self` and `x` fn xor(&self, x: &Bool) -> Result { diff --git a/pop-mpc/src/element/mod.rs b/pop-mpc/src/element/mod.rs index fbbeadb65..c0ab62e30 100644 --- a/pop-mpc/src/element/mod.rs +++ b/pop-mpc/src/element/mod.rs @@ -1,3 +1,3 @@ -mod boolean; +pub mod boolean; pub use boolean::Bool; diff --git a/pop-mpc/src/garble/evaluator/half_gate.rs b/pop-mpc/src/garble/evaluator/half_gate.rs index 1fb64692a..4426e410a 100644 --- a/pop-mpc/src/garble/evaluator/half_gate.rs +++ b/pop-mpc/src/garble/evaluator/half_gate.rs @@ -9,6 +9,7 @@ use cipher::{consts::U16, generic_array::GenericArray, BlockCipher, BlockEncrypt pub struct HalfGateEvaluator; impl HalfGateEvaluator { + /// Evaluates AND gate #[inline] pub fn and_gate + BlockEncrypt>( &self, @@ -33,11 +34,13 @@ impl HalfGateEvaluator { w_g ^ w_e } + /// Evaluates XOR gate #[inline] pub fn xor_gate(&self, x: Block, y: Block) -> Block { x ^ y } + /// Evaluates INV gate #[inline] pub fn inv_gate(&self, x: Block, public_label: Block) -> Block { x ^ public_label diff --git a/pop-mpc/src/garble/evaluator/mod.rs b/pop-mpc/src/garble/evaluator/mod.rs index f26800dde..8a00f347a 100644 --- a/pop-mpc/src/garble/evaluator/mod.rs +++ b/pop-mpc/src/garble/evaluator/mod.rs @@ -9,6 +9,7 @@ use crate::garble::circuit::GarbledCircuit; use cipher::{consts::U16, generic_array::GenericArray, BlockCipher, BlockEncrypt}; pub trait GarbledCircuitEvaluator { + /// Evaluates a garbled circuit with the provided input labels fn eval + BlockEncrypt>( &self, c: &mut C, diff --git a/pop-mpc/src/garble/generator/mod.rs b/pop-mpc/src/garble/generator/mod.rs index 8242ef8a5..f93891a9a 100644 --- a/pop-mpc/src/garble/generator/mod.rs +++ b/pop-mpc/src/garble/generator/mod.rs @@ -9,6 +9,7 @@ use cipher::{consts::U16, generic_array::GenericArray, BlockCipher, BlockEncrypt use rand::{CryptoRng, Rng}; pub trait GarbledCircuitGenerator { + /// Generates a garbled circuit fn garble + BlockEncrypt>( &self, c: &mut C,