mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-09 14:47:56 -05:00
chore: fix new clippy lints
This commit is contained in:
@@ -146,8 +146,7 @@ fn build_branches(
|
||||
build_branches(
|
||||
content,
|
||||
&(RegExpr::Seq {
|
||||
re_xs: std::iter::repeat(*repeat_re.clone())
|
||||
.take(std::cmp::max(1, at_least))
|
||||
re_xs: std::iter::repeat_n(*repeat_re.clone(), std::cmp::max(1, at_least))
|
||||
.collect(),
|
||||
}),
|
||||
c_pos,
|
||||
|
||||
@@ -294,7 +294,10 @@ fn encrypt_data<T: AsRef<[u8]>>(input: T, client_key: Option<&ClientKey>) -> Vec
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(iter::once(0x80))
|
||||
.chain(iter::repeat(0x00).take(if remainder == 0 { 0 } else { 64 - remainder }))
|
||||
.chain(std::iter::repeat_n(
|
||||
0x00,
|
||||
if remainder == 0 { 0 } else { 64 - remainder },
|
||||
))
|
||||
.chain(((len * 8) as u64).to_be_bytes());
|
||||
|
||||
ArrayChunks::<_, 4>::new(bytes_iter)
|
||||
|
||||
@@ -41,7 +41,7 @@ fn pad_sha256_data(data: &[u8]) -> Vec<bool> {
|
||||
|
||||
// Calculate the number of padding zeros required
|
||||
let padding_zeros = (512 - ((bits.len() + 64) % 512)) % 512;
|
||||
bits.extend(std::iter::repeat(false).take(padding_zeros));
|
||||
bits.extend(std::iter::repeat_n(false, padding_zeros));
|
||||
|
||||
// Append a 64-bit big-endian representation of the original message length
|
||||
let data_len_bits = (data.len() as u64) * 8;
|
||||
|
||||
@@ -39,18 +39,16 @@ impl KeySwitchingKey {
|
||||
pub fn cast_into(&self, ct: &Ciphertext, ct_dest: &mut Ciphertext) {
|
||||
match ct {
|
||||
Ciphertext::Trivial(_) => *ct_dest = ct.clone(),
|
||||
Ciphertext::Encrypted(ref cipher) => {
|
||||
match ct_dest {
|
||||
Ciphertext::Trivial(_) => {
|
||||
let mut cipher_dest = cipher.clone();
|
||||
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, &mut cipher_dest);
|
||||
*ct_dest = Ciphertext::Encrypted(cipher_dest);
|
||||
}
|
||||
Ciphertext::Encrypted(ref mut cipher_dest) => {
|
||||
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, cipher_dest);
|
||||
}
|
||||
};
|
||||
}
|
||||
Ciphertext::Encrypted(ref cipher) => match ct_dest {
|
||||
Ciphertext::Trivial(_) => {
|
||||
let mut cipher_dest = cipher.clone();
|
||||
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, &mut cipher_dest);
|
||||
*ct_dest = Ciphertext::Encrypted(cipher_dest);
|
||||
}
|
||||
Ciphertext::Encrypted(ref mut cipher_dest) => {
|
||||
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, cipher_dest);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ pub unsafe extern "C" fn compact_pke_crs_safe_serialize(
|
||||
crate::safe_serialization::SerializationConfig::new(serialized_size_limit)
|
||||
.serialize_into(&wrapper.0, &mut buffer)
|
||||
.unwrap();
|
||||
};
|
||||
}
|
||||
|
||||
*result = buffer.into();
|
||||
})
|
||||
|
||||
@@ -119,7 +119,7 @@ pub fn fill_lwe_mask_and_body_for_encryption_native_mod_compatible<
|
||||
*output_body.data = (*output_body.data).wrapping_mul(torus_scaling);
|
||||
}
|
||||
CiphertextModulusKind::Other => unreachable!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fill_lwe_mask_and_body_for_encryption_other_mod<
|
||||
|
||||
@@ -178,9 +178,10 @@ impl<Scalar: UnsignedTorus> CompressedModulusSwitchedGlweCiphertext<Scalar> {
|
||||
.unpack()
|
||||
// Scaling
|
||||
.map(|a| a << (Scalar::BITS - log_modulus))
|
||||
.chain(
|
||||
std::iter::repeat(Scalar::ZERO).take(self.polynomial_size.0 - self.bodies_count.0),
|
||||
)
|
||||
.chain(std::iter::repeat_n(
|
||||
Scalar::ZERO,
|
||||
self.polynomial_size.0 - self.bodies_count.0,
|
||||
))
|
||||
.collect();
|
||||
|
||||
GlweCiphertextOwned::from_container(
|
||||
|
||||
@@ -318,7 +318,7 @@ impl<Scalar: UnsignedInteger + CastInto<usize> + CastFrom<usize>>
|
||||
|
||||
if let Some(packed_diffs) = &self.packed_diffs {
|
||||
diffs_two_complement = packed_diffs.unpack().collect()
|
||||
};
|
||||
}
|
||||
|
||||
let diffs = |a: usize| {
|
||||
self.packed_diffs.as_ref().map_or(0, |packed_diffs| {
|
||||
|
||||
@@ -155,7 +155,7 @@ where
|
||||
self.data >>= self.num_bits_in_mask;
|
||||
} else {
|
||||
self.data = T::ZERO;
|
||||
};
|
||||
}
|
||||
|
||||
if self.num_bits_valid < self.num_bits_in_mask {
|
||||
// This will be the case when self.num_bits_in_mask is not a multiple
|
||||
|
||||
@@ -389,7 +389,7 @@ impl ClientKey {
|
||||
// End of T::BITS reached no need to try more
|
||||
// recomposition
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
recomposer.value()
|
||||
|
||||
@@ -67,7 +67,7 @@ impl CudaServerKey {
|
||||
d_multibit_bsk.grouping_factor,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn unchecked_abs<T>(&self, ct: &T, streams: &CudaStreams) -> T
|
||||
@@ -135,7 +135,7 @@ impl CudaServerKey {
|
||||
let mut res = unsafe { ct.duplicate_async(streams) };
|
||||
if !ct.block_carries_are_empty() {
|
||||
unsafe { self.full_propagate_assign_async(&mut res, streams) };
|
||||
};
|
||||
}
|
||||
if T::IS_SIGNED {
|
||||
unsafe { self.unchecked_abs_assign_async(&mut res, streams) };
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ impl CudaServerKey {
|
||||
d_multibit_bsk.grouping_factor,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
quotient.as_mut().info = quotient.as_ref().info.after_div_rem();
|
||||
remainder.as_mut().info = remainder.as_ref().info.after_div_rem();
|
||||
|
||||
@@ -286,7 +286,7 @@ impl CudaServerKey {
|
||||
uses_carry,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
ciphertext.info.blocks.iter_mut().for_each(|b| {
|
||||
b.degree = Degree::new(b.message_modulus.0 - 1);
|
||||
b.noise_level = NoiseLevel::NOMINAL;
|
||||
@@ -374,7 +374,7 @@ impl CudaServerKey {
|
||||
uses_carry,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
lhs.as_mut().info.blocks.iter_mut().for_each(|b| {
|
||||
b.degree = Degree::new(b.message_modulus.0 - 1);
|
||||
b.noise_level = NoiseLevel::NOMINAL;
|
||||
@@ -435,7 +435,7 @@ impl CudaServerKey {
|
||||
d_multibit_bsk.grouping_factor,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
ciphertext.info.blocks.iter_mut().for_each(|b| {
|
||||
b.degree = Degree::new(b.message_modulus.0 - 1);
|
||||
@@ -989,7 +989,7 @@ impl CudaServerKey {
|
||||
d_multibit_bsk.grouping_factor,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for (i, info) in output.info.blocks[block_range].iter_mut().enumerate() {
|
||||
@@ -1109,7 +1109,7 @@ impl CudaServerKey {
|
||||
self.message_modulus.0 as u32,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for (i, info) in output.info.blocks[block_range].iter_mut().enumerate() {
|
||||
@@ -1286,7 +1286,7 @@ impl CudaServerKey {
|
||||
lut.sample_extraction_stride as u32,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let mut ciphertexts = Vec::<CudaRadixCiphertext>::with_capacity(function_count);
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ impl CudaServerKey {
|
||||
d_multibit_bsk.grouping_factor,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ct_left.as_mut().info = ct_left.as_ref().info.after_mul();
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ impl CudaServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_assign_async(ct, streams);
|
||||
};
|
||||
}
|
||||
|
||||
self.unchecked_scalar_add_assign_async(ct, scalar, streams);
|
||||
let _carry = self.propagate_single_carry_assign_async(ct, streams, None, OutputFlag::None);
|
||||
|
||||
@@ -161,7 +161,7 @@ impl CudaServerKey {
|
||||
d_multibit_bsk.grouping_factor,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ct.as_mut().info = ct.as_ref().info.after_scalar_mul();
|
||||
}
|
||||
@@ -243,7 +243,7 @@ impl CudaServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_assign_async(ct, streams);
|
||||
};
|
||||
}
|
||||
|
||||
self.unchecked_scalar_mul_assign_async(ct, scalar, streams);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ impl CudaServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_assign_async(ct, streams);
|
||||
};
|
||||
}
|
||||
|
||||
self.unchecked_scalar_sub_assign_async(ct, scalar, streams);
|
||||
let _carry = self.propagate_single_carry_assign_async(ct, streams, None, OutputFlag::None);
|
||||
|
||||
@@ -429,7 +429,7 @@ impl CudaServerKey {
|
||||
uses_input_borrow,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
ciphertext.info.blocks.iter_mut().for_each(|b| {
|
||||
b.degree = Degree::new(b.message_modulus.0 - 1);
|
||||
b.noise_level = NoiseLevel::NOMINAL;
|
||||
|
||||
@@ -624,7 +624,7 @@ impl ServerKey {
|
||||
} else {
|
||||
let num_blocks_to_remove = current_num_blocks - target_num_blocks;
|
||||
self.trim_radix_blocks_msb_assign(&mut ct_as_unsigned_radix, num_blocks_to_remove);
|
||||
};
|
||||
}
|
||||
ct_as_unsigned_radix.blocks
|
||||
};
|
||||
|
||||
@@ -702,7 +702,7 @@ impl ServerKey {
|
||||
} else {
|
||||
let num_blocks_to_remove = current_num_blocks - target_num_blocks;
|
||||
self.trim_radix_blocks_msb_assign(&mut ct_as_unsigned_radix, num_blocks_to_remove);
|
||||
};
|
||||
}
|
||||
ct_as_unsigned_radix.blocks
|
||||
};
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ impl<'a> BitExtractor<'a> {
|
||||
} else {
|
||||
let iterator = blocks[..num_blocks_to_process].iter().cloned();
|
||||
self.buffer.extend(iterator);
|
||||
};
|
||||
}
|
||||
|
||||
// We have to advance our internal iterator
|
||||
self.input_blocks = blocks[num_blocks_to_process..].iter();
|
||||
|
||||
@@ -314,7 +314,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::RightRotate)
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::LeftRotate)
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::RightShift)
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::LeftShift)
|
||||
}
|
||||
|
||||
|
||||
@@ -631,7 +631,7 @@ impl ServerKey {
|
||||
};
|
||||
self.key.unchecked_scalar_add_assign(&mut result, corrector);
|
||||
result.degree = crate::shortint::ciphertext::Degree::new(3);
|
||||
};
|
||||
}
|
||||
|
||||
result
|
||||
})
|
||||
|
||||
@@ -83,7 +83,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
|
||||
self.unchecked_count_bits_parallelized(ct, kind)
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
|
||||
let scalar_blocks = BlockDecomposer::new(scalar, self.message_modulus().0.ilog2())
|
||||
.iter_as::<u8>()
|
||||
|
||||
@@ -1106,7 +1106,7 @@ mod tests {
|
||||
|
||||
// signed usage example
|
||||
let chosen = choose_multiplier(3u64, 31, 32);
|
||||
assert_eq!(chosen.multiplier, ((1u128 << 32) + 2) / 3);
|
||||
assert_eq!(chosen.multiplier, (1u128 << 32).div_ceil(3));
|
||||
assert_eq!(chosen.shift_post, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ impl ServerKey {
|
||||
{
|
||||
if !ct.block_carries_are_empty() {
|
||||
self.full_propagate_parallelized(ct);
|
||||
};
|
||||
}
|
||||
|
||||
if Scalar::ZERO == scalar {
|
||||
return;
|
||||
|
||||
@@ -342,7 +342,7 @@ fn draw_unique_randoms(
|
||||
special_value,
|
||||
modulus,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
let mut numbers = unique_numbers.into_iter().collect::<Vec<u64>>();
|
||||
for _ in 0..occurrence_count.saturating_sub(1) {
|
||||
|
||||
@@ -254,7 +254,7 @@ impl SerializationConfig {
|
||||
SerializationVersioningMode::Unversioned { .. } => {
|
||||
options.serialize_into(&mut writer, &object)?
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
let options = options.with_no_limit();
|
||||
|
||||
@@ -267,8 +267,8 @@ impl SerializationConfig {
|
||||
SerializationVersioningMode::Unversioned { .. } => {
|
||||
options.serialize_into(&mut writer, &object)?
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ impl ParameterSetConformant for ProvenCompactCiphertextList {
|
||||
} else {
|
||||
expected_len = remaining_len;
|
||||
remaining_len = 0;
|
||||
};
|
||||
}
|
||||
|
||||
let params = CiphertextListConformanceParams {
|
||||
ct_list_params: LweCiphertextListParameters {
|
||||
|
||||
@@ -1531,7 +1531,7 @@ pub(crate) fn apply_blind_rotate<Scalar, InputCont, OutputCont>(
|
||||
*deterministic_execution,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn apply_programmable_bootstrap<InputCont, OutputCont>(
|
||||
|
||||
@@ -898,7 +898,7 @@ mod experimental {
|
||||
ShortintBootstrappingKey::MultiBit { .. } => {
|
||||
return Err(WopbsKeyCreationError::UnsupportedMultiBit);
|
||||
}
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ fn ends_with_cases<'a>(
|
||||
let start = str_len - (pat_len - 1);
|
||||
|
||||
range = start..start + pat_len;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
(true, true) => {
|
||||
|
||||
Reference in New Issue
Block a user