When I released MemCloud (a distributed RAM engine for macOS & Linux), the biggest question I got was:
โIsnโt letting other devices store your RAM risky? How is it secured?โ
So hereโs a deep-dive into the authentication, encryption, and trust model behind MemCloud โ written for engineers who love protocols, threat models, and cryptographic design.
This post focuses purely on the Security & Authentication layer.
(If you're new to MemCloud, see the intro blog โ this assumes familiarity.)
๐งฉ Threat Model
Before designing the protocol, I outlined real-world LAN threats:
| Threat | Example |
|---|---|
| Impersonation | Rogue device pretends to be a trusted peer |
| MITM Attack | Attacker intercepts or mutates handshake traffic |
| Replay Attack | Reusing old handshake messages |
| Unauthorized Memory Access | Device silently joins the cluster |
| Session Hijacking | Stealing or predicting traffic keys |
MemCloudโs protocol addresses all of them.
๐ 1. Persistent Identity Keys (Ed25519)
Every device has a long-term identity keypair:
~/.memcloud/identity_key
- Ed25519 (fast + secure)
- Only used to sign handshake transcripts
- Never used for encryption
This behaves like a device certificate without the complexity of PKI.
๐ 2. Noise-Style Handshake (XX Pattern)
MemCloud uses an authentication flow inspired by the Noise Protocol Framework โ specifically Noise_XX, chosen because:
- Both sides begin unauthenticated
- Supports Trust-On-First-Use (TOFU)
- Offers mutual authentication
- Ensures forward secrecy
Simplified handshake:
A โ B : eA, nonceA
B โ A : eB, nonceB
A โ B : identity proof (encrypted)
B โ A : identity proof (encrypted)
Where eA and eB are ephemeral X25519 public keys.
๐ 3. Transcript Hashing
Every handshake message is hashed into a transcript:
H = Hash(H || message)
This prevents:
- Replay attacks
- Downgrade attacks
- Cross-session confusion
- MITM tampering
The transcript is later fed into key derivation.
๐งพ 4. Encrypted Identity Proofs
Once ephemeral keys are exchanged, both sides compute:
shared_secret = DH(eA, eB)
Using this encryption key, each device sends:
signature = Sign(TranscriptHash, IdentityKey)
This signature:
- is encrypted
- is bound to the transcript
- cannot be replayed
- proves identity with forward secrecy
If signature verification fails โ connection closed immediately.
๐ 5. Session Key Derivation (HKDF)
Final traffic keys are derived using:
session_key = HKDF(shared_secret + transcript_hash)
Properties:
โ Unique keys per session
โ Handshake keys โ traffic keys
โ Forward secrecy (ephemeral DH)
โ Resistant to key compromise
Traffic encryption uses:
ChaCha20-Poly1305 AEAD
Perfect for high-speed LAN communication.
๐ 6. Trust-On-First-Use (TOFU)
Requesting device:

On first contact, the user must explicitly approve the peer:
Trusted peers are stored in:
~/.memcloud/trusted_devices.json
Future connections:
- Still cryptographically authenticated
- Skip interactive approval
- Cannot be silently spoofed or replaced
๐ซ What Happens When Auth Fails?
MemCloud rejects the session if:
- identity signature fails
- transcript mismatch occurs
- handshake is malformed
- device is untrusted
- the consent layer blocks authorization
Rejected peers cannot:
- read your RAM
- receive block data
- join the cluster
- impersonate a previous peer
๐ Why Not TLS?
TLS is powerful, but not ideal for a P2P LAN memory engine.
โ Requires PKI or certificate distribution
MemCloud is designed to be zero-config.
โ Not optimized for TOFU
Noise is.
โ More overhead for LAN P2P
MemCloud aims for sub-10ms latency.
โ Noise-style handshake advantages:
- Mutual authentication
- Identity hiding
- Forward secrecy
- TOFU support
- Lightweight binary protocol
- Perfect for peer-to-peer systems
๐งช Fuzzing & Attack Testing
I tested the handshake against:
| Attack Attempt | Result |
|---|---|
| Replay | Blocked via transcript mismatch |
| MITM | Blocked (identity proof mismatch) |
| Impersonation | Blocked (signature invalid) |
| Downgrade attempt | Impossible |
| Payload tampering | Blocked (MAC failure) |
So far the protocol has held up extremely well in real-world LAN conditions.
๐ Security Roadmap
Planned improvements:
- ๐ Trust revocation broadcasting
- ๐ฅ GUI trust manager
- ๐ก Optional hardware-backed identity keys
- ๐ Session resumption
- ๐ฆ Encrypted replication across peers
Contributors welcomed.
๐ฆ Source Code
๐ Authentication Code: /memnode/src/net/auth
๐ Main Repo: https://github.com/vibhanshu2001/memcloud
๐ Documentation: https://memcloud.vercel.app/docs/cli
๐ CLI Trust Manager: memcli trust
โค๏ธ Final Thoughts
MemCloud may look simple on the surface:
โDevices sharing RAM over LAN.โ
But underneath is a carefully engineered secure protocol designed to make that actually safe.
If you'd like a follow-up on the:
- P2P binary protocol
- memory isolation model
- quota enforcement
- zero-copy streaming design
Just let me know!

Top comments (0)