Ciphern Crypto Library
Ciphern is an enterprise-grade, security-first Rust cryptographic library providing cryptographic capabilities that comply with both Chinese National Standards (GuoMi) and international standards. Designed for data storage encryption, communication encryption, and key management.
✨ Core Features
🔒 Security First
- Memory Protection: Securely clear keys using
zeroize, support for memory locking (mlock) and integrity verification - Side-channel Protection: Provides constant-time operation implementation to prevent timing attacks
- Compliance: Compliant with Chinese National Standards (SM2/SM3/SM4) and FIPS 140-3 basic requirements
- Audit Logs: Full audit trail for cryptographic operations
- Key Lifecycle: Support for basic lifecycle management including key generation, activation, and destruction
⚡ High Performance
- Zero-Copy Design: Minimizes memory allocation and copying
- Smart Caching: Reuses keys and algorithm instances
- Pure Rust Implementation: No external dependencies, compile-time optimization
🔧 Easy Integration
- Unified Interface: Simple API that hides underlying complexity
- Multi-language Support: C FFI interface, basic Java JNI and Python PyO3 bindings
- Pluggable Architecture: Supports custom cryptographic algorithm plugins (basic framework)
- Rich Testing: Includes unit tests, integration tests, and performance tests
- Internationalization (i18n): Full i18n support with English and Chinese locales, string interpolation with arguments
🌐 Standard Compatibility
- International Standards: AES-128/192/256-GCM, ECDSA-P256/P384/P521, RSA-2048/3072/4096, Ed25519
- National Standards: SM2, SM3, SM4-GCM
- Hash Functions: SHA-256/384/512, SHA3-256/384/512, SM3
- Key Derivation: HKDF, PBKDF2, Argon2id, Sm3Kdf
🚀 Quick Start
Installation
Rust (Cargo)
[]
= "0.1"
Java (Maven)
Java JNI bindings have completed core functionality implementation, supporting encryption/decryption and key management:
<!-- Maven direct installation is not yet supported, requires compilation of the JNI library from source -->
Python (pip)
Python PyO3 bindings have completed core functionality implementation, supporting encryption/decryption, signature verification, and hash calculation:
# pip direct installation is not yet supported, requires compilation from source
# pip install ciphern # Not available yet
5-Minute Examples
Basic Encryption/Decryption (Rust)
use ;
use Hash;
Digital Signature (Rust)
use ;
National Standard Algorithms (Rust)
use ;
Java Example
Java JNI bindings have completed core functionality implementation:
;
Python Example
Python PyO3 bindings have completed core functionality implementation:
# Initialize KeyManager
=
# Generate a key
=
# Create cipher
=
# Encrypt
= b
=
# Decrypt
=
📚 Documentation
Core Documentation
- User Guide - Detailed instructions and best practices
- API Reference - Complete API reference
- Examples - Examples covering common scenarios
Advanced Topics
- Architecture - System architecture and design decisions
- Performance Optimization - SIMD, hardware acceleration, benchmark
- Security Guide - Threat model, security best practices
- Multi-Tenancy Guide - Key isolation and access control
Developer Documentation
- Contributing Guide - How to participate in development
- Plugin Development - Implementing custom algorithms
- FFI Guide - C/Java/Python bindings
🎯 Use Cases
Data Storage Encryption
Protect sensitive data in databases and file systems
use ;
init?;
let km = new?;
let key_id = km.generate_key_with_alias?;
let cipher = new?;
// Encrypt sensitive field
let encrypted_ssn = cipher.encrypt?;
db.save_encrypted_field?;
API Communication Encryption
Protect the confidentiality and integrity of API requests and responses
use ;
init?;
let km = new?;
let key_id = km.generate_key?;
let cipher = new?;
let signature = cipher.sign?;
http_request
.header
.body
.send?;
Key Management
Basic key lifecycle management
use ;
init?;
let km = new?;
// Generate a key
let key_id = km.generate_key?;
// Manage keys using aliases
let alias_key_id = km.generate_key_with_alias?;
🔧 Advanced Features
FIPS 140-3 Compliance Mode
[]
= { = "0.1", = ["fips"] }
use ;
// Enable FIPS mode during initialization
init?;
// Check if FIPS mode is enabled
if is_fips_enabled
// In FIPS mode, non-approved algorithms will be rejected
let result = new;
assert!; // CryptoError::FipsError
Audit Logging and Monitoring
use AuditLogger;
use Arc;
// Initialize the library
init?;
// Log an event
log?;
// Get performance metrics
let metrics = audit_logger.get_performance_metrics?;
println!;
println!;
Custom Algorithm Plugins
use ;
// Extend algorithms by implementing Plugin and CipherPlugin traits
Internationalization (i18n)
[]
= { = "0.1", = ["i18n"] }
use ;
// Set locale to English or Chinese
set_locale; // or "zh"
// Simple translation
let message = tr?; // Returns "OK" in English
// Translation with arguments
let error_msg = tr_with_args?;
// Returns: "Key my-key not found in keyring main: not found"
// Check supported locales
use ;
assert!;
assert!;
let locales = get_supported_locales; // Returns vec!["en", "zh"]
📊 Performance Metrics
Performance Metrics
The current version is based on a pure Rust implementation. Performance data can be obtained through the audit system:
// Performance monitoring is handled internally by the audit system
// The current version collects performance metrics internally
// Performance data is available through internal monitoring systems
Note: SIMD optimization and hardware acceleration features are under development. The current version provides a basic implementation of cryptographic functions.
Run benchmark:
🔐 Security
Security Features
- ✅ Automatic Memory Erasure: Securely clear keys using
zeroize - ✅ Memory Locking: Uses
mlockto prevent sensitive data from being swapped to disk - ✅ Integrity Verification: Key integrity checks to prevent memory tampering
- ✅ Constant-time Operations: Side-channel protection to prevent timing attacks
- ✅ FIPS 140-3 Basic Compliance: Supports verification of FIPS-approved algorithms
- ✅ Audit Logs: Full audit trail for cryptographic operations
- ✅ Algorithm Verification: Built-in algorithm correctness self-checks
- ✅ Error Handling: Secure error state management
Security Audit
Ciphern security features are based on the following implementations:
- ✅ Uses mature cryptographic libraries (
ring,libsm) as the underlying implementation - ✅ Built-in algorithm correctness verification
- ✅ FIPS 140-3 algorithm approval checks
- ✅ Comprehensive error handling and state management
Note: NIST CAVP testing, Fuzzing, third-party security audits, etc., are planned.
Vulnerability Reporting
If you find a security vulnerability, please report it in the GitHub Issues.
Note: A dedicated security email and SECURITY.md documentation are being prepared.
🛠️ Development Environment
Prerequisites
- Rust 1.75+ (stable)
- Standard C compiler (for FFI bindings)
Build
# Clone the repository
# Default build
# Enable all features
# FIPS mode
Test
# Run all tests
# Run benchmarks
# Check code quality
Cross-Compilation
# ARM64 Linux
# Windows
# macOS ARM (Apple Silicon)
🗺️ Roadmap
v0.1.0 - MVP (Completed) ✅
- Core encryption (AES-128/192/256-GCM, SM4-GCM)
- Digital signatures (ECDSA-P256/P384/P521, RSA-2048/3072/4096, Ed25519, SM2)
- Hash functions (SHA-256/384/512, SHA3-256/384/512, SM3)
- Key derivation (HKDF, PBKDF2, Argon2id, Sm3Kdf)
- Basic key management
- Rust API
- Audit logging system
- FIPS 140-3 basic support
v0.2.0 - Multi-language Support (Completed) ✅
- C FFI interface
- Java JNI bindings (core functionality implemented)
- Python PyO3 bindings (core functionality implemented)
- Memory protection enhancements (mlock + integrity verification)
- Side-channel protection (constant-time operations)
- Plugin system improvements
- Internationalization (i18n) with English and Chinese locale support
v0.3.0 - Extensibility (Planned) 📋
- SIMD optimization
- WASM support
- HSM integration (PKCS#11)
- TEE support (Intel SGX, ARM TrustZone)
v1.0.0 - Production Ready (Planned) 🎯
- Complete security audit
- FIPS 140-3 certification
- Performance optimization (SIMD, multi-core)
- Full documentation and examples
🤝 Contributing
We welcome all forms of contribution!
How to Contribute
- Fork this repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
Note: CONTRIBUTING.md documentation is being prepared.
Contributors
Thanks to all contributors!
📄 License
This project is dual-licensed:
- MIT License - see LICENSE-MIT
- Apache License 2.0 - see LICENSE-APACHE
You may choose either license for your use.
Note: License files are being prepared. The current version follows standard Rust open-source protocols.
🙏 Acknowledgments
Ciphern is built upon these excellent open-source projects:
- ring - High-performance cryptography library (v0.17)
- libsm - GuoMi algorithm implementation (v0.6)
- aes-gcm - AES-GCM implementation (v0.10)
- argon2 - Argon2 key derivation (v0.5)
- zeroize - Secure memory erasure (v1.7)
Special thanks to all security researchers who audited the code and provided feedback.
📞 Contact
- Issues: https://github.com/Kirky-X/ciphern/issues
- Discussions: https://github.com/Kirky-X/ciphern/discussions
Note: Official website, documentation site, and dedicated support email are being prepared.
⭐ Star History
Built with ❤️ by the Ciphern Team