Skip to content

Repository files navigation

Secure Voice Communication Using Post-Quantum Cryptography

A demonstration project that simulates a post-quantum secure voice communication system using AES-GCM encryption and simulated Kyber KEM key exchange.

Overview

This project demonstrates how voice communication can be secured using post-quantum cryptography principles. It simulates a real-time voice encryption system that would be resistant to attacks from quantum computers.

Key Features

  • Real-time audio capture and playback using microphone and speakers
  • AES-GCM encryption for symmetric encryption of audio chunks
  • Simulated Kyber KEM for post-quantum key exchange
  • WebSocket communication for real-time audio transmission
  • Chunk-by-chunk encryption for low-latency processing
  • Enhanced terminal output showing cryptographic operations
  • Real-time encryption/decryption activity monitoring
  • Session statistics and connection status
  • Detailed key information display (private key, public key, shared secret)

Post-Quantum Cryptography Concepts

What is Post-Quantum Cryptography?

Post-quantum cryptography refers to cryptographic algorithms that are designed to be secure against both classical and quantum computers. Traditional cryptographic systems like RSA and ECC (Elliptic Curve Cryptography) are vulnerable to quantum attacks using Shor's algorithm.

Kyber KEM (Key Encapsulation Mechanism)

Kyber is a post-quantum key encapsulation mechanism based on the learning-with-errors (LWE) problem over module lattices. It's designed to be:

  • Quantum-resistant: Secure against quantum computer attacks
  • Efficient: Fast key generation, encapsulation, and decapsulation
  • Standardized: Part of NIST's post-quantum cryptography standards

AES-GCM (Advanced Encryption Standard - Galois/Counter Mode)

AES-GCM is a symmetric encryption algorithm that provides:

  • Confidentiality: Data is encrypted and cannot be read without the key
  • Authenticity: Ensures data hasn't been tampered with
  • Integrity: Detects any modifications to the encrypted data

Project Architecture

┌─────────────────┐    WebSocket     ┌─────────────────┐
│   Client        │◄─────────────────►│   Server        │
│                 │                   │                 │
│ ┌─────────────┐ │                   │ ┌─────────────┐ │
│ │ Microphone  │ │                   │ │ Speakers    │ │
│ └─────────────┘ │                   │ └─────────────┘ │
│        │        │                   │        ▲        │
│        ▼        │                   │        │        │
│ ┌─────────────┐ │                   │ ┌─────────────┐ │
│ │ Audio       │ │                   │ │ Audio       │ │
│ │ Capture     │ │                   │ │ Playback    │ │
│ └─────────────┘ │                   │ └─────────────┘ │
│        │        │                   │        ▲        │
│        ▼        │                   │        │        │
│ ┌─────────────┐ │                   │ ┌─────────────┐ │
│ │ AES-GCM     │ │                   │ │ AES-GCM     │ │
│ │ Encryption  │ │                   │ │ Decryption  │ │
│ └─────────────┘ │                   │ └─────────────┘ │
│        │        │                   │        ▲        │
│        ▼        │                   │        │        │
│ ┌─────────────┐ │                   │ ┌─────────────┐ │
│ │ WebSocket   │ │                   │ │ WebSocket   │ │
│ │ Sender      │ │                   │ │ Receiver    │ │
│ └─────────────┘ │                   │ └─────────────┘ │
└─────────────────┘                   └─────────────────┘

Installation

Prerequisites

  • Python 3.7 or higher
  • Microphone and speakers/headphones
  • Internet connection (for installing dependencies)

Setup

  1. Clone or download this project

    # If you have git
    git clone https://github.com/dineshyadav03/postquantumkeyexchange.git
    cd postquantumkeyexchange
    
    # Or simply download and extract the files
  2. Install dependencies

    pip install -r requirements.txt
  3. Verify installation

    python test_installation.py

Available Demo Files

  • simple_voice_demo.py - Enhanced demo with detailed cryptographic output (recommended)
  • pq_voice_demo.py - Original demo with basic functionality
  • test_installation.py - Verify all dependencies are installed
  • test_audio.py - Test microphone and speaker functionality
  • test_websocket.py - Test WebSocket connectivity

Usage

Running the Demo

The demo requires two instances running simultaneously - one as a server and one as a client.

Step 1: Start the Server

Open a terminal/command prompt and run:

python simple_voice_demo.py server

You should see enhanced output like:

============================================================
POST-QUANTUM KEY EXCHANGE SIMULATION
============================================================
Simulating Kyber KEM (Key Encapsulation Mechanism)...
Private Key: 8f33d497b199f62e...836911e6
Public Key:  0ed2c293dbfd7fd0...a4e46ef8
Shared Secret: 44656d6f53686172...6d6d3132
Key exchange completed successfully!
============================================================
Derived AES-256 Key: c6bc51ca62465dd7...7b8d2a50
Ready for secure communication!
============================================================

============================================================
SECURE VOICE COMMUNICATION SERVER
============================================================
Starting audio capture and playback...
Starting WebSocket server...
Audio system ready!
Server listening for connections...
============================================================

Step 2: Start the Client

Open another terminal/command prompt and run:

python simple_voice_demo.py client

You should see enhanced output like:

============================================================
POST-QUANTUM KEY EXCHANGE SIMULATION
============================================================
Simulating Kyber KEM (Key Encapsulation Mechanism)...
Private Key: 8f33d497b199f62e...836911e6
Public Key:  0ed2c293dbfd7fd0...a4e46ef8
Shared Secret: 44656d6f53686172...6d6d3132
Key exchange completed successfully!
============================================================
Derived AES-256 Key: c6bc51ca62465dd7...7b8d2a50
Ready for secure communication!
============================================================

============================================================
SECURE VOICE COMMUNICATION CLIENT
============================================================
Starting audio capture and playback...
Connecting to server...
Audio system ready!
============================================================
Connected to server successfully!
Ready to capture and encrypt audio...
Ready to receive and decrypt audio...
============================================================

Step 3: Real-time Encryption Activity

During operation, you'll see live encryption/decryption activity:

[ENCRYPT] Chunk #50 | Size: 4096 bytes | Nonce: a1b2c3d4...
[DECRYPT] Chunk #50 | Size: 4096 bytes | Nonce: a1b2c3d4...
[ENCRYPT] Chunk #100 | Size: 4096 bytes | Nonce: e5f6g7h8...
[DECRYPT] Chunk #100 | Size: 4096 bytes | Nonce: e5f6g7h8...

Step 4: Test the Communication

  1. Speak into the microphone on the client side
  2. Listen to the decrypted audio on the server side
  3. The audio should be transmitted securely with minimal delay
  4. Watch the terminal for real-time encryption/decryption activity

Step 5: Session Statistics

When you stop the demo, you'll see session statistics:

Session Statistics:
Total encrypted: 1250 chunks
Total decrypted: 1250 chunks
============================================================

Stopping the Demo

Press Ctrl+C in either terminal to stop the respective instance.

Technical Details

Audio Processing

  • Sample Rate: 44.1 kHz
  • Chunk Size: 1024 samples
  • Channels: Mono (1 channel)
  • Format: 32-bit float

Encryption Details

  • Algorithm: AES-256-GCM
  • Key Size: 256 bits (32 bytes)
  • Nonce Size: 96 bits (12 bytes)
  • Authentication Tag: 128 bits (16 bytes)

Key Derivation

  • Method: PBKDF2 (Password-Based Key Derivation Function 2)
  • Salt: Fixed salt for demo purposes
  • Iterations: 100,000 rounds
  • Output: 256-bit AES key

WebSocket Communication

  • Protocol: WebSocket over TCP
  • Port: 8765
  • Message Format: JSON
  • Data Encoding: Base64

Security Considerations

What This Demo Shows

  • Symmetric encryption of real-time audio
  • Key derivation from shared secret
  • Authenticated encryption (AES-GCM)
  • Real-time processing with low latency

What This Demo Simulates

  • 🔄 Kyber KEM key exchange (simulated with random key generation)
  • 🔄 Post-quantum security (demonstrates the concept)

What This Demo Does NOT Include

  • Real Kyber KEM implementation (would require additional libraries)
  • Perfect Forward Secrecy (keys don't change during session)
  • Certificate validation (no PKI infrastructure)
  • Network security (no TLS/DTLS)
  • Production-ready code (this is a demonstration)

Troubleshooting

Common Issues

  1. "No module named 'sounddevice'"

    • Solution: Install dependencies with pip install -r requirements.txt
  2. "No audio devices found"

    • Solution: Check your microphone and speaker connections
    • On Windows: Check Windows Audio service
    • On Linux: Check ALSA/PulseAudio configuration
  3. "WebSocket connection failed"

    • Solution: Make sure the server is running before starting the client
    • Check if port 8765 is available
  4. "Audio quality is poor"

    • Solution: Check microphone levels and speaker volume
    • Ensure stable network connection (even for localhost)
  5. "Permission denied" for microphone

    • Solution: Grant microphone permissions to your terminal/IDE
    • On macOS: System Preferences > Security & Privacy > Microphone

Performance Tips

  • Close unnecessary applications to reduce CPU usage
  • Use wired headphones to reduce audio latency
  • Ensure stable system performance for real-time processing
  • Test with short phrases initially to verify functionality

Educational Value

This demo is designed to help understand:

  1. Post-quantum cryptography concepts and why they're important
  2. Real-time encryption challenges and solutions
  3. Audio processing in Python
  4. WebSocket communication for real-time data
  5. Symmetric encryption with authentication
  6. Key derivation from shared secrets

Future Enhancements

Potential improvements for a production system:

  • Real Kyber KEM implementation using libraries like liboqs
  • Perfect Forward Secrecy with key rotation
  • TLS/DTLS integration for network security
  • Certificate-based authentication
  • Multi-user support with conference rooms
  • Mobile app integration
  • Voice activity detection to reduce bandwidth
  • Audio compression before encryption

License

This project is for educational and demonstration purposes. Feel free to use and modify for learning about post-quantum cryptography and real-time audio encryption.

Contributing

This is a demonstration project, but suggestions and improvements are welcome! Focus areas:

  • Code clarity and documentation
  • Educational explanations
  • Performance optimizations
  • Additional security features

Note: This is a demonstration project. For production use, consult with cryptography experts and use established, audited libraries for post-quantum cryptography.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages