Trait fancy_garbling::BinaryGadgets
source · [−]pub trait BinaryGadgets: FancyBinary + BundleGadgets {
Show 26 methods
fn bin_constant_bundle(
&mut self,
val: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_output(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<Option<u128>, Self::Error> { ... }
fn bin_outputs(
&mut self,
xs: &[BinaryBundle<Self::Item>]
) -> Result<Option<Vec<u128>>, Self::Error> { ... }
fn bin_xor(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_and(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_or(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_addition(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<(BinaryBundle<Self::Item>, Self::Item), Self::Error> { ... }
fn bin_addition_no_carry(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_multiplication_lower_half(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_mul(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_div(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_twos_complement(
&mut self,
xs: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_subtraction(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<(BinaryBundle<Self::Item>, Self::Item), Self::Error> { ... }
fn bin_multiplex_constant_bits(
&mut self,
x: &Self::Item,
c1: u128,
c2: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_multiplex(
&mut self,
b: &Self::Item,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_cmul(
&mut self,
x: &BinaryBundle<Self::Item>,
c: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_abs(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_lt_signed(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error> { ... }
fn bin_lt(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error> { ... }
fn bin_geq(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error> { ... }
fn bin_max(
&mut self,
xs: &[BinaryBundle<Self::Item>]
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_demux(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<Vec<Self::Item>, Self::Error> { ... }
fn bin_rsa(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_rsl(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_shr(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize,
pad: &Self::Item
) -> Result<BinaryBundle<Self::Item>, Self::Error> { ... }
fn bin_eq_bundles(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error> { ... }
}
Expand description
Extension trait for Fancy
providing gadgets that operate over bundles of mod2 wires.
Provided Methods
sourcefn bin_constant_bundle(
&mut self,
val: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_constant_bundle(
&mut self,
val: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Create a constant bundle using base 2 inputs.
sourcefn bin_output(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<Option<u128>, Self::Error>
fn bin_output(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<Option<u128>, Self::Error>
Output a binary bundle and interpret the result as a u128
.
sourcefn bin_outputs(
&mut self,
xs: &[BinaryBundle<Self::Item>]
) -> Result<Option<Vec<u128>>, Self::Error>
fn bin_outputs(
&mut self,
xs: &[BinaryBundle<Self::Item>]
) -> Result<Option<Vec<u128>>, Self::Error>
Output a slice of binary bundles and interpret the results as a u128
.
sourcefn bin_xor(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_xor(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Xor the bits of two bundles together pairwise.
sourcefn bin_and(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_and(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
And the bits of two bundles together pairwise.
sourcefn bin_or(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_or(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Or the bits of two bundles together pairwise.
sourcefn bin_addition(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<(BinaryBundle<Self::Item>, Self::Item), Self::Error>
fn bin_addition(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<(BinaryBundle<Self::Item>, Self::Item), Self::Error>
Binary addition. Returns the result and the carry.
sourcefn bin_addition_no_carry(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_addition_no_carry(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Binary addition. Avoids creating extra gates for the final carry.
sourcefn bin_multiplication_lower_half(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_multiplication_lower_half(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Binary multiplication.
Returns the lower-order half of the output bits, ie a number with the same number of bits as the inputs.
sourcefn bin_mul(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_mul(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Full multiplier
sourcefn bin_div(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_div(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Divider
sourcefn bin_twos_complement(
&mut self,
xs: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_twos_complement(
&mut self,
xs: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Compute the twos complement of the input bundle (which must be base 2).
sourcefn bin_subtraction(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<(BinaryBundle<Self::Item>, Self::Item), Self::Error>
fn bin_subtraction(
&mut self,
xs: &BinaryBundle<Self::Item>,
ys: &BinaryBundle<Self::Item>
) -> Result<(BinaryBundle<Self::Item>, Self::Item), Self::Error>
Subtract two binary bundles. Returns the result and whether it underflowed.
Due to the way that twos_complement(0) = 0
, underflow indicates y != 0 && x >= y
.
sourcefn bin_multiplex_constant_bits(
&mut self,
x: &Self::Item,
c1: u128,
c2: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_multiplex_constant_bits(
&mut self,
x: &Self::Item,
c1: u128,
c2: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
If x=0
return c1
as a bundle of constant bits, else return c2
.
sourcefn bin_multiplex(
&mut self,
b: &Self::Item,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_multiplex(
&mut self,
b: &Self::Item,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Multiplex gadget for binary bundles
sourcefn bin_cmul(
&mut self,
x: &BinaryBundle<Self::Item>,
c: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_cmul(
&mut self,
x: &BinaryBundle<Self::Item>,
c: u128,
nbits: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Write the constant in binary and that gives you the shift amounts, Eg.. 7x is 4x+2x+x.
sourcefn bin_abs(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_abs(
&mut self,
x: &BinaryBundle<Self::Item>
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Compute the absolute value of a binary bundle.
sourcefn bin_lt_signed(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
fn bin_lt_signed(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
Returns 1 if x < y
(signed version)
sourcefn bin_lt(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
fn bin_lt(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
Returns 1 if x < y
.
sourcefn bin_geq(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
fn bin_geq(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
Returns 1 if x >= y
.
sourcefn bin_max(
&mut self,
xs: &[BinaryBundle<Self::Item>]
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_max(
&mut self,
xs: &[BinaryBundle<Self::Item>]
) -> Result<BinaryBundle<Self::Item>, Self::Error>
Compute the maximum bundle in xs
.
Demux a binary bundle into a unary vector.
sourcefn bin_rsa(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_rsa(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
arithmetic right shift (shifts the sign of the MSB into the new spaces)
sourcefn bin_rsl(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_rsl(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize
) -> Result<BinaryBundle<Self::Item>, Self::Error>
logical right shift (shifts 0 into the empty spaces)
sourcefn bin_shr(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize,
pad: &Self::Item
) -> Result<BinaryBundle<Self::Item>, Self::Error>
fn bin_shr(
&mut self,
x: &BinaryBundle<Self::Item>,
c: usize,
pad: &Self::Item
) -> Result<BinaryBundle<Self::Item>, Self::Error>
shift a value right by a constant, filling space on the right by pad
sourcefn bin_eq_bundles(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
fn bin_eq_bundles(
&mut self,
x: &BinaryBundle<Self::Item>,
y: &BinaryBundle<Self::Item>
) -> Result<Self::Item, Self::Error>
Compute x == y
for binary bundles.