pub trait CrtGadgets:
FancyArithmetic
+ FancyBinary
+ ArithmeticBundleGadgets
+ BundleGadgets {
Show 20 methods
// Provided methods
fn crt_constant_bundle(
&mut self,
x: u128,
q: u128,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_output(
&mut self,
x: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Option<u128>> { ... }
fn crt_outputs(
&mut self,
xs: &[CrtBundle<Self::Item>],
channel: &mut Channel<'_>,
) -> Result<Option<Vec<u128>>> { ... }
fn crt_add(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> CrtBundle<Self::Item> { ... }
fn crt_sub(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> CrtBundle<Self::Item> { ... }
fn crt_cmul(
&mut self,
x: &CrtBundle<Self::Item>,
c: u128,
) -> CrtBundle<Self::Item> { ... }
fn crt_mul(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_cexp(
&mut self,
x: &CrtBundle<Self::Item>,
c: u16,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_rem(
&mut self,
x: &CrtBundle<Self::Item>,
p: u16,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_fractional_mixed_radix(
&mut self,
bun: &CrtBundle<Self::Item>,
ms: &[u16],
channel: &mut Channel<'_>,
) -> Result<Self::Item> { ... }
fn crt_relu(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
output_moduli: Option<&[u16]>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_sign(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<Self::Item> { ... }
fn crt_sgn(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
output_moduli: Option<&[u16]>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_lt(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<Self::Item> { ... }
fn crt_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<Self::Item> { ... }
fn crt_max(
&mut self,
xs: &[CrtBundle<Self::Item>],
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
fn crt_to_pmr(
&mut self,
xs: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Bundle<Self::Item>> { ... }
fn pmr_lt(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Self::Item> { ... }
fn pmr_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Self::Item> { ... }
fn crt_div(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>> { ... }
}Expand description
Extension trait for Fancy providing advanced CRT gadgets based on bundles of wires.
Provided Methods§
Sourcefn crt_constant_bundle(
&mut self,
x: u128,
q: u128,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_constant_bundle( &mut self, x: u128, q: u128, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Creates a bundle of constant wires for the CRT representation of x under
composite modulus q.
Sourcefn crt_output(
&mut self,
x: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Option<u128>>
fn crt_output( &mut self, x: &CrtBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Option<u128>>
Output a CRT bundle and interpret it mod Q.
Sourcefn crt_outputs(
&mut self,
xs: &[CrtBundle<Self::Item>],
channel: &mut Channel<'_>,
) -> Result<Option<Vec<u128>>>
fn crt_outputs( &mut self, xs: &[CrtBundle<Self::Item>], channel: &mut Channel<'_>, ) -> Result<Option<Vec<u128>>>
Output a slice of CRT bundles and interpret the outputs mod Q.
Sourcefn crt_add(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> CrtBundle<Self::Item>
fn crt_add( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> CrtBundle<Self::Item>
Add two CRT bundles.
Sourcefn crt_sub(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> CrtBundle<Self::Item>
fn crt_sub( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> CrtBundle<Self::Item>
Subtract two CRT bundles.
Sourcefn crt_cmul(
&mut self,
x: &CrtBundle<Self::Item>,
c: u128,
) -> CrtBundle<Self::Item>
fn crt_cmul( &mut self, x: &CrtBundle<Self::Item>, c: u128, ) -> CrtBundle<Self::Item>
Multiplies each wire in x by the corresponding residue of c.
Sourcefn crt_mul(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_mul( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Multiply x with y.
Sourcefn crt_cexp(
&mut self,
x: &CrtBundle<Self::Item>,
c: u16,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_cexp( &mut self, x: &CrtBundle<Self::Item>, c: u16, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Exponentiate x by the constant c.
Sourcefn crt_rem(
&mut self,
x: &CrtBundle<Self::Item>,
p: u16,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_rem( &mut self, x: &CrtBundle<Self::Item>, p: u16, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Compute the remainder with respect to modulus p.
§Panics
Panics if p is not a modulus contained in x.
Sourcefn crt_fractional_mixed_radix(
&mut self,
bun: &CrtBundle<Self::Item>,
ms: &[u16],
channel: &mut Channel<'_>,
) -> Result<Self::Item>
fn crt_fractional_mixed_radix( &mut self, bun: &CrtBundle<Self::Item>, ms: &[u16], channel: &mut Channel<'_>, ) -> Result<Self::Item>
Helper function for advanced gadgets, returns the MSB of the fractional part of
X/M where M=product(ms).
Sourcefn crt_relu(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
output_moduli: Option<&[u16]>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_relu( &mut self, x: &CrtBundle<Self::Item>, accuracy: &str, output_moduli: Option<&[u16]>, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Compute max(x,0).
Optional output moduli.
Sourcefn crt_sign(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<Self::Item>
fn crt_sign( &mut self, x: &CrtBundle<Self::Item>, accuracy: &str, channel: &mut Channel<'_>, ) -> Result<Self::Item>
Return 0 if x is positive and 1 if x is negative.
Sourcefn crt_sgn(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
output_moduli: Option<&[u16]>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_sgn( &mut self, x: &CrtBundle<Self::Item>, accuracy: &str, output_moduli: Option<&[u16]>, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Return if x >= 0 then 1 else -1, where -1 is interpreted as Q-1.
If provided, will produce a bundle under output_moduli instead of x.moduli()
Sourcefn crt_lt(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<Self::Item>
fn crt_lt( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, accuracy: &str, channel: &mut Channel<'_>, ) -> Result<Self::Item>
Returns 1 if x < y.
Sourcefn crt_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<Self::Item>
fn crt_geq( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, accuracy: &str, channel: &mut Channel<'_>, ) -> Result<Self::Item>
Returns 1 if x >= y.
Sourcefn crt_max(
&mut self,
xs: &[CrtBundle<Self::Item>],
accuracy: &str,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_max( &mut self, xs: &[CrtBundle<Self::Item>], accuracy: &str, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Sourcefn crt_to_pmr(
&mut self,
xs: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Bundle<Self::Item>>
fn crt_to_pmr( &mut self, xs: &CrtBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Bundle<Self::Item>>
Convert the xs bundle to PMR representation. Useful for extracting out of CRT.
Sourcefn pmr_lt(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Self::Item>
fn pmr_lt( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item>
Comparison based on PMR, more expensive than crt_lt but works on more things. For it to work, there must be an extra modulus in the CRT that is not necessary to represent the values. This ensures that if x < y, the most significant PMR digit is nonzero after subtracting them. You could add a prime to your CrtBundles right before using this gadget.
Sourcefn pmr_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<Self::Item>
fn pmr_geq( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item>
Comparison based on PMR, more expensive than crt_lt but works on more things. For it to work, there must be an extra modulus in the CRT that is not necessary to represent the values. This ensures that if x < y, the most significant PMR digit is nonzero after subtracting them. You could add a prime to your CrtBundles right before using this gadget.
Sourcefn crt_div(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
channel: &mut Channel<'_>,
) -> Result<CrtBundle<Self::Item>>
fn crt_div( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<CrtBundle<Self::Item>>
Generic, and expensive, CRT-based addition for two ciphertexts. Uses PMR comparison repeatedly. Requires an extra unused prime in both inputs.
§Panics
Panics if x and y do not have equal moduli.