mirror of
https://github.com/rosenpass/rosenpass.git
synced 2025-12-05 20:40:02 -08:00
chore: Split constants from protocol.rs into own file
This commit is contained in:
64
rosenpass/src/protocol/constants.rs
Normal file
64
rosenpass/src/protocol/constants.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
//! Constants and configuration values used in the rosenpass core protocol
|
||||
|
||||
use crate::msgs::MAC_SIZE;
|
||||
|
||||
use super::timing::Timing;
|
||||
|
||||
/// Time after which the responder attempts to rekey the session
|
||||
///
|
||||
/// From the wireguard paper: rekey every two minutes,
|
||||
/// discard the key if no rekey is achieved within three
|
||||
pub const REKEY_AFTER_TIME_RESPONDER: Timing = 120.0;
|
||||
/// Time after which the initiator attempts to rekey the session.
|
||||
///
|
||||
/// This happens ten seconds after [REKEY_AFTER_TIME_RESPONDER], so
|
||||
/// parties would usually switch roles after every handshake.
|
||||
///
|
||||
/// From the wireguard paper: rekey every two minutes,
|
||||
/// discard the key if no rekey is achieved within three
|
||||
pub const REKEY_AFTER_TIME_INITIATOR: Timing = 130.0;
|
||||
/// Time after which either party rejects the current key.
|
||||
///
|
||||
/// At this point a new key should have been negotiated.
|
||||
/// Rejection happens 50-60 seconds after key renegotiation
|
||||
/// to allow for a graceful handover.
|
||||
///
|
||||
/// From the wireguard paper: rekey every two minutes,
|
||||
/// discard the key if no rekey is achieved within three
|
||||
pub const REJECT_AFTER_TIME: Timing = 180.0;
|
||||
|
||||
/// The length of the `cookie_secret` in the [whitepaper](https://rosenpass.eu/whitepaper.pdf)
|
||||
pub const COOKIE_SECRET_LEN: usize = MAC_SIZE;
|
||||
/// The life time of the `cookie_secret` in the [whitepaper](https://rosenpass.eu/whitepaper.pdf)
|
||||
pub const COOKIE_SECRET_EPOCH: Timing = 120.0;
|
||||
|
||||
/// Length of a cookie value (see info about the cookie mechanism in the [whitepaper](https://rosenpass.eu/whitepaper.pdf))
|
||||
pub const COOKIE_VALUE_LEN: usize = MAC_SIZE;
|
||||
/// Time after which to delete a cookie, as the initiator, for a certain peer (see info about the cookie mechanism in the [whitepaper](https://rosenpass.eu/whitepaper.pdf))
|
||||
pub const PEER_COOKIE_VALUE_EPOCH: Timing = 120.0;
|
||||
|
||||
/// Seconds until the biscuit key is changed; we issue biscuits
|
||||
/// using one biscuit key for one epoch and store the biscuit for
|
||||
/// decryption for a second epoch
|
||||
///
|
||||
/// The biscuit mechanism is used to make sure the responder is stateless in our protocol.
|
||||
pub const BISCUIT_EPOCH: Timing = 300.0;
|
||||
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the factor by which the delay grows after each
|
||||
/// retransmission.
|
||||
pub const RETRANSMIT_DELAY_GROWTH: Timing = 2.0;
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the initial delay between retransmissions.
|
||||
pub const RETRANSMIT_DELAY_BEGIN: Timing = 0.5;
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the maximum delay between retransmissions.
|
||||
pub const RETRANSMIT_DELAY_END: Timing = 10.0;
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the jitter (randomness) applied to the retransmission
|
||||
/// delay.
|
||||
pub const RETRANSMIT_DELAY_JITTER: Timing = 0.5;
|
||||
|
||||
/// This is the maximum delay that can separate two events for us to consider the events to have
|
||||
/// happened at the same time.
|
||||
pub const EVENT_GRACE: Timing = 0.0025;
|
||||
@@ -78,6 +78,7 @@
|
||||
mod build_crypto_server;
|
||||
pub use build_crypto_server::*;
|
||||
|
||||
pub mod constants;
|
||||
pub mod timing;
|
||||
|
||||
#[allow(clippy::module_inception)]
|
||||
|
||||
@@ -35,79 +35,17 @@ use rosenpass_util::{
|
||||
|
||||
use crate::{hash_domains, msgs::*, RosenpassError};
|
||||
|
||||
use super::constants::{
|
||||
BISCUIT_EPOCH, COOKIE_SECRET_EPOCH, COOKIE_SECRET_LEN, COOKIE_VALUE_LEN,
|
||||
PEER_COOKIE_VALUE_EPOCH, REJECT_AFTER_TIME, REKEY_AFTER_TIME_INITIATOR,
|
||||
REKEY_AFTER_TIME_RESPONDER, RETRANSMIT_DELAY_BEGIN, RETRANSMIT_DELAY_END,
|
||||
RETRANSMIT_DELAY_GROWTH, RETRANSMIT_DELAY_JITTER,
|
||||
};
|
||||
use super::timing::{has_happened, Timing, BCE, UNENDING};
|
||||
|
||||
#[cfg(feature = "trace_bench")]
|
||||
use rosenpass_util::trace_bench::Trace as _;
|
||||
|
||||
// CONSTANTS & SETTINGS //////////////////////////
|
||||
|
||||
/// Time after which the responder attempts to rekey the session
|
||||
///
|
||||
/// From the wireguard paper: rekey every two minutes,
|
||||
/// discard the key if no rekey is achieved within three
|
||||
pub const REKEY_AFTER_TIME_RESPONDER: Timing = 120.0;
|
||||
/// Time after which the initiator attempts to rekey the session.
|
||||
///
|
||||
/// This happens ten seconds after [REKEY_AFTER_TIME_RESPONDER], so
|
||||
/// parties would usually switch roles after every handshake.
|
||||
///
|
||||
/// From the wireguard paper: rekey every two minutes,
|
||||
/// discard the key if no rekey is achieved within three
|
||||
pub const REKEY_AFTER_TIME_INITIATOR: Timing = 130.0;
|
||||
/// Time after which either party rejects the current key.
|
||||
///
|
||||
/// At this point a new key should have been negotiated.
|
||||
/// Rejection happens 50-60 seconds after key renegotiation
|
||||
/// to allow for a graceful handover.
|
||||
///
|
||||
/// From the wireguard paper: rekey every two minutes,
|
||||
/// discard the key if no rekey is achieved within three
|
||||
pub const REJECT_AFTER_TIME: Timing = 180.0;
|
||||
|
||||
/// Maximum period between sending rekey initiation messages
|
||||
///
|
||||
/// From the wireguard paper; "under no circumstances send an initiation message more than once every 5 seconds"
|
||||
pub const REKEY_TIMEOUT: Timing = 5.0;
|
||||
|
||||
/// The length of the `cookie_secret` in the [whitepaper](https://rosenpass.eu/whitepaper.pdf)
|
||||
pub const COOKIE_SECRET_LEN: usize = MAC_SIZE;
|
||||
/// The life time of the `cookie_secret` in the [whitepaper](https://rosenpass.eu/whitepaper.pdf)
|
||||
pub const COOKIE_SECRET_EPOCH: Timing = 120.0;
|
||||
|
||||
/// Length of a cookie value (see info about the cookie mechanism in the [whitepaper](https://rosenpass.eu/whitepaper.pdf))
|
||||
pub const COOKIE_VALUE_LEN: usize = MAC_SIZE;
|
||||
/// Time after which to delete a cookie, as the initiator, for a certain peer (see info about the cookie mechanism in the [whitepaper](https://rosenpass.eu/whitepaper.pdf))
|
||||
pub const PEER_COOKIE_VALUE_EPOCH: Timing = 120.0;
|
||||
|
||||
/// Seconds until the biscuit key is changed; we issue biscuits
|
||||
/// using one biscuit key for one epoch and store the biscuit for
|
||||
/// decryption for a second epoch
|
||||
///
|
||||
/// The biscuit mechanism is used to make sure the responder is stateless in our protocol.
|
||||
pub const BISCUIT_EPOCH: Timing = 300.0;
|
||||
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the factor by which the delay grows after each
|
||||
/// retransmission.
|
||||
pub const RETRANSMIT_DELAY_GROWTH: Timing = 2.0;
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the initial delay between retransmissions.
|
||||
pub const RETRANSMIT_DELAY_BEGIN: Timing = 0.5;
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the maximum delay between retransmissions.
|
||||
pub const RETRANSMIT_DELAY_END: Timing = 10.0;
|
||||
/// The initiator opportunistically retransmits their messages; it applies an increasing delay
|
||||
/// between each retreansmission. This is the jitter (randomness) applied to the retransmission
|
||||
/// delay.
|
||||
pub const RETRANSMIT_DELAY_JITTER: Timing = 0.5;
|
||||
|
||||
/// This is the maximum delay that can separate two events for us to consider the events to have
|
||||
/// happened at the same time.
|
||||
pub const EVENT_GRACE: Timing = 0.0025;
|
||||
|
||||
// UTILITY FUNCTIONS /////////////////////////////
|
||||
|
||||
// DATA STRUCTURES & BASIC TRAITS & ACCESSORS ////
|
||||
|
||||
/// Static public key
|
||||
@@ -118,7 +56,6 @@ pub type SPk = PublicBox<{ StaticKem::PK_LEN }>;
|
||||
pub type SSk = Secret<{ StaticKem::SK_LEN }>;
|
||||
/// Ephemeral public key
|
||||
pub type EPk = Public<{ EphemeralKem::PK_LEN }>;
|
||||
/// Ephemeral secret key
|
||||
pub type ESk = Secret<{ EphemeralKem::SK_LEN }>;
|
||||
|
||||
/// Symmetric key
|
||||
@@ -2612,7 +2549,7 @@ pub enum PollResult {
|
||||
/// The caller should immediately erase any cryptographic keys exchanged with
|
||||
/// the peer previously and then immediately call poll again.
|
||||
///
|
||||
/// This is raised after [REKEY_TIMEOUT] if no successful rekey could be achieved.
|
||||
/// This is raised after [super::constants::REKEY_TIMEOUT] if no successful rekey could be achieved.
|
||||
DeleteKey(PeerPtr),
|
||||
/// The caller should invoke [CryptoServer::handle_initiation] and transmit the
|
||||
/// initiation to the other party before invoking poll again.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Time-keeping related utilities for the Rosenpass protocol
|
||||
|
||||
use super::EVENT_GRACE;
|
||||
use super::constants::EVENT_GRACE;
|
||||
|
||||
/// A type for time, e.g. for backoff before re-tries
|
||||
pub type Timing = f64;
|
||||
@@ -35,7 +35,7 @@ pub const UNENDING: Timing = 3600.0 * 8.0;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use rosenpass::protocol::{timing::has_happened, EVENT_GRACE};
|
||||
/// use rosenpass::protocol::{timing::has_happened, constants::EVENT_GRACE};
|
||||
/// assert!(has_happened(EVENT_GRACE * -1.0, 0.0));
|
||||
/// assert!(has_happened(0.0, 0.0));
|
||||
/// assert!(has_happened(EVENT_GRACE * 0.999, 0.0));
|
||||
|
||||
Reference in New Issue
Block a user