Skip to main content

Module encryption

Module encryption 

Source
Expand description

AES Crypt v3 encryption surface.

This crate writes the AES Crypt v3 format only; v0–v2 are not supported on the write side. The high-level entry point is encrypt(), which composes every helper exposed here into a complete .aes file. The lower-level pieces are public so that callers integrating with custom containers (mmap’d files, framed network protocols, etc.) can drive each stage themselves.

§Layout of a v3 file

+----------------------------------+
| "AES" 0x03 0x00                  |  write_header
| extensions (0x00 0x00 to end)    |  write_extensions
| iterations (4 BE bytes)          |  write_iterations
| public IV (16 bytes)             |  write_public_iv
| encrypted session block (48 B)   |  encrypt_session_block + write_octets
| session HMAC (32 bytes)          |  write_hmac
| ciphertext stream + payload HMAC |  encrypt_stream
+----------------------------------+

§Security

See the crate-level Security Model for the full primitive list. Briefly: AES-256-CBC + HMAC-SHA256 over the encrypted session block and ciphertext, PBKDF2-HMAC-SHA512 for password hardening, secure-gate-managed memory for every secret. Random IVs and session keys come from the secure-gate CSPRNG.

Functions§

derive_setup_key
Derives the AES-256 setup key from a password and public IV using PBKDF2-HMAC-SHA512.
encrypt
Encrypts the bytes read from input into a complete AES Crypt v3 file written to output.
encrypt_session_block
Encrypts the 48-byte session block (session IV + session key) under the setup key and feeds each ciphertext block into the running HMAC.
encrypt_stream
Encrypts the payload stream of an AES Crypt v3 file with PKCS#7 padding and appends a 32-byte HMAC-SHA256 trailer.
write_extensions
Writes the v3 extension-block section, terminated by a zero-length record.
write_header
Writes the 5-byte AES Crypt v3 file header b"AES" || version || 0x00.
write_hmac
Finalizes hmac and writes the resulting 32-byte HMAC-SHA256 tag.
write_iterations
Writes the v3 PBKDF2 iteration count as 4 big-endian bytes.
write_public_iv
Writes the 16-byte public IV after revealing it from its secure-gate wrapper.