Boolean
In tfhe::boolean, the available operations are mainly related to their equivalent Boolean gates (i.e., AND, OR... etc). What follows are examples of a unary gate (NOT) and a binary gate (XOR). The last one is about the ternary MUX gate, which allows homomorphic computation of conditional statements of the form If..Then..Else.
This library is meant to be used both on the server side and the client side. The typical use case should follow the subsequent steps:
On the client side, generate the
clientandserver keys.Send the
server keyto the server.Then any number of times:
On the client side, encrypt the input data with the
client key.Transmit the encrypted input to the server.
On the server side, perform homomorphic computation with the
server key.Transmit the encrypted output to the client.
On the client side, decrypt the output data with the
client key.
Setup
In the first step, the client creates two keys, the client key and the server key, with the tfhe::boolean::gen_keys function:
use tfhe::boolean::prelude::*;
fn main() {
// We generate the client key and the server key,
// using the default parameters:
let (client_key, server_key): (ClientKey, ServerKey) = gen_keys();
}The
client_keyis of typeClientKey. It is secret and must never be transmitted. This key will only be used to encrypt and decrypt data.The
server_keyis of typeServerKey. It is a public key and can be shared with any party. This key has to be sent to the server because it is required for homomorphic computation.
Note that both the client_key and server_key implement the Serialize and Deserialize traits. This way you can use any compatible serializer to store/send the data. To store the server_key in a binary file, you can use the bincode library:
Encrypting inputs
Once the server key is available on the server side, it is possible to perform some homomorphic computations. The client needs to encrypt some data and send it to the server. Again, the Ciphertext type implements the Serialize and the Deserialize traits, so that any serializer and communication tool suiting your use case can be employed:
Encrypting inputs using a public key
Anyone (the server or a third party) with the public key can also encrypt some (or all) of the inputs. The public key can only be used to encrypt, not to decrypt.
Executing a Boolean circuit
Once the encrypted inputs are on the server side, the server_key can be used to homomorphically execute the desired Boolean circuit:
Decrypting the output
Once the encrypted output is on the client side, the client_key can be used to decrypt it:
Last updated
Was this helpful?