$ show rfjakob/gocryptfs
gocryptfs is a production-grade, FUSE-based encrypted overlay filesystem written in Go. It transparently encrypts file contents and filenames on the fly, supporting both forward mode (encrypting a plaintext directory) and reverse mode (presenting an encrypted view of a plaintext directory). The system uses multiple cryptographic backends (AES-GCM, AES-SIV, XChaCha20-Poly1305) with optional OpenSSL hardware acceleration, HKDF key derivation, and scrypt-based password hashing. It provides a rich CLI with subcommands for mounting, initializing filesystems, changing passwords, filesystem checking, and benchmarking. The architecture is a monolithic CLI tool that mounts a FUSE filesystem, with internal packages for content encryption, filename encryption (EME), safe syscall wrappers, and a control socket for path encryption/decryption. The codebase demonstrates strong security practices (O_NOFOLLOW, *at syscalls, memory wiping) and includes an extensive test suite with backward compatibility testing against multiple filesystem versions.
The LLM identified 4 files worth highlighting for reuse:
Implements a cipher.AEAD interface using OpenSSL's GCM via CGo, with automatic fallback to Go's standard library implementation. Includes thread-safe locking, key wiping, and support for multiple cipher suites (AES-128-GCM, AES-256-GCM, ChaCha20-Poly1305, XChaCha20-Poly1305). This is a self-contained, reusable crypto backend that can be extracted into any Go project needing hardware-accelerated AEAD encryption.
Provides a stable, unique inode number mapping for files across different devices and filesystems. Uses a two-level mapping with a primary map for small inode numbers and a spill map for large ones, ensuring 64-bit inode numbers remain within a configurable range. This is a standalone, reusable component for any filesystem or storage system that needs to assign stable virtual inode numbers to real files.
A simple, efficient byte buffer pool that reduces memory allocations for ciphertext and plaintext blocks. Uses sync.Pool internally with size-specific pools. This is a straightforward, reusable pattern for any Go application that frequently allocates and discards fixed-size byte slices.
Provides safe file operations using O_NOFOLLOW and *at syscalls to prevent symlink races. Includes OpenDirNofollow, OpenNofollow, and helpers for path traversal without following symlinks. This is a reusable security pattern that can be extracted into any Go project needing robust filesystem access.