Protocol E2EE

End-to-End Encryption (E2EE) means that messages are encrypted on the sender device and can be decrypted only on recipient devices. The server routes packets but cannot read plaintext content.

 

This topic explains the technical flow for:

 

Cryptographic building blocks

 

 

Direct messages (1:1) technical flow

 

  1. Public key discovery
    Each peer publishes a public identity key. The server may distribute public keys, but private keys never leave the client device.

  2. Shared secret establishment
    The sender and recipient perform ECDH (private key + peer public key) and obtain the same shared secret.

  3. Session key derivation
    HKDF-SHA-256 derives one or more symmetric keys (encryption key, optional header key) from the ECDH output.

  4. Message encryption
    The plaintext is encrypted with AES-256-GCM using a unique nonce/IV. Output includes ciphertext + authentication tag.

  5. Transport
    The server forwards encrypted payloads and metadata (for example: sender id, key id, counter, timestamp) without plaintext access.

  6. Recipient decryption
    The recipient derives the same session key, verifies the authentication tag, and decrypts. Any tampering causes authentication failure.

 

Group messages technical flow (Sender Keys)

 

For groups, encrypting each message separately for every member is expensive. A common optimization is a sender key design:

 

How a sender key is distributed

 

  1. When a sender joins a group, it creates a fresh sender key state.

  2. The sender key state is shared to each current member over existing 1:1 encrypted sessions (pairwise E2EE).

  3. After distribution, normal group payloads use the sender-key fast path (single encryption per message).

 

Membership changes and sender key rotation

 

To preserve forward and backward secrecy, group sender keys must rotate on membership events:

 

Typical rotation sequence:

  1. Create a new sender key state (new key id, new chain key).

  2. Distribute it only to currently authorized members through pairwise E2EE channels.

  3. Start encrypting new group messages with the new key id.

  4. Accept old key id only during a short transition window, then retire it.

 

Security properties

 

 

Components

  TsgcWSPServer_E2EE: Server Protocol E2EE component. It forwards encrypted messages between clients without knowing message contents.

 

  TsgcWSPClient_E2EE: Client Protocol E2EE component. It manages key exchange, encryption and decryption on peer devices.