Skip to content

Commit

Permalink
feat(hlapi): add generate_oblivious_pseudo_random on FheBool
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Sep 26, 2024
1 parent 4bb115e commit 84de0a7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions tfhe/src/high_level_api/booleans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ mod base;
mod compressed;
mod encrypt;
mod inner;
mod oprf;
#[cfg(test)]
mod tests;
39 changes: 39 additions & 0 deletions tfhe/src/high_level_api/booleans/oprf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use super::FheBool;
use crate::high_level_api::global_state;
use crate::high_level_api::keys::InternalServerKey;
use crate::integer::BooleanBlock;
use concrete_csprng::seeders::Seed;

impl FheBool {
/// Generates an encrypted boolean
/// taken uniformly using the given seed.
/// The encryted value is oblivious to the server.
/// It can be useful to make server random generation deterministic.
///
/// ```rust
/// use tfhe::prelude::FheDecrypt;
/// use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheBool, Seed};
///
/// let config = ConfigBuilder::default().build();
/// let (client_key, server_key) = generate_keys(config);
///
/// set_server_key(server_key);
///
/// let ct_res = FheBool::generate_oblivious_pseudo_random(Seed(0));
///
/// let dec_result: bool = ct_res.decrypt(&client_key);
/// ```
pub fn generate_oblivious_pseudo_random(seed: Seed) -> Self {
global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let ct = key.pbs_key().key.generate_oblivious_pseudo_random(seed, 1);

Self::new(BooleanBlock(ct), key.tag.clone())
}
#[cfg(feature = "gpu")]
InternalServerKey::Cuda(_) => {
todo!("Cuda devices do not yet support oblivious pseudo random generation")
}
})
}
}

0 comments on commit 84de0a7

Please sign in to comment.