From 2bfc7f03ad589e39d8fd5fc3a59eacb0ca91df09 Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Tue, 21 Nov 2023 16:03:04 -0500 Subject: [PATCH] implemented cargo clippy changes --- performance/src/lib.rs | 1 + reference/src/challenge.rs | 3 +-- reference/src/context.rs | 22 +++++++++++----------- reference/src/fragmentation.rs | 9 +++------ reference/src/lib.rs | 1 + reference/src/proto.rs | 2 +- reference/src/symmetric_state.rs | 2 +- reference/src/zeta.rs | 10 +++++----- 8 files changed, 24 insertions(+), 26 deletions(-) diff --git a/performance/src/lib.rs b/performance/src/lib.rs index cfc6835..4e2f78c 100644 --- a/performance/src/lib.rs +++ b/performance/src/lib.rs @@ -37,6 +37,7 @@ //! - **AES-256**: Single block encryption of header to harden packet fragmentation protocol //! - **AES-256-GCM**: Authenticated encryption //#![warn(missing_docs, rust_2018_idioms)] +#![allow(clippy::too_many_arguments, clippy::type_complexity, clippy::assertions_on_constants)] pub mod crypto; pub mod crypto_impl; diff --git a/reference/src/challenge.rs b/reference/src/challenge.rs index fa8ccd2..4813cbb 100644 --- a/reference/src/challenge.rs +++ b/reference/src/challenge.rs @@ -24,7 +24,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(); loop { @@ -80,7 +80,6 @@ impl ChallengeContext { hasher.write(&c.to_be_bytes()); addr.hash(&mut hasher); hasher.write(&self.salt); - drop(hasher); let mac = h.finish(); mac[..MAC_SIZE].try_into().unwrap() diff --git a/reference/src/context.rs b/reference/src/context.rs index e5a849a..5e05a51 100644 --- a/reference/src/context.rs +++ b/reference/src/context.rs @@ -117,7 +117,7 @@ impl Context { identity, |Packet(kid, nonce, payload): &Packet| { // Process fragmentation layer. - let _ = send_with_fragmentation::(send, mtu, *kid, to_packet_nonce(&nonce), payload, None); + let _ = send_with_fragmentation::(send, mtu, *kid, to_packet_nonce(nonce), payload, None); }, ) } @@ -152,7 +152,7 @@ impl Context { let mut zeta = session.0.borrow_mut(); let result = zeta.defrag - .received_fragment::(raw_fragment, app.time(), |n, frag_no, frag_count| { + .received_fragment::(raw_fragment, app.time(), |n, frag_no, frag_count| { let (p, c) = from_nonce(n); if p != PACKET_TYPE_DATA { log!(app, ReceivedRawFragment(p, c, frag_no, frag_count)); @@ -191,7 +191,7 @@ impl Context { send_fragment, mtu, *kid, - to_packet_nonce(&nonce), + to_packet_nonce(nonce), payload, hk, ); @@ -215,7 +215,7 @@ impl Context { &mut zeta, &session, &mut app, - &ctx, + ctx, kid_recv, to_aes_nonce(&pn), assembled_packet, @@ -307,7 +307,7 @@ impl Context { if let Entry::Occupied(mut entry) = b2_map.entry(kid_recv) { let zeta = entry.get_mut(); // Process recv fragmentation layer. - let result = zeta.defrag.received_fragment::( + let result = zeta.defrag.received_fragment::( raw_fragment, app.time(), |n, frag_no, frag_count| { @@ -334,7 +334,7 @@ impl Context { send_unassociated_reply, send_unassociated_mtu, *kid, - to_packet_nonce(&nonce), + to_packet_nonce(nonce), payload, hk, ); @@ -358,7 +358,7 @@ impl Context { } } else { // Process recv fragmentation layer. - let result = ctx.hello_defrag.borrow_mut().received_fragment::( + let result = ctx.hello_defrag.borrow_mut().received_fragment::( raw_fragment, app.time(), |n, frag_no, frag_count| { @@ -405,7 +405,7 @@ impl Context { // Process recv zeta layer. received_x1_trans( &mut app, - &ctx, + ctx, to_aes_nonce(&n), assembled_packet, |Packet(kid, nonce, payload), hk| { @@ -413,7 +413,7 @@ impl Context { send_unassociated_reply, send_unassociated_mtu, *kid, - to_packet_nonce(&nonce), + to_packet_nonce(nonce), payload, Some(hk), ); @@ -471,7 +471,7 @@ impl Context { mtu = mtu.max(MIN_TRANSPORT_MTU); let mut zeta = session.0.borrow_mut(); send_payload::(&mut zeta, payload, |Packet(kid, nonce, payload), hk| { - let result = send_with_fragmentation::(send, mtu, *kid, to_packet_nonce(nonce), &payload, hk); + let result = send_with_fragmentation::(send, mtu, *kid, to_packet_nonce(nonce), payload, hk); if matches!(result, Err(true)) { return Err(SendError::DataTooLarge); } @@ -511,7 +511,7 @@ impl Context { send_fragment, mtu, *kid, - to_packet_nonce(&nonce), + to_packet_nonce(nonce), payload, hk, ); diff --git a/reference/src/fragmentation.rs b/reference/src/fragmentation.rs index 11a022f..626fc69 100644 --- a/reference/src/fragmentation.rs +++ b/reference/src/fragmentation.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use zeroize::Zeroizing; -use crate::application::{ApplicationLayer, CryptoLayer}; +use crate::application::CryptoLayer; use crate::crypto::{Aes256Prp, AES_256_KEY_SIZE}; use crate::proto::*; use crate::result::{byzantine_fault, ReceiveError}; @@ -86,7 +86,7 @@ impl DefragBuffer { } /// Corresponds to the authentication and defragmentation algorithm described in Section 6.1. - pub fn received_fragment>( + pub fn received_fragment( &self, mut raw_fragment: Vec, current_time: i64, @@ -113,10 +113,7 @@ impl DefragBuffer { } let n = raw_fragment[PACKET_NONCE_START..HEADER_SIZE].try_into().unwrap(); - let result = vrfy(&n, fragment_no, fragment_count); - if let Err(e) = result { - return Err(e); - } + vrfy(&n, fragment_no, fragment_count)?; let expiration_time = current_time + C::SETTINGS.fragment_assembly_timeout as i64; let mut map = self.fragment_map.borrow_mut(); diff --git a/reference/src/lib.rs b/reference/src/lib.rs index 415fe06..0d656e0 100644 --- a/reference/src/lib.rs +++ b/reference/src/lib.rs @@ -37,6 +37,7 @@ //! - **AES-256**: Single block encryption of header to harden packet fragmentation protocol //! - **AES-256-GCM**: Authenticated encryption #![warn(missing_docs, rust_2018_idioms)] +#![allow(clippy::too_many_arguments, clippy::type_complexity, clippy::assertions_on_constants)] mod challenge; mod context; diff --git a/reference/src/proto.rs b/reference/src/proto.rs index 779ca53..65947e9 100644 --- a/reference/src/proto.rs +++ b/reference/src/proto.rs @@ -119,7 +119,7 @@ pub(crate) const HANDSHAKE_HELLO_MAX_SIZE: usize = HANDSHAKE_HELLO_MIN_SIZE + RA pub(crate) const HANDSHAKE_RESPONSE_SIZE: usize = P384_PUBLIC_KEY_SIZE + KYBER_CIPHERTEXT_SIZE + AES_GCM_TAG_SIZE + KID_SIZE + AES_GCM_TAG_SIZE; -pub(crate) const HANDSHAKE_COMPLETION_MIN_SIZE: usize = P384_PUBLIC_KEY_SIZE + AES_GCM_TAG_SIZE + 0 + AES_GCM_TAG_SIZE; +pub(crate) const HANDSHAKE_COMPLETION_MIN_SIZE: usize = P384_PUBLIC_KEY_SIZE + AES_GCM_TAG_SIZE + AES_GCM_TAG_SIZE; pub(crate) const HANDSHAKE_COMPLETION_MAX_SIZE: usize = HANDSHAKE_COMPLETION_MIN_SIZE + IDENTITY_MAX_SIZE; pub(crate) const KEY_CONFIRMATION_SIZE: usize = AES_GCM_TAG_SIZE; diff --git a/reference/src/symmetric_state.rs b/reference/src/symmetric_state.rs index e061efb..14d4fd6 100644 --- a/reference/src/symmetric_state.rs +++ b/reference/src/symmetric_state.rs @@ -19,7 +19,7 @@ impl Clone for SymmetricState { Self { k: self.k.clone(), ck: self.ck.clone(), - h: self.h.clone(), + h: self.h, _app: PhantomData, } } diff --git a/reference/src/zeta.rs b/reference/src/zeta.rs index d7d4558..3c333db 100644 --- a/reference/src/zeta.rs +++ b/reference/src/zeta.rs @@ -124,7 +124,7 @@ impl SymmetricState { C::PublicKey::from_bytes((pub_key).try_into().unwrap()) } fn mix_dh(&mut self, secret: &C::KeyPair, remote: &C::PublicKey) { - let ecdh = Zeroizing::new(secret.agree(&remote)); + let ecdh = Zeroizing::new(secret.agree(remote)); self.mix_key(ecdh.as_ref()); } } @@ -171,7 +171,7 @@ fn remap( let weak = if let Some(Some(weak)) = zeta.key_ref(true).recv.kid.as_ref().map(|kid| session_map.remove(kid)) { weak } else { - Arc::downgrade(&session) + Arc::downgrade(session) }; let new_kid_recv = gen_kid(session_map.deref(), rng.borrow_mut().deref_mut()); session_map.insert(new_kid_recv, weak); @@ -236,7 +236,7 @@ impl Zeta { } } -fn create_a1_state>( +fn create_a1_state( rng: &RefCell, s_remote: &C::PublicKey, kid_recv: NonZeroU32, @@ -301,7 +301,7 @@ pub(crate) fn trans_to_a1>( let mut session_map = ctx.session_map.borrow_mut(); let kid_recv = gen_kid(session_map.deref(), ctx.rng.borrow_mut().deref_mut()); - let a1 = create_a1_state::(&ctx.rng, &s_remote, kid_recv, &state1, state2.as_ref(), identity); + let a1 = create_a1_state::(&ctx.rng, &s_remote, kid_recv, &state1, state2.as_ref(), identity); let packet = a1.packet.clone(); let (hk_recv, hk_send) = a1.noise.get_ask(LABEL_HEADER_KEY); @@ -1015,7 +1015,7 @@ fn timeout_trans>( } let new_kid_recv = remap(session, zeta, &ctx.rng, &ctx.session_map); - let a1 = create_a1_state::( + let a1 = create_a1_state::( &ctx.rng, &zeta.s_remote, new_kid_recv,