From c82d1565ceeefdf3a423f4ef6922106e4ecabe9e Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Tue, 21 Nov 2023 15:54:57 -0500 Subject: [PATCH] cargo clippy --- performance/src/challenge.rs | 3 +-- performance/src/indexed_heap.rs | 6 ++++- performance/src/zeta.rs | 10 ++++---- performance/src/zssp.rs | 2 +- reference/src/context.rs | 6 ++--- reference/src/crypto_impl/aes_impl.rs | 10 ++++---- reference/src/zeta.rs | 36 +++++++++++++-------------- 7 files changed, 38 insertions(+), 35 deletions(-) diff --git a/performance/src/challenge.rs b/performance/src/challenge.rs index 09b14d4..815fc7e 100644 --- a/performance/src/challenge.rs +++ b/performance/src/challenge.rs @@ -26,7 +26,7 @@ pub fn respond_to_challenge_in_place( challenge: &[u8; CHALLENGE_SIZE], pre_response: &mut [u8; CHALLENGE_SIZE], ) { - if &challenge[POW_START..] == &pre_response[POW_START..] { + if challenge[POW_START..] == pre_response[POW_START..] { pre_response.copy_from_slice(challenge); let mut pow = rng.next_u64(); let mut work_buf = [0u8; SHA512_HASH_SIZE]; @@ -79,7 +79,6 @@ impl ChallengeContext { hasher.write(&c.to_be_bytes()); addr.hash(&mut hasher); hasher.write(&self.salt); - drop(hasher); let mut mac = [0u8; SHA512_HASH_SIZE]; hash.finish_and_reset(&mut mac); diff --git a/performance/src/indexed_heap.rs b/performance/src/indexed_heap.rs index b37dc70..bd711e4 100644 --- a/performance/src/indexed_heap.rs +++ b/performance/src/indexed_heap.rs @@ -31,7 +31,11 @@ pub struct IndexedBinaryHeap { data: Vec<(T, P, usize)>, map: Vec<(usize, u64)>, } - +impl Default for IndexedBinaryHeap { + fn default() -> Self { + Self::new() + } +} impl IndexedBinaryHeap { /// Create a new, empty binary heap. pub fn new() -> Self { diff --git a/performance/src/zeta.rs b/performance/src/zeta.rs index b7f50dd..0bcdd60 100644 --- a/performance/src/zeta.rs +++ b/performance/src/zeta.rs @@ -432,7 +432,7 @@ pub(crate) fn received_x1_trans>( return Err(fault!(InvalidPacket, true)); } - if &n[AES_GCM_NONCE_SIZE - 8..] != &x1[x1.len() - 8..] { + if n[AES_GCM_NONCE_SIZE - 8..] != x1[x1.len() - 8..] { return Err(fault!(FailedAuth, true)); } let hmac = &mut C::Hmac::new(); @@ -591,7 +591,7 @@ pub(crate) fn received_x2_trans>( return Err(fault!(UnknownLocalKeyId, true, session)); } let (_, c) = from_nonce(n); - if c >= COUNTER_WINDOW_MAX_SKIP_AHEAD || &n[AES_GCM_NONCE_SIZE - 3..] != &x2[x2.len() - 3..] { + if c >= COUNTER_WINDOW_MAX_SKIP_AHEAD || n[AES_GCM_NONCE_SIZE - 3..] != x2[x2.len() - 3..] { return Err(fault!(FailedAuth, true, session)); } @@ -690,7 +690,7 @@ pub(crate) fn received_x2_trans>( let tag = noise.encrypt_and_hash_in_place(hash, to_nonce(PACKET_TYPE_HANDSHAKE_COMPLETION, 0), &mut x3[i..]); x3.extend(tag); - let new_ratchet_state = create_ratchet_state(hmac, &mut noise, chain_len); + let new_ratchet_state = create_ratchet_state(hmac, &noise, chain_len); let (ratchet_to_preserve, ratchet_to_delete) = if ratchet_i == 1 { (Some(&state.ratchet_state1), state.ratchet_state2.as_ref()) @@ -859,7 +859,7 @@ pub(crate) fn received_x3_trans>( let RatchetStates { state1, state2 } = rss.unwrap_or_default(); let mut should_warn_missing_ratchet = false; - if (&zeta.ratchet_state != &state1) & (Some(&zeta.ratchet_state) != state2.as_ref()) { + if (zeta.ratchet_state != state1) & (Some(&zeta.ratchet_state) != state2.as_ref()) { if !responder_disallows_downgrade && zeta.ratchet_state.fingerprint().is_none() { should_warn_missing_ratchet = true; } else { @@ -873,7 +873,7 @@ pub(crate) fn received_x3_trans>( let mut noise_kk_ss = Zeroizing::new([0u8; P384_ECDH_SHARED_SECRET_SIZE]); ctx.s_secret.agree(&s_remote, &mut noise_kk_ss); - let new_ratchet_state = create_ratchet_state(hmac, &mut noise, zeta.ratchet_state.chain_len); + let new_ratchet_state = create_ratchet_state(hmac, &noise, zeta.ratchet_state.chain_len); let mut nk_recv = Zeroizing::new([0u8; HASHLEN]); let mut nk_send = Zeroizing::new([0u8; HASHLEN]); noise.split(hmac, &mut nk_send, &mut nk_recv); diff --git a/performance/src/zssp.rs b/performance/src/zssp.rs index 9c49e0b..9d7fc18 100644 --- a/performance/src/zssp.rs +++ b/performance/src/zssp.rs @@ -199,7 +199,7 @@ impl Context { /// * `remote_address` - Whatever the remote address is, as long as you can Hash it /// * `incoming_fragment_buf` - Buffer containing incoming wire packet (the context takes ownership) /// * `output_buffer` - Buffer to receive decrypted and authenticated object data - pub fn receive<'a, App: ApplicationLayer>( + pub fn receive>( &self, mut app: App, mut send_unassociated_reply: impl Sender, diff --git a/reference/src/context.rs b/reference/src/context.rs index 482705f..e5a849a 100644 --- a/reference/src/context.rs +++ b/reference/src/context.rs @@ -201,7 +201,7 @@ impl Context { let (p, _) = from_nonce(&pn); let ret = match p { PACKET_TYPE_DATA => { - received_payload_in_place::( + received_payload_in_place::( &mut zeta, kid_recv, to_aes_nonce(&pn), @@ -291,7 +291,7 @@ impl Context { } PACKET_TYPE_SESSION_REJECTED => { log!(app, ReceivedRawD); - received_d_trans::(&mut zeta, kid_recv, to_aes_nonce(&pn), assembled_packet)?; + received_d_trans::(&mut zeta, kid_recv, to_aes_nonce(&pn), assembled_packet)?; log!(app, DIsAuthClosedSession(&session)); SessionEvent::Rejected } @@ -432,7 +432,7 @@ impl Context { { if let Some(Some(session)) = ctx.session_map.borrow_mut().get(&kid_recv).map(|r| r.upgrade()) { let mut zeta = session.0.borrow_mut(); - respond_to_challenge::( + respond_to_challenge::( &mut zeta, &ctx.rng, &assembled_packet[KID_SIZE..].try_into().unwrap(), diff --git a/reference/src/crypto_impl/aes_impl.rs b/reference/src/crypto_impl/aes_impl.rs index 5160ef4..e8565d7 100644 --- a/reference/src/crypto_impl/aes_impl.rs +++ b/reference/src/crypto_impl/aes_impl.rs @@ -29,9 +29,9 @@ impl AesGcmAead for AesGcmCrate { buffer: &mut [u8], ) -> [u8; AES_GCM_TAG_SIZE] { let key = Key::::from_slice(key); - let mut cipher = Aes256Gcm::new(&key); + let mut cipher = Aes256Gcm::new(key); cipher - .encrypt_in_place_detached(&Nonce::from_slice(iv), aad.unwrap_or(&[]), buffer) + .encrypt_in_place_detached(Nonce::from_slice(iv), aad.unwrap_or(&[]), buffer) .unwrap() .try_into() .unwrap() @@ -45,13 +45,13 @@ impl AesGcmAead for AesGcmCrate { tag: &[u8; AES_GCM_TAG_SIZE], ) -> bool { let key = Key::::from_slice(key); - let mut cipher = Aes256Gcm::new(&key); + let mut cipher = Aes256Gcm::new(key); cipher .decrypt_in_place_detached( - &Nonce::from_slice(iv), + Nonce::from_slice(iv), aad.unwrap_or(&[]), buffer, - &Tag::from_slice(tag), + Tag::from_slice(tag), ) .is_ok() } diff --git a/reference/src/zeta.rs b/reference/src/zeta.rs index c9de2b2..d7d4558 100644 --- a/reference/src/zeta.rs +++ b/reference/src/zeta.rs @@ -295,7 +295,7 @@ pub(crate) fn trans_to_a1>( ) -> Result>, OpenError> { let ratchet_states = app .restore_by_identity(&s_remote, &session_data) - .map_err(|e| OpenError::StorageError(e))?; + .map_err(OpenError::StorageError)?; let RatchetStates { state1, state2 } = ratchet_states.unwrap_or_default(); let mut session_map = ctx.session_map.borrow_mut(); @@ -338,7 +338,7 @@ pub(crate) fn trans_to_a1>( Ok(session) } /// Corresponds to Algorithm 13 found in Section 5. -pub(crate) fn respond_to_challenge>( +pub(crate) fn respond_to_challenge( zeta: &mut Zeta, rng: &RefCell, challenge: &[u8; CHALLENGE_SIZE], @@ -368,7 +368,7 @@ pub(crate) fn received_x1_trans>( if !(HANDSHAKE_HELLO_MIN_SIZE..=HANDSHAKE_HELLO_MAX_SIZE).contains(&x1.len()) { return Err(byzantine_fault!(InvalidPacket, true)); } - if &n[AES_GCM_NONCE_SIZE - 8..] != &x1[x1.len() - 8..] { + if n[AES_GCM_NONCE_SIZE - 8..] != x1[x1.len() - 8..] { return Err(byzantine_fault!(FailedAuth, true)); } let mut noise = SymmetricState::::initialize(PROTOCOL_NAME_NOISE_XK); @@ -499,7 +499,7 @@ pub(crate) fn received_x2_trans>( return Err(byzantine_fault!(UnknownLocalKeyId, true)); } let (_, c) = from_nonce(&n); - if c >= COUNTER_WINDOW_MAX_SKIP_AHEAD || &n[AES_GCM_NONCE_SIZE - 3..] != &x2[x2.len() - 3..] { + if c >= COUNTER_WINDOW_MAX_SKIP_AHEAD || n[AES_GCM_NONCE_SIZE - 3..] != x2[x2.len() - 3..] { return Err(byzantine_fault!(FailedAuth, true)); } let mut should_warn_missing_ratchet = false; @@ -538,7 +538,7 @@ pub(crate) fn received_x2_trans>( // Check for which ratchet key Bob wants to use. let test_ratchet_key = |ratchet_key| -> Option<(NonZeroU32, SymmetricState)> { let mut noise = noise.clone(); - let mut payload = payload.clone(); + let mut payload = payload; // Process message pattern 2 psk token. noise.mix_key_and_hash(ratchet_key); // Process message pattern 2 payload. @@ -639,7 +639,7 @@ pub(crate) fn received_x2_trans>( } result.map(|_| should_warn_missing_ratchet) } -fn send_control>( +fn send_control( zeta: &mut Zeta, packet_type: u8, mut payload: Vec, @@ -726,7 +726,7 @@ pub(crate) fn received_x3_trans>( let RatchetStates { state1, state2 } = rss.unwrap_or_default(); let mut should_warn_missing_ratchet = false; - if (&zeta.ratchet_state != &state1) & (Some(&zeta.ratchet_state) != state2.as_ref()) { + if (zeta.ratchet_state != state1) & (Some(&zeta.ratchet_state) != state2.as_ref()) { if !responder_disallows_downgrade && zeta.ratchet_state.fingerprint().is_none() { should_warn_missing_ratchet = true; } else { @@ -879,7 +879,7 @@ pub(crate) fn received_c1_trans>( } } let c2 = Vec::new(); - if !send_control::(zeta, PACKET_TYPE_ACK, c2, send) { + if !send_control::(zeta, PACKET_TYPE_ACK, c2, send) { return Err(byzantine_fault!(OutOfSequence, true)); } @@ -926,7 +926,7 @@ pub(crate) fn received_c2_trans>( } /// Corresponds to the trivial Transition Algorithm described for processing D packets found in /// Section 4.3. -pub(crate) fn received_d_trans>( +pub(crate) fn received_d_trans( zeta: &mut Zeta, kid: NonZeroU32, n: [u8; AES_GCM_NONCE_SIZE], @@ -993,7 +993,7 @@ pub(crate) fn service>( } }; - send_control::(zeta, p, control_payload, send); + send_control::(zeta, p, control_payload, send); } } /// Corresponds to the timeout timer Transition Algorithm described in Section 4.1 - Definition 3. @@ -1013,7 +1013,7 @@ fn timeout_trans>( } else { log!(app, TimeoutX3(session)); } - let new_kid_recv = remap(session, &zeta, &ctx.rng, &ctx.session_map); + let new_kid_recv = remap(session, zeta, &ctx.rng, &ctx.session_map); let a1 = create_a1_state::( &ctx.rng, @@ -1039,7 +1039,7 @@ fn timeout_trans>( ZetaAutomata::S2 => { // Corresponds to Transition Algorithm 6 found in Section 4.3. log!(app, StartedRekeyingSentK1(session)); - let new_kid_recv = remap(session, &zeta, &ctx.rng, &ctx.session_map); + let new_kid_recv = remap(session, zeta, &ctx.rng, &ctx.session_map); // -> s // <- s // ... @@ -1067,7 +1067,7 @@ fn timeout_trans>( zeta.resend_timer = current_time + C::SETTINGS.resend_time as i64; zeta.beta = ZetaAutomata::R1 { noise, e_secret, k1: k1.clone() }; - send_control::(zeta, PACKET_TYPE_REKEY_INIT, k1, send); + send_control::(zeta, PACKET_TYPE_REKEY_INIT, k1, send); } ZetaAutomata::S1 { .. } => { log!(app, TimeoutKeyConfirm(session)); @@ -1166,10 +1166,10 @@ pub(crate) fn received_k1_trans>( // Process message pattern 2 ee token. noise.mix_dh(&e_secret, &e_remote); // Process message pattern 2 se token. - noise.mix_dh(&s_secret, &e_remote); + noise.mix_dh(s_secret, &e_remote); // Process message pattern 2 payload. let i = k2.len(); - let new_kid_recv = remap(session, &zeta, rng, session_map); + let new_kid_recv = remap(session, zeta, rng, session_map); k2.extend(&new_kid_recv.get().to_be_bytes()); noise.encrypt_and_hash_in_place(to_nonce(PACKET_TYPE_REKEY_COMPLETE, 0), i, &mut k2); @@ -1206,7 +1206,7 @@ pub(crate) fn received_k1_trans>( zeta.resend_timer = current_time + C::SETTINGS.resend_time as i64; zeta.beta = ZetaAutomata::R2 { k2: k2.clone() }; - send_control::(zeta, PACKET_TYPE_REKEY_COMPLETE, k2, send); + send_control::(zeta, PACKET_TYPE_REKEY_COMPLETE, k2, send); Ok(()) })(); if matches!(result, Err(ReceiveError::ByzantineFault { .. })) { @@ -1306,7 +1306,7 @@ pub(crate) fn received_k2_trans>( zeta.beta = ZetaAutomata::S1; let c1 = Vec::new(); - send_control::(zeta, PACKET_TYPE_KEY_CONFIRM, c1, send); + send_control::(zeta, PACKET_TYPE_KEY_CONFIRM, c1, send); Ok(()) } else { unreachable!() @@ -1354,7 +1354,7 @@ pub(crate) fn send_payload( } } /// Corresponds to Algorithm 10 found in Section 4.3. -pub(crate) fn received_payload_in_place>( +pub(crate) fn received_payload_in_place( zeta: &mut Zeta, kid: NonZeroU32, n: [u8; AES_GCM_NONCE_SIZE],