-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hlapi): add generate_oblivious_pseudo_random on FheBool
- Loading branch information
1 parent
4bb115e
commit 84de0a7
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ mod base; | |
mod compressed; | ||
mod encrypt; | ||
mod inner; | ||
mod oprf; | ||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
}) | ||
} | ||
} |