diff --git a/performance/src/application.rs b/performance/src/application.rs index 5a1a00b..c128a0f 100644 --- a/performance/src/application.rs +++ b/performance/src/application.rs @@ -323,7 +323,7 @@ pub trait Sender { /// Send the given fragment on this interface and then return whether or not an error occured. /// /// If `true` is returned then sending is cancelled and this instance of `Sender` is dropped. - fn send_frag<'a>(&'a mut self, frag: &mut [u8]) -> bool; + fn send_frag(&mut self, frag: &mut [u8]) -> bool; } /// A trait to genericize the process of borrowing the resources necessary to repeatedly @@ -353,7 +353,7 @@ pub trait SendTo { } impl bool> Sender for F { - fn send_frag<'a>(&'a mut self, frag: &mut [u8]) -> bool { + fn send_frag(&mut self, frag: &mut [u8]) -> bool { self(frag) } } diff --git a/performance/src/frag_cache.rs b/performance/src/frag_cache.rs index 8c7de57..6e3789b 100644 --- a/performance/src/frag_cache.rs +++ b/performance/src/frag_cache.rs @@ -93,7 +93,7 @@ impl UnassociatedFragCache { } else if self.map[idx1].key == key { idx1 } else if self.map[idx0].key == 0 || self.map[idx1].key == 0 { - if (fragment_count as usize) > self.frags_unused_size { + if fragment_count > self.frags_unused_size { // There are not enough free fragment slots so attempt to expire a bunch of entries. let _ = self.check_for_expiry_inner(Crypto::SETTINGS.resend_time as i64, current_time); } @@ -117,7 +117,7 @@ impl UnassociatedFragCache { let mut new_expiry = None; if self.map[idx].key == 0 { // This is a new entry so initialize it. - if (fragment_count as usize) <= self.frags_unused_size { + if fragment_count <= self.frags_unused_size { new_expiry = Some(current_time + Crypto::SETTINGS.fragment_assembly_timeout as i64); let entry = &mut self.map[idx]; entry.key = key; @@ -148,7 +148,7 @@ impl UnassociatedFragCache { entry.packet_size = new_size; entry.fragment_have |= got; - let frag_idx = (entry.frags_idx as usize + fragment_no as usize) % self.frags.len(); + let frag_idx = (entry.frags_idx as usize + fragment_no) % self.frags.len(); self.frags[frag_idx].write(fragment); if entry.fragment_have == 1u64.wrapping_shl(fragment_count as u32) - 1 { @@ -183,7 +183,7 @@ impl UnassociatedFragCache { return expiry; } } - return i64::MAX; + i64::MAX } fn invalidate(&mut self, idx: usize) { diff --git a/performance/src/fragged.rs b/performance/src/fragged.rs index 59b876d..546d2cd 100644 --- a/performance/src/fragged.rs +++ b/performance/src/fragged.rs @@ -53,8 +53,8 @@ impl Fragged { if got & self.have == 0 && self.count == fragment_count as u32 { self.have |= got; unsafe { - self.frags.get_unchecked_mut(fragment_no as usize).write(fragment); - if self.have == 1u64.wrapping_shl(self.count as u32) - 1 { + self.frags.get_unchecked_mut(fragment_no).write(fragment); + if self.have == 1u64.wrapping_shl(self.count) - 1 { self.have = 0; self.count = 0; self.nonce = u64::MAX; diff --git a/performance/src/handshake_cache.rs b/performance/src/handshake_cache.rs index 0b637ee..6c7a7d1 100644 --- a/performance/src/handshake_cache.rs +++ b/performance/src/handshake_cache.rs @@ -61,7 +61,7 @@ impl UnassociatedHandshakeCache { cache.expiries[idx] = expiry; cache.handshakes[idx] = Some(state); self.has_pending.store(true, Ordering::Release); - return Some(expiry); + Some(expiry) } pub(crate) fn remove(&self, local_id: NonZeroU32) -> bool { let mut cache = self.cache.write().unwrap(); diff --git a/performance/src/proto.rs b/performance/src/proto.rs index b64ad0b..5b1c3cb 100644 --- a/performance/src/proto.rs +++ b/performance/src/proto.rs @@ -94,8 +94,8 @@ pub(crate) const LABEL_RATCHET_STATE: &[u8; 4] = b"ASKR"; pub(crate) const LABEL_HEADER_KEY: &[u8; 4] = b"ASKH"; pub(crate) const LABEL_KEX_KEY: &[u8; 4] = b"ASKK"; -pub(crate) const EXPIRE_AFTER_USES: u64 = 1 << 32 - 1; -pub(crate) const THREAD_SAFE_COUNTER_HARD_EXPIRE: u64 = u64::MAX - 1 << 16; +pub(crate) const EXPIRE_AFTER_USES: u64 = (1 << 32) - 1; +pub(crate) const THREAD_SAFE_COUNTER_HARD_EXPIRE: u64 = u64::MAX - (1 << 16); /// Determines the number of counters a session will remember. If a counter arrives over /// this amount out of order relative to other received counters, it is likely to be /// rejected on the basis that the session can't remember if this counter was replayed. @@ -137,7 +137,7 @@ 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 HEADERED_HANDSHAKE_RESPONSE_SIZE: usize = HANDSHAKE_RESPONSE_SIZE + HEADER_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 HEADERED_HANDSHAKE_COMPLETION_MAX_SIZE: usize = HANDSHAKE_COMPLETION_MAX_SIZE + HEADER_SIZE; diff --git a/performance/src/symmetric_state.rs b/performance/src/symmetric_state.rs index c9ea5a8..2b45049 100644 --- a/performance/src/symmetric_state.rs +++ b/performance/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/performance/src/zeta.rs b/performance/src/zeta.rs index cde05a5..4247274 100644 --- a/performance/src/zeta.rs +++ b/performance/src/zeta.rs @@ -184,12 +184,12 @@ impl SymmetricState { } fn mix_dh(&mut self, hmac: &mut Crypto::Hmac, secret: &Crypto::KeyPair, remote: &Crypto::PublicKey) { let mut ecdh_secret = Zeroizing::new([0u8; P384_ECDH_SHARED_SECRET_SIZE]); - secret.agree(&remote, &mut ecdh_secret); + secret.agree(remote, &mut ecdh_secret); self.mix_key(hmac, ecdh_secret.as_ref()); } fn mix_dh_no_init(&mut self, hmac: &mut Crypto::Hmac, secret: &Crypto::KeyPair, remote: &Crypto::PublicKey) { let mut ecdh_secret = Zeroizing::new([0u8; P384_ECDH_SHARED_SECRET_SIZE]); - secret.agree(&remote, &mut ecdh_secret); + secret.agree(remote, &mut ecdh_secret); self.mix_key_no_init(hmac, ecdh_secret.as_ref()); } } @@ -262,7 +262,7 @@ fn remap( let weak = if let Some(Some(weak)) = state.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(), ctx.rng.lock().unwrap().deref_mut()); session_map.insert(new_kid_recv, weak); @@ -332,7 +332,7 @@ pub(crate) fn trans_to_a1>( ) -> Result<(Arc>, Option), OpenError> { let RatchetStates { state1, state2 } = app .restore_by_identity(&s_remote, &session_data) - .map_err(|e| OpenError::StorageError(e))? + .map_err(OpenError::StorageError)? .unwrap_or_default(); let mut session_queue = ctx.session_queue.lock().unwrap(); @@ -450,7 +450,7 @@ pub(crate) fn received_x1_trans 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(hash, hmac, ratchet_key); // Process message pattern 2 payload. @@ -774,7 +774,7 @@ fn send_control( mut payload: ArrayVec, send: impl FnOnce(&mut [u8], Option<&Crypto::PrpEnc>), ) -> Result<(), bool> { - if let Some((c, _)) = get_counter(session, &state) { + if let Some((c, _)) = get_counter(session, state) { if let (Some(kek), Some(kid)) = (state.key_ref(false).send.kek.as_ref(), state.key_ref(false).send.kid) { let nonce = to_nonce(packet_type, c); let tag = Crypto::Aead::encrypt_in_place(kek, &nonce, &[], &mut payload[HEADER_SIZE..]); @@ -1386,7 +1386,7 @@ pub(crate) fn received_k1_trans::new(); c1.extend([0u8; HEADER_SIZE]); - match send_control(&session, &state, PACKET_TYPE_KEY_CONFIRM, c1, send) { + match send_control(session, &state, PACKET_TYPE_KEY_CONFIRM, c1, send) { Ok(()) => Ok(reduced_service_time), Err(false) => Err(fault!(OutOfSequence, true, session)), Err(true) => Err(fault!(ExpiredCounter, true, session, true)), } } else { // Some rekey packet may have arrived extremely delayed. - return Err(fault!(OutOfSequence, false, session)); + Err(fault!(OutOfSequence, false, session)) } })(); diff --git a/performance/src/zssp.rs b/performance/src/zssp.rs index b2c3e9a..c63f12e 100644 --- a/performance/src/zssp.rs +++ b/performance/src/zssp.rs @@ -483,7 +483,7 @@ impl Context { // This can occur naturally because either Bob's incoming_sessions cache got // full so Alice's incoming session was dropped, or the session this packet // was for was dropped by the application. - return Err(fault!(UnknownLocalKeyId, false)); + Err(fault!(UnknownLocalKeyId, false)) } } } else { diff --git a/reference/src/proto.rs b/reference/src/proto.rs index 6a08419..779ca53 100644 --- a/reference/src/proto.rs +++ b/reference/src/proto.rs @@ -83,7 +83,6 @@ pub(crate) const LABEL_RATCHET_STATE: &[u8; 4] = b"ASKR"; pub(crate) const LABEL_HEADER_KEY: &[u8; 4] = b"ASKH"; pub(crate) const LABEL_KEX_KEY: &[u8; 4] = b"ASKK"; -//pub(crate) const EXPIRE_AFTER_USES: u64 = (1 << 32) - 1; pub(crate) const HARD_EXPIRATION: u64 = u64::MAX; /// Determines the number of counters a session will remember. If a counter arrives over /// this amount out of order relative to other received counters, it is likely to be