A comprehensive collection of cryptographic algorithm examples implemented in C++ using OpenSSL, covering hash functions, symmetric encryption, asymmetric cryptography, and more.
This repository provides practical, educational examples of cryptographic algorithms using OpenSSL 3.x. Each example includes complete source code, detailed explanations, build instructions, and comprehensive documentation to help developers understand and implement cryptographic operations correctly.
openssl_example/
βββ Hash/ # Cryptographic Hash Functions
β βββ blake2b512/ # BLAKE2b 512-bit hash
β βββ blake2s256/ # BLAKE2s 256-bit hash
β βββ MD5/ # MD5 (legacy, educational only)
β βββ mdc2/ # MDC-2 hash function
β βββ ripemd160/ # RIPEMD-160 hash
β βββ SHA-1/ # SHA-1 (legacy, educational only)
β βββ SHA-224/ # SHA-224 hash
β βββ SHA-256/ # SHA-256 hash
β βββ SHA-384/ # SHA-384 hash
β βββ SHA-512/ # SHA-512 hash
β βββ sha3-224/ # SHA3-224 hash
β βββ SHA3-256/ # SHA3-256 hash
β βββ SHA3-384/ # SHA3-384 hash
β βββ SHA3-512/ # SHA3-512 hash
β βββ sm3/ # SM3 (Chinese national standard)
β βββ whirlpool/ # Whirlpool hash function
βββ Symmetric/ # Symmetric Key Cryptography
β βββ block_cipers/ # Block Ciphers
β β βββ 3DES/ # Triple DES
β β βββ AES-CBC/ # AES in CBC mode
β β βββ AES-CBC-HMAC/ # AES-CBC with HMAC authentication
β β βββ Blowfish/ # Blowfish cipher
β β βββ Camellia/ # Camellia cipher
β β βββ CAST5/ # CAST5 cipher
β β βββ DES/ # DES (legacy, educational only)
β β βββ IDEA/ # IDEA cipher
β β βββ RC2/ # RC2 cipher
β β βββ SEED/ # SEED (Korean national standard)
β βββ stream_ciphers/ # Stream Ciphers
β β βββ chacha20/ # ChaCha20 stream cipher
β βββ authentication_encryption/ # Authenticated Encryption
β βββ AES-CCM/ # AES in CCM mode
β βββ AES-GCM/ # AES in GCM mode
β βββ ChaCha20-Poly1305/ # ChaCha20-Poly1305 AEAD
βββ Asymmetric/ # Public Key Cryptography
βββ RSA/ # RSA encryption and signatures
βββ ECC/ # Elliptic Curve Cryptography
βββ DSA/ # Digital Signature Algorithm
βββ Diffie-Hellman/ # Diffie-Hellman key exchange
# Install OpenSSL
brew install openssl
# Install development tools
xcode-select --installsudo apt-get update
sudo apt-get install build-essential libssl-devsudo yum groupinstall "Development Tools"
sudo yum install openssl-develEach algorithm directory contains:
- Source code: Implementation with detailed comments
- Makefile: Build configuration optimized for the platform
- README.md: Algorithm-specific documentation
- Key generation: Utilities for generating cryptographic keys
- Test data: Sample inputs and expected outputs
# Navigate to any algorithm directory
cd Hash/SHA-256
# Build the example
make
# Run the example
./sha256
# Save output for analysis
./sha256 > output.txt# Navigate to cipher directory
cd Symmetric/block_cipers/AES-CBC
# Generate keys first
make -f Makefile.key create
# Build and run example
make
./aes_cbcCryptographic hash functions for data integrity, digital signatures, and password verification.
- SHA-256/SHA-512: NIST standard, widely supported
- SHA3-256/SHA3-512: Latest NIST standard, sponge construction
- BLAKE2b/BLAKE2s: High-performance alternative to SHA-2
- SM3: Chinese national cryptographic standard
- Whirlpool: ISO/IEC standard based on AES design
- MD5: Cryptographically broken, educational purposes only
- SHA-1: Deprecated, educational purposes only
Fixed-size block encryption algorithms.
Modern Standards:
- AES: Current global standard (128/192/256-bit keys)
- Camellia: Japanese standard, AES alternative
- SEED: Korean standard, government applications
Historical/Educational:
- DES/3DES: Legacy standards, educational value
- Blowfish: Variable key length, educational interest
- IDEA: PGP cipher, patent expired
- CAST5: OpenPGP standard
- RC2: Microsoft CryptoAPI legacy
Bit-by-bit encryption algorithms.
- ChaCha20: Modern high-speed cipher, TLS 1.3 standard
Provides both confidentiality and authenticity.
- AES-GCM: High-performance authenticated encryption
- AES-CCM: Lower memory usage alternative
- ChaCha20-Poly1305: Modern AEAD for mobile/embedded systems
Public key cryptography for secure communication and digital signatures.
- RSA: Widely-used public key system for encryption and signatures
- ECC (ECDSA): Elliptic curve cryptography, smaller keys than RSA
- DSA: Digital signatures, government standard
- Diffie-Hellman: Key exchange protocol, foundation of many protocols
- SHA-256 or SHA-512 for general purposes
- SHA3-256 for diversity from SHA-2
- BLAKE2b for high-performance applications
- AES-256-GCM for authenticated encryption
- ChaCha20-Poly1305 for mobile/embedded systems
- AES-CBC + HMAC for legacy compatibility (with proper implementation)
- RSA-2048 minimum, RSA-3072 preferred for new systems
- ECDSA P-256 or P-384 for better performance
- Ed25519 for modern applications (when available)
- MD5: Cryptographically broken
- SHA-1: Collision attacks demonstrated
- DES: 56-bit key too small
- RC4: Multiple vulnerabilities
- RSA-1024: Insufficient key length
Each example includes optimized Makefiles with:
- Platform detection: Automatic OpenSSL path detection for macOS
- Compiler optimization: Performance and security flags
- Dependency management: Clear library requirements
- Cross-compilation: Support for different architectures
make # Build main example
make clean # Remove compiled binaries
make -f Makefile.key create # Generate cryptographic keys- Clean C++ code: Modern C++11 standards
- Detailed comments: Explaining cryptographic concepts
- Error handling: Proper OpenSSL error management
- Security practices: Secure key handling and memory management
- Algorithm explanations: Mathematical foundations and security properties
- Historical context: Development timeline and standardization
- Use case guidance: When and how to use each algorithm
- Security analysis: Strengths, weaknesses, and recommendations
- Start with hash functions: Understand cryptographic basics
- Move to symmetric encryption: Learn about keys and modes
- Explore asymmetric cryptography: Public key concepts
- Study authenticated encryption: Modern security requirements
Error: 'openssl/evp.h' file not foundSolution: Install OpenSSL development libraries using platform package manager.
Error: cipher/digest not availableSolution: Some older algorithms require loading the legacy provider in OpenSSL 3.x.
Error: cannot find -lssl -lcryptoSolution: Use provided Makefiles with correct library paths for your platform.
- Makefiles automatically detect Homebrew OpenSSL installation
- May need to set
LIBRARY_PATHfor custom OpenSSL installations - Apple's LibreSSL doesn't include all algorithms
- Use distribution package manager for OpenSSL installation
- Different distributions may have different package names
- Check for separate development packages (-dev, -devel)
- Recommended: OpenSSL 3.x (latest stable)
- Supported: OpenSSL 1.1.1 (with minor modifications)
- Legacy: OpenSSL 1.0.x (requires significant changes)
- Default provider: AES, SHA-2, SHA-3, RSA, ECC
- Legacy provider: RC2, RC4, DES, MD5, etc.
- FIPS provider: FIPS 140-2 validated algorithms
- NIST: SP 800 series cryptographic standards
- ISO/IEC: International cryptographic standards
- IETF: Internet cryptographic protocol standards
- ANSI: American national standards
- FIPS 197: AES specification
- FIPS 180-4: SHA-2 specification
- FIPS 202: SHA-3 specification
- RFC 8439: ChaCha20-Poly1305 specification
Contributions are welcome! Please:
- Follow the existing code style and documentation format
- Include comprehensive test cases and examples
- Update README files with algorithm details
- Ensure cross-platform compatibility
This project is intended for educational and research purposes. Individual algorithms may be subject to patents or export restrictions. Always verify legal compliance for your specific use case.
- OpenSSL Documentation
- Crypto++ Library
- Applied Cryptography by Bruce Schneier
- Cryptography Engineering by Ferguson, Schneier, and Kohno
Note: This collection is for educational purposes. Always use well-tested cryptographic libraries and follow current security best practices for production applications.