concrete_boolean/engine/bootstrapping/
mod.rs

1use crate::ciphertext::Ciphertext;
2use concrete_core::prelude::{LweCiphertext32, LweSize};
3mod cpu;
4#[cfg(feature = "cuda")]
5mod cuda;
6
7#[cfg(feature = "cuda")]
8pub(crate) use cuda::{CudaBootstrapKey, CudaBootstrapper};
9
10pub(crate) use cpu::{CpuBootstrapKey, CpuBootstrapper};
11
12pub trait BooleanServerKey {
13    /// The LweSize of the Ciphertexts that this key can bootstrap
14    fn lwe_size(&self) -> LweSize;
15}
16
17/// Trait for types which implement the bootstrapping + key switching
18/// of a ciphertext.
19///
20/// Meant to be implemented for different hardware (CPU, GPU) or for other bootstrapping
21/// technics.
22pub(crate) trait Bootstrapper: Default {
23    type ServerKey: BooleanServerKey;
24
25    /// Shall return the result of the bootstrapping of the
26    /// input ciphertext or an error if any
27    fn bootstrap(
28        &mut self,
29        input: &LweCiphertext32,
30        server_key: &Self::ServerKey,
31    ) -> Result<LweCiphertext32, Box<dyn std::error::Error>>;
32
33    /// Shall return the result of the key switching of the
34    /// input ciphertext or an error if any
35    fn keyswitch(
36        &mut self,
37        input: &LweCiphertext32,
38        server_key: &Self::ServerKey,
39    ) -> Result<LweCiphertext32, Box<dyn std::error::Error>>;
40
41    /// Shall do the bootstrapping and key switching of the ciphertext.
42    /// The result is returned as a new value.
43    fn bootstrap_keyswitch(
44        &mut self,
45        ciphertext: LweCiphertext32,
46        server_key: &Self::ServerKey,
47    ) -> Result<Ciphertext, Box<dyn std::error::Error>>;
48}