pub trait CrtGadgets:
FancyArithmetic
+ FancyBinary
+ ArithmeticBundleGadgets
+ BundleGadgets {
Show 20 methods
// Provided methods
fn crt_constant_bundle(
&mut self,
x: u128,
q: u128,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_output(
&mut self,
x: &CrtBundle<Self::Item>,
) -> Result<Option<u128>, Self::Error> { ... }
fn crt_outputs(
&mut self,
xs: &[CrtBundle<Self::Item>],
) -> Result<Option<Vec<u128>>, Self::Error> { ... }
fn crt_add(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_sub(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_cmul(
&mut self,
x: &CrtBundle<Self::Item>,
c: u128,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_mul(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_cexp(
&mut self,
x: &CrtBundle<Self::Item>,
c: u16,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_rem(
&mut self,
x: &CrtBundle<Self::Item>,
p: u16,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_fractional_mixed_radix(
&mut self,
bun: &CrtBundle<Self::Item>,
ms: &[u16],
) -> Result<Self::Item, Self::Error> { ... }
fn crt_relu(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
output_moduli: Option<&[u16]>,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_sign(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
) -> Result<Self::Item, Self::Error> { ... }
fn crt_sgn(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
output_moduli: Option<&[u16]>,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_lt(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
) -> Result<Self::Item, Self::Error> { ... }
fn crt_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
) -> Result<Self::Item, Self::Error> { ... }
fn crt_max(
&mut self,
xs: &[CrtBundle<Self::Item>],
accuracy: &str,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
fn crt_to_pmr(
&mut self,
xs: &CrtBundle<Self::Item>,
) -> Result<Bundle<Self::Item>, Self::Error> { ... }
fn pmr_lt(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<Self::Item, Self::Error> { ... }
fn pmr_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<Self::Item, Self::Error> { ... }
fn crt_div(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<CrtBundle<Self::Item>, Self::Error> { ... }
}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,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_constant_bundle( &mut self, x: u128, q: u128, ) -> Result<CrtBundle<Self::Item>, Self::Error>
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>,
) -> Result<Option<u128>, Self::Error>
fn crt_output( &mut self, x: &CrtBundle<Self::Item>, ) -> Result<Option<u128>, Self::Error>
Output a CRT bundle and interpret it mod Q.
Sourcefn crt_outputs(
&mut self,
xs: &[CrtBundle<Self::Item>],
) -> Result<Option<Vec<u128>>, Self::Error>
fn crt_outputs( &mut self, xs: &[CrtBundle<Self::Item>], ) -> Result<Option<Vec<u128>>, Self::Error>
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>,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_add( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Add two CRT bundles.
Sourcefn crt_sub(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_sub( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Subtract two CRT bundles.
Sourcefn crt_cmul(
&mut self,
x: &CrtBundle<Self::Item>,
c: u128,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_cmul( &mut self, x: &CrtBundle<Self::Item>, c: u128, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Multiplies each wire in x by the corresponding residue of c.
Sourcefn crt_mul(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_mul( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Multiply x with y.
Sourcefn crt_cexp(
&mut self,
x: &CrtBundle<Self::Item>,
c: u16,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_cexp( &mut self, x: &CrtBundle<Self::Item>, c: u16, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Exponentiate x by the constant c.
Sourcefn crt_rem(
&mut self,
x: &CrtBundle<Self::Item>,
p: u16,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_rem( &mut self, x: &CrtBundle<Self::Item>, p: u16, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Compute the remainder with respect to modulus p.
Sourcefn crt_fractional_mixed_radix(
&mut self,
bun: &CrtBundle<Self::Item>,
ms: &[u16],
) -> Result<Self::Item, Self::Error>
fn crt_fractional_mixed_radix( &mut self, bun: &CrtBundle<Self::Item>, ms: &[u16], ) -> Result<Self::Item, Self::Error>
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]>,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_relu( &mut self, x: &CrtBundle<Self::Item>, accuracy: &str, output_moduli: Option<&[u16]>, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Compute max(x,0).
Optional output moduli.
Sourcefn crt_sign(
&mut self,
x: &CrtBundle<Self::Item>,
accuracy: &str,
) -> Result<Self::Item, Self::Error>
fn crt_sign( &mut self, x: &CrtBundle<Self::Item>, accuracy: &str, ) -> Result<Self::Item, Self::Error>
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]>,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_sgn( &mut self, x: &CrtBundle<Self::Item>, accuracy: &str, output_moduli: Option<&[u16]>, ) -> Result<CrtBundle<Self::Item>, Self::Error>
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,
) -> Result<Self::Item, Self::Error>
fn crt_lt( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, accuracy: &str, ) -> Result<Self::Item, Self::Error>
Returns 1 if x < y.
Sourcefn crt_geq(
&mut self,
x: &CrtBundle<Self::Item>,
y: &CrtBundle<Self::Item>,
accuracy: &str,
) -> Result<Self::Item, Self::Error>
fn crt_geq( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, accuracy: &str, ) -> Result<Self::Item, Self::Error>
Returns 1 if x >= y.
Sourcefn crt_max(
&mut self,
xs: &[CrtBundle<Self::Item>],
accuracy: &str,
) -> Result<CrtBundle<Self::Item>, Self::Error>
fn crt_max( &mut self, xs: &[CrtBundle<Self::Item>], accuracy: &str, ) -> Result<CrtBundle<Self::Item>, Self::Error>
Compute the maximum bundle in xs.
Sourcefn crt_to_pmr(
&mut self,
xs: &CrtBundle<Self::Item>,
) -> Result<Bundle<Self::Item>, Self::Error>
fn crt_to_pmr( &mut self, xs: &CrtBundle<Self::Item>, ) -> Result<Bundle<Self::Item>, Self::Error>
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>,
) -> Result<Self::Item, Self::Error>
fn pmr_lt( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> Result<Self::Item, Self::Error>
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>,
) -> Result<Self::Item, Self::Error>
fn pmr_geq( &mut self, x: &CrtBundle<Self::Item>, y: &CrtBundle<Self::Item>, ) -> Result<Self::Item, Self::Error>
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.