Designed for Nemesis, Harpocrates delivers secure and well-tested primitives for encryption, decryption, key and nonce management, and key fingerprinting using AES-256-GCM with advanced optimizations including cipher caching, buffer pooling, and cache-line tuned algorithms.
Features • Installation • Quick Examples • Philosophy • Documentation • Security • Performance
- AES-256-GCM authenticated encryption with cipher caching (49% performance boost)
- Binary & string data support with optimized
EncryptBytes/DecryptBytescore functions - Streaming encryption/decryption for large datasets (GB-scale) with chunked processing
- Advanced buffer pooling with 79% memory reduction and cache-line optimization
- Ring buffer techniques applied for consistent low latency
- Thread-safe operations with linear scaling on multi-core systems
- Zero-downtime key rotation with dual-KEK architecture and automated rollback
- NEMESIS-grade key lifecycle with multi-state management (pending, validating, active, deprecated, revoked)
- Prepare→Validate→Commit rotation phases with automatic failure recovery
- Backward compatibility - all existing APIs work unchanged while adding new capabilities
- Argon2id key derivation (resistant to ASIC/FPGA attacks) with secure defaults
- PBKDF2-SHA256 legacy support for backward compatibility
- HKDF key derivation for hierarchical key generation and context separation
- Cryptographically secure random generation for keys and nonces
- Enterprise HSM support with PKCS#11 compliance (SafeNet, Thales, AWS CloudHSM)
- Plugin architecture powered by github.com/agilira/go-plugins
- Hardware-protected key generation within secure HSM boundaries
- FIPS 140-2 Level 3/4 compliance for regulated environments
- Tamper-resistant operations with hardware attestation
- Multi-vendor compatibility through standardized plugin interface
- Secure memory zeroization for sensitive data protection
- Advanced error handling with rich error context and structured error codes
- Comprehensive testing with 90%+ coverage including boundary, stress, and integration tests
- Fuzz testing with Go native fuzzer for discovering edge cases and security vulnerabilities
- CodeQL semantic analysis for advanced SAST with data flow and taint analysis
- Multi-layered static analysis combining gosec patterns with CodeQL deep analysis
- Advanced red team analysis - Multi-vector attack simulation with CWE-classified vulnerabilities
- Statistical timing analysis - T-test significance testing for side-channel resistance
- Race condition testing - Concurrent state machine exploitation with 50+ goroutines
- Memory management exploitation - Buffer pool exhaustion and cleanup verification
- Cryptographic attack vectors - Weak keys, nonce reuse, AAD manipulation, buffer overflow
- NEMESIS-specific testing - Vault-targeted attack scenarios and authenticated encryption bypass attempts
- Information leakage analysis - Error message content validation and side-channel detection
Harpocrates supports the latest two minor versions of Go (currently Go 1.24+ and Go 1.25+) and follows Long-Term Support guidelines to ensure consistent performance across production deployments.
go get github.com/agilira/harpocratesAll releases are cryptographically signed with GitHub attestations. Verify authenticity:
gh attestation verify ./harpocrates-* --owner agiliraimport crypto "github.com/agilira/harpocrates"
key, err := crypto.GenerateKey()
if err != nil {
// handle error
}
// For text data (convenience functions)
ciphertext, err := crypto.Encrypt("secret data", key)
plaintext, err := crypto.Decrypt(ciphertext, key)
// For binary data (core functions - recommended)
binaryData := []byte{0x00, 0x01, 0xFF, 0xFE}
ciphertext, err := crypto.EncryptBytes(binaryData, key)
decrypted, err := crypto.DecryptBytes(ciphertext, key)// Initialize key manager
km := crypto.NewKeyManager()
// Current way: immediate rotation (brief downtime)
newKEK, err := km.RotateKEK("purpose")
// New way: zero-downtime rotation
newKEK, err := km.RotateKEKZeroDowntime("purpose")
// Or step-by-step control
pendingKEK, err := km.PrepareKEKRotation("purpose") // Phase 1: prepare
err = km.ValidateKEKRotation() // Phase 2: validate
err = km.CommitKEKRotation() // Phase 3: commit
// err = km.RollbackKEKRotation() // Emergency rollback// For large files/datasets (GB-scale)
key, _ := crypto.GenerateKey()
// Streaming encryption
encryptor, err := crypto.NewStreamingEncryptor(outputWriter, key)
defer encryptor.Close()
io.Copy(encryptor, inputReader) // Encrypts while streaming
// Streaming decryption
decryptor, err := crypto.NewStreamingDecryptor(inputReader, key)
defer decryptor.Close()
io.Copy(outputWriter, decryptor) // Decrypts while streaming// Initialize HSM with go-plugins gRPC interface
hsm, err := crypto.NewHSM("pkcs11", map[string]interface{}{
"plugin_path": "./plugins/hsm-pkcs11",
"grpc_address": "localhost:50051",
"slot_id": 0,
"pin": "1234",
})
defer hsm.Close()
// Generate key in HSM hardware
keyHandle, err := hsm.GenerateKey("vault-master-kek", 32)
// Hardware-protected encryption
ciphertext, err := hsm.Encrypt(keyHandle, []byte("sensitive data"))
plaintext, err := hsm.Decrypt(keyHandle, ciphertext)password := []byte("my-secure-password")
salt := []byte("random-salt-123")
// Argon2id (recommended)
key, err := crypto.DeriveKeyDefault(password, salt, 32)
// HKDF for hierarchical keys
context := []byte("user-session-keys")
sessionKey, err := crypto.DeriveKeyHKDF(masterKey, salt, context, 32)
// Custom Argon2 parameters
key, err := crypto.DeriveKeyWithParams(password, salt, 3, 64*1024, 4, 32)Harpocrates, the child of silence, understood what others could not grasp. In ancient temples, when priests whispered the most sacred incantations, when merchants sealed their most valuable contracts, when lovers shared their deepest secrets—Harpocrates was there, finger raised to his lips, guardian of what must never be spoken aloud.
The young god knew that true power lay not in the message itself, but in ensuring that only the intended could hear it. His silence was not empty—it was full of protection. Each secret he guarded was wrapped in layers of divine safekeeping, accessible only to those who possessed the proper keys to unlock his trust.
In the halls of Alexandria's great library, scholars would invoke Harpocrates before transcribing their most precious knowledge, knowing that the god of silence would ensure their wisdom reached only worthy hands across the centuries.
# Unix/Linux/macOS
./build.sh # Development build (debug symbols preserved)
./build.sh --strip # Production build (debug symbols stripped)
# Windows PowerShell
.\build.ps1 # Development build (debug symbols preserved)
.\build.ps1 -Strip # Production build (debug symbols stripped)All build scripts use -trimpath and -buildid= flags to ensure bit-for-bit reproducible builds
make test # Use the Makefile for comprehensive testing
make check # Run all quality checks (tests + linting + security)
make security # Run security analysis and fuzz testingUse Makefile on Unix systems or Makefile.ps1 on Windows PowerShell.
- API Reference - Complete API documentation with examples for all functions
- Security Considerations - Security features, best practices, and compliance
- Security Testing Suite - Professional red team analysis and attack vector testing
- Encryption & Decryption - Core encryption, binary data, and streaming functions
- Key Management - Zero-downtime rotation, dual-KEK architecture, and lifecycle
- Hardware Security Modules - HSM integration, PKCS#11 support, and enterprise deployment
- Key Derivation Functions - Argon2id, PBKDF2, and HKDF support
- Key Utilities - Key generation, import/export, and utilities
- Streaming Operations - Large data encryption/decryption with chunked processing
This library uses industry-standard cryptographic algorithms and follows security best practices. For detailed security information, see Security Documentation.
BenchmarkEncryptionAllocation-8 734821 1692 ns/op 632 B/op 15 allocs/op
BenchmarkEncryptionWithPooling/Small_(16B)-8 827762 1528 ns/op 424 B/op 14 allocs/op
- Single-core: 1.31M ops/sec theoretical maximum
- Multi-core: Linear scaling with worker pools
- Memory: 79% reduction in allocations with buffer pooling
- Latency: Consistent sub-microsecond performance with cache optimization
Harpocrates • an AGILira library
