added some comments

This commit is contained in:
sinuio
2022-02-19 01:26:45 -08:00
parent ea09c5ef8e
commit eeb830bf4d
7 changed files with 9 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ impl Circuit {
}
}
/// Evaluates the circuit in plaintext with the provided inputs
pub fn eval<E: GateOps>(&self, inputs: Vec<Vec<E>>) -> Result<Vec<E>, CircuitEvalError> {
let mut wires: Vec<Option<E>> = vec![None; self.nwires];
let inputs = inputs.concat();

View File

@@ -22,7 +22,7 @@ fn line2vec<'a>(re: &Regex, line: &'a str) -> Result<Vec<&'a str>, 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<Self, CircuitParserError> {
let f = File::open(filename)?;
let mut reader = BufReader::new(f);

View File

@@ -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<Bool, GateOpsError> {

View File

@@ -1,3 +1,3 @@
mod boolean;
pub mod boolean;
pub use boolean::Bool;

View File

@@ -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<C: BlockCipher<BlockSize = U16> + 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

View File

@@ -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<C: BlockCipher<BlockSize = U16> + BlockEncrypt>(
&self,
c: &mut C,

View File

@@ -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<R: Rng + CryptoRng, C: BlockCipher<BlockSize = U16> + BlockEncrypt>(
&self,
c: &mut C,