A C++17 command-line utility for creating and extracting encrypted archives using modern ChaCha20-Poly1305 AEAD and SHA-256 key derivation.
Copyright (c) 2026 Dario Deledda. All rights reserved.
- Encrypt files or folders into a single
.dcfarchive - Decrypt
.dcfarchives back to the original folder structure - ChaCha20-Poly1305 AEAD - Authenticated Encryption with Associated Data for modern, secure cryptography
- SHA-256 Key Derivation (KDF) - Derives unique cryptographic keys and nonces for every chunk
- Single-file implementation - Only the C++17 standard library is required
- Cross-platform - Works natively on Linux, macOS, and Windows
- All data encrypted - Header, paths, and content are fully encrypted
- Cryptographic Authentication - Poly1305 MAC tags prevent chosen-ciphertext attacks and data tampering
- CRC32 integrity verification - Detects accidental corruption automatically (with hardware SSE4.2 support)
- Streaming architecture - Processes files via an in-place 4MB push-buffer, allowing arbitrarily large files with ultra-low memory overhead
- Custom output paths - Specify output file with
-oflag - Password support - Interactive prompt or
-pflag for key entry - Progress bar - Real-time progress with ETA, speed, and phase status
| Flag | Description |
|---|---|
-o, --output <path> |
Custom output file path |
-p, --password <key> |
Encryption key (interactive if omitted) |
--encrypt |
Force encrypt mode |
--decrypt |
Force decrypt mode |
--no-progress |
Disable progress bar display |
g++ -std=c++17 -O3 -Wall -o dcf crypto.cpp(Optional: add -msse4.2 to explicitly enforce hardware-accelerated CRC32 on x86_64, though the code auto-detects it in MSVC.)
cl /std:c++17 /O2 /EHsc dcf.exe crypto.cppif SSE4.2 is supported use:
cl /EHsc /std:c++17 /O2 /arch:SSE4.2 /Fe:dcf.exe crypto.cppBefore compiling with cl, activate the 64-bit environment (if not using the Dev Prompt):
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64./dcf <input> [output] # Auto-detect mode
./dcf --encrypt <files/folder> # Force encrypt mode
./dcf --decrypt <archive.dcf> # Force decrypt mode-o <path> Custom output file path
-p <key> Encryption key (or prompted if omitted)./dcf myfolder/
# Creates: myfolder.dcf./dcf file1.txt file2.jpg file3.pdf
# Creates: archive.dcf (default fallback name)./dcf document.pdf
# Creates: document.pdf.dcf./dcf -o /backup/myfiles.dcf myfolder/
./dcf -o encrypted.zip file1.txt file2.txt./dcf -p "mysecretkey" file.txt # Key from argument
./dcf -p folder/ # Interactive password prompt
./dcf -p secret archive.dcf # Decrypt with specific key./dcf backup.dcf
# Extracts to the directory containing the .dcf file
# Recreates the original folder structure automaticallyA real-time, terminal-aware progress bar is displayed by default, showing:
- Visual bar:
[#################---] - Progress:
45.2MB / 67.8MB (67%) - Speed:
125.3 MB/s - ETA:
00:01:23 - Phase status:
[Building archive...],[Reading header...],[Verifying...], etc.
Disable with the --no-progress flag:
./dcf --no-progress file.txt # Silent modeThe application uses a secure, chunked ChaCha20-Poly1305 implementation:
- Key Derivation (SHA-256): The user's password and the specific chunk index are hashed using SHA-256. This derives an independent 32-byte key and 8-byte nonce for every 4MB chunk of data.
- ChaCha20 Stream Cipher: Data is encrypted using ChaCha20. The implementation includes word-level SIMD XOR optimizations for rapid block processing.
- Poly1305 Authentication (AEAD): A robust 26-bit limb Poly1305 algorithm calculates a 16-byte MAC (Message Authentication Code) appended to every chunk. This provides Authenticated Encryption with Associated Data, guaranteeing that ciphertexts cannot be tampered with.
- Streaming Serialization: Files are streamed directly into a pre-allocated 4MB push-buffer, encrypted in-place, and immediately flushed to disk. Peak RAM overhead is practically constant regardless of total archive size.
- Buffered Decryption:
BufferedStreamReaderreads chunks, verifies the Poly1305 authentication tag before attempting decryption (preventing chosen-ciphertext attacks), and streams plaintext back to the disk.
All data is fully encrypted.
Physical File Layout:
+-------------------------------------------------+
| Header (20 bytes) |
| Encrypted directly via ChaCha20 (Chunk 0 Key) |
| - magic: "DCF1" (4 bytes) |
| - version: 4 (4 bytes, little-endian) |
| - entryCount (4 bytes, little-endian) |
| - contentCrc32 (4 bytes) |
| - headerCrc32 (4 bytes) |
+-------------------------------------------------+
| Cryptographic Chunks Stream |
| - Chunk 0 [Encrypted Payload + 16b Poly1305 Tag]|
| - Chunk 1 [Encrypted Payload + 16b Poly1305 Tag]|
| - Chunk 2 ... |
+-------------------------------------------------+
Logical Layout (Inside the decrypted stream):
+------------------+
| Entry 1 |
| - pathLen | 4 bytes (little-endian uint32)
| - path | pathLen bytes (relative path string)
| - isDirectory | 1 byte (0=false, 1=true)
| - contentSize | 8 bytes (little-endian uint64)
| - content | contentSize bytes (raw file data)
+------------------+
| Entry 2 ... |
+------------------+
Version History:
- Version 1: Original format (RC4, no CRC)
- Version 2: Added CRC32 integrity verification
- Version 3: Added parallel RC4-CTR chunked encryption
- Version 4: Complete overhaul to ChaCha20-Poly1305 AEAD + SHA-256 KDF (Current)
Integrity is strictly enforced at two levels:
- Cryptographic (Poly1305): Every 4MB chunk is individually authenticated during streaming extraction. If a single byte is flipped by an attacker or corrupted, the extraction process aborts immediately with a Poly1305 verification failure.
- Structural (CRC32): The header has its own CRC32. Additionally, a
contentCrc32checksum validates the entirely extracted plaintext data to ensure perfect reconstruction.
- Large file support: Tested with massive files (10GB+). The buffered streaming approach easily handles arbitrary sizes.
- Constant Memory Footprint: Peak RAM is exceptionally low (~4MB push-buffer + ~4MB read buffer) for both encryption and decryption.
- Hardware Acceleration: Automatically uses SSE4.2
_mm_crc32_u64intrinsics on supported architectures for massive CRC calculation speedups.
The tool leverages ChaCha20-Poly1305, widely regarded as one of the most secure and performant modern software-based stream ciphers (used heavily in TLS 1.3 and WireGuard).
Note: While SHA-256 is used to derive distinct internal stream keys and nonces to avoid key/nonce reuse across chunks, it is a fast hash. For extreme, nation-state level threat models, pre-hashing your chosen password with a memory-hard KDF (like Argon2 or PBKDF2) before providing it to the CLI is recommended.
This project is provided under Mozilla Public License 2.0 (MPL 2.0).