mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
chore(csprng)!: remove seeder_x86_64_rdseed feature
BREAKING_CHANGE: - The `seeder_x86_64_rdseed` feature is no longer supported for tfhe-csprng
This commit is contained in:
committed by
Nicolas Sarlin
parent
e0ee8af1ac
commit
3de23d14a2
@@ -25,14 +25,12 @@ clap = "=4.4.4"
|
||||
|
||||
[features]
|
||||
parallel = ["rayon"]
|
||||
seeder_x86_64_rdseed = []
|
||||
generator_x86_64_aesni = []
|
||||
generator_fallback = []
|
||||
generator_aarch64_aes = []
|
||||
|
||||
x86_64 = [
|
||||
"parallel",
|
||||
"seeder_x86_64_rdseed",
|
||||
"generator_x86_64_aesni",
|
||||
"generator_fallback",
|
||||
]
|
||||
@@ -44,7 +42,7 @@ aarch64-unix = ["aarch64"]
|
||||
name = "benchmark"
|
||||
path = "benches/benchmark.rs"
|
||||
harness = false
|
||||
required-features = ["seeder_x86_64_rdseed", "generator_x86_64_aesni"]
|
||||
required-features = ["generator_x86_64_aesni"]
|
||||
|
||||
[[example]]
|
||||
name = "generate"
|
||||
|
||||
@@ -8,13 +8,13 @@ The implementation is based on the AES blockcipher used in CTR mode, as describe
|
||||
|
||||
Two implementations are available, an accelerated one on x86_64 CPUs with the `aes` feature and the `sse2` feature, and a pure software one that can be used on other platforms.
|
||||
|
||||
The crate also makes two seeders available, one needing the x86_64 feature `rdseed` and another one based on the Unix random device `/dev/random` the latter requires the user to provide a secret.
|
||||
The crate also makes two seeders available, one needing the x86_64 instruction `rdseed` and another one based on the Unix random device `/dev/random` the latter requires the user to provide a secret.
|
||||
|
||||
## Running the benchmarks
|
||||
|
||||
To execute the benchmarks on an x86_64 platform:
|
||||
```shell
|
||||
RUSTFLAGS="-Ctarget-cpu=native" cargo bench --features=seeder_x86_64_rdseed,generator_x86_64_aesni
|
||||
RUSTFLAGS="-Ctarget-cpu=native" cargo bench --features=generator_x86_64_aesni
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@@ -8,7 +8,7 @@ use tfhe_csprng::seeders::{RdseedSeeder, Seeder};
|
||||
const N_GEN: usize = 1_000_000;
|
||||
|
||||
fn parent_generate(c: &mut Criterion) {
|
||||
let mut seeder = RdseedSeeder;
|
||||
let mut seeder = RdseedSeeder::new();
|
||||
let mut generator = AesniRandomGenerator::new(seeder.seed());
|
||||
c.bench_function("parent_generate", |b| {
|
||||
b.iter(|| {
|
||||
@@ -20,7 +20,7 @@ fn parent_generate(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn child_generate(c: &mut Criterion) {
|
||||
let mut seeder = RdseedSeeder;
|
||||
let mut seeder = RdseedSeeder::new();
|
||||
let mut generator = AesniRandomGenerator::new(seeder.seed());
|
||||
let mut generator = generator
|
||||
.try_fork(ChildrenCount(1), BytesPerChild(N_GEN * 10_000))
|
||||
@@ -37,7 +37,7 @@ fn child_generate(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn fork(c: &mut Criterion) {
|
||||
let mut seeder = RdseedSeeder;
|
||||
let mut seeder = RdseedSeeder::new();
|
||||
let mut generator = AesniRandomGenerator::new(seeder.seed());
|
||||
c.bench_function("fork", |b| {
|
||||
b.iter(|| {
|
||||
|
||||
@@ -53,12 +53,7 @@ impl FeatureRequirement {
|
||||
|
||||
// const vecs are not yet a thing so use a fixed size array (update the array size when adding
|
||||
// requirements)
|
||||
static FEATURE_REQUIREMENTS: [FeatureRequirement; 3] = [
|
||||
FeatureRequirement {
|
||||
feature_name: "seeder_x86_64_rdseed",
|
||||
feature_req_target_arch: Some("x86_64"),
|
||||
feature_req_target_family: None,
|
||||
},
|
||||
static FEATURE_REQUIREMENTS: [FeatureRequirement; 2] = [
|
||||
FeatureRequirement {
|
||||
feature_name: "generator_x86_64_aesni",
|
||||
feature_req_target_arch: Some("x86_64"),
|
||||
@@ -83,7 +78,6 @@ macro_rules! feature_cfg {
|
||||
// function that returns the HashMap we are interested in
|
||||
fn get_feature_enabled_status() -> HashMap<&'static str, bool> {
|
||||
HashMap::from([
|
||||
feature_cfg!("seeder_x86_64_rdseed"),
|
||||
feature_cfg!("generator_x86_64_aesni"),
|
||||
feature_cfg!("generator_aarch64_aes"),
|
||||
])
|
||||
|
||||
@@ -18,12 +18,16 @@ use std::io::prelude::*;
|
||||
use std::io::{stdout, StdoutLock};
|
||||
#[cfg(target_os = "macos")]
|
||||
use tfhe_csprng::seeders::AppleSecureEnclaveSeeder as ActivatedSeeder;
|
||||
#[cfg(all(not(target_os = "macos"), feature = "seeder_x86_64_rdseed"))]
|
||||
#[cfg(all(
|
||||
not(target_os = "macos"),
|
||||
target_arch = "x86_64",
|
||||
target_feature = "rdseed"
|
||||
))]
|
||||
use tfhe_csprng::seeders::RdseedSeeder as ActivatedSeeder;
|
||||
use tfhe_csprng::seeders::Seeder;
|
||||
#[cfg(all(
|
||||
not(target_os = "macos"),
|
||||
not(feature = "seeder_x86_64_rdseed"),
|
||||
not(all(target_arch = "x86_64", target_feature = "rdseed")),
|
||||
target_family = "unix"
|
||||
))]
|
||||
use tfhe_csprng::seeders::UnixSeeder as ActivatedSeeder;
|
||||
@@ -77,16 +81,16 @@ pub fn main() {
|
||||
// Ugly hack to be able to use UnixSeeder
|
||||
#[cfg(all(
|
||||
not(target_os = "macos"),
|
||||
not(feature = "seeder_x86_64_rdseed"),
|
||||
not(all(target_arch = "x86_64", target_feature = "rdseed")),
|
||||
target_family = "unix"
|
||||
))]
|
||||
let new_seeder = || ActivatedSeeder::new(0);
|
||||
#[cfg(not(all(
|
||||
not(target_os = "macos"),
|
||||
not(feature = "seeder_x86_64_rdseed"),
|
||||
not(all(target_arch = "x86_64", target_feature = "rdseed")),
|
||||
target_family = "unix"
|
||||
)))]
|
||||
let new_seeder = || ActivatedSeeder;
|
||||
let new_seeder = || ActivatedSeeder::new();
|
||||
|
||||
let mut seeder = new_seeder();
|
||||
let seed = seeder.seed();
|
||||
|
||||
@@ -3,9 +3,9 @@ mod apple_secure_enclave_seeder;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use apple_secure_enclave_seeder::AppleSecureEnclaveSeeder;
|
||||
|
||||
#[cfg(feature = "seeder_x86_64_rdseed")]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
mod rdseed;
|
||||
#[cfg(feature = "seeder_x86_64_rdseed")]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub use rdseed::RdseedSeeder;
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
|
||||
@@ -4,7 +4,23 @@ use crate::seeders::{Seed, Seeder};
|
||||
///
|
||||
/// The `rdseed` instruction allows to deliver seeds from a hardware source of entropy see
|
||||
/// <https://www.felixcloutier.com/x86/rdseed> .
|
||||
pub struct RdseedSeeder;
|
||||
pub struct RdseedSeeder(());
|
||||
|
||||
impl RdseedSeeder {
|
||||
pub fn new() -> Self {
|
||||
if Self::is_available() {
|
||||
Self(())
|
||||
} else {
|
||||
panic!("Tried to use RdSeedSeeder but rdseed instruction is not enabled on the current machine");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RdseedSeeder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Seeder for RdseedSeeder {
|
||||
fn seed(&mut self) -> Seed {
|
||||
@@ -46,6 +62,6 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn check_bounded_sequence_difference() {
|
||||
check_seeder_fixed_sequences_different(|_| RdseedSeeder);
|
||||
check_seeder_fixed_sequences_different(|_| RdseedSeeder::new());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,13 +141,11 @@ generator_aarch64_aes = ["tfhe-csprng/generator_aarch64_aes"]
|
||||
__profiling = []
|
||||
__long_run_tests = []
|
||||
|
||||
seeder_x86_64_rdseed = ["tfhe-csprng/seeder_x86_64_rdseed"]
|
||||
|
||||
# These target_arch features enable a set of public features for tfhe if users want a known
|
||||
# good/working configuration for tfhe.
|
||||
# For a target_arch that does not yet have such a feature, one can still enable features manually or
|
||||
# create a feature for said target_arch to make its use simpler.
|
||||
x86_64 = ["generator_x86_64_aesni", "seeder_x86_64_rdseed"]
|
||||
x86_64 = ["generator_x86_64_aesni"]
|
||||
x86_64-unix = ["x86_64"]
|
||||
|
||||
aarch64 = ["generator_aarch64_aes"]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
pub use crate::core_crypto::commons::math::random::Seeder;
|
||||
#[cfg(all(target_os = "macos", not(feature = "__wasm_api")))]
|
||||
pub use tfhe_csprng::seeders::AppleSecureEnclaveSeeder;
|
||||
#[cfg(feature = "seeder_x86_64_rdseed")]
|
||||
#[cfg(all(target_arch = "x86_64", not(feature = "__wasm_api")))]
|
||||
pub use tfhe_csprng::seeders::RdseedSeeder;
|
||||
#[cfg(all(target_family = "unix", not(feature = "__wasm_api")))]
|
||||
pub use tfhe_csprng::seeders::UnixSeeder;
|
||||
@@ -41,7 +41,7 @@ mod wasm_seeder {
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// With the `seeder_x86_64_rdseed` feature enabled on `x86_64` CPUs the rdseed seeder is
|
||||
/// When the `rdseed` CPU feature is detected on `x86_64` CPUs the rdseed seeder is
|
||||
/// prioritized.
|
||||
///
|
||||
/// On macOS the next seeder to be prioritized uses Apple's [`Randomization
|
||||
@@ -74,10 +74,10 @@ pub fn new_seeder() -> Box<dyn Seeder> {
|
||||
|
||||
#[cfg(not(feature = "__wasm_api"))]
|
||||
{
|
||||
#[cfg(feature = "seeder_x86_64_rdseed")]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
if RdseedSeeder::is_available() {
|
||||
seeder = Some(Box::new(RdseedSeeder));
|
||||
seeder = Some(Box::new(RdseedSeeder::new()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user