Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many refactors #983

Merged
merged 12 commits into from
Mar 21, 2024
3 changes: 0 additions & 3 deletions apps/trivium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Example of a Rust main below:
```rust
use tfhe::{ConfigBuilder, generate_keys, FheBool};
use tfhe::prelude::*;

use tfhe_trivium::TriviumStream;

fn get_hexadecimal_string_from_lsb_first_stream(a: Vec<bool>) -> String {
Expand Down Expand Up @@ -139,10 +138,8 @@ Example code:
```rust
use tfhe::shortint::prelude::*;
use tfhe::shortint::CastingKey;

use tfhe::{ConfigBuilder, generate_keys, FheUint64};
use tfhe::prelude::*;

use tfhe_trivium::TriviumStreamShortint;

fn test_shortint() {
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/benches/kreyvium_bool.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use criterion::Criterion;
use tfhe::prelude::*;
use tfhe::{generate_keys, ConfigBuilder, FheBool};

use tfhe_trivium::KreyviumStream;

use criterion::Criterion;

pub fn kreyvium_bool_gen(c: &mut Criterion) {
let config = ConfigBuilder::default().build();
let (client_key, server_key) = generate_keys(config);
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/benches/kreyvium_byte.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use criterion::Criterion;
use tfhe::prelude::*;
use tfhe::{generate_keys, ConfigBuilder, FheUint64, FheUint8};

use tfhe_trivium::{KreyviumStreamByte, TransCiphering};

use criterion::Criterion;

pub fn kreyvium_byte_gen(c: &mut Criterion) {
let config = ConfigBuilder::default()
.enable_function_evaluation()
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/benches/trivium_bool.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use criterion::Criterion;
use tfhe::prelude::*;
use tfhe::{generate_keys, ConfigBuilder, FheBool};

use tfhe_trivium::TriviumStream;

use criterion::Criterion;

pub fn trivium_bool_gen(c: &mut Criterion) {
let config = ConfigBuilder::default().build();
let (client_key, server_key) = generate_keys(config);
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/benches/trivium_byte.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use criterion::Criterion;
use tfhe::prelude::*;
use tfhe::{generate_keys, ConfigBuilder, FheUint64, FheUint8};

use tfhe_trivium::{TransCiphering, TriviumStreamByte};

use criterion::Criterion;

pub fn trivium_byte_gen(c: &mut Criterion) {
let config = ConfigBuilder::default().build();
let (client_key, server_key) = generate_keys(config);
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/src/kreyvium/kreyvium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
//! for the representation of the inner bits.

use crate::static_deque::StaticDeque;

use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{set_server_key, unset_server_key, FheBool, ServerKey};

use rayon::prelude::*;

/// Internal trait specifying which operations are necessary for KreyviumStream generic type
pub trait KreyviumBoolInput<OpOutput>:
Sized
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/src/kreyvium/kreyvium_byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
//! for the representation of the inner bits.

use crate::static_deque::{StaticByteDeque, StaticByteDequeInput};

use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{set_server_key, unset_server_key, FheUint8, ServerKey};

use rayon::prelude::*;

/// Internal trait specifying which operations are necessary for KreyviumStreamByte generic type
pub trait KreyviumByteInput<OpOutput>:
Sized
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/src/kreyvium/kreyvium_shortint.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::static_deque::StaticDeque;

use tfhe::shortint::prelude::*;

use rayon::prelude::*;
use tfhe::shortint::prelude::*;

/// KreyviumStreamShortint: a struct implementing the Kreyvium stream cipher, using a generic
/// Ciphertext for the internal representation of bits (intended to represent a single bit). To be
Expand Down
3 changes: 1 addition & 2 deletions apps/trivium/src/kreyvium/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{KreyviumStream, KreyviumStreamByte, KreyviumStreamShortint, TransCiphering};
use tfhe::prelude::*;
use tfhe::{generate_keys, ConfigBuilder, FheBool, FheUint64, FheUint8};

use crate::{KreyviumStream, KreyviumStreamByte, KreyviumStreamShortint, TransCiphering};

// Values for these tests come from the github repo renaud1239/Kreyvium,
// commit fd6828f68711276c25f55e605935028f5e843f43

Expand Down
1 change: 1 addition & 0 deletions apps/trivium/src/static_deque/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[allow(clippy::module_inception)]
mod static_deque;
pub use static_deque::StaticDeque;

mod static_byte_deque;
pub use static_byte_deque::{StaticByteDeque, StaticByteDequeInput};
1 change: 0 additions & 1 deletion apps/trivium/src/static_deque/static_byte_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! This is pretending to store bits, and allows accessing bits in chunks of 8 consecutive.

use crate::static_deque::StaticDeque;

use tfhe::FheUint8;

/// Internal trait specifying which operations are needed by StaticByteDeque
Expand Down
6 changes: 2 additions & 4 deletions apps/trivium/src/trans_ciphering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
//! when trans ciphering is available to them.

use crate::{KreyviumStreamByte, KreyviumStreamShortint, TriviumStreamByte, TriviumStreamShortint};
use tfhe::shortint::Ciphertext;

use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::shortint::Ciphertext;
use tfhe::{set_server_key, unset_server_key, FheUint64, FheUint8, ServerKey};

use rayon::prelude::*;

/// Triat specifying the interface for trans ciphering a FheUint64 object. Since it is meant
/// to be used with stream ciphers, encryption and decryption are by default the same.
pub trait TransCiphering {
Expand Down
3 changes: 1 addition & 2 deletions apps/trivium/src/trivium/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{TransCiphering, TriviumStream, TriviumStreamByte, TriviumStreamShortint};
use tfhe::prelude::*;
use tfhe::{generate_keys, ConfigBuilder, FheBool, FheUint64, FheUint8};

use crate::{TransCiphering, TriviumStream, TriviumStreamByte, TriviumStreamShortint};

// Values for these tests come from the github repo cantora/avr-crypto-lib, commit 2a5b018,
// file testvectors/trivium-80.80.test-vectors

Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/src/trivium/trivium_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
//! for the representation of the inner bits.

use crate::static_deque::StaticDeque;

use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{set_server_key, unset_server_key, FheBool, ServerKey};

use rayon::prelude::*;

/// Internal trait specifying which operations are necessary for TriviumStream generic type
pub trait TriviumBoolInput<OpOutput>:
Sized
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/src/trivium/trivium_byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
//! for the representation of the inner bits.

use crate::static_deque::{StaticByteDeque, StaticByteDequeInput};

use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{set_server_key, unset_server_key, FheUint8, ServerKey};

use rayon::prelude::*;

/// Internal trait specifying which operations are necessary for TriviumStreamByte generic type
pub trait TriviumByteInput<OpOutput>:
Sized
Expand Down
4 changes: 1 addition & 3 deletions apps/trivium/src/trivium/trivium_shortint.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::static_deque::StaticDeque;

use tfhe::shortint::prelude::*;

use rayon::prelude::*;
use tfhe::shortint::prelude::*;

/// TriviumStreamShortint: a struct implementing the Trivium stream cipher, using a generic
/// Ciphertext for the internal representation of bits (intended to represent a single bit). To be
Expand Down
7 changes: 2 additions & 5 deletions concrete-csprng/examples/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@ use clap::{value_parser, Arg, Command};
use concrete_csprng::generators::AesniRandomGenerator as ActivatedRandomGenerator;
#[cfg(feature = "generator_aarch64_aes")]
use concrete_csprng::generators::NeonAesRandomGenerator as ActivatedRandomGenerator;
use concrete_csprng::generators::RandomGenerator;
#[cfg(all(
not(feature = "generator_x86_64_aesni"),
not(feature = "generator_aarch64_aes"),
feature = "generator_fallback"
))]
use concrete_csprng::generators::SoftwareRandomGenerator as ActivatedRandomGenerator;

use concrete_csprng::generators::RandomGenerator;

#[cfg(target_os = "macos")]
use concrete_csprng::seeders::AppleSecureEnclaveSeeder as ActivatedSeeder;
#[cfg(all(not(target_os = "macos"), feature = "seeder_x86_64_rdseed"))]
use concrete_csprng::seeders::RdseedSeeder as ActivatedSeeder;
use concrete_csprng::seeders::Seeder;
#[cfg(all(
not(target_os = "macos"),
not(feature = "seeder_x86_64_rdseed"),
feature = "seeder_unix"
))]
use concrete_csprng::seeders::UnixSeeder as ActivatedSeeder;

use concrete_csprng::seeders::Seeder;

use std::io::prelude::*;
use std::io::{stdout, StdoutLock};

Expand Down
25 changes: 1 addition & 24 deletions tasks/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#[macro_use]
extern crate lazy_static;
use clap::{Arg, Command};
use lazy_static::lazy_static;
use log::LevelFilter;
use simplelog::{ColorChoice, CombinedLogger, Config, TermLogger, TerminalMode};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Relaxed;

Expand All @@ -16,26 +13,6 @@ mod utils;
// -------------------------------------------------------------------------------------------------
lazy_static! {
static ref DRY_RUN: AtomicBool = AtomicBool::new(false);
static ref ROOT_DIR: PathBuf = utils::project_root();
static ref ENV_TARGET_NATIVE: utils::Environment = {
let mut env = HashMap::new();
env.insert("RUSTFLAGS", "-Ctarget-cpu=native");
env
};
}

// -------------------------------------------------------------------------------------------------
// MACROS
// -------------------------------------------------------------------------------------------------

#[macro_export]
macro_rules! cmd {
(<$env: ident> $cmd: expr) => {
$crate::utils::execute($cmd, Some(&*$env), Some(&*$crate::ROOT_DIR))
};
($cmd: expr) => {
$crate::utils::execute($cmd, None, Some(&*$crate::ROOT_DIR))
};
}

// -------------------------------------------------------------------------------------------------
Expand Down
41 changes: 0 additions & 41 deletions tasks/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
use log::{debug, info};
use std::collections::HashMap;
use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::atomic::Ordering::Relaxed;

pub type Environment = HashMap<&'static str, &'static str>;

#[allow(dead_code)]
pub fn execute(cmd: &str, env: Option<&Environment>, cwd: Option<&PathBuf>) -> Result<(), Error> {
info!("Executing {}", cmd);
debug!("Env {:?}", env);
debug!("Cwd {:?}", cwd);
if crate::DRY_RUN.load(Relaxed) {
info!("Skipping execution because of --dry-run mode");
return Ok(());
}
let mut command = Command::new("sh");
command
.arg("-c")
.arg(cmd)
.stderr(Stdio::inherit())
.stdout(Stdio::inherit());
if let Some(env) = env {
for (key, val) in env.iter() {
command.env(key, val);
}
}
if let Some(cwd) = cwd {
command.current_dir(cwd);
}
let output = command.output()?;
if !output.status.success() {
Err(Error::new(
ErrorKind::Other,
"Command exited with nonzero status.",
))
} else {
Ok(())
}
}

pub fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR"))
Expand Down
2 changes: 1 addition & 1 deletion tfhe/benches/boolean/bench.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[path = "../utilities.rs"]
mod utilities;
use crate::utilities::{write_to_json, CryptoParametersRecord, OperatorType};

use crate::utilities::{write_to_json, CryptoParametersRecord, OperatorType};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tfhe::boolean::client_key::ClientKey;
use tfhe::boolean::parameters::{
Expand Down
1 change: 1 addition & 0 deletions tfhe/benches/core_crypto/ks_bench.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[path = "../utilities.rs"]
mod utilities;

use crate::utilities::{write_to_json, CryptoParametersRecord, OperatorType};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use serde::Serialize;
Expand Down
5 changes: 2 additions & 3 deletions tfhe/benches/core_crypto/pbs_bench.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#[path = "../utilities.rs"]
mod utilities;
use crate::utilities::{write_to_json, CryptoParametersRecord, OperatorType};
use rayon::prelude::*;

use crate::utilities::{write_to_json, CryptoParametersRecord, OperatorType};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rayon::prelude::*;
use serde::Serialize;
use tfhe::boolean::parameters::{
BooleanParameters, DEFAULT_PARAMETERS, PARAMETERS_ERROR_PROB_2_POW_MINUS_165,
};

use tfhe::core_crypto::prelude::*;
use tfhe::keycache::NamedParam;
use tfhe::shortint::parameters::*;
Expand Down
4 changes: 1 addition & 3 deletions tfhe/benches/high_level_api/bench.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::ops::*;

use criterion::{black_box, Criterion};

use rand::prelude::*;
use std::fmt::Write;
use std::ops::*;
use tfhe::prelude::*;
use tfhe::shortint::parameters::*;
use tfhe::{
Expand Down
15 changes: 3 additions & 12 deletions tfhe/benches/integer/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
mod utilities;

use crate::utilities::{write_to_json, EnvConfig, OperatorType};
use std::env;

use criterion::{criterion_group, Criterion};
use itertools::iproduct;
use rand::prelude::*;
use std::env;
use std::vec::IntoIter;
use tfhe::integer::keycache::KEY_CACHE;
use tfhe::integer::{IntegerKeyKind, RadixCiphertext, RadixClientKey, ServerKey};
use tfhe::integer::{IntegerKeyKind, RadixCiphertext, RadixClientKey, ServerKey, U256};
use tfhe::keycache::NamedParam;

use tfhe::integer::U256;

#[allow(unused_imports)]
use tfhe::shortint::parameters::{
PARAM_MESSAGE_1_CARRY_1_KS_PBS, PARAM_MESSAGE_2_CARRY_2_KS_PBS, PARAM_MESSAGE_3_CARRY_3_KS_PBS,
PARAM_MESSAGE_4_CARRY_4_KS_PBS, PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS,
PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS,
};
use tfhe::shortint::parameters::*;

/// The type used to hold scalar values
/// It must be as big as the largest bit size tested
Expand Down
4 changes: 1 addition & 3 deletions tfhe/benches/integer/signed_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
mod utilities;

use crate::utilities::{write_to_json, EnvConfig, OperatorType};
use std::env;

use criterion::{criterion_group, Criterion};
use itertools::iproduct;
use rand::prelude::*;
use std::env;
use std::vec::IntoIter;
use tfhe::integer::keycache::KEY_CACHE;
use tfhe::integer::{IntegerKeyKind, RadixCiphertext, ServerKey, SignedRadixCiphertext, I256};
use tfhe::keycache::NamedParam;

use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
#[cfg(not(feature = "gpu"))]
use tfhe::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS;
Expand Down
Loading
Loading