mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-04-28 03:01:21 -04:00
Compare commits
2 Commits
main
...
am/chore/m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb400ed85a | ||
|
|
1c05b863f4 |
@@ -108,14 +108,14 @@ fn plans() -> &'static PlanMap {
|
||||
}
|
||||
|
||||
pub fn setup_custom_fft_plan(plan: Plan) {
|
||||
let base_n = FourierPolynomialSize(plan.fft_size());
|
||||
let n = base_n.to_standard_polynomial_size();
|
||||
let fft_size = FourierPolynomialSize(plan.fft_size());
|
||||
let std_poly_size = fft_size.to_standard_polynomial_size();
|
||||
|
||||
let plan = Arc::new((Twisties::new(base_n.0), plan));
|
||||
let plan = Arc::new((Twisties::new(fft_size.0), plan));
|
||||
|
||||
let global_plans = plans();
|
||||
|
||||
global_plans.set(n, plan);
|
||||
global_plans.set(std_poly_size, plan);
|
||||
}
|
||||
|
||||
/// Return the input slice, cast to the same type.
|
||||
|
||||
@@ -56,7 +56,7 @@ impl<Scalar: UnsignedInteger + CastFrom<u64>> ShortintEncoding<Scalar> {
|
||||
}
|
||||
|
||||
impl<Scalar: UnsignedInteger + CastFrom<u64>> ShortintEncoding<Scalar> {
|
||||
/// Return the cleatext space including the space for the [`Self::padding_bit`] if it is set to
|
||||
/// Return the cleartext space including the space for the [`Self::padding_bit`] if it is set to
|
||||
/// [`PaddingBit::Yes`].
|
||||
pub(crate) fn full_cleartext_space(&self) -> Scalar {
|
||||
let cleartext_modulus = self.cleartext_space_without_padding();
|
||||
@@ -69,7 +69,7 @@ impl<Scalar: UnsignedInteger + CastFrom<u64>> ShortintEncoding<Scalar> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the cleatext space defined by the [`Self::message_modulus`] and
|
||||
/// Return the cleartext space defined by the [`Self::message_modulus`] and
|
||||
/// [`Self::carry_modulus`], not taking the value of the [`Self::padding_bit`] into account.
|
||||
pub(crate) fn cleartext_space_without_padding(&self) -> Scalar {
|
||||
(self.message_modulus.0 * self.carry_modulus.0).cast_into()
|
||||
|
||||
@@ -1130,7 +1130,7 @@ pub mod test_utils {
|
||||
/// to 0 to keep the carry free.
|
||||
/// output_modulus: the output cleartext space, continuing the above example, it must contain
|
||||
/// the padding bit, so for 4 bits of cleartext this is actually 2^(1 + 4)==32
|
||||
pub fn cleatext_prf(
|
||||
pub fn cleartext_prf(
|
||||
input_cleartext: u64,
|
||||
random_bits_count: u64,
|
||||
output_modulus: u64,
|
||||
@@ -1163,7 +1163,7 @@ pub mod test_utils {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
use super::test_utils::cleatext_prf;
|
||||
use super::test_utils::cleartext_prf;
|
||||
use super::*;
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::prelude::{decrypt_lwe_ciphertext, CastInto, LweSecretKeyView};
|
||||
@@ -1244,7 +1244,7 @@ pub(crate) mod test {
|
||||
|
||||
// includes padding bit
|
||||
let output_modulus = 2 * params.message_modulus().0 * params.carry_modulus().0;
|
||||
let expected_output = cleatext_prf(
|
||||
let expected_output = cleartext_prf(
|
||||
plain_prf_input,
|
||||
random_bits_count,
|
||||
output_modulus,
|
||||
@@ -1477,4 +1477,67 @@ pub(crate) mod test {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oprf_test_uniformity_bits_ci_run_filter() {
|
||||
let sample_count: usize = 100_000;
|
||||
|
||||
let p_value_limit: f64 = 0.000_01;
|
||||
|
||||
use crate::shortint::gen_keys;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
for params in [
|
||||
ShortintParameterSet::from(
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
),
|
||||
ShortintParameterSet::from(PARAM_MESSAGE_2_CARRY_2_KS_PBS),
|
||||
ShortintParameterSet::from(TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128),
|
||||
] {
|
||||
let (ck, sk) = gen_keys(params);
|
||||
let oprf_ck = OprfPrivateKey::new(&ck);
|
||||
let oprf_sk = OprfServerKey::new(&oprf_ck, &ck).unwrap();
|
||||
|
||||
let random_bits_per_block = sk.message_modulus.0.ilog2() as u64;
|
||||
|
||||
for random_bits_count in [3u64, 4] {
|
||||
let expected_num_blocks =
|
||||
random_bits_count.div_ceil(random_bits_per_block) as usize;
|
||||
|
||||
test_uniformity(
|
||||
sample_count,
|
||||
p_value_limit,
|
||||
1 << random_bits_count,
|
||||
|seed| {
|
||||
let seed = (seed as u128).to_le_bytes();
|
||||
let blocks = oprf_sk.generate_oblivious_pseudo_random_bits(
|
||||
seed.as_slice(),
|
||||
random_bits_count,
|
||||
&sk,
|
||||
);
|
||||
|
||||
let mut combined: u64 = 0;
|
||||
let mut shift = 0u64;
|
||||
for (i, block) in blocks.iter().enumerate() {
|
||||
let decrypted = ck.decrypt_message_and_carry(block);
|
||||
let block_bits = bits_in_block(
|
||||
i,
|
||||
expected_num_blocks,
|
||||
random_bits_count,
|
||||
random_bits_per_block,
|
||||
);
|
||||
combined |= decrypted << shift;
|
||||
shift += block_bits;
|
||||
}
|
||||
|
||||
combined
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user