chore: split up more xof key gen function

This commit is contained in:
Thomas Montaigu
2025-09-23 20:27:59 +02:00
committed by tmontaigu
parent 736185bb31
commit 8b5d7321fb
8 changed files with 605 additions and 513 deletions

View File

@@ -15,6 +15,8 @@ rust-version = "1.72"
aes = "0.8.2"
rayon = { workspace = true, optional = true }
getrandom = { workspace = true }
serde = "1.0.226"
tfhe-versionable = { version = "0.6.2", path = "../utils/tfhe-versionable" }
[target.'cfg(target_os = "macos")'.dependencies]
libc = "0.2.133"

View File

@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;
use crate::seeders::XofSeed;
#[derive(VersionsDispatch)]
pub enum XofSeedVersions {
V0(XofSeed),
}

View File

@@ -9,14 +9,15 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Seed(pub u128);
/// A Seed as described in the [NIST document]
/// A Seed as described in the [Threshold (Fully) Homomorphic Encryption]
///
/// This seed contains 2 information:
/// * The domain separator bytes (ASCII string)
/// * The seed bytes
///
/// [NIST document]: https://eprint.iacr.org/2025/699
#[derive(Debug, Clone, PartialEq, Eq)]
/// [Threshold (Fully) Homomorphic Encryption]: https://eprint.iacr.org/2025/699
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Versionize)]
#[versionize(XofSeedVersions)]
pub struct XofSeed {
// We store the domain separator concatenated with the seed bytes (str||seed)
// as it makes it easier to create the iterator of u128 blocks
@@ -97,7 +98,8 @@ pub enum SeedKind {
/// Initializes the Aes-Ctr with a counter starting at 0
/// and uses the seed as the Aes key.
Ctr(Seed),
/// Seed that initialized the Aes-Ctr following the NIST document (see [XofSeed]).
/// Seed that initialized the Aes-Ctr following the Threshold (Fully) Homomorphic Encryption
/// document (see [XofSeed]).
///
/// An Aes-Key and starting counter will be derived from the XofSeed, to
/// then initialize the Aes-Ctr random generator
@@ -128,11 +130,15 @@ pub trait Seeder {
Self: Sized;
}
pub mod backward_compatibility;
mod implem;
// This import statement can be empty if seeder features are disabled, rustc's behavior changed to
// warn of empty modules, we know this can happen, so allow it.
#[allow(unused_imports)]
pub use implem::*;
use tfhe_versionable::Versionize;
use crate::seeders::backward_compatibility::XofSeedVersions;
#[cfg(test)]
mod generic_tests {