Encryption Overview
All sensitive data is encrypted on your device before being sent to the Happy server:Code & Messages
Session messages and code snippets are encrypted with AES-256-GCM
Metadata
Session metadata and settings use TweetNaCl secretbox
Authentication
Challenge-response protocol with Ed25519 signatures
Key Exchange
Ephemeral keypairs for secure key sharing
Cryptographic Library
Happy uses TweetNaCl (NaCl), a high-security cryptographic library:- Audited: Extensively reviewed and battle-tested
- Fast: Optimized implementations for performance
- Simple: Clean API reduces implementation errors
- Portable: Works across platforms (Node.js, browsers, React Native)
Encryption Implementations
Legacy Encryption (Secretbox)
Used for backward compatibility and simple encryption:- Algorithm: XSalsa20-Poly1305 (secretbox)
- Nonce: 24 bytes, randomly generated per message
- Authentication: Built-in Poly1305 MAC
- Bundle format: nonce (24 bytes) + ciphertext + auth tag
Data Key Encryption (AES-256-GCM)
Used for high-performance encryption of large data:- Algorithm: AES-256 in Galois/Counter Mode
- Nonce: 12 bytes, randomly generated
- Authentication: Built-in GHASH authentication
- Bundle format: version(1) + nonce(12) + ciphertext + auth tag(16)
- Versioning: Supports protocol upgrades
Public Key Encryption
For asymmetric encryption (e.g., sending data to specific users):- Algorithm: X25519-XSalsa20-Poly1305 (NaCl box)
- Ephemeral keys: New keypair for each message
- Forward secrecy: Compromising one message doesn’t affect others
- Libsodium compatible: Works with other NaCl implementations
Authentication System
Happy uses challenge-response authentication:- Client generates random 32-byte challenge
- Client signs challenge with Ed25519 secret key
- Server verifies signature against public key
- Server issues authentication token
- No password transmission: Secret never leaves device
- Replay protection: Each challenge is unique
- Cryptographic proof: Ed25519 provides strong authentication
Base64 Encoding
For safe transmission and storage:Random Number Generation
Secure random bytes for nonces and keys:Key Storage
CLI (Desktop)
Keys are stored in~/.happy/access.key with restricted permissions:
Mobile (iOS/Android)
Keys are stored using platform secure storage:- iOS: Uses Keychain with kSecAttrAccessibleAfterFirstUnlock
- Android: Uses EncryptedSharedPreferences with hardware-backed keystore
- Web: Uses localStorage (less secure, not recommended for production keys)
Encryption Strategy
Unified encryption function with variant selection:Data Flow
Key Points:- Server never has decryption keys
- All encryption/decryption happens on client devices
- Server acts as encrypted message relay
Security Guarantees
Confidentiality
Data is encrypted before leaving your device. Server cannot read contents.
Integrity
Authenticated encryption (GCM, Poly1305) prevents tampering.
Forward Secrecy
Ephemeral keys ensure past messages stay secure if keys are compromised.
Authentication
Ed25519 signatures prove identity without exposing secrets.
Threat Model
Protected Against
- Server compromise (data stored encrypted)
- Network eavesdropping (TLS + E2E encryption)
- Message tampering (authenticated encryption)
- Replay attacks (unique nonces, challenge-response)
Not Protected Against
- Device compromise (malware, keyloggers)
- Physical access to unlocked device
- Compromised client app (supply chain attacks)
- Social engineering
Best Practices
Secure key generation
Always use cryptographically secure random number generators. Never hardcode keys or use predictable seeds.
Key rotation
Generate new encryption keys periodically. Happy creates new session keys for each conversation.
Secure deletion
When deleting sessions, ensure encryption keys are securely wiped from memory and storage.
Audit & Compliance
- Open Source: All encryption code is publicly auditable
- Standard Algorithms: Uses NIST-approved and widely reviewed algorithms
- No Custom Crypto: Relies on established libraries (TweetNaCl, Node.js crypto)
- Regular Updates: Dependencies are kept current with security patches
Performance
Encryption overhead is minimal:- AES-256-GCM: Hardware-accelerated on modern CPUs (~1-2GB/s)
- TweetNaCl: Optimized implementations (~100MB/s for secretbox)
- Negligible latency: Encryption adds less than 1ms for typical messages
Next Steps
Mobile Access
Learn how encryption works across platforms
Sandbox Configuration
Configure OS-level sandboxing for security
Authentication
Learn about secure authentication
Contributing
Help improve Happy