
đ TL;DR
End-to-end encryption isnât just about keeping secrets from a hacker / eavesdropper â itâs about building systems where users donât have to trust anyone but themselves, including the service provider who offers the communication service (i.e. the server).
In this series, weâll build a simple E2E encrypted communication system that is post-quantum secure based on the libsignal library from the Signal team using Rust.
In Part 1 (this post), weâll cover:
- đŻ Why E2E encryption matters (security vs privacy vs trust)
- đ What the Signal Protocol offers (and its limitations)
- đď¸ How the protocol works conceptually (key exchange, encryption layers)
- đ§ Theory behind PQXDH and post-quantum cryptography
By the end of this 3-part series, youâll have implemented:
- â Post-quantum secure key exchange (PQXDH)
- â End-to-end encrypted file sharing
- â A working demo that encrypts and decrypts images
Code coming in parts 2 and 3!
The Problem: Learning E2E Encryption is Hard
These days, Iâve been working on building an end-to-end encryption system for SyftBox â an open-source network for privacy-first, offline-capable AI. However, when I started researching how to implement it based on libsignal, I felt like hitting a wall.
The Signal Protocol is the gold standard for
implementing E2E encryption systemsâitâs what powers Signal, WhatsApp, and many other secure messaging apps.
However, the whitepaper is highly technical and rigorous, making it difficult to understand without
a strong cryptography background. I was trying to search for good learning materials that
bridge theory and practice, but couldnât find anything that really clicked. So I spent time
diving deep into the protocol, implementing it, and visualizing all the concepts to truly understand how it works.
This series shares what I learned, and my goal is to help you save time understanding and
implementing your own E2E encryption system using libsignal, with clear explanations and visual aids along the way.
Security vs Privacy: Understanding the Difference
While security protects you against external eavesdroppers and attackers, privacy refers to your right to control how your personal information is collected, stored, and used. This distinction is crucial when comparing TLS (the technology behind HTTPS) and end-to-end encryption:
- TLS provides security against external threats but still allows the service provider (server) to access your data
- E2EE delivers true privacy by ensuring that not even the service provider can read your messagesâonly you and your intended recipient hold the keys.
TLS vs E2EE: A Visual Comparison
In the diagram above:
- Traditional TLS Encryption (left): The server decrypts and re-encrypts messages, meaning it can read your communications. This protects against external attackers but not against the service provider itself.
- End-to-End Encryption (right): The server only forwards encrypted data without being able to decrypt it. Only Alice and Bob can read the messages, giving you both security and privacy.
đ¤ Why does the server need to decrypt and re-encrypt with TLS?
The server keeps separate encryption keys with Alice and with Bob. When Alice sends a message, the server decrypts it using Aliceâs keys, then re-encrypts it using Bobâs keys. This means the server sees the plaintext message in betweenâprotecting you from network hackers, but not from the service provider itself.
The Signal Protocol: Battle-Tested E2E Encryption
We will build our E2E encryption system based on Signal Protocol - the gold standard for E2E encrypted messaging:
- Used by Signal (obviously), WhatsApp, Facebook Messenger, Google Messages
- Protects billions of messages every day
- Open source and academically vetted
Why Signal Protocol?
- Forward Secrecy - New keys for every message
- Asynchronous - Works even when recipients are offline
- Authenticated - You know who sent each message
- Deniable - Canât cryptographically prove who said what
- Post-Quantum Ready - Updated to include Kyber for quantum resistance
What is PQXDH?
PQXDH (Post-Quantum Extended Diffie-Hellman) is Signalâs latest key agreement protocol, designed to resist quantum computers. Itâs currently implemented in the libsignal library (as of Nov 2025) and will be the foundation of our E2E encryption system.
The basic idea:
- Alice and Bob each have several keys (identity, signed prekeys, quantum keys)
- They perform multiple Diffie-Hellman exchanges
- They combine the results into a shared secret
- This secret is used to derive encryption keys
Weâll implement a simplified 3-key version in this series (we skip the optional one-time prekeys)
References
- Signal. âThe PQXDH Key Agreement Protocol.â Signal Specifications.
- Okta. âPrivacy vs. Security: Whatâs the Difference?â Okta Identity 101.
