Operations

The structure and operations related to all types (ì.e., Booleans, shortint and integer) are described in this section.

Booleans

Native homomorphic Booleans support common Boolean operations.

The list of supported operations is:

ShortInt

Native small homomorphic integer types (e.g., FheUint3 or FheUint4) easily compute various operations. In general, computing over encrypted data is as easy as computing over clear data, since the same operation symbol is used. The addition between two ciphertexts is done using the symbol + between two FheUint. Many operations can be computed between a clear value (i.e. a scalar) and a ciphertext.

In Rust native types, any operation is modular. In Rust, u8, computations are done modulus 2^8. The similar idea is applied for FheUintX, where operations are done modulus 2^X. In the type FheUint3, operations are done modulo 8.

Arithmetic operations.

Small homomorphic integer types support all common arithmetic operations, meaning +, -, x, /, mod.

The division operation implements a subtlety: since data is encrypted, it might be possible to compute a division by 0. In this case, the division is tweaked so that dividing by 0 returns 0.

The list of supported operations is:

A simple example on how to use these operations:

Bitwise operations.

Small homomorphic integer types support some bitwise operations.

The list of supported operations is:

A simple example on how to use these operations:

Comparisons.

Small homomorphic integer types support comparison operations.

Due to some Rust limitations, it is not possible to overload the comparison symbols because of the inner definition of the operations. Rust expects to have a Boolean as an output, whereas a ciphertext encrypted result is returned when using homomorphic types.

You will need to use the different methods instead of using symbols for the comparisons. These methods follow the same naming conventions as the two standard Rust traits:

A simple example on how to use these operations:

Univariate function evaluations.

The shortint type also supports the computation of univariate functions, which deep down uses TFHE's programmable bootstrapping.

A simple example on how to use these operations:

Bivariate function evaluations.

Using the shortint type allows you to evaluate bivariate functions (i.e., functions that takes two ciphertexts as input).

A simple code example:

Integer

In TFHE-rs, integers are used to encrypt any messages larger than 4 bits. All supported operations are listed below.

Arithmetic operations.

Homomorphic integer types support arithmetic operations.

The list of supported operations is:

A simple example on how to use these operations:

Bitwise operations.

Homomorphic integer types support some bitwise operations.

The list of supported operations is:

A simple example on how to use these operations:

Comparisons.

Homomorphic integers support comparison operations. Since Rust does not allow the overloading of these operations, a simple function has been associated to each one.

The list of supported operations is:

name
symbol
type

Greater than

gt

Binary

Greater or equal than

ge

Binary

Lower than

lt

Binary

Lower or equal than

le

Binary

Equal

eq

Binary

A simple example on how to use these operations:

Min/Max.

Homomorphic integers support the min/max operations.

name
symbol
type

Min

min

Binary

Max

max

Binary

A simple example on how to use these operations:

Last updated

Was this helpful?