Skip to content

harshitsidhwa/cipher-bench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Cipher Benchmark Suite

A comprehensive performance benchmarking suite comparing encryption algorithms across Go and Java implementations.

Go Java License

πŸ“Š Overview

This project benchmarks the performance of three major encryption algorithms implemented in both Go and Java:

  • AES-256-GCM (Authenticated Encryption)
  • AES-256-CBC (Block Cipher with PKCS#7 padding)
  • PGP (RSA-4096 + AES-256 hybrid encryption)

🎯 Key Findings

Algorithm Language 1KB Throughput 5MB Throughput Best Use Case
AES-256-GCM Go 358,038 ops/sec 373 ops/sec High-frequency APIs
AES-256-GCM Java 10,162 ops/sec 163 ops/sec Enterprise systems
AES-256-CBC Go 155,860 ops/sec 86 ops/sec Legacy compatibility
AES-256-CBC Java 42,895 ops/sec 110 ops/sec Large file processing
PGP Go 168 ops/sec 4 ops/sec Key exchange
PGP Java 134 ops/sec 8 ops/sec Email encryption

πŸ† Winner: Go + AES-256-GCM for high-performance applications (up to 35x faster than Java)

πŸš€ Quick Start

Prerequisites

  • Go 1.24+
  • Java 11+
  • Maven 3.6+

Clone and Run

git clone https://github.com/harshitsidhwa/cipher-bench.git
cd cipher-bench

# Run Go benchmarks
cd go-benchmarks
go run .

# Run Java benchmarks  
cd ../java-benchmarks
mvn compile exec:java -Dexec.mainClass="com.benchmark.SimpleBenchmarkRunner"

πŸ“ Project Structure

cipher-bench/
β”œβ”€β”€ πŸ“Š ENCRYPTION_PERFORMANCE_REPORT.md   # Comprehensive analysis report
β”œβ”€β”€ 🐹 go-benchmarks/                     # Go implementation
β”‚   β”œβ”€β”€ main.go                           # Benchmark runner
β”‚   β”œβ”€β”€ aes_gcm.go                        # AES-GCM implementation  
β”‚   β”œβ”€β”€ aes_cbc.go                        # AES-CBC implementation
β”‚   β”œβ”€β”€ pgp.go                            # PGP implementation
β”‚   β”œβ”€β”€ utils.go                          # Utility functions
β”‚   └── benchmark_results.json            # Go results
β”œβ”€β”€ β˜• java-benchmarks/                    # Java implementation
β”‚   β”œβ”€β”€ pom.xml                           # Maven configuration
β”‚   β”œβ”€β”€ src/main/java/com/benchmark/
β”‚   β”‚   β”œβ”€β”€ SimpleBenchmarkRunner.java    # Main benchmark runner
β”‚   β”‚   β”œβ”€β”€ AESGCMBenchmark.java         # JMH AES-GCM benchmarks
β”‚   β”‚   β”œβ”€β”€ AESCBCBenchmark.java         # JMH AES-CBC benchmarks
β”‚   β”‚   β”œβ”€β”€ SimplePGPBenchmark.java      # PGP implementation
β”‚   β”‚   └── PGPTest.java                 # PGP validation test
β”‚   └── java_benchmark_results.json      # Java results
└── πŸ“ README.md                         # This file

πŸ”§ Implementation Details

Go Implementation

  • Libraries: Standard crypto/* + golang.org/x/crypto/openpgp
  • Strengths: Native crypto optimizations, excellent small payload performance
  • Best for: Microservices, APIs, real-time processing

Java Implementation

  • Libraries: javax.crypto + Bouncy Castle for PGP
  • Strengths: Enterprise ecosystem, competitive large payload performance
  • Best for: Enterprise applications, complex cryptographic workflows

πŸ“ˆ Benchmark Results

Performance by Payload Size

Payload Size Go AES-GCM Java AES-GCM Go Advantage
1 KB 358,038 ops/sec 10,162 ops/sec 35.2x faster
10 KB 197,550 ops/sec 13,899 ops/sec 14.2x faster
50 KB 41,729 ops/sec 22,530 ops/sec 1.9x faster
100 KB 15,124 ops/sec 11,420 ops/sec 1.3x faster
200 KB 10,370 ops/sec 7,165 ops/sec 1.4x faster
5 MB 373 ops/sec 163 ops/sec 2.3x faster

πŸ“Š Visualization Data

Chart-ready CSV data is available in the comprehensive report.

🎯 Use Case Recommendations

πŸš€ High-Performance Applications

Choose: Go + AES-256-GCM

  • Microservices and APIs
  • Real-time data processing
  • IoT and edge computing
  • Systems programming

🏒 Enterprise Applications

Choose: Java + AES-256-GCM/CBC

  • Large file processing
  • Existing Java infrastructure
  • Complex integration requirements
  • Rich cryptographic workflows

πŸ” Public Key Infrastructure

Choose: Either Language + PGP

  • Email encryption
  • Document signing
  • Key exchange protocols
  • Certificate management

πŸ”¬ Running Custom Benchmarks

Go Benchmarks

cd go-benchmarks

# Standard benchmarks
go run .

# Custom payload sizes (modify PayloadSizes in main.go)
# Custom iteration counts (modify iterations in benchmark functions)

# Build optimized binary
go build -o cipher-bench .
./cipher-bench

Java Benchmarks

cd java-benchmarks

# Run all benchmarks
mvn compile exec:java -Dexec.mainClass="com.benchmark.SimpleBenchmarkRunner"

# Test PGP implementation
mvn compile exec:java -Dexec.mainClass="com.benchmark.PGPTest"

# Build JAR (note: signature issues with shaded JAR)
mvn clean package

JMH Benchmarks (Advanced)

cd java-benchmarks

# Individual algorithm benchmarks using JMH directly
mvn compile exec:java -Dexec.mainClass="com.benchmark.AESGCMBenchmark"
mvn compile exec:java -Dexec.mainClass="com.benchmark.AESCBCBenchmark"

πŸ“‹ Payload Sizes Tested

  • 1 KB (1,024 bytes) - Small API responses
  • 10 KB (10,240 bytes) - Medium documents
  • 50 KB (51,200 bytes) - Large documents
  • 100 KB (102,400 bytes) - Small files
  • 200 KB (204,800 bytes) - Medium files
  • 5 MB (5,242,880 bytes) - Large files

πŸ” Security Considerations

Cryptographic Standards

  • AES-256: NIST-approved, quantum-resistant
  • GCM Mode: Authenticated encryption (AEAD)
  • CBC Mode: Industry standard with PKCS#7 padding
  • RSA-4096: Strong asymmetric encryption
  • PGP: OpenPGP standard compliance

Key Management

  • Cryptographically secure random key generation
  • Keys generated outside benchmark loops
  • No key reuse across different payload sizes
  • Proper IV/nonce generation for each operation

🀝 Contributing

Contributions are welcome! Please read our Contributing Guidelines before submitting pull requests.

Areas for Contribution

  • Additional encryption algorithms (ChaCha20-Poly1305, XSalsa20, etc.)
  • More language implementations (Rust, Python, C++)
  • Performance optimizations
  • Additional payload size testing
  • Platform-specific benchmarks (ARM, x86, cloud environments)

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“š Further Reading


πŸ“Š Quick Performance Summary

πŸ† WINNER: Go + AES-256-GCM
πŸ“ˆ Performance: Up to 35x faster than Java
🎯 Best for: High-frequency encryption, APIs, microservices
⚑ Throughput: 358,038 operations/second (1KB payloads)

Built with ❀️ for the cryptography and performance engineering community

About

πŸ” Comprehensive encryption algorithm benchmarking suite

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published