pub struct GenericInteger<P: IntegerParameter> { /* private fields */ }
Available on crate feature integers only.
Expand description

A Generic FHE unsigned integer

Contrary to shortints, these integers can in theory by parametrized to represent integers of any number of bits (eg: 16, 24, 32, 64).

However, in practice going above 16 bits may not be ideal as the computations would not scale and become very expensive.

Integers works by combining together multiple shortints with one of the available representation.

This struct is generic over some parameters, as its the parameters that controls how many bit they represent. You will need to use one of this type specialization (e.g., FheUint8, FheUint12, FheUint16).

Its the type that overloads the operators (+, -, *), since the GenericInteger type is not Copy the operators are also overloaded to work with references.

To be able to use this type, the cargo feature integers must be enabled, and your config should also enable the type with either default parameters or custom ones.

Implementations

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more

Allows using the + operator between a GenericInteger and a GenericInteger or a &GenericInteger

Examples

use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(142, &keys)?;
let b = FheUint8::try_encrypt(83, &keys)?;
 
set_server_key(server_key);
 
let c = a + b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(142u8) + Wrapping(83u8);
assert_eq!(decrypted, expected.0);
use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(208, &keys)?;
let b = FheUint8::try_encrypt(29, &keys)?;
 
set_server_key(server_key);
 
let c = a + &b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(208u8) + Wrapping(29u8);
assert_eq!(decrypted, expected.0);
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more

Allows using the & operator between a GenericInteger and a GenericInteger or a &GenericInteger

Examples

use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(142, &keys)?;
let b = FheUint8::try_encrypt(83, &keys)?;
 
set_server_key(server_key);
 
let c = a & b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(142u8) & Wrapping(83u8);
assert_eq!(decrypted, expected.0);
use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(208, &keys)?;
let b = FheUint8::try_encrypt(29, &keys)?;
 
set_server_key(server_key);
 
let c = a & &b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(208u8) & Wrapping(29u8);
assert_eq!(decrypted, expected.0);
The resulting type after applying the & operator.
Performs the & operation. Read more
Performs the &= operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more

Allows using the | operator between a GenericInteger and a GenericInteger or a &GenericInteger

Examples

use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(142, &keys)?;
let b = FheUint8::try_encrypt(83, &keys)?;
 
set_server_key(server_key);
 
let c = a | b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(142u8) | Wrapping(83u8);
assert_eq!(decrypted, expected.0);
use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(208, &keys)?;
let b = FheUint8::try_encrypt(29, &keys)?;
 
set_server_key(server_key);
 
let c = a | &b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(208u8) | Wrapping(29u8);
assert_eq!(decrypted, expected.0);
The resulting type after applying the | operator.
Performs the | operation. Read more
Performs the |= operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more

Allows using the ^ operator between a GenericInteger and a GenericInteger or a &GenericInteger

Examples

use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(142, &keys)?;
let b = FheUint8::try_encrypt(83, &keys)?;
 
set_server_key(server_key);
 
let c = a ^ b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(142u8) ^ Wrapping(83u8);
assert_eq!(decrypted, expected.0);
use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(208, &keys)?;
let b = FheUint8::try_encrypt(29, &keys)?;
 
set_server_key(server_key);
 
let c = a ^ &b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(208u8) ^ Wrapping(29u8);
assert_eq!(decrypted, expected.0);
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
Performs the ^= operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Deserialize this value from the given Serde deserializer. Read more
Compute a function over an encrypted message, and returns a new encrypted value containing the result. Read more
Compute a function over the encrypted message.
The resulting type after applying the * operator.
Performs the * operation. Read more

Allows using the * operator between a GenericInteger and a GenericInteger or a &GenericInteger

Examples

use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(142, &keys)?;
let b = FheUint8::try_encrypt(83, &keys)?;
 
set_server_key(server_key);
 
let c = a * b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(142u8) * Wrapping(83u8);
assert_eq!(decrypted, expected.0);
use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(208, &keys)?;
let b = FheUint8::try_encrypt(29, &keys)?;
 
set_server_key(server_key);
 
let c = a * &b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(208u8) * Wrapping(29u8);
assert_eq!(decrypted, expected.0);
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
Serialize this value into the given Serde serializer. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Allows using the - operator between a GenericInteger and a GenericInteger or a &GenericInteger

Examples

use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(142, &keys)?;
let b = FheUint8::try_encrypt(83, &keys)?;
 
set_server_key(server_key);
 
let c = a - b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(142u8) - Wrapping(83u8);
assert_eq!(decrypted, expected.0);
use concrete::prelude::*;
use concrete::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
use std::num::Wrapping;
 
let config = ConfigBuilder::all_disabled()
    .enable_default_uint8()
    .build();
let (keys, server_key) = generate_keys(config);
 
let a = FheUint8::try_encrypt(208, &keys)?;
let b = FheUint8::try_encrypt(29, &keys)?;
 
set_server_key(server_key);
 
let c = a - &b;
let decrypted: u8 = c.decrypt(&keys);
let expected = Wrapping(208u8) - Wrapping(29u8);
assert_eq!(decrypted, expected.0);
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.