[][src]Trait fancy_garbling::Fancy

pub trait Fancy {
    type Item: Clone + HasModulus;
    type Error: Debug + Display + From<FancyError>;
    fn constant(&mut self, x: u16, q: u16) -> Result<Self::Item, Self::Error>;
fn add(
        &mut self,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error>;
fn sub(
        &mut self,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error>;
fn cmul(
        &mut self,
        x: &Self::Item,
        c: u16
    ) -> Result<Self::Item, Self::Error>;
fn mul(
        &mut self,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error>;
fn proj(
        &mut self,
        x: &Self::Item,
        q: u16,
        tt: Option<Vec<u16>>
    ) -> Result<Self::Item, Self::Error>;
fn output(&mut self, x: &Self::Item) -> Result<(), Self::Error>; fn add_many(
        &mut self,
        args: &[Self::Item]
    ) -> Result<Self::Item, Self::Error> { ... }
fn xor(
        &mut self,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error> { ... }
fn negate(&mut self, x: &Self::Item) -> Result<Self::Item, Self::Error> { ... }
fn and(
        &mut self,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error> { ... }
fn or(
        &mut self,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error> { ... }
fn and_many(
        &mut self,
        args: &[Self::Item]
    ) -> Result<Self::Item, Self::Error> { ... }
fn or_many(
        &mut self,
        args: &[Self::Item]
    ) -> Result<Self::Item, Self::Error> { ... }
fn mod_change(
        &mut self,
        x: &Self::Item,
        to_modulus: u16
    ) -> Result<Self::Item, Self::Error> { ... }
fn adder(
        &mut self,
        x: &Self::Item,
        y: &Self::Item,
        carry_in: Option<&Self::Item>
    ) -> Result<(Self::Item, Self::Item), Self::Error> { ... }
fn mux(
        &mut self,
        b: &Self::Item,
        x: &Self::Item,
        y: &Self::Item
    ) -> Result<Self::Item, Self::Error> { ... }
fn mux_constant_bits(
        &mut self,
        x: &Self::Item,
        b1: bool,
        b2: bool
    ) -> Result<Self::Item, Self::Error> { ... }
fn outputs(&mut self, xs: &[Self::Item]) -> Result<(), Self::Error> { ... } }

DSL for the basic computations supported by fancy-garbling.

Associated Types

type Item: Clone + HasModulus

The underlying wire datatype created by an object implementing Fancy.

type Error: Debug + Display + From<FancyError>

Errors which may be thrown by the users of Fancy.

Loading content...

Required methods

fn constant(&mut self, x: u16, q: u16) -> Result<Self::Item, Self::Error>

Create a constant x with modulus q.

fn add(
    &mut self,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

Add x and y.

fn sub(
    &mut self,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

Subtract x and y.

fn cmul(&mut self, x: &Self::Item, c: u16) -> Result<Self::Item, Self::Error>

Multiply x times the constant c.

fn mul(
    &mut self,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

Multiply x and y.

fn proj(
    &mut self,
    x: &Self::Item,
    q: u16,
    tt: Option<Vec<u16>>
) -> Result<Self::Item, Self::Error>

Project x according to the truth table tt. Resulting wire has modulus q.

Optional tt is useful for hiding the gate from the evaluator.

fn output(&mut self, x: &Self::Item) -> Result<(), Self::Error>

Process this wire as output.

Loading content...

Provided methods

fn add_many(&mut self, args: &[Self::Item]) -> Result<Self::Item, Self::Error>

Sum up a slice of wires.

fn xor(
    &mut self,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

Xor is just addition, with the requirement that x and y are mod 2.

fn negate(&mut self, x: &Self::Item) -> Result<Self::Item, Self::Error>

Negate by xoring x with 1.

fn and(
    &mut self,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

And is just multiplication, with the requirement that x and y are mod 2.

fn or(
    &mut self,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

Or uses Demorgan's Rule implemented with multiplication and negation.

fn and_many(&mut self, args: &[Self::Item]) -> Result<Self::Item, Self::Error>

Returns 1 if all wires equal 1.

fn or_many(&mut self, args: &[Self::Item]) -> Result<Self::Item, Self::Error>

Returns 1 if any wire equals 1.

fn mod_change(
    &mut self,
    x: &Self::Item,
    to_modulus: u16
) -> Result<Self::Item, Self::Error>

Change the modulus of x to to_modulus using a projection gate.

fn adder(
    &mut self,
    x: &Self::Item,
    y: &Self::Item,
    carry_in: Option<&Self::Item>
) -> Result<(Self::Item, Self::Item), Self::Error>

Binary adder. Returns the result and the carry.

fn mux(
    &mut self,
    b: &Self::Item,
    x: &Self::Item,
    y: &Self::Item
) -> Result<Self::Item, Self::Error>

If b = 0 returns x else y.

b must be mod 2 but x and y can be have any modulus.

fn mux_constant_bits(
    &mut self,
    x: &Self::Item,
    b1: bool,
    b2: bool
) -> Result<Self::Item, Self::Error>

If x = 0 returns the constant b1 else return b2. Folds constants if possible.

fn outputs(&mut self, xs: &[Self::Item]) -> Result<(), Self::Error>

Output a slice of wires.

Loading content...

Implementors

impl Fancy for CircuitBuilder[src]

type Item = CircuitRef

type Error = CircuitBuilderError

impl Fancy for Dummy[src]

type Item = DummyVal

type Error = DummyError

impl Fancy for Informer[src]

type Item = InformerVal

type Error = InformerError

impl<C: AbstractChannel> Fancy for Evaluator<C>[src]

type Item = Wire

type Error = EvaluatorError

impl<C: AbstractChannel, RNG: CryptoRng + RngCore> Fancy for Garbler<C, RNG>[src]

type Item = Wire

type Error = GarblerError

Loading content...