Function tfhe::set_server_key

source ·
pub fn set_server_key<T: Into<InternalServerKey>>(keys: T)
Available on crate feature integer only.
Expand description

The function used to initialize internal keys.

As each thread has its own set of keys, this function must be called at least once on each thread to initialize its keys.

§Example

Only working in the main thread

use tfhe::{generate_keys, ConfigBuilder};

let config = ConfigBuilder::default().build();
let (client_key, server_key) = generate_keys(config);

tfhe::set_server_key(server_key);
// Now we can do operations on homomorphic types

Working with multiple threads

use std::thread;
use tfhe;
use tfhe::ConfigBuilder;

let config = tfhe::ConfigBuilder::default().build();
let (client_key, server_key) = tfhe::generate_keys(config);
let server_key_2 = server_key.clone();

let th1 = thread::spawn(move || {
    tfhe::set_server_key(server_key);
    // Now, this thread we can do operations on homomorphic types
});

let th2 = thread::spawn(move || {
    tfhe::set_server_key(server_key_2);
    // Now, this thread we can do operations on homomorphic types
});

th2.join().unwrap();
th1.join().unwrap();