From 8202a831b2b40aa1430761f93e393ff00bb48caa Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 6 Jan 2023 20:51:28 -0500 Subject: [PATCH] Rename to be more descriptive. --- zssp/src/constants.rs | 2 +- zssp/src/zssp.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/zssp/src/constants.rs b/zssp/src/constants.rs index 20bd3b345..7f6ed7ae8 100644 --- a/zssp/src/constants.rs +++ b/zssp/src/constants.rs @@ -70,7 +70,7 @@ pub(crate) const HMAC_SIZE: usize = 48; pub(crate) const SESSION_ID_SIZE: usize = 6; /// Maximum difference between out-of-order incoming packet counters, and size of deduplication buffer. -pub(crate) const COUNTER_MAX_DELTA: usize = 16; +pub(crate) const COUNTER_WINDOW_MAX_OUT_OF_ORDER: usize = 16; // Packet types can range from 0 to 15 (4 bits) -- 0-3 are defined and 4-15 are reserved for future use pub(crate) const PACKET_TYPE_DATA: u8 = 0; diff --git a/zssp/src/zssp.rs b/zssp/src/zssp.rs index 6e1758531..38409222a 100644 --- a/zssp/src/zssp.rs +++ b/zssp/src/zssp.rs @@ -61,14 +61,14 @@ pub struct Session { /// An arbitrary application defined object associated with each session pub application_data: Application::Data, - send_counter: AtomicU64, // Outgoing packet counter and nonce state - receive_window: [AtomicU64; COUNTER_MAX_DELTA], // Receive window for anti-replay and deduplication - psk: Secret<64>, // Arbitrary PSK provided by external code - noise_ss: Secret<48>, // Static raw shared ECDH NIST P-384 key - header_check_cipher: Aes, // Cipher used for header check codes (not Noise related) - state: RwLock, // Mutable parts of state (other than defrag buffers) - remote_s_public_blob_hash: [u8; 48], // SHA384(remote static public key blob) - remote_s_public_p384_bytes: [u8; P384_PUBLIC_KEY_SIZE], // Remote NIST P-384 static public key + send_counter: AtomicU64, // Outgoing packet counter and nonce state + receive_window: [AtomicU64; COUNTER_WINDOW_MAX_OUT_OF_ORDER], // Receive window for anti-replay and deduplication + psk: Secret<64>, // Arbitrary PSK provided by external code + noise_ss: Secret<48>, // Static raw shared ECDH NIST P-384 key + header_check_cipher: Aes, // Cipher used for header check codes (not Noise related) + state: RwLock, // Mutable parts of state (other than defrag buffers) + remote_s_public_blob_hash: [u8; 48], // SHA384(remote static public key blob) + remote_s_public_p384_bytes: [u8; P384_PUBLIC_KEY_SIZE], // Remote NIST P-384 static public key defrag: Mutex, 8, 8>>, } @@ -355,14 +355,14 @@ impl Session { /// Check the receive window without mutating state. #[inline(always)] fn check_receive_window(&self, counter: u64) -> bool { - self.receive_window[(counter as usize) % COUNTER_MAX_DELTA].load(Ordering::Acquire) < counter + self.receive_window[(counter as usize) % COUNTER_WINDOW_MAX_OUT_OF_ORDER].load(Ordering::Acquire) < counter } /// Update the receive window, returning true if the packet is still valid. /// This should only be called after the packet is authenticated. #[inline(always)] fn update_receive_window(&self, counter: u64) -> bool { - self.receive_window[(counter as usize) % COUNTER_MAX_DELTA].fetch_max(counter, Ordering::AcqRel) < counter + self.receive_window[(counter as usize) % COUNTER_WINDOW_MAX_OUT_OF_ORDER].fetch_max(counter, Ordering::AcqRel) < counter } }