Expand description
The core of this program. Encrypt/decrypt, compress/decompress files.
GITSE Binary Header Layout (64 Bytes)
00 04 05 06 07 17 27 3F
+———–+—+—+—+———–+—————––+—————+
| MAGIC | V | F | A | SALT | FILE_ID | RESERVED |
| “GITSE” | | | | (16 bytes)| (16 bytes) | (24 bytes) |
+———–+—+—+—+———–+—————––+—————+
5 bytes 1 1 1 16 bytes 16 bytes 24 bytes
| | |
Version —+ | +— Encryption Algo (1 = XChaCha20-Poly1305 Stream)
|
Flags ––––+ (Bit 0: Compression)
Streaming Format: Files are processed in 64KB chunks. Each chunk is individually encrypted using XChaCha20-Poly1305.
§Nonce Derivation (Content-Based with File ID)
Per-chunk nonces are derived from the file’s random File_ID and the
chunk’s own plaintext content using keyed Blake3:
- A random 16-byte
File_IDis generated once per file and stored in the header. This ensures that even if two different files have identical plaintext at chunk 0, they produce different nonces and ciphertexts. - The Argon2-derived master key is split via
blake3::derive_keyintoKey_ENC(for XChaCha20-Poly1305 encryption) andKey_MAC(for nonce generation). - For each chunk
i:Nonce_i = Blake3_keyed(Key_MAC, File_ID || M_i || chunk_idx_le)[0..24] - The 24-byte nonce is stored in plaintext at the head of each encrypted chunk.
Different plaintext always produces a different nonce (within the same
file). The File_ID ensures cross-file uniqueness. The chunk index prevents
reordering attacks on identical 64 KB blocks.
§Authenticated Additional Data (AAD)
Each chunk’s AAD binds the ciphertext to the full file header so that any
tampering with header fields (version, compression flag, salt, file_id,
reserved) is detected via Poly1305 authentication failure:
AAD = HEADER (64B) || chunk_idx (8B LE) || is_last_chunk (1B) // 73 bytesEach encrypted chunk layout: [NONCE (24B)] [CIPHERTEXT] [TAG (16B)]
Structs§
- File
Header - Fixed-size file header stored at the beginning of every encrypted file.
Constants§
- FILE_
ID_ LEN - HEADER_
LEN - MAGIC
- NONCE_
LEN - SALT_
LEN - VERSION
- Current encryption format version.
Functions§
- decrypt_
file - Decrypt a single file using streaming chunked decryption.
- decrypt_
file_ with_ cache - Decrypt a single file using streaming chunked decryption, with a thread-safe cache for derived keys and an optional cache sender for deterministic re-encryption.
- decrypt_
repo - Decrypt given files in the repo. If no paths are given, decrypt all files in the repo’s crypt list.
- encrypt_
file - Encrypt a single file using streaming chunked encryption.
- encrypt_
repo - Encrypt given files in the repo. If no paths are given, encrypt all files in the repo’s crypt list.
- is_
encrypted_ version - Returns
trueif the given version byte is supported for decryption.