True Randomness as a Service powered by cosmic unpredictability
This project generates cryptographically secure random numbers by extracting entropy from live NASA space imagery, served via a REST API with a modern React web interface. Unlike pseudo-random generators (PRNGs) which are deterministic, this system harnesses natural cosmic unpredictability to produce true random numbers suitable for:
- ๐ Cryptographic key generation
- โ๏ธ Blockchain randomness
- ๐ค AI/ML stochastic processes
- ๐ฒ Simulations and gaming
- ๐ Security applications
- True Randomness: Extracts entropy from natural cosmic phenomena (NASA SDO)
- High Quality: Shannon entropy ~8 bits per byte (avg 0.93+ quality score)
- Scalable: Redis-backed entropy pool with concurrent access
- Secure: Cryptographic hashing (SHA-256 + BLAKE3, multi-round, blockchain chaining)
- Real-time: Continuous image ingestion (1,200+ MB entropy pool)
- Production Ready: Docker containerized, fully deployed
- Interactive Playground: Generate and display random bytes in real-time
- Live Statistics: Auto-updating pool status and entropy quality metrics
- Beautiful UI: Modern React interface with Tailwind CSS styling
- API Documentation: Interactive endpoint documentation
- Fully Integrated: Connected to live backend API endpoints
- Python 3.11+
- Node.js 18+ (for frontend)
- Docker & Docker Compose
- Git
Option 1: Automated Single Script (Recommended)
# Clone repository
git clone <repository-url>
cd Space-Image-Based-Entropy-Generator-True-Randomness-as-a-Service-
# Run everything with one command
python3 run.pyThis single script will:
- โ Start Redis + Backend (Docker containers)
- โ Start Frontend (Vite dev server)
- โ Wait for all services to be healthy
- โ Display service URLs and status
- โ Gracefully shutdown all services on Ctrl+C
Option 2: Manual Docker Compose
# Start backend services
docker-compose up -d
# Start frontend (in another terminal)
cd website/solar-entropy-api-main/solar-entropy-api-main
npm run dev| Service | URL | Purpose |
|---|---|---|
| Web Frontend | http://localhost:8080 | Interactive UI with Playground & Docs |
| API Docs | http://localhost:8000/docs | Swagger API documentation |
| Health Check | http://localhost:8000/api/v1/health | Backend status |
# Check backend health
curl http://localhost:8000/api/v1/health
# Get random bytes
curl http://localhost:8000/api/v1/random/256
# Check pool statistics
curl http://localhost:8000/api/v1/stats
# Visit frontend
open http://localhost:8080Expected Response:
{
"status": "healthy",
"redis": {
"available_blocks": 1262,
"available_bytes": 5169152,
"average_quality": 0.932
}
}The React frontend provides an interactive experience for exploring entropy generation:
- Playground: Generate random bytes and download results
- Live Statistics: Real-time pool metrics (entropy quality, available bytes, generation rate)
- API Documentation: Interactive docs with copy-paste examples
- Beautiful Design: Modern UI with Tailwind CSS
Frontend uses environment variables for API connectivity:
# .env.local
VITE_API_BASE_URL=http://localhost:8000/api/v1
VITE_STATS_POLL_INTERVAL=10000 # Update stats every 10 secondsFor production deployment, see WEBSITE_DEPLOYMENT.md
# Get 256 random bytes (Base64 encoded)
curl http://localhost:8000/api/v1/random/256
# Get 1024 random bytes
curl http://localhost:8000/api/v1/random/1024curl http://localhost:8000/api/v1/healthcurl http://localhost:8000/api/v1/statsVisit http://localhost:8000/docs for Swagger UI documentation.
NASA SDO API โ Image Ingestion โ Noise Extraction โ Cryptographic Hashing โ Validation โ Redis Pool โ REST API
โ
React UI
-
Image Ingestion (app/ingestion/)
- Fetches 4 wavelengths concurrently from NASA SDO
- Automatic cleanup of old images (keeps 10 most recent)
- Optional Azure Blob Storage backup
-
Noise Extraction (app/preprocessing/)
- Laplacian edge detection with image mixing
- High-frequency FFT filtering
- Sobel gradient calculation
- Non-deterministic random region sampling
- RGB channel separation
-
Cryptographic Hashing (app/entropy/hashing.py)
- 3-round alternating BLAKE3/SHA-256 hashing
- Microsecond timestamp integration
- Blockchain-like chaining between blocks
- BLAKE3 XOF extension to target block size
-
Quality Validation (app/entropy/validation.py)
- Shannon entropy calculation (target: โฅ7.8 bits/byte)
- Chi-square test for uniform distribution
- Runs test for consecutive patterns
- Autocorrelation test for self-similarity
- Bit entropy test for bit-level randomness
-
Entropy Pool (app/entropy/pool.py)
- Redis-backed storage with 1-hour TTL
- Atomic retrieval with automatic block deletion
- Statistics tracking (blocks added/served, average quality)
- Health monitoring
-
REST API (app/api/routes.py)
/health- Service health and pool status/stats- Pool statistics/random/{n}- Retrieve 1-10240 random bytes- Base64-encoded responses
space-entropy-generator/
โโโ app/ # Backend (FastAPI)
โ โโโ main.py # Entry point, lifespan context
โ โโโ config.py # Configuration & settings
โ โโโ api/
โ โ โโโ routes.py # REST endpoints
โ โโโ ingestion/
โ โ โโโ fetch_images.py # NASA SDO image fetching
โ โโโ preprocessing/
โ โ โโโ noise_extraction.py # Entropy extraction (5 techniques)
โ โโโ entropy/
โ โโโ hashing.py # Cryptographic hashing
โ โโโ validation.py # Statistical quality tests
โ โโโ pool.py # Redis entropy pool
โ
โโโ website/ # Frontend (React + TypeScript)
โ โโโ src/
โ โ โโโ lib/
โ โ โ โโโ api.ts # API utilities & TypeScript types
โ โ โโโ components/
โ โ โ โโโ Playground.tsx # Random bytes generator
โ โ โ โโโ LiveStats.tsx # Real-time pool metrics
โ โ โ โโโ APISection.tsx # API documentation
โ โ โโโ pages/
โ โ โ โโโ Index.tsx # Home page
โ โ โ โโโ Docs.tsx # Full API docs
โ โ โโโ App.tsx # Router setup
โ โ โโโ index.css # Tailwind styles
โ โโโ .env.local # Local API configuration
โ โโโ vite.config.ts # Vite configuration
โ โโโ package.json # Frontend dependencies
โ
โโโ docker-compose.yml # Full stack (Backend + Redis)
โโโ Dockerfile # Backend containerization
โโโ requirements.txt # Python dependencies
โโโ test_pipeline.py # End-to-end testing
โโโ .env.example # Environment template
โโโ README.md # This file
Environment variables (see .env.example):
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_USE_SSL=False
# Entropy Pool Settings
ENTROPY_POOL_SIZE=1048576 # 1MB pool size
ENTROPY_BLOCK_SIZE=4096 # 4KB blocks
MIN_SHANNON_ENTROPY=7.8 # Quality threshold
# Image Ingestion
IMAGE_FETCH_INTERVAL=300 # Fetch every 5 minutes
IMAGES_DIR=data/images # Local image storage
MAX_IMAGES=10 # Keep 10 most recent
# Azure Integration (Optional)
USE_AZURE_BLOB=False
AZURE_STORAGE_CONNECTION_STRING=
AZURE_STORAGE_ACCOUNT=
AZURE_STORAGE_CONTAINER=space-entropy
AZURE_STORAGE_SAS_TOKEN=
AZURE_USE_MANAGED_IDENTITY=False
# API Settings
API_V1_PREFIX=/api/v1
MAX_RANDOM_BYTES=10240 # Max bytes per request- Project structure & configuration
- Image ingestion from NASA SDO (4 wavelengths)
- Complete preprocessing pipeline (5 noise extraction techniques)
- Cryptographic hashing (BLAKE3, SHA-256, multi-round)
- Entropy validation (5 statistical tests)
- Redis entropy pool manager
- Complete REST API (health, stats, random/{n})
- Background tasks (periodic image fetch & generation)
- Docker containerization & docker-compose
- Azure integration (optional)
- React web interface (NEW)
- API utilities & TypeScript types (NEW)
- Live statistics component (NEW)
- Interactive playground (NEW)
- Complete integration testing (NEW)
- Dual-service deployment (NEW)
- โ Backend running on port 8000 (FastAPI + Uvicorn)
- โ Frontend running on port 8080 (React + Vite)
- โ Redis pool: 1,262+ blocks (5+ MB entropy)
- โ API responding with live random bytes
- โ Live stats updating every 10 seconds
- โ Playground generating real entropy
Typical Performance Metrics:
- Entropy Generation: ~1,281 blocks (5.2MB) from single 1024ร1024 image
- Quality Score: Average 0.93-0.95 (threshold: 0.75)
- Shannon Entropy: 7.95+ bits/byte (threshold: 7.8)
- Processing Time: ~10-15 seconds per image
- API Response Time: <100ms for requests up to 10KB
- Pool Capacity: Configurable (default 1MB), auto-refills when below threshold
python test_pipeline.pyThis tests:
- Redis connection
- Image ingestion from NASA
- Noise extraction
- Cryptographic hashing
- Quality validation
- Pool storage and retrieval
- End-to-end pipeline
# Test individual modules
python -m app.ingestion.fetch_images
python -m app.preprocessing.noise_extraction
python -m app.entropy.validation
python -m app.entropy.pool- Physical Entropy Source: Real solar activity provides true randomness
- Multiple Extraction Methods: Reduces vulnerability to single-method weaknesses
- Cryptographic Hardening: Multi-round hashing whitens any residual patterns
- Quality Validation: Statistical tests ensure cryptographic standards
- No Reuse: Entropy blocks deleted after serving
- Network Dependency: Requires internet access to NASA SDO
- Processing Overhead: ~10-15 seconds per image generation
- Pool Depletion: High-volume requests may temporarily exhaust pool
- Trust Model: Assumes NASA image stream integrity
- Use for non-critical applications or as entropy mixing source
- Combine with system entropy (
/dev/urandom) for defense in depth - Monitor pool statistics to avoid depletion
- Implement rate limiting for production deployments
- Rotate entropy frequently (1-hour TTL default)
Currently supported:
- NASA Solar Dynamics Observatory (SDO): Multiple wavelength solar images
- 193 ร (1.6 million K)
- 304 ร (50,000 K)
- 171 ร (600,000 K)
- 211 ร (2 million K)
Future sources:
- Hubble Space Telescope images
- Weather satellite imagery
- Ground-based telescope starfields
- Cosmic ray detectors
Contributions welcome! Areas for improvement:
- Additional entropy sources (other space telescopes)
- NIST SP 800-22 test suite integration
- GPU acceleration for image processing
- Rate limiting and API authentication
- Performance benchmarking suite
- Prometheus metrics export
This project is licensed under the MIT License - see the LICENSE file for details.
- NASA for providing free access to Solar Dynamics Observatory imagery
- Inspired by Cloudflare's lava lamp entropy wall
- Built with FastAPI, React, OpenCV, and modern Python tools
For questions, issues, or suggestions, please open an issue on GitHub.
Note: This is a research/educational project. For production cryptographic applications, always combine multiple entropy sources and consult security experts.
Built with โ๏ธ solar entropy