Trait CrtGadgets

Source
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§

Source

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.

Source

fn crt_output( &mut self, x: &CrtBundle<Self::Item>, ) -> Result<Option<u128>, Self::Error>

Output a CRT bundle and interpret it mod Q.

Source

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.

Source

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

Add two CRT bundles.

Source

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

Subtract two CRT bundles.

Source

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.

Source

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

Multiply x with y.

Source

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

Exponentiate x by the constant c.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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()

Source

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.

Source

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.

Source

fn crt_max( &mut self, xs: &[CrtBundle<Self::Item>], accuracy: &str, ) -> Result<CrtBundle<Self::Item>, Self::Error>

Compute the maximum bundle in xs.

Source

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.

Source

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.

Source

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.

Source

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

Generic, and expensive, CRT-based addition for two ciphertexts. Uses PMR comparison repeatedly. Requires an extra unused prime in both inputs.

Implementors§