mirror of
https://github.com/zerotier/zssp.git
synced 2026-05-22 16:28:40 -07:00
implemented cargo clippy changes
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn respond_to_challenge_in_place<Rng: RngCore + CryptoRng, Hash: Sha512Hash>
|
||||
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()
|
||||
|
||||
+11
-11
@@ -117,7 +117,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
identity,
|
||||
|Packet(kid, nonce, payload): &Packet| {
|
||||
// Process fragmentation layer.
|
||||
let _ = send_with_fragmentation::<C>(send, mtu, *kid, to_packet_nonce(&nonce), payload, None);
|
||||
let _ = send_with_fragmentation::<C>(send, mtu, *kid, to_packet_nonce(nonce), payload, None);
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -152,7 +152,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
let mut zeta = session.0.borrow_mut();
|
||||
let result =
|
||||
zeta.defrag
|
||||
.received_fragment::<C, App>(raw_fragment, app.time(), |n, frag_no, frag_count| {
|
||||
.received_fragment::<C>(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<C: CryptoLayer> Context<C> {
|
||||
send_fragment,
|
||||
mtu,
|
||||
*kid,
|
||||
to_packet_nonce(&nonce),
|
||||
to_packet_nonce(nonce),
|
||||
payload,
|
||||
hk,
|
||||
);
|
||||
@@ -215,7 +215,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
&mut zeta,
|
||||
&session,
|
||||
&mut app,
|
||||
&ctx,
|
||||
ctx,
|
||||
kid_recv,
|
||||
to_aes_nonce(&pn),
|
||||
assembled_packet,
|
||||
@@ -307,7 +307,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
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::<C, App>(
|
||||
let result = zeta.defrag.received_fragment::<C>(
|
||||
raw_fragment,
|
||||
app.time(),
|
||||
|n, frag_no, frag_count| {
|
||||
@@ -334,7 +334,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
send_unassociated_reply,
|
||||
send_unassociated_mtu,
|
||||
*kid,
|
||||
to_packet_nonce(&nonce),
|
||||
to_packet_nonce(nonce),
|
||||
payload,
|
||||
hk,
|
||||
);
|
||||
@@ -358,7 +358,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
}
|
||||
} else {
|
||||
// Process recv fragmentation layer.
|
||||
let result = ctx.hello_defrag.borrow_mut().received_fragment::<C, App>(
|
||||
let result = ctx.hello_defrag.borrow_mut().received_fragment::<C>(
|
||||
raw_fragment,
|
||||
app.time(),
|
||||
|n, frag_no, frag_count| {
|
||||
@@ -405,7 +405,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
// 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<C: CryptoLayer> Context<C> {
|
||||
send_unassociated_reply,
|
||||
send_unassociated_mtu,
|
||||
*kid,
|
||||
to_packet_nonce(&nonce),
|
||||
to_packet_nonce(nonce),
|
||||
payload,
|
||||
Some(hk),
|
||||
);
|
||||
@@ -471,7 +471,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
mtu = mtu.max(MIN_TRANSPORT_MTU);
|
||||
let mut zeta = session.0.borrow_mut();
|
||||
send_payload::<C>(&mut zeta, payload, |Packet(kid, nonce, payload), hk| {
|
||||
let result = send_with_fragmentation::<C>(send, mtu, *kid, to_packet_nonce(nonce), &payload, hk);
|
||||
let result = send_with_fragmentation::<C>(send, mtu, *kid, to_packet_nonce(nonce), payload, hk);
|
||||
if matches!(result, Err(true)) {
|
||||
return Err(SendError::DataTooLarge);
|
||||
}
|
||||
@@ -511,7 +511,7 @@ impl<C: CryptoLayer> Context<C> {
|
||||
send_fragment,
|
||||
mtu,
|
||||
*kid,
|
||||
to_packet_nonce(&nonce),
|
||||
to_packet_nonce(nonce),
|
||||
payload,
|
||||
hk,
|
||||
);
|
||||
|
||||
@@ -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<C: CryptoLayer, App: ApplicationLayer<C>>(
|
||||
pub fn received_fragment<C: CryptoLayer>(
|
||||
&self,
|
||||
mut raw_fragment: Vec<u8>,
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -19,7 +19,7 @@ impl<Crypto: CryptoLayer> Clone for SymmetricState<Crypto> {
|
||||
Self {
|
||||
k: self.k.clone(),
|
||||
ck: self.ck.clone(),
|
||||
h: self.h.clone(),
|
||||
h: self.h,
|
||||
_app: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ impl<C: CryptoLayer> SymmetricState<C> {
|
||||
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<C: CryptoLayer>(
|
||||
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<C: CryptoLayer> Zeta<C> {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_a1_state<C: CryptoLayer, App: ApplicationLayer<C>>(
|
||||
fn create_a1_state<C: CryptoLayer>(
|
||||
rng: &RefCell<C::Rng>,
|
||||
s_remote: &C::PublicKey,
|
||||
kid_recv: NonZeroU32,
|
||||
@@ -301,7 +301,7 @@ pub(crate) fn trans_to_a1<C: CryptoLayer, App: ApplicationLayer<C>>(
|
||||
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::<C, App>(&ctx.rng, &s_remote, kid_recv, &state1, state2.as_ref(), identity);
|
||||
let a1 = create_a1_state::<C>(&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<C: CryptoLayer, App: ApplicationLayer<C>>(
|
||||
}
|
||||
let new_kid_recv = remap(session, zeta, &ctx.rng, &ctx.session_map);
|
||||
|
||||
let a1 = create_a1_state::<C, App>(
|
||||
let a1 = create_a1_state::<C>(
|
||||
&ctx.rng,
|
||||
&zeta.s_remote,
|
||||
new_kid_recv,
|
||||
|
||||
Reference in New Issue
Block a user