Skip to content

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.

License

Notifications You must be signed in to change notification settings

agilira/harpocrates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Harpocrates: High-Performance Professional Cryptography Library for Go

Harpocrates Banner

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.

CI CodeQL Security Go Report Card Test Coverage OpenSSF Best Practices

FeaturesInstallationQuick ExamplesPhilosophyDocumentationSecurityPerformance

Features

High-Performance Core Cryptography

  • AES-256-GCM authenticated encryption with cipher caching (49% performance boost)
  • Binary & string data support with optimized EncryptBytes/DecryptBytes core 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 Management

  • 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

Key Derivation Functions

  • 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

Hardware Security Module (HSM) Integration

  • 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

Security & Quality

  • 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

Professional Security Testing

  • 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

Compatibility and Support

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.

Installation

go get github.com/agilira/harpocrates

Release Verification

All releases are cryptographically signed with GitHub attestations. Verify authenticity:

gh attestation verify ./harpocrates-* --owner agilira

Quick Examples

Basic Encryption/Decryption

import 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)

Zero-Downtime Key Rotation

// 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

Streaming Large Data

// 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

Hardware Security Module (HSM) Integration

// 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)

Advanced Key Derivation

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)

The Philosophy Behind Harpocrates

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.

Building

# 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

Running Tests

make test         # Use the Makefile for comprehensive testing
make check        # Run all quality checks (tests + linting + security)
make security     # Run security analysis and fuzz testing

Use Makefile on Unix systems or Makefile.ps1 on Windows PowerShell.

Documentation

Security

This library uses industry-standard cryptographic algorithms and follows security best practices. For detailed security information, see Security Documentation.

Performance

Benchmark Results (AMD Ryzen 5 7520U)

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

Scaling Characteristics

  • 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

About

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.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages