chore: fix new lints

This commit is contained in:
Mayeul@Zama
2025-11-05 13:39:57 +01:00
committed by mayeul-zama
parent 12426573fa
commit 36fb820ed4
8 changed files with 21 additions and 26 deletions

View File

@@ -38,18 +38,18 @@ unsafe fn rdseed_random_m128() -> u128 {
let mut rand1: u64 = 0;
let mut rand2: u64 = 0;
let mut output_bytes = [0u8; 16];
unsafe {
loop {
if core::arch::x86_64::_rdseed64_step(&mut rand1) == 1 {
break;
}
}
loop {
if core::arch::x86_64::_rdseed64_step(&mut rand2) == 1 {
break;
}
loop {
if core::arch::x86_64::_rdseed64_step(&mut rand1) == 1 {
break;
}
}
loop {
if core::arch::x86_64::_rdseed64_step(&mut rand2) == 1 {
break;
}
}
output_bytes[0..8].copy_from_slice(&rand1.to_ne_bytes());
output_bytes[8..16].copy_from_slice(&rand2.to_ne_bytes());
u128::from_ne_bytes(output_bytes)

View File

@@ -229,7 +229,7 @@ pub fn generate_keys() {
println!("Generating keys for core_crypto");
let classical_u32_params = vec![DUMMY_31_U32, DUMMY_NATIVE_U32];
let classical_u32_params = [DUMMY_31_U32, DUMMY_NATIVE_U32];
for param in classical_u32_params.iter().copied() {
let mut keys_gen = |_| lwe_programmable_bootstrapping::generate_keys(param, &mut rsc);
generate_and_store(param, &mut keys_gen);

View File

@@ -115,7 +115,7 @@ impl UpgradeGraph {
fn get_or_insert_node(&mut self, node: Node) -> NodeId {
self.index_of_node(&node)
.map_or_else(|| self.add_node(node), |index| index)
.unwrap_or_else(|| self.add_node(node))
}
fn add_node(&mut self, node: Node) -> NodeId {

View File

@@ -337,11 +337,7 @@ pub(crate) fn shr_assign(lhs: &mut [u64], shift: u32, shift_type: ShiftType) {
let value_mask = u64::MAX >> shift_in_words;
let carry_mask = ((1u64 << shift_in_words) - 1u64).rotate_right(shift_in_words);
let mut carry = if sign_bit == 1 {
u64::MAX & carry_mask
} else {
0
};
let mut carry = if sign_bit == 1 { carry_mask } else { 0 };
for word in &mut head.iter_mut().rev() {
let rotated = word.rotate_right(shift_in_words);
let value = (rotated & value_mask) | carry;

View File

@@ -257,6 +257,7 @@ mod tests {
}
#[test]
#[allow(clippy::identity_op)]
fn test_shr_limits() {
assert_eq!(U256::MAX >> 256u32, U256::MAX >> (256 % U256::BITS));
assert_eq!(U256::MAX >> 257u32, U256::MAX >> (257 % U256::BITS));

View File

@@ -137,6 +137,7 @@ mod tests {
}
#[test]
#[allow(clippy::identity_op)]
fn test_shr_limits() {
assert_eq!(U512::MAX >> 512u32, U512::MAX >> (512u32 % U512::BITS));
assert_eq!(U512::MAX >> 513u32, U512::MAX >> (513u32 % U512::BITS));

View File

@@ -226,14 +226,11 @@ pub mod utils {
// we check if we can load the key from persistent storage
let persistent_storage = &self.persistent_storage;
let maybe_key = persistent_storage.load(param);
maybe_key.map_or_else(
|| {
let key = key_gen_closure(param);
persistent_storage.store(param, &key);
key
},
|key| key,
)
maybe_key.unwrap_or_else(|| {
let key = key_gen_closure(param);
persistent_storage.store(param, &key);
key
})
};
let try_load_from_memory_and_init = || -> Result<_, ()> {

View File

@@ -813,7 +813,7 @@ impl<'keys> KeySwitchingKeyView<'keys> {
let output_ciphertext_count = functions.map_or_else(|| 1, |x| x.len());
let identity_fn_array: &[&(dyn Fn(u64) -> u64 + Sync)] = &[&|x: u64| x];
let functions_to_use = functions.map_or_else(|| identity_fn_array, |fns| fns);
let functions_to_use = functions.unwrap_or(identity_fn_array);
let using_user_provided_functions = functions.is_some();
let using_identity_lut = !using_user_provided_functions;
let mut output_cts = vec![self.dest_server_key.create_trivial(0); output_ciphertext_count];