pub(super) struct PqxdhSession {
pub(super) shared_secret: PqxdhSharedSecret,
pub(super) sequence_number: u64,
pub(super) my_session_channel_id: PqxdhSessionId,
pub(super) their_session_channel_id: PqxdhSessionId,
pub(super) their_key: VerifyingKey,
}Expand description
A PQXDH session for secure communication
This struct represents an established PQXDH session between two parties. It contains the shared cryptographic material and state needed to encrypt and decrypt messages within the session.
§Key Features
- Shared Secret: Cryptographic material derived from PQXDH key exchange
- Sequence Numbers: Monotonic counter for replay protection
- Session Channel IDs: A hash of the session channel id prefix and the target key, provides unlinkability
- Serializable: Can be persisted and restored across application restarts
§Security Properties
- Forward secrecy through ephemeral key material
- Replay protection via sequence numbering
- Unlinkability through randomized channel identifiers
- Post-quantum resistance via CRYSTALS-Kyber
Fields§
§sequence_number: u64Current sequence number for this session (stored as u64 for serialization)
my_session_channel_id: PqxdhSessionIdThe channel Id we are listening for, derived from the session channel id prefix
their_session_channel_id: PqxdhSessionIdThe session id channel they will be listening to, derived from the session channel id prefix
their_key: VerifyingKeyThe key of the sender of the messages
Implementations§
Source§impl PqxdhSession
impl PqxdhSession
Sourcepub fn publish_channel_tag(&self) -> Tag
pub fn publish_channel_tag(&self) -> Tag
Get the channel they are listening for
Sourcepub fn listening_channel_tag(&self) -> Tag
pub fn listening_channel_tag(&self) -> Tag
Get the channel tag we want to be listening for
Sourcepub fn next_sequence_number(&mut self) -> u64
pub fn next_sequence_number(&mut self) -> u64
Get the next sequence number and increment the internal counter
Sourcepub fn gen_next_message<T: Serialize>(
&mut self,
client_keypair: &KeyPair,
payload: &T,
kind: Kind,
) -> Result<MessageFull>
pub fn gen_next_message<T: Serialize>( &mut self, client_keypair: &KeyPair, payload: &T, kind: Kind, ) -> Result<MessageFull>
Sends a message in an established PQXDH session
This method encrypts and sends a message over an already established PQXDH session. The message is encrypted using the session’s shared secret and includes sequence numbering for replay protection.
§Arguments
messages_service- The messages service for publishing the encrypted messageclient_keypair- The sender’s keypair for message authenticationpayload- The user data to encrypt and send
§Security Features
- Messages are encrypted with the session’s shared secret
- Sequence numbers prevent replay attacks
- Messages are sent to the session’s private channel ID
- Each message uses fresh randomness for encryption
Creates a PQXDH session from an established shared secret and channel ID (for responders)
This constructor is used by service providers to create a session after successfully processing an initial PQXDH message. It initializes the session with the derived shared secret and the channel ID extracted from the initial message.
§Arguments
shared_secret- The cryptographic material derived from PQXDH key exchangemy_session_channel_id- The channel ID we are listening fortheir_session_channel_id- The channel ID they are listening forsender_key- The public key of the sender of the initial message
§Returns
Returns a new PqxdhSession ready for encrypting and decrypting messages
§Usage
Typically called after extract_initial_payload() to create a session
that can be used for ongoing communication with the client.
Trait Implementations§
Source§impl Clone for PqxdhSession
impl Clone for PqxdhSession
Source§fn clone(&self) -> PqxdhSession
fn clone(&self) -> PqxdhSession
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more